* @ingroup Parser
*/
class Preprocessor_Hash implements Preprocessor {
- /** @var Parser */
- public $parser;
+ /**
+ * @var Parser
+ */
+ var $parser;
const CACHE_VERSION = 1;
* @ingroup Parser
*/
class PPDAccum_Hash {
- public $firstNode;
-
- public $lastNode;
+ var $firstNode, $lastNode;
function __construct() {
$this->firstNode = $this->lastNode = false;
* Append a PPDAccum_Hash
* Takes over ownership of the nodes in the source argument. These nodes may
* subsequently be modified, especially nextSibling.
- * @param PPAccum_Hash $accum
+ * @param PPDAccum_Hash $accum
*/
function addAccum( $accum ) {
if ( $accum->lastNode === false ) {
* @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
+ */
+ var $parser;
+
+ /**
+ * @var Preprocessor
*/
- public $depth;
+ var $preprocessor;
- /** @var Parser */
- protected $parser;
+ /**
+ * @var Title
+ */
+ var $title;
+ var $titleCache;
- /** @var Preprocessor */
- protected $preprocessor;
+ /**
+ * Hashtable listing templates which are disallowed for expansion in this frame,
+ * having been encountered previously in parent frames.
+ */
+ var $loopCheckHash;
- /** @var Title */
- protected $title;
+ /**
+ * 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;
/**
- * @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.
$this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
$this->loopCheckHash = array();
$this->depth = 0;
+ $this->childExpansionCache = array();
}
/**
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
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;
+ }
}
/**
* @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
* @param bool|PPFrame $parent
* @param array $numberedArgs
* @param array $namedArgs
- * @param Title $title
+ * @param bool|Title $title
*/
function __construct( $preprocessor, $parent = false, $numberedArgs = array(),
$namedArgs = array(), $title = false
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
*
function isTemplate() {
return true;
}
+
+ function setVolatile( $flag = true ) {
+ parent::setVolatile( $flag );
+ $this->parent->setVolatile( $flag );
+ }
}
/**
* @ingroup Parser
*/
class PPCustomFrame_Hash extends PPFrame_Hash {
- /** @var array */
- protected $args;
+ var $args;
function __construct( $preprocessor, $args ) {
parent::__construct( $preprocessor );
* @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;
* @ingroup Parser
*/
class PPNode_Hash_Text implements PPNode {
- public $value;
-
- public $nextSibling;
+ var $value, $nextSibling;
function __construct( $value ) {
if ( is_object( $value ) ) {
* @ingroup Parser
*/
class PPNode_Hash_Array implements PPNode {
- public $value;
-
- public $nextSibling;
+ var $value, $nextSibling;
function __construct( $value ) {
$this->value = $value;
* @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;