Merge "Reduce some code duplication"
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index d15b43a..4f5ebc8 100644 (file)
@@ -983,6 +983,11 @@ class PPFrame_DOM implements PPFrame {
         */
        var $depth;
 
+       /**
+        * @var array
+        */
+       protected $childExpansionCache;
+
        /**
         * Construct a new preprocessor frame.
         * @param Preprocessor $preprocessor The parent preprocessor
@@ -994,6 +999,7 @@ class PPFrame_DOM implements PPFrame {
                $this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
                $this->loopCheckHash = array();
                $this->depth = 0;
+               $this->childExpansionCache = array();
        }
 
        /**
@@ -1043,6 +1049,18 @@ class PPFrame_DOM implements PPFrame {
                return new PPTemplateFrame_DOM( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
        }
 
+       /**
+        * @throws MWException
+        * @param string|int $key
+        * @param string|PPNode_DOM|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_DOM|DOMDocument $root
@@ -1526,6 +1544,20 @@ class PPTemplateFrame_DOM extends PPFrame_DOM {
                return $s;
        }
 
+       /**
+        * @throws MWException
+        * @param string|int $key
+        * @param string|PPNode_DOM|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
         *