64 foreach ( $values
as $k => $val ) {
70 $partNode->addChild( $nameNode );
73 $partNode->addChild( $nameNode );
79 $partNode->addChild( $valueNode );
117 $cacheable = $wgPreprocessorCacheThreshold !==
false && strlen( $text ) > $wgPreprocessorCacheThreshold;
122 $cacheValue =
$wgMemc->get( $cacheKey );
124 $version = substr( $cacheValue, 0, 8 );
125 if ( intval(
$version ) == self::CACHE_VERSION ) {
126 $hash = unserialize( substr( $cacheValue, 8 ) );
129 "Loaded preprocessor hash from memcached (key $cacheKey)" );
150 'names' =>
array( 2 =>
null ),
156 $forInclusion =
$flags & Parser::PTD_FOR_INCLUSION;
158 $xmlishElements = $this->parser->getStripList();
159 $enableOnlyinclude =
false;
160 if ( $forInclusion ) {
161 $ignoredTags =
array(
'includeonly',
'/includeonly' );
162 $ignoredElements =
array(
'noinclude' );
163 $xmlishElements[] =
'noinclude';
164 if ( strpos( $text,
'<onlyinclude>' ) !==
false && strpos( $text,
'</onlyinclude>' ) !==
false ) {
165 $enableOnlyinclude =
true;
168 $ignoredTags =
array(
'noinclude',
'/noinclude',
'onlyinclude',
'/onlyinclude' );
169 $ignoredElements =
array(
'includeonly' );
170 $xmlishElements[] =
'includeonly';
172 $xmlishRegex = implode(
'|', array_merge( $xmlishElements, $ignoredTags ) );
175 $elementsRegex =
"~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
179 $searchBase =
"[{<\n";
180 $revText = strrev( $text );
181 $lengthText = strlen( $text );
183 $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the
start
184 $accum =& $stack->getAccum(); # Current accumulator
185 $findEquals =
false; # True to find equals signs
in arguments
186 $findPipe =
false; # True to take notice
of pipe characters
188 $inHeading =
false; # True
if $i
is inside a possible heading
189 $noMoreGT =
false; # True
if there are no more greater-than (>) signs right
of $i
190 $findOnlyinclude = $enableOnlyinclude;
# True to ignore all input up to the next <onlyinclude>
196 if ( $findOnlyinclude ) {
198 $startPos = strpos( $text,
'<onlyinclude>', $i );
199 if ( $startPos ===
false ) {
201 $accum->addNodeWithText(
'ignore', substr( $text, $i ) );
204 $tagEndPos = $startPos + strlen(
'<onlyinclude>' );
205 $accum->addNodeWithText(
'ignore', substr( $text, $i, $tagEndPos - $i ) );
207 $findOnlyinclude =
false;
210 if ( $fakeLineStart ) {
211 $found =
'line-start';
214 # Find next opening brace, closing brace or pipe
215 $search = $searchBase;
216 if ( $stack->top ===
false ) {
217 $currentClosing =
'';
219 $currentClosing = $stack->top->close;
220 $search .= $currentClosing;
230 # Output literal section, advance input counter
231 $literalLength = strcspn( $text, $search, $i );
232 if ( $literalLength > 0 ) {
233 $accum->addLiteral( substr( $text, $i, $literalLength ) );
234 $i += $literalLength;
236 if ( $i >= $lengthText ) {
237 if ( $currentClosing ==
"\n" ) {
246 $curChar = $text[$i];
247 if ( $curChar ==
'|' ) {
249 } elseif ( $curChar ==
'=' ) {
251 } elseif ( $curChar ==
'<' ) {
253 } elseif ( $curChar ==
"\n" ) {
257 $found =
'line-start';
259 } elseif ( $curChar == $currentClosing ) {
261 } elseif ( isset( $rules[$curChar] ) ) {
263 $rule = $rules[$curChar];
265 # Some versions of PHP have a strcspn which stops on null characters
266 # Ignore and continue
273 if ( $found ==
'angle' ) {
276 if ( $enableOnlyinclude && substr( $text, $i, strlen(
'</onlyinclude>' ) ) ==
'</onlyinclude>' ) {
277 $findOnlyinclude =
true;
282 if ( !preg_match( $elementsRegex, $text,
$matches, 0, $i + 1 ) ) {
284 $accum->addLiteral(
'<' );
297 $endPos = strpos( $text,
'-->', $i + 4 );
298 if ( $endPos ===
false ) {
300 $inner = substr( $text, $i );
301 $accum->addNodeWithText(
'comment', $inner );
305 $wsStart = $i ? ( $i - strspn( $revText,
" \t", $lengthText - $i ) ) : 0;
309 $wsEnd = $endPos + 2 + strspn( $text,
" \t", $endPos + 3 );
313 $comments =
array(
array( $wsStart, $wsEnd ) );
314 while ( substr( $text, $wsEnd + 1, 4 ) ==
'<!--' ) {
315 $c = strpos( $text,
'-->', $wsEnd + 4 );
316 if ( $c ===
false ) {
319 $c = $c + 2 + strspn( $text,
" \t", $c + 3 );
320 $comments[] =
array( $wsEnd + 1, $c );
328 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) ==
"\n"
329 && substr( $text, $wsEnd + 1, 1 ) ==
"\n"
333 $wsLength = $i - $wsStart;
336 && strspn( $accum->lastNode->value,
" \t", -$wsLength ) === $wsLength
338 $accum->lastNode->value = substr( $accum->lastNode->value, 0, -$wsLength );
342 foreach ( $comments
as $j => $com ) {
344 $endPos = $com[1] + 1;
345 if ( $j == ( count( $comments ) - 1 ) ) {
348 $inner = substr( $text, $startPos, $endPos - $startPos );
349 $accum->addNodeWithText(
'comment', $inner );
353 $fakeLineStart =
true;
361 $part = $stack->top->getCurrentPart();
362 if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
363 $part->visualEnd = $wsStart;
366 $part->commentEnd = $endPos;
369 $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
370 $accum->addNodeWithText(
'comment', $inner );
375 $lowerName = strtolower(
$name );
376 $attrStart = $i + strlen(
$name ) + 1;
379 $tagEndPos = $noMoreGT ?
false : strpos( $text,
'>', $attrStart );
380 if ( $tagEndPos ===
false ) {
384 $accum->addLiteral(
'<' );
390 if ( in_array( $lowerName, $ignoredTags ) ) {
391 $accum->addNodeWithText(
'ignore', substr( $text, $i, $tagEndPos - $i + 1 ) );
397 if ( $text[$tagEndPos - 1] ==
'/' ) {
399 $attrEnd = $tagEndPos - 1;
404 $attrEnd = $tagEndPos;
406 if ( preg_match(
"/<\/" . preg_quote(
$name,
'/' ) .
"\s*>/i",
407 $text,
$matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
409 $inner = substr( $text, $tagEndPos + 1,
$matches[0][1] - $tagEndPos - 1 );
414 $inner = substr( $text, $tagEndPos + 1 );
420 if ( in_array( $lowerName, $ignoredElements ) ) {
421 $accum->addNodeWithText(
'ignore', substr( $text, $tagStartPos, $i - $tagStartPos ) );
425 if ( $attrEnd <= $attrStart ) {
430 $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
436 if ( $inner !==
null ) {
439 if ( $close !==
null ) {
442 $accum->addNode( $extNode );
443 } elseif ( $found ==
'line-start' ) {
446 if ( $fakeLineStart ) {
447 $fakeLineStart =
false;
449 $accum->addLiteral( $curChar );
453 $count = strspn( $text,
'=', $i, 6 );
454 if (
$count == 1 && $findEquals ) {
465 $stack->push( $piece );
466 $accum =& $stack->getAccum();
467 extract( $stack->getFlags() );
470 } elseif ( $found ==
'line-end' ) {
471 $piece = $stack->top;
473 assert(
'$piece->open == "\n"' );
474 $part = $piece->getCurrentPart();
477 $wsLength = strspn( $revText,
" \t", $lengthText - $i );
478 $searchStart = $i - $wsLength;
479 if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
482 $searchStart = $part->visualEnd;
483 $searchStart -= strspn( $revText,
" \t", $lengthText - $searchStart );
486 $equalsLength = strspn( $revText,
'=', $lengthText - $searchStart );
487 if ( $equalsLength > 0 ) {
488 if ( $searchStart - $equalsLength == $piece->startPos ) {
506 $element->lastChild->nextSibling = $accum->firstNode;
507 $element->lastChild = $accum->lastNode;
518 $accum =& $stack->getAccum();
519 extract( $stack->getFlags() );
522 if ( $element instanceof
PPNode ) {
523 $accum->addNode( $element );
525 $accum->addAccum( $element );
532 } elseif ( $found ==
'open' ) {
533 # count opening brace characters
534 $count = strspn( $text, $curChar, $i );
536 # we need to add to stack only if opening brace count is enough for one of the rules
537 if (
$count >= $rule[
'min'] ) {
538 # Add it to the stack
541 'close' => $rule[
'end'],
543 'lineStart' => ( $i > 0 && $text[$i - 1] ==
"\n" ),
546 $stack->push( $piece );
547 $accum =& $stack->getAccum();
548 extract( $stack->getFlags() );
550 # Add literal brace(s)
551 $accum->addLiteral( str_repeat( $curChar,
$count ) );
554 } elseif ( $found ==
'close' ) {
555 $piece = $stack->top;
556 # lets check if there are enough characters for closing brace
557 $maxCount = $piece->count;
558 $count = strspn( $text, $curChar, $i, $maxCount );
560 # check for maximum matching characters (if there are 5 closing
561 # characters, we will probably need only 3 - depending on the rules)
562 $rule = $rules[$piece->open];
563 if (
$count > $rule[
'max'] ) {
564 # The specified maximum exists in the callback array, unless the caller
566 $matchingCount = $rule[
'max'];
568 # Count is less than the maximum
569 # Skip any gaps in the callback array to find the true largest match
570 # Need to use array_key_exists not isset because the callback can be null
572 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule[
'names'] ) ) {
577 if ( $matchingCount <= 0 ) {
578 # No matching element found in callback array
579 # Output a literal closing brace and continue
580 $accum->addLiteral( str_repeat( $curChar,
$count ) );
584 $name = $rule[
'names'][$matchingCount];
585 if (
$name ===
null ) {
587 $element = $piece->breakSyntax( $matchingCount );
588 $element->addLiteral( str_repeat( $rule[
'end'], $matchingCount ) );
591 # Note: $parts is already XML, does not need to be encoded further
592 $parts = $piece->parts;
593 $titleAccum = $parts[0]->out;
598 # The invocation is at the start of the line if lineStart is set in
599 # the stack, and all opening brackets are used up.
600 if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
604 $titleNode->firstChild = $titleAccum->firstNode;
605 $titleNode->lastChild = $titleAccum->lastNode;
606 $element->addChild( $titleNode );
608 foreach ( $parts
as $part ) {
609 if ( isset( $part->eqpos ) ) {
612 for ( $node = $part->out->firstNode; $node; $node = $node->nextSibling ) {
613 if ( $node === $part->eqpos ) {
624 throw new MWException( __METHOD__ .
': eqpos not found' );
626 if ( $node->name !==
'equals' ) {
632 throw new MWException( __METHOD__ .
': eqpos is not equals' );
638 if ( $lastNode !==
false ) {
639 $lastNode->nextSibling =
false;
640 $nameNode->firstChild = $part->out->firstNode;
641 $nameNode->lastChild = $lastNode;
646 if ( $equalsNode->nextSibling !==
false ) {
647 $valueNode->firstChild = $equalsNode->nextSibling;
648 $valueNode->lastChild = $part->out->lastNode;
651 $partNode->addChild( $nameNode );
652 $partNode->addChild( $equalsNode->firstChild );
653 $partNode->addChild( $valueNode );
654 $element->addChild( $partNode );
660 $valueNode->firstChild = $part->out->firstNode;
661 $valueNode->lastChild = $part->out->lastNode;
662 $partNode->addChild( $nameNode );
663 $partNode->addChild( $valueNode );
664 $element->addChild( $partNode );
669 # Advance input pointer
670 $i += $matchingCount;
674 $accum =& $stack->getAccum();
676 # Re-add the old stack element if it still has unmatched opening characters remaining
677 if ( $matchingCount < $piece->count ) {
679 $piece->count -= $matchingCount;
680 # do we still qualify for any callback with remaining count?
681 $min = $rules[$piece->open][
'min'];
682 if ( $piece->count >= $min ) {
683 $stack->push( $piece );
684 $accum =& $stack->getAccum();
686 $accum->addLiteral( str_repeat( $piece->open, $piece->count ) );
690 extract( $stack->getFlags() );
692 # Add XML element to the enclosing accumulator
693 if ( $element instanceof
PPNode ) {
694 $accum->addNode( $element );
696 $accum->addAccum( $element );
698 } elseif ( $found ==
'pipe' ) {
701 $accum =& $stack->getAccum();
703 } elseif ( $found ==
'equals' ) {
705 $accum->addNodeWithText(
'equals',
'=' );
706 $stack->getCurrentPart()->eqpos = $accum->lastNode;
711 # Output any remaining unclosed brackets
712 foreach ( $stack->stack
as $piece ) {
713 $stack->rootAccum->addAccum( $piece->breakSyntax() );
716 # Enable top-level headings
717 for ( $node = $stack->rootAccum->firstNode; $node; $node = $node->nextSibling ) {
718 if ( isset( $node->name ) && $node->name ===
'possible-h' ) {
724 $rootNode->firstChild = $stack->rootAccum->firstNode;
725 $rootNode->lastChild = $stack->rootAccum->lastNode;
729 $cacheValue = sprintf(
"%08d", self::CACHE_VERSION ) . serialize( $rootNode );
730 $wgMemc->set( $cacheKey, $cacheValue, 86400 );
733 wfDebugLog(
"Preprocessor",
"Saved preprocessor Hash to memcached (key $cacheKey)" );
747 $this->elementClass =
'PPDStackElement_Hash';
748 parent::__construct();
758 $this->partClass =
'PPDPart_Hash';
759 parent::__construct( $data );
768 if ( $this->
open ==
"\n" ) {
769 $accum = $this->parts[0]->out;
771 if ( $openingCount ===
false ) {
777 foreach ( $this->parts
as $part ) {
781 $accum->addLiteral(
'|' );
783 $accum->addAccum( $part->out );
799 parent::__construct( $accum );
810 $this->firstNode = $this->lastNode =
false;
817 if ( $this->lastNode ===
false ) {
820 $this->lastNode->value .=
$s;
823 $this->lastNode = $this->lastNode->nextSibling;
831 if ( $this->lastNode ===
false ) {
832 $this->firstNode = $this->lastNode = $node;
834 $this->lastNode->nextSibling = $node;
835 $this->lastNode = $node;
853 if ( $accum->lastNode ===
false ) {
855 } elseif ( $this->lastNode ===
false ) {
856 $this->firstNode = $accum->firstNode;
857 $this->lastNode = $accum->lastNode;
859 $this->lastNode->nextSibling = $accum->firstNode;
860 $this->lastNode = $accum->lastNode;
906 $this->
title = $this->parser->mTitle;
908 $this->loopCheckHash =
array();
924 $namedArgs =
array();
925 $numberedArgs =
array();
929 if (
$args !==
false ) {
932 } elseif ( !is_array(
$args ) ) {
933 throw new MWException( __METHOD__ .
': $args must be array or PPNode_Hash_Array' );
936 $bits = $arg->splitArg();
937 if ( $bits[
'index'] !==
'' ) {
939 $index = $bits[
'index'] - $indexOffset;
940 $numberedArgs[$index] = $bits[
'value'];
941 unset( $namedArgs[$index] );
945 $namedArgs[
$name] = $bits[
'value'];
946 unset( $numberedArgs[
$name] );
960 static $expansionDepth = 0;
961 if ( is_string( $root ) ) {
965 if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
966 $this->parser->limitationWarn(
'node-count-exceeded',
967 $this->parser->mPPNodeCount,
968 $this->parser->mOptions->getMaxPPNodeCount()
970 return '<span class="error">Node-count limit exceeded</span>';
972 if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
973 $this->parser->limitationWarn(
'expansion-depth-exceeded',
975 $this->parser->mOptions->getMaxPPExpandDepth()
977 return '<span class="error">Expansion depth limit exceeded</span>';
980 if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
981 $this->parser->mHighestExpansionDepth = $expansionDepth;
984 $outStack =
array(
'',
'' );
985 $iteratorStack =
array(
false, $root );
986 $indexStack =
array( 0, 0 );
988 while ( count( $iteratorStack ) > 1 ) {
989 $level = count( $outStack ) - 1;
990 $iteratorNode =& $iteratorStack[$level];
991 $out =& $outStack[$level];
992 $index =& $indexStack[$level];
994 if ( is_array( $iteratorNode ) ) {
995 if ( $index >= count( $iteratorNode ) ) {
997 $iteratorStack[$level] =
false;
998 $contextNode =
false;
1000 $contextNode = $iteratorNode[$index];
1004 if ( $index >= $iteratorNode->getLength() ) {
1006 $iteratorStack[$level] =
false;
1007 $contextNode =
false;
1009 $contextNode = $iteratorNode->item( $index );
1015 $contextNode = $iteratorStack[$level];
1016 $iteratorStack[$level] =
false;
1019 $newIterator =
false;
1021 if ( $contextNode ===
false ) {
1023 } elseif ( is_string( $contextNode ) ) {
1024 $out .= $contextNode;
1025 } elseif ( is_array( $contextNode ) || $contextNode instanceof
PPNode_Hash_Array ) {
1026 $newIterator = $contextNode;
1030 $out .= $contextNode->value;
1032 if ( $contextNode->name ==
'template' ) {
1033 # Double-brace expansion
1034 $bits = $contextNode->splitTemplate();
1038 $ret = $this->parser->braceSubstitution( $bits, $this );
1039 if ( isset(
$ret[
'object'] ) ) {
1040 $newIterator =
$ret[
'object'];
1045 } elseif ( $contextNode->name ==
'tplarg' ) {
1046 # Triple-brace expansion
1047 $bits = $contextNode->splitTemplate();
1051 $ret = $this->parser->argSubstitution( $bits, $this );
1052 if ( isset(
$ret[
'object'] ) ) {
1053 $newIterator =
$ret[
'object'];
1058 } elseif ( $contextNode->name ==
'comment' ) {
1059 # HTML-style comment
1060 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1061 if ( $this->parser->ot[
'html']
1062 || ( $this->parser->ot[
'pre'] && $this->parser->mOptions->getRemoveComments() )
1067 # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
1068 # Not in RECOVER_COMMENTS mode (extractSections) though
1069 $out .= $this->parser->insertStripItem( $contextNode->firstChild->value );
1071 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1072 $out .= $contextNode->firstChild->value;
1074 } elseif ( $contextNode->name ==
'ignore' ) {
1075 # Output suppression used by <includeonly> etc.
1076 # OT_WIKI will only respect <ignore> in substed templates.
1077 # The other output types respect it unless NO_IGNORE is set.
1078 # extractSections() sets NO_IGNORE and so never respects it.
1080 $out .= $contextNode->firstChild->value;
1084 } elseif ( $contextNode->name ==
'ext' ) {
1086 $bits = $contextNode->splitExt() +
array(
'attr' =>
null,
'inner' =>
null,
'close' =>
null );
1087 $out .= $this->parser->extensionSubstitution( $bits, $this );
1088 } elseif ( $contextNode->name ==
'h' ) {
1090 if ( $this->parser->ot[
'html'] ) {
1091 # Expand immediately and insert heading index marker
1093 for ( $node = $contextNode->firstChild; $node; $node = $node->nextSibling ) {
1097 $bits = $contextNode->splitHeading();
1098 $titleText = $this->
title->getPrefixedDBkey();
1099 $this->parser->mHeadings[] =
array( $titleText, $bits[
'i'] );
1100 $serial = count( $this->parser->mHeadings ) - 1;
1101 $marker =
"{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX;
1102 $s = substr(
$s, 0, $bits[
'level'] ) . $marker . substr(
$s, $bits[
'level'] );
1103 $this->parser->mStripState->addGeneral( $marker,
'' );
1106 # Expand in virtual stack
1107 $newIterator = $contextNode->getChildren();
1110 # Generic recursive expansion
1111 $newIterator = $contextNode->getChildren();
1114 throw new MWException( __METHOD__ .
': Invalid parameter type' );
1117 if ( $newIterator !==
false ) {
1119 $iteratorStack[] = $newIterator;
1121 } elseif ( $iteratorStack[$level] ===
false ) {
1124 while ( $iteratorStack[$level] ===
false && $level > 0 ) {
1125 $outStack[$level - 1] .=
$out;
1126 array_pop( $outStack );
1127 array_pop( $iteratorStack );
1128 array_pop( $indexStack );
1134 return $outStack[0];
1143 $args = array_slice( func_get_args(), 2 );
1149 $root = $root->value;
1151 if ( !is_array( $root ) ) {
1152 $root =
array( $root );
1154 foreach ( $root
as $node ) {
1172 $args = array_slice( func_get_args(), 1 );
1178 $root = $root->value;
1180 if ( !is_array( $root ) ) {
1181 $root =
array( $root );
1183 foreach ( $root
as $node ) {
1202 $args = array_slice( func_get_args(), 1 );
1208 $root = $root->value;
1210 if ( !is_array( $root ) ) {
1211 $root =
array( $root );
1213 foreach ( $root
as $node ) {
1231 $args = array_slice( func_get_args(), 3 );
1237 $root = $root->value;
1239 if ( !is_array( $root ) ) {
1240 $root =
array( $root );
1242 foreach ( $root
as $node ) {
1263 function getPDBK( $level =
false ) {
1264 if ( $level ===
false ) {
1265 return $this->
title->getPrefixedDBkey();
1267 return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] :
false;
1362 $this->titleCache =
$parent->titleCache;
1363 $this->titleCache[] = $pdbk;
1364 $this->loopCheckHash =
$parent->loopCheckHash;
1365 if ( $pdbk !==
false ) {
1366 $this->loopCheckHash[$pdbk] =
true;
1369 $this->numberedExpansionCache = $this->namedExpansionCache =
array();
1382 $s .=
"\"$name\":\"" .
1383 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1395 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
1402 $arguments =
array();
1403 foreach ( array_merge(
1404 array_keys( $this->numberedArgs ),
1405 array_keys( $this->namedArgs ) )
as $key ) {
1415 $arguments =
array();
1416 foreach ( array_keys( $this->numberedArgs )
as $key ) {
1426 $arguments =
array();
1427 foreach ( array_keys( $this->namedArgs )
as $key ) {
1438 if ( !isset( $this->numberedArgs[$index] ) ) {
1441 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1442 # No trimming for unnamed arguments
1443 $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index],
PPFrame::STRIP_COMMENTS );
1445 return $this->numberedExpansionCache[$index];
1453 if ( !isset( $this->namedArgs[
$name] ) ) {
1456 if ( !isset( $this->namedExpansionCache[
$name] ) ) {
1457 # Trim named arguments post-expand, for backwards compatibility
1458 $this->namedExpansionCache[
$name] = trim(
1461 return $this->namedExpansionCache[
$name];
1470 if ( $text ===
false ) {
1495 $this->args =
$args;
1507 $s .=
"\"$name\":\"" .
1508 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1518 return !count( $this->args );
1526 if ( !isset( $this->args[$index] ) ) {
1529 return $this->args[$index];
1545 $this->firstChild = $this->lastChild = $this->nextSibling =
false;
1551 for ( $node = $this->firstChild; $node; $node = $node->nextSibling ) {
1553 $attribs .=
' ' . $node->name .
'="' . htmlspecialchars( $node->value ) .
'"';
1555 $inner .= $node->__toString();
1558 if ( $inner ===
'' ) {
1559 return "<{$this->name}$attribs/>";
1561 return "<{$this->name}$attribs>$inner</{$this->name}>";
1571 $obj =
new self(
$name );
1577 if ( $this->lastChild ===
false ) {
1578 $this->firstChild = $this->lastChild = $node;
1580 $this->lastChild->nextSibling = $node;
1581 $this->lastChild = $node;
1589 $children =
array();
1590 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1591 $children[] = $child;
1605 $children =
array();
1606 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1607 if ( isset( $child->name ) && $child->name ===
$name ) {
1608 $children[] = $child;
1625 function item( $i ) {
1647 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1648 if ( !isset( $child->name ) ) {
1651 if ( $child->name ===
'name' ) {
1652 $bits[
'name'] = $child;
1654 && $child->firstChild->name ===
'index'
1656 $bits[
'index'] = $child->firstChild->value;
1658 } elseif ( $child->name ===
'value' ) {
1659 $bits[
'value'] = $child;
1663 if ( !isset( $bits[
'name'] ) ) {
1664 throw new MWException(
'Invalid brace node passed to ' . __METHOD__ );
1666 if ( !isset( $bits[
'index'] ) ) {
1667 $bits[
'index'] =
'';
1681 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1682 if ( !isset( $child->name ) ) {
1685 if ( $child->name ==
'name' ) {
1686 $bits[
'name'] = $child;
1687 } elseif ( $child->name ==
'attr' ) {
1688 $bits[
'attr'] = $child;
1689 } elseif ( $child->name ==
'inner' ) {
1690 $bits[
'inner'] = $child;
1691 } elseif ( $child->name ==
'close' ) {
1692 $bits[
'close'] = $child;
1695 if ( !isset( $bits[
'name'] ) ) {
1696 throw new MWException(
'Invalid ext node passed to ' . __METHOD__ );
1708 if ( $this->
name !==
'h' ) {
1709 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1712 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1713 if ( !isset( $child->name ) ) {
1716 if ( $child->name ==
'i' ) {
1717 $bits[
'i'] = $child->value;
1718 } elseif ( $child->name ==
'level' ) {
1719 $bits[
'level'] = $child->value;
1722 if ( !isset( $bits[
'i'] ) ) {
1723 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1736 $bits =
array(
'lineStart' =>
'' );
1737 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1738 if ( !isset( $child->name ) ) {
1741 if ( $child->name ==
'title' ) {
1742 $bits[
'title'] = $child;
1744 if ( $child->name ==
'part' ) {
1747 if ( $child->name ==
'lineStart' ) {
1748 $bits[
'lineStart'] =
'1';
1751 if ( !isset( $bits[
'title'] ) ) {
1752 throw new MWException(
'Invalid node passed to ' . __METHOD__ );
1766 if ( is_object(
$value ) ) {
1767 throw new MWException( __CLASS__ .
' given object instead of string' );
1773 return htmlspecialchars( $this->value );
1784 function item( $i ) {
return false; }
1785 function getName() {
return '#text'; }
1802 return var_export( $this,
true );
1806 return count( $this->value );
1810 return $this->value[$i];
1813 function getName() {
return '#nodelist'; }
1839 return "<@{$this->name}>" . htmlspecialchars( $this->value ) .
"</@{$this->name}>";
1854 function item( $i ) {
return false; }