* @ingroup Parser
*/
class Preprocessor_DOM implements Preprocessor {
- /** @var Parser */
- public $parser;
- protected $memoryLimit;
+ /**
+ * @var Parser
+ */
+ var $parser;
+
+ var $memoryLimit;
const CACHE_VERSION = 1;
$xml .= "</list>";
+ wfProfileIn( __METHOD__ . '-loadXML' );
$dom = new DOMDocument();
- $dom->loadXML( $xml );
- $root = $dom->documentElement;
+ wfSuppressWarnings();
+ $result = $dom->loadXML( $xml );
+ wfRestoreWarnings();
+ 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
+ $result = $dom->loadXML( $xml, 1 << 19 );
+ }
+ wfProfileOut( __METHOD__ . '-loadXML' );
+ if ( !$result ) {
+ throw new MWException( 'Parameters passed to ' . __METHOD__ . ' result in invalid XML' );
+ }
+
+ $root = $dom->documentElement;
$node = new PPNode_DOM( $root->childNodes );
return $node;
}
* @ingroup Parser
*/
class PPDStack {
- /** @var array */
- public $stack;
-
- /** @var string */
- public $rootAccum;
+ var $stack, $rootAccum;
- /** @var bool|PPDStack */
- public $top;
-
- /** @var */
- public $out;
-
- /** @var string */
- protected $elementClass = 'PPDStackElement';
+ /**
+ * @var PPDStack
+ */
+ var $top;
+ var $out;
+ var $elementClass = 'PPDStackElement';
- protected static $false = false;
+ static $false = false;
function __construct() {
$this->stack = array();
* @ingroup Parser
*/
class PPDStackElement {
- /** @var string Opening character (\n for heading) */
- public $open;
-
- /** @var string Matching closing character */
- public $close;
-
- /** @var int Number of opening characters found (number of "=" for heading) */
- public $count;
-
- /** @var array PPDPart objects describing pipe-separated parts. */
- public $parts;
-
- /**
- * @var bool True if the open char appeared at the start of the input line.
- * Not set for headings.
- */
- public $lineStart;
+ var $open, // Opening character (\n for heading)
+ $close, // Matching closing character
+ $count, // Number of opening characters found (number of "=" for heading)
+ $parts, // Array of PPDPart objects describing pipe-separated parts.
+ $lineStart; // True if the open char appeared at the start of the input line. Not set for headings.
- /** @var string */
- protected $partClass = 'PPDPart';
+ var $partClass = 'PPDPart';
function __construct( $data = array() ) {
$class = $this->partClass;
* @ingroup Parser
*/
class PPDPart {
- /** @var string */
- public $out;
+ var $out; // Output accumulator string
// Optional member variables:
// eqpos Position of equals sign in output accumulator
* @ingroup Parser
*/
class PPFrame_DOM implements PPFrame {
- /** @var array */
- public $titleCache;
/**
- * @var array Hashtable listing templates which are disallowed for expansion
- * in this frame, having been encountered previously in parent frames.
+ * @var Preprocessor
*/
- public $loopCheckHash;
+ var $preprocessor;
/**
- * @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 Title
+ */
+ var $title;
+ var $titleCache;
+
+ /**
+ * Hashtable listing templates which are disallowed for expansion in this frame,
+ * having been encountered previously in parent frames.
*/
- public $depth;
+ var $loopCheckHash;
- /** @var Preprocessor */
- protected $preprocessor;
+ /**
+ * Recursion depth of this frame, top = 0
+ * Note that this is NOT the same as expansion depth in expand()
+ */
+ var $depth;
- /** @var Parser */
- protected $parser;
+ private $volatile = false;
- /** @var Title */
- protected $title;
+ /**
+ * @var array
+ */
+ 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_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
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_DOM extends PPFrame_DOM {
- /** @var PPFrame_DOM */
- public $parent;
-
- /** @var array */
- protected $numberedArgs;
-
- /** @var array */
- protected $namedArgs;
+ var $numberedArgs, $namedArgs;
- /** @var array */
- protected $numberedExpansionCache;
-
- /** @var string[] */
- protected $namedExpansionCache;
+ /**
+ * @var PPFrame_DOM
+ */
+ var $parent;
+ var $numberedExpansionCache, $namedExpansionCache;
/**
* @param Preprocessor $preprocessor
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
*
function isTemplate() {
return true;
}
+
+ function setVolatile( $flag = true ) {
+ parent::setVolatile( $flag );
+ $this->parent->setVolatile( $flag );
+ }
}
/**
* @ingroup Parser
*/
class PPCustomFrame_DOM extends PPFrame_DOM {
- protected $args;
+ var $args;
function __construct( $preprocessor, $args ) {
parent::__construct( $preprocessor );
* @ingroup Parser
*/
class PPNode_DOM implements PPNode {
- /** @var DOMElement */
- public $node;
- /** @var DOMXPath */
- protected $xpath;
+ /**
+ * @var DOMElement
+ */
+ var $node;
+ var $xpath;
function __construct( $node, $xpath = false ) {
$this->node = $node;