build: Enable jscs rules 'requireSpacesInside*Brackets' and make pass
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.jqueryMsg.js
index 343d516..bd9ad02 100644 (file)
                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 ] );
                        }
                }
 
 
                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 ) {
                 */
                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 );
                                return function () {
                                        var i, result;
                                        for ( i = 0; i < ps.length; i++ ) {
-                                               result = ps[i]();
+                                               result = ps[ i ]();
                                                if ( result !== null ) {
                                                        return result;
                                                }
                                        originalPos = pos,
                                        result = [];
                                for ( i = 0; i < ps.length; i++ ) {
-                                       res = ps[i]();
+                                       res = ps[ i ]();
                                        if ( res === null ) {
                                                pos = originalPos;
                                                return null;
                                        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( '{{' );
                                        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 + '"' );
                 * @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 );
                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 ] ] );
                },
 
                /**
                        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 === '' ) {
                 * @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 );
                },
 
                 * @return {string} Other message
                 */
                'int': function ( nodes ) {
-                       var msg = nodes[0];
+                       var msg = nodes[ 0 ];
                        return mw.jqueryMsg.getMessageFunction()( msg.charAt( 0 ).toLowerCase() + msg.slice( 1 ) );
                },
 
                 * @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 );
                }