fix some spacing
[lhc/web/wiklou.git] / includes / parser / Preprocessor_HipHop.hphp
index d7b0716..bd5e1a7 100644 (file)
@@ -51,7 +51,7 @@ class Preprocessor_HipHop implements Preprocessor {
         * @param $args array
         * @return PPCustomFrame_HipHop
         */
-       function newCustomFrame( array $args ) {
+       function newCustomFrame( $args ) {
                return new PPCustomFrame_HipHop( $this, $args );
        }
 
@@ -109,17 +109,19 @@ class Preprocessor_HipHop implements Preprocessor {
         * @throws MWException
         * @return PPNode_HipHop_Tree
         */
-       function preprocessToObj( string $text, int $flags = 0 ) {
+       function preprocessToObj( $text, $flags = 0 ) {
                wfProfileIn( __METHOD__ );
 
                // Check cache.
                global $wgMemc, $wgPreprocessorCacheThreshold;
 
-               $cacheable = ($wgPreprocessorCacheThreshold !== false && strlen( $text ) > $wgPreprocessorCacheThreshold);
+               $lengthText = strlen( $text );
+
+               $cacheable = ($wgPreprocessorCacheThreshold !== false && $lengthText > $wgPreprocessorCacheThreshold);
                if ( $cacheable ) {
                        wfProfileIn( __METHOD__.'-cacheable' );
 
-                       $cacheKey = strval( wfMemcKey( 'preprocess-hash', md5($text), $flags ) );
+                       $cacheKey = strval( wfMemcKey( 'preprocess-hash', md5( $text ), $flags ) );
                        $cacheValue = strval( $wgMemc->get( $cacheKey ) );
                        if ( $cacheValue !== '' ) {
                                $version = substr( $cacheValue, 0, 8 );
@@ -239,7 +241,7 @@ class Preprocessor_HipHop implements Preprocessor {
                                        $accum->addLiteral( strval( substr( $text, $i, $literalLength ) ) );
                                        $i += $literalLength;
                                }
-                               if ( $i >= strlen( $text ) ) {
+                               if ( $i >= $lengthText ) {
                                        if ( $currentClosing === "\n" ) {
                                                // Do a past-the-end run to finish off the heading
                                                $curChar = '';
@@ -305,12 +307,12 @@ class Preprocessor_HipHop implements Preprocessor {
                                                // Unclosed comment in input, runs to end
                                                $inner = strval( substr( $text, $i ) );
                                                $accum->addNodeWithText( 'comment', $inner );
-                                               $i = strlen( $text );
+                                               $i = $lengthText;
                                        } else {
                                                $endPos = intval( $variantEndPos );
                                                // Search backwards for leading whitespace
                                                if ( $i ) {
-                                                       $wsStart = $i - intval( strspn( $revText, ' ', strlen( $text ) - $i ) );
+                                                       $wsStart = $i - intval( strspn( $revText, ' ', $lengthText - $i ) );
                                                } else {
                                                        $wsStart = 0;
                                                }
@@ -345,7 +347,7 @@ class Preprocessor_HipHop implements Preprocessor {
 
                                                if ( $stack->top ) {
                                                        $part = $stack->getTop()->getCurrentPart();
-                                                       if ( ! (isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 )) {
+                                                       if ( !(isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 )) {
                                                                $part->visualEnd = $wsStart;
                                                        }
                                                        // Else comments abutting, no change in visual end
@@ -403,13 +405,13 @@ class Preprocessor_HipHop implements Preprocessor {
                                        } else {
                                                // No end tag -- let it run out to the end of the text.
                                                $inner = strval( substr( $text, $tagEndPos + 1 ) );
-                                               $i = strlen( $text );
+                                               $i = $lengthText;
                                                $haveClose = false;
                                        }
                                }
                                // <includeonly> and <noinclude> just become <ignore> tags
                                if ( in_array( $lowerName, $ignoredElements ) ) {
-                                       $accum->addNodeWithText(  'ignore', strval( substr( $text, $tagStartPos, $i - $tagStartPos ) ) );
+                                       $accum->addNodeWithText( 'ignore', strval( substr( $text, $tagStartPos, $i - $tagStartPos ) ) );
                                        continue;
                                }
 
@@ -468,16 +470,16 @@ class Preprocessor_HipHop implements Preprocessor {
                                $part = $piece->getCurrentPart();
                                // Search back through the input to see if it has a proper close
                                // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient
-                               $wsLength = intval( strspn( $revText, " \t", strlen( $text ) - $i ) );
+                               $wsLength = intval( strspn( $revText, " \t", $lengthText - $i ) );
                                $searchStart = $i - $wsLength;
                                if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
                                        // Comment found at line end
                                        // Search for equals signs before the comment
                                        $searchStart = intval( $part->visualEnd );
-                                       $searchStart -= intval( strspn( $revText, " \t", strlen( $text ) - $searchStart ) );
+                                       $searchStart -= intval( strspn( $revText, " \t", $lengthText - $searchStart ) );
                                }
                                $count = intval( $piece->count );
-                               $equalsLength = intval( strspn( $revText, '=', strlen( $text ) - $searchStart ) );
+                               $equalsLength = intval( strspn( $revText, '=', $lengthText - $searchStart ) );
                                $isTreeNode = false;
                                $resultAccum = $accum;
                                if ( $equalsLength > 0 ) {
@@ -576,7 +578,7 @@ class Preprocessor_HipHop implements Preprocessor {
                                        }
                                }
 
-                               if ($matchingCount <= 0) {
+                               if ( $matchingCount <= 0 ) {
                                        # No matching element found in callback array
                                        # Output a literal closing brace and continue
                                        $accum->addLiteral( str_repeat( $curChar, $count ) );
@@ -669,7 +671,7 @@ class Preprocessor_HipHop implements Preprocessor {
                                $accum = $stack->getAccum();
 
                                # Re-add the old stack element if it still has unmatched opening characters remaining
-                               if ($matchingCount < $piece->count) {
+                               if ( $matchingCount < $piece->count ) {
                                        $piece->parts = array( new PPDPart_HipHop );
                                        $piece->count -= $matchingCount;
                                        # do we still qualify for any callback with remaining count?
@@ -727,7 +729,7 @@ class Preprocessor_HipHop implements Preprocessor {
                $rootNode->lastChild = $stack->rootAccum->lastNode;
 
                // Cache
-               if ($cacheable) {
+               if ( $cacheable ) {
                        $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . serialize( $rootNode );
                        $wgMemc->set( $cacheKey, $cacheValue, 86400 );
                        wfProfileOut( __METHOD__.'-cache-miss' );
@@ -863,7 +865,7 @@ class PPDStackElement_HipHop {
         * @return PPDAccum_HipHop
         */
        function getAccum() {
-               return PPDAccum_HipHop::cast( $this->parts[count($this->parts) - 1]->out );
+               return PPDAccum_HipHop::cast( $this->parts[count( $this->parts ) - 1]->out );
        }
 
        /**
@@ -877,7 +879,7 @@ class PPDStackElement_HipHop {
         * @return PPDPart_HipHop
         */
        function getCurrentPart() {
-               return PPDPart_HipHop::cast( $this->parts[count($this->parts) - 1] );
+               return PPDPart_HipHop::cast( $this->parts[count( $this->parts ) - 1] );
        }
 
        /**
@@ -1064,11 +1066,12 @@ class PPFrame_HipHop implements PPFrame {
         *
         * @param $args PPNode_HipHop_Array|array|bool
         * @param $title Title|bool
+        * @param $indexOffset A number subtracted from the index attributes of the arguments
         *
         * @throws MWException
         * @return PPTemplateFrame_HipHop
         */
-       function newChild( $args = false, $title = false ) {
+       function newChild( $args = false, $title = false, $indexOffset = 0 ) {
                $namedArgs = array();
                $numberedArgs = array();
                if ( $title === false ) {
@@ -1213,7 +1216,7 @@ class PPFrame_HipHop implements PPFrame {
                                        }
                                        # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
                                        # Not in RECOVER_COMMENTS mode (extractSections) though
-                                       elseif ( $this->parser->ot['wiki'] && ! ( $flags & PPFrame::RECOVER_COMMENTS ) ) {
+                                       elseif ( $this->parser->ot['wiki'] && !( $flags & PPFrame::RECOVER_COMMENTS ) ) {
                                                $out .= $this->parser->insertStripItem( $contextNode->firstChild->value );
                                        }
                                        # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
@@ -1566,8 +1569,8 @@ class PPTemplateFrame_HipHop extends PPFrame_HipHop {
         */
        function getNumberedArguments() {
                $arguments = array();
-               foreach ( array_keys($this->numberedArgs) as $key ) {
-                       $arguments[$key] = $this->getArgument($key);
+               foreach ( array_keys( $this->numberedArgs ) as $key ) {
+                       $arguments[$key] = $this->getArgument( $key );
                }
                return $arguments;
        }
@@ -1577,8 +1580,8 @@ class PPTemplateFrame_HipHop extends PPFrame_HipHop {
         */
        function getNamedArguments() {
                $arguments = array();
-               foreach ( array_keys($this->namedArgs) as $key ) {
-                       $arguments[$key] = $this->getArgument($key);
+               foreach ( array_keys( $this->namedArgs ) as $key ) {
+                       $arguments[$key] = $this->getArgument( $key );
                }
                return $arguments;
        }
@@ -1758,7 +1761,7 @@ class PPNode_HipHop_Tree implements PPNode {
                $children = array();
                for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
                        if ( isset( $child->name ) && $child->name === $name ) {
-                               $children[] = $name;
+                               $children[] = $child;
                        }
                }
                return $children;
@@ -1881,6 +1884,7 @@ class PPNode_HipHop_Tree implements PPNode {
        /**
         * Split a <template> or <tplarg> node
         *
+        * @throws MWException
         * @return array
         */
        function splitTemplate() {