Remove ParserOptions::setSkin() (deprecated since 1.19)
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 0d12205..f5fc3ec 100644 (file)
@@ -91,7 +91,8 @@ class Preprocessor_DOM implements Preprocessor {
                if ( !$result ) {
                        // Try running the XML through UtfNormal to get rid of invalid characters
                        $xml = UtfNormal::cleanUp( $xml );
-                       // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep
+                       // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2
+                       // don't barf when the XML is >256 levels deep
                        $result = $dom->loadXML( $xml, 1 << 19 );
                }
                wfProfileOut( __METHOD__ . '-loadXML' );
@@ -982,6 +983,14 @@ class PPFrame_DOM implements PPFrame {
         */
        var $depth;
 
+       private $volatile = false;
+       private $ttl = null;
+
+       /**
+        * @var array
+        */
+       protected $childExpansionCache;
+
        /**
         * Construct a new preprocessor frame.
         * @param Preprocessor $preprocessor The parent preprocessor
@@ -993,6 +1002,7 @@ class PPFrame_DOM implements PPFrame {
                $this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
                $this->loopCheckHash = array();
                $this->depth = 0;
+               $this->childExpansionCache = array();
        }
 
        /**
@@ -1042,6 +1052,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
@@ -1212,13 +1234,29 @@ class PPFrame_DOM implements PPFrame {
                                        $attrs = $xpath->query( 'attr', $contextNode );
                                        $inners = $xpath->query( 'inner', $contextNode );
                                        $closes = $xpath->query( 'close', $contextNode );
-                                       $params = array(
-                                               'name' => new PPNode_DOM( $names->item( 0 ) ),
-                                               'attr' => $attrs->length > 0 ? new PPNode_DOM( $attrs->item( 0 ) ) : null,
-                                               'inner' => $inners->length > 0 ? new PPNode_DOM( $inners->item( 0 ) ) : null,
-                                               'close' => $closes->length > 0 ? new PPNode_DOM( $closes->item( 0 ) ) : null,
-                                       );
-                                       $out .= $this->parser->extensionSubstitution( $params, $this );
+                                       if ( $flags & PPFrame::NO_TAGS ) {
+                                               $s = '<' . $this->expand( $names->item( 0 ), $flags );
+                                               if ( $attrs->length > 0 ) {
+                                                       $s .= $this->expand( $attrs->item( 0 ), $flags );
+                                               }
+                                               if ( $inners->length > 0 ) {
+                                                       $s .= '>' . $this->expand( $inners->item( 0 ), $flags );
+                                                       if ( $closes->length > 0 ) {
+                                                               $s .= $this->expand( $closes->item( 0 ), $flags );
+                                                       }
+                                               } else {
+                                                       $s .= '/>';
+                                               }
+                                               $out .= $s;
+                                       } else {
+                                               $params = array(
+                                                       'name' => new PPNode_DOM( $names->item( 0 ) ),
+                                                       'attr' => $attrs->length > 0 ? new PPNode_DOM( $attrs->item( 0 ) ) : null,
+                                                       'inner' => $inners->length > 0 ? new PPNode_DOM( $inners->item( 0 ) ) : null,
+                                                       'close' => $closes->length > 0 ? new PPNode_DOM( $closes->item( 0 ) ) : null,
+                                               );
+                                               $out .= $this->parser->extensionSubstitution( $params, $this );
+                                       }
                                } elseif ( $contextNode->nodeName == 'h' ) {
                                        # Heading
                                        $s = $this->expand( $contextNode->childNodes, $flags );
@@ -1466,6 +1504,44 @@ class PPFrame_DOM 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;
+       }
+
+       /**
+        * Set the TTL
+        *
+        * @param int $ttl
+        */
+       function setTTL( $ttl ) {
+               if ( $ttl !== null && ( $this->ttl === null || $ttl < $this->ttl ) ) {
+                       $this->ttl = $ttl;
+               }
+       }
+
+       /**
+        * Get the TTL
+        *
+        * @return int|null
+        */
+       function getTTL() {
+               return $this->ttl;
+       }
 }
 
 /**
@@ -1525,6 +1601,24 @@ 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] ) ) {
+                       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
         *
@@ -1602,6 +1696,16 @@ class PPTemplateFrame_DOM extends PPFrame_DOM {
        function isTemplate() {
                return true;
        }
+
+       function setVolatile( $flag = true ) {
+               parent::setVolatile( $flag );
+               $this->parent->setVolatile( $flag );
+       }
+
+       function setTTL( $ttl ) {
+               parent::setTTL( $ttl );
+               $this->parent->setTTL( $ttl );
+       }
 }
 
 /**