Gerrit Patch Uploader has uploaded a new change for review. https://gerrit.wikimedia.org/r/133162
Change subject: Show deprecation notices when accessing wg* JavaScript globals ...................................................................... Show deprecation notices when accessing wg* JavaScript globals For $wgLegacyJavaScriptGlobals = true the object mw.config.values is no longer an alias to the global object window. Does not work on Internet Explorer 8. Errors gets catched. Bug: 56550 Change-Id: I703f7c12b59bc3207b2a291eacc393a8ae92df6f --- M resources/src/mediawiki/mediawiki.js 1 file changed, 33 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/62/133162/1 diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index fc4635a..8818ea5 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -83,7 +83,13 @@ * true to map over the global object. Defaults to an empty object. */ function Map( values ) { - this.values = values === true ? window : ( values || {} ); + if ( values === true ) { + this.global = true; + this.values = {}; + } else { + this.global = false; + this.values = values || {}; + } return this; } @@ -139,16 +145,41 @@ * @return {Boolean} This returns true on success, false on failure. */ set: function ( selection, value ) { - var s; + var s, map = this; + + function setGlobal( key, value ) { + if ( map.global && Object.defineProperty ) { + try { + Object.defineProperty( window, key, { + configurable: true, + enumerable: true, + get: function () { + mw.track( 'mw.deprecate', key ); + mw.log.warn( 'Use of "' + key + '" is deprecated. Use "mw.config.get( \'' + key + '\' )" instead.' ); + return map.values[key]; + }, + set: function ( newVal ) { + mw.track( 'mw.deprecate', key ); + mw.log.warn( 'Use of "' + key + '" is deprecated. Use "mw.config.set( \'' + key + '\', \'' + newVal + '\' )" instead.' ); + map.values[key] = newVal; + } + } ); + } catch ( error ) { + // IE8 can throw on Object.defineProperty + } + } + } if ( $.isPlainObject( selection ) ) { for ( s in selection ) { this.values[s] = selection[s]; + setGlobal( s, value ); } return true; } if ( typeof selection === 'string' && arguments.length > 1 ) { this.values[selection] = value; + setGlobal( selection, value ); return true; } return false; -- To view, visit https://gerrit.wikimedia.org/r/133162 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I703f7c12b59bc3207b2a291eacc393a8ae92df6f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits