* @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;
* @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.
$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
} 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'] ) {
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;
+ }
}
/**
* @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
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 );
+ }
+
+ function setTTL( $ttl ) {
+ parent::setTTL( $ttl );
+ $this->parent->setTTL( $ttl );
+ }
}
/**
* @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;