mediawiki.action.edit.preview.js: Use formatversion=2 for API requests
authorFomafix <fomafix@googlemail.com>
Mon, 8 Feb 2016 07:30:37 +0000 (07:30 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Mon, 8 Feb 2016 07:30:37 +0000 (07:30 +0000)
With formatversion=2 the JSON response uses UTF-8 instead of escape sequences
with hexadecimal numbers for encoding of non-ASCII characters.

The other syntax changes of formatversion=2 requires here a lot of changes.

Change-Id: Icc2ca23bfc8ab0d2ed91e5ae67ada2a14147fb87

resources/src/mediawiki.action/mediawiki.action.edit.preview.js

index 1d4d0e9..3b19b35 100644 (file)
@@ -75,6 +75,7 @@
 
                api = new mw.Api();
                postData = {
+                       formatversion: 2,
                        action: 'parse',
                        title: mw.config.get( 'wgPageName' ),
                        summary: $summary.textSelection( 'getContents' ),
@@ -89,8 +90,8 @@
                        }
 
                        diffRequest = api.post( {
+                               formatversion: 2,
                                action: 'query',
-                               indexpageids: true,
                                prop: 'revisions',
                                titles: mw.config.get( 'wgPageName' ),
                                rvdifftotext: $textbox.textSelection( 'getContents' ),
 
                        // Wait for the summary before showing the diff so the page doesn't jump twice
                        $.when( diffRequest, parseRequest ).done( function ( response ) {
-                               var diffHtml,
-                                       query = response[ 0 ].query;
+                               var diffHtml;
                                try {
-                                       diffHtml = query.pages[ query.pageids[ 0 ] ]
-                                               .revisions[ 0 ].diff[ '*' ];
+                                       diffHtml = response[ 0 ].query.pages[ 0 ]
+                                               .revisions[ 0 ].diff.body;
                                        $wikiDiff.find( 'table.diff tbody' ).html( diffHtml );
                                        mw.hook( 'wikipage.diff' ).fire( $wikiDiff.find( 'table.diff' ) );
                                } catch ( e ) {
                                }
 
                                newList = [];
-                               $.each( response.parse.indicators, function ( i, indicator ) {
+                               $.each( response.parse.indicators, function ( name, indicator ) {
                                        newList.push(
                                                $( '<div>' )
                                                        .addClass( 'mw-indicator' )
-                                                       .attr( 'id', mw.util.escapeId( 'mw-indicator-' + indicator.name ) )
-                                                       .html( indicator[ '*' ] )
+                                                       .attr( 'id', mw.util.escapeId( 'mw-indicator-' + name ) )
+                                                       .html( indicator )
                                                        .get( 0 ),
                                                // Add a whitespace between the <div>s because
                                                // they get displayed with display: inline-block
                                        );
                                }
                                if ( response.parse.categorieshtml ) {
-                                       $content = $( $.parseHTML( response.parse.categorieshtml[ '*' ] ) );
+                                       $content = $( $.parseHTML( response.parse.categorieshtml ) );
                                        mw.hook( 'wikipage.categories' ).fire( $content );
                                        $( '.catlinks[data-mw="interface"]' ).replaceWith( $content );
                                }
                                                li = $( '<li>' )
                                                        .append( $( '<a>' )
                                                                .attr( {
-                                                                       href: mw.util.getUrl( template[ '*' ] ),
-                                                                       'class': ( template.exists !== undefined ? '' : 'new' )
+                                                                       href: mw.util.getUrl( template.title ),
+                                                                       'class': ( template.exists ? '' : 'new' )
                                                                } )
-                                                               .text( template[ '*' ] )
+                                                               .text( template.title )
                                                        );
                                                newList.push( li );
                                        } );
                                        $editform.find( '.templatesUsed .mw-editfooter-list' ).detach().empty().append( newList ).appendTo( '.templatesUsed' );
                                }
                                if ( response.parse.limitreporthtml ) {
-                                       $( '.limitreport' ).html( response.parse.limitreporthtml[ '*' ] );
+                                       $( '.limitreport' ).html( response.parse.limitreporthtml );
                                }
                                if ( response.parse.langlinks && mw.config.get( 'skin' ) === 'vector' ) {
                                        newList = [];
                                                        .append( $( '<a>' )
                                                                .attr( {
                                                                        href: langlink.url,
-                                                                       title: langlink[ '*' ] + ' - ' + langlink.langname,
+                                                                       title: langlink.title + ' - ' + langlink.langname,
                                                                        lang: langlink.lang,
                                                                        hreflang: langlink.lang
                                                                } )
                                        $list.detach().empty().append( newList ).prependTo( $parent );
                                }
 
-                               if ( response.parse.text[ '*' ] ) {
+                               if ( response.parse.text ) {
                                        $content = $wikiPreview.children( '.mw-content-ltr,.mw-content-rtl' );
                                        $content
                                                .detach()
-                                               .html( response.parse.text[ '*' ] );
+                                               .html( response.parse.text );
 
                                        mw.hook( 'wikipage.content' ).fire( $content );
 
                                isSubject = ( section === 'new' ),
                                summaryMsg = isSubject ? 'subject-preview' : 'summary-preview',
                                $summaryPreview = $editform.find( '.mw-summary-preview' ).empty();
-                       if ( parse && parse.parsedsummary && parse.parsedsummary[ '*' ] !== '' ) {
+                       if ( parse && parse.parsedsummary ) {
                                $summaryPreview.append(
                                        mw.message( summaryMsg ).parse(),
                                        ' ',
                                        $( '<span>' ).addClass( 'comment' ).html(
                                                // There is no equivalent to rawParams
                                                mw.message( 'parentheses' ).escaped()
-                                                       .replace( '$1', parse.parsedsummary[ '*' ] )
+                                                       .replace( '$1', parse.parsedsummary )
                                        )
                                );
                        }