From: Timo Tijhof Date: Mon, 30 Apr 2018 22:58:00 +0000 (+0100) Subject: mediawiki.jqueryMsg: Remove deprecated window.gM() method X-Git-Tag: 1.34.0-rc.0~5544 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=b0a6b192f447b9fa59c36068143536df461abb7c;p=lhc%2Fweb%2Fwiklou.git mediawiki.jqueryMsg: Remove deprecated window.gM() method * Deprecated with warnings since MediaWiki 1.23 (released 2013). * Zero results for 'gM(' in mwgrep (sitewide scripts on public WMF wikis). Bug: T135148 Change-Id: I3b97355012fc8741c7f4953f4b249d70beb96b01 --- diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index c7bec8d44b..8e5022c2e0 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -68,6 +68,8 @@ changes to languages because of Phabricator reports. * Revision::getRawUser() * Revision::getRawUserText() * Revision::getRawComment() +* window.gM() from mediawiki.jqueryMsg was removed (deprecated in 1.23). + Use mw.msg() or mw.message() instead. === Deprecations in 1.32 === * Use of a StartProfiler.php file is deprecated in favour of placing diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js b/resources/src/mediawiki/mediawiki.jqueryMsg.js index 67d6e2c5f5..d81df65ebb 100644 --- a/resources/src/mediawiki/mediawiki.jqueryMsg.js +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js @@ -186,14 +186,16 @@ }; /** - * Returns a function suitable for use as a global, to construct strings from the message key (and optional replacements). - * e.g. + * Returns a function suitable for static use, to construct strings from a message key (and optional replacements). + * + * Example: * - * window.gM = mediaWiki.jqueryMsg.getMessageFunction( options ); - * $( 'p#headline' ).html( gM( 'hello-user', username ) ); + * var format = mediaWiki.jqueryMsg.getMessageFunction( options ); + * $( '#example' ).text( format( 'hello-user', username ) ); * - * Like the old gM() function this returns only strings, so it destroys any bindings. If you want to preserve bindings use the - * jQuery plugin version instead. This is only included for backwards compatibility with gM(). + * Tthis returns only strings, so it destroys any bindings. If you want to preserve bindings, use the + * jQuery plugin version instead. This was originally created to ease migration from `window.gM()`, + * from a time when the parser used by `mw.message` was not extendable. * * N.B. replacements are variadic arguments or an array in second parameter. In other words: * somefunction( a, b, c, d ) @@ -201,7 +203,7 @@ * somefunction( a, [b, c, d] ) * * @param {Object} options parser options - * @return {Function} Function suitable for assigning to window.gM + * @return {Function} Function The message formatter * @return {string} return.key Message key. * @return {Array|Mixed} return.replacements Optional variable replacements (variadically or an array). * @return {string} return.return Rendered HTML. @@ -1341,13 +1343,6 @@ } }; - // Deprecated! don't rely on gM existing. - // The window.gM ought not to be required - or if required, not required here. - // But moving it to extensions breaks it (?!) - // Need to fix plugin so it could do attributes as well, then will be okay to remove this. - // @deprecated since 1.23 - mw.log.deprecate( window, 'gM', mw.jqueryMsg.getMessageFunction(), 'Use mw.message( ... ).parse() instead.' ); - /** * @method * @member jQuery diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js index 0653dfd3d0..71362fd0d1 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js @@ -1154,21 +1154,11 @@ } ); QUnit.test( 'Integration', function ( assert ) { - var expected, logSpy, msg; + var expected, msg; expected = 'Bold!'; mw.messages.set( 'integration-test', '[[Bold]]!' ); - this.suppressWarnings(); - logSpy = this.sandbox.spy( mw.log, 'warn' ); - assert.equal( - window.gM( 'integration-test' ), - expected, - 'Global function gM() works correctly' - ); - assert.equal( logSpy.callCount, 1, 'mw.log.warn called' ); - this.restoreWarnings(); - assert.equal( mw.message( 'integration-test' ).parse(), expected,