From 715b6907ced1727a0f132526cc7893b2faae2e8e Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 4 May 2018 03:28:10 +0100 Subject: [PATCH] CLDRPluralRuleParser: Move from src/ to lib/ without local patch Follows-up 648667ac9f, which didn't move this module because it had a local patch for exposing via module.exports and mw.lib (instead of its default 'pluralRuleParser' global). Restore the file back to a clean copy from upstream, and perform the export via a separately concatenated file instead, using the same pattern we already use for 'oojs' and 'moment'. Change-Id: I27ee80dc34e0ad5206cf9c1ce68be3ec8811ecf8 --- resources/Resources.php | 5 +- .../CLDRPluralRuleParser.js | 52 ++++++++++++------- .../mediawiki.libs.pluralruleparser/export.js | 5 ++ 3 files changed, 41 insertions(+), 21 deletions(-) rename resources/{src/mediawiki.libs => lib/CLDRPluralRuleParser}/CLDRPluralRuleParser.js (92%) create mode 100644 resources/src/mediawiki.libs.pluralruleparser/export.js diff --git a/resources/Resources.php b/resources/Resources.php index 095ca75f10..91e5750b0a 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1627,7 +1627,10 @@ return [ ], 'mediawiki.libs.pluralruleparser' => [ - 'scripts' => 'resources/src/mediawiki.libs/CLDRPluralRuleParser.js', + 'scripts' => [ + 'resources/lib/CLDRPluralRuleParser/CLDRPluralRuleParser.js', + 'resources/src/mediawiki.libs.pluralruleparser/export.js', + ], 'targets' => [ 'desktop', 'mobile' ], ], diff --git a/resources/src/mediawiki.libs/CLDRPluralRuleParser.js b/resources/lib/CLDRPluralRuleParser/CLDRPluralRuleParser.js similarity index 92% rename from resources/src/mediawiki.libs/CLDRPluralRuleParser.js rename to resources/lib/CLDRPluralRuleParser/CLDRPluralRuleParser.js index 549a9ab3da..1491e3d70d 100644 --- a/resources/src/mediawiki.libs/CLDRPluralRuleParser.js +++ b/resources/lib/CLDRPluralRuleParser/CLDRPluralRuleParser.js @@ -1,20 +1,18 @@ -/* This is CLDRPluralRuleParser v1.1.3, ported to MediaWiki ResourceLoader */ - /** -* CLDRPluralRuleParser.js -* A parser engine for CLDR plural rules. -* -* Copyright 2012-2014 Santhosh Thottingal and other contributors -* Released under the MIT license -* http://opensource.org/licenses/MIT -* -* @source https://github.com/santhoshtr/CLDRPluralRuleParser -* @author Santhosh Thottingal -* @author Timo Tijhof -* @author Amir Aharoni -*/ - -( function ( mw ) { + * cldrpluralparser.js + * A parser engine for CLDR plural rules. + * + * Copyright 2012-2014 Santhosh Thottingal and other contributors + * Released under the MIT license + * http://opensource.org/licenses/MIT + * + * @version 0.1.0 + * @source https://github.com/santhoshtr/CLDRPluralRuleParser + * @author Santhosh Thottingal + * @author Timo Tijhof + * @author Amir Aharoni + */ + /** * Evaluates a plural rule in CLDR syntax for a number * @param {string} rule @@ -22,6 +20,22 @@ * @return {boolean} true if evaluation passed, false if evaluation failed. */ +// UMD returnExports https://github.com/umdjs/umd/blob/master/returnExports.js +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(factory); + } else if (typeof exports === 'object') { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + module.exports = factory(); + } else { + // Browser globals (root is window) + root.pluralRuleParser = factory(); + } +}(this, function() { + function pluralRuleParser(rule, number) { 'use strict'; @@ -589,8 +603,6 @@ function pluralRuleParser(rule, number) { return result; } -/* pluralRuleParser ends here */ -mw.libs.pluralRuleParser = pluralRuleParser; -module.exports = pluralRuleParser; +return pluralRuleParser; -} )( mediaWiki ); +})); diff --git a/resources/src/mediawiki.libs.pluralruleparser/export.js b/resources/src/mediawiki.libs.pluralruleparser/export.js new file mode 100644 index 0000000000..28449d3df9 --- /dev/null +++ b/resources/src/mediawiki.libs.pluralruleparser/export.js @@ -0,0 +1,5 @@ +// Expose via module.exports +module.exports = window.pluralRuleParser; + +// Back-compat: Also expose via mw.lib +mediaWiki.libs.pluralRuleParser = window.pluralRuleParser; -- 2.20.1