integration with Title and Revision (work in progress)
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
index 8a51a6b..2934181 100644 (file)
@@ -24,14 +24,25 @@ class Preprocessor_Hash implements Preprocessor {
                $this->parser = $parser;
        }
 
+       /**
+        * @return PPFrame_Hash
+        */
        function newFrame() {
                return new PPFrame_Hash( $this );
        }
 
+       /**
+        * @param $args
+        * @return PPCustomFrame_Hash
+        */
        function newCustomFrame( $args ) {
                return new PPCustomFrame_Hash( $this, $args );
        }
 
+       /**
+        * @param $values array
+        * @return PPNode_Hash_Array
+        */
        function newPartNodeArray( $values ) {
                $list = array();
 
@@ -79,7 +90,7 @@ class Preprocessor_Hash implements Preprocessor {
         * cache may be implemented at a later date which takes further advantage of these strict
         * dependency requirements.
         *
-        * @private
+        * @return PPNode_Hash_Tree
         */
        function preprocessToObj( $text, $flags = 0 ) {
                wfProfileIn( __METHOD__ );
@@ -304,13 +315,11 @@ class Preprocessor_Hash implements Preprocessor {
 
                                                if ( $stack->top ) {
                                                        $part = $stack->top->getCurrentPart();
-                                                       if ( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) {
-                                                               // Comments abutting, no change in visual end
-                                                               $part->commentEnd = $wsEnd;
-                                                       } else {
+                                                       if ( ! (isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 )) {
                                                                $part->visualEnd = $wsStart;
-                                                               $part->commentEnd = $endPos;
                                                        }
+                                                       // Else comments abutting, no change in visual end
+                                                       $part->commentEnd = $endPos;
                                                }
                                                $i = $endPos + 1;
                                                $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
@@ -416,9 +425,7 @@ class Preprocessor_Hash implements Preprocessor {
                                        extract( $stack->getFlags() );
                                        $i += $count;
                                }
-                       }
-
-                       elseif ( $found == 'line-end' ) {
+                       } elseif ( $found == 'line-end' ) {
                                $piece = $stack->top;
                                // A heading must be open, otherwise \n wouldn't have been in the search list
                                assert( $piece->open == "\n" );
@@ -480,9 +487,7 @@ class Preprocessor_Hash implements Preprocessor {
                                // another heading. Infinite loops are avoided because the next iteration MUST
                                // hit the heading open case above, which unconditionally increments the
                                // input pointer.
-                       }
-
-                       elseif ( $found == 'open' ) {
+                       } elseif ( $found == 'open' ) {
                                # count opening brace characters
                                $count = strspn( $text, $curChar, $i );
 
@@ -504,9 +509,7 @@ class Preprocessor_Hash implements Preprocessor {
                                        $accum->addLiteral( str_repeat( $curChar, $count ) );
                                }
                                $i += $count;
-                       }
-
-                       elseif ( $found == 'close' ) {
+                       } elseif ( $found == 'close' ) {
                                $piece = $stack->top;
                                # lets check if there are enough characters for closing brace
                                $maxCount = $piece->count;
@@ -646,16 +649,12 @@ class Preprocessor_Hash implements Preprocessor {
                                } else {
                                        $accum->addAccum( $element );
                                }
-                       }
-
-                       elseif ( $found == 'pipe' ) {
+                       } elseif ( $found == 'pipe' ) {
                                $findEquals = true; // shortcut for getFlags()
                                $stack->addPart();
                                $accum =& $stack->getAccum();
                                ++$i;
-                       }
-
-                       elseif ( $found == 'equals' ) {
+                       } elseif ( $found == 'equals' ) {
                                $findEquals = false; // shortcut for getFlags()
                                $accum->addNodeWithText( 'equals', '=' );
                                $stack->getCurrentPart()->eqpos = $accum->lastNode;
@@ -716,6 +715,8 @@ class PPDStackElement_Hash extends PPDStackElement {
 
        /**
         * Get the accumulator that would result if the close is not found.
+        *
+        * @return PPDAccum_Hash
         */
        function breakSyntax( $openingCount = false ) {
                if ( $this->open == "\n" ) {
@@ -820,7 +821,21 @@ class PPDAccum_Hash {
  * @ingroup Parser
  */
 class PPFrame_Hash implements PPFrame {
-       var $preprocessor, $parser, $title;
+
+       /**
+        * @var Parser
+        */
+       var $parser;
+
+       /**
+        * @var Preprocessor
+        */
+       var $preprocessor;
+
+       /**
+        * @var Title
+        */
+       var $title;
        var $titleCache;
 
        /**
@@ -852,6 +867,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 $title Title|false
+        *
+        * @return PPTemplateFrame_Hash
         */
        function newChild( $args = false, $title = false ) {
                $namedArgs = array();
@@ -882,14 +902,19 @@ class PPFrame_Hash implements PPFrame {
                return new PPTemplateFrame_Hash( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
        }
 
+       /**
+        * @throws MWException
+        * @param $root
+        * @param $flags int
+        * @return string
+        */
        function expand( $root, $flags = 0 ) {
                static $expansionDepth = 0;
                if ( is_string( $root ) ) {
                        return $root;
                }
 
-               if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() )
-               {
+               if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
                        return '<span class="error">Node-count limit exceeded</span>';
                }
                if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
@@ -1018,7 +1043,7 @@ class PPFrame_Hash implements PPFrame {
                                                $serial = count( $this->parser->mHeadings ) - 1;
                                                $marker = "{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX;
                                                $s = substr( $s, 0, $bits['level'] ) . $marker . substr( $s, $bits['level'] );
-                                               $this->parser->mStripState->setGeneral( $marker, '' );
+                                               $this->parser->mStripState->addGeneral( $marker, '' );
                                                $out .= $s;
                                        } else {
                                                # Expand in virtual stack
@@ -1052,6 +1077,11 @@ class PPFrame_Hash implements PPFrame {
                return $outStack[0];
        }
 
+       /**
+        * @param $sep
+        * @param $flags
+        * @return string
+        */
        function implodeWithFlags( $sep, $flags /*, ... */ ) {
                $args = array_slice( func_get_args(), 2 );
 
@@ -1079,6 +1109,7 @@ class PPFrame_Hash implements PPFrame {
        /**
         * Implode with no flags specified
         * This previously called implodeWithFlags but has now been inlined to reduce stack depth
+        * @return string
         */
        function implode( $sep /*, ... */ ) {
                $args = array_slice( func_get_args(), 1 );
@@ -1107,6 +1138,8 @@ class PPFrame_Hash implements PPFrame {
        /**
         * Makes an object that, when expand()ed, will be the same as one obtained
         * with implode()
+        *
+        * @return PPNode_Hash_Array
         */
        function virtualImplode( $sep /*, ... */ ) {
                $args = array_slice( func_get_args(), 1 );
@@ -1134,6 +1167,8 @@ class PPFrame_Hash implements PPFrame {
 
        /**
         * Virtual implode with brackets
+        *
+        * @return PPNode_Hash_Array
         */
        function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
                $args = array_slice( func_get_args(), 3 );
@@ -1164,6 +1199,10 @@ class PPFrame_Hash implements PPFrame {
                return 'frame{}';
        }
 
+       /**
+        * @param $level bool
+        * @return array|bool|String
+        */
        function getPDBK( $level = false ) {
                if ( $level === false ) {
                        return $this->title->getPrefixedDBkey();
@@ -1172,31 +1211,50 @@ class PPFrame_Hash implements PPFrame {
                }
        }
 
+       /**
+        * @return array
+        */
        function getArguments() {
                return array();
        }
 
+       /**
+        * @return array
+        */
        function getNumberedArguments() {
                return array();
        }
 
+       /**
+        * @return array
+        */
        function getNamedArguments() {
                return array();
        }
 
        /**
         * Returns true if there are no arguments in this frame
+        *
+        * @return bool
         */
        function isEmpty() {
                return true;
        }
 
+       /**
+        * @param $name
+        * @return bool
+        */
        function getArgument( $name ) {
                return false;
        }
 
        /**
         * Returns true if the infinite loop check is OK, false if a loop is detected
+        *
+        * @param $title Title
+        *
+        * @return bool
         */
        function loopCheck( $title ) {
                return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
@@ -1204,10 +1262,21 @@ class PPFrame_Hash implements PPFrame {
 
        /**
         * Return true if the frame is a template frame
+        *
+        * @return bool
         */
        function isTemplate() {
                return false;
        }
+
+       /**
+        * Get a title of frame
+        *
+        * @return Title
+        */
+       function getTitle() {
+               return $this->title;
+       }
 }
 
 /**
@@ -1218,6 +1287,13 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
        var $numberedArgs, $namedArgs, $parent;
        var $numberedExpansionCache, $namedExpansionCache;
 
+       /**
+        * @param $preprocessor
+        * @param $parent
+        * @param $numberedArgs array
+        * @param $namedArgs array
+        * @param $title Title
+        */
        function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
                parent::__construct( $preprocessor );
 
@@ -1254,11 +1330,16 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
        }
        /**
         * Returns true if there are no arguments in this frame
+        *
+        * @return bool
         */
        function isEmpty() {
                return !count( $this->numberedArgs ) && !count( $this->namedArgs );
        }
 
+       /**
+        * @return array
+        */
        function getArguments() {
                $arguments = array();
                foreach ( array_merge(
@@ -1269,6 +1350,9 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
                return $arguments;
        }
 
+       /**
+        * @return array
+        */
        function getNumberedArguments() {
                $arguments = array();
                foreach ( array_keys($this->numberedArgs) as $key ) {
@@ -1277,6 +1361,9 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
                return $arguments;
        }
 
+       /**
+        * @return array
+        */
        function getNamedArguments() {
                $arguments = array();
                foreach ( array_keys($this->namedArgs) as $key ) {
@@ -1285,6 +1372,10 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
                return $arguments;
        }
 
+       /**
+        * @param $index
+        * @return array|bool
+        */
        function getNumberedArgument( $index ) {
                if ( !isset( $this->numberedArgs[$index] ) ) {
                        return false;
@@ -1296,6 +1387,10 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
                return $this->numberedExpansionCache[$index];
        }
 
+       /**
+        * @param $name
+        * @return bool
+        */
        function getNamedArgument( $name ) {
                if ( !isset( $this->namedArgs[$name] ) ) {
                        return false;
@@ -1308,6 +1403,10 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
                return $this->namedExpansionCache[$name];
        }
 
+       /**
+        * @param $name
+        * @return array|bool
+        */
        function getArgument( $name ) {
                $text = $this->getNumberedArgument( $name );
                if ( $text === false ) {
@@ -1318,6 +1417,8 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
 
        /**
         * Return true if the frame is a template frame
+        *
+        * @return bool
         */
        function isTemplate() {
                return true;
@@ -1352,10 +1453,17 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
                return $s;
        }
 
+       /**
+        * @return bool
+        */
        function isEmpty() {
                return !count( $this->args );
        }
 
+       /**
+        * @param $index
+        * @return bool
+        */
        function getArgument( $index ) {
                if ( !isset( $this->args[$index] ) ) {
                        return false;
@@ -1392,6 +1500,11 @@ class PPNode_Hash_Tree implements PPNode {
                }
        }
 
+       /**
+        * @param $name
+        * @param $text
+        * @return PPNode_Hash_Tree
+        */
        static function newWithText( $name, $text ) {
                $obj = new self( $name );
                $obj->addChild( new PPNode_Hash_Text( $text ) );
@@ -1407,6 +1520,9 @@ class PPNode_Hash_Tree implements PPNode {
                }
        }
 
+       /**
+        * @return PPNode_Hash_Array
+        */
        function getChildren() {
                $children = array();
                for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
@@ -1433,9 +1549,24 @@ class PPNode_Hash_Tree implements PPNode {
                return $children;
        }
 
-       function getLength() { return false; }
-       function item( $i ) { return false; }
+       /**
+        * @return bool
+        */
+       function getLength() {
+               return false;
+       }
 
+       /**
+        * @param  $i
+        * @return bool
+        */
+       function item( $i ) {
+               return false;
+       }
+
+       /**
+        * @return string
+        */
        function getName() {
                return $this->name;
        }
@@ -1445,6 +1576,8 @@ class PPNode_Hash_Tree implements PPNode {
         *    name          PPNode name
         *    index         String index
         *    value         PPNode value
+        *
+        * @return array
         */
        function splitArg() {
                $bits = array();
@@ -1476,6 +1609,8 @@ 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.
+        *
+        * @return array
         */
        function splitExt() {
                $bits = array();
@@ -1501,6 +1636,8 @@ class PPNode_Hash_Tree implements PPNode {
 
        /**
         * Split an <h> node
+        *
+        * @return array
         */
        function splitHeading() {
                if ( $this->name !== 'h' ) {
@@ -1525,6 +1662,8 @@ class PPNode_Hash_Tree implements PPNode {
 
        /**
         * Split a <template> or <tplarg> node
+        *
+        * @return array
         */
        function splitTemplate() {
                $parts = array();