40 $mem = ini_get(
'memory_limit' );
41 $this->memoryLimit =
false;
42 if ( strval( $mem ) !==
'' && $mem != -1 ) {
43 if ( preg_match(
'/^\d+$/', $mem ) ) {
44 $this->memoryLimit = $mem;
45 } elseif ( preg_match(
'/^(\d+)M$/i', $mem, $m ) ) {
46 $this->memoryLimit = $m[1] * 1048576;
74 foreach ( $values
as $k => $val ) {
76 $xml .=
"<part><name index=\"$k\"/><value>" . htmlspecialchars( $val ) .
"</value></part>";
78 $xml .=
"<part><name>" . htmlspecialchars( $k ) .
"</name>=<value>" . htmlspecialchars( $val ) .
"</value></part>";
84 $dom =
new DOMDocument();
85 $dom->loadXML( $xml );
86 $root = $dom->documentElement;
97 if ( $this->memoryLimit ===
false ) {
100 $usage = memory_get_usage();
101 if ( $usage > $this->memoryLimit * 0.9 ) {
102 $limit = intval( $this->memoryLimit * 0.9 / 1048576 + 0.5 );
103 throw new MWException(
"Preprocessor hit 90% memory limit ($limit MB)" );
105 return $usage <= $this->memoryLimit * 0.8;
136 $cacheable = ( $wgPreprocessorCacheThreshold !==
false
137 && strlen( $text ) > $wgPreprocessorCacheThreshold );
142 $cacheValue =
$wgMemc->get( $cacheKey );
144 $version = substr( $cacheValue, 0, 8 );
145 if ( intval(
$version ) == self::CACHE_VERSION ) {
146 $xml = substr( $cacheValue, 8 );
148 wfDebugLog(
"Preprocessor",
"Loaded preprocessor XML from memcached (key $cacheKey)" );
151 if ( $xml ===
false ) {
154 $cacheValue = sprintf(
"%08d", self::CACHE_VERSION ) . $xml;
155 $wgMemc->set( $cacheKey, $cacheValue, 86400 );
157 wfDebugLog(
"Preprocessor",
"Saved preprocessor XML to memcached (key $cacheKey)" );
165 $this->parser->mGeneratedPPNodeCount += substr_count( $xml,
'<' );
166 $max = $this->parser->mOptions->getMaxGeneratedPPNodeCount();
167 if ( $this->parser->mGeneratedPPNodeCount > $max ) {
172 throw new MWException( __METHOD__ .
': generated node count limit exceeded' );
176 $dom =
new DOMDocument;
178 $result = $dom->loadXML( $xml );
184 $result = $dom->loadXML( $xml, 1 << 19 );
187 $obj =
new PPNode_DOM( $dom->documentElement );
198 throw new MWException( __METHOD__ .
' generated invalid XML' );
222 'names' =>
array( 2 =>
null ),
228 $forInclusion =
$flags & Parser::PTD_FOR_INCLUSION;
230 $xmlishElements = $this->parser->getStripList();
231 $enableOnlyinclude =
false;
232 if ( $forInclusion ) {
233 $ignoredTags =
array(
'includeonly',
'/includeonly' );
234 $ignoredElements =
array(
'noinclude' );
235 $xmlishElements[] =
'noinclude';
236 if ( strpos( $text,
'<onlyinclude>' ) !==
false && strpos( $text,
'</onlyinclude>' ) !==
false ) {
237 $enableOnlyinclude =
true;
240 $ignoredTags =
array(
'noinclude',
'/noinclude',
'onlyinclude',
'/onlyinclude' );
241 $ignoredElements =
array(
'includeonly' );
242 $xmlishElements[] =
'includeonly';
244 $xmlishRegex = implode(
'|', array_merge( $xmlishElements, $ignoredTags ) );
247 $elementsRegex =
"~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
251 $searchBase =
"[{<\n"; #}
252 $revText = strrev( $text );
253 $lengthText = strlen( $text );
255 $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the
start
256 $accum =& $stack->getAccum(); # Current accumulator
258 $findEquals =
false; # True to find equals signs
in arguments
259 $findPipe =
false; # True to take notice
of pipe characters
261 $inHeading =
false; # True
if $i
is inside a possible heading
262 $noMoreGT =
false; # True
if there are no more greater-than (>) signs right
of $i
263 $findOnlyinclude = $enableOnlyinclude;
# True to ignore all input up to the next <onlyinclude>
269 if ( $findOnlyinclude ) {
271 $startPos = strpos( $text,
'<onlyinclude>', $i );
272 if ( $startPos ===
false ) {
274 $accum .=
'<ignore>' . htmlspecialchars( substr( $text, $i ) ) .
'</ignore>';
277 $tagEndPos = $startPos + strlen(
'<onlyinclude>' );
278 $accum .=
'<ignore>' . htmlspecialchars( substr( $text, $i, $tagEndPos - $i ) ) .
'</ignore>';
280 $findOnlyinclude =
false;
283 if ( $fakeLineStart ) {
284 $found =
'line-start';
287 # Find next opening brace, closing brace or pipe
288 $search = $searchBase;
289 if ( $stack->top ===
false ) {
290 $currentClosing =
'';
292 $currentClosing = $stack->top->close;
293 $search .= $currentClosing;
303 # Output literal section, advance input counter
304 $literalLength = strcspn( $text, $search, $i );
305 if ( $literalLength > 0 ) {
306 $accum .= htmlspecialchars( substr( $text, $i, $literalLength ) );
307 $i += $literalLength;
309 if ( $i >= $lengthText ) {
310 if ( $currentClosing ==
"\n" ) {
319 $curChar = $text[$i];
320 if ( $curChar ==
'|' ) {
322 } elseif ( $curChar ==
'=' ) {
324 } elseif ( $curChar ==
'<' ) {
326 } elseif ( $curChar ==
"\n" ) {
330 $found =
'line-start';
332 } elseif ( $curChar == $currentClosing ) {
334 } elseif ( isset( $rules[$curChar] ) ) {
336 $rule = $rules[$curChar];
338 # Some versions of PHP have a strcspn which stops on null characters
339 # Ignore and continue
346 if ( $found ==
'angle' ) {
349 if ( $enableOnlyinclude && substr( $text, $i, strlen(
'</onlyinclude>' ) ) ==
'</onlyinclude>' ) {
350 $findOnlyinclude =
true;
355 if ( !preg_match( $elementsRegex, $text,
$matches, 0, $i + 1 ) ) {
370 $endPos = strpos( $text,
'-->', $i + 4 );
371 if ( $endPos ===
false ) {
373 $inner = substr( $text, $i );
374 $accum .=
'<comment>' . htmlspecialchars( $inner ) .
'</comment>';
378 $wsStart = $i ? ( $i - strspn( $revText,
" \t", $lengthText - $i ) ) : 0;
382 $wsEnd = $endPos + 2 + strspn( $text,
" \t", $endPos + 3 );
386 $comments =
array(
array( $wsStart, $wsEnd ) );
387 while ( substr( $text, $wsEnd + 1, 4 ) ==
'<!--' ) {
388 $c = strpos( $text,
'-->', $wsEnd + 4 );
389 if ( $c ===
false ) {
392 $c = $c + 2 + strspn( $text,
" \t", $c + 3 );
393 $comments[] =
array( $wsEnd + 1, $c );
401 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) ==
"\n"
402 && substr( $text, $wsEnd + 1, 1 ) ==
"\n"
406 $wsLength = $i - $wsStart;
408 && strspn( $accum,
" \t", -$wsLength ) === $wsLength
410 $accum = substr( $accum, 0, -$wsLength );
414 foreach ( $comments
as $j => $com ) {
416 $endPos = $com[1] + 1;
417 if ( $j == ( count( $comments ) - 1 ) ) {
420 $inner = substr( $text, $startPos, $endPos - $startPos );
421 $accum .=
'<comment>' . htmlspecialchars( $inner ) .
'</comment>';
425 $fakeLineStart =
true;
433 $part = $stack->top->getCurrentPart();
434 if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
435 $part->visualEnd = $wsStart;
438 $part->commentEnd = $endPos;
441 $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
442 $accum .=
'<comment>' . htmlspecialchars( $inner ) .
'</comment>';
447 $lowerName = strtolower(
$name );
448 $attrStart = $i + strlen(
$name ) + 1;
451 $tagEndPos = $noMoreGT ?
false : strpos( $text,
'>', $attrStart );
452 if ( $tagEndPos ===
false ) {
462 if ( in_array( $lowerName, $ignoredTags ) ) {
463 $accum .=
'<ignore>' . htmlspecialchars( substr( $text, $i, $tagEndPos - $i + 1 ) ) .
'</ignore>';
469 if ( $text[$tagEndPos - 1] ==
'/' ) {
470 $attrEnd = $tagEndPos - 1;
475 $attrEnd = $tagEndPos;
477 if ( preg_match(
"/<\/" . preg_quote(
$name,
'/' ) .
"\s*>/i",
478 $text,
$matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
480 $inner = substr( $text, $tagEndPos + 1,
$matches[0][1] - $tagEndPos - 1 );
482 $close =
'<close>' . htmlspecialchars(
$matches[0][0] ) .
'</close>';
485 $inner = substr( $text, $tagEndPos + 1 );
491 if ( in_array( $lowerName, $ignoredElements ) ) {
492 $accum .=
'<ignore>' . htmlspecialchars( substr( $text, $tagStartPos, $i - $tagStartPos ) )
498 if ( $attrEnd <= $attrStart ) {
501 $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
503 $accum .=
'<name>' . htmlspecialchars(
$name ) .
'</name>' .
506 '<attr>' . htmlspecialchars( $attr ) .
'</attr>';
507 if ( $inner !==
null ) {
508 $accum .=
'<inner>' . htmlspecialchars( $inner ) .
'</inner>';
510 $accum .= $close .
'</ext>';
511 } elseif ( $found ==
'line-start' ) {
514 if ( $fakeLineStart ) {
515 $fakeLineStart =
false;
521 $count = strspn( $text,
'=', $i, 6 );
522 if (
$count == 1 && $findEquals ) {
533 $stack->push( $piece );
534 $accum =& $stack->getAccum();
535 $flags = $stack->getFlags();
539 } elseif ( $found ==
'line-end' ) {
540 $piece = $stack->top;
542 assert(
'$piece->open == "\n"' );
543 $part = $piece->getCurrentPart();
546 $wsLength = strspn( $revText,
" \t", $lengthText - $i );
547 $searchStart = $i - $wsLength;
548 if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
551 $searchStart = $part->visualEnd;
552 $searchStart -= strspn( $revText,
" \t", $lengthText - $searchStart );
555 $equalsLength = strspn( $revText,
'=', $lengthText - $searchStart );
556 if ( $equalsLength > 0 ) {
557 if ( $searchStart - $equalsLength == $piece->startPos ) {
572 $element =
"<h level=\"$count\" i=\"$headingIndex\">$accum</h>";
584 $accum =& $stack->getAccum();
585 $flags = $stack->getFlags();
595 } elseif ( $found ==
'open' ) {
596 # count opening brace characters
597 $count = strspn( $text, $curChar, $i );
599 # we need to add to stack only if opening brace count is enough for one of the rules
600 if (
$count >= $rule[
'min'] ) {
601 # Add it to the stack
604 'close' => $rule[
'end'],
606 'lineStart' => ( $i > 0 && $text[$i - 1] ==
"\n" ),
609 $stack->push( $piece );
610 $accum =& $stack->getAccum();
611 $flags = $stack->getFlags();
614 # Add literal brace(s)
615 $accum .= htmlspecialchars( str_repeat( $curChar,
$count ) );
618 } elseif ( $found ==
'close' ) {
619 $piece = $stack->top;
620 # lets check if there are enough characters for closing brace
621 $maxCount = $piece->count;
622 $count = strspn( $text, $curChar, $i, $maxCount );
624 # check for maximum matching characters (if there are 5 closing
625 # characters, we will probably need only 3 - depending on the rules)
626 $rule = $rules[$piece->open];
627 if (
$count > $rule[
'max'] ) {
628 # The specified maximum exists in the callback array, unless the caller
630 $matchingCount = $rule[
'max'];
632 # Count is less than the maximum
633 # Skip any gaps in the callback array to find the true largest match
634 # Need to use array_key_exists not isset because the callback can be null
636 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule[
'names'] ) ) {
641 if ( $matchingCount <= 0 ) {
642 # No matching element found in callback array
643 # Output a literal closing brace and continue
644 $accum .= htmlspecialchars( str_repeat( $curChar,
$count ) );
648 $name = $rule[
'names'][$matchingCount];
649 if (
$name ===
null ) {
651 $element = $piece->breakSyntax( $matchingCount ) . str_repeat( $rule[
'end'], $matchingCount );
654 # Note: $parts is already XML, does not need to be encoded further
655 $parts = $piece->parts;
659 # The invocation is at the start of the line if lineStart is set in
660 # the stack, and all opening brackets are used up.
661 if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
662 $attr =
' lineStart="1"';
667 $element =
"<$name$attr>";
668 $element .=
"<title>$title</title>";
670 foreach ( $parts
as $part ) {
671 if ( isset( $part->eqpos ) ) {
672 $argName = substr( $part->out, 0, $part->eqpos );
673 $argValue = substr( $part->out, $part->eqpos + 1 );
674 $element .=
"<part><name>$argName</name>=<value>$argValue</value></part>";
676 $element .=
"<part><name index=\"$argIndex\" /><value>{$part->out}</value></part>";
680 $element .=
"</$name>";
683 # Advance input pointer
684 $i += $matchingCount;
688 $accum =& $stack->getAccum();
690 # Re-add the old stack element if it still has unmatched opening characters remaining
691 if ( $matchingCount < $piece->count ) {
693 $piece->count -= $matchingCount;
694 # do we still qualify for any callback with remaining count?
695 $min = $rules[$piece->open][
'min'];
696 if ( $piece->count >= $min ) {
697 $stack->push( $piece );
698 $accum =& $stack->getAccum();
700 $accum .= str_repeat( $piece->open, $piece->count );
703 $flags = $stack->getFlags();
706 # Add XML element to the enclosing accumulator
708 } elseif ( $found ==
'pipe' ) {
711 $accum =& $stack->getAccum();
713 } elseif ( $found ==
'equals' ) {
715 $stack->getCurrentPart()->eqpos = strlen( $accum );
721 # Output any remaining unclosed brackets
722 foreach ( $stack->stack
as $piece ) {
723 $stack->rootAccum .= $piece->breakSyntax();
725 $stack->rootAccum .=
'</root>';
726 $xml = $stack->rootAccum;
751 $this->stack =
array();
753 $this->rootAccum =
'';
761 return count( $this->stack );
769 if ( $this->top ===
false ) {
772 return $this->top->getCurrentPart();
776 function push( $data ) {
777 if ( $data instanceof $this->elementClass ) {
778 $this->stack[] = $data;
781 $this->stack[] =
new $class( $data );
783 $this->top = $this->stack[
count( $this->stack ) - 1];
784 $this->accum =& $this->top->getAccum();
788 if ( !
count( $this->stack ) ) {
789 throw new MWException( __METHOD__ .
': no elements remaining' );
791 $temp = array_pop( $this->stack );
793 if (
count( $this->stack ) ) {
794 $this->top = $this->stack[
count( $this->stack ) - 1];
795 $this->accum =& $this->top->getAccum();
804 $this->top->addPart(
$s );
805 $this->accum =& $this->top->getAccum();
812 if ( !
count( $this->stack ) ) {
814 'findEquals' =>
false,
816 'inHeading' =>
false,
819 return $this->top->getFlags();
838 $this->parts =
array(
new $class );
846 return $this->parts[count( $this->parts ) - 1]->out;
851 $this->parts[] =
new $class(
$s );
855 return $this->parts[count( $this->parts ) - 1];
862 $partCount = count( $this->parts );
863 $findPipe = $this->
open !=
"\n" && $this->
open !=
'[';
865 'findPipe' => $findPipe,
866 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
867 'inHeading' => $this->
open ==
"\n",
877 if ( $this->
open ==
"\n" ) {
878 $s = $this->parts[0]->out;
880 if ( $openingCount ===
false ) {
883 $s = str_repeat( $this->
open, $openingCount );
885 foreach ( $this->parts
as $part ) {
955 $this->
title = $this->parser->mTitle;
957 $this->loopCheckHash =
array();
968 $namedArgs =
array();
969 $numberedArgs =
array();
973 if (
$args !==
false ) {
979 if ( $arg instanceof
PPNode ) {
983 $xpath =
new DOMXPath( $arg->ownerDocument );
986 $nameNodes = $xpath->query(
'name', $arg );
987 $value = $xpath->query(
'value', $arg );
988 if ( $nameNodes->item( 0 )->hasAttributes() ) {
990 $index = $nameNodes->item( 0 )->attributes->getNamedItem(
'index' )->textContent;
991 $index = $index - $indexOffset;
992 $numberedArgs[$index] =
$value->item( 0 );
993 unset( $namedArgs[$index] );
998 unset( $numberedArgs[
$name] );
1012 static $expansionDepth = 0;
1013 if ( is_string( $root ) ) {
1017 if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
1018 $this->parser->limitationWarn(
'node-count-exceeded',
1019 $this->parser->mPPNodeCount,
1020 $this->parser->mOptions->getMaxPPNodeCount()
1022 return '<span class="error">Node-count limit exceeded</span>';
1025 if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
1026 $this->parser->limitationWarn(
'expansion-depth-exceeded',
1028 $this->parser->mOptions->getMaxPPExpandDepth()
1030 return '<span class="error">Expansion depth limit exceeded</span>';
1034 if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
1035 $this->parser->mHighestExpansionDepth = $expansionDepth;
1039 $root = $root->node;
1041 if ( $root instanceof DOMDocument ) {
1042 $root = $root->documentElement;
1045 $outStack =
array(
'',
'' );
1046 $iteratorStack =
array(
false, $root );
1047 $indexStack =
array( 0, 0 );
1049 while ( count( $iteratorStack ) > 1 ) {
1050 $level = count( $outStack ) - 1;
1051 $iteratorNode =& $iteratorStack[$level];
1052 $out =& $outStack[$level];
1053 $index =& $indexStack[$level];
1056 $iteratorNode = $iteratorNode->node;
1059 if ( is_array( $iteratorNode ) ) {
1060 if ( $index >= count( $iteratorNode ) ) {
1062 $iteratorStack[$level] =
false;
1063 $contextNode =
false;
1065 $contextNode = $iteratorNode[$index];
1068 } elseif ( $iteratorNode instanceof DOMNodeList ) {
1069 if ( $index >= $iteratorNode->length ) {
1071 $iteratorStack[$level] =
false;
1072 $contextNode =
false;
1074 $contextNode = $iteratorNode->item( $index );
1080 $contextNode = $iteratorStack[$level];
1081 $iteratorStack[$level] =
false;
1085 $contextNode = $contextNode->node;
1088 $newIterator =
false;
1090 if ( $contextNode ===
false ) {
1092 } elseif ( is_string( $contextNode ) ) {
1093 $out .= $contextNode;
1094 } elseif ( is_array( $contextNode ) || $contextNode instanceof DOMNodeList ) {
1095 $newIterator = $contextNode;
1096 } elseif ( $contextNode instanceof DOMNode ) {
1097 if ( $contextNode->nodeType == XML_TEXT_NODE ) {
1098 $out .= $contextNode->nodeValue;
1099 } elseif ( $contextNode->nodeName ==
'template' ) {
1100 # Double-brace expansion
1101 $xpath =
new DOMXPath( $contextNode->ownerDocument );
1102 $titles = $xpath->query(
'title', $contextNode );
1104 $parts = $xpath->query(
'part', $contextNode );
1108 $lineStart = $contextNode->getAttribute(
'lineStart' );
1112 'lineStart' => $lineStart );
1113 $ret = $this->parser->braceSubstitution(
$params, $this );
1114 if ( isset(
$ret[
'object'] ) ) {
1115 $newIterator =
$ret[
'object'];
1120 } elseif ( $contextNode->nodeName ==
'tplarg' ) {
1121 # Triple-brace expansion
1122 $xpath =
new DOMXPath( $contextNode->ownerDocument );
1123 $titles = $xpath->query(
'title', $contextNode );
1125 $parts = $xpath->query(
'part', $contextNode );
1132 $ret = $this->parser->argSubstitution(
$params, $this );
1133 if ( isset(
$ret[
'object'] ) ) {
1134 $newIterator =
$ret[
'object'];
1139 } elseif ( $contextNode->nodeName ==
'comment' ) {
1140 # HTML-style comment
1141 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1142 if ( $this->parser->ot[
'html']
1143 || ( $this->parser->ot[
'pre'] && $this->parser->mOptions->getRemoveComments() )
1148 # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
1149 # Not in RECOVER_COMMENTS mode (extractSections) though
1150 $out .= $this->parser->insertStripItem( $contextNode->textContent );
1152 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1153 $out .= $contextNode->textContent;
1155 } elseif ( $contextNode->nodeName ==
'ignore' ) {
1156 # Output suppression used by <includeonly> etc.
1157 # OT_WIKI will only respect <ignore> in substed templates.
1158 # The other output types respect it unless NO_IGNORE is set.
1159 # extractSections() sets NO_IGNORE and so never respects it.
1161 $out .= $contextNode->textContent;
1165 } elseif ( $contextNode->nodeName ==
'ext' ) {
1167 $xpath =
new DOMXPath( $contextNode->ownerDocument );
1168 $names = $xpath->query(
'name', $contextNode );
1169 $attrs = $xpath->query(
'attr', $contextNode );
1170 $inners = $xpath->query(
'inner', $contextNode );
1171 $closes = $xpath->query(
'close', $contextNode );
1173 'name' =>
new PPNode_DOM( $names->item( 0 ) ),
1174 'attr' => $attrs->length > 0 ?
new PPNode_DOM( $attrs->item( 0 ) ) :
null,
1175 'inner' => $inners->length > 0 ?
new PPNode_DOM( $inners->item( 0 ) ) :
null,
1176 'close' => $closes->length > 0 ?
new PPNode_DOM( $closes->item( 0 ) ) :
null,
1178 $out .= $this->parser->extensionSubstitution(
$params, $this );
1179 } elseif ( $contextNode->nodeName ==
'h' ) {
1183 # Insert a heading marker only for <h> children of <root>
1184 # This is to stop extractSections from going over multiple tree levels
1185 if ( $contextNode->parentNode->nodeName ==
'root' && $this->parser->ot[
'html'] ) {
1186 # Insert heading index marker
1187 $headingIndex = $contextNode->getAttribute(
'i' );
1188 $titleText = $this->
title->getPrefixedDBkey();
1189 $this->parser->mHeadings[] =
array( $titleText, $headingIndex );
1190 $serial = count( $this->parser->mHeadings ) - 1;
1191 $marker =
"{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX;
1192 $count = $contextNode->getAttribute(
'level' );
1194 $this->parser->mStripState->addGeneral( $marker,
'' );
1198 # Generic recursive expansion
1199 $newIterator = $contextNode->childNodes;
1203 throw new MWException( __METHOD__ .
': Invalid parameter type' );
1206 if ( $newIterator !==
false ) {
1208 $newIterator = $newIterator->node;
1211 $iteratorStack[] = $newIterator;
1213 } elseif ( $iteratorStack[$level] ===
false ) {
1216 while ( $iteratorStack[$level] ===
false && $level > 0 ) {
1217 $outStack[$level - 1] .=
$out;
1218 array_pop( $outStack );
1219 array_pop( $iteratorStack );
1220 array_pop( $indexStack );
1227 return $outStack[0];
1236 $args = array_slice( func_get_args(), 2 );
1242 $root = $root->node;
1244 if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1245 $root =
array( $root );
1247 foreach ( $root
as $node ) {
1266 $args = array_slice( func_get_args(), 1 );
1272 $root = $root->node;
1274 if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1275 $root =
array( $root );
1277 foreach ( $root
as $node ) {
1296 $args = array_slice( func_get_args(), 1 );
1302 $root = $root->node;
1304 if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1305 $root =
array( $root );
1307 foreach ( $root
as $node ) {
1324 $args = array_slice( func_get_args(), 3 );
1330 $root = $root->node;
1332 if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1333 $root =
array( $root );
1335 foreach ( $root
as $node ) {
1352 function getPDBK( $level =
false ) {
1353 if ( $level ===
false ) {
1354 return $this->
title->getPrefixedDBkey();
1356 return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] :
false;
1450 $this->titleCache =
$parent->titleCache;
1451 $this->titleCache[] = $pdbk;
1452 $this->loopCheckHash =
$parent->loopCheckHash;
1453 if ( $pdbk !==
false ) {
1454 $this->loopCheckHash[$pdbk] =
true;
1456 $this->depth =
$parent->depth + 1;
1457 $this->numberedExpansionCache = $this->namedExpansionCache =
array();
1470 $s .=
"\"$name\":\"" .
1471 str_replace(
'"',
'\\"',
$value->ownerDocument->saveXML(
$value ) ) .
'"';
1483 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
1487 $arguments =
array();
1488 foreach ( array_merge(
1489 array_keys( $this->numberedArgs ),
1490 array_keys( $this->namedArgs ) )
as $key ) {
1497 $arguments =
array();
1498 foreach ( array_keys( $this->numberedArgs )
as $key ) {
1505 $arguments =
array();
1506 foreach ( array_keys( $this->namedArgs )
as $key ) {
1513 if ( !isset( $this->numberedArgs[$index] ) ) {
1516 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1517 # No trimming for unnamed arguments
1518 $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index],
PPFrame::STRIP_COMMENTS );
1520 return $this->numberedExpansionCache[$index];
1524 if ( !isset( $this->namedArgs[
$name] ) ) {
1527 if ( !isset( $this->namedExpansionCache[
$name] ) ) {
1528 # Trim named arguments post-expand, for backwards compatibility
1529 $this->namedExpansionCache[
$name] = trim(
1532 return $this->namedExpansionCache[
$name];
1537 if ( $text ===
false ) {
1562 $this->args =
$args;
1574 $s .=
"\"$name\":\"" .
1575 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1585 return !count( $this->args );
1589 if ( !isset( $this->args[$index] ) ) {
1592 return $this->args[$index];
1612 $this->node =
$node;
1619 if ( $this->xpath ===
null ) {
1620 $this->xpath =
new DOMXPath( $this->node->ownerDocument );
1626 if ( $this->node instanceof DOMNodeList ) {
1628 foreach ( $this->node
as $node ) {
1632 $s = $this->node->ownerDocument->saveXML( $this->node );
1641 return $this->node->childNodes ?
new self( $this->node->childNodes ) :
false;
1648 return $this->node->firstChild ?
new self( $this->node->firstChild ) :
false;
1655 return $this->node->nextSibling ?
new self( $this->node->nextSibling ) :
false;
1664 return new self( $this->
getXPath()->query(
$type, $this->node ) );
1671 if ( $this->node instanceof DOMNodeList ) {
1672 return $this->node->length;
1682 function item( $i ) {
1683 $item = $this->node->item( $i );
1684 return $item ?
new self( $item ) :
false;
1691 if ( $this->node instanceof DOMNodeList ) {
1694 return $this->node->nodeName;
1709 $names =
$xpath->query(
'name', $this->node );
1710 $values =
$xpath->query(
'value', $this->node );
1711 if ( !$names->length || !$values->length ) {
1712 throw new MWException(
'Invalid brace node passed to ' . __METHOD__ );
1714 $name = $names->item( 0 );
1715 $index =
$name->getAttribute(
'index' );
1717 'name' =>
new self(
$name ),
1719 'value' =>
new self( $values->item( 0 ) ) );
1731 $names =
$xpath->query(
'name', $this->node );
1732 $attrs =
$xpath->query(
'attr', $this->node );
1733 $inners =
$xpath->query(
'inner', $this->node );
1734 $closes =
$xpath->query(
'close', $this->node );
1735 if ( !$names->length || !$attrs->length ) {
1736 throw new MWException(
'Invalid ext node passed to ' . __METHOD__ );
1739 'name' =>
new self( $names->item( 0 ) ),
1740 'attr' =>
new self( $attrs->item( 0 ) ) );
1741 if ( $inners->length ) {
1742 $parts[
'inner'] =
new self( $inners->item( 0 ) );
1744 if ( $closes->length ) {
1745 $parts[
'close'] =
new self( $closes->item( 0 ) );
1756 if ( $this->
getName() !==
'h' ) {
1757 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1760 'i' => $this->node->getAttribute(
'i' ),
1761 'level' => $this->node->getAttribute(
'level' ),