From 906e9ddcfa2ee5ba9d85f79a27fa29990fc1eca0 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 8 Feb 2016 07:30:37 +0000 Subject: [PATCH] mediawiki.action.edit.preview.js: Use formatversion=2 for API requests 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 --- .../mediawiki.action.edit.preview.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js index 1d4d0e954c..3b19b35817 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js @@ -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' ), @@ -101,11 +102,10 @@ // 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 ) { @@ -145,12 +145,12 @@ } newList = []; - $.each( response.parse.indicators, function ( i, indicator ) { + $.each( response.parse.indicators, function ( name, indicator ) { newList.push( $( '
' ) .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
s because // they get displayed with display: inline-block @@ -174,7 +174,7 @@ ); } 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 ); } @@ -184,10 +184,10 @@ li = $( '
  • ' ) .append( $( '' ) .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 ); } ); @@ -195,7 +195,7 @@ $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 = []; @@ -205,7 +205,7 @@ .append( $( '' ) .attr( { href: langlink.url, - title: langlink[ '*' ] + ' - ' + langlink.langname, + title: langlink.title + ' - ' + langlink.langname, lang: langlink.lang, hreflang: langlink.lang } ) @@ -218,11 +218,11 @@ $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 ); @@ -238,14 +238,14 @@ 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(), ' ', $( '' ).addClass( 'comment' ).html( // There is no equivalent to rawParams mw.message( 'parentheses' ).escaped() - .replace( '$1', parse.parsedsummary[ '*' ] ) + .replace( '$1', parse.parsedsummary ) ) ); } -- 2.20.1