80 foreach ( $values
as $k => $val ) {
82 $store = [ [
'part', [
83 [
'name', [ [
'@index', [ $k ] ] ] ],
84 [
'value', [ strval( $val ) ] ],
87 $store = [ [
'part', [
88 [
'name', [ strval( $k ) ] ],
90 [
'value', [ strval( $val ) ] ],
120 global $wgDisableLangConversion;
123 if ( $tree !==
false ) {
124 $store = json_decode( $tree );
125 if ( is_array( $store ) ) {
130 $forInclusion =
$flags & Parser::PTD_FOR_INCLUSION;
132 $xmlishElements = $this->
parser->getStripList();
133 $xmlishAllowMissingEndTag = [
'includeonly',
'noinclude',
'onlyinclude' ];
134 $enableOnlyinclude =
false;
135 if ( $forInclusion ) {
136 $ignoredTags = [
'includeonly',
'/includeonly' ];
137 $ignoredElements = [
'noinclude' ];
138 $xmlishElements[] =
'noinclude';
139 if ( strpos( $text,
'<onlyinclude>' ) !==
false
140 && strpos( $text,
'</onlyinclude>' ) !==
false
142 $enableOnlyinclude =
true;
145 $ignoredTags = [
'noinclude',
'/noinclude',
'onlyinclude',
'/onlyinclude' ];
146 $ignoredElements = [
'includeonly' ];
147 $xmlishElements[] =
'includeonly';
149 $xmlishRegex = implode(
'|', array_merge( $xmlishElements, $ignoredTags ) );
152 $elementsRegex =
"~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
156 $searchBase =
"[{<\n";
157 if ( !$wgDisableLangConversion ) {
163 $revText = strrev( $text );
164 $lengthText = strlen( $text );
169 $accum =& $stack->getAccum();
180 $noMoreClosingTag = [];
182 $findOnlyinclude = $enableOnlyinclude;
184 $fakeLineStart =
true;
189 if ( $findOnlyinclude ) {
191 $startPos = strpos( $text,
'<onlyinclude>', $i );
192 if ( $startPos ===
false ) {
194 $accum[] = [
'ignore', [ substr( $text, $i ) ] ];
197 $tagEndPos = $startPos + strlen(
'<onlyinclude>' );
198 $accum[] = [
'ignore', [ substr( $text, $i, $tagEndPos - $i ) ] ];
200 $findOnlyinclude =
false;
203 if ( $fakeLineStart ) {
204 $found =
'line-start';
207 # Find next opening brace, closing brace or pipe
208 $search = $searchBase;
209 if ( $stack->top ===
false ) {
210 $currentClosing =
'';
212 $currentClosing = $stack->top->close;
213 $search .= $currentClosing;
223 # Output literal section, advance input counter
224 $literalLength = strcspn( $text, $search, $i );
225 if ( $literalLength > 0 ) {
227 $i += $literalLength;
229 if ( $i >= $lengthText ) {
230 if ( $currentClosing ==
"\n" ) {
239 $curChar = $curTwoChar = $text[$i];
240 if ( ( $i + 1 ) < $lengthText ) {
241 $curTwoChar .= $text[$i + 1];
243 if ( $curChar ==
'|' ) {
245 } elseif ( $curChar ==
'=' ) {
247 } elseif ( $curChar ==
'<' ) {
249 } elseif ( $curChar ==
"\n" ) {
253 $found =
'line-start';
255 } elseif ( $curTwoChar == $currentClosing ) {
257 $curChar = $curTwoChar;
258 } elseif ( $curChar == $currentClosing ) {
260 } elseif ( isset( $this->rules[$curTwoChar] ) ) {
261 $curChar = $curTwoChar;
263 $rule = $this->rules[$curChar];
264 } elseif ( isset( $this->rules[$curChar] ) ) {
266 $rule = $this->rules[$curChar];
267 } elseif ( $curChar ==
'-' ) {
270 # Some versions of PHP have a strcspn which stops on null characters
271 # Ignore and continue
278 if ( $found ==
'angle' ) {
281 if ( $enableOnlyinclude
282 && substr( $text, $i, strlen(
'</onlyinclude>' ) ) ==
'</onlyinclude>'
284 $findOnlyinclude =
true;
289 if ( !preg_match( $elementsRegex, $text,
$matches, 0, $i + 1 ) ) {
304 $endPos = strpos( $text,
'-->', $i + 4 );
305 if ( $endPos ===
false ) {
307 $inner = substr( $text, $i );
308 $accum[] = [
'comment', [ $inner ] ];
312 $wsStart = $i ? ( $i - strspn( $revText,
" \t", $lengthText - $i ) ) : 0;
316 $wsEnd = $endPos + 2 + strspn( $text,
" \t", $endPos + 3 );
320 $comments = [ [ $wsStart, $wsEnd ] ];
321 while ( substr( $text, $wsEnd + 1, 4 ) ==
'<!--' ) {
322 $c = strpos( $text,
'-->', $wsEnd + 4 );
323 if ( $c ===
false ) {
326 $c = $c + 2 + strspn( $text,
" \t", $c + 3 );
327 $comments[] = [ $wsEnd + 1, $c ];
335 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) ==
"\n"
336 && substr( $text, $wsEnd + 1, 1 ) ==
"\n"
339 $wsLength = $i - $wsStart;
340 $endIndex =
count( $accum ) - 1;
345 && is_string( $accum[$endIndex] )
346 && strspn( $accum[$endIndex],
" \t", -$wsLength ) === $wsLength
348 $accum[$endIndex] = substr( $accum[$endIndex], 0, -$wsLength );
352 foreach ( $comments
as $j => $com ) {
354 $endPos = $com[1] + 1;
355 if ( $j == (
count( $comments ) - 1 ) ) {
358 $inner = substr( $text, $startPos, $endPos - $startPos );
359 $accum[] = [
'comment', [ $inner ] ];
363 $fakeLineStart =
true;
371 $part = $stack->top->getCurrentPart();
372 if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
373 $part->visualEnd = $wsStart;
376 $part->commentEnd = $endPos;
379 $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
380 $accum[] = [
'comment', [ $inner ] ];
385 $lowerName = strtolower(
$name );
386 $attrStart = $i + strlen(
$name ) + 1;
389 $tagEndPos = $noMoreGT ?
false : strpos( $text,
'>', $attrStart );
390 if ( $tagEndPos ===
false ) {
400 if ( in_array( $lowerName, $ignoredTags ) ) {
401 $accum[] = [
'ignore', [ substr( $text, $i, $tagEndPos - $i + 1 ) ] ];
407 if ( $text[$tagEndPos - 1] ==
'/' ) {
409 $attrEnd = $tagEndPos - 1;
414 $attrEnd = $tagEndPos;
417 !isset( $noMoreClosingTag[
$name] ) &&
418 preg_match(
"/<\/" . preg_quote(
$name,
'/' ) .
"\s*>/i",
419 $text,
$matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
421 $inner = substr( $text, $tagEndPos + 1,
$matches[0][1] - $tagEndPos - 1 );
426 if ( in_array(
$name, $xmlishAllowMissingEndTag ) ) {
428 $inner = substr( $text, $tagEndPos + 1 );
435 substr( $text, $tagStartPos, $tagEndPos + 1 - $tagStartPos ) );
437 $noMoreClosingTag[
$name] =
true;
443 if ( in_array( $lowerName, $ignoredElements ) ) {
444 $accum[] = [
'ignore', [ substr( $text, $tagStartPos, $i - $tagStartPos ) ] ];
448 if ( $attrEnd <= $attrStart ) {
453 $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
457 [
'name', [
$name ] ],
458 [
'attr', [ $attr ] ] ];
459 if ( $inner !==
null ) {
460 $children[] = [
'inner', [ $inner ] ];
462 if ( $close !==
null ) {
463 $children[] = [
'close', [ $close ] ];
465 $accum[] = [
'ext', $children ];
466 } elseif ( $found ==
'line-start' ) {
469 if ( $fakeLineStart ) {
470 $fakeLineStart =
false;
476 $count = strspn( $text,
'=', $i, 6 );
477 if ( $count == 1 && $findEquals ) {
482 } elseif ( $count > 0 ) {
486 'parts' => [
new PPDPart_Hash( str_repeat(
'=', $count ) ) ],
489 $stack->push( $piece );
490 $accum =& $stack->getAccum();
491 extract( $stack->getFlags() );
494 } elseif ( $found ==
'line-end' ) {
495 $piece = $stack->top;
497 assert( $piece->open ===
"\n" );
498 $part = $piece->getCurrentPart();
502 $wsLength = strspn( $revText,
" \t", $lengthText - $i );
503 $searchStart = $i - $wsLength;
504 if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
507 $searchStart = $part->visualEnd;
508 $searchStart -= strspn( $revText,
" \t", $lengthText - $searchStart );
510 $count = $piece->count;
511 $equalsLength = strspn( $revText,
'=', $lengthText - $searchStart );
512 if ( $equalsLength > 0 ) {
513 if ( $searchStart - $equalsLength == $piece->startPos ) {
517 $count = $equalsLength;
521 $count = min( 6, intval( ( $count - 1 ) / 2 ) );
524 $count = min( $equalsLength, $count );
528 $element = [ [
'possible-h',
531 [
'@level', [ $count ] ],
532 [
'@i', [ $headingIndex++ ] ]
547 $accum =& $stack->getAccum();
548 extract( $stack->getFlags() );
551 array_splice( $accum,
count( $accum ), 0, $element );
558 } elseif ( $found ==
'open' ) {
559 # count opening brace characters
560 $curLen = strlen( $curChar );
561 $count = ( $curLen > 1 ) ? 1 : strspn( $text, $curChar, $i );
563 # we need to add to stack only if opening brace count is enough for one of the rules
564 if ( $count >= $rule[
'min'] ) {
565 # Add it to the stack
568 'close' => $rule[
'end'],
570 'lineStart' => ( $i > 0 && $text[$i - 1] ==
"\n" ),
573 $stack->push( $piece );
574 $accum =& $stack->getAccum();
575 extract( $stack->getFlags() );
577 # Add literal brace(s)
580 $i += $curLen * $count;
581 } elseif ( $found ==
'close' ) {
582 $piece = $stack->top;
583 # lets check if there are enough characters for closing brace
584 $maxCount = $piece->count;
585 $curLen = strlen( $curChar );
586 $count = ( $curLen > 1 ) ? 1 : strspn( $text, $curChar, $i, $maxCount );
588 # check for maximum matching characters (if there are 5 closing
589 # characters, we will probably need only 3 - depending on the rules)
590 $rule = $this->rules[$piece->open];
591 if ( $count > $rule[
'max'] ) {
592 # The specified maximum exists in the callback array, unless the caller
594 $matchingCount = $rule[
'max'];
596 # Count is less than the maximum
597 # Skip any gaps in the callback array to find the true largest match
598 # Need to use array_key_exists not isset because the callback can be null
599 $matchingCount = $count;
600 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule[
'names'] ) ) {
605 if ( $matchingCount <= 0 ) {
606 # No matching element found in callback array
607 # Output a literal closing brace and continue
609 $i += $curLen * $count;
612 $name = $rule[
'names'][$matchingCount];
613 if (
$name ===
null ) {
615 $element = $piece->breakSyntax( $matchingCount );
619 $parts = $piece->parts;
620 $titleAccum = $parts[0]->out;
625 # The invocation is at the start of the line if lineStart is set in
626 # the stack, and all opening brackets are used up.
627 if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
628 $children[] = [
'@lineStart', [ 1 ] ];
630 $titleNode = [
'title', $titleAccum ];
631 $children[] = $titleNode;
633 foreach ( $parts
as $part ) {
634 if ( isset( $part->eqpos ) ) {
635 $equalsNode = $part->out[$part->eqpos];
636 $nameNode = [
'name', array_slice( $part->out, 0, $part->eqpos ) ];
637 $valueNode = [
'value', array_slice( $part->out, $part->eqpos + 1 ) ];
638 $partNode = [
'part', [ $nameNode, $equalsNode, $valueNode ] ];
639 $children[] = $partNode;
641 $nameNode = [
'name', [ [
'@index', [ $argIndex++ ] ] ] ];
642 $valueNode = [
'value', $part->out ];
643 $partNode = [
'part', [ $nameNode, $valueNode ] ];
644 $children[] = $partNode;
647 $element = [ [
$name, $children ] ];
650 # Advance input pointer
651 $i += $curLen * $matchingCount;
655 $accum =& $stack->getAccum();
657 # Re-add the old stack element if it still has unmatched opening characters remaining
658 if ( $matchingCount < $piece->
count ) {
660 $piece->count -= $matchingCount;
661 # do we still qualify for any callback with remaining count?
662 $min = $this->rules[$piece->open][
'min'];
663 if ( $piece->count >= $min ) {
664 $stack->push( $piece );
665 $accum =& $stack->getAccum();
671 extract( $stack->getFlags() );
673 # Add XML element to the enclosing accumulator
674 array_splice( $accum,
count( $accum ), 0, $element );
675 } elseif ( $found ==
'pipe' ) {
678 $accum =& $stack->getAccum();
680 } elseif ( $found ==
'equals' ) {
682 $accum[] = [
'equals', [
'=' ] ];
683 $stack->getCurrentPart()->eqpos =
count( $accum ) - 1;
685 } elseif ( $found ==
'dash' ) {
691 # Output any remaining unclosed brackets
692 foreach ( $stack->stack
as $piece ) {
693 array_splice( $stack->rootAccum,
count( $stack->rootAccum ), 0, $piece->breakSyntax() );
696 # Enable top-level headings
697 foreach ( $stack->rootAccum
as &$node ) {
703 $rootStore = [ [
'root', $stack->rootAccum ] ];
707 $tree = json_encode( $rootStore, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
708 if ( $tree !==
false ) {
716 $n =
count( $accum );
717 if ( $n && is_string( $accum[$n - 1] ) ) {
718 $accum[$n - 1] .= $text;
734 $this->elementClass =
'PPDStackElement_Hash';
735 parent::__construct();
736 $this->rootAccum = [];
748 $this->partClass =
'PPDPart_Hash';
749 parent::__construct( $data );
759 if ( $this->
open ==
"\n" ) {
760 $accum = $this->parts[0]->out;
762 if ( $openingCount ===
false ) {
765 $accum = [ str_repeat( $this->
open, $openingCount ) ];
768 foreach ( $this->parts
as $part ) {
771 } elseif ( is_string( $accum[$lastIndex] ) ) {
772 $accum[$lastIndex] .=
'|';
774 $accum[++$lastIndex] =
'|';
776 foreach ( $part->out
as $node ) {
777 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
778 $accum[$lastIndex] .= $node;
780 $accum[++$lastIndex] = $node;
802 parent::__construct( $accum );
858 $this->titleCache = [ $this->
title ? $this->
title->getPrefixedDBkey() :
false ];
859 $this->loopCheckHash = [];
861 $this->childExpansionCache = [];
880 if (
$args !==
false ) {
883 } elseif ( !is_array(
$args ) ) {
884 throw new MWException( __METHOD__ .
': $args must be array or PPNode_Hash_Array' );
887 $bits = $arg->splitArg();
888 if ( $bits[
'index'] !==
'' ) {
890 $index = $bits[
'index'] - $indexOffset;
891 if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
892 $this->
parser->getOutput()->addWarning(
wfMessage(
'duplicate-args-warning',
896 $this->
parser->addTrackingCategory(
'duplicate-args-category' );
898 $numberedArgs[$index] = $bits[
'value'];
899 unset( $namedArgs[$index] );
903 if ( isset( $namedArgs[
$name] ) || isset( $numberedArgs[
$name] ) ) {
904 $this->
parser->getOutput()->addWarning(
wfMessage(
'duplicate-args-warning',
908 $this->
parser->addTrackingCategory(
'duplicate-args-category' );
910 $namedArgs[
$name] = $bits[
'value'];
911 unset( $numberedArgs[
$name] );
937 static $expansionDepth = 0;
938 if ( is_string( $root ) ) {
942 if ( ++$this->
parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
943 $this->
parser->limitationWarn(
'node-count-exceeded',
944 $this->
parser->mPPNodeCount,
945 $this->parser->mOptions->getMaxPPNodeCount()
947 return '<span class="error">Node-count limit exceeded</span>';
949 if ( $expansionDepth > $this->
parser->mOptions->getMaxPPExpandDepth() ) {
950 $this->
parser->limitationWarn(
'expansion-depth-exceeded',
952 $this->
parser->mOptions->getMaxPPExpandDepth()
954 return '<span class="error">Expansion depth limit exceeded</span>';
957 if ( $expansionDepth > $this->
parser->mHighestExpansionDepth ) {
958 $this->
parser->mHighestExpansionDepth = $expansionDepth;
961 $outStack = [
'',
'' ];
962 $iteratorStack = [
false, $root ];
963 $indexStack = [ 0, 0 ];
965 while (
count( $iteratorStack ) > 1 ) {
966 $level =
count( $outStack ) - 1;
967 $iteratorNode =& $iteratorStack[$level];
968 $out =& $outStack[$level];
969 $index =& $indexStack[$level];
971 if ( is_array( $iteratorNode ) ) {
972 if ( $index >=
count( $iteratorNode ) ) {
974 $iteratorStack[$level] =
false;
975 $contextNode =
false;
977 $contextNode = $iteratorNode[$index];
981 if ( $index >= $iteratorNode->getLength() ) {
983 $iteratorStack[$level] =
false;
984 $contextNode =
false;
986 $contextNode = $iteratorNode->item( $index );
992 $contextNode = $iteratorStack[$level];
993 $iteratorStack[$level] =
false;
996 $newIterator =
false;
997 $contextName =
false;
998 $contextChildren =
false;
1000 if ( $contextNode ===
false ) {
1002 } elseif ( is_string( $contextNode ) ) {
1003 $out .= $contextNode;
1005 $newIterator = $contextNode;
1009 $out .= $contextNode->value;
1011 $contextName = $contextNode->name;
1012 $contextChildren = $contextNode->getRawChildren();
1013 } elseif ( is_array( $contextNode ) ) {
1015 if (
count( $contextNode ) !== 2 ) {
1017 ': found an array where a node descriptor should be' );
1019 list( $contextName, $contextChildren ) = $contextNode;
1021 throw new MWException( __METHOD__ .
': Invalid parameter type' );
1025 if ( $contextName ===
false ) {
1027 } elseif ( $contextName[0] ===
'@' ) {
1029 } elseif ( $contextName ===
'template' ) {
1030 # Double-brace expansion
1039 $ret = $this->
parser->braceSubstitution( $bits, $this );
1040 if ( isset(
$ret[
'object'] ) ) {
1041 $newIterator =
$ret[
'object'];
1046 } elseif ( $contextName ===
'tplarg' ) {
1047 # Triple-brace expansion
1056 $ret = $this->
parser->argSubstitution( $bits, $this );
1057 if ( isset(
$ret[
'object'] ) ) {
1058 $newIterator =
$ret[
'object'];
1063 } elseif ( $contextName ===
'comment' ) {
1064 # HTML-style comment
1065 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1066 # Not in RECOVER_COMMENTS mode (msgnw) though.
1067 if ( ( $this->
parser->ot[
'html']
1068 || ( $this->parser->ot[
'pre'] && $this->parser->mOptions->getRemoveComments() )
1073 } elseif ( $this->
parser->ot[
'wiki'] && !(
$flags & PPFrame::RECOVER_COMMENTS ) ) {
1074 # Add a strip marker in PST mode so that pstPass2() can
1075 # run some old-fashioned regexes on the result.
1076 # Not in RECOVER_COMMENTS mode (extractSections) though.
1077 $out .= $this->
parser->insertStripItem( $contextChildren[0] );
1079 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1080 $out .= $contextChildren[0];
1082 } elseif ( $contextName ===
'ignore' ) {
1083 # Output suppression used by <includeonly> etc.
1084 # OT_WIKI will only respect <ignore> in substed templates.
1085 # The other output types respect it unless NO_IGNORE is set.
1086 # extractSections() sets NO_IGNORE and so never respects it.
1087 if ( ( !isset( $this->parent ) && $this->
parser->ot[
'wiki'] )
1090 $out .= $contextChildren[0];
1094 } elseif ( $contextName ===
'ext' ) {
1097 [
'attr' =>
null,
'inner' =>
null,
'close' => null ];
1099 $s =
'<' . $bits[
'name']->getFirstChild()->value;
1100 if ( $bits[
'attr'] ) {
1101 $s .= $bits[
'attr']->getFirstChild()->value;
1103 if ( $bits[
'inner'] ) {
1104 $s .=
'>' . $bits[
'inner']->getFirstChild()->value;
1105 if ( $bits[
'close'] ) {
1106 $s .= $bits[
'close']->getFirstChild()->value;
1113 $out .= $this->
parser->extensionSubstitution( $bits, $this );
1115 } elseif ( $contextName ===
'h' ) {
1117 if ( $this->
parser->ot[
'html'] ) {
1118 # Expand immediately and insert heading index marker
1121 $titleText = $this->
title->getPrefixedDBkey();
1122 $this->
parser->mHeadings[] = [ $titleText, $bits[
'i'] ];
1124 $marker = Parser::MARKER_PREFIX .
"-h-$serial-" . Parser::MARKER_SUFFIX;
1125 $s = substr(
$s, 0, $bits[
'level'] ) . $marker . substr(
$s, $bits[
'level'] );
1126 $this->
parser->mStripState->addGeneral( $marker,
'' );
1129 # Expand in virtual stack
1130 $newIterator = $contextChildren;
1133 # Generic recursive expansion
1134 $newIterator = $contextChildren;
1137 if ( $newIterator !==
false ) {
1139 $iteratorStack[] = $newIterator;
1141 } elseif ( $iteratorStack[$level] ===
false ) {
1144 while ( $iteratorStack[$level] ===
false && $level > 0 ) {
1145 $outStack[$level - 1] .=
$out;
1146 array_pop( $outStack );
1147 array_pop( $iteratorStack );
1148 array_pop( $indexStack );
1154 return $outStack[0];
1164 $args = array_slice( func_get_args(), 2 );
1170 $root = $root->value;
1172 if ( !is_array( $root ) ) {
1175 foreach ( $root
as $node ) {
1195 $args = array_slice( func_get_args(), 1 );
1201 $root = $root->value;
1203 if ( !is_array( $root ) ) {
1206 foreach ( $root
as $node ) {
1227 $args = array_slice( func_get_args(), 1 );
1233 $root = $root->value;
1235 if ( !is_array( $root ) ) {
1238 foreach ( $root
as $node ) {
1260 $args = array_slice( func_get_args(), 3 );
1266 $root = $root->value;
1268 if ( !is_array( $root ) ) {
1271 foreach ( $root
as $node ) {
1293 if ( $level ===
false ) {
1294 return $this->
title->getPrefixedDBkey();
1296 return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] :
false;
1373 $this->
volatile = $flag;
1391 if (
$ttl !==
null && ( $this->ttl ===
null || $ttl < $this->ttl ) ) {
1434 $this->titleCache =
$parent->titleCache;
1435 $this->titleCache[] = $pdbk;
1436 $this->loopCheckHash =
$parent->loopCheckHash;
1437 if ( $pdbk !==
false ) {
1438 $this->loopCheckHash[$pdbk] =
true;
1440 $this->depth =
$parent->depth + 1;
1441 $this->numberedExpansionCache = $this->namedExpansionCache = [];
1454 $s .=
"\"$name\":\"" .
1455 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1469 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
1470 return $this->parent->childExpansionCache[$key];
1474 $this->parent->childExpansionCache[$key] =
$retval;
1485 return !
count( $this->numberedArgs ) && !
count( $this->namedArgs );
1493 foreach ( array_merge(
1494 array_keys( $this->numberedArgs ),
1495 array_keys( $this->namedArgs ) )
as $key ) {
1506 foreach ( array_keys( $this->numberedArgs )
as $key ) {
1517 foreach ( array_keys( $this->namedArgs )
as $key ) {
1528 if ( !isset( $this->numberedArgs[$index] ) ) {
1531 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1532 # No trimming for unnamed arguments
1533 $this->numberedExpansionCache[$index] = $this->parent->expand(
1534 $this->numberedArgs[$index],
1538 return $this->numberedExpansionCache[$index];
1546 if ( !isset( $this->namedArgs[
$name] ) ) {
1549 if ( !isset( $this->namedExpansionCache[
$name] ) ) {
1550 # Trim named arguments post-expand, for backwards compatibility
1551 $this->namedExpansionCache[
$name] = trim(
1554 return $this->namedExpansionCache[
$name];
1563 if ( $text ===
false ) {
1579 parent::setVolatile( $flag );
1580 $this->parent->setVolatile( $flag );
1584 parent::setTTL(
$ttl );
1585 $this->parent->setTTL(
$ttl );
1613 $s .=
"\"$name\":\"" .
1614 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1632 if ( !isset( $this->
args[$index] ) ) {
1635 return $this->
args[$index];
1708 if ( is_string( $descriptor ) ) {
1709 $class =
'PPNode_Hash_Text';
1710 } elseif ( is_array( $descriptor ) ) {
1711 if ( $descriptor[self::NAME][0] ===
'@' ) {
1712 $class =
'PPNode_Hash_Attr';
1714 $class =
'PPNode_Hash_Tree';
1717 throw new MWException( __METHOD__.
': invalid node descriptor' );
1728 for ( $node = $this->
getFirstChild(); $node; $node = $node->getNextSibling() ) {
1730 $attribs .=
' ' . $node->name .
'="' . htmlspecialchars( $node->value ) .
'"';
1732 $inner .= $node->__toString();
1735 if ( $inner ===
'' ) {
1736 return "<{$this->name}$attribs/>";
1738 return "<{$this->name}$attribs>$inner</{$this->name}>";
1747 foreach ( $this->rawChildren
as $i => $child ) {
1761 if ( !isset( $this->rawChildren[0] ) ) {
1787 foreach ( $this->rawChildren
as $i => $child ) {
1788 if ( is_array( $child ) && $child[self::NAME] ===
$name ) {
1843 foreach ( $children
as $i => $child ) {
1844 if ( !is_array( $child ) ) {
1847 if ( $child[self::NAME] ===
'name' ) {
1848 $bits[
'name'] =
new self( $children, $i );
1849 if ( isset( $child[self::CHILDREN][0][self::NAME] )
1854 } elseif ( $child[self::NAME] ===
'value' ) {
1855 $bits[
'value'] =
new self( $children, $i );
1859 if ( !isset( $bits[
'name'] ) ) {
1860 throw new MWException(
'Invalid brace node passed to ' . __METHOD__ );
1862 if ( !isset( $bits[
'index'] ) ) {
1863 $bits[
'index'] =
'';
1884 foreach ( $children
as $i => $child ) {
1885 if ( !is_array( $child ) ) {
1888 switch ( $child[self::NAME] ) {
1890 $bits[
'name'] =
new self( $children, $i );
1893 $bits[
'attr'] =
new self( $children, $i );
1896 $bits[
'inner'] =
new self( $children, $i );
1899 $bits[
'close'] =
new self( $children, $i );
1903 if ( !isset( $bits[
'name'] ) ) {
1904 throw new MWException(
'Invalid ext node passed to ' . __METHOD__ );
1916 if ( $this->
name !==
'h' ) {
1917 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1927 foreach ( $children
as $i => $child ) {
1928 if ( !is_array( $child ) ) {
1931 if ( $child[self::NAME] ===
'@i' ) {
1933 } elseif ( $child[self::NAME] ===
'@level' ) {
1937 if ( !isset( $bits[
'i'] ) ) {
1938 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1958 $bits = [
'lineStart' =>
'' ];
1959 foreach ( $children
as $i => $child ) {
1960 if ( !is_array( $child ) ) {
1963 switch ( $child[self::NAME] ) {
1965 $bits[
'title'] =
new self( $children, $i );
1968 $parts[] =
new self( $children, $i );
1971 $bits[
'lineStart'] =
'1';
1975 if ( !isset( $bits[
'title'] ) ) {
1976 throw new MWException(
'Invalid node passed to ' . __METHOD__ );
2002 if ( !is_scalar( $this->
value ) ) {
2003 throw new MWException( __CLASS__ .
' given object instead of string' );
2010 return htmlspecialchars( $this->
value );
2042 throw new MWException( __METHOD__ .
': not supported' );
2046 throw new MWException( __METHOD__ .
': not supported' );
2050 throw new MWException( __METHOD__ .
': not supported' );
2068 return var_export( $this,
true );
2076 return $this->
value[$i];
2100 throw new MWException( __METHOD__ .
': not supported' );
2104 throw new MWException( __METHOD__ .
': not supported' );
2108 throw new MWException( __METHOD__ .
': not supported' );
2132 throw new MWException( __METHOD__.
': invalid name in attribute descriptor' );
2141 return "<@{$this->name}>" . htmlspecialchars( $this->
value ) .
"</@{$this->name}>";
2173 throw new MWException( __METHOD__ .
': not supported' );
2177 throw new MWException( __METHOD__ .
': not supported' );
2181 throw new MWException( __METHOD__ .
': not supported' );