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 ) ] ],
121 if ( $tree !==
false ) {
122 $store = json_decode( $tree );
123 if ( is_array( $store ) ) {
130 $xmlishElements = $this->parser->getStripList();
131 $xmlishAllowMissingEndTag = [
'includeonly',
'noinclude',
'onlyinclude' ];
132 $enableOnlyinclude =
false;
133 if ( $forInclusion ) {
134 $ignoredTags = [
'includeonly',
'/includeonly' ];
135 $ignoredElements = [
'noinclude' ];
136 $xmlishElements[] =
'noinclude';
137 if ( strpos( $text,
'<onlyinclude>' ) !==
false
138 && strpos( $text,
'</onlyinclude>' ) !==
false
140 $enableOnlyinclude =
true;
143 $ignoredTags = [
'noinclude',
'/noinclude',
'onlyinclude',
'/onlyinclude' ];
144 $ignoredElements = [
'includeonly' ];
145 $xmlishElements[] =
'includeonly';
147 $xmlishRegex = implode(
'|', array_merge( $xmlishElements, $ignoredTags ) );
150 $elementsRegex =
"~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
154 $searchBase =
"[{<\n";
156 $revText = strrev( $text );
157 $lengthText = strlen( $text );
162 $accum =& $stack->getAccum();
173 $noMoreClosingTag = [];
175 $findOnlyinclude = $enableOnlyinclude;
177 $fakeLineStart =
true;
182 if ( $findOnlyinclude ) {
184 $startPos = strpos( $text,
'<onlyinclude>', $i );
185 if ( $startPos ===
false ) {
187 $accum[] = [
'ignore', [ substr( $text, $i ) ] ];
190 $tagEndPos = $startPos + strlen(
'<onlyinclude>' );
191 $accum[] = [
'ignore', [ substr( $text, $i, $tagEndPos - $i ) ] ];
193 $findOnlyinclude =
false;
196 if ( $fakeLineStart ) {
197 $found =
'line-start';
200 # Find next opening brace, closing brace or pipe
201 $search = $searchBase;
202 if ( $stack->top ===
false ) {
203 $currentClosing =
'';
205 $currentClosing = $stack->top->close;
206 $search .= $currentClosing;
216 # Output literal section, advance input counter
217 $literalLength = strcspn( $text, $search, $i );
218 if ( $literalLength > 0 ) {
219 self::addLiteral( $accum, substr( $text, $i, $literalLength ) );
220 $i += $literalLength;
222 if ( $i >= $lengthText ) {
223 if ( $currentClosing ==
"\n" ) {
232 $curChar = $text[$i];
233 if ( $curChar ==
'|' ) {
235 } elseif ( $curChar ==
'=' ) {
237 } elseif ( $curChar ==
'<' ) {
239 } elseif ( $curChar ==
"\n" ) {
243 $found =
'line-start';
245 } elseif ( $curChar == $currentClosing ) {
247 } elseif ( isset( $this->rules[$curChar] ) ) {
249 $rule = $this->rules[$curChar];
251 # Some versions of PHP have a strcspn which stops on null characters
252 # Ignore and continue
259 if ( $found ==
'angle' ) {
262 if ( $enableOnlyinclude
263 && substr( $text, $i, strlen(
'</onlyinclude>' ) ) ==
'</onlyinclude>'
265 $findOnlyinclude =
true;
270 if ( !preg_match( $elementsRegex, $text,
$matches, 0, $i + 1 ) ) {
272 self::addLiteral( $accum,
'<' );
285 $endPos = strpos( $text,
'-->', $i + 4 );
286 if ( $endPos ===
false ) {
288 $inner = substr( $text, $i );
289 $accum[] = [
'comment', [ $inner ] ];
293 $wsStart = $i ? ( $i - strspn( $revText,
" \t", $lengthText - $i ) ) : 0;
297 $wsEnd = $endPos + 2 + strspn( $text,
" \t", $endPos + 3 );
301 $comments = [ [ $wsStart, $wsEnd ] ];
302 while ( substr( $text, $wsEnd + 1, 4 ) ==
'<!--' ) {
303 $c = strpos( $text,
'-->', $wsEnd + 4 );
304 if ( $c ===
false ) {
307 $c = $c + 2 + strspn( $text,
" \t", $c + 3 );
308 $comments[] = [ $wsEnd + 1, $c ];
316 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) ==
"\n"
317 && substr( $text, $wsEnd + 1, 1 ) ==
"\n"
320 $wsLength = $i - $wsStart;
321 $endIndex = count( $accum ) - 1;
326 && is_string( $accum[$endIndex] )
327 && strspn( $accum[$endIndex],
" \t", -$wsLength ) === $wsLength
329 $accum[$endIndex] = substr( $accum[$endIndex], 0, -$wsLength );
333 foreach ( $comments
as $j => $com ) {
335 $endPos = $com[1] + 1;
336 if ( $j == ( count( $comments ) - 1 ) ) {
339 $inner = substr( $text, $startPos, $endPos - $startPos );
340 $accum[] = [
'comment', [ $inner ] ];
344 $fakeLineStart =
true;
352 $part = $stack->top->getCurrentPart();
353 if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
354 $part->visualEnd = $wsStart;
357 $part->commentEnd = $endPos;
360 $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
361 $accum[] = [
'comment', [ $inner ] ];
366 $lowerName = strtolower(
$name );
367 $attrStart = $i + strlen(
$name ) + 1;
370 $tagEndPos = $noMoreGT ?
false : strpos( $text,
'>', $attrStart );
371 if ( $tagEndPos ===
false ) {
375 self::addLiteral( $accum,
'<' );
381 if ( in_array( $lowerName, $ignoredTags ) ) {
382 $accum[] = [
'ignore', [ substr( $text, $i, $tagEndPos - $i + 1 ) ] ];
388 if ( $text[$tagEndPos - 1] ==
'/' ) {
390 $attrEnd = $tagEndPos - 1;
395 $attrEnd = $tagEndPos;
398 !isset( $noMoreClosingTag[
$name] ) &&
399 preg_match(
"/<\/" . preg_quote( $name,
'/' ) .
"\s*>/i",
400 $text,
$matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
402 $inner = substr( $text, $tagEndPos + 1,
$matches[0][1] - $tagEndPos - 1 );
407 if ( in_array( $name, $xmlishAllowMissingEndTag ) ) {
409 $inner = substr( $text, $tagEndPos + 1 );
415 self::addLiteral( $accum,
416 substr( $text, $tagStartPos, $tagEndPos + 1 - $tagStartPos ) );
418 $noMoreClosingTag[
$name] =
true;
424 if ( in_array( $lowerName, $ignoredElements ) ) {
425 $accum[] = [
'ignore', [ substr( $text, $tagStartPos, $i - $tagStartPos ) ] ];
429 if ( $attrEnd <= $attrStart ) {
434 $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
438 [
'name', [
$name ] ],
439 [
'attr', [ $attr ] ] ];
440 if ( $inner !== null ) {
441 $children[] = [
'inner', [ $inner ] ];
443 if ( $close !== null ) {
444 $children[] = [
'close', [ $close ] ];
446 $accum[] = [
'ext', $children ];
447 } elseif ( $found ==
'line-start' ) {
450 if ( $fakeLineStart ) {
451 $fakeLineStart =
false;
453 self::addLiteral( $accum, $curChar );
457 $count = strspn( $text,
'=', $i, 6 );
458 if (
$count == 1 && $findEquals ) {
470 $stack->push( $piece );
471 $accum =& $stack->getAccum();
472 extract( $stack->getFlags() );
475 } elseif ( $found ==
'line-end' ) {
476 $piece = $stack->top;
478 assert( $piece->open ===
"\n" );
479 $part = $piece->getCurrentPart();
483 $wsLength = strspn( $revText,
" \t", $lengthText - $i );
484 $searchStart = $i - $wsLength;
485 if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
488 $searchStart = $part->visualEnd;
489 $searchStart -= strspn( $revText,
" \t", $lengthText - $searchStart );
492 $equalsLength = strspn( $revText,
'=', $lengthText - $searchStart );
493 if ( $equalsLength > 0 ) {
494 if ( $searchStart - $equalsLength == $piece->startPos ) {
509 $element = [ [
'possible-h',
513 [
'@i', [ $headingIndex++ ] ]
528 $accum =& $stack->getAccum();
529 extract( $stack->getFlags() );
532 array_splice( $accum, count( $accum ), 0, $element );
539 } elseif ( $found ==
'open' ) {
540 # count opening brace characters
541 $count = strspn( $text, $curChar, $i );
543 # we need to add to stack only if opening brace count is enough for one of the rules
544 if (
$count >= $rule[
'min'] ) {
545 # Add it to the stack
548 'close' => $rule[
'end'],
550 'lineStart' => ( $i > 0 && $text[$i - 1] ==
"\n" ),
553 $stack->push( $piece );
554 $accum =& $stack->getAccum();
555 extract( $stack->getFlags() );
557 # Add literal brace(s)
558 self::addLiteral( $accum, str_repeat( $curChar,
$count ) );
561 } elseif ( $found ==
'close' ) {
562 $piece = $stack->top;
563 # lets check if there are enough characters for closing brace
564 $maxCount = $piece->count;
565 $count = strspn( $text, $curChar, $i, $maxCount );
567 # check for maximum matching characters (if there are 5 closing
568 # characters, we will probably need only 3 - depending on the rules)
569 $rule = $this->rules[$piece->open];
570 if (
$count > $rule[
'max'] ) {
571 # The specified maximum exists in the callback array, unless the caller
573 $matchingCount = $rule[
'max'];
575 # Count is less than the maximum
576 # Skip any gaps in the callback array to find the true largest match
577 # Need to use array_key_exists not isset because the callback can be null
579 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule[
'names'] ) ) {
584 if ( $matchingCount <= 0 ) {
585 # No matching element found in callback array
586 # Output a literal closing brace and continue
587 self::addLiteral( $accum, str_repeat( $curChar,
$count ) );
591 $name = $rule[
'names'][$matchingCount];
592 if (
$name === null ) {
594 $element = $piece->breakSyntax( $matchingCount );
595 self::addLiteral( $element, str_repeat( $rule[
'end'], $matchingCount ) );
598 $parts = $piece->parts;
599 $titleAccum = $parts[0]->out;
604 # The invocation is at the start of the line if lineStart is set in
605 # the stack, and all opening brackets are used up.
606 if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
607 $children[] = [
'@lineStart', [ 1 ] ];
609 $titleNode = [
'title', $titleAccum ];
610 $children[] = $titleNode;
612 foreach ( $parts
as $part ) {
613 if ( isset( $part->eqpos ) ) {
614 $equalsNode = $part->out[$part->eqpos];
615 $nameNode = [
'name', array_slice( $part->out, 0, $part->eqpos ) ];
616 $valueNode = [
'value', array_slice( $part->out, $part->eqpos + 1 ) ];
617 $partNode = [
'part', [ $nameNode, $equalsNode, $valueNode ] ];
618 $children[] = $partNode;
620 $nameNode = [
'name', [ [
'@index', [ $argIndex++ ] ] ] ];
621 $valueNode = [
'value', $part->out ];
622 $partNode = [
'part', [ $nameNode, $valueNode ] ];
623 $children[] = $partNode;
626 $element = [ [
$name, $children ] ];
629 # Advance input pointer
630 $i += $matchingCount;
634 $accum =& $stack->getAccum();
636 # Re-add the old stack element if it still has unmatched opening characters remaining
637 if ( $matchingCount < $piece->count ) {
639 $piece->count -= $matchingCount;
640 # do we still qualify for any callback with remaining count?
641 $min = $this->rules[$piece->open][
'min'];
642 if ( $piece->count >= $min ) {
643 $stack->push( $piece );
644 $accum =& $stack->getAccum();
646 self::addLiteral( $accum, str_repeat( $piece->open, $piece->count ) );
650 extract( $stack->getFlags() );
652 # Add XML element to the enclosing accumulator
653 array_splice( $accum, count( $accum ), 0, $element );
654 } elseif ( $found ==
'pipe' ) {
657 $accum =& $stack->getAccum();
659 } elseif ( $found ==
'equals' ) {
661 $accum[] = [
'equals', [
'=' ] ];
662 $stack->getCurrentPart()->eqpos = count( $accum ) - 1;
667 # Output any remaining unclosed brackets
668 foreach ( $stack->stack
as $piece ) {
669 array_splice( $stack->rootAccum, count( $stack->rootAccum ), 0, $piece->breakSyntax() );
672 # Enable top-level headings
673 foreach ( $stack->rootAccum
as &$node ) {
679 $rootStore = [ [
'root', $stack->rootAccum ] ];
683 $tree = json_encode( $rootStore, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
684 if ( $tree !==
false ) {
692 $n = count( $accum );
693 if ( $n && is_string( $accum[$n - 1] ) ) {
694 $accum[$n - 1] .= $text;
710 $this->elementClass =
'PPDStackElement_Hash';
711 parent::__construct();
712 $this->rootAccum = [];
724 $this->partClass =
'PPDPart_Hash';
725 parent::__construct( $data );
735 if ( $this->
open ==
"\n" ) {
736 $accum = $this->parts[0]->out;
738 if ( $openingCount ===
false ) {
741 $accum = [ str_repeat( $this->
open, $openingCount ) ];
744 foreach ( $this->parts
as $part ) {
747 } elseif ( is_string( $accum[$lastIndex] ) ) {
748 $accum[$lastIndex] .=
'|';
750 $accum[++$lastIndex] =
'|';
752 foreach ( $part->out
as $node ) {
753 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
754 $accum[$lastIndex] .= $node;
756 $accum[++$lastIndex] = $node;
778 parent::__construct( $accum );
833 $this->
title = $this->parser->mTitle;
834 $this->titleCache = [ $this->
title ? $this->
title->getPrefixedDBkey() :
false ];
835 $this->loopCheckHash = [];
837 $this->childExpansionCache = [];
856 if (
$args !==
false ) {
859 } elseif ( !is_array(
$args ) ) {
860 throw new MWException( __METHOD__ .
': $args must be array or PPNode_Hash_Array' );
863 $bits = $arg->splitArg();
864 if ( $bits[
'index'] !==
'' ) {
866 $index = $bits[
'index'] - $indexOffset;
867 if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
868 $this->parser->getOutput()->addWarning(
wfMessage(
'duplicate-args-warning',
872 $this->parser->addTrackingCategory(
'duplicate-args-category' );
874 $numberedArgs[$index] = $bits[
'value'];
875 unset( $namedArgs[$index] );
879 if ( isset( $namedArgs[
$name] ) || isset( $numberedArgs[$name] ) ) {
880 $this->parser->getOutput()->addWarning(
wfMessage(
'duplicate-args-warning',
884 $this->parser->addTrackingCategory(
'duplicate-args-category' );
886 $namedArgs[
$name] = $bits[
'value'];
887 unset( $numberedArgs[$name] );
913 static $expansionDepth = 0;
914 if ( is_string( $root ) ) {
918 if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
919 $this->parser->limitationWarn(
'node-count-exceeded',
920 $this->parser->mPPNodeCount,
921 $this->parser->mOptions->getMaxPPNodeCount()
923 return '<span class="error">Node-count limit exceeded</span>';
925 if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
926 $this->parser->limitationWarn(
'expansion-depth-exceeded',
928 $this->parser->mOptions->getMaxPPExpandDepth()
930 return '<span class="error">Expansion depth limit exceeded</span>';
933 if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
934 $this->parser->mHighestExpansionDepth = $expansionDepth;
937 $outStack = [
'',
'' ];
938 $iteratorStack = [
false, $root ];
939 $indexStack = [ 0, 0 ];
941 while ( count( $iteratorStack ) > 1 ) {
942 $level = count( $outStack ) - 1;
943 $iteratorNode =& $iteratorStack[$level];
944 $out =& $outStack[$level];
945 $index =& $indexStack[$level];
947 if ( is_array( $iteratorNode ) ) {
948 if ( $index >= count( $iteratorNode ) ) {
950 $iteratorStack[$level] =
false;
951 $contextNode =
false;
953 $contextNode = $iteratorNode[$index];
957 if ( $index >= $iteratorNode->getLength() ) {
959 $iteratorStack[$level] =
false;
960 $contextNode =
false;
962 $contextNode = $iteratorNode->item( $index );
968 $contextNode = $iteratorStack[$level];
969 $iteratorStack[$level] =
false;
972 $newIterator =
false;
973 $contextName =
false;
974 $contextChildren =
false;
976 if ( $contextNode ===
false ) {
978 } elseif ( is_string( $contextNode ) ) {
979 $out .= $contextNode;
980 } elseif ( $contextNode instanceof PPNode_Hash_Array ) {
981 $newIterator = $contextNode;
985 $out .= $contextNode->value;
987 $contextName = $contextNode->name;
988 $contextChildren = $contextNode->getRawChildren();
989 } elseif ( is_array( $contextNode ) ) {
991 if ( count( $contextNode ) !== 2 ) {
993 ': found an array where a node descriptor should be' );
995 list( $contextName, $contextChildren ) = $contextNode;
997 throw new MWException( __METHOD__ .
': Invalid parameter type' );
1001 if ( $contextName ===
false ) {
1003 } elseif ( $contextName[0] ===
'@' ) {
1005 } elseif ( $contextName ===
'template' ) {
1006 # Double-brace expansion
1015 $ret = $this->parser->braceSubstitution( $bits, $this );
1016 if ( isset(
$ret[
'object'] ) ) {
1017 $newIterator =
$ret[
'object'];
1022 } elseif ( $contextName ===
'tplarg' ) {
1023 # Triple-brace expansion
1032 $ret = $this->parser->argSubstitution( $bits, $this );
1033 if ( isset(
$ret[
'object'] ) ) {
1034 $newIterator =
$ret[
'object'];
1039 } elseif ( $contextName ===
'comment' ) {
1040 # HTML-style comment
1041 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1042 # Not in RECOVER_COMMENTS mode (msgnw) though.
1043 if ( ( $this->parser->ot[
'html']
1044 || ( $this->parser->ot[
'pre'] && $this->parser->mOptions->getRemoveComments() )
1049 } elseif ( $this->parser->ot[
'wiki'] && !(
$flags & PPFrame::RECOVER_COMMENTS ) ) {
1050 # Add a strip marker in PST mode so that pstPass2() can
1051 # run some old-fashioned regexes on the result.
1052 # Not in RECOVER_COMMENTS mode (extractSections) though.
1053 $out .= $this->parser->insertStripItem( $contextChildren[0] );
1055 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1056 $out .= $contextChildren[0];
1058 } elseif ( $contextName ===
'ignore' ) {
1059 # Output suppression used by <includeonly> etc.
1060 # OT_WIKI will only respect <ignore> in substed templates.
1061 # The other output types respect it unless NO_IGNORE is set.
1062 # extractSections() sets NO_IGNORE and so never respects it.
1063 if ( ( !isset( $this->parent ) && $this->parser->ot[
'wiki'] )
1066 $out .= $contextChildren[0];
1070 } elseif ( $contextName ===
'ext' ) {
1073 [
'attr' => null,
'inner' => null,
'close' => null ];
1075 $s =
'<' . $bits[
'name']->getFirstChild()->value;
1076 if ( $bits[
'attr'] ) {
1077 $s .= $bits[
'attr']->getFirstChild()->value;
1079 if ( $bits[
'inner'] ) {
1080 $s .=
'>' . $bits[
'inner']->getFirstChild()->value;
1081 if ( $bits[
'close'] ) {
1082 $s .= $bits[
'close']->getFirstChild()->value;
1089 $out .= $this->parser->extensionSubstitution( $bits, $this );
1091 } elseif ( $contextName ===
'h' ) {
1093 if ( $this->parser->ot[
'html'] ) {
1094 # Expand immediately and insert heading index marker
1097 $titleText = $this->
title->getPrefixedDBkey();
1098 $this->parser->mHeadings[] = [ $titleText, $bits[
'i'] ];
1099 $serial = count( $this->parser->mHeadings ) - 1;
1101 $s = substr(
$s, 0, $bits[
'level'] ) . $marker . substr(
$s, $bits[
'level'] );
1102 $this->parser->mStripState->addGeneral( $marker,
'' );
1105 # Expand in virtual stack
1106 $newIterator = $contextChildren;
1109 # Generic recursive expansion
1110 $newIterator = $contextChildren;
1113 if ( $newIterator !==
false ) {
1115 $iteratorStack[] = $newIterator;
1117 } elseif ( $iteratorStack[$level] ===
false ) {
1120 while ( $iteratorStack[$level] ===
false && $level > 0 ) {
1121 $outStack[$level - 1] .=
$out;
1122 array_pop( $outStack );
1123 array_pop( $iteratorStack );
1124 array_pop( $indexStack );
1130 return $outStack[0];
1140 $args = array_slice( func_get_args(), 2 );
1146 $root = $root->value;
1148 if ( !is_array( $root ) ) {
1151 foreach ( $root
as $node ) {
1171 $args = array_slice( func_get_args(), 1 );
1177 $root = $root->value;
1179 if ( !is_array( $root ) ) {
1182 foreach ( $root
as $node ) {
1203 $args = array_slice( func_get_args(), 1 );
1209 $root = $root->value;
1211 if ( !is_array( $root ) ) {
1214 foreach ( $root
as $node ) {
1236 $args = array_slice( func_get_args(), 3 );
1242 $root = $root->value;
1244 if ( !is_array( $root ) ) {
1247 foreach ( $root
as $node ) {
1269 if ( $level ===
false ) {
1270 return $this->
title->getPrefixedDBkey();
1272 return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] :
false;
1349 $this->
volatile = $flag;
1367 if (
$ttl !== null && ( $this->ttl === null || $ttl < $this->ttl ) ) {
1401 $namedArgs = [],
$title =
false
1410 $this->titleCache = $parent->titleCache;
1411 $this->titleCache[] = $pdbk;
1412 $this->loopCheckHash = $parent->loopCheckHash;
1413 if ( $pdbk !==
false ) {
1414 $this->loopCheckHash[$pdbk] =
true;
1416 $this->depth = $parent->depth + 1;
1417 $this->numberedExpansionCache = $this->namedExpansionCache = [];
1430 $s .=
"\"$name\":\"" .
1431 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1445 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
1446 return $this->parent->childExpansionCache[$key];
1450 $this->parent->childExpansionCache[$key] =
$retval;
1461 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
1469 foreach ( array_merge(
1470 array_keys( $this->numberedArgs ),
1471 array_keys( $this->namedArgs ) )
as $key ) {
1482 foreach ( array_keys( $this->numberedArgs )
as $key ) {
1493 foreach ( array_keys( $this->namedArgs )
as $key ) {
1504 if ( !isset( $this->numberedArgs[$index] ) ) {
1507 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1508 # No trimming for unnamed arguments
1509 $this->numberedExpansionCache[$index] = $this->parent->expand(
1510 $this->numberedArgs[$index],
1514 return $this->numberedExpansionCache[$index];
1522 if ( !isset( $this->namedArgs[
$name] ) ) {
1525 if ( !isset( $this->namedExpansionCache[$name] ) ) {
1526 # Trim named arguments post-expand, for backwards compatibility
1527 $this->namedExpansionCache[
$name] = trim(
1530 return $this->namedExpansionCache[
$name];
1539 if ( $text ===
false ) {
1555 parent::setVolatile( $flag );
1556 $this->parent->setVolatile( $flag );
1560 parent::setTTL(
$ttl );
1561 $this->parent->setTTL(
$ttl );
1577 $this->args =
$args;
1589 $s .=
"\"$name\":\"" .
1590 str_replace(
'"',
'\\"',
$value->__toString() ) .
'"';
1600 return !count( $this->args );
1608 if ( !isset( $this->args[$index] ) ) {
1611 return $this->args[$index];
1679 if ( !isset( $store[
$index] ) ) {
1683 $descriptor = $store[
$index];
1684 if ( is_string( $descriptor ) ) {
1685 $class =
'PPNode_Hash_Text';
1686 } elseif ( is_array( $descriptor ) ) {
1687 if ( $descriptor[self::NAME][0] ===
'@' ) {
1688 $class =
'PPNode_Hash_Attr';
1690 $class =
'PPNode_Hash_Tree';
1693 throw new MWException( __METHOD__.
': invalid node descriptor' );
1695 return new $class( $store, $index );
1704 for ( $node = $this->
getFirstChild(); $node; $node = $node->getNextSibling() ) {
1706 $attribs .=
' ' . $node->name .
'="' . htmlspecialchars( $node->value ) .
'"';
1708 $inner .= $node->__toString();
1711 if ( $inner ===
'' ) {
1712 return "<{$this->name}$attribs/>";
1714 return "<{$this->name}$attribs>$inner</{$this->name}>";
1723 foreach ( $this->rawChildren
as $i => $child ) {
1724 $children[] = self::factory( $this->rawChildren, $i );
1737 if ( !isset( $this->rawChildren[0] ) ) {
1740 return self::factory( $this->rawChildren, 0 );
1752 return self::factory( $this->
store, $this->index + 1 );
1763 foreach ( $this->rawChildren
as $i => $child ) {
1764 if ( is_array( $child ) && $child[self::NAME] ===
$name ) {
1765 $children[] = self::factory( $this->rawChildren, $i );
1811 return self::splitRawArg( $this->rawChildren );
1819 foreach ( $children
as $i => $child ) {
1820 if ( !is_array( $child ) ) {
1823 if ( $child[self::NAME] ===
'name' ) {
1824 $bits[
'name'] =
new self( $children, $i );
1825 if ( isset( $child[self::CHILDREN][0][self::NAME] )
1826 && $child[self::CHILDREN][0][self::NAME] ===
'@index'
1828 $bits[
'index'] = $child[self::CHILDREN][0][self::CHILDREN][0];
1830 } elseif ( $child[self::NAME] ===
'value' ) {
1831 $bits[
'value'] =
new self( $children, $i );
1835 if ( !isset( $bits[
'name'] ) ) {
1836 throw new MWException(
'Invalid brace node passed to ' . __METHOD__ );
1838 if ( !isset( $bits[
'index'] ) ) {
1839 $bits[
'index'] =
'';
1852 return self::splitRawExt( $this->rawChildren );
1860 foreach ( $children
as $i => $child ) {
1861 if ( !is_array( $child ) ) {
1864 switch ( $child[self::NAME] ) {
1866 $bits[
'name'] =
new self( $children, $i );
1869 $bits[
'attr'] =
new self( $children, $i );
1872 $bits[
'inner'] =
new self( $children, $i );
1875 $bits[
'close'] =
new self( $children, $i );
1879 if ( !isset( $bits[
'name'] ) ) {
1880 throw new MWException(
'Invalid ext node passed to ' . __METHOD__ );
1892 if ( $this->
name !==
'h' ) {
1893 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1895 return self::splitRawHeading( $this->rawChildren );
1903 foreach ( $children
as $i => $child ) {
1904 if ( !is_array( $child ) ) {
1907 if ( $child[self::NAME] ===
'@i' ) {
1908 $bits[
'i'] = $child[self::CHILDREN][0];
1909 } elseif ( $child[self::NAME] ===
'@level' ) {
1910 $bits[
'level'] = $child[self::CHILDREN][0];
1913 if ( !isset( $bits[
'i'] ) ) {
1914 throw new MWException(
'Invalid h node passed to ' . __METHOD__ );
1926 return self::splitRawTemplate( $this->rawChildren );
1934 $bits = [
'lineStart' =>
'' ];
1935 foreach ( $children
as $i => $child ) {
1936 if ( !is_array( $child ) ) {
1939 switch ( $child[self::NAME] ) {
1941 $bits[
'title'] =
new self( $children, $i );
1944 $parts[] =
new self( $children, $i );
1947 $bits[
'lineStart'] =
'1';
1951 if ( !isset( $bits[
'title'] ) ) {
1952 throw new MWException(
'Invalid node passed to ' . __METHOD__ );
1977 $this->value = $store[
$index];
1978 if ( !is_scalar( $this->value ) ) {
1979 throw new MWException( __CLASS__ .
' given object instead of string' );
1986 return htmlspecialchars( $this->value );
2018 throw new MWException( __METHOD__ .
': not supported' );
2022 throw new MWException( __METHOD__ .
': not supported' );
2026 throw new MWException( __METHOD__ .
': not supported' );
2044 return var_export( $this,
true );
2048 return count( $this->value );
2052 return $this->value[$i];
2076 throw new MWException( __METHOD__ .
': not supported' );
2080 throw new MWException( __METHOD__ .
': not supported' );
2084 throw new MWException( __METHOD__ .
': not supported' );
2106 $descriptor = $store[
$index];
2108 throw new MWException( __METHOD__.
': invalid name in attribute descriptor' );
2117 return "<@{$this->name}>" . htmlspecialchars( $this->value ) .
"</@{$this->name}>";
2149 throw new MWException( __METHOD__ .
': not supported' );
2153 throw new MWException( __METHOD__ .
': not supported' );
2157 throw new MWException( __METHOD__ .
': not supported' );
splitArg()
Split a "
" node into an associative array containing:
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
the array() calling protocol came about after MediaWiki 1.4rc1.
splitTemplate()
Split a "" or "" node.
getArguments()
Returns all arguments of this frame.
$index
The index into $this->store which contains the descriptor of this node.
getNextSibling()
Get the next sibling of any node.
Stack class to help Preprocessor::preprocessToObj()
processing should stop and the error should be shown to the user * false
__construct(array $store, $index)
Construct an object using the data from $store[$index].
getFirstChild()
Get the first child, or false if there is none.
__construct($preprocessor)
Construct a new preprocessor frame.
$depth
Recursion depth of this frame, top = 0 Note that this is NOT the same as expansion depth in expand() ...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
int $count
Number of opening characters found (number of "=" for heading)
newChild($args=false, $title=false, $indexOffset=0)
Create a new child frame $args is optionally a multi-root PPNode or array containing the template arg...
item($i)
Returns an item of an array-type node.
static addLiteral(array &$accum, $text)
setTTL($ttl)
Set the TTL of the output of this frame and all of its ancestors.
splitExt()
Split an "" node into an associative array containing name, attr, inner and close All values in ...
__construct(array $store, $index)
Construct an object using the data from $store[$index].
There are three types of nodes:
__construct($preprocessor, $args)
getLength()
Returns the length of the array, or false if this is not an array-type node.
isEmpty()
Returns true if there are no arguments in this frame.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
implode($sep)
Implode with no flags specified This previously called implodeWithFlags but has now been inlined to r...
static splitRawHeading(array $children)
Like splitHeading() but for a raw child array.
isTemplate()
Return true if the frame is a template frame.
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database store
static factory(array $store, $index)
Construct an appropriate PPNode_Hash_* object with a class that depends on what is at the relevant st...
getChildren()
Get an array-type node containing the children of this node.
breakSyntax($openingCount=false)
Get the accumulator that would result if the close is not found.
Differences from DOM schema:
Stack class to help Preprocessor::preprocessToObj()
splitHeading()
Split an "" node.
item($i)
Returns an item of an array-type node.
getNextSibling()
Get the next sibling, or false if there is none.
getNextSibling()
Get the next sibling of any node.
const NAME
The offset of the name within descriptors, used in some places for readability.
preprocessToObj($text, $flags=0)
Preprocess some wikitext and return the document tree.
array cacheSetTree($text, $flags, $tree)
Store a document tree in the cache.
wfEscapeWikiText($text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
implodeWithFlags($sep, $flags)
virtualImplode($sep)
Makes an object that, when expand()ed, will be the same as one obtained with implode() ...
An expansion frame, used as a context to expand the result of preprocessToObj()
setVolatile($flag=true)
Set the "volatile" flag.
virtualBracketedImplode($start, $sep, $end)
Virtual implode with brackets.
isTemplate()
Return true if the frame is a template frame.
getChildren()
Get an array-type node containing the children of this node.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
isEmpty()
Returns true if there are no arguments in this frame.
splitArg()
Split a "
" node into an associative array containing: name PPNode name index String index value...
getTitle()
Get a title of frame.
getChildren()
Get an array-type node containing the children of this node.
getChildrenOfType($name)
Get all children of this tree node which have a given name.
getName()
Get the name of this node.
getName()
Get the name of this node.
static splitRawTemplate(array $children)
Like splitTemplate() but for a raw child array.
getChildrenOfType($name)
Get all children of this tree node which have a given name.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Expansion frame with template arguments.
static splitRawExt(array $children)
Like splitExt() but for a raw child array.
newPartNodeArray($values)
getRawChildren()
Get the raw child array.
getFirstChild()
Get the first child of a tree node.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
splitExt()
Split an "" node into an associative array containing name, attr, inner and close All values in ...
isVolatile()
Get the volatile flag.
static splitRawArg(array $children)
Like splitArg() but for a raw child array.
getLength()
Returns the length of the array, or false if this is not an array-type node.
splitArg()
Split a "
" node into an associative array containing: name PPNode name index String index value...
__construct($preprocessor, $parent=false, $numberedArgs=[], $namedArgs=[], $title=false)
setVolatile($flag=true)
Set the volatile flag.
$store
The store array for the siblings of this node, including this node itself.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
splitHeading()
Split an "" node.
loopCheck($title)
Returns true if the infinite loop check is OK, false if a loop is detected.
getNumberedArgument($index)
getNextSibling()
Get the next sibling of any node.
array $childExpansionCache
$rawChildren
The store array for children of this node.
getChildrenOfType($name)
Get an array of the children with a given node name.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
item($i)
Returns an item of an array-type node.
cachedExpand($key, $root, $flags=0)
splitHeading()
Split an "" node.
getLength()
Returns the length of the array, or false if this is not an array-type node.
splitHeading()
Split an "" node.
splitExt()
Split an "" node into an associative array containing name, attr, inner and close All values in ...
$loopCheckHash
Hashtable listing templates which are disallowed for expansion in this frame, having been encountered...
__toString()
Convert a node to XML, for debugging.
cachedExpand($key, $root, $flags=0)
splitExt()
Split an "" node into an associative array containing name, attr, inner and close All values in ...
Expansion frame with custom arguments.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
getChildrenOfType($name)
Get all children of this tree node which have a given name.
string $out
Output accumulator string.
splitArg()
Split a "
" node into an associative array containing: name PPNode name index String index value...
getFirstChild()
Get the first child of a tree node.
Preprocessor $preprocessor
cacheGetTree($text, $flags)
Attempt to load a precomputed document tree for some given wikitext from the cache.
getFirstChild()
Get the first child of a tree node.
const CHILDREN
The offset of the child list within descriptors, used in some places for readability.
getPrefixedDBkey()
Get the prefixed database key form.
getName()
Get the name of this node.
__construct(array $store, $index)
Construct an object using the data from $store[$index].
Allows to change the fields on the form that will be generated $name