Merge "Fix alpha transparency in XCF images"
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
index a5b6b43..bf2bf61 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,42 @@ 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
         */
-       public $depth;
+       var $parser;
 
-       /** @var Parser */
-       protected $parser;
+       /**
+        * @var Preprocessor
+        */
+       var $preprocessor;
 
-       /** @var Preprocessor */
-       protected $preprocessor;
+       /**
+        * @var Title
+        */
+       var $title;
+       var $titleCache;
 
-       /** @var Title */
-       protected $title;
+       /**
+        * Hashtable listing templates which are disallowed for expansion in this frame,
+        * having been encountered previously in parent frames.
+        */
+       var $loopCheckHash;
+
+       /**
+        * 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;
+       private $ttl = null;
 
        /**
-        * @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 +938,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 +981,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
@@ -1113,7 +1138,23 @@ class PPFrame_Hash implements PPFrame {
                                } elseif ( $contextNode->name == 'ext' ) {
                                        # Extension tag
                                        $bits = $contextNode->splitExt() + array( 'attr' => null, 'inner' => null, 'close' => null );
-                                       $out .= $this->parser->extensionSubstitution( $bits, $this );
+                                       if ( $flags & PPFrame::NO_TAGS ) {
+                                               $s = '<' . $bits['name']->firstChild->value;
+                                               if ( $bits['attr'] ) {
+                                                       $s .= $bits['attr']->firstChild->value;
+                                               }
+                                               if ( $bits['inner'] ) {
+                                                       $s .= '>' . $bits['inner']->firstChild->value;
+                                                       if ( $bits['close'] ) {
+                                                               $s .= $bits['close']->firstChild->value;
+                                                       }
+                                               } else {
+                                                       $s .= '/>';
+                                               }
+                                               $out .= $s;
+                                       } else {
+                                               $out .= $this->parser->extensionSubstitution( $bits, $this );
+                                       }
                                } elseif ( $contextNode->name == 'h' ) {
                                        # Heading
                                        if ( $this->parser->ot['html'] ) {
@@ -1368,6 +1409,44 @@ 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;
+       }
+
+       /**
+        * 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;
+       }
 }
 
 /**
@@ -1375,20 +1454,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 +1501,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 +1617,16 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
        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 );
+       }
 }
 
 /**
@@ -1539,8 +1634,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 +1684,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 +1906,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 +1964,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 +2019,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;