From dd6c05481068f8105d11d6b9be6c65c379e9cbda Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Wed, 29 Aug 2018 16:34:24 -0700 Subject: [PATCH] resources: Drop jquery.localize, deprecated in 1.32 Change-Id: Iaab8637cd336ab47c789ebcf1d0610695555095f --- RELEASE-NOTES-1.33 | 2 + resources/Resources.php | 4 - resources/src/jquery/jquery.localize.js | 180 ------------------ tests/qunit/QUnitTestResources.php | 2 - .../resources/jquery/jquery.localize.test.js | 135 ------------- 5 files changed, 2 insertions(+), 321 deletions(-) delete mode 100644 resources/src/jquery/jquery.localize.js delete mode 100644 tests/qunit/suites/resources/jquery/jquery.localize.test.js diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index 39e288d20c..ddccef5d31 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -95,6 +95,8 @@ because of Phabricator reports. the FakeAuthTemplate and LoginForm classes are removed, that FakeAuthTemplate is no longer passed into LoginSignupSpecialPage->getFieldDefinitions(), and that LoginSignupSpecialPage->getBCFieldDefinitions() is removed. +* The 'jquery.localize' module, deprecated in 1.32, has been removed. Instead, + use 'jquery.i18n'. * … === Deprecations in 1.33 === diff --git a/resources/Resources.php b/resources/Resources.php index 86315fca05..47e2b3f350 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -284,10 +284,6 @@ return [ 'dependencies' => 'mediawiki.String', 'targets' => [ 'desktop', 'mobile' ], ], - 'jquery.localize' => [ - 'scripts' => 'resources/src/jquery/jquery.localize.js', - 'deprecated' => 'Please use "jquery.i18n" instead.', - ], 'jquery.makeCollapsible' => [ 'dependencies' => [ 'jquery.makeCollapsible.styles' ], 'scripts' => 'resources/src/jquery/jquery.makeCollapsible.js', diff --git a/resources/src/jquery/jquery.localize.js b/resources/src/jquery/jquery.localize.js deleted file mode 100644 index ab269f0cff..0000000000 --- a/resources/src/jquery/jquery.localize.js +++ /dev/null @@ -1,180 +0,0 @@ -/** - * @class jQuery.plugin.localize - */ -( function () { - - /** - * Gets a localized message, using parameters from options if present. - * - * @ignore - * @param {Object} options - * @param {string} key - * @return {string} Localized message - */ - function msg( options, key ) { - var args = options.params[ key ] || []; - // Format: mw.msg( key [, p1, p2, ...] ) - args.unshift( options.prefix + ( options.keys[ key ] || key ) ); - return mw.msg.apply( mw, args ); - } - - /** - * Localizes a DOM selection by replacing elements with localized text and adding - * localized title and alt attributes to elements with title-msg and alt-msg attributes - * respectively. - * - * Call on a selection of HTML which contains `` elements or elements - * with title-msg="message-key", alt-msg="message-key" or placeholder-msg="message-key" attributes. - * `` elements will be replaced with localized text, *-msg attributes will be replaced - * with attributes that do not have the "-msg" suffix and contain a localized message. - * - * Example: - * - * // Messages: { 'title': 'Awesome', 'desc': 'Cat doing backflip' 'search' contains 'Search' } - * var html = '\ - *

\ - * \ - * \ - * \ - *

'; - * $( 'body' ).append( $( html ).localize() ); - * - * Appends something like this to the body... - * - *

- * Awesome - * Cat doing backflip - * - *

- * - * Arguments can be passed into uses of a message using the params property of the options object - * given to .localize(). Multiple messages can be given parameters, because the params property is - * an object keyed by the message key to apply the parameters to, each containing an array of - * parameters to use. The limitation is that you can not use different parameters to individual uses - * of a message in the same selection being localized - they will all recieve the same parameters. - * - * Example: - * - * // Messages: { 'easy-as': 'Easy as $1 $2 $3.' } - * var html = '

'; - * $( 'body' ).append( $( html ).localize( { 'params': { 'easy-as': ['a', 'b', 'c'] } } ) ); - * - * Appends something like this to the body... - * - *

Easy as a, b, c

- * - * Raw HTML content can be used, instead of it being escaped as text. To do this, just use the raw - * attribute on a msg element. - * - * Example: - * - * // Messages: { 'hello': 'Hello $1!' } - * var html = '\ - *

\ - * \ - * \ - *

'; - * $( 'body' ).append( $( html ).localize( { 'params': { 'hello': ['world'] } } ) ); - * - * Appends something like this to the body... - * - *

- * <b><i>Hello</i> world!</b> - * Hello world! - *

- * - * Message keys can also be remapped, allowing the same generic template to be used with a variety - * of messages. This is important for improving re-usability of templates. - * - * Example: - * - * // Messages: { 'good-afternoon': 'Good afternoon' } - * var html = '

'; - * $( 'body' ).append( $( html ).localize( { 'keys': { 'greeting': 'good-afternoon' } } ) ); - * - * Appends something like this to the body... - * - *

Good afternoon

- * - * Message keys can also be prefixed globally, which is handy when writing extensions, where by - * convention all messages are prefixed with the extension's name. - * - * Example: - * - * // Messages: { 'teleportation-warning': 'You may not get there all in one piece.' } - * var html = '

'; - * $( 'body' ).append( $( html ).localize( { 'prefix': 'teleportation-' } ) ); - * - * Appends something like this to the body... - * - *

You may not get there all in one piece.

- * - * @param {Object} options Map of options to be used while localizing - * @param {string} options.prefix String to prepend to all message keys - * @param {Object} options.keys Message key aliases, used for remapping keys to a template - * @param {Object} options.params Lists of parameters to use with certain message keys - * @return {jQuery} - * @chainable - */ - $.fn.localize = function ( options ) { - var $target = this, - attributes = [ 'title', 'alt', 'placeholder' ]; - - // Extend options - options = $.extend( { - prefix: '', - keys: {}, - params: {} - }, options ); - - // Elements - // Ok, so here's the story on this selector. In IE 6/7, searching for 'msg' turns up the - // 'html:msg', but searching for 'html:msg' doesn't. In later IE and other browsers, searching - // for 'html:msg' turns up the 'html:msg', but searching for 'msg' doesn't. So searching for - // both 'msg' and 'html:msg' seems to get the job done. This feels pretty icky, though. - $target.find( 'msg,html\\:msg' ).each( function () { - var $el = $( this ); - // Escape by default - if ( $el.attr( 'raw' ) ) { - $el.html( msg( options, $el.attr( 'key' ) ) ); - } else { - $el.text( msg( options, $el.attr( 'key' ) ) ); - } - // Remove wrapper - $el.replaceWith( $el.html() ); - } ); - - // Attributes - // Note: there's no way to prevent escaping of values being injected into attributes, this is - // on purpose, not a design flaw. - attributes.forEach( function ( attr ) { - var msgAttr = attr + '-msg'; - $target.find( '[' + msgAttr + ']' ).each( function () { - var $el = $( this ); - $el.attr( attr, msg( options, $el.attr( msgAttr ) ) ).removeAttr( msgAttr ); - } ); - } ); - - // HTML, Text for elements which cannot have children e.g. OPTION - $target.find( '[data-msg-text]' ).each( function () { - var $el = $( this ); - $el.text( msg( options, $el.attr( 'data-msg-text' ) ) ); - } ); - - $target.find( '[data-msg-html]' ).each( function () { - var $el = $( this ); - $el.html( msg( options, $el.attr( 'data-msg-html' ) ) ); - } ); - - return $target; - }; - - // Let IE know about the msg tag before it's used... - document.createElement( 'msg' ); - - /** - * @class jQuery - * @mixins jQuery.plugin.localize - */ - -}() ); diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index 6c8923d551..d6ede4f53b 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -44,7 +44,6 @@ return [ 'tests/qunit/suites/resources/jquery/jquery.hidpi.test.js', 'tests/qunit/suites/resources/jquery/jquery.highlightText.test.js', 'tests/qunit/suites/resources/jquery/jquery.lengthLimit.test.js', - 'tests/qunit/suites/resources/jquery/jquery.localize.test.js', 'tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js', 'tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js', 'tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js', @@ -105,7 +104,6 @@ return [ 'jquery.hidpi', 'jquery.highlightText', 'jquery.lengthLimit', - 'jquery.localize', 'jquery.makeCollapsible', 'jquery.tabIndex', 'jquery.tablesorter', diff --git a/tests/qunit/suites/resources/jquery/jquery.localize.test.js b/tests/qunit/suites/resources/jquery/jquery.localize.test.js deleted file mode 100644 index c88768d57e..0000000000 --- a/tests/qunit/suites/resources/jquery/jquery.localize.test.js +++ /dev/null @@ -1,135 +0,0 @@ -( function () { - QUnit.module( 'jquery.localize', QUnit.newMwEnvironment() ); - - QUnit.test( 'Handle basic replacements', function ( assert ) { - var html, $lc; - mw.messages.set( 'basic', 'Basic stuff' ); - - // Tag: html:msg - html = '
'; - $lc = $( html ).localize().find( 'span' ); - - assert.strictEqual( $lc.text(), 'Basic stuff', 'Tag: html:msg' ); - - // Attribute: title-msg - html = '
'; - $lc = $( html ).localize().find( 'span' ); - - assert.strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' ); - - // Attribute: alt-msg - html = '
'; - $lc = $( html ).localize().find( 'span' ); - - assert.strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' ); - - // Attribute: placeholder-msg - html = '
'; - $lc = $( html ).localize().find( 'input' ); - - assert.strictEqual( $lc.attr( 'placeholder' ), 'Basic stuff', 'Attribute: placeholder-msg' ); - } ); - - QUnit.test( 'Proper escaping', function ( assert ) { - var html, $lc; - mw.messages.set( 'properfoo', '' ); - - // This is handled by jQuery inside $.fn.localize, just a simple sanity checked - // making sure it is actually using text() and attr() (or something with the same effect) - - // Text escaping - html = '
'; - $lc = $( html ).localize().find( 'span' ); - - assert.strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' ); - - // Attribute escaping - html = '
'; - $lc = $( html ).localize().find( 'span' ); - - assert.strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' ); - } ); - - QUnit.test( 'Options', function ( assert ) { - var html, $lc, x, sitename = 'Wikipedia'; - mw.messages.set( { - 'foo-lorem': 'Lorem', - 'foo-ipsum': 'Ipsum', - 'foo-bar-title': 'Read more about bars', - 'foo-bar-label': 'The Bars', - 'foo-bazz-title': 'Read more about bazz at $1 (last modified: $2)', - 'foo-bazz-label': 'The Bazz ($1)', - 'foo-welcome': 'Welcome to $1! (last visit: $2)' - } ); - - // Message key prefix - html = '
'; - $lc = $( html ).localize( { - prefix: 'foo-' - } ).find( 'span' ); - - assert.strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' ); - assert.strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' ); - - // Variable keys mapping - x = 'bar'; - html = '
'; - $lc = $( html ).localize( { - keys: { - title: 'foo-' + x + '-title', - label: 'foo-' + x + '-label' - } - } ).find( 'span' ); - - assert.strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' ); - assert.strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' ); - - // Passing parameteters to mw.msg - html = '
'; - $lc = $( html ).localize( { - params: { - 'foo-welcome': [ sitename, 'yesterday' ] - } - } ).find( 'span' ); - - assert.strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' ); - - // Combination of options prefix, params and keys - x = 'bazz'; - html = '
'; - $lc = $( html ).localize( { - prefix: 'foo-', - keys: { - title: x + '-title', - label: x + '-label' - }, - params: { - title: [ sitename, '3 minutes ago' ], - label: [ sitename, '3 minutes ago' ] - - } - } ).find( 'span' ); - - assert.strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' ); - assert.strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' ); - } ); - - QUnit.test( 'Handle data text', function ( assert ) { - var html, $lc; - mw.messages.set( 'option-one', 'Item 1' ); - mw.messages.set( 'option-two', 'Item 2' ); - html = ''; - $lc = $( html ).localize().find( 'option' ); - assert.strictEqual( $lc.eq( 0 ).text(), mw.msg( 'option-one' ), 'data-msg-text becomes text of options' ); - assert.strictEqual( $lc.eq( 1 ).text(), mw.msg( 'option-two' ), 'data-msg-text becomes text of options' ); - } ); - - QUnit.test( 'Handle data html', function ( assert ) { - var html, $lc; - mw.messages.set( 'html', 'behold... there is a link here!!' ); - html = '
'; - $lc = $( html ).localize().find( 'a' ); - assert.strictEqual( $lc.length, 1, 'link is created' ); - assert.strictEqual( $lc.text(), 'link', 'the link text got added' ); - } ); -}() ); -- 2.20.1