Remove Preprocessor_HipHop
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
index 0e202fd..c22da64 100644 (file)
@@ -105,6 +105,7 @@ class Preprocessor_Hash implements Preprocessor {
         * cache may be implemented at a later date which takes further advantage of these strict
         * dependency requirements.
         *
+        * @throws MWException
         * @return PPNode_Hash_Tree
         */
        function preprocessToObj( $text, $flags = 0 ) {
@@ -115,9 +116,9 @@ class Preprocessor_Hash implements Preprocessor {
 
                $cacheable = $wgPreprocessorCacheThreshold !== false && strlen( $text ) > $wgPreprocessorCacheThreshold;
                if ( $cacheable ) {
-                       wfProfileIn( __METHOD__.'-cacheable' );
+                       wfProfileIn( __METHOD__ . '-cacheable' );
 
-                       $cacheKey = wfMemcKey( 'preprocess-hash', md5($text), $flags );
+                       $cacheKey = wfMemcKey( 'preprocess-hash', md5( $text ), $flags );
                        $cacheValue = $wgMemc->get( $cacheKey );
                        if ( $cacheValue ) {
                                $version = substr( $cacheValue, 0, 8 );
@@ -126,12 +127,12 @@ class Preprocessor_Hash implements Preprocessor {
                                        // From the cache
                                        wfDebugLog( "Preprocessor",
                                                "Loaded preprocessor hash from memcached (key $cacheKey)" );
-                                       wfProfileOut( __METHOD__.'-cacheable' );
+                                       wfProfileOut( __METHOD__ . '-cacheable' );
                                        wfProfileOut( __METHOD__ );
                                        return $hash;
                                }
                        }
-                       wfProfileIn( __METHOD__.'-cache-miss' );
+                       wfProfileIn( __METHOD__ . '-cache-miss' );
                }
 
                $rules = array(
@@ -177,6 +178,7 @@ class Preprocessor_Hash implements Preprocessor {
 
                $searchBase = "[{<\n";
                $revText = strrev( $text ); // For fast reverse searches
+               $lengthText = strlen( $text );
 
                $i = 0;                     # Input pointer, starts out pointing to a pseudo-newline before the start
                $accum =& $stack->getAccum();   # Current accumulator
@@ -231,7 +233,7 @@ class Preprocessor_Hash implements Preprocessor {
                                        $accum->addLiteral( 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 = '';
@@ -295,10 +297,10 @@ class Preprocessor_Hash implements Preprocessor {
                                                // Unclosed comment in input, runs to end
                                                $inner = substr( $text, $i );
                                                $accum->addNodeWithText( 'comment', $inner );
-                                               $i = strlen( $text );
+                                               $i = $lengthText;
                                        } else {
                                                // Search backwards for leading whitespace
-                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0;
+                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0;
                                                // Search forwards for trailing whitespace
                                                // $wsEnd will be the position of the last space (or the '>' if there's none)
                                                $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 );
@@ -330,7 +332,7 @@ class Preprocessor_Hash implements Preprocessor {
 
                                                if ( $stack->top ) {
                                                        $part = $stack->top->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
@@ -383,13 +385,13 @@ class Preprocessor_Hash implements Preprocessor {
                                        } else {
                                                // No end tag -- let it run out to the end of the text.
                                                $inner = substr( $text, $tagEndPos + 1 );
-                                               $i = strlen( $text );
+                                               $i = $lengthText;
                                                $close = null;
                                        }
                                }
                                // <includeonly> and <noinclude> just become <ignore> tags
                                if ( in_array( $lowerName, $ignoredElements ) ) {
-                                       $accum->addNodeWithText(  'ignore', substr( $text, $tagStartPos, $i - $tagStartPos ) );
+                                       $accum->addNodeWithText( 'ignore', substr( $text, $tagStartPos, $i - $tagStartPos ) );
                                        continue;
                                }
 
@@ -447,16 +449,16 @@ class Preprocessor_Hash 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 = strspn( $revText, " \t", strlen( $text ) - $i );
+                               $wsLength = 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 = $part->visualEnd;
-                                       $searchStart -= strspn( $revText, " \t", strlen( $text ) - $searchStart );
+                                       $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart );
                                }
                                $count = $piece->count;
-                               $equalsLength = strspn( $revText, '=', strlen( $text ) - $searchStart );
+                               $equalsLength = strspn( $revText, '=', $lengthText - $searchStart );
                                if ( $equalsLength > 0 ) {
                                        if ( $searchStart - $equalsLength == $piece->startPos ) {
                                                // This is just a single string of equals signs on its own line
@@ -547,7 +549,7 @@ class Preprocessor_Hash 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 ) );
@@ -589,10 +591,10 @@ class Preprocessor_Hash implements Preprocessor {
                                                                $lastNode = $node;
                                                        }
                                                        if ( !$node ) {
-                                                               throw new MWException( __METHOD__. ': eqpos not found' );
+                                                               throw new MWException( __METHOD__ . ': eqpos not found' );
                                                        }
                                                        if ( $node->name !== 'equals' ) {
-                                                               throw new MWException( __METHOD__ .': eqpos is not equals' );
+                                                               throw new MWException( __METHOD__ . ': eqpos is not equals' );
                                                        }
                                                        $equalsNode = $node;
 
@@ -637,23 +639,17 @@ class Preprocessor_Hash 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_Hash );
                                        $piece->count -= $matchingCount;
                                        # do we still qualify for any callback with remaining count?
-                                       $names = $rules[$piece->open]['names'];
-                                       $skippedBraces = 0;
-                                       $enclosingAccum =& $accum;
-                                       while ( $piece->count ) {
-                                               if ( array_key_exists( $piece->count, $names ) ) {
-                                                       $stack->push( $piece );
-                                                       $accum =& $stack->getAccum();
-                                                       break;
-                                               }
-                                               --$piece->count;
-                                               $skippedBraces ++;
+                                       $min = $rules[$piece->open]['min'];
+                                       if ( $piece->count >= $min ) {
+                                               $stack->push( $piece );
+                                               $accum =& $stack->getAccum();
+                                       } else {
+                                               $accum->addLiteral( str_repeat( $piece->open, $piece->count ) );
                                        }
-                                       $enclosingAccum->addLiteral( str_repeat( $piece->open, $skippedBraces ) );
                                }
 
                                extract( $stack->getFlags() );
@@ -694,11 +690,11 @@ class Preprocessor_Hash 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' );
-                       wfProfileOut( __METHOD__.'-cacheable' );
+                       wfProfileOut( __METHOD__ . '-cache-miss' );
+                       wfProfileOut( __METHOD__ . '-cacheable' );
                        wfDebugLog( "Preprocessor", "Saved preprocessor Hash to memcached (key $cacheKey)" );
                }
 
@@ -883,9 +879,11 @@ class PPFrame_Hash implements PPFrame {
         * Create a new child frame
         * $args is optionally a multi-root PPNode or array containing the template arguments
         *
-        * @param $args PPNode_Hash_Array|array
+        * @param array|bool|\PPNode_Hash_Array $args PPNode_Hash_Array|array
         * @param $title Title|bool
         *
+        * @param int $indexOffset
+        * @throws MWException
         * @return PPTemplateFrame_Hash
         */
        function newChild( $args = false, $title = false, $indexOffset = 0 ) {
@@ -1034,7 +1032,7 @@ class PPFrame_Hash 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
@@ -1081,7 +1079,7 @@ class PPFrame_Hash implements PPFrame {
                                        $newIterator = $contextNode->getChildren();
                                }
                        } else {
-                               throw new MWException( __METHOD__.': Invalid parameter type' );
+                               throw new MWException( __METHOD__ . ': Invalid parameter type' );
                        }
 
                        if ( $newIterator !== false ) {
@@ -1370,9 +1368,9 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
        function getArguments() {
                $arguments = array();
                foreach ( array_merge(
-                               array_keys($this->numberedArgs),
-                               array_keys($this->namedArgs)) as $key ) {
-                       $arguments[$key] = $this->getArgument($key);
+                               array_keys( $this->numberedArgs ),
+                               array_keys( $this->namedArgs ) ) as $key ) {
+                       $arguments[$key] = $this->getArgument( $key );
                }
                return $arguments;
        }
@@ -1382,8 +1380,8 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
         */
        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;
        }
@@ -1393,8 +1391,8 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
         */
        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;
        }
@@ -1574,7 +1572,7 @@ class PPNode_Hash_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;
@@ -1608,6 +1606,7 @@ class PPNode_Hash_Tree implements PPNode {
         *  - index         String index
         *  - value         PPNode value
         *
+        * @throws MWException
         * @return array
         */
        function splitArg() {
@@ -1641,6 +1640,7 @@ class PPNode_Hash_Tree implements PPNode {
         * Split an "<ext>" node into an associative array containing name, attr, inner and close
         * All values in the resulting array are PPNodes. Inner and close are optional.
         *
+        * @throws MWException
         * @return array
         */
        function splitExt() {
@@ -1668,6 +1668,7 @@ class PPNode_Hash_Tree implements PPNode {
        /**
         * Split an "<h>" node
         *
+        * @throws MWException
         * @return array
         */
        function splitHeading() {
@@ -1694,6 +1695,7 @@ class PPNode_Hash_Tree implements PPNode {
        /**
         * Split a "<template>" or "<tplarg>" node
         *
+        * @throws MWException
         * @return array
         */
        function splitTemplate() {