Merge "tests: Complete test coverage of HtmlArmor"
[lhc/web/wiklou.git] / includes / parser / Preprocessor_Hash.php
1 <?php
2 /**
3 * Preprocessor using PHP arrays
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Parser
22 */
23
24 /**
25 * Differences from DOM schema:
26 * * attribute nodes are children
27 * * "<h>" nodes that aren't at the top are replaced with <possible-h>
28 *
29 * Nodes are stored in a recursive array data structure. A node store is an
30 * array where each element may be either a scalar (representing a text node)
31 * or a "descriptor", which is a two-element array where the first element is
32 * the node name and the second element is the node store for the children.
33 *
34 * Attributes are represented as children that have a node name starting with
35 * "@", and a single text node child.
36 *
37 * @todo: Consider replacing descriptor arrays with objects of a new class.
38 * Benchmark and measure resulting memory impact.
39 *
40 * @ingroup Parser
41 */
42 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
43 class Preprocessor_Hash extends Preprocessor {
44 // @codingStandardsIgnoreEnd
45
46 /**
47 * @var Parser
48 */
49 public $parser;
50
51 const CACHE_PREFIX = 'preprocess-hash';
52 const CACHE_VERSION = 2;
53
54 public function __construct( $parser ) {
55 $this->parser = $parser;
56 }
57
58 /**
59 * @return PPFrame_Hash
60 */
61 public function newFrame() {
62 return new PPFrame_Hash( $this );
63 }
64
65 /**
66 * @param array $args
67 * @return PPCustomFrame_Hash
68 */
69 public function newCustomFrame( $args ) {
70 return new PPCustomFrame_Hash( $this, $args );
71 }
72
73 /**
74 * @param array $values
75 * @return PPNode_Hash_Array
76 */
77 public function newPartNodeArray( $values ) {
78 $list = [];
79
80 foreach ( $values as $k => $val ) {
81 if ( is_int( $k ) ) {
82 $store = [ [ 'part', [
83 [ 'name', [ [ '@index', [ $k ] ] ] ],
84 [ 'value', [ strval( $val ) ] ],
85 ] ] ];
86 } else {
87 $store = [ [ 'part', [
88 [ 'name', [ strval( $k ) ] ],
89 '=',
90 [ 'value', [ strval( $val ) ] ],
91 ] ] ];
92 }
93
94 $list[] = new PPNode_Hash_Tree( $store, 0 );
95 }
96
97 $node = new PPNode_Hash_Array( $list );
98 return $node;
99 }
100
101 /**
102 * Preprocess some wikitext and return the document tree.
103 *
104 * @param string $text The text to parse
105 * @param int $flags Bitwise combination of:
106 * Parser::PTD_FOR_INCLUSION Handle "<noinclude>" and "<includeonly>" as if the text is being
107 * included. Default is to assume a direct page view.
108 *
109 * The generated DOM tree must depend only on the input text and the flags.
110 * The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of T6899.
111 *
112 * Any flag added to the $flags parameter here, or any other parameter liable to cause a
113 * change in the DOM tree for a given text, must be passed through the section identifier
114 * in the section edit link and thus back to extractSections().
115 *
116 * @throws MWException
117 * @return PPNode_Hash_Tree
118 */
119 public function preprocessToObj( $text, $flags = 0 ) {
120 global $wgDisableLangConversion;
121
122 $tree = $this->cacheGetTree( $text, $flags );
123 if ( $tree !== false ) {
124 $store = json_decode( $tree );
125 if ( is_array( $store ) ) {
126 return new PPNode_Hash_Tree( $store, 0 );
127 }
128 }
129
130 $forInclusion = $flags & Parser::PTD_FOR_INCLUSION;
131
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
141 ) {
142 $enableOnlyinclude = true;
143 }
144 } else {
145 $ignoredTags = [ 'noinclude', '/noinclude', 'onlyinclude', '/onlyinclude' ];
146 $ignoredElements = [ 'includeonly' ];
147 $xmlishElements[] = 'includeonly';
148 }
149 $xmlishRegex = implode( '|', array_merge( $xmlishElements, $ignoredTags ) );
150
151 // Use "A" modifier (anchored) instead of "^", because ^ doesn't work with an offset
152 $elementsRegex = "~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
153
154 $stack = new PPDStack_Hash;
155
156 $searchBase = "[{<\n";
157 if ( !$wgDisableLangConversion ) {
158 $searchBase .= '-';
159 }
160
161 // For fast reverse searches
162 $revText = strrev( $text );
163 $lengthText = strlen( $text );
164
165 // Input pointer, starts out pointing to a pseudo-newline before the start
166 $i = 0;
167 // Current accumulator. See the doc comment for Preprocessor_Hash for the format.
168 $accum =& $stack->getAccum();
169 // True to find equals signs in arguments
170 $findEquals = false;
171 // True to take notice of pipe characters
172 $findPipe = false;
173 $headingIndex = 1;
174 // True if $i is inside a possible heading
175 $inHeading = false;
176 // True if there are no more greater-than (>) signs right of $i
177 $noMoreGT = false;
178 // Map of tag name => true if there are no more closing tags of given type right of $i
179 $noMoreClosingTag = [];
180 // True to ignore all input up to the next <onlyinclude>
181 $findOnlyinclude = $enableOnlyinclude;
182 // Do a line-start run without outputting an LF character
183 $fakeLineStart = true;
184
185 while ( true ) {
186 // $this->memCheck();
187
188 if ( $findOnlyinclude ) {
189 // Ignore all input up to the next <onlyinclude>
190 $startPos = strpos( $text, '<onlyinclude>', $i );
191 if ( $startPos === false ) {
192 // Ignored section runs to the end
193 $accum[] = [ 'ignore', [ substr( $text, $i ) ] ];
194 break;
195 }
196 $tagEndPos = $startPos + strlen( '<onlyinclude>' ); // past-the-end
197 $accum[] = [ 'ignore', [ substr( $text, $i, $tagEndPos - $i ) ] ];
198 $i = $tagEndPos;
199 $findOnlyinclude = false;
200 }
201
202 if ( $fakeLineStart ) {
203 $found = 'line-start';
204 $curChar = '';
205 } else {
206 # Find next opening brace, closing brace or pipe
207 $search = $searchBase;
208 if ( $stack->top === false ) {
209 $currentClosing = '';
210 } elseif (
211 $stack->top->close === '}-' &&
212 $stack->top->count > 2
213 ) {
214 # adjust closing for -{{{...{{
215 $currentClosing = '}';
216 $search .= $currentClosing;
217 } else {
218 $currentClosing = $stack->top->close;
219 $search .= $currentClosing;
220 }
221 if ( $findPipe ) {
222 $search .= '|';
223 }
224 if ( $findEquals ) {
225 // First equals will be for the template
226 $search .= '=';
227 }
228 $rule = null;
229 # Output literal section, advance input counter
230 $literalLength = strcspn( $text, $search, $i );
231 if ( $literalLength > 0 ) {
232 self::addLiteral( $accum, substr( $text, $i, $literalLength ) );
233 $i += $literalLength;
234 }
235 if ( $i >= $lengthText ) {
236 if ( $currentClosing == "\n" ) {
237 // Do a past-the-end run to finish off the heading
238 $curChar = '';
239 $found = 'line-end';
240 } else {
241 # All done
242 break;
243 }
244 } else {
245 $curChar = $curTwoChar = $text[$i];
246 if ( ( $i + 1 ) < $lengthText ) {
247 $curTwoChar .= $text[$i + 1];
248 }
249 if ( $curChar == '|' ) {
250 $found = 'pipe';
251 } elseif ( $curChar == '=' ) {
252 $found = 'equals';
253 } elseif ( $curChar == '<' ) {
254 $found = 'angle';
255 } elseif ( $curChar == "\n" ) {
256 if ( $inHeading ) {
257 $found = 'line-end';
258 } else {
259 $found = 'line-start';
260 }
261 } elseif ( $curTwoChar == $currentClosing ) {
262 $found = 'close';
263 $curChar = $curTwoChar;
264 } elseif ( $curChar == $currentClosing ) {
265 $found = 'close';
266 } elseif ( isset( $this->rules[$curTwoChar] ) ) {
267 $curChar = $curTwoChar;
268 $found = 'open';
269 $rule = $this->rules[$curChar];
270 } elseif ( isset( $this->rules[$curChar] ) ) {
271 $found = 'open';
272 $rule = $this->rules[$curChar];
273 } else {
274 # Some versions of PHP have a strcspn which stops on
275 # null characters; ignore these and continue.
276 # We also may get '-' and '}' characters here which
277 # don't match -{ or $currentClosing. Add these to
278 # output and continue.
279 if ( $curChar == '-' || $curChar == '}' ) {
280 self::addLiteral( $accum, $curChar );
281 }
282 ++$i;
283 continue;
284 }
285 }
286 }
287
288 if ( $found == 'angle' ) {
289 $matches = false;
290 // Handle </onlyinclude>
291 if ( $enableOnlyinclude
292 && substr( $text, $i, strlen( '</onlyinclude>' ) ) == '</onlyinclude>'
293 ) {
294 $findOnlyinclude = true;
295 continue;
296 }
297
298 // Determine element name
299 if ( !preg_match( $elementsRegex, $text, $matches, 0, $i + 1 ) ) {
300 // Element name missing or not listed
301 self::addLiteral( $accum, '<' );
302 ++$i;
303 continue;
304 }
305 // Handle comments
306 if ( isset( $matches[2] ) && $matches[2] == '!--' ) {
307 // To avoid leaving blank lines, when a sequence of
308 // space-separated comments is both preceded and followed by
309 // a newline (ignoring spaces), then
310 // trim leading and trailing spaces and the trailing newline.
311
312 // Find the end
313 $endPos = strpos( $text, '-->', $i + 4 );
314 if ( $endPos === false ) {
315 // Unclosed comment in input, runs to end
316 $inner = substr( $text, $i );
317 $accum[] = [ 'comment', [ $inner ] ];
318 $i = $lengthText;
319 } else {
320 // Search backwards for leading whitespace
321 $wsStart = $i ? ( $i - strspn( $revText, " \t", $lengthText - $i ) ) : 0;
322
323 // Search forwards for trailing whitespace
324 // $wsEnd will be the position of the last space (or the '>' if there's none)
325 $wsEnd = $endPos + 2 + strspn( $text, " \t", $endPos + 3 );
326
327 // Keep looking forward as long as we're finding more
328 // comments.
329 $comments = [ [ $wsStart, $wsEnd ] ];
330 while ( substr( $text, $wsEnd + 1, 4 ) == '<!--' ) {
331 $c = strpos( $text, '-->', $wsEnd + 4 );
332 if ( $c === false ) {
333 break;
334 }
335 $c = $c + 2 + strspn( $text, " \t", $c + 3 );
336 $comments[] = [ $wsEnd + 1, $c ];
337 $wsEnd = $c;
338 }
339
340 // Eat the line if possible
341 // TODO: This could theoretically be done if $wsStart == 0, i.e. for comments at
342 // the overall start. That's not how Sanitizer::removeHTMLcomments() did it, but
343 // it's a possible beneficial b/c break.
344 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) == "\n"
345 && substr( $text, $wsEnd + 1, 1 ) == "\n"
346 ) {
347 // Remove leading whitespace from the end of the accumulator
348 $wsLength = $i - $wsStart;
349 $endIndex = count( $accum ) - 1;
350
351 // Sanity check
352 if ( $wsLength > 0
353 && $endIndex >= 0
354 && is_string( $accum[$endIndex] )
355 && strspn( $accum[$endIndex], " \t", -$wsLength ) === $wsLength
356 ) {
357 $accum[$endIndex] = substr( $accum[$endIndex], 0, -$wsLength );
358 }
359
360 // Dump all but the last comment to the accumulator
361 foreach ( $comments as $j => $com ) {
362 $startPos = $com[0];
363 $endPos = $com[1] + 1;
364 if ( $j == ( count( $comments ) - 1 ) ) {
365 break;
366 }
367 $inner = substr( $text, $startPos, $endPos - $startPos );
368 $accum[] = [ 'comment', [ $inner ] ];
369 }
370
371 // Do a line-start run next time to look for headings after the comment
372 $fakeLineStart = true;
373 } else {
374 // No line to eat, just take the comment itself
375 $startPos = $i;
376 $endPos += 2;
377 }
378
379 if ( $stack->top ) {
380 $part = $stack->top->getCurrentPart();
381 if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
382 $part->visualEnd = $wsStart;
383 }
384 // Else comments abutting, no change in visual end
385 $part->commentEnd = $endPos;
386 }
387 $i = $endPos + 1;
388 $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
389 $accum[] = [ 'comment', [ $inner ] ];
390 }
391 continue;
392 }
393 $name = $matches[1];
394 $lowerName = strtolower( $name );
395 $attrStart = $i + strlen( $name ) + 1;
396
397 // Find end of tag
398 $tagEndPos = $noMoreGT ? false : strpos( $text, '>', $attrStart );
399 if ( $tagEndPos === false ) {
400 // Infinite backtrack
401 // Disable tag search to prevent worst-case O(N^2) performance
402 $noMoreGT = true;
403 self::addLiteral( $accum, '<' );
404 ++$i;
405 continue;
406 }
407
408 // Handle ignored tags
409 if ( in_array( $lowerName, $ignoredTags ) ) {
410 $accum[] = [ 'ignore', [ substr( $text, $i, $tagEndPos - $i + 1 ) ] ];
411 $i = $tagEndPos + 1;
412 continue;
413 }
414
415 $tagStartPos = $i;
416 if ( $text[$tagEndPos - 1] == '/' ) {
417 // Short end tag
418 $attrEnd = $tagEndPos - 1;
419 $inner = null;
420 $i = $tagEndPos + 1;
421 $close = null;
422 } else {
423 $attrEnd = $tagEndPos;
424 // Find closing tag
425 if (
426 !isset( $noMoreClosingTag[$name] ) &&
427 preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
428 $text, $matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
429 ) {
430 $inner = substr( $text, $tagEndPos + 1, $matches[0][1] - $tagEndPos - 1 );
431 $i = $matches[0][1] + strlen( $matches[0][0] );
432 $close = $matches[0][0];
433 } else {
434 // No end tag
435 if ( in_array( $name, $xmlishAllowMissingEndTag ) ) {
436 // Let it run out to the end of the text.
437 $inner = substr( $text, $tagEndPos + 1 );
438 $i = $lengthText;
439 $close = null;
440 } else {
441 // Don't match the tag, treat opening tag as literal and resume parsing.
442 $i = $tagEndPos + 1;
443 self::addLiteral( $accum,
444 substr( $text, $tagStartPos, $tagEndPos + 1 - $tagStartPos ) );
445 // Cache results, otherwise we have O(N^2) performance for input like <foo><foo><foo>...
446 $noMoreClosingTag[$name] = true;
447 continue;
448 }
449 }
450 }
451 // <includeonly> and <noinclude> just become <ignore> tags
452 if ( in_array( $lowerName, $ignoredElements ) ) {
453 $accum[] = [ 'ignore', [ substr( $text, $tagStartPos, $i - $tagStartPos ) ] ];
454 continue;
455 }
456
457 if ( $attrEnd <= $attrStart ) {
458 $attr = '';
459 } else {
460 // Note that the attr element contains the whitespace between name and attribute,
461 // this is necessary for precise reconstruction during pre-save transform.
462 $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
463 }
464
465 $children = [
466 [ 'name', [ $name ] ],
467 [ 'attr', [ $attr ] ] ];
468 if ( $inner !== null ) {
469 $children[] = [ 'inner', [ $inner ] ];
470 }
471 if ( $close !== null ) {
472 $children[] = [ 'close', [ $close ] ];
473 }
474 $accum[] = [ 'ext', $children ];
475 } elseif ( $found == 'line-start' ) {
476 // Is this the start of a heading?
477 // Line break belongs before the heading element in any case
478 if ( $fakeLineStart ) {
479 $fakeLineStart = false;
480 } else {
481 self::addLiteral( $accum, $curChar );
482 $i++;
483 }
484
485 $count = strspn( $text, '=', $i, 6 );
486 if ( $count == 1 && $findEquals ) {
487 // DWIM: This looks kind of like a name/value separator.
488 // Let's let the equals handler have it and break the potential
489 // heading. This is heuristic, but AFAICT the methods for
490 // completely correct disambiguation are very complex.
491 } elseif ( $count > 0 ) {
492 $piece = [
493 'open' => "\n",
494 'close' => "\n",
495 'parts' => [ new PPDPart_Hash( str_repeat( '=', $count ) ) ],
496 'startPos' => $i,
497 'count' => $count ];
498 $stack->push( $piece );
499 $accum =& $stack->getAccum();
500 $stackFlags = $stack->getFlags();
501 if ( isset( $stackFlags['findEquals'] ) ) {
502 $findEquals = $stackFlags['findEquals'];
503 }
504 if ( isset( $stackFlags['findPipe'] ) ) {
505 $findPipe = $stackFlags['findPipe'];
506 }
507 if ( isset( $stackFlags['inHeading'] ) ) {
508 $inHeading = $stackFlags['inHeading'];
509 }
510 $i += $count;
511 }
512 } elseif ( $found == 'line-end' ) {
513 $piece = $stack->top;
514 // A heading must be open, otherwise \n wouldn't have been in the search list
515 assert( $piece->open === "\n" );
516 $part = $piece->getCurrentPart();
517 // Search back through the input to see if it has a proper close.
518 // Do this using the reversed string since the other solutions
519 // (end anchor, etc.) are inefficient.
520 $wsLength = strspn( $revText, " \t", $lengthText - $i );
521 $searchStart = $i - $wsLength;
522 if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
523 // Comment found at line end
524 // Search for equals signs before the comment
525 $searchStart = $part->visualEnd;
526 $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart );
527 }
528 $count = $piece->count;
529 $equalsLength = strspn( $revText, '=', $lengthText - $searchStart );
530 if ( $equalsLength > 0 ) {
531 if ( $searchStart - $equalsLength == $piece->startPos ) {
532 // This is just a single string of equals signs on its own line
533 // Replicate the doHeadings behavior /={count}(.+)={count}/
534 // First find out how many equals signs there really are (don't stop at 6)
535 $count = $equalsLength;
536 if ( $count < 3 ) {
537 $count = 0;
538 } else {
539 $count = min( 6, intval( ( $count - 1 ) / 2 ) );
540 }
541 } else {
542 $count = min( $equalsLength, $count );
543 }
544 if ( $count > 0 ) {
545 // Normal match, output <h>
546 $element = [ [ 'possible-h',
547 array_merge(
548 [
549 [ '@level', [ $count ] ],
550 [ '@i', [ $headingIndex++ ] ]
551 ],
552 $accum
553 )
554 ] ];
555 } else {
556 // Single equals sign on its own line, count=0
557 $element = $accum;
558 }
559 } else {
560 // No match, no <h>, just pass down the inner text
561 $element = $accum;
562 }
563 // Unwind the stack
564 $stack->pop();
565 $accum =& $stack->getAccum();
566 $stackFlags = $stack->getFlags();
567 if ( isset( $stackFlags['findEquals'] ) ) {
568 $findEquals = $stackFlags['findEquals'];
569 }
570 if ( isset( $stackFlags['findPipe'] ) ) {
571 $findPipe = $stackFlags['findPipe'];
572 }
573 if ( isset( $stackFlags['inHeading'] ) ) {
574 $inHeading = $stackFlags['inHeading'];
575 }
576
577 // Append the result to the enclosing accumulator
578 array_splice( $accum, count( $accum ), 0, $element );
579
580 // Note that we do NOT increment the input pointer.
581 // This is because the closing linebreak could be the opening linebreak of
582 // another heading. Infinite loops are avoided because the next iteration MUST
583 // hit the heading open case above, which unconditionally increments the
584 // input pointer.
585 } elseif ( $found == 'open' ) {
586 # count opening brace characters
587 $curLen = strlen( $curChar );
588 $count = ( $curLen > 1 ) ?
589 # allow the final character to repeat
590 strspn( $text, $curChar[$curLen - 1], $i + 1 ) + 1 :
591 strspn( $text, $curChar, $i );
592
593 # we need to add to stack only if opening brace count is enough for one of the rules
594 if ( $count >= $rule['min'] ) {
595 # Add it to the stack
596 $piece = [
597 'open' => $curChar,
598 'close' => $rule['end'],
599 'count' => $count,
600 'lineStart' => ( $i > 0 && $text[$i - 1] == "\n" ),
601 ];
602
603 $stack->push( $piece );
604 $accum =& $stack->getAccum();
605 $stackFlags = $stack->getFlags();
606 if ( isset( $stackFlags['findEquals'] ) ) {
607 $findEquals = $stackFlags['findEquals'];
608 }
609 if ( isset( $stackFlags['findPipe'] ) ) {
610 $findPipe = $stackFlags['findPipe'];
611 }
612 if ( isset( $stackFlags['inHeading'] ) ) {
613 $inHeading = $stackFlags['inHeading'];
614 }
615 } else {
616 # Add literal brace(s)
617 self::addLiteral( $accum, str_repeat( $curChar, $count ) );
618 }
619 $i += $count;
620 } elseif ( $found == 'close' ) {
621 $piece = $stack->top;
622 # lets check if there are enough characters for closing brace
623 $maxCount = $piece->count;
624 if ( $piece->close === '}-' && $curChar === '}' ) {
625 $maxCount--; # don't try to match closing '-' as a '}'
626 }
627 $curLen = strlen( $curChar );
628 $count = ( $curLen > 1 ) ? $curLen :
629 strspn( $text, $curChar, $i, $maxCount );
630
631 # check for maximum matching characters (if there are 5 closing
632 # characters, we will probably need only 3 - depending on the rules)
633 $rule = $this->rules[$piece->open];
634 if ( $piece->close === '}-' && $piece->count > 2 ) {
635 # tweak for -{..{{ }}..}-
636 $rule = $this->rules['{'];
637 }
638 if ( $count > $rule['max'] ) {
639 # The specified maximum exists in the callback array, unless the caller
640 # has made an error
641 $matchingCount = $rule['max'];
642 } else {
643 # Count is less than the maximum
644 # Skip any gaps in the callback array to find the true largest match
645 # Need to use array_key_exists not isset because the callback can be null
646 $matchingCount = $count;
647 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule['names'] ) ) {
648 --$matchingCount;
649 }
650 }
651
652 if ( $matchingCount <= 0 ) {
653 # No matching element found in callback array
654 # Output a literal closing brace and continue
655 $endText = substr( $text, $i, $count );
656 self::addLiteral( $accum, $endText );
657 $i += $count;
658 continue;
659 }
660 $name = $rule['names'][$matchingCount];
661 if ( $name === null ) {
662 // No element, just literal text
663 $endText = substr( $text, $i, $matchingCount );
664 $element = $piece->breakSyntax( $matchingCount );
665 self::addLiteral( $element, $endText );
666 } else {
667 # Create XML element
668 $parts = $piece->parts;
669 $titleAccum = $parts[0]->out;
670 unset( $parts[0] );
671
672 $children = [];
673
674 # The invocation is at the start of the line if lineStart is set in
675 # the stack, and all opening brackets are used up.
676 if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
677 $children[] = [ '@lineStart', [ 1 ] ];
678 }
679 $titleNode = [ 'title', $titleAccum ];
680 $children[] = $titleNode;
681 $argIndex = 1;
682 foreach ( $parts as $part ) {
683 if ( isset( $part->eqpos ) ) {
684 $equalsNode = $part->out[$part->eqpos];
685 $nameNode = [ 'name', array_slice( $part->out, 0, $part->eqpos ) ];
686 $valueNode = [ 'value', array_slice( $part->out, $part->eqpos + 1 ) ];
687 $partNode = [ 'part', [ $nameNode, $equalsNode, $valueNode ] ];
688 $children[] = $partNode;
689 } else {
690 $nameNode = [ 'name', [ [ '@index', [ $argIndex++ ] ] ] ];
691 $valueNode = [ 'value', $part->out ];
692 $partNode = [ 'part', [ $nameNode, $valueNode ] ];
693 $children[] = $partNode;
694 }
695 }
696 $element = [ [ $name, $children ] ];
697 }
698
699 # Advance input pointer
700 $i += $matchingCount;
701
702 # Unwind the stack
703 $stack->pop();
704 $accum =& $stack->getAccum();
705
706 # Re-add the old stack element if it still has unmatched opening characters remaining
707 if ( $matchingCount < $piece->count ) {
708 $piece->parts = [ new PPDPart_Hash ];
709 $piece->count -= $matchingCount;
710 # do we still qualify for any callback with remaining count?
711 $min = $this->rules[$piece->open]['min'];
712 if ( $piece->count >= $min ) {
713 $stack->push( $piece );
714 $accum =& $stack->getAccum();
715 } else {
716 $s = substr( $piece->open, 0, -1 );
717 $s .= str_repeat(
718 substr( $piece->open, -1 ),
719 $piece->count - strlen( $s )
720 );
721 self::addLiteral( $accum, $s );
722 }
723 }
724
725 $stackFlags = $stack->getFlags();
726 if ( isset( $stackFlags['findEquals'] ) ) {
727 $findEquals = $stackFlags['findEquals'];
728 }
729 if ( isset( $stackFlags['findPipe'] ) ) {
730 $findPipe = $stackFlags['findPipe'];
731 }
732 if ( isset( $stackFlags['inHeading'] ) ) {
733 $inHeading = $stackFlags['inHeading'];
734 }
735
736 # Add XML element to the enclosing accumulator
737 array_splice( $accum, count( $accum ), 0, $element );
738 } elseif ( $found == 'pipe' ) {
739 $findEquals = true; // shortcut for getFlags()
740 $stack->addPart();
741 $accum =& $stack->getAccum();
742 ++$i;
743 } elseif ( $found == 'equals' ) {
744 $findEquals = false; // shortcut for getFlags()
745 $accum[] = [ 'equals', [ '=' ] ];
746 $stack->getCurrentPart()->eqpos = count( $accum ) - 1;
747 ++$i;
748 } elseif ( $found == 'dash' ) {
749 self::addLiteral( $accum, '-' );
750 ++$i;
751 }
752 }
753
754 # Output any remaining unclosed brackets
755 foreach ( $stack->stack as $piece ) {
756 array_splice( $stack->rootAccum, count( $stack->rootAccum ), 0, $piece->breakSyntax() );
757 }
758
759 # Enable top-level headings
760 foreach ( $stack->rootAccum as &$node ) {
761 if ( is_array( $node ) && $node[PPNode_Hash_Tree::NAME] === 'possible-h' ) {
762 $node[PPNode_Hash_Tree::NAME] = 'h';
763 }
764 }
765
766 $rootStore = [ [ 'root', $stack->rootAccum ] ];
767 $rootNode = new PPNode_Hash_Tree( $rootStore, 0 );
768
769 // Cache
770 $tree = json_encode( $rootStore, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
771 if ( $tree !== false ) {
772 $this->cacheSetTree( $text, $flags, $tree );
773 }
774
775 return $rootNode;
776 }
777
778 private static function addLiteral( array &$accum, $text ) {
779 $n = count( $accum );
780 if ( $n && is_string( $accum[$n - 1] ) ) {
781 $accum[$n - 1] .= $text;
782 } else {
783 $accum[] = $text;
784 }
785 }
786 }
787
788 /**
789 * Stack class to help Preprocessor::preprocessToObj()
790 * @ingroup Parser
791 */
792 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
793 class PPDStack_Hash extends PPDStack {
794 // @codingStandardsIgnoreEnd
795
796 public function __construct() {
797 $this->elementClass = 'PPDStackElement_Hash';
798 parent::__construct();
799 $this->rootAccum = [];
800 }
801 }
802
803 /**
804 * @ingroup Parser
805 */
806 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
807 class PPDStackElement_Hash extends PPDStackElement {
808 // @codingStandardsIgnoreEnd
809
810 public function __construct( $data = [] ) {
811 $this->partClass = 'PPDPart_Hash';
812 parent::__construct( $data );
813 }
814
815 /**
816 * Get the accumulator that would result if the close is not found.
817 *
818 * @param int|bool $openingCount
819 * @return array
820 */
821 public function breakSyntax( $openingCount = false ) {
822 if ( $this->open == "\n" ) {
823 $accum = $this->parts[0]->out;
824 } else {
825 if ( $openingCount === false ) {
826 $openingCount = $this->count;
827 }
828 $s = substr( $this->open, 0, -1 );
829 $s .= str_repeat(
830 substr( $this->open, -1 ),
831 $openingCount - strlen( $s )
832 );
833 $accum = [ $s ];
834 $lastIndex = 0;
835 $first = true;
836 foreach ( $this->parts as $part ) {
837 if ( $first ) {
838 $first = false;
839 } elseif ( is_string( $accum[$lastIndex] ) ) {
840 $accum[$lastIndex] .= '|';
841 } else {
842 $accum[++$lastIndex] = '|';
843 }
844 foreach ( $part->out as $node ) {
845 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
846 $accum[$lastIndex] .= $node;
847 } else {
848 $accum[++$lastIndex] = $node;
849 }
850 }
851 }
852 }
853 return $accum;
854 }
855 }
856
857 /**
858 * @ingroup Parser
859 */
860 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
861 class PPDPart_Hash extends PPDPart {
862 // @codingStandardsIgnoreEnd
863
864 public function __construct( $out = '' ) {
865 if ( $out !== '' ) {
866 $accum = [ $out ];
867 } else {
868 $accum = [];
869 }
870 parent::__construct( $accum );
871 }
872 }
873
874 /**
875 * An expansion frame, used as a context to expand the result of preprocessToObj()
876 * @ingroup Parser
877 */
878 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
879 class PPFrame_Hash implements PPFrame {
880 // @codingStandardsIgnoreEnd
881
882 /**
883 * @var Parser
884 */
885 public $parser;
886
887 /**
888 * @var Preprocessor
889 */
890 public $preprocessor;
891
892 /**
893 * @var Title
894 */
895 public $title;
896 public $titleCache;
897
898 /**
899 * Hashtable listing templates which are disallowed for expansion in this frame,
900 * having been encountered previously in parent frames.
901 */
902 public $loopCheckHash;
903
904 /**
905 * Recursion depth of this frame, top = 0
906 * Note that this is NOT the same as expansion depth in expand()
907 */
908 public $depth;
909
910 private $volatile = false;
911 private $ttl = null;
912
913 /**
914 * @var array
915 */
916 protected $childExpansionCache;
917
918 /**
919 * Construct a new preprocessor frame.
920 * @param Preprocessor $preprocessor The parent preprocessor
921 */
922 public function __construct( $preprocessor ) {
923 $this->preprocessor = $preprocessor;
924 $this->parser = $preprocessor->parser;
925 $this->title = $this->parser->mTitle;
926 $this->titleCache = [ $this->title ? $this->title->getPrefixedDBkey() : false ];
927 $this->loopCheckHash = [];
928 $this->depth = 0;
929 $this->childExpansionCache = [];
930 }
931
932 /**
933 * Create a new child frame
934 * $args is optionally a multi-root PPNode or array containing the template arguments
935 *
936 * @param array|bool|PPNode_Hash_Array $args
937 * @param Title|bool $title
938 * @param int $indexOffset
939 * @throws MWException
940 * @return PPTemplateFrame_Hash
941 */
942 public function newChild( $args = false, $title = false, $indexOffset = 0 ) {
943 $namedArgs = [];
944 $numberedArgs = [];
945 if ( $title === false ) {
946 $title = $this->title;
947 }
948 if ( $args !== false ) {
949 if ( $args instanceof PPNode_Hash_Array ) {
950 $args = $args->value;
951 } elseif ( !is_array( $args ) ) {
952 throw new MWException( __METHOD__ . ': $args must be array or PPNode_Hash_Array' );
953 }
954 foreach ( $args as $arg ) {
955 $bits = $arg->splitArg();
956 if ( $bits['index'] !== '' ) {
957 // Numbered parameter
958 $index = $bits['index'] - $indexOffset;
959 if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
960 $this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning',
961 wfEscapeWikiText( $this->title ),
962 wfEscapeWikiText( $title ),
963 wfEscapeWikiText( $index ) )->text() );
964 $this->parser->addTrackingCategory( 'duplicate-args-category' );
965 }
966 $numberedArgs[$index] = $bits['value'];
967 unset( $namedArgs[$index] );
968 } else {
969 // Named parameter
970 $name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
971 if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) {
972 $this->parser->getOutput()->addWarning( wfMessage( 'duplicate-args-warning',
973 wfEscapeWikiText( $this->title ),
974 wfEscapeWikiText( $title ),
975 wfEscapeWikiText( $name ) )->text() );
976 $this->parser->addTrackingCategory( 'duplicate-args-category' );
977 }
978 $namedArgs[$name] = $bits['value'];
979 unset( $numberedArgs[$name] );
980 }
981 }
982 }
983 return new PPTemplateFrame_Hash( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
984 }
985
986 /**
987 * @throws MWException
988 * @param string|int $key
989 * @param string|PPNode $root
990 * @param int $flags
991 * @return string
992 */
993 public function cachedExpand( $key, $root, $flags = 0 ) {
994 // we don't have a parent, so we don't have a cache
995 return $this->expand( $root, $flags );
996 }
997
998 /**
999 * @throws MWException
1000 * @param string|PPNode $root
1001 * @param int $flags
1002 * @return string
1003 */
1004 public function expand( $root, $flags = 0 ) {
1005 static $expansionDepth = 0;
1006 if ( is_string( $root ) ) {
1007 return $root;
1008 }
1009
1010 if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
1011 $this->parser->limitationWarn( 'node-count-exceeded',
1012 $this->parser->mPPNodeCount,
1013 $this->parser->mOptions->getMaxPPNodeCount()
1014 );
1015 return '<span class="error">Node-count limit exceeded</span>';
1016 }
1017 if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
1018 $this->parser->limitationWarn( 'expansion-depth-exceeded',
1019 $expansionDepth,
1020 $this->parser->mOptions->getMaxPPExpandDepth()
1021 );
1022 return '<span class="error">Expansion depth limit exceeded</span>';
1023 }
1024 ++$expansionDepth;
1025 if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
1026 $this->parser->mHighestExpansionDepth = $expansionDepth;
1027 }
1028
1029 $outStack = [ '', '' ];
1030 $iteratorStack = [ false, $root ];
1031 $indexStack = [ 0, 0 ];
1032
1033 while ( count( $iteratorStack ) > 1 ) {
1034 $level = count( $outStack ) - 1;
1035 $iteratorNode =& $iteratorStack[$level];
1036 $out =& $outStack[$level];
1037 $index =& $indexStack[$level];
1038
1039 if ( is_array( $iteratorNode ) ) {
1040 if ( $index >= count( $iteratorNode ) ) {
1041 // All done with this iterator
1042 $iteratorStack[$level] = false;
1043 $contextNode = false;
1044 } else {
1045 $contextNode = $iteratorNode[$index];
1046 $index++;
1047 }
1048 } elseif ( $iteratorNode instanceof PPNode_Hash_Array ) {
1049 if ( $index >= $iteratorNode->getLength() ) {
1050 // All done with this iterator
1051 $iteratorStack[$level] = false;
1052 $contextNode = false;
1053 } else {
1054 $contextNode = $iteratorNode->item( $index );
1055 $index++;
1056 }
1057 } else {
1058 // Copy to $contextNode and then delete from iterator stack,
1059 // because this is not an iterator but we do have to execute it once
1060 $contextNode = $iteratorStack[$level];
1061 $iteratorStack[$level] = false;
1062 }
1063
1064 $newIterator = false;
1065 $contextName = false;
1066 $contextChildren = false;
1067
1068 if ( $contextNode === false ) {
1069 // nothing to do
1070 } elseif ( is_string( $contextNode ) ) {
1071 $out .= $contextNode;
1072 } elseif ( $contextNode instanceof PPNode_Hash_Array ) {
1073 $newIterator = $contextNode;
1074 } elseif ( $contextNode instanceof PPNode_Hash_Attr ) {
1075 // No output
1076 } elseif ( $contextNode instanceof PPNode_Hash_Text ) {
1077 $out .= $contextNode->value;
1078 } elseif ( $contextNode instanceof PPNode_Hash_Tree ) {
1079 $contextName = $contextNode->name;
1080 $contextChildren = $contextNode->getRawChildren();
1081 } elseif ( is_array( $contextNode ) ) {
1082 // Node descriptor array
1083 if ( count( $contextNode ) !== 2 ) {
1084 throw new MWException( __METHOD__.
1085 ': found an array where a node descriptor should be' );
1086 }
1087 list( $contextName, $contextChildren ) = $contextNode;
1088 } else {
1089 throw new MWException( __METHOD__ . ': Invalid parameter type' );
1090 }
1091
1092 // Handle node descriptor array or tree object
1093 if ( $contextName === false ) {
1094 // Not a node, already handled above
1095 } elseif ( $contextName[0] === '@' ) {
1096 // Attribute: no output
1097 } elseif ( $contextName === 'template' ) {
1098 # Double-brace expansion
1099 $bits = PPNode_Hash_Tree::splitRawTemplate( $contextChildren );
1100 if ( $flags & PPFrame::NO_TEMPLATES ) {
1101 $newIterator = $this->virtualBracketedImplode(
1102 '{{', '|', '}}',
1103 $bits['title'],
1104 $bits['parts']
1105 );
1106 } else {
1107 $ret = $this->parser->braceSubstitution( $bits, $this );
1108 if ( isset( $ret['object'] ) ) {
1109 $newIterator = $ret['object'];
1110 } else {
1111 $out .= $ret['text'];
1112 }
1113 }
1114 } elseif ( $contextName === 'tplarg' ) {
1115 # Triple-brace expansion
1116 $bits = PPNode_Hash_Tree::splitRawTemplate( $contextChildren );
1117 if ( $flags & PPFrame::NO_ARGS ) {
1118 $newIterator = $this->virtualBracketedImplode(
1119 '{{{', '|', '}}}',
1120 $bits['title'],
1121 $bits['parts']
1122 );
1123 } else {
1124 $ret = $this->parser->argSubstitution( $bits, $this );
1125 if ( isset( $ret['object'] ) ) {
1126 $newIterator = $ret['object'];
1127 } else {
1128 $out .= $ret['text'];
1129 }
1130 }
1131 } elseif ( $contextName === 'comment' ) {
1132 # HTML-style comment
1133 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1134 # Not in RECOVER_COMMENTS mode (msgnw) though.
1135 if ( ( $this->parser->ot['html']
1136 || ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() )
1137 || ( $flags & PPFrame::STRIP_COMMENTS )
1138 ) && !( $flags & PPFrame::RECOVER_COMMENTS )
1139 ) {
1140 $out .= '';
1141 } elseif ( $this->parser->ot['wiki'] && !( $flags & PPFrame::RECOVER_COMMENTS ) ) {
1142 # Add a strip marker in PST mode so that pstPass2() can
1143 # run some old-fashioned regexes on the result.
1144 # Not in RECOVER_COMMENTS mode (extractSections) though.
1145 $out .= $this->parser->insertStripItem( $contextChildren[0] );
1146 } else {
1147 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1148 $out .= $contextChildren[0];
1149 }
1150 } elseif ( $contextName === 'ignore' ) {
1151 # Output suppression used by <includeonly> etc.
1152 # OT_WIKI will only respect <ignore> in substed templates.
1153 # The other output types respect it unless NO_IGNORE is set.
1154 # extractSections() sets NO_IGNORE and so never respects it.
1155 if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] )
1156 || ( $flags & PPFrame::NO_IGNORE )
1157 ) {
1158 $out .= $contextChildren[0];
1159 } else {
1160 // $out .= '';
1161 }
1162 } elseif ( $contextName === 'ext' ) {
1163 # Extension tag
1164 $bits = PPNode_Hash_Tree::splitRawExt( $contextChildren ) +
1165 [ 'attr' => null, 'inner' => null, 'close' => null ];
1166 if ( $flags & PPFrame::NO_TAGS ) {
1167 $s = '<' . $bits['name']->getFirstChild()->value;
1168 if ( $bits['attr'] ) {
1169 $s .= $bits['attr']->getFirstChild()->value;
1170 }
1171 if ( $bits['inner'] ) {
1172 $s .= '>' . $bits['inner']->getFirstChild()->value;
1173 if ( $bits['close'] ) {
1174 $s .= $bits['close']->getFirstChild()->value;
1175 }
1176 } else {
1177 $s .= '/>';
1178 }
1179 $out .= $s;
1180 } else {
1181 $out .= $this->parser->extensionSubstitution( $bits, $this );
1182 }
1183 } elseif ( $contextName === 'h' ) {
1184 # Heading
1185 if ( $this->parser->ot['html'] ) {
1186 # Expand immediately and insert heading index marker
1187 $s = $this->expand( $contextChildren, $flags );
1188 $bits = PPNode_Hash_Tree::splitRawHeading( $contextChildren );
1189 $titleText = $this->title->getPrefixedDBkey();
1190 $this->parser->mHeadings[] = [ $titleText, $bits['i'] ];
1191 $serial = count( $this->parser->mHeadings ) - 1;
1192 $marker = Parser::MARKER_PREFIX . "-h-$serial-" . Parser::MARKER_SUFFIX;
1193 $s = substr( $s, 0, $bits['level'] ) . $marker . substr( $s, $bits['level'] );
1194 $this->parser->mStripState->addGeneral( $marker, '' );
1195 $out .= $s;
1196 } else {
1197 # Expand in virtual stack
1198 $newIterator = $contextChildren;
1199 }
1200 } else {
1201 # Generic recursive expansion
1202 $newIterator = $contextChildren;
1203 }
1204
1205 if ( $newIterator !== false ) {
1206 $outStack[] = '';
1207 $iteratorStack[] = $newIterator;
1208 $indexStack[] = 0;
1209 } elseif ( $iteratorStack[$level] === false ) {
1210 // Return accumulated value to parent
1211 // With tail recursion
1212 while ( $iteratorStack[$level] === false && $level > 0 ) {
1213 $outStack[$level - 1] .= $out;
1214 array_pop( $outStack );
1215 array_pop( $iteratorStack );
1216 array_pop( $indexStack );
1217 $level--;
1218 }
1219 }
1220 }
1221 --$expansionDepth;
1222 return $outStack[0];
1223 }
1224
1225 /**
1226 * @param string $sep
1227 * @param int $flags
1228 * @param string|PPNode $args,...
1229 * @return string
1230 */
1231 public function implodeWithFlags( $sep, $flags /*, ... */ ) {
1232 $args = array_slice( func_get_args(), 2 );
1233
1234 $first = true;
1235 $s = '';
1236 foreach ( $args as $root ) {
1237 if ( $root instanceof PPNode_Hash_Array ) {
1238 $root = $root->value;
1239 }
1240 if ( !is_array( $root ) ) {
1241 $root = [ $root ];
1242 }
1243 foreach ( $root as $node ) {
1244 if ( $first ) {
1245 $first = false;
1246 } else {
1247 $s .= $sep;
1248 }
1249 $s .= $this->expand( $node, $flags );
1250 }
1251 }
1252 return $s;
1253 }
1254
1255 /**
1256 * Implode with no flags specified
1257 * This previously called implodeWithFlags but has now been inlined to reduce stack depth
1258 * @param string $sep
1259 * @param string|PPNode $args,...
1260 * @return string
1261 */
1262 public function implode( $sep /*, ... */ ) {
1263 $args = array_slice( func_get_args(), 1 );
1264
1265 $first = true;
1266 $s = '';
1267 foreach ( $args as $root ) {
1268 if ( $root instanceof PPNode_Hash_Array ) {
1269 $root = $root->value;
1270 }
1271 if ( !is_array( $root ) ) {
1272 $root = [ $root ];
1273 }
1274 foreach ( $root as $node ) {
1275 if ( $first ) {
1276 $first = false;
1277 } else {
1278 $s .= $sep;
1279 }
1280 $s .= $this->expand( $node );
1281 }
1282 }
1283 return $s;
1284 }
1285
1286 /**
1287 * Makes an object that, when expand()ed, will be the same as one obtained
1288 * with implode()
1289 *
1290 * @param string $sep
1291 * @param string|PPNode $args,...
1292 * @return PPNode_Hash_Array
1293 */
1294 public function virtualImplode( $sep /*, ... */ ) {
1295 $args = array_slice( func_get_args(), 1 );
1296 $out = [];
1297 $first = true;
1298
1299 foreach ( $args as $root ) {
1300 if ( $root instanceof PPNode_Hash_Array ) {
1301 $root = $root->value;
1302 }
1303 if ( !is_array( $root ) ) {
1304 $root = [ $root ];
1305 }
1306 foreach ( $root as $node ) {
1307 if ( $first ) {
1308 $first = false;
1309 } else {
1310 $out[] = $sep;
1311 }
1312 $out[] = $node;
1313 }
1314 }
1315 return new PPNode_Hash_Array( $out );
1316 }
1317
1318 /**
1319 * Virtual implode with brackets
1320 *
1321 * @param string $start
1322 * @param string $sep
1323 * @param string $end
1324 * @param string|PPNode $args,...
1325 * @return PPNode_Hash_Array
1326 */
1327 public function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
1328 $args = array_slice( func_get_args(), 3 );
1329 $out = [ $start ];
1330 $first = true;
1331
1332 foreach ( $args as $root ) {
1333 if ( $root instanceof PPNode_Hash_Array ) {
1334 $root = $root->value;
1335 }
1336 if ( !is_array( $root ) ) {
1337 $root = [ $root ];
1338 }
1339 foreach ( $root as $node ) {
1340 if ( $first ) {
1341 $first = false;
1342 } else {
1343 $out[] = $sep;
1344 }
1345 $out[] = $node;
1346 }
1347 }
1348 $out[] = $end;
1349 return new PPNode_Hash_Array( $out );
1350 }
1351
1352 public function __toString() {
1353 return 'frame{}';
1354 }
1355
1356 /**
1357 * @param bool $level
1358 * @return array|bool|string
1359 */
1360 public function getPDBK( $level = false ) {
1361 if ( $level === false ) {
1362 return $this->title->getPrefixedDBkey();
1363 } else {
1364 return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] : false;
1365 }
1366 }
1367
1368 /**
1369 * @return array
1370 */
1371 public function getArguments() {
1372 return [];
1373 }
1374
1375 /**
1376 * @return array
1377 */
1378 public function getNumberedArguments() {
1379 return [];
1380 }
1381
1382 /**
1383 * @return array
1384 */
1385 public function getNamedArguments() {
1386 return [];
1387 }
1388
1389 /**
1390 * Returns true if there are no arguments in this frame
1391 *
1392 * @return bool
1393 */
1394 public function isEmpty() {
1395 return true;
1396 }
1397
1398 /**
1399 * @param int|string $name
1400 * @return bool Always false in this implementation.
1401 */
1402 public function getArgument( $name ) {
1403 return false;
1404 }
1405
1406 /**
1407 * Returns true if the infinite loop check is OK, false if a loop is detected
1408 *
1409 * @param Title $title
1410 *
1411 * @return bool
1412 */
1413 public function loopCheck( $title ) {
1414 return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
1415 }
1416
1417 /**
1418 * Return true if the frame is a template frame
1419 *
1420 * @return bool
1421 */
1422 public function isTemplate() {
1423 return false;
1424 }
1425
1426 /**
1427 * Get a title of frame
1428 *
1429 * @return Title
1430 */
1431 public function getTitle() {
1432 return $this->title;
1433 }
1434
1435 /**
1436 * Set the volatile flag
1437 *
1438 * @param bool $flag
1439 */
1440 public function setVolatile( $flag = true ) {
1441 $this->volatile = $flag;
1442 }
1443
1444 /**
1445 * Get the volatile flag
1446 *
1447 * @return bool
1448 */
1449 public function isVolatile() {
1450 return $this->volatile;
1451 }
1452
1453 /**
1454 * Set the TTL
1455 *
1456 * @param int $ttl
1457 */
1458 public function setTTL( $ttl ) {
1459 if ( $ttl !== null && ( $this->ttl === null || $ttl < $this->ttl ) ) {
1460 $this->ttl = $ttl;
1461 }
1462 }
1463
1464 /**
1465 * Get the TTL
1466 *
1467 * @return int|null
1468 */
1469 public function getTTL() {
1470 return $this->ttl;
1471 }
1472 }
1473
1474 /**
1475 * Expansion frame with template arguments
1476 * @ingroup Parser
1477 */
1478 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
1479 class PPTemplateFrame_Hash extends PPFrame_Hash {
1480 // @codingStandardsIgnoreEnd
1481
1482 public $numberedArgs, $namedArgs, $parent;
1483 public $numberedExpansionCache, $namedExpansionCache;
1484
1485 /**
1486 * @param Preprocessor $preprocessor
1487 * @param bool|PPFrame $parent
1488 * @param array $numberedArgs
1489 * @param array $namedArgs
1490 * @param bool|Title $title
1491 */
1492 public function __construct( $preprocessor, $parent = false, $numberedArgs = [],
1493 $namedArgs = [], $title = false
1494 ) {
1495 parent::__construct( $preprocessor );
1496
1497 $this->parent = $parent;
1498 $this->numberedArgs = $numberedArgs;
1499 $this->namedArgs = $namedArgs;
1500 $this->title = $title;
1501 $pdbk = $title ? $title->getPrefixedDBkey() : false;
1502 $this->titleCache = $parent->titleCache;
1503 $this->titleCache[] = $pdbk;
1504 $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
1505 if ( $pdbk !== false ) {
1506 $this->loopCheckHash[$pdbk] = true;
1507 }
1508 $this->depth = $parent->depth + 1;
1509 $this->numberedExpansionCache = $this->namedExpansionCache = [];
1510 }
1511
1512 public function __toString() {
1513 $s = 'tplframe{';
1514 $first = true;
1515 $args = $this->numberedArgs + $this->namedArgs;
1516 foreach ( $args as $name => $value ) {
1517 if ( $first ) {
1518 $first = false;
1519 } else {
1520 $s .= ', ';
1521 }
1522 $s .= "\"$name\":\"" .
1523 str_replace( '"', '\\"', $value->__toString() ) . '"';
1524 }
1525 $s .= '}';
1526 return $s;
1527 }
1528
1529 /**
1530 * @throws MWException
1531 * @param string|int $key
1532 * @param string|PPNode $root
1533 * @param int $flags
1534 * @return string
1535 */
1536 public function cachedExpand( $key, $root, $flags = 0 ) {
1537 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
1538 return $this->parent->childExpansionCache[$key];
1539 }
1540 $retval = $this->expand( $root, $flags );
1541 if ( !$this->isVolatile() ) {
1542 $this->parent->childExpansionCache[$key] = $retval;
1543 }
1544 return $retval;
1545 }
1546
1547 /**
1548 * Returns true if there are no arguments in this frame
1549 *
1550 * @return bool
1551 */
1552 public function isEmpty() {
1553 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
1554 }
1555
1556 /**
1557 * @return array
1558 */
1559 public function getArguments() {
1560 $arguments = [];
1561 foreach ( array_merge(
1562 array_keys( $this->numberedArgs ),
1563 array_keys( $this->namedArgs ) ) as $key ) {
1564 $arguments[$key] = $this->getArgument( $key );
1565 }
1566 return $arguments;
1567 }
1568
1569 /**
1570 * @return array
1571 */
1572 public function getNumberedArguments() {
1573 $arguments = [];
1574 foreach ( array_keys( $this->numberedArgs ) as $key ) {
1575 $arguments[$key] = $this->getArgument( $key );
1576 }
1577 return $arguments;
1578 }
1579
1580 /**
1581 * @return array
1582 */
1583 public function getNamedArguments() {
1584 $arguments = [];
1585 foreach ( array_keys( $this->namedArgs ) as $key ) {
1586 $arguments[$key] = $this->getArgument( $key );
1587 }
1588 return $arguments;
1589 }
1590
1591 /**
1592 * @param int $index
1593 * @return string|bool
1594 */
1595 public function getNumberedArgument( $index ) {
1596 if ( !isset( $this->numberedArgs[$index] ) ) {
1597 return false;
1598 }
1599 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1600 # No trimming for unnamed arguments
1601 $this->numberedExpansionCache[$index] = $this->parent->expand(
1602 $this->numberedArgs[$index],
1603 PPFrame::STRIP_COMMENTS
1604 );
1605 }
1606 return $this->numberedExpansionCache[$index];
1607 }
1608
1609 /**
1610 * @param string $name
1611 * @return string|bool
1612 */
1613 public function getNamedArgument( $name ) {
1614 if ( !isset( $this->namedArgs[$name] ) ) {
1615 return false;
1616 }
1617 if ( !isset( $this->namedExpansionCache[$name] ) ) {
1618 # Trim named arguments post-expand, for backwards compatibility
1619 $this->namedExpansionCache[$name] = trim(
1620 $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
1621 }
1622 return $this->namedExpansionCache[$name];
1623 }
1624
1625 /**
1626 * @param int|string $name
1627 * @return string|bool
1628 */
1629 public function getArgument( $name ) {
1630 $text = $this->getNumberedArgument( $name );
1631 if ( $text === false ) {
1632 $text = $this->getNamedArgument( $name );
1633 }
1634 return $text;
1635 }
1636
1637 /**
1638 * Return true if the frame is a template frame
1639 *
1640 * @return bool
1641 */
1642 public function isTemplate() {
1643 return true;
1644 }
1645
1646 public function setVolatile( $flag = true ) {
1647 parent::setVolatile( $flag );
1648 $this->parent->setVolatile( $flag );
1649 }
1650
1651 public function setTTL( $ttl ) {
1652 parent::setTTL( $ttl );
1653 $this->parent->setTTL( $ttl );
1654 }
1655 }
1656
1657 /**
1658 * Expansion frame with custom arguments
1659 * @ingroup Parser
1660 */
1661 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
1662 class PPCustomFrame_Hash extends PPFrame_Hash {
1663 // @codingStandardsIgnoreEnd
1664
1665 public $args;
1666
1667 public function __construct( $preprocessor, $args ) {
1668 parent::__construct( $preprocessor );
1669 $this->args = $args;
1670 }
1671
1672 public function __toString() {
1673 $s = 'cstmframe{';
1674 $first = true;
1675 foreach ( $this->args as $name => $value ) {
1676 if ( $first ) {
1677 $first = false;
1678 } else {
1679 $s .= ', ';
1680 }
1681 $s .= "\"$name\":\"" .
1682 str_replace( '"', '\\"', $value->__toString() ) . '"';
1683 }
1684 $s .= '}';
1685 return $s;
1686 }
1687
1688 /**
1689 * @return bool
1690 */
1691 public function isEmpty() {
1692 return !count( $this->args );
1693 }
1694
1695 /**
1696 * @param int|string $index
1697 * @return string|bool
1698 */
1699 public function getArgument( $index ) {
1700 if ( !isset( $this->args[$index] ) ) {
1701 return false;
1702 }
1703 return $this->args[$index];
1704 }
1705
1706 public function getArguments() {
1707 return $this->args;
1708 }
1709 }
1710
1711 /**
1712 * @ingroup Parser
1713 */
1714 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
1715 class PPNode_Hash_Tree implements PPNode {
1716 // @codingStandardsIgnoreEnd
1717
1718 public $name;
1719
1720 /**
1721 * The store array for children of this node. It is "raw" in the sense that
1722 * nodes are two-element arrays ("descriptors") rather than PPNode_Hash_*
1723 * objects.
1724 */
1725 private $rawChildren;
1726
1727 /**
1728 * The store array for the siblings of this node, including this node itself.
1729 */
1730 private $store;
1731
1732 /**
1733 * The index into $this->store which contains the descriptor of this node.
1734 */
1735 private $index;
1736
1737 /**
1738 * The offset of the name within descriptors, used in some places for
1739 * readability.
1740 */
1741 const NAME = 0;
1742
1743 /**
1744 * The offset of the child list within descriptors, used in some places for
1745 * readability.
1746 */
1747 const CHILDREN = 1;
1748
1749 /**
1750 * Construct an object using the data from $store[$index]. The rest of the
1751 * store array can be accessed via getNextSibling().
1752 *
1753 * @param array $store
1754 * @param int $index
1755 */
1756 public function __construct( array $store, $index ) {
1757 $this->store = $store;
1758 $this->index = $index;
1759 list( $this->name, $this->rawChildren ) = $this->store[$index];
1760 }
1761
1762 /**
1763 * Construct an appropriate PPNode_Hash_* object with a class that depends
1764 * on what is at the relevant store index.
1765 *
1766 * @param array $store
1767 * @param int $index
1768 * @return PPNode_Hash_Tree|PPNode_Hash_Attr|PPNode_Hash_Text
1769 */
1770 public static function factory( array $store, $index ) {
1771 if ( !isset( $store[$index] ) ) {
1772 return false;
1773 }
1774
1775 $descriptor = $store[$index];
1776 if ( is_string( $descriptor ) ) {
1777 $class = 'PPNode_Hash_Text';
1778 } elseif ( is_array( $descriptor ) ) {
1779 if ( $descriptor[self::NAME][0] === '@' ) {
1780 $class = 'PPNode_Hash_Attr';
1781 } else {
1782 $class = 'PPNode_Hash_Tree';
1783 }
1784 } else {
1785 throw new MWException( __METHOD__.': invalid node descriptor' );
1786 }
1787 return new $class( $store, $index );
1788 }
1789
1790 /**
1791 * Convert a node to XML, for debugging
1792 */
1793 public function __toString() {
1794 $inner = '';
1795 $attribs = '';
1796 for ( $node = $this->getFirstChild(); $node; $node = $node->getNextSibling() ) {
1797 if ( $node instanceof PPNode_Hash_Attr ) {
1798 $attribs .= ' ' . $node->name . '="' . htmlspecialchars( $node->value ) . '"';
1799 } else {
1800 $inner .= $node->__toString();
1801 }
1802 }
1803 if ( $inner === '' ) {
1804 return "<{$this->name}$attribs/>";
1805 } else {
1806 return "<{$this->name}$attribs>$inner</{$this->name}>";
1807 }
1808 }
1809
1810 /**
1811 * @return PPNode_Hash_Array
1812 */
1813 public function getChildren() {
1814 $children = [];
1815 foreach ( $this->rawChildren as $i => $child ) {
1816 $children[] = self::factory( $this->rawChildren, $i );
1817 }
1818 return new PPNode_Hash_Array( $children );
1819 }
1820
1821 /**
1822 * Get the first child, or false if there is none. Note that this will
1823 * return a temporary proxy object: different instances will be returned
1824 * if this is called more than once on the same node.
1825 *
1826 * @return PPNode_Hash_Tree|PPNode_Hash_Attr|PPNode_Hash_Text|bool
1827 */
1828 public function getFirstChild() {
1829 if ( !isset( $this->rawChildren[0] ) ) {
1830 return false;
1831 } else {
1832 return self::factory( $this->rawChildren, 0 );
1833 }
1834 }
1835
1836 /**
1837 * Get the next sibling, or false if there is none. Note that this will
1838 * return a temporary proxy object: different instances will be returned
1839 * if this is called more than once on the same node.
1840 *
1841 * @return PPNode_Hash_Tree|PPNode_Hash_Attr|PPNode_Hash_Text|bool
1842 */
1843 public function getNextSibling() {
1844 return self::factory( $this->store, $this->index + 1 );
1845 }
1846
1847 /**
1848 * Get an array of the children with a given node name
1849 *
1850 * @param string $name
1851 * @return PPNode_Hash_Array
1852 */
1853 public function getChildrenOfType( $name ) {
1854 $children = [];
1855 foreach ( $this->rawChildren as $i => $child ) {
1856 if ( is_array( $child ) && $child[self::NAME] === $name ) {
1857 $children[] = self::factory( $this->rawChildren, $i );
1858 }
1859 }
1860 return new PPNode_Hash_Array( $children );
1861 }
1862
1863 /**
1864 * Get the raw child array. For internal use.
1865 * @return array
1866 */
1867 public function getRawChildren() {
1868 return $this->rawChildren;
1869 }
1870
1871 /**
1872 * @return bool
1873 */
1874 public function getLength() {
1875 return false;
1876 }
1877
1878 /**
1879 * @param int $i
1880 * @return bool
1881 */
1882 public function item( $i ) {
1883 return false;
1884 }
1885
1886 /**
1887 * @return string
1888 */
1889 public function getName() {
1890 return $this->name;
1891 }
1892
1893 /**
1894 * Split a "<part>" node into an associative array containing:
1895 * - name PPNode name
1896 * - index String index
1897 * - value PPNode value
1898 *
1899 * @throws MWException
1900 * @return array
1901 */
1902 public function splitArg() {
1903 return self::splitRawArg( $this->rawChildren );
1904 }
1905
1906 /**
1907 * Like splitArg() but for a raw child array. For internal use only.
1908 * @param array $children
1909 * @return array
1910 */
1911 public static function splitRawArg( array $children ) {
1912 $bits = [];
1913 foreach ( $children as $i => $child ) {
1914 if ( !is_array( $child ) ) {
1915 continue;
1916 }
1917 if ( $child[self::NAME] === 'name' ) {
1918 $bits['name'] = new self( $children, $i );
1919 if ( isset( $child[self::CHILDREN][0][self::NAME] )
1920 && $child[self::CHILDREN][0][self::NAME] === '@index'
1921 ) {
1922 $bits['index'] = $child[self::CHILDREN][0][self::CHILDREN][0];
1923 }
1924 } elseif ( $child[self::NAME] === 'value' ) {
1925 $bits['value'] = new self( $children, $i );
1926 }
1927 }
1928
1929 if ( !isset( $bits['name'] ) ) {
1930 throw new MWException( 'Invalid brace node passed to ' . __METHOD__ );
1931 }
1932 if ( !isset( $bits['index'] ) ) {
1933 $bits['index'] = '';
1934 }
1935 return $bits;
1936 }
1937
1938 /**
1939 * Split an "<ext>" node into an associative array containing name, attr, inner and close
1940 * All values in the resulting array are PPNodes. Inner and close are optional.
1941 *
1942 * @throws MWException
1943 * @return array
1944 */
1945 public function splitExt() {
1946 return self::splitRawExt( $this->rawChildren );
1947 }
1948
1949 /**
1950 * Like splitExt() but for a raw child array. For internal use only.
1951 * @param array $children
1952 * @return array
1953 */
1954 public static function splitRawExt( array $children ) {
1955 $bits = [];
1956 foreach ( $children as $i => $child ) {
1957 if ( !is_array( $child ) ) {
1958 continue;
1959 }
1960 switch ( $child[self::NAME] ) {
1961 case 'name':
1962 $bits['name'] = new self( $children, $i );
1963 break;
1964 case 'attr':
1965 $bits['attr'] = new self( $children, $i );
1966 break;
1967 case 'inner':
1968 $bits['inner'] = new self( $children, $i );
1969 break;
1970 case 'close':
1971 $bits['close'] = new self( $children, $i );
1972 break;
1973 }
1974 }
1975 if ( !isset( $bits['name'] ) ) {
1976 throw new MWException( 'Invalid ext node passed to ' . __METHOD__ );
1977 }
1978 return $bits;
1979 }
1980
1981 /**
1982 * Split an "<h>" node
1983 *
1984 * @throws MWException
1985 * @return array
1986 */
1987 public function splitHeading() {
1988 if ( $this->name !== 'h' ) {
1989 throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
1990 }
1991 return self::splitRawHeading( $this->rawChildren );
1992 }
1993
1994 /**
1995 * Like splitHeading() but for a raw child array. For internal use only.
1996 * @param array $children
1997 * @return array
1998 */
1999 public static function splitRawHeading( array $children ) {
2000 $bits = [];
2001 foreach ( $children as $i => $child ) {
2002 if ( !is_array( $child ) ) {
2003 continue;
2004 }
2005 if ( $child[self::NAME] === '@i' ) {
2006 $bits['i'] = $child[self::CHILDREN][0];
2007 } elseif ( $child[self::NAME] === '@level' ) {
2008 $bits['level'] = $child[self::CHILDREN][0];
2009 }
2010 }
2011 if ( !isset( $bits['i'] ) ) {
2012 throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
2013 }
2014 return $bits;
2015 }
2016
2017 /**
2018 * Split a "<template>" or "<tplarg>" node
2019 *
2020 * @throws MWException
2021 * @return array
2022 */
2023 public function splitTemplate() {
2024 return self::splitRawTemplate( $this->rawChildren );
2025 }
2026
2027 /**
2028 * Like splitTemplate() but for a raw child array. For internal use only.
2029 * @param array $children
2030 * @return array
2031 */
2032 public static function splitRawTemplate( array $children ) {
2033 $parts = [];
2034 $bits = [ 'lineStart' => '' ];
2035 foreach ( $children as $i => $child ) {
2036 if ( !is_array( $child ) ) {
2037 continue;
2038 }
2039 switch ( $child[self::NAME] ) {
2040 case 'title':
2041 $bits['title'] = new self( $children, $i );
2042 break;
2043 case 'part':
2044 $parts[] = new self( $children, $i );
2045 break;
2046 case '@lineStart':
2047 $bits['lineStart'] = '1';
2048 break;
2049 }
2050 }
2051 if ( !isset( $bits['title'] ) ) {
2052 throw new MWException( 'Invalid node passed to ' . __METHOD__ );
2053 }
2054 $bits['parts'] = new PPNode_Hash_Array( $parts );
2055 return $bits;
2056 }
2057 }
2058
2059 /**
2060 * @ingroup Parser
2061 */
2062 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
2063 class PPNode_Hash_Text implements PPNode {
2064 // @codingStandardsIgnoreEnd
2065
2066 public $value;
2067 private $store, $index;
2068
2069 /**
2070 * Construct an object using the data from $store[$index]. The rest of the
2071 * store array can be accessed via getNextSibling().
2072 *
2073 * @param array $store
2074 * @param int $index
2075 */
2076 public function __construct( array $store, $index ) {
2077 $this->value = $store[$index];
2078 if ( !is_scalar( $this->value ) ) {
2079 throw new MWException( __CLASS__ . ' given object instead of string' );
2080 }
2081 $this->store = $store;
2082 $this->index = $index;
2083 }
2084
2085 public function __toString() {
2086 return htmlspecialchars( $this->value );
2087 }
2088
2089 public function getNextSibling() {
2090 return PPNode_Hash_Tree::factory( $this->store, $this->index + 1 );
2091 }
2092
2093 public function getChildren() {
2094 return false;
2095 }
2096
2097 public function getFirstChild() {
2098 return false;
2099 }
2100
2101 public function getChildrenOfType( $name ) {
2102 return false;
2103 }
2104
2105 public function getLength() {
2106 return false;
2107 }
2108
2109 public function item( $i ) {
2110 return false;
2111 }
2112
2113 public function getName() {
2114 return '#text';
2115 }
2116
2117 public function splitArg() {
2118 throw new MWException( __METHOD__ . ': not supported' );
2119 }
2120
2121 public function splitExt() {
2122 throw new MWException( __METHOD__ . ': not supported' );
2123 }
2124
2125 public function splitHeading() {
2126 throw new MWException( __METHOD__ . ': not supported' );
2127 }
2128 }
2129
2130 /**
2131 * @ingroup Parser
2132 */
2133 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
2134 class PPNode_Hash_Array implements PPNode {
2135 // @codingStandardsIgnoreEnd
2136
2137 public $value;
2138
2139 public function __construct( $value ) {
2140 $this->value = $value;
2141 }
2142
2143 public function __toString() {
2144 return var_export( $this, true );
2145 }
2146
2147 public function getLength() {
2148 return count( $this->value );
2149 }
2150
2151 public function item( $i ) {
2152 return $this->value[$i];
2153 }
2154
2155 public function getName() {
2156 return '#nodelist';
2157 }
2158
2159 public function getNextSibling() {
2160 return false;
2161 }
2162
2163 public function getChildren() {
2164 return false;
2165 }
2166
2167 public function getFirstChild() {
2168 return false;
2169 }
2170
2171 public function getChildrenOfType( $name ) {
2172 return false;
2173 }
2174
2175 public function splitArg() {
2176 throw new MWException( __METHOD__ . ': not supported' );
2177 }
2178
2179 public function splitExt() {
2180 throw new MWException( __METHOD__ . ': not supported' );
2181 }
2182
2183 public function splitHeading() {
2184 throw new MWException( __METHOD__ . ': not supported' );
2185 }
2186 }
2187
2188 /**
2189 * @ingroup Parser
2190 */
2191 // @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
2192 class PPNode_Hash_Attr implements PPNode {
2193 // @codingStandardsIgnoreEnd
2194
2195 public $name, $value;
2196 private $store, $index;
2197
2198 /**
2199 * Construct an object using the data from $store[$index]. The rest of the
2200 * store array can be accessed via getNextSibling().
2201 *
2202 * @param array $store
2203 * @param int $index
2204 */
2205 public function __construct( array $store, $index ) {
2206 $descriptor = $store[$index];
2207 if ( $descriptor[PPNode_Hash_Tree::NAME][0] !== '@' ) {
2208 throw new MWException( __METHOD__.': invalid name in attribute descriptor' );
2209 }
2210 $this->name = substr( $descriptor[PPNode_Hash_Tree::NAME], 1 );
2211 $this->value = $descriptor[PPNode_Hash_Tree::CHILDREN][0];
2212 $this->store = $store;
2213 $this->index = $index;
2214 }
2215
2216 public function __toString() {
2217 return "<@{$this->name}>" . htmlspecialchars( $this->value ) . "</@{$this->name}>";
2218 }
2219
2220 public function getName() {
2221 return $this->name;
2222 }
2223
2224 public function getNextSibling() {
2225 return PPNode_Hash_Tree::factory( $this->store, $this->index + 1 );
2226 }
2227
2228 public function getChildren() {
2229 return false;
2230 }
2231
2232 public function getFirstChild() {
2233 return false;
2234 }
2235
2236 public function getChildrenOfType( $name ) {
2237 return false;
2238 }
2239
2240 public function getLength() {
2241 return false;
2242 }
2243
2244 public function item( $i ) {
2245 return false;
2246 }
2247
2248 public function splitArg() {
2249 throw new MWException( __METHOD__ . ': not supported' );
2250 }
2251
2252 public function splitExt() {
2253 throw new MWException( __METHOD__ . ': not supported' );
2254 }
2255
2256 public function splitHeading() {
2257 throw new MWException( __METHOD__ . ': not supported' );
2258 }
2259 }