summaryrefslogtreecommitdiff
path: root/includes/parser/Preprocessor_Hash.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/parser/Preprocessor_Hash.php')
-rw-r--r--includes/parser/Preprocessor_Hash.php620
1 files changed, 435 insertions, 185 deletions
diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php
index 2fc5e118..63763967 100644
--- a/includes/parser/Preprocessor_Hash.php
+++ b/includes/parser/Preprocessor_Hash.php
@@ -26,39 +26,42 @@
* * attribute nodes are children
* * "<h>" nodes that aren't at the top are replaced with <possible-h>
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class Preprocessor_Hash implements Preprocessor {
+ // @codingStandardsIgnoreEnd
+
/**
* @var Parser
*/
- var $parser;
+ public $parser;
const CACHE_VERSION = 1;
- function __construct( $parser ) {
+ public function __construct( $parser ) {
$this->parser = $parser;
}
/**
* @return PPFrame_Hash
*/
- function newFrame() {
+ public function newFrame() {
return new PPFrame_Hash( $this );
}
/**
- * @param $args array
+ * @param array $args
* @return PPCustomFrame_Hash
*/
- function newCustomFrame( $args ) {
+ public function newCustomFrame( $args ) {
return new PPCustomFrame_Hash( $this, $args );
}
/**
- * @param $values array
+ * @param array $values
* @return PPNode_Hash_Array
*/
- function newPartNodeArray( $values ) {
+ public function newPartNodeArray( $values ) {
$list = array();
foreach ( $values as $k => $val ) {
@@ -89,10 +92,10 @@ class Preprocessor_Hash implements Preprocessor {
* Preprocess some wikitext and return the document tree.
* This is the ghost of Parser::replace_variables().
*
- * @param string $text the text to parse
- * @param $flags Integer: bitwise combination of:
- * Parser::PTD_FOR_INCLUSION Handle "<noinclude>" and "<includeonly>" as if the text is being
- * included. Default is to assume a direct page view.
+ * @param string $text The text to parse
+ * @param int $flags Bitwise combination of:
+ * Parser::PTD_FOR_INCLUSION Handle "<noinclude>" and "<includeonly>" as if the text is being
+ * included. Default is to assume a direct page view.
*
* The generated DOM tree must depend only on the input text and the flags.
* The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of bug 4899.
@@ -108,13 +111,15 @@ class Preprocessor_Hash implements Preprocessor {
* @throws MWException
* @return PPNode_Hash_Tree
*/
- function preprocessToObj( $text, $flags = 0 ) {
+ public function preprocessToObj( $text, $flags = 0 ) {
wfProfileIn( __METHOD__ );
// Check cache.
global $wgMemc, $wgPreprocessorCacheThreshold;
- $cacheable = $wgPreprocessorCacheThreshold !== false && strlen( $text ) > $wgPreprocessorCacheThreshold;
+ $cacheable = $wgPreprocessorCacheThreshold !== false
+ && strlen( $text ) > $wgPreprocessorCacheThreshold;
+
if ( $cacheable ) {
wfProfileIn( __METHOD__ . '-cacheable' );
@@ -161,7 +166,9 @@ class Preprocessor_Hash implements Preprocessor {
$ignoredTags = array( 'includeonly', '/includeonly' );
$ignoredElements = array( 'noinclude' );
$xmlishElements[] = 'noinclude';
- if ( strpos( $text, '<onlyinclude>' ) !== false && strpos( $text, '</onlyinclude>' ) !== false ) {
+ if ( strpos( $text, '<onlyinclude>' ) !== false
+ && strpos( $text, '</onlyinclude>' ) !== false
+ ) {
$enableOnlyinclude = true;
}
} else {
@@ -177,18 +184,27 @@ class Preprocessor_Hash implements Preprocessor {
$stack = new PPDStack_Hash;
$searchBase = "[{<\n";
- $revText = strrev( $text ); // For fast reverse searches
+ // For fast reverse searches
+ $revText = strrev( $text );
$lengthText = strlen( $text );
- $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the start
- $accum =& $stack->getAccum(); # Current accumulator
- $findEquals = false; # True to find equals signs in arguments
- $findPipe = false; # True to take notice of pipe characters
+ // Input pointer, starts out pointing to a pseudo-newline before the start
+ $i = 0;
+ // Current accumulator
+ $accum =& $stack->getAccum();
+ // True to find equals signs in arguments
+ $findEquals = false;
+ // True to take notice of pipe characters
+ $findPipe = false;
$headingIndex = 1;
- $inHeading = false; # True if $i is inside a possible heading
- $noMoreGT = false; # True if there are no more greater-than (>) signs right of $i
- $findOnlyinclude = $enableOnlyinclude; # True to ignore all input up to the next <onlyinclude>
- $fakeLineStart = true; # Do a line-start run without outputting an LF character
+ // True if $i is inside a possible heading
+ $inHeading = false;
+ // True if there are no more greater-than (>) signs right of $i
+ $noMoreGT = false;
+ // True to ignore all input up to the next <onlyinclude>
+ $findOnlyinclude = $enableOnlyinclude;
+ // Do a line-start run without outputting an LF character
+ $fakeLineStart = true;
while ( true ) {
//$this->memCheck();
@@ -273,7 +289,9 @@ class Preprocessor_Hash implements Preprocessor {
if ( $found == 'angle' ) {
$matches = false;
// Handle </onlyinclude>
- if ( $enableOnlyinclude && substr( $text, $i, strlen( '</onlyinclude>' ) ) == '</onlyinclude>' ) {
+ if ( $enableOnlyinclude
+ && substr( $text, $i, strlen( '</onlyinclude>' ) ) == '</onlyinclude>'
+ ) {
$findOnlyinclude = true;
continue;
}
@@ -326,15 +344,15 @@ class Preprocessor_Hash implements Preprocessor {
// the overall start. That's not how Sanitizer::removeHTMLcomments() did it, but
// it's a possible beneficial b/c break.
if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) == "\n"
- && substr( $text, $wsEnd + 1, 1 ) == "\n" )
- {
+ && substr( $text, $wsEnd + 1, 1 ) == "\n"
+ ) {
// Remove leading whitespace from the end of the accumulator
// Sanity check first though
$wsLength = $i - $wsStart;
if ( $wsLength > 0
&& $accum->lastNode instanceof PPNode_Hash_Text
- && strspn( $accum->lastNode->value, " \t", -$wsLength ) === $wsLength )
- {
+ && strspn( $accum->lastNode->value, " \t", -$wsLength ) === $wsLength
+ ) {
$accum->lastNode->value = substr( $accum->lastNode->value, 0, -$wsLength );
}
@@ -404,8 +422,8 @@ class Preprocessor_Hash implements Preprocessor {
$attrEnd = $tagEndPos;
// Find closing tag
if ( preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
- $text, $matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 ) )
- {
+ $text, $matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
+ ) {
$inner = substr( $text, $tagEndPos + 1, $matches[0][1] - $tagEndPos - 1 );
$i = $matches[0][1] + strlen( $matches[0][0] );
$close = $matches[0][0];
@@ -440,9 +458,7 @@ class Preprocessor_Hash implements Preprocessor {
$extNode->addChild( PPNode_Hash_Tree::newWithText( 'close', $close ) );
}
$accum->addNode( $extNode );
- }
-
- elseif ( $found == 'line-start' ) {
+ } elseif ( $found == 'line-start' ) {
// Is this the start of a heading?
// Line break belongs before the heading element in any case
if ( $fakeLineStart ) {
@@ -454,9 +470,10 @@ class Preprocessor_Hash implements Preprocessor {
$count = strspn( $text, '=', $i, 6 );
if ( $count == 1 && $findEquals ) {
- // DWIM: This looks kind of like a name/value separator
- // Let's let the equals handler have it and break the potential heading
- // This is heuristic, but AFAICT the methods for completely correct disambiguation are very complex.
+ // DWIM: This looks kind of like a name/value separator.
+ // Let's let the equals handler have it and break the potential
+ // heading. This is heuristic, but AFAICT the methods for
+ // completely correct disambiguation are very complex.
} elseif ( $count > 0 ) {
$piece = array(
'open' => "\n",
@@ -474,8 +491,9 @@ class Preprocessor_Hash implements Preprocessor {
// A heading must be open, otherwise \n wouldn't have been in the search list
assert( '$piece->open == "\n"' );
$part = $piece->getCurrentPart();
- // Search back through the input to see if it has a proper close
- // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient
+ // Search back through the input to see if it has a proper close.
+ // Do this using the reversed string since the other solutions
+ // (end anchor, etc.) are inefficient.
$wsLength = strspn( $revText, " \t", $lengthText - $i );
$searchStart = $i - $wsLength;
if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
@@ -743,9 +761,12 @@ class Preprocessor_Hash implements Preprocessor {
/**
* Stack class to help Preprocessor::preprocessToObj()
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPDStack_Hash extends PPDStack {
- function __construct() {
+ // @codingStandardsIgnoreEnd
+
+ public function __construct() {
$this->elementClass = 'PPDStackElement_Hash';
parent::__construct();
$this->rootAccum = new PPDAccum_Hash;
@@ -754,9 +775,12 @@ class PPDStack_Hash extends PPDStack {
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPDStackElement_Hash extends PPDStackElement {
- function __construct( $data = array() ) {
+ // @codingStandardsIgnoreENd
+
+ public function __construct( $data = array() ) {
$this->partClass = 'PPDPart_Hash';
parent::__construct( $data );
}
@@ -764,9 +788,10 @@ class PPDStackElement_Hash extends PPDStackElement {
/**
* Get the accumulator that would result if the close is not found.
*
+ * @param int|bool $openingCount
* @return PPDAccum_Hash
*/
- function breakSyntax( $openingCount = false ) {
+ public function breakSyntax( $openingCount = false ) {
if ( $this->open == "\n" ) {
$accum = $this->parts[0]->out;
} else {
@@ -791,9 +816,12 @@ class PPDStackElement_Hash extends PPDStackElement {
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPDPart_Hash extends PPDPart {
- function __construct( $out = '' ) {
+ // @codingStandardsIgnoreEnd
+
+ public function __construct( $out = '' ) {
$accum = new PPDAccum_Hash;
if ( $out !== '' ) {
$accum->addLiteral( $out );
@@ -804,18 +832,22 @@ class PPDPart_Hash extends PPDPart {
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPDAccum_Hash {
- var $firstNode, $lastNode;
+ // @codingStandardsIgnoreEnd
+
+ public $firstNode, $lastNode;
- function __construct() {
+ public function __construct() {
$this->firstNode = $this->lastNode = false;
}
/**
* Append a string literal
+ * @param string $s
*/
- function addLiteral( $s ) {
+ public function addLiteral( $s ) {
if ( $this->lastNode === false ) {
$this->firstNode = $this->lastNode = new PPNode_Hash_Text( $s );
} elseif ( $this->lastNode instanceof PPNode_Hash_Text ) {
@@ -828,8 +860,9 @@ class PPDAccum_Hash {
/**
* Append a PPNode
+ * @param PPNode $node
*/
- function addNode( PPNode $node ) {
+ public function addNode( PPNode $node ) {
if ( $this->lastNode === false ) {
$this->firstNode = $this->lastNode = $node;
} else {
@@ -840,18 +873,21 @@ class PPDAccum_Hash {
/**
* Append a tree node with text contents
+ * @param string $name
+ * @param string $value
*/
- function addNodeWithText( $name, $value ) {
+ public function addNodeWithText( $name, $value ) {
$node = PPNode_Hash_Tree::newWithText( $name, $value );
$this->addNode( $node );
}
/**
- * Append a PPAccum_Hash
+ * Append a PPDAccum_Hash
* Takes over ownership of the nodes in the source argument. These nodes may
* subsequently be modified, especially nextSibling.
+ * @param PPDAccum_Hash $accum
*/
- function addAccum( $accum ) {
+ public function addAccum( $accum ) {
if ( $accum->lastNode === false ) {
// nothing to add
} elseif ( $this->lastNode === false ) {
@@ -867,62 +903,72 @@ class PPDAccum_Hash {
/**
* An expansion frame, used as a context to expand the result of preprocessToObj()
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPFrame_Hash implements PPFrame {
+ // @codingStandardsIgnoreEnd
/**
* @var Parser
*/
- var $parser;
+ public $parser;
/**
* @var Preprocessor
*/
- var $preprocessor;
+ public $preprocessor;
/**
* @var Title
*/
- var $title;
- var $titleCache;
+ public $title;
+ public $titleCache;
/**
* Hashtable listing templates which are disallowed for expansion in this frame,
* having been encountered previously in parent frames.
*/
- var $loopCheckHash;
+ public $loopCheckHash;
/**
* Recursion depth of this frame, top = 0
* Note that this is NOT the same as expansion depth in expand()
*/
- var $depth;
+ public $depth;
+
+ private $volatile = false;
+ private $ttl = null;
+
+ /**
+ * @var array
+ */
+ protected $childExpansionCache;
/**
* Construct a new preprocessor frame.
- * @param $preprocessor Preprocessor: the parent preprocessor
+ * @param Preprocessor $preprocessor The parent preprocessor
*/
- function __construct( $preprocessor ) {
+ public function __construct( $preprocessor ) {
$this->preprocessor = $preprocessor;
$this->parser = $preprocessor->parser;
$this->title = $this->parser->mTitle;
$this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
$this->loopCheckHash = array();
$this->depth = 0;
+ $this->childExpansionCache = array();
}
/**
* Create a new child frame
* $args is optionally a multi-root PPNode or array containing the template arguments
*
- * @param array|bool|\PPNode_Hash_Array $args PPNode_Hash_Array|array
- * @param $title Title|bool
- *
+ * @param array|bool|PPNode_Hash_Array $args
+ * @param Title|bool $title
* @param int $indexOffset
* @throws MWException
* @return PPTemplateFrame_Hash
*/
- function newChild( $args = false, $title = false, $indexOffset = 0 ) {
+ public function newChild( $args = false, $title = false, $indexOffset = 0 ) {
$namedArgs = array();
$numberedArgs = array();
if ( $title === false ) {
@@ -954,11 +1000,23 @@ class PPFrame_Hash implements PPFrame {
/**
* @throws MWException
- * @param $root
- * @param $flags int
+ * @param string|int $key
+ * @param string|PPNode $root
+ * @param int $flags
+ * @return string
+ */
+ public 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
+ * @param int $flags
* @return string
*/
- function expand( $root, $flags = 0 ) {
+ public function expand( $root, $flags = 0 ) {
static $expansionDepth = 0;
if ( is_string( $root ) ) {
return $root;
@@ -1035,7 +1093,11 @@ class PPFrame_Hash implements PPFrame {
# Double-brace expansion
$bits = $contextNode->splitTemplate();
if ( $flags & PPFrame::NO_TEMPLATES ) {
- $newIterator = $this->virtualBracketedImplode( '{{', '|', '}}', $bits['title'], $bits['parts'] );
+ $newIterator = $this->virtualBracketedImplode(
+ '{{', '|', '}}',
+ $bits['title'],
+ $bits['parts']
+ );
} else {
$ret = $this->parser->braceSubstitution( $bits, $this );
if ( isset( $ret['object'] ) ) {
@@ -1048,7 +1110,11 @@ class PPFrame_Hash implements PPFrame {
# Triple-brace expansion
$bits = $contextNode->splitTemplate();
if ( $flags & PPFrame::NO_ARGS ) {
- $newIterator = $this->virtualBracketedImplode( '{{{', '|', '}}}', $bits['title'], $bits['parts'] );
+ $newIterator = $this->virtualBracketedImplode(
+ '{{{', '|', '}}}',
+ $bits['title'],
+ $bits['parts']
+ );
} else {
$ret = $this->parser->argSubstitution( $bits, $this );
if ( isset( $ret['object'] ) ) {
@@ -1062,17 +1128,16 @@ class PPFrame_Hash implements PPFrame {
# Remove it in HTML, pre+remove and STRIP_COMMENTS modes
if ( $this->parser->ot['html']
|| ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() )
- || ( $flags & PPFrame::STRIP_COMMENTS ) )
- {
+ || ( $flags & PPFrame::STRIP_COMMENTS )
+ ) {
$out .= '';
- }
- # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
- # Not in RECOVER_COMMENTS mode (extractSections) though
- elseif ( $this->parser->ot['wiki'] && !( $flags & PPFrame::RECOVER_COMMENTS ) ) {
+ } elseif ( $this->parser->ot['wiki'] && !( $flags & PPFrame::RECOVER_COMMENTS ) ) {
+ # Add a strip marker in PST mode so that pstPass2() can
+ # run some old-fashioned regexes on the result.
+ # Not in RECOVER_COMMENTS mode (extractSections) though.
$out .= $this->parser->insertStripItem( $contextNode->firstChild->value );
- }
- # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
- else {
+ } else {
+ # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
$out .= $contextNode->firstChild->value;
}
} elseif ( $contextNode->name == 'ignore' ) {
@@ -1080,7 +1145,9 @@ class PPFrame_Hash implements PPFrame {
# OT_WIKI will only respect <ignore> in substed templates.
# The other output types respect it unless NO_IGNORE is set.
# extractSections() sets NO_IGNORE and so never respects it.
- if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] ) || ( $flags & PPFrame::NO_IGNORE ) ) {
+ if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] )
+ || ( $flags & PPFrame::NO_IGNORE )
+ ) {
$out .= $contextNode->firstChild->value;
} else {
//$out .= '';
@@ -1088,7 +1155,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'] ) {
@@ -1139,11 +1222,12 @@ class PPFrame_Hash implements PPFrame {
}
/**
- * @param $sep
- * @param $flags
+ * @param string $sep
+ * @param int $flags
+ * @param string|PPNode $args,...
* @return string
*/
- function implodeWithFlags( $sep, $flags /*, ... */ ) {
+ public function implodeWithFlags( $sep, $flags /*, ... */ ) {
$args = array_slice( func_get_args(), 2 );
$first = true;
@@ -1170,9 +1254,11 @@ class PPFrame_Hash implements PPFrame {
/**
* Implode with no flags specified
* This previously called implodeWithFlags but has now been inlined to reduce stack depth
+ * @param string $sep
+ * @param string|PPNode $args,...
* @return string
*/
- function implode( $sep /*, ... */ ) {
+ public function implode( $sep /*, ... */ ) {
$args = array_slice( func_get_args(), 1 );
$first = true;
@@ -1200,9 +1286,11 @@ class PPFrame_Hash implements PPFrame {
* Makes an object that, when expand()ed, will be the same as one obtained
* with implode()
*
+ * @param string $sep
+ * @param string|PPNode $args,...
* @return PPNode_Hash_Array
*/
- function virtualImplode( $sep /*, ... */ ) {
+ public function virtualImplode( $sep /*, ... */ ) {
$args = array_slice( func_get_args(), 1 );
$out = array();
$first = true;
@@ -1229,9 +1317,13 @@ class PPFrame_Hash implements PPFrame {
/**
* Virtual implode with brackets
*
+ * @param string $start
+ * @param string $sep
+ * @param string $end
+ * @param string|PPNode $args,...
* @return PPNode_Hash_Array
*/
- function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
+ public function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
$args = array_slice( func_get_args(), 3 );
$out = array( $start );
$first = true;
@@ -1256,15 +1348,15 @@ class PPFrame_Hash implements PPFrame {
return new PPNode_Hash_Array( $out );
}
- function __toString() {
+ public function __toString() {
return 'frame{}';
}
/**
- * @param $level bool
- * @return array|bool|String
+ * @param bool $level
+ * @return array|bool|string
*/
- function getPDBK( $level = false ) {
+ public function getPDBK( $level = false ) {
if ( $level === false ) {
return $this->title->getPrefixedDBkey();
} else {
@@ -1275,21 +1367,21 @@ class PPFrame_Hash implements PPFrame {
/**
* @return array
*/
- function getArguments() {
+ public function getArguments() {
return array();
}
/**
* @return array
*/
- function getNumberedArguments() {
+ public function getNumberedArguments() {
return array();
}
/**
* @return array
*/
- function getNamedArguments() {
+ public function getNamedArguments() {
return array();
}
@@ -1298,26 +1390,26 @@ class PPFrame_Hash implements PPFrame {
*
* @return bool
*/
- function isEmpty() {
+ public function isEmpty() {
return true;
}
/**
- * @param $name
+ * @param string $name
* @return bool
*/
- function getArgument( $name ) {
+ public function getArgument( $name ) {
return false;
}
/**
* Returns true if the infinite loop check is OK, false if a loop is detected
*
- * @param $title Title
+ * @param Title $title
*
* @return bool
*/
- function loopCheck( $title ) {
+ public function loopCheck( $title ) {
return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
}
@@ -1326,7 +1418,7 @@ class PPFrame_Hash implements PPFrame {
*
* @return bool
*/
- function isTemplate() {
+ public function isTemplate() {
return false;
}
@@ -1335,27 +1427,70 @@ class PPFrame_Hash implements PPFrame {
*
* @return Title
*/
- function getTitle() {
+ public function getTitle() {
return $this->title;
}
+
+ /**
+ * Set the volatile flag
+ *
+ * @param bool $flag
+ */
+ public function setVolatile( $flag = true ) {
+ $this->volatile = $flag;
+ }
+
+ /**
+ * Get the volatile flag
+ *
+ * @return bool
+ */
+ public function isVolatile() {
+ return $this->volatile;
+ }
+
+ /**
+ * Set the TTL
+ *
+ * @param int $ttl
+ */
+ public function setTTL( $ttl ) {
+ if ( $ttl !== null && ( $this->ttl === null || $ttl < $this->ttl ) ) {
+ $this->ttl = $ttl;
+ }
+ }
+
+ /**
+ * Get the TTL
+ *
+ * @return int|null
+ */
+ public function getTTL() {
+ return $this->ttl;
+ }
}
/**
* Expansion frame with template arguments
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPTemplateFrame_Hash extends PPFrame_Hash {
- var $numberedArgs, $namedArgs, $parent;
- var $numberedExpansionCache, $namedExpansionCache;
+ // @codingStandardsIgnoreEnd
+
+ public $numberedArgs, $namedArgs, $parent;
+ public $numberedExpansionCache, $namedExpansionCache;
/**
- * @param $preprocessor
- * @param $parent
- * @param $numberedArgs array
- * @param $namedArgs array
- * @param $title Title
+ * @param Preprocessor $preprocessor
+ * @param bool|PPFrame $parent
+ * @param array $numberedArgs
+ * @param array $namedArgs
+ * @param bool|Title $title
*/
- function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
+ public function __construct( $preprocessor, $parent = false, $numberedArgs = array(),
+ $namedArgs = array(), $title = false
+ ) {
parent::__construct( $preprocessor );
$this->parent = $parent;
@@ -1373,7 +1508,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
$this->numberedExpansionCache = $this->namedExpansionCache = array();
}
- function __toString() {
+ public function __toString() {
$s = 'tplframe{';
$first = true;
$args = $this->numberedArgs + $this->namedArgs;
@@ -1389,19 +1524,38 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
$s .= '}';
return $s;
}
+
+ /**
+ * @throws MWException
+ * @param string|int $key
+ * @param string|PPNode $root
+ * @param int $flags
+ * @return string
+ */
+ public 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
*
* @return bool
*/
- function isEmpty() {
+ public function isEmpty() {
return !count( $this->numberedArgs ) && !count( $this->namedArgs );
}
/**
* @return array
*/
- function getArguments() {
+ public function getArguments() {
$arguments = array();
foreach ( array_merge(
array_keys( $this->numberedArgs ),
@@ -1414,7 +1568,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
/**
* @return array
*/
- function getNumberedArguments() {
+ public function getNumberedArguments() {
$arguments = array();
foreach ( array_keys( $this->numberedArgs ) as $key ) {
$arguments[$key] = $this->getArgument( $key );
@@ -1425,7 +1579,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
/**
* @return array
*/
- function getNamedArguments() {
+ public function getNamedArguments() {
$arguments = array();
foreach ( array_keys( $this->namedArgs ) as $key ) {
$arguments[$key] = $this->getArgument( $key );
@@ -1434,25 +1588,28 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
}
/**
- * @param $index
+ * @param int $index
* @return array|bool
*/
- function getNumberedArgument( $index ) {
+ public function getNumberedArgument( $index ) {
if ( !isset( $this->numberedArgs[$index] ) ) {
return false;
}
if ( !isset( $this->numberedExpansionCache[$index] ) ) {
# No trimming for unnamed arguments
- $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index], PPFrame::STRIP_COMMENTS );
+ $this->numberedExpansionCache[$index] = $this->parent->expand(
+ $this->numberedArgs[$index],
+ PPFrame::STRIP_COMMENTS
+ );
}
return $this->numberedExpansionCache[$index];
}
/**
- * @param $name
+ * @param string $name
* @return bool
*/
- function getNamedArgument( $name ) {
+ public function getNamedArgument( $name ) {
if ( !isset( $this->namedArgs[$name] ) ) {
return false;
}
@@ -1465,10 +1622,10 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
}
/**
- * @param $name
+ * @param string $name
* @return array|bool
*/
- function getArgument( $name ) {
+ public function getArgument( $name ) {
$text = $this->getNumberedArgument( $name );
if ( $text === false ) {
$text = $this->getNamedArgument( $name );
@@ -1481,24 +1638,37 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
*
* @return bool
*/
- function isTemplate() {
+ public function isTemplate() {
return true;
}
+
+ public function setVolatile( $flag = true ) {
+ parent::setVolatile( $flag );
+ $this->parent->setVolatile( $flag );
+ }
+
+ public function setTTL( $ttl ) {
+ parent::setTTL( $ttl );
+ $this->parent->setTTL( $ttl );
+ }
}
/**
* Expansion frame with custom arguments
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPCustomFrame_Hash extends PPFrame_Hash {
- var $args;
+ // @codingStandardsIgnoreEnd
- function __construct( $preprocessor, $args ) {
+ public $args;
+
+ public function __construct( $preprocessor, $args ) {
parent::__construct( $preprocessor );
$this->args = $args;
}
- function __toString() {
+ public function __toString() {
$s = 'cstmframe{';
$first = true;
foreach ( $this->args as $name => $value ) {
@@ -1517,38 +1687,41 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
/**
* @return bool
*/
- function isEmpty() {
+ public function isEmpty() {
return !count( $this->args );
}
/**
- * @param $index
+ * @param int $index
* @return bool
*/
- function getArgument( $index ) {
+ public function getArgument( $index ) {
if ( !isset( $this->args[$index] ) ) {
return false;
}
return $this->args[$index];
}
- function getArguments() {
+ public function getArguments() {
return $this->args;
}
}
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPNode_Hash_Tree implements PPNode {
- var $name, $firstChild, $lastChild, $nextSibling;
+ // @codingStandardsIgnoreEnd
+
+ public $name, $firstChild, $lastChild, $nextSibling;
- function __construct( $name ) {
+ public function __construct( $name ) {
$this->name = $name;
$this->firstChild = $this->lastChild = $this->nextSibling = false;
}
- function __toString() {
+ public function __toString() {
$inner = '';
$attribs = '';
for ( $node = $this->firstChild; $node; $node = $node->nextSibling ) {
@@ -1566,17 +1739,17 @@ class PPNode_Hash_Tree implements PPNode {
}
/**
- * @param $name
- * @param $text
+ * @param string $name
+ * @param string $text
* @return PPNode_Hash_Tree
*/
- static function newWithText( $name, $text ) {
+ public static function newWithText( $name, $text ) {
$obj = new self( $name );
$obj->addChild( new PPNode_Hash_Text( $text ) );
return $obj;
}
- function addChild( $node ) {
+ public function addChild( $node ) {
if ( $this->lastChild === false ) {
$this->firstChild = $this->lastChild = $node;
} else {
@@ -1588,7 +1761,7 @@ class PPNode_Hash_Tree implements PPNode {
/**
* @return PPNode_Hash_Array
*/
- function getChildren() {
+ public function getChildren() {
$children = array();
for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
$children[] = $child;
@@ -1596,15 +1769,15 @@ class PPNode_Hash_Tree implements PPNode {
return new PPNode_Hash_Array( $children );
}
- function getFirstChild() {
+ public function getFirstChild() {
return $this->firstChild;
}
- function getNextSibling() {
+ public function getNextSibling() {
return $this->nextSibling;
}
- function getChildrenOfType( $name ) {
+ public function getChildrenOfType( $name ) {
$children = array();
for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
if ( isset( $child->name ) && $child->name === $name ) {
@@ -1617,22 +1790,22 @@ class PPNode_Hash_Tree implements PPNode {
/**
* @return bool
*/
- function getLength() {
+ public function getLength() {
return false;
}
/**
- * @param $i
+ * @param int $i
* @return bool
*/
- function item( $i ) {
+ public function item( $i ) {
return false;
}
/**
* @return string
*/
- function getName() {
+ public function getName() {
return $this->name;
}
@@ -1645,7 +1818,7 @@ class PPNode_Hash_Tree implements PPNode {
* @throws MWException
* @return array
*/
- function splitArg() {
+ public function splitArg() {
$bits = array();
for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
if ( !isset( $child->name ) ) {
@@ -1654,8 +1827,8 @@ class PPNode_Hash_Tree implements PPNode {
if ( $child->name === 'name' ) {
$bits['name'] = $child;
if ( $child->firstChild instanceof PPNode_Hash_Attr
- && $child->firstChild->name === 'index' )
- {
+ && $child->firstChild->name === 'index'
+ ) {
$bits['index'] = $child->firstChild->value;
}
} elseif ( $child->name === 'value' ) {
@@ -1679,7 +1852,7 @@ class PPNode_Hash_Tree implements PPNode {
* @throws MWException
* @return array
*/
- function splitExt() {
+ public function splitExt() {
$bits = array();
for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
if ( !isset( $child->name ) ) {
@@ -1707,7 +1880,7 @@ class PPNode_Hash_Tree implements PPNode {
* @throws MWException
* @return array
*/
- function splitHeading() {
+ public function splitHeading() {
if ( $this->name !== 'h' ) {
throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
}
@@ -1734,7 +1907,7 @@ class PPNode_Hash_Tree implements PPNode {
* @throws MWException
* @return array
*/
- function splitTemplate() {
+ public function splitTemplate() {
$parts = array();
$bits = array( 'lineStart' => '' );
for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
@@ -1761,101 +1934,178 @@ class PPNode_Hash_Tree implements PPNode {
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPNode_Hash_Text implements PPNode {
- var $value, $nextSibling;
+ // @codingStandardsIgnoreEnd
- function __construct( $value ) {
+ public $value, $nextSibling;
+
+ public function __construct( $value ) {
if ( is_object( $value ) ) {
throw new MWException( __CLASS__ . ' given object instead of string' );
}
$this->value = $value;
}
- function __toString() {
+ public function __toString() {
return htmlspecialchars( $this->value );
}
- function getNextSibling() {
+ public function getNextSibling() {
return $this->nextSibling;
}
- function getChildren() { return false; }
- function getFirstChild() { return false; }
- function getChildrenOfType( $name ) { return false; }
- function getLength() { return false; }
- function item( $i ) { return false; }
- function getName() { return '#text'; }
- function splitArg() { throw new MWException( __METHOD__ . ': not supported' ); }
- function splitExt() { throw new MWException( __METHOD__ . ': not supported' ); }
- function splitHeading() { throw new MWException( __METHOD__ . ': not supported' ); }
+ public function getChildren() {
+ return false;
+ }
+
+ public function getFirstChild() {
+ return false;
+ }
+
+ public function getChildrenOfType( $name ) {
+ return false;
+ }
+
+ public function getLength() {
+ return false;
+ }
+
+ public function item( $i ) {
+ return false;
+ }
+
+ public function getName() {
+ return '#text';
+ }
+
+ public function splitArg() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
+
+ public function splitExt() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
+
+ public function splitHeading() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
}
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPNode_Hash_Array implements PPNode {
- var $value, $nextSibling;
+ // @codingStandardsIgnoreEnd
+
+ public $value, $nextSibling;
- function __construct( $value ) {
+ public function __construct( $value ) {
$this->value = $value;
}
- function __toString() {
+ public function __toString() {
return var_export( $this, true );
}
- function getLength() {
+ public function getLength() {
return count( $this->value );
}
- function item( $i ) {
+ public function item( $i ) {
return $this->value[$i];
}
- function getName() { return '#nodelist'; }
+ public function getName() {
+ return '#nodelist';
+ }
- function getNextSibling() {
+ public function getNextSibling() {
return $this->nextSibling;
}
- function getChildren() { return false; }
- function getFirstChild() { return false; }
- function getChildrenOfType( $name ) { return false; }
- function splitArg() { throw new MWException( __METHOD__ . ': not supported' ); }
- function splitExt() { throw new MWException( __METHOD__ . ': not supported' ); }
- function splitHeading() { throw new MWException( __METHOD__ . ': not supported' ); }
+ public function getChildren() {
+ return false;
+ }
+
+ public function getFirstChild() {
+ return false;
+ }
+
+ public function getChildrenOfType( $name ) {
+ return false;
+ }
+
+ public function splitArg() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
+
+ public function splitExt() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
+
+ public function splitHeading() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
}
/**
* @ingroup Parser
+ * @codingStandardsIgnoreStart
*/
class PPNode_Hash_Attr implements PPNode {
- var $name, $value, $nextSibling;
+ // @codingStandardsIgnoreEnd
+
+ public $name, $value, $nextSibling;
- function __construct( $name, $value ) {
+ public function __construct( $name, $value ) {
$this->name = $name;
$this->value = $value;
}
- function __toString() {
+ public function __toString() {
return "<@{$this->name}>" . htmlspecialchars( $this->value ) . "</@{$this->name}>";
}
- function getName() {
+ public function getName() {
return $this->name;
}
- function getNextSibling() {
+ public function getNextSibling() {
return $this->nextSibling;
}
- function getChildren() { return false; }
- function getFirstChild() { return false; }
- function getChildrenOfType( $name ) { return false; }
- function getLength() { return false; }
- function item( $i ) { return false; }
- function splitArg() { throw new MWException( __METHOD__ . ': not supported' ); }
- function splitExt() { throw new MWException( __METHOD__ . ': not supported' ); }
- function splitHeading() { throw new MWException( __METHOD__ . ': not supported' ); }
+ public function getChildren() {
+ return false;
+ }
+
+ public function getFirstChild() {
+ return false;
+ }
+
+ public function getChildrenOfType( $name ) {
+ return false;
+ }
+
+ public function getLength() {
+ return false;
+ }
+
+ public function item( $i ) {
+ return false;
+ }
+
+ public function splitArg() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
+
+ public function splitExt() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
+
+ public function splitHeading() {
+ throw new MWException( __METHOD__ . ': not supported' );
+ }
}