Some random URL protocol forcing for protocol-relative URLs
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 907cbd0..5b79876 100644 (file)
  * @ingroup Parser
  */
 class Preprocessor_DOM implements Preprocessor {
-       var $parser, $memoryLimit;
+
+       /**
+        * @var Parser
+        */
+       var $parser;
+
+       var $memoryLimit;
 
        const CACHE_VERSION = 1;
 
@@ -27,14 +33,25 @@ class Preprocessor_DOM implements Preprocessor {
                }
        }
 
+       /**
+        * @return PPFrame_DOM
+        */
        function newFrame() {
                return new PPFrame_DOM( $this );
        }
 
+       /**
+        * @param $args
+        * @return PPCustomFrame_DOM
+        */
        function newCustomFrame( $args ) {
                return new PPCustomFrame_DOM( $this, $args );
        }
 
+       /**
+        * @param $values
+        * @return PPNode_DOM
+        */
        function newPartNodeArray( $values ) {
                //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
                $xml = "<list>";
@@ -58,6 +75,10 @@ class Preprocessor_DOM implements Preprocessor {
                return $node;
        }
 
+       /**
+        * @throws MWException
+        * @return bool
+        */
        function memCheck() {
                if ( $this->memoryLimit === false ) {
                        return;
@@ -90,14 +111,15 @@ class Preprocessor_DOM implements Preprocessor {
         * cache may be implemented at a later date which takes further advantage of these strict
         * dependency requirements.
         *
-        * @private
+        * @return PPNode_DOM
         */
        function preprocessToObj( $text, $flags = 0 ) {
                wfProfileIn( __METHOD__ );
                global $wgMemc, $wgPreprocessorCacheThreshold;
 
                $xml = false;
-               $cacheable = $wgPreprocessorCacheThreshold !== false && strlen( $text ) > $wgPreprocessorCacheThreshold;
+               $cacheable = ( $wgPreprocessorCacheThreshold !== false
+                       && strlen( $text ) > $wgPreprocessorCacheThreshold );
                if ( $cacheable ) {
                        wfProfileIn( __METHOD__.'-cacheable' );
 
@@ -147,6 +169,11 @@ class Preprocessor_DOM implements Preprocessor {
                return $obj;
        }
 
+       /**
+        * @param $text string
+        * @param $flags int
+        * @return string
+        */
        function preprocessToXml( $text, $flags = 0 ) {
                wfProfileIn( __METHOD__ );
                $rules = array(
@@ -343,11 +370,11 @@ class Preprocessor_DOM implements Preprocessor {
 
                                                if ( $stack->top ) {
                                                        $part = $stack->top->getCurrentPart();
-                                                       $part->commentEnd = $endPos;
                                                        if ( ! (isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 )) {
                                                                $part->visualEnd = $wsStart;
                                                        }
                                                        // Else comments abutting, no change in visual end
+                                                       $part->commentEnd = $endPos;
                                                }
                                                $i = $endPos + 1;
                                                $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
@@ -420,9 +447,7 @@ class Preprocessor_DOM implements Preprocessor {
                                        $accum .= '<inner>' . htmlspecialchars( $inner ) . '</inner>';
                                }
                                $accum .= $close . '</ext>';
-                       }
-
-                       elseif ( $found == 'line-start' ) {
+                       } elseif ( $found == 'line-start' ) {
                                // Is this the start of a heading?
                                // Line break belongs before the heading element in any case
                                if ( $fakeLineStart ) {
@@ -450,9 +475,7 @@ class Preprocessor_DOM implements Preprocessor {
                                        extract( $flags );
                                        $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" );
@@ -554,7 +577,7 @@ class Preprocessor_DOM implements Preprocessor {
                                        }
                                }
 
-                               if ($matchingCount <= 0) {
+                               if ( $matchingCount <= 0 ) {
                                        # No matching element found in callback array
                                        # Output a literal closing brace and continue
                                        $accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
@@ -604,7 +627,7 @@ class Preprocessor_DOM 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 );
                                        $piece->count -= $matchingCount;
                                        # do we still qualify for any callback with remaining count?
@@ -627,16 +650,12 @@ class Preprocessor_DOM implements Preprocessor {
 
                                # Add XML element to the enclosing accumulator
                                $accum .= $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()
                                $stack->getCurrentPart()->eqpos = strlen( $accum );
                                $accum .= '=';
@@ -662,7 +681,12 @@ class Preprocessor_DOM implements Preprocessor {
  * @ingroup Parser
  */
 class PPDStack {
-       var $stack, $rootAccum, $top;
+       var $stack, $rootAccum;
+
+       /**
+        * @var PPDStack
+        */
+       var $top;
        var $out;
        var $elementClass = 'PPDStackElement';
 
@@ -675,6 +699,9 @@ class PPDStack {
                $this->accum =& $this->rootAccum;
        }
 
+       /**
+        * @return int
+        */
        function count() {
                return count( $this->stack );
        }
@@ -723,6 +750,9 @@ class PPDStack {
                $this->accum =& $this->top->getAccum();
        }
 
+       /**
+        * @return array
+        */
        function getFlags() {
                if ( !count( $this->stack ) ) {
                        return array(
@@ -770,6 +800,9 @@ class PPDStackElement {
                return $this->parts[count($this->parts) - 1];
        }
 
+       /**
+        * @return array
+        */
        function getFlags() {
                $partCount = count( $this->parts );
                $findPipe = $this->open != "\n" && $this->open != '[';
@@ -782,6 +815,8 @@ class PPDStackElement {
 
        /**
         * Get the output string that would result if the close is not found.
+        *
+        * @return string
         */
        function breakSyntax( $openingCount = false ) {
                if ( $this->open == "\n" ) {
@@ -826,7 +861,21 @@ class PPDPart {
  * @ingroup Parser
  */
 class PPFrame_DOM implements PPFrame {
-       var $preprocessor, $parser, $title;
+
+       /**
+        * @var Preprocessor
+        */
+       var $preprocessor;
+
+       /**
+        * @var Parser
+        */
+       var $parser;
+
+       /**
+        * @var Title
+        */
+       var $title;
        var $titleCache;
 
        /**
@@ -844,7 +893,7 @@ class PPFrame_DOM implements PPFrame {
 
        /**
         * Construct a new preprocessor frame.
-        * @param $preprocessor Preprocessor: The parent preprocessor
+        * @param $preprocessor Preprocessor The parent preprocessor
         */
        function __construct( $preprocessor ) {
                $this->preprocessor = $preprocessor;
@@ -858,6 +907,8 @@ class PPFrame_DOM implements PPFrame {
        /**
         * Create a new child frame
         * $args is optionally a multi-root PPNode or array containing the template arguments
+        *
+        * @return PPTemplateFrame_DOM
         */
        function newChild( $args = false, $title = false ) {
                $namedArgs = array();
@@ -893,14 +944,19 @@ class PPFrame_DOM implements PPFrame {
                return new PPTemplateFrame_DOM( $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>';
                }
 
@@ -1104,6 +1160,11 @@ class PPFrame_DOM implements PPFrame {
                return $outStack[0];
        }
 
+       /**
+        * @param $sep
+        * @param $flags
+        * @return string
+        */
        function implodeWithFlags( $sep, $flags /*, ... */ ) {
                $args = array_slice( func_get_args(), 2 );
 
@@ -1129,6 +1190,8 @@ class PPFrame_DOM 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 );
@@ -1157,6 +1220,8 @@ class PPFrame_DOM implements PPFrame {
        /**
         * Makes an object that, when expand()ed, will be the same as one obtained
         * with implode()
+        *
+        * @return array
         */
        function virtualImplode( $sep /*, ... */ ) {
                $args = array_slice( func_get_args(), 1 );
@@ -1222,20 +1287,31 @@ class PPFrame_DOM 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;
@@ -1247,6 +1323,8 @@ class PPFrame_DOM implements PPFrame {
 
        /**
         * Returns true if the infinite loop check is OK, false if a loop is detected
+        *
+        * @return bool
         */
        function loopCheck( $title ) {
                return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
@@ -1254,6 +1332,8 @@ class PPFrame_DOM implements PPFrame {
 
        /**
         * Return true if the frame is a template frame
+        *
+        * @return bool
         */
        function isTemplate() {
                return false;
@@ -1265,9 +1345,21 @@ class PPFrame_DOM implements PPFrame {
  * @ingroup Parser
  */
 class PPTemplateFrame_DOM extends PPFrame_DOM {
-       var $numberedArgs, $namedArgs, $parent;
+       var $numberedArgs, $namedArgs;
+
+       /**
+        * @var PPFrame_DOM
+        */
+       var $parent;
        var $numberedExpansionCache, $namedExpansionCache;
 
+       /**
+        * @param $preprocessor
+        * @param $parent PPFrame_DOM
+        * @param $numberedArgs array
+        * @param $namedArgs array
+        * @param $title Title
+        */
        function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
                parent::__construct( $preprocessor );
 
@@ -1302,8 +1394,11 @@ class PPTemplateFrame_DOM extends PPFrame_DOM {
                $s .= '}';
                return $s;
        }
+
        /**
         * Returns true if there are no arguments in this frame
+        *
+        * @return bool
         */
        function isEmpty() {
                return !count( $this->numberedArgs ) && !count( $this->namedArgs );
@@ -1368,6 +1463,8 @@ class PPTemplateFrame_DOM extends PPFrame_DOM {
 
        /**
         * Return true if the frame is a template frame
+        *
+        * @return bool
         */
        function isTemplate() {
                return true;
@@ -1402,6 +1499,9 @@ class PPCustomFrame_DOM extends PPFrame_DOM {
                return $s;
        }
 
+       /**
+        * @return bool
+        */
        function isEmpty() {
                return !count( $this->args );
        }
@@ -1418,12 +1518,20 @@ class PPCustomFrame_DOM extends PPFrame_DOM {
  * @ingroup Parser
  */
 class PPNode_DOM implements PPNode {
-       var $node, $xpath;
+
+       /**
+        * @var DOMElement
+        */
+       var $node;
+       var $xpath;
 
        function __construct( $node, $xpath = false ) {
                $this->node = $node;
        }
 
+       /**
+        * @return DOMXPath
+        */
        function getXPath() {
                if ( $this->xpath === null ) {
                        $this->xpath = new DOMXPath( $this->node->ownerDocument );
@@ -1443,22 +1551,39 @@ class PPNode_DOM implements PPNode {
                return $s;
        }
 
+       /**
+        * @return bool|PPNode_DOM
+        */
        function getChildren() {
                return $this->node->childNodes ? new self( $this->node->childNodes ) : false;
        }
 
+       /**
+        * @return bool|PPNode_DOM
+        */
        function getFirstChild() {
                return $this->node->firstChild ? new self( $this->node->firstChild ) : false;
        }
 
+       /**
+        * @return bool|PPNode_DOM
+        */
        function getNextSibling() {
                return $this->node->nextSibling ? new self( $this->node->nextSibling ) : false;
        }
 
+       /**
+        * @param $type
+        *
+        * @return bool|PPNode_DOM
+        */
        function getChildrenOfType( $type ) {
                return new self( $this->getXPath()->query( $type, $this->node ) );
        }
 
+       /**
+        * @return int
+        */
        function getLength() {
                if ( $this->node instanceof DOMNodeList ) {
                        return $this->node->length;
@@ -1467,11 +1592,18 @@ class PPNode_DOM implements PPNode {
                }
        }
 
+       /**
+        * @param $i
+        * @return bool|PPNode_DOM
+        */
        function item( $i ) {
                $item = $this->node->item( $i );
                return $item ? new self( $item ) : false;
        }
 
+       /**
+        * @return string
+        */
        function getName() {
                if ( $this->node instanceof DOMNodeList ) {
                        return '#nodelist';
@@ -1485,6 +1617,8 @@ class PPNode_DOM implements PPNode {
         *    name          PPNode name
         *    index         String index
         *    value         PPNode value
+        *
+        * @return array
         */
        function splitArg() {
                $xpath = $this->getXPath();
@@ -1504,6 +1638,8 @@ class PPNode_DOM 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() {
                $xpath = $this->getXPath();