Merge "Drop zh-tw message "saveprefs""
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.jqueryMsg.js
index 66d560e..ce92423 100644 (file)
@@ -15,7 +15,7 @@
                slice = Array.prototype.slice,
                parserDefaults = {
                        magic: {
-                               'SITENAME': mw.config.get( 'wgSiteName' )
+                               SITENAME: mw.config.get( 'wgSiteName' )
                        },
                        // Whitelist for allowed HTML elements in wikitext.
                        // Self-closing tags are not currently supported.
                var i, len;
 
                if ( !$.isArray( children ) ) {
-                       children = [children];
+                       children = [ children ];
                }
 
                for ( i = 0, len = children.length; i < len; i++ ) {
-                       if ( typeof children[i] !== 'object' ) {
-                               children[i] = document.createTextNode( children[i] );
+                       if ( typeof children[ i ] !== 'object' ) {
+                               children[ i ] = document.createTextNode( children[ i ] );
                        }
                }
 
         * Try to parse a key and optional replacements, returning a jQuery object that may be a tree of jQuery nodes.
         * If there was an error parsing, return the key and the error message (wrapped in jQuery). This should put the error right into
         * the interface, without causing the page to halt script execution, and it hopefully should be clearer how to fix it.
+        *
         * @private
         * @param {Object} options Parser options
         * @return {Function}
 
                return function ( args ) {
                        var fallback,
-                               key = args[0],
-                               argsArray = $.isArray( args[1] ) ? args[1] : slice.call( args, 1 );
+                               key = args[ 0 ],
+                               argsArray = $.isArray( args[ 1 ] ) ? args[ 1 ] : slice.call( args, 1 );
                        try {
                                return parser.parse( key, argsArray );
                        } catch ( e ) {
                 * Where the magic happens.
                 * Parses a message from the key, and swaps in replacements as necessary, wraps in jQuery
                 * If an error is thrown, returns original key, and logs the error
+                *
                 * @param {string} key Message key.
                 * @param {Array} replacements Variable replacements for $1, $2... $n
                 * @return {jQuery}
                /**
                 * Fetch the message string associated with a key, return parsed structure. Memoized.
                 * Note that we pass '[' + key + ']' back for a missing message here.
+                *
                 * @param {string} key
                 * @return {string|Array} string of '[key]' if message missing, simple string if possible, array of arrays if needs parsing
                 */
                getAst: function ( key ) {
                        var wikiText,
-                               cacheKey = [key, this.settings.onlyCurlyBraceTransform].join( ':' );
+                               cacheKey = [ key, this.settings.onlyCurlyBraceTransform ].join( ':' );
 
                        if ( this.astCache[ cacheKey ] === undefined ) {
                                wikiText = this.settings.messages.get( key );
 
                        /**
                         * Try parsers until one works, if none work return null
+                        *
                         * @private
                         * @param {Function[]} ps
                         * @return {string|null}
                                return function () {
                                        var i, result;
                                        for ( i = 0; i < ps.length; i++ ) {
-                                               result = ps[i]();
+                                               result = ps[ i ]();
                                                if ( result !== null ) {
                                                        return result;
                                                }
                        /**
                         * Try several ps in a row, all must succeed or return null.
                         * This is the only eager one.
+                        *
                         * @private
                         * @param {Function[]} ps
                         * @return {string|null}
                                        originalPos = pos,
                                        result = [];
                                for ( i = 0; i < ps.length; i++ ) {
-                                       res = ps[i]();
+                                       res = ps[ i ]();
                                        if ( res === null ) {
                                                pos = originalPos;
                                                return null;
                        /**
                         * Run the same parser over and over until it fails.
                         * Must succeed a minimum of n times or return null.
+                        *
                         * @private
                         * @param {number} n
                         * @param {Function} p
 
                        /**
                         * Just make parsers out of simpler JS builtin types
+                        *
                         * @private
                         * @param {string} s
                         * @return {Function}
                                        if ( matches === null ) {
                                                return null;
                                        }
-                                       pos += matches[0].length;
-                                       return matches[0];
+                                       pos += matches[ 0 ].length;
+                                       return matches[ 0 ];
                                };
                        }
 
                                        backslash,
                                        anyCharacter
                                ] );
-                               return result === null ? null : result[1];
+                               return result === null ? null : result[ 1 ];
                        }
                        escapedOrLiteralWithoutSpace = choice( [
                                escapedLiteral,
                                if ( result === null ) {
                                        return null;
                                }
-                               return [ 'REPLACE', parseInt( result[1], 10 ) - 1 ];
+                               return [ 'REPLACE', parseInt( result[ 1 ], 10 ) - 1 ];
                        }
                        openExtlink = makeStringParser( '[' );
                        closeExtlink = makeStringParser( ']' );
                                        closeExtlink
                                ] );
                                if ( parsedResult !== null ) {
-                                       result = [ 'EXTLINK', parsedResult[1] ];
+                                       result = [ 'EXTLINK', parsedResult[ 1 ] ];
                                        // TODO (mattflaschen, 2013-03-22): Clean this up if possible.
                                        // It's avoiding CONCAT for single nodes, so they at least doesn't get the htmlEmitter span.
-                                       if ( parsedResult[3].length === 1 ) {
-                                               result.push( parsedResult[3][0] );
+                                       if ( parsedResult[ 3 ].length === 1 ) {
+                                               result.push( parsedResult[ 3 ][ 0 ] );
                                        } else {
-                                               result.push( ['CONCAT'].concat( parsedResult[3] ) );
+                                               result.push( [ 'CONCAT' ].concat( parsedResult[ 3 ] ) );
                                        }
                                }
                                return result;
                                if ( result === null ) {
                                        return null;
                                }
-                               return [ 'EXTLINKPARAM', parseInt( result[2], 10 ) - 1, result[4] ];
+                               return [ 'EXTLINKPARAM', parseInt( result[ 2 ], 10 ) - 1, result[ 4 ] ];
                        }
                        openWikilink = makeStringParser( '[[' );
                        closeWikilink = makeStringParser( ']]' );
                                        templateContents,
                                        closeTemplate
                                ] );
-                               return result === null ? null : result[1];
+                               return result === null ? null : result[ 1 ];
                        }
 
                        wikilinkPage = choice( [
                                        pipe,
                                        expression
                                ] );
-                               return result === null ? null : [ result[0], result[2] ];
+                               return result === null ? null : [ result[ 0 ], result[ 2 ] ];
                        }
 
                        wikilinkContents = choice( [
                                        closeWikilink
                                ] );
                                if ( parsedResult !== null ) {
-                                       parsedLinkContents = parsedResult[1];
+                                       parsedLinkContents = parsedResult[ 1 ];
                                        result = [ 'WIKILINK' ].concat( parsedLinkContents );
                                }
                                return result;
                                        htmlDoubleQuoteAttributeValue,
                                        doubleQuote
                                ] );
-                               return parsedResult === null ? null : parsedResult[1];
+                               return parsedResult === null ? null : parsedResult[ 1 ];
                        }
 
                        function singleQuotedHtmlAttributeValue() {
                                        htmlSingleQuoteAttributeValue,
                                        singleQuote
                                ] );
-                               return parsedResult === null ? null : parsedResult[1];
+                               return parsedResult === null ? null : parsedResult[ 1 ];
                        }
 
                        function htmlAttribute() {
                                                singleQuotedHtmlAttributeValue
                                        ] )
                                ] );
-                               return parsedResult === null ? null : [parsedResult[1], parsedResult[3]];
+                               return parsedResult === null ? null : [ parsedResult[ 1 ], parsedResult[ 3 ] ];
                        }
 
                        /**
                                }
 
                                for ( i = 0, len = attributes.length; i < len; i += 2 ) {
-                                       attributeName = attributes[i];
+                                       attributeName = attributes[ i ];
                                        if ( $.inArray( attributeName, settings.allowedHtmlCommonAttributes ) === -1 &&
-                                               $.inArray( attributeName, settings.allowedHtmlAttributesByElement[startTagName] || [] ) === -1 ) {
+                                               $.inArray( attributeName, settings.allowedHtmlAttributesByElement[ startTagName ] || [] ) === -1 ) {
                                                return false;
                                        }
                                }
                        function htmlAttributes() {
                                var parsedResult = nOrMore( 0, htmlAttribute )();
                                // Un-nest attributes array due to structure of jQueryMsg operations (see emit).
-                               return concat.apply( ['HTMLATTRIBUTES'], parsedResult );
+                               return concat.apply( [ 'HTMLATTRIBUTES' ], parsedResult );
                        }
 
                        // Subset of allowed HTML markup.
                                }
 
                                endOpenTagPos = pos;
-                               startTagName = parsedOpenTagResult[1];
+                               startTagName = parsedOpenTagResult[ 1 ];
 
                                parsedHtmlContents = nOrMore( 0, expression )();
 
                                }
 
                                endCloseTagPos = pos;
-                               endTagName = parsedCloseTagResult[1];
-                               wrappedAttributes = parsedOpenTagResult[2];
+                               endTagName = parsedCloseTagResult[ 1 ];
+                               wrappedAttributes = parsedOpenTagResult[ 2 ];
                                attributes = wrappedAttributes.slice( 1 );
                                if ( isAllowedHtml( startTagName, endTagName, attributes ) ) {
                                        result = [ 'HTMLELEMENT', startTagName, wrappedAttributes ]
                                if ( result === null ) {
                                        return null;
                                }
-                               expr = result[1];
+                               expr = result[ 1 ];
                                // use a CONCAT operator if there are multiple nodes, otherwise return the first node, raw.
-                               return expr.length > 1 ? [ 'CONCAT' ].concat( expr ) : expr[0];
+                               return expr.length > 1 ? [ 'CONCAT' ].concat( expr ) : expr[ 0 ];
                        }
 
                        function templateWithReplacement() {
                                        colon,
                                        replacement
                                ] );
-                               return result === null ? null : [ result[0], result[2] ];
+                               return result === null ? null : [ result[ 0 ], result[ 2 ] ];
                        }
                        function templateWithOutReplacement() {
                                var result = sequence( [
                                        colon,
                                        paramExpression
                                ] );
-                               return result === null ? null : [ result[0], result[2] ];
+                               return result === null ? null : [ result[ 0 ], result[ 2 ] ];
                        }
                        function templateWithOutFirstParameter() {
                                var result = sequence( [
                                        templateName,
                                        colon
                                ] );
-                               return result === null ? null : [ result[0], '' ];
+                               return result === null ? null : [ result[ 0 ], '' ];
                        }
                        colon = makeStringParser( ':' );
                        templateContents = choice( [
                                                choice( [ templateWithReplacement, templateWithOutReplacement, templateWithOutFirstParameter ] ),
                                                nOrMore( 0, templateParam )
                                        ] );
-                                       return res === null ? null : res[0].concat( res[1] );
+                                       return res === null ? null : res[ 0 ].concat( res[ 1 ] );
                                },
                                function () {
                                        var res = sequence( [
                                        if ( res === null ) {
                                                return null;
                                        }
-                                       return [ res[0] ].concat( res[1] );
+                                       return [ res[ 0 ] ].concat( res[ 1 ] );
                                }
                        ] );
                        openTemplate = makeStringParser( '{{' );
                /**
                 * (We put this method definition here, and not in prototype, to make sure it's not overwritten by any magic.)
                 * Walk entire node structure, applying replacements and template functions when appropriate
+                *
                 * @param {Mixed} node Abstract syntax tree (top node or subnode)
                 * @param {Array} replacements for $1, $2, ... $n
                 * @return {Mixed} single-string node or array of nodes suitable for jQuery appending
                                        subnodes = $.map( node.slice( 1 ), function ( n ) {
                                                return jmsg.emit( n, replacements );
                                        } );
-                                       operation = node[0].toLowerCase();
-                                       if ( typeof jmsg[operation] === 'function' ) {
+                                       operation = node[ 0 ].toLowerCase();
+                                       if ( typeof jmsg[ operation ] === 'function' ) {
                                                ret = jmsg[ operation ]( subnodes, replacements );
                                        } else {
                                                throw new Error( 'Unknown operation "' + operation + '"' );
                 * Parsing has been applied depth-first we can assume that all nodes here are single nodes
                 * Must return a single node to parents -- a jQuery with synthetic span
                 * However, unwrap any other synthetic spans in our children and pass them upwards
+                *
                 * @param {Mixed[]} nodes Some single nodes, some arrays of nodes
                 * @return {jQuery}
                 */
                 * @return {String} replacement
                 */
                replace: function ( nodes, replacements ) {
-                       var index = parseInt( nodes[0], 10 );
+                       var index = parseInt( nodes[ 0 ], 10 );
 
                        if ( index < replacements.length ) {
-                               return replacements[index];
+                               return replacements[ index ];
                        } else {
                                // index not found, fallback to displaying variable
                                return '$' + ( index + 1 );
                 * from the server, since the replacement is done at save time.
                 * It may, though, if the wikitext appears in extension-controlled content.
                 *
-                * @param nodes
+                * @param {String[]} nodes
                 */
                wikilink: function ( nodes ) {
                        var page, anchor, url;
 
-                       page = nodes[0];
+                       page = nodes[ 0 ];
                        url = mw.util.getUrl( page );
 
                        if ( nodes.length === 1 ) {
                                anchor = page;
                        } else {
                                // [[Some Page|anchor text]] or [[Namespace:Some Page|anchor]]
-                               anchor = nodes[1];
+                               anchor = nodes[ 1 ];
                        }
 
                        return $( '<a>' ).attr( {
                htmlattributes: function ( nodes ) {
                        var i, len, mapping = {};
                        for ( i = 0, len = nodes.length; i < len; i += 2 ) {
-                               mapping[nodes[i]] = decodePrimaryHtmlEntities( nodes[i + 1] );
+                               mapping[ nodes[ i ] ] = decodePrimaryHtmlEntities( nodes[ i + 1 ] );
                        }
                        return mapping;
                },
                 */
                extlink: function ( nodes ) {
                        var $el,
-                               arg = nodes[0],
-                               contents = nodes[1];
+                               arg = nodes[ 0 ],
+                               contents = nodes[ 1 ];
                        if ( arg instanceof jQuery ) {
                                $el = arg;
                        } else {
                 */
                extlinkparam: function ( nodes, replacements ) {
                        var replacement,
-                               index = parseInt( nodes[0], 10 );
+                               index = parseInt( nodes[ 0 ], 10 );
                        if ( index < replacements.length ) {
-                               replacement = replacements[index];
+                               replacement = replacements[ index ];
                        } else {
                                replacement = '$' + ( index + 1 );
                        }
-                       return this.extlink( [ replacement, nodes[1] ] );
+                       return this.extlink( [ replacement, nodes[ 1 ] ] );
                },
 
                /**
                 * Transform parsed structure into pluralization
                 * n.b. The first node may be a non-integer (for instance, a string representing an Arabic number).
                 * So convert it back with the current language's convertNumber.
+                *
                 * @param {Array} nodes List of nodes, [ {string|number}, {string}, {string} ... ]
                 * @return {string} selected pluralized form according to current language
                 */
                        var forms, firstChild, firstChildText, explicitPluralFormNumber, formIndex, form, count,
                                explicitPluralForms = {};
 
-                       count = parseFloat( this.language.convertNumber( nodes[0], true ) );
+                       count = parseFloat( this.language.convertNumber( nodes[ 0 ], true ) );
                        forms = nodes.slice( 1 );
                        for ( formIndex = 0; formIndex < forms.length; formIndex++ ) {
-                               form = forms[formIndex];
+                               form = forms[ formIndex ];
 
                                if ( form.jquery && form.hasClass( 'mediaWiki_htmlEmitter' ) ) {
                                        // This is a nested node, may be an explicit plural form like 5=[$2 linktext]
                                        if ( firstChild && firstChild.nodeType === Node.TEXT_NODE ) {
                                                firstChildText = firstChild.textContent;
                                                if ( /^\d+=/.test( firstChildText ) ) {
-                                                       explicitPluralFormNumber = parseInt( firstChildText.split( /=/ )[0], 10 );
+                                                       explicitPluralFormNumber = parseInt( firstChildText.split( /=/ )[ 0 ], 10 );
                                                        // Use the digit part as key and rest of first text node and
                                                        // rest of child nodes as value.
                                                        firstChild.textContent = firstChildText.slice( firstChildText.indexOf( '=' ) + 1 );
-                                                       explicitPluralForms[explicitPluralFormNumber] = form;
-                                                       forms[formIndex] = undefined;
+                                                       explicitPluralForms[ explicitPluralFormNumber ] = form;
+                                                       forms[ formIndex ] = undefined;
                                                }
                                        }
                                } else if ( /^\d+=/.test( form ) ) {
                                        // Simple explicit plural forms like 12=a dozen
-                                       explicitPluralFormNumber = parseInt( form.split( /=/ )[0], 10 );
-                                       explicitPluralForms[explicitPluralFormNumber] = form.slice( form.indexOf( '=' ) + 1 );
-                                       forms[formIndex] = undefined;
+                                       explicitPluralFormNumber = parseInt( form.split( /=/ )[ 0 ], 10 );
+                                       explicitPluralForms[ explicitPluralFormNumber ] = form.slice( form.indexOf( '=' ) + 1 );
+                                       forms[ formIndex ] = undefined;
                                }
                        }
 
                 */
                gender: function ( nodes ) {
                        var gender,
-                               maybeUser = nodes[0],
+                               maybeUser = nodes[ 0 ],
                                forms = nodes.slice( 1 );
 
                        if ( maybeUser === '' ) {
                /**
                 * Transform parsed structure into grammar conversion.
                 * Invoked by putting `{{grammar:form|word}}` in a message
+                *
                 * @param {Array} nodes List of nodes [{Grammar case eg: genitive}, {string word}]
                 * @return {string} selected grammatical form according to current language
                 */
                grammar: function ( nodes ) {
-                       var form = nodes[0],
-                               word = nodes[1];
+                       var form = nodes[ 0 ],
+                               word = nodes[ 1 ];
                        return word && form && this.language.convertGrammar( word, form );
                },
 
                /**
                 * Tranform parsed structure into a int: (interface language) message include
                 * Invoked by putting `{{int:othermessage}}` into a message
+                *
                 * @param {Array} nodes List of nodes
                 * @return {string} Other message
                 */
                'int': function ( nodes ) {
-                       return mw.jqueryMsg.getMessageFunction()( nodes[0].toLowerCase() );
+                       var msg = nodes[ 0 ];
+                       return mw.jqueryMsg.getMessageFunction()( msg.charAt( 0 ).toLowerCase() + msg.slice( 1 ) );
                },
 
                /**
                 * Takes an unformatted number (arab, no group separators and . as decimal separator)
                 * and outputs it in the localized digit script and formatted with decimal
                 * separator, according to the current language.
+                *
                 * @param {Array} nodes List of nodes
                 * @return {number|string} Formatted number
                 */
                formatnum: function ( nodes ) {
-                       var isInteger = ( nodes[1] && nodes[1] === 'R' ) ? true : false,
-                               number = nodes[0];
+                       var isInteger = ( nodes[ 1 ] && nodes[ 1 ] === 'R' ) ? true : false,
+                               number = nodes[ 0 ];
 
                        return this.language.convertNumber( number, isInteger );
                }
                }
 
                messageFunction = mw.jqueryMsg.getMessageFunction( {
-                       'messages': this.map,
+                       messages: this.map,
                        // For format 'escaped', escaping part is handled by mediawiki.js
-                       'format': this.format
+                       format: this.format
                } );
                return messageFunction( this.key, this.parameters );
        };