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.php72
1 files changed, 52 insertions, 20 deletions
diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php
index c5d69685..6cb2febc 100644
--- a/includes/parser/Preprocessor_Hash.php
+++ b/includes/parser/Preprocessor_Hash.php
@@ -1,5 +1,11 @@
<?php
-
+/**
+ * Preprocessor using PHP arrays
+ *
+ * @file
+ * @ingroup Parser
+ */
+
/**
* Differences from DOM schema:
* * attribute nodes are children
@@ -23,12 +29,39 @@ class Preprocessor_Hash implements Preprocessor {
return new PPCustomFrame_Hash( $this, $args );
}
+ function newPartNodeArray( $values ) {
+ $list = array();
+
+ foreach ( $values as $k => $val ) {
+ $partNode = new PPNode_Hash_Tree( 'part' );
+ $nameNode = new PPNode_Hash_Tree( 'name' );
+
+ if ( is_int( $k ) ) {
+ $nameNode->addChild( new PPNode_Hash_Attr( 'index', $k ) );
+ $partNode->addChild( $nameNode );
+ } else {
+ $nameNode->addChild( new PPNode_Hash_Text( $k ) );
+ $partNode->addChild( $nameNode );
+ $partNode->addChild( new PPNode_Hash_Text( '=' ) );
+ }
+
+ $valueNode = new PPNode_Hash_Tree( 'value' );
+ $valueNode->addChild( new PPNode_Hash_Text( $val ) );
+ $partNode->addChild( $valueNode );
+
+ $list[] = $partNode;
+ }
+
+ $node = new PPNode_Hash_Array( $list );
+ return $node;
+ }
+
/**
* Preprocess some wikitext and return the document tree.
* This is the ghost of Parser::replace_variables().
*
- * @param string $text The text to parse
- * @param integer flags Bitwise combination of:
+ * @param $text String: the text to parse
+ * @param $flags Integer: bitwise combination of:
* Parser::PTD_FOR_INCLUSION Handle <noinclude>/<includeonly> as if the text is being
* included. Default is to assume a direct page view.
*
@@ -401,7 +434,7 @@ class Preprocessor_Hash implements Preprocessor {
$count = $piece->count;
$equalsLength = strspn( $revText, '=', strlen( $text ) - $searchStart );
if ( $equalsLength > 0 ) {
- if ( $i - $equalsLength == $piece->startPos ) {
+ if ( $searchStart - $equalsLength == $piece->startPos ) {
// This is just a single string of equals signs on its own line
// Replicate the doHeadings behaviour /={count}(.+)={count}/
// First find out how many equals signs there really are (don't stop at 6)
@@ -479,7 +512,6 @@ class Preprocessor_Hash implements Preprocessor {
# check for maximum matching characters (if there are 5 closing
# characters, we will probably need only 3 - depending on the rules)
- $matchingCount = 0;
$rule = $rules[$piece->open];
if ( $count > $rule['max'] ) {
# The specified maximum exists in the callback array, unless the caller
@@ -526,7 +558,7 @@ class Preprocessor_Hash implements Preprocessor {
$titleNode->lastChild = $titleAccum->lastNode;
$element->addChild( $titleNode );
$argIndex = 1;
- foreach ( $parts as $partIndex => $part ) {
+ foreach ( $parts as $part ) {
if ( isset( $part->eqpos ) ) {
// Find equals
$lastNode = false;
@@ -647,7 +679,7 @@ class Preprocessor_Hash implements Preprocessor {
// Cache
if ($cacheable) {
- $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . serialize( $rootNode );;
+ $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . serialize( $rootNode );
$wgMemc->set( $cacheKey, $cacheValue, 86400 );
wfProfileOut( __METHOD__.'-cache-miss' );
wfProfileOut( __METHOD__.'-cacheable' );
@@ -804,7 +836,7 @@ class PPFrame_Hash implements PPFrame {
/**
* Construct a new preprocessor frame.
- * @param Preprocessor $preprocessor The parent preprocessor
+ * @param $preprocessor Preprocessor: the parent preprocessor
*/
function __construct( $preprocessor ) {
$this->preprocessor = $preprocessor;
@@ -826,7 +858,6 @@ class PPFrame_Hash implements PPFrame {
$title = $this->title;
}
if ( $args !== false ) {
- $xpath = false;
if ( $args instanceof PPNode_Hash_Array ) {
$args = $args->value;
} elseif ( !is_array( $args ) ) {
@@ -855,11 +886,11 @@ class PPFrame_Hash implements PPFrame {
return $root;
}
- if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->mMaxPPNodeCount )
+ if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() )
{
return '<span class="error">Node-count limit exceeded</span>';
}
- if ( $expansionDepth > $this->parser->mOptions->mMaxPPExpandDepth ) {
+ if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
return '<span class="error">Expansion depth limit exceeded</span>';
}
++$expansionDepth;
@@ -915,7 +946,7 @@ class PPFrame_Hash implements PPFrame {
if ( $contextNode->name == 'template' ) {
# Double-brace expansion
$bits = $contextNode->splitTemplate();
- if ( $flags & self::NO_TEMPLATES ) {
+ if ( $flags & PPFrame::NO_TEMPLATES ) {
$newIterator = $this->virtualBracketedImplode( '{{', '|', '}}', $bits['title'], $bits['parts'] );
} else {
$ret = $this->parser->braceSubstitution( $bits, $this );
@@ -928,7 +959,7 @@ class PPFrame_Hash implements PPFrame {
} elseif ( $contextNode->name == 'tplarg' ) {
# Triple-brace expansion
$bits = $contextNode->splitTemplate();
- if ( $flags & self::NO_ARGS ) {
+ if ( $flags & PPFrame::NO_ARGS ) {
$newIterator = $this->virtualBracketedImplode( '{{{', '|', '}}}', $bits['title'], $bits['parts'] );
} else {
$ret = $this->parser->argSubstitution( $bits, $this );
@@ -943,13 +974,13 @@ 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 & self::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 & self::RECOVER_COMMENTS ) ) {
+ elseif ( $this->parser->ot['wiki'] && ! ( $flags & PPFrame::RECOVER_COMMENTS ) ) {
$out .= $this->parser->insertStripItem( $contextNode->firstChild->value );
}
# Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
@@ -961,7 +992,7 @@ 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 & self::NO_IGNORE ) ) {
+ if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] ) || ( $flags & PPFrame::NO_IGNORE ) ) {
$out .= $contextNode->firstChild->value;
} else {
//$out .= '';
@@ -1186,7 +1217,8 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
var $numberedExpansionCache, $namedExpansionCache;
function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
- PPFrame_Hash::__construct( $preprocessor );
+ parent::__construct( $preprocessor );
+
$this->parent = $parent;
$this->numberedArgs = $numberedArgs;
$this->namedArgs = $namedArgs;
@@ -1257,7 +1289,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
}
if ( !isset( $this->numberedExpansionCache[$index] ) ) {
# No trimming for unnamed arguments
- $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index], self::STRIP_COMMENTS );
+ $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index], PPFrame::STRIP_COMMENTS );
}
return $this->numberedExpansionCache[$index];
}
@@ -1269,7 +1301,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
if ( !isset( $this->namedExpansionCache[$name] ) ) {
# Trim named arguments post-expand, for backwards compatibility
$this->namedExpansionCache[$name] = trim(
- $this->parent->expand( $this->namedArgs[$name], self::STRIP_COMMENTS ) );
+ $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
}
return $this->namedExpansionCache[$name];
}
@@ -1298,7 +1330,7 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
var $args;
function __construct( $preprocessor, $args ) {
- PPFrame_Hash::__construct( $preprocessor );
+ parent::__construct( $preprocessor );
$this->args = $args;
}