From d8e423db314e45a8ad56ce78bd15f6aa2756b724 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Wed, 30 Oct 2024 15:19:49 +0000 Subject: [PATCH] Improve TinyURL shortener --- wikibase/queryService/api/UrlShortener.js | 28 +++++++++++++++++------ wikibase/queryService/ui/App.js | 7 ++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/wikibase/queryService/api/UrlShortener.js b/wikibase/queryService/api/UrlShortener.js index 4fc99025..3135aa46 100644 --- a/wikibase/queryService/api/UrlShortener.js +++ b/wikibase/queryService/api/UrlShortener.js @@ -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 ''; + 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 = '
' + htmlEscape( text ) + '
'; + $element = $( '