Pass real boolean or array params to mw.Api#get and #post when convenient
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 26 Aug 2015 23:07:54 +0000 (01:07 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 30 Sep 2015 13:34:30 +0000 (15:34 +0200)
We have this wonderful feature, let's use is more often!

Change-Id: I3cc48d11780c0f83df2f13acc9885bb0b4124a92

resources/src/mediawiki.action/mediawiki.action.edit.preview.js
resources/src/mediawiki.messagePoster/mediawiki.messagePoster.factory.js
resources/src/mediawiki.special/mediawiki.special.upload.js
resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
resources/src/mediawiki/api/options.js
resources/src/mediawiki/mediawiki.searchSuggest.js

index dd23e87..aeef453 100644 (file)
                        uselang: mw.config.get( 'wgUserLanguage' ),
                        title: mw.config.get( 'wgPageName' ),
                        text: $textbox.textSelection( 'getContents' ),
-                       summary: $summary.textSelection( 'getContents' )
+                       summary: $summary.textSelection( 'getContents' ),
+                       sectionpreview: section !== ''
                };
 
-               if ( section !== '' ) {
-                       postData.sectionpreview = '';
-                       if ( section === 'new' ) {
-                               postData.section = section;
-                               postData.sectiontitle = postData.summary;
-                       }
+               if ( section === 'new' ) {
+                       postData.section = 'new';
+                       postData.sectiontitle = postData.summary;
                }
 
                if ( isDiff ) {
                        $wikiPreview.hide();
 
                        // First PST the input, then diff it
-                       postData.onlypst = '';
+                       postData.onlypst = true;
                        request = api.post( postData );
                        request.done( function ( response ) {
-                               var postData;
-                               postData = {
+                               return api.post( {
                                        action: 'query',
-                                       indexpageids: '',
+                                       indexpageids: true,
                                        prop: 'revisions',
                                        titles: mw.config.get( 'wgPageName' ),
                                        rvdifftotext: response.parse.text[ '*' ],
-                                       rvprop: ''
-                               };
-                               if ( section !== '' ) {
-                                       postData.rvsection = section;
-                               }
-                               return api.post( postData ).done( function ( result2 ) {
+                                       rvprop: [],
+                                       rvsection: section === '' ? undefined : section
+                               } ).done( function ( response ) {
                                        try {
-                                               var diffHtml = result2.query.pages[ result2.query.pageids[ 0 ] ]
+                                               var diffHtml = response.query.pages[ response.query.pageids[ 0 ] ]
                                                        .revisions[ 0 ].diff[ '*' ];
                                                $wikiDiff.find( 'table.diff tbody' ).html( diffHtml );
                                        } catch ( e ) {
                } else {
                        $wikiDiff.hide();
                        $.extend( postData, {
-                               pst: '',
-                               preview: '',
+                               pst: true,
+                               preview: true,
                                prop: 'text|displaytitle|modules|jsconfigvars|categorieshtml|templates|langlinks|limitreporthtml',
                                disableeditsection: true
                        } );
index 6f9aa02..4d0231f 100644 (file)
@@ -64,7 +64,7 @@
                return this.api.get( {
                        action: 'query',
                        prop: 'info',
-                       indexpageids: 1,
+                       indexpageids: true,
                        titles: title.getPrefixedDb()
                } ).then( function ( result ) {
                        if ( result.query.pageids && result.query.pageids.length > 0 ) {
index c6ae5ac..7693340 100644 (file)
@@ -68,7 +68,7 @@
                                titles: ( new mw.Title( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(),
                                prop: 'imageinfo',
                                iiprop: 'uploadwarning',
-                               indexpageids: ''
+                               indexpageids: true
                        } ).done( function ( result ) {
                                var resultOut = '';
                                if ( result.query ) {
                                text: '{{' + license + '}}',
                                title: $( '#wpDestFile' ).val() || 'File:Sample.jpg',
                                prop: 'text',
-                               pst: ''
+                               pst: true
                        } ).done( function ( result ) {
                                $spinnerLicense.remove();
                                uploadLicense.processResult( result, license );
index 672b54a..5732aa5 100644 (file)
 
                if ( mw.Title.newFromText( query ) ) {
                        return this.interwikiPrefixesPromise.then( function () {
-                               var params, props,
+                               var params,
                                        interwiki = query.substring( 0, query.indexOf( ':' ) );
                                if (
                                        interwiki && interwiki !== '' &&
                                } else {
                                        params = {
                                                action: 'query',
+                                               prop: [ 'info', 'pageprops' ],
                                                generator: 'prefixsearch',
                                                gpssearch: query,
                                                gpsnamespace: widget.namespace !== null ? widget.namespace : undefined,
                                                gpslimit: widget.limit,
                                                ppprop: 'disambiguation'
                                        };
-                                       props = [ 'info', 'pageprops' ];
                                        if ( widget.showRedirectTargets ) {
-                                               params.redirects = '1';
+                                               params.redirects = true;
                                        }
                                        if ( widget.showImages ) {
-                                               props.push( 'pageimages' );
+                                               params.prop.push( 'pageimages' );
                                                params.pithumbsize = 80;
                                                params.pilimit = widget.limit;
                                        }
                                        if ( widget.showDescriptions ) {
-                                               props.push( 'pageterms' );
+                                               params.prop.push( 'pageterms' );
                                                params.wbptterms = 'description';
                                        }
-                                       params.prop = props.join( '|' );
                                        req = new mw.Api().get( params );
                                        promiseAbortObject.abort = req.abort.bind( req ); // todo: ew
                                        return req;
index 399e6f4..9dd276d 100644 (file)
@@ -72,7 +72,7 @@
                        if ( grouped.length ) {
                                deferreds.push( this.postWithToken( 'options', {
                                        action: 'options',
-                                       change: grouped.join( '|' )
+                                       change: grouped
                                } ) );
                        }
 
index 6c7484e..c960d65 100644 (file)
@@ -9,7 +9,7 @@
                                search: query,
                                namespace: 0,
                                limit: maxRows,
-                               suggest: ''
+                               suggest: true
                        } ).done( function ( data ) {
                                response( data[ 1 ] );
                        } );