Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions wikibase/queryService/api/UrlShortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,28 @@ wikibase.queryService.api.UrlShortener = ( function ( $ ) {

/** @return {string} HTML */
SELF.prototype._getTinyUrl = function( url ) {
var TINYURL_API = '//tinyurl.com/api-create.php?url=';
var base64Url = new URL( url );
base64Url.searchParams.append( 'base64', true );
base64Url.hash = btoa( base64Url.hash );

return '<iframe ' +
'class="shortUrl" ' +
'src="' + TINYURL_API + encodeURIComponent( url ) + '" ' +
'referrerpolicy="origin" ' +
'sandbox="" ' +
'></iframe>';
var deferred = $.Deferred();
$.ajax( {
'method': 'POST',
'url': 'https://tinyurl.com/api-create.php',
'data': jQuery.param({ 'url': base64Url.toString() })
} ).done( function( text ) {
var text, html, $element;
html = '<!DOCTYPE html><meta charset="utf-8"><pre>' + htmlEscape( text ) + '</pre>';
$element = $( '<iframe>' ).attr( {
'class': 'shortUrl',
'src': 'data:text/html;charset=utf-8,' + encodeURI( html ),
'sandbox': ''
} );
deferred.resolve( $element );
} ).fail( function() {
deferred.resolve( wikibase.queryService.ui.i18n.getMessage( 'wdqs-app-urlshortener-failed' ) );
} );
return deferred;
};

/** @return {string} HTML */
Expand Down
7 changes: 7 additions & 0 deletions wikibase/queryService/ui/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ wikibase.queryService.ui.App = ( function( $, window, _, Cookies, moment ) {
* @private
*/
SELF.prototype._initQuery = function() {
var url = new URL( window.location );
if ( url.searchParams.has( 'base64', true ) ) {
url.search = '';
url.hash = atob( url.hash.substring( 1 ) );
history.pushState( null, '', url.toString() );
}

if ( window.location.hash !== '' ) {
if ( location.hash.indexOf( '#result#' ) === 0 ) {
location.hash = location.hash.replace( '#result#', '#' );
Expand Down
Loading