X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FPreprocessor_Hash.php;h=bc2b68658f1745eb662d40771a98a39a50664733;hb=5e6151b3904b4438785e16a2c4e5b2a06bede597;hp=a5b6b43e9ee5ab63cbbcf8e2ece74e7b5782aad7;hpb=3564c521a1fe45269cb4505572bb4851254c7b6e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index a5b6b43e9e..bc2b68658f 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -28,8 +28,10 @@ * @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 @@ -1368,6 +1393,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 +1438,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 +1485,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 +1601,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 +1618,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 +1668,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 +1890,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 +1948,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 +2003,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;