Merge "Add global limit to PoolCounter"
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
index a5b6b43..ad61eec 100644 (file)
  * @ingroup Parser
  */
 class Preprocessor_Hash implements Preprocessor {
-       /** @var Parser */
-       public $parser;
+       /**
+        * @var Parser
+        */
+       var $parser;
 
        const CACHE_VERSION = 1;
 
@@ -820,9 +822,7 @@ class PPDPart_Hash extends PPDPart {
  * @ingroup Parser
  */
 class PPDAccum_Hash {
-       public $firstNode;
-
-       public $lastNode;
+       var $firstNode, $lastNode;
 
        function __construct() {
                $this->firstNode = $this->lastNode = false;
@@ -890,30 +890,41 @@ class PPDAccum_Hash {
  * @ingroup Parser
  */
 class PPFrame_Hash implements PPFrame {
+
        /**
-        * @var int Recursion depth of this frame, top = 0
-        * Note that this is NOT the same as expansion depth in expand()
+        * @var Parser
+        */
+       var $parser;
+
+       /**
+        * @var Preprocessor
         */
-       public $depth;
+       var $preprocessor;
 
-       /** @var Parser */
-       protected $parser;
+       /**
+        * @var Title
+        */
+       var $title;
+       var $titleCache;
 
-       /** @var Preprocessor */
-       protected $preprocessor;
+       /**
+        * Hashtable listing templates which are disallowed for expansion in this frame,
+        * having been encountered previously in parent frames.
+        */
+       var $loopCheckHash;
 
-       /** @var Title */
-       protected $title;
+       /**
+        * Recursion depth of this frame, top = 0
+        * Note that this is NOT the same as expansion depth in expand()
+        */
+       var $depth;
 
-       /** @var array */
-       protected $titleCache;
+       private $volatile = false;
 
        /**
-        * @var array Hashtable listing templates which are disallowed for
-        *   expansion in this frame, having been encountered previously in
-        *   parent frames.
+        * @var array
         */
-       protected $loopCheckHash;
+       protected $childExpansionCache;
 
        /**
         * Construct a new preprocessor frame.
@@ -926,6 +937,7 @@ class PPFrame_Hash implements PPFrame {
                $this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
                $this->loopCheckHash = array();
                $this->depth = 0;
+               $this->childExpansionCache = array();
        }
 
        /**
@@ -968,6 +980,18 @@ class PPFrame_Hash implements PPFrame {
                return new PPTemplateFrame_Hash( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
        }
 
+       /**
+        * @throws MWException
+        * @param string|int $key
+        * @param string|PPNode_Hash|DOMDocument $root
+        * @param int $flags
+        * @return string
+        */
+       function cachedExpand( $key, $root, $flags = 0 ) {
+               // we don't have a parent, so we don't have a cache
+               return $this->expand( $root, $flags );
+       }
+
        /**
         * @throws MWException
         * @param string|PPNode$root
@@ -1368,6 +1392,24 @@ class PPFrame_Hash implements PPFrame {
        function getTitle() {
                return $this->title;
        }
+
+       /**
+        * Set the volatile flag
+        *
+        * @param bool $flag
+        */
+       function setVolatile( $flag = true ) {
+               $this->volatile = $flag;
+       }
+
+       /**
+        * Get the volatile flag
+        *
+        * @return bool
+        */
+       function isVolatile() {
+               return $this->volatile;
+       }
 }
 
 /**
@@ -1375,20 +1417,8 @@ class PPFrame_Hash implements PPFrame {
  * @ingroup Parser
  */
 class PPTemplateFrame_Hash extends PPFrame_Hash {
-       /** @var array */
-       protected $numberedArgs;
-
-       /** @var array */
-       protected $namedArgs;
-
-       /** @var bool|PPFrame */
-       protected $parent;
-
-       /** @var array */
-       protected $numberedExpansionCache;
-
-       /** @var  */
-       protected $namedExpansionCache;
+       var $numberedArgs, $namedArgs, $parent;
+       var $numberedExpansionCache, $namedExpansionCache;
 
        /**
         * @param Preprocessor $preprocessor
@@ -1434,6 +1464,24 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
                return $s;
        }
 
+       /**
+        * @throws MWException
+        * @param string|int $key
+        * @param string|PPNode_Hash|DOMDocument $root
+        * @param int $flags
+        * @return string
+        */
+       function cachedExpand( $key, $root, $flags = 0 ) {
+               if ( isset( $this->parent->childExpansionCache[$key] ) ) {
+                       return $this->parent->childExpansionCache[$key];
+               }
+               $retval = $this->expand( $root, $flags );
+               if ( !$this->isVolatile() ) {
+                       $this->parent->childExpansionCache[$key] = $retval;
+               }
+               return $retval;
+       }
+
        /**
         * Returns true if there are no arguments in this frame
         *
@@ -1532,6 +1580,11 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
        function isTemplate() {
                return true;
        }
+
+       function setVolatile( $flag = true ) {
+               parent::setVolatile( $flag );
+               $this->parent->setVolatile( $flag );
+       }
 }
 
 /**
@@ -1539,8 +1592,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
  * @ingroup Parser
  */
 class PPCustomFrame_Hash extends PPFrame_Hash {
-       /** @var array */
-       protected $args;
+       var $args;
 
        function __construct( $preprocessor, $args ) {
                parent::__construct( $preprocessor );
@@ -1590,13 +1642,7 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
  * @ingroup Parser
  */
 class PPNode_Hash_Tree implements PPNode {
-       public $name;
-
-       public $firstChild;
-
-       public $lastChild;
-
-       public $nextSibling;
+       var $name, $firstChild, $lastChild, $nextSibling;
 
        function __construct( $name ) {
                $this->name = $name;
@@ -1818,9 +1864,7 @@ class PPNode_Hash_Tree implements PPNode {
  * @ingroup Parser
  */
 class PPNode_Hash_Text implements PPNode {
-       public $value;
-
-       public $nextSibling;
+       var $value, $nextSibling;
 
        function __construct( $value ) {
                if ( is_object( $value ) ) {
@@ -1878,9 +1922,7 @@ class PPNode_Hash_Text implements PPNode {
  * @ingroup Parser
  */
 class PPNode_Hash_Array implements PPNode {
-       public $value;
-
-       public $nextSibling;
+       var $value, $nextSibling;
 
        function __construct( $value ) {
                $this->value = $value;
@@ -1935,13 +1977,7 @@ class PPNode_Hash_Array implements PPNode {
  * @ingroup Parser
  */
 class PPNode_Hash_Attr implements PPNode {
-       /** @var string */
-       public $name;
-
-       /** @var string */
-       public $value;
-
-       public $nextSibling;
+       var $name, $value, $nextSibling;
 
        function __construct( $name, $value ) {
                $this->name = $name;