From bd6196132419bdde8e270a4e6de306605bdeb455 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Fri, 23 Sep 2016 01:50:05 +0000 Subject: [PATCH] Add a continuation button to ApiSandbox Change-Id: I4def43b2000b5639e3ced2643afea4b1288e28b0 --- includes/api/ApiFormatBase.php | 1 + languages/i18n/en.json | 3 ++ languages/i18n/qqq.json | 3 ++ resources/Resources.php | 3 ++ .../mediawiki.special.apisandbox.js | 48 +++++++++++++++++-- 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index c826bbad95..4df7f51ead 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -231,6 +231,7 @@ abstract class ApiFormatBase extends ApiBase { $out->getModuleScripts(), $out->getModuleStyles() ) ) ), + 'continue' => $this->getResult()->getResultData( 'continue' ), 'time' => round( $time * 1000 ), ], false, FormatJson::ALL_OK diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 67e649148b..7216fc72df 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1922,6 +1922,9 @@ "apisandbox-results-fixtoken-fail": "Failed to fetch \"$1\" token.", "apisandbox-alert-page": "Fields on this page are not valid.", "apisandbox-alert-field": "The value of this field is not valid.", + "apisandbox-continue": "Continue", + "apisandbox-continue-clear": "Clear", + "apisandbox-continue-help": "{{int:apisandbox-continue}} will [https://www.mediawiki.org/wiki/API:Query#Continuing_queries continue] the last request; {{int:apisandbox-continue-clear}} will clear continuation-related parameters.", "booksources": "Book sources", "booksources-summary": "", "booksources-search-legend": "Search for book sources", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 163b613247..b055ed9a6e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2106,6 +2106,9 @@ "apisandbox-results-fixtoken-fail": "Displayed as an error message from JavaScript when a CSRF token could not be fetched.\n\nParameters:\n* $1 - Token type", "apisandbox-alert-page": "Tooltip for the alert icon on a module's page tab when the page contains fields with issues.", "apisandbox-alert-field": "Tooltip for the alert icon on a field when the field has issues.", + "apisandbox-continue": "Button text for sending another request using query continuation.", + "apisandbox-continue-clear": "Button text for clearing query continuation parameters.", + "apisandbox-continue-help": "Help text for the continue and clear buttons.", "booksources": "{{doc-special|BookSources}}\n\n'''This message shouldn't be changed unless it has serious mistakes.'''\n\nIt's used as the page name of the configuration page of [[Special:BookSources]]. Changing it breaks existing sites using the default version of this message.\n\nSee also:\n* {{msg-mw|Booksources|title}}\n* {{msg-mw|Booksources-text|text}}", "booksources-summary": "{{doc-specialpagesummary|booksources}}", "booksources-search-legend": "Box heading on [[Special:BookSources|book sources]] special page. The box is for searching for places where a particular book can be bought or viewed.", diff --git a/resources/Resources.php b/resources/Resources.php index 89168db6ca..377f13c002 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1858,6 +1858,9 @@ return [ 'apisandbox-results-fixtoken-fail', 'apisandbox-alert-page', 'apisandbox-alert-field', + 'apisandbox-continue', + 'apisandbox-continue-clear', + 'apisandbox-continue-help', 'blanknamespace', ], ], diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index 5c3715db02..4feaa35c08 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -10,7 +10,8 @@ suppressErrors = true, updatingBooklet = false, pages = {}, - moduleInfoCache = {}; + moduleInfoCache = {}, + baseRequestParams; WidgetMethods = { textInputWidget: { @@ -803,12 +804,15 @@ /** * Submit button handler + * + * @param {Object} [params] Use this set of params instead of those in the form fields. + * The form fields will be updated to match. */ - sendRequest: function () { + sendRequest: function ( params ) { var page, subpages, i, query, $result, $focus, progress, $progressText, progressLoading, deferreds = [], - params = {}, + paramsAreForced = !!params, displayParams = {}, checkPages = [ pages.main ]; @@ -821,6 +825,11 @@ suppressErrors = false; + // save widget state in params (or load from it if we are forced) + if ( paramsAreForced ) { + ApiSandbox.updateUI( params ); + } + params = {}; while ( checkPages.length ) { page = checkPages.shift(); deferreds.push( page.apiCheckValid() ); @@ -833,6 +842,11 @@ } } + if ( !paramsAreForced ) { + // forced params means we are continuing a query; the base query should be preserved + baseRequestParams = $.extend( {}, params ); + } + $.when.apply( $, deferreds ).done( function () { if ( $.inArray( false, arguments ) !== -1 ) { windowManager.openWindow( 'errorAlert', { @@ -940,7 +954,7 @@ ); } ) .done( function ( data, jqXHR ) { - var m, loadTime, button, + var m, loadTime, button, clear, ct = jqXHR.getResponseHeader( 'Content-Type' ); $result.empty(); @@ -962,6 +976,32 @@ .text( data ) .appendTo( $result ); } + if ( paramsAreForced || data[ 'continue' ] ) { + $result.append( + $( '
' ).append( + new OO.ui.ButtonWidget( { + label: mw.message( 'apisandbox-continue' ).text() + } ).on( 'click', function () { + ApiSandbox.sendRequest( $.extend( {}, baseRequestParams, data[ 'continue' ] ) ); + } ).setDisabled( !data[ 'continue' ] ).$element, + ( clear = new OO.ui.ButtonWidget( { + label: mw.message( 'apisandbox-continue-clear' ).text() + } ).on( 'click', function () { + ApiSandbox.updateUI( baseRequestParams ); + clear.setDisabled( true ); + booklet.setPage( '|results|' ); + } ).setDisabled( !paramsAreForced ) ).$element, + new OO.ui.PopupButtonWidget( { + framed: false, + icon: 'info', + popup: { + $content: $( '
' ).append( mw.message( 'apisandbox-continue-help' ).parse() ), + padded: true + } + } ).$element + ) + ); + } if ( typeof loadTime === 'number' ) { $result.append( $( '
' ).append( -- 2.20.1