Merge "Reduce some code duplication"
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
index a464461..cb652ac 100644 (file)
@@ -919,6 +919,11 @@ class PPFrame_Hash implements PPFrame {
         */
        var $depth;
 
+       /**
+        * @var array
+        */
+       protected $childExpansionCache;
+
        /**
         * Construct a new preprocessor frame.
         * @param Preprocessor $preprocessor The parent preprocessor
@@ -930,6 +935,7 @@ class PPFrame_Hash implements PPFrame {
                $this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
                $this->loopCheckHash = array();
                $this->depth = 0;
+               $this->childExpansionCache = array();
        }
 
        /**
@@ -972,6 +978,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
@@ -1426,6 +1444,20 @@ 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] ) ) {
+                       $this->parent->childExpansionCache[$key] = $this->expand( $root, $flags );
+               }
+               return $this->parent->childExpansionCache[$key];
+       }
+
        /**
         * Returns true if there are no arguments in this frame
         *