From 042a3bb213b29b59aaa96b3529e25c6397df4e36 Mon Sep 17 00:00:00 2001 From: Leszek Manicki Date: Mon, 1 Aug 2016 13:33:36 +0200 Subject: [PATCH] Consider custom user language setting, and include all parameters in generated URLs User langauge setting could be overriden by adding uselang parameter to the URL. Extension should use its value if present when fetching the localized diff page. Bug: T141760 Change-Id: I2539bc7bf523870f55f67bc94000c28644528172 --- modules/ext.RevisionSlider.DiffPage.js | 40 ++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/modules/ext.RevisionSlider.DiffPage.js b/modules/ext.RevisionSlider.DiffPage.js index 112b22f2..7f230c4a 100644 --- a/modules/ext.RevisionSlider.DiffPage.js +++ b/modules/ext.RevisionSlider.DiffPage.js @@ -15,16 +15,21 @@ * @param {number} revId2 */ refresh: function ( revId1, revId2 ) { + var data = { + diff: Math.max( revId1, revId2 ), + oldid: Math.min( revId1, revId2 ) + }, + params = this.getExtraDiffPageParams(); + if ( Object.keys( params ).length > 0 ) { + $.extend( data, params ); + } $( 'table.diff[data-mw="interface"]' ) .append( $( '' ) ) .append( $( '' ) ) .append( $( '
' ).attr( 'id', 'mw-revslider-darkness' ) ); $.ajax( { url: mw.util.wikiScript( 'index' ), - data: { - diff: Math.max( revId1, revId2 ), - oldid: Math.min( revId1, revId2 ) - }, + data: data, tryCount: 0, retryLimit: 2, success: function ( data ) { @@ -114,7 +119,32 @@ * @param {number} revId2 */ getStateUrl: function ( revId1, revId2 ) { - return mw.util.wikiScript( 'index' ) + '?diff=' + Math.max( revId1, revId2 ) + '&oldid=' + Math.min( revId1, revId2 ); + var url = mw.util.wikiScript( 'index' ) + '?diff=' + Math.max( revId1, revId2 ) + '&oldid=' + Math.min( revId1, revId2 ), + params = this.getExtraDiffPageParams(); + if ( Object.keys( params ).length > 0 ) { + Object.keys( params ).forEach( function ( key ) { + url += '&' + key + '=' + params[ key ]; + } ); + } + return url; + }, + + /** + * Returns an object containing all possible parameters that should be included in diff URLs + * when selected revisions change, e.g. uselang + * + * @return {Object} + */ + getExtraDiffPageParams: function () { + var params = {}, + paramArray = location.search.substr( 1 ).split( '&' ).filter( function ( elem ) { + return elem.indexOf( '=' ) > 0 && elem.match( /^(diff|oldid)=/ ) === null; + } ); + paramArray.forEach( function ( elem ) { + var pair = elem.split( '=', 2 ); + params[ pair[ 0 ] ] = pair[ 1 ]; + } ); + return params; }, /**