Add a continuation button to ApiSandbox
authorGergő Tisza <gtisza@wikimedia.org>
Fri, 23 Sep 2016 01:50:05 +0000 (01:50 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Wed, 5 Oct 2016 08:52:35 +0000 (08:52 +0000)
Change-Id: I4def43b2000b5639e3ced2643afea4b1288e28b0

includes/api/ApiFormatBase.php
languages/i18n/en.json
languages/i18n/qqq.json
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.apisandbox.js

index c826bba..4df7f51 100644 (file)
@@ -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
index 67e6491..7216fc7 100644 (file)
        "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",
index 163b613..b055ed9 100644 (file)
        "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.",
index 89168db..377f13c 100644 (file)
@@ -1858,6 +1858,9 @@ return [
                        'apisandbox-results-fixtoken-fail',
                        'apisandbox-alert-page',
                        'apisandbox-alert-field',
+                       'apisandbox-continue',
+                       'apisandbox-continue-clear',
+                       'apisandbox-continue-help',
                        'blanknamespace',
                ],
        ],
index 5c3715d..4feaa35 100644 (file)
@@ -10,7 +10,8 @@
                suppressErrors = true,
                updatingBooklet = false,
                pages = {},
-               moduleInfoCache = {};
+               moduleInfoCache = {},
+               baseRequestParams;
 
        WidgetMethods = {
                textInputWidget: {
 
                /**
                 * 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 ];
 
 
                        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() );
                                }
                        }
 
+                       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', {
                                                        );
                                        } )
                                        .done( function ( data, jqXHR ) {
-                                               var m, loadTime, button,
+                                               var m, loadTime, button, clear,
                                                        ct = jqXHR.getResponseHeader( 'Content-Type' );
 
                                                $result.empty();
                                                                .text( data )
                                                                .appendTo( $result );
                                                }
+                                               if ( paramsAreForced || data[ 'continue' ] ) {
+                                                       $result.append(
+                                                               $( '<div>' ).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: $( '<div>' ).append( mw.message( 'apisandbox-continue-help' ).parse() ),
+                                                                                       padded: true
+                                                                               }
+                                                                       } ).$element
+                                                               )
+                                                       );
+                                               }
                                                if ( typeof loadTime === 'number' ) {
                                                        $result.append(
                                                                $( '<div>' ).append(