3 * A preprocessor optimised for HipHop, using HipHop-specific syntax.
13 class Preprocessor_HipHop implements Preprocessor {
19 const CACHE_VERSION = 1;
21 function __construct( $parser ) {
22 $this->parser = $parser;
26 * @return PPFrame_HipHop
29 return new PPFrame_HipHop( $this );
34 * @return PPCustomFrame_HipHop
36 function newCustomFrame( array $args ) {
37 return new PPCustomFrame_HipHop( $this, $args );
41 * @param $values array
42 * @return PPNode_HipHop_Array
44 function newPartNodeArray( $values ) {
47 foreach ( $values as $k => $val ) {
48 $partNode = new PPNode_HipHop_Tree( 'part' );
49 $nameNode = new PPNode_HipHop_Tree( 'name' );
52 $nameNode->addChild( new PPNode_HipHop_Attr( 'index', $k ) );
53 $partNode->addChild( $nameNode );
55 $nameNode->addChild( new PPNode_HipHop_Text( $k ) );
56 $partNode->addChild( $nameNode );
57 $partNode->addChild( new PPNode_HipHop_Text( '=' ) );
60 $valueNode = new PPNode_HipHop_Tree( 'value' );
61 $valueNode->addChild( new PPNode_HipHop_Text( $val ) );
62 $partNode->addChild( $valueNode );
67 $node = new PPNode_HipHop_Array( $list );
72 * Preprocess some wikitext and return the document tree.
73 * This is the ghost of Parser::replace_variables().
75 * @param $text String: the text to parse
76 * @param $flags Integer: bitwise combination of:
77 * Parser::PTD_FOR_INCLUSION Handle <noinclude>/<includeonly> as if the text is being
78 * included. Default is to assume a direct page view.
80 * The generated DOM tree must depend only on the input text and the flags.
81 * The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of bug 4899.
83 * Any flag added to the $flags parameter here, or any other parameter liable to cause a
84 * change in the DOM tree for a given text, must be passed through the section identifier
85 * in the section edit link and thus back to extractSections().
87 * The output of this function is currently only cached in process memory, but a persistent
88 * cache may be implemented at a later date which takes further advantage of these strict
89 * dependency requirements.
91 * @return PPNode_HipHop_Tree
93 function preprocessToObj( string $text, int $flags = 0 ) {
94 wfProfileIn( __METHOD__ );
97 global $wgMemc, $wgPreprocessorCacheThreshold;
99 $cacheable = ($wgPreprocessorCacheThreshold !== false && strlen( $text ) > $wgPreprocessorCacheThreshold);
101 wfProfileIn( __METHOD__.'-cacheable' );
103 $cacheKey = strval( wfMemcKey( 'preprocess-hash', md5($text), $flags ) );
104 $cacheValue = strval( $wgMemc->get( $cacheKey ) );
105 if ( $cacheValue !== '' ) {
106 $version = substr( $cacheValue, 0, 8 );
107 if ( intval( $version ) == self::CACHE_VERSION ) {
108 $hash = unserialize( substr( $cacheValue, 8 ) );
110 wfDebugLog( "Preprocessor",
111 "Loaded preprocessor hash from memcached (key $cacheKey)" );
112 wfProfileOut( __METHOD__.'-cacheable' );
113 wfProfileOut( __METHOD__ );
117 wfProfileIn( __METHOD__.'-cache-miss' );
132 'names' => array( 2 => 'LITERAL' ),
138 $forInclusion = (bool)( $flags & Parser::PTD_FOR_INCLUSION );
140 $xmlishElements = (array)$this->parser->getStripList();
141 $enableOnlyinclude = false;
142 if ( $forInclusion ) {
143 $ignoredTags = array( 'includeonly', '/includeonly' );
144 $ignoredElements = array( 'noinclude' );
145 $xmlishElements[] = 'noinclude';
146 if ( strpos( $text, '<onlyinclude>' ) !== false && strpos( $text, '</onlyinclude>' ) !== false ) {
147 $enableOnlyinclude = true;
149 } else if ( $this->parser->ot['wiki'] ) {
150 $ignoredTags = array( 'noinclude', '/noinclude', 'onlyinclude', '/onlyinclude', 'includeonly', '/includeonly' );
151 $ignoredElements = array();
153 $ignoredTags = array( 'noinclude', '/noinclude', 'onlyinclude', '/onlyinclude' );
154 $ignoredElements = array( 'includeonly' );
155 $xmlishElements[] = 'includeonly';
157 $xmlishRegex = implode( '|', array_merge( $xmlishElements, $ignoredTags ) );
159 // Use "A" modifier (anchored) instead of "^", because ^ doesn't work with an offset
160 $elementsRegex = "~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
162 $stack = new PPDStack_HipHop;
164 $searchBase = "[{<\n";
165 $revText = strrev( $text ); // For fast reverse searches
167 $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the start
168 $accum = $stack->getAccum(); # Current accumulator
171 'findPipe' => false, # True to take notice of pipe characters
172 'findEquals' => false, # True to find equals signs in arguments
173 'inHeading' => false, # True if $i is inside a possible heading
175 $noMoreGT = false; # True if there are no more greater-than (>) signs right of $i
176 $findOnlyinclude = $enableOnlyinclude; # True to ignore all input up to the next <onlyinclude>
177 $fakeLineStart = true; # Do a line-start run without outputting an LF character
182 if ( $findOnlyinclude ) {
183 // Ignore all input up to the next <onlyinclude>
184 $variantStartPos = strpos( $text, '<onlyinclude>', $i );
185 if ( $variantStartPos === false ) {
186 // Ignored section runs to the end
187 $accum->addNodeWithText( 'ignore', strval( substr( $text, $i ) ) );
190 $startPos1 = intval( $variantStartPos );
191 $tagEndPos = $startPos1 + strlen( '<onlyinclude>' ); // past-the-end
192 $accum->addNodeWithText( 'ignore', strval( substr( $text, $i, $tagEndPos - $i ) ) );
194 $findOnlyinclude = false;
197 if ( $fakeLineStart ) {
198 $found = 'line-start';
201 # Find next opening brace, closing brace or pipe
202 $search = $searchBase;
203 if ( $stack->top === false ) {
204 $currentClosing = '';
206 $currentClosing = strval( $stack->getTop()->close );
207 $search .= $currentClosing;
209 if ( $stackFlags['findPipe'] ) {
212 if ( $stackFlags['findEquals'] ) {
213 // First equals will be for the template
217 # Output literal section, advance input counter
218 $literalLength = intval( strcspn( $text, $search, $i ) );
219 if ( $literalLength > 0 ) {
220 $accum->addLiteral( strval( substr( $text, $i, $literalLength ) ) );
221 $i += $literalLength;
223 if ( $i >= strlen( $text ) ) {
224 if ( $currentClosing === "\n" ) {
225 // Do a past-the-end run to finish off the heading
233 $curChar = $text[$i];
234 if ( $curChar === '|' ) {
236 } elseif ( $curChar === '=' ) {
238 } elseif ( $curChar === '<' ) {
240 } elseif ( $curChar === "\n" ) {
241 if ( $stackFlags['inHeading'] ) {
244 $found = 'line-start';
246 } elseif ( $curChar === $currentClosing ) {
248 } elseif ( isset( $rules[$curChar] ) ) {
250 $rule = $rules[$curChar];
252 # Some versions of PHP have a strcspn which stops on null characters
253 # Ignore and continue
260 if ( $found === 'angle' ) {
262 // Handle </onlyinclude>
263 if ( $enableOnlyinclude
264 && substr( $text, $i, strlen( '</onlyinclude>' ) ) === '</onlyinclude>' )
266 $findOnlyinclude = true;
270 // Determine element name
271 if ( !preg_match( $elementsRegex, $text, $matches, 0, $i + 1 ) ) {
272 // Element name missing or not listed
273 $accum->addLiteral( '<' );
278 if ( isset( $matches[2] ) && $matches[2] === '!--' ) {
279 // To avoid leaving blank lines, when a comment is both preceded
280 // and followed by a newline (ignoring spaces), trim leading and
281 // trailing spaces and one of the newlines.
284 $variantEndPos = strpos( $text, '-->', $i + 4 );
285 if ( $variantEndPos === false ) {
286 // Unclosed comment in input, runs to end
287 $inner = strval( substr( $text, $i ) );
288 $accum->addNodeWithText( 'comment', $inner );
289 $i = strlen( $text );
291 $endPos = intval( $variantEndPos );
292 // Search backwards for leading whitespace
294 $wsStart = $i - intval( strspn( $revText, ' ', strlen( $text ) - $i ) );
298 // Search forwards for trailing whitespace
299 // $wsEnd will be the position of the last space (or the '>' if there's none)
300 $wsEnd = $endPos + 2 + intval( strspn( $text, ' ', $endPos + 3 ) );
301 // Eat the line if possible
302 // TODO: This could theoretically be done if $wsStart == 0, i.e. for comments at
303 // the overall start. That's not how Sanitizer::removeHTMLcomments() did it, but
304 // it's a possible beneficial b/c break.
305 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) === "\n"
306 && substr( $text, $wsEnd + 1, 1 ) === "\n" )
308 $startPos2 = $wsStart;
309 $endPos = $wsEnd + 1;
310 // Remove leading whitespace from the end of the accumulator
311 // Sanity check first though
312 $wsLength = $i - $wsStart;
314 && $accum->lastNode instanceof PPNode_HipHop_Text
315 && substr( $accum->lastNode->value, -$wsLength ) === str_repeat( ' ', $wsLength ) )
317 $accum->lastNode->value = strval( substr( $accum->lastNode->value, 0, -$wsLength ) );
319 // Do a line-start run next time to look for headings after the comment
320 $fakeLineStart = true;
322 // No line to eat, just take the comment itself
328 $part = $stack->getTop()->getCurrentPart();
329 if ( ! (isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 )) {
330 $part->visualEnd = $wsStart;
332 // Else comments abutting, no change in visual end
333 $part->commentEnd = $endPos;
336 $inner = strval( substr( $text, $startPos2, $endPos - $startPos2 + 1 ) );
337 $accum->addNodeWithText( 'comment', $inner );
341 $name = strval( $matches[1] );
342 $lowerName = strtolower( $name );
343 $attrStart = $i + strlen( $name ) + 1;
346 $variantTagEndPos = $noMoreGT ? false : strpos( $text, '>', $attrStart );
347 if ( $variantTagEndPos === false ) {
348 // Infinite backtrack
349 // Disable tag search to prevent worst-case O(N^2) performance
351 $accum->addLiteral( '<' );
355 $tagEndPos = intval( $variantTagEndPos );
357 // Handle ignored tags
358 if ( in_array( $lowerName, $ignoredTags ) ) {
359 $accum->addNodeWithText( 'ignore', strval( substr( $text, $i, $tagEndPos - $i + 1 ) ) );
366 if ( $text[$tagEndPos-1] === '/' ) {
368 $attrEnd = $tagEndPos - 1;
374 $attrEnd = $tagEndPos;
377 if ( preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
378 $text, $matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 ) )
380 $inner = strval( substr( $text, $tagEndPos + 1, $matches[0][1] - $tagEndPos - 1 ) );
381 $i = intval( $matches[0][1] ) + strlen( $matches[0][0] );
382 $close = strval( $matches[0][0] );
385 // No end tag -- let it run out to the end of the text.
386 $inner = strval( substr( $text, $tagEndPos + 1 ) );
387 $i = strlen( $text );
391 // <includeonly> and <noinclude> just become <ignore> tags
392 if ( in_array( $lowerName, $ignoredElements ) ) {
393 $accum->addNodeWithText( 'ignore', strval( substr( $text, $tagStartPos, $i - $tagStartPos ) ) );
397 if ( $attrEnd <= $attrStart ) {
400 // Note that the attr element contains the whitespace between name and attribute,
401 // this is necessary for precise reconstruction during pre-save transform.
402 $attr = strval( substr( $text, $attrStart, $attrEnd - $attrStart ) );
405 $extNode = new PPNode_HipHop_Tree( 'ext' );
406 $extNode->addChild( PPNode_HipHop_Tree::newWithText( 'name', $name ) );
407 $extNode->addChild( PPNode_HipHop_Tree::newWithText( 'attr', $attr ) );
409 $extNode->addChild( PPNode_HipHop_Tree::newWithText( 'inner', $inner ) );
412 $extNode->addChild( PPNode_HipHop_Tree::newWithText( 'close', $close ) );
414 $accum->addNode( $extNode );
417 elseif ( $found === 'line-start' ) {
418 // Is this the start of a heading?
419 // Line break belongs before the heading element in any case
420 if ( $fakeLineStart ) {
421 $fakeLineStart = false;
423 $accum->addLiteral( $curChar );
427 $count = intval( strspn( $text, '=', $i, 6 ) );
428 if ( $count == 1 && $stackFlags['findEquals'] ) {
429 // DWIM: This looks kind of like a name/value separator
430 // Let's let the equals handler have it and break the potential heading
431 // This is heuristic, but AFAICT the methods for completely correct disambiguation are very complex.
432 } elseif ( $count > 0 ) {
436 'parts' => array( new PPDPart_HipHop( str_repeat( '=', $count ) ) ),
439 $stack->push( $partData );
440 $accum = $stack->getAccum();
441 $stackFlags = $stack->getFlags();
444 } elseif ( $found === 'line-end' ) {
445 $piece = $stack->getTop();
446 // A heading must be open, otherwise \n wouldn't have been in the search list
447 assert( $piece->open === "\n" ); // Passing the assert condition directly instead of string, as
448 // HPHP /compiler/ chokes on strings when ASSERT_ACTIVE != 0.
449 $part = $piece->getCurrentPart();
450 // Search back through the input to see if it has a proper close
451 // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient
452 $wsLength = intval( strspn( $revText, " \t", strlen( $text ) - $i ) );
453 $searchStart = $i - $wsLength;
454 if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
455 // Comment found at line end
456 // Search for equals signs before the comment
457 $searchStart = intval( $part->visualEnd );
458 $searchStart -= intval( strspn( $revText, " \t", strlen( $text ) - $searchStart ) );
460 $count = intval( $piece->count );
461 $equalsLength = intval( strspn( $revText, '=', strlen( $text ) - $searchStart ) );
463 $resultAccum = $accum;
464 if ( $equalsLength > 0 ) {
465 if ( $searchStart - $equalsLength == $piece->startPos ) {
466 // This is just a single string of equals signs on its own line
467 // Replicate the doHeadings behaviour /={count}(.+)={count}/
468 // First find out how many equals signs there really are (don't stop at 6)
469 $count = $equalsLength;
473 $count = intval( ( $count - 1 ) / 2 );
479 if ( $count > $equalsLength ) {
480 $count = $equalsLength;
484 // Normal match, output <h>
485 $tree = new PPNode_HipHop_Tree( 'possible-h' );
486 $tree->addChild( new PPNode_HipHop_Attr( 'level', $count ) );
487 $tree->addChild( new PPNode_HipHop_Attr( 'i', $headingIndex++ ) );
488 $tree->lastChild->nextSibling = $accum->firstNode;
489 $tree->lastChild = $accum->lastNode;
492 // Single equals sign on its own line, count=0
493 // Output $resultAccum
496 // No match, no <h>, just pass down the inner text
497 // Output $resultAccum
501 $accum = $stack->getAccum();
502 $stackFlags = $stack->getFlags();
504 // Append the result to the enclosing accumulator
506 $accum->addNode( $tree );
508 $accum->addAccum( $resultAccum );
510 // Note that we do NOT increment the input pointer.
511 // This is because the closing linebreak could be the opening linebreak of
512 // another heading. Infinite loops are avoided because the next iteration MUST
513 // hit the heading open case above, which unconditionally increments the
515 } elseif ( $found === 'open' ) {
516 # count opening brace characters
517 $count = intval( strspn( $text, $curChar, $i ) );
519 # we need to add to stack only if opening brace count is enough for one of the rules
520 if ( $count >= $rule['min'] ) {
521 # Add it to the stack
524 'close' => $rule['end'],
526 'lineStart' => ($i == 0 || $text[$i-1] === "\n"),
529 $stack->push( $partData );
530 $accum = $stack->getAccum();
531 $stackFlags = $stack->getFlags();
533 # Add literal brace(s)
534 $accum->addLiteral( str_repeat( $curChar, $count ) );
537 } elseif ( $found === 'close' ) {
538 $piece = $stack->getTop();
539 # lets check if there are enough characters for closing brace
540 $maxCount = intval( $piece->count );
541 $count = intval( strspn( $text, $curChar, $i, $maxCount ) );
543 # check for maximum matching characters (if there are 5 closing
544 # characters, we will probably need only 3 - depending on the rules)
545 $rule = $rules[$piece->open];
546 if ( $count > $rule['max'] ) {
547 # The specified maximum exists in the callback array, unless the caller
549 $matchingCount = intval( $rule['max'] );
551 # Count is less than the maximum
552 # Skip any gaps in the callback array to find the true largest match
553 # Need to use array_key_exists not isset because the callback can be null
554 $matchingCount = $count;
555 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule['names'] ) ) {
560 if ($matchingCount <= 0) {
561 # No matching element found in callback array
562 # Output a literal closing brace and continue
563 $accum->addLiteral( str_repeat( $curChar, $count ) );
567 $name = strval( $rule['names'][$matchingCount] );
569 if ( $name === 'LITERAL' ) {
570 // No element, just literal text
571 $resultAccum = $piece->breakSyntax( $matchingCount );
572 $resultAccum->addLiteral( str_repeat( $rule['end'], $matchingCount ) );
575 # Note: $parts is already XML, does not need to be encoded further
577 $parts = $piece->parts;
578 $titleAccum = PPDAccum_HipHop::cast( $parts[0]->out );
581 $tree = new PPNode_HipHop_Tree( $name );
583 # The invocation is at the start of the line if lineStart is set in
584 # the stack, and all opening brackets are used up.
585 if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
586 $tree->addChild( new PPNode_HipHop_Attr( 'lineStart', 1 ) );
588 $titleNode = new PPNode_HipHop_Tree( 'title' );
589 $titleNode->firstChild = $titleAccum->firstNode;
590 $titleNode->lastChild = $titleAccum->lastNode;
591 $tree->addChild( $titleNode );
593 foreach ( $parts as $variantPart ) {
594 $part = PPDPart_HipHop::cast( $variantPart );
595 if ( isset( $part->eqpos ) ) {
598 for ( $node = $part->out->firstNode; $node; $node = $node->nextSibling ) {
599 if ( $node === $part->eqpos ) {
605 throw new MWException( __METHOD__. ': eqpos not found' );
607 if ( $node->name !== 'equals' ) {
608 throw new MWException( __METHOD__ .': eqpos is not equals' );
612 // Construct name node
613 $nameNode = new PPNode_HipHop_Tree( 'name' );
614 if ( $lastNode !== false ) {
615 $lastNode->nextSibling = false;
616 $nameNode->firstChild = $part->out->firstNode;
617 $nameNode->lastChild = $lastNode;
620 // Construct value node
621 $valueNode = new PPNode_HipHop_Tree( 'value' );
622 if ( $equalsNode->nextSibling !== false ) {
623 $valueNode->firstChild = $equalsNode->nextSibling;
624 $valueNode->lastChild = $part->out->lastNode;
626 $partNode = new PPNode_HipHop_Tree( 'part' );
627 $partNode->addChild( $nameNode );
628 $partNode->addChild( $equalsNode->firstChild );
629 $partNode->addChild( $valueNode );
630 $tree->addChild( $partNode );
632 $partNode = new PPNode_HipHop_Tree( 'part' );
633 $nameNode = new PPNode_HipHop_Tree( 'name' );
634 $nameNode->addChild( new PPNode_HipHop_Attr( 'index', $argIndex++ ) );
635 $valueNode = new PPNode_HipHop_Tree( 'value' );
636 $valueNode->firstChild = $part->out->firstNode;
637 $valueNode->lastChild = $part->out->lastNode;
638 $partNode->addChild( $nameNode );
639 $partNode->addChild( $valueNode );
640 $tree->addChild( $partNode );
645 # Advance input pointer
646 $i += $matchingCount;
650 $accum = $stack->getAccum();
652 # Re-add the old stack element if it still has unmatched opening characters remaining
653 if ($matchingCount < $piece->count) {
654 $piece->parts = array( new PPDPart_HipHop );
655 $piece->count -= $matchingCount;
656 # do we still qualify for any callback with remaining count?
657 $names = $rules[$piece->open]['names'];
659 $enclosingAccum = $accum;
660 while ( $piece->count ) {
661 if ( array_key_exists( $piece->count, $names ) ) {
662 $stack->push( $piece );
663 $accum = $stack->getAccum();
669 $enclosingAccum->addLiteral( str_repeat( $piece->open, $skippedBraces ) );
672 $stackFlags = $stack->getFlags();
674 # Add XML element to the enclosing accumulator
676 $accum->addNode( $tree );
678 $accum->addAccum( $resultAccum );
680 } elseif ( $found === 'pipe' ) {
681 $stackFlags['findEquals'] = true; // shortcut for getFlags()
683 $accum = $stack->getAccum();
685 } elseif ( $found === 'equals' ) {
686 $stackFlags['findEquals'] = false; // shortcut for getFlags()
687 $accum->addNodeWithText( 'equals', '=' );
688 $stack->getCurrentPart()->eqpos = $accum->lastNode;
693 # Output any remaining unclosed brackets
694 foreach ( $stack->stack as $variantPiece ) {
695 $piece = PPDStackElement_HipHop::cast( $variantPiece );
696 $stack->rootAccum->addAccum( $piece->breakSyntax() );
699 # Enable top-level headings
700 for ( $node = $stack->rootAccum->firstNode; $node; $node = $node->nextSibling ) {
701 if ( isset( $node->name ) && $node->name === 'possible-h' ) {
706 $rootNode = new PPNode_HipHop_Tree( 'root' );
707 $rootNode->firstChild = $stack->rootAccum->firstNode;
708 $rootNode->lastChild = $stack->rootAccum->lastNode;
712 $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . serialize( $rootNode );
713 $wgMemc->set( $cacheKey, $cacheValue, 86400 );
714 wfProfileOut( __METHOD__.'-cache-miss' );
715 wfProfileOut( __METHOD__.'-cacheable' );
716 wfDebugLog( "Preprocessor", "Saved preprocessor Hash to memcached (key $cacheKey)" );
719 wfProfileOut( __METHOD__ );
727 * Stack class to help Preprocessor::preprocessToObj()
730 class PPDStack_HipHop {
731 var $stack, $rootAccum;
739 static $false = false;
741 function __construct() {
742 $this->stack = array();
744 $this->rootAccum = new PPDAccum_HipHop;
745 $this->accum = $this->rootAccum;
752 return count( $this->stack );
755 function getAccum() {
756 return PPDAccum_HipHop::cast( $this->accum );
759 function getCurrentPart() {
760 return $this->getTop()->getCurrentPart();
764 return PPDStackElement_HipHop::cast( $this->top );
767 function push( $data ) {
768 if ( $data instanceof PPDStackElement_HipHop ) {
769 $this->stack[] = $data;
771 $this->stack[] = new PPDStackElement_HipHop( $data );
773 $this->top = $this->stack[ count( $this->stack ) - 1 ];
774 $this->accum = $this->top->getAccum();
778 if ( !count( $this->stack ) ) {
779 throw new MWException( __METHOD__.': no elements remaining' );
781 $temp = array_pop( $this->stack );
783 if ( count( $this->stack ) ) {
784 $this->top = $this->stack[ count( $this->stack ) - 1 ];
785 $this->accum = $this->top->getAccum();
787 $this->top = self::$false;
788 $this->accum = $this->rootAccum;
793 function addPart( $s = '' ) {
794 $this->top->addPart( $s );
795 $this->accum = $this->top->getAccum();
801 function getFlags() {
802 if ( !count( $this->stack ) ) {
804 'findEquals' => false,
806 'inHeading' => false,
809 return $this->top->getFlags();
817 class PPDStackElement_HipHop {
818 var $open, // Opening character (\n for heading)
819 $close, // Matching closing character
820 $count, // Number of opening characters found (number of "=" for heading)
821 $parts, // Array of PPDPart objects describing pipe-separated parts.
822 $lineStart; // True if the open char appeared at the start of the input line. Not set for headings.
824 static function cast( PPDStackElement_HipHop $obj ) {
828 function __construct( $data = array() ) {
829 $this->parts = array( new PPDPart_HipHop );
831 foreach ( $data as $name => $value ) {
832 $this->$name = $value;
836 function getAccum() {
837 return PPDAccum_HipHop::cast( $this->parts[count($this->parts) - 1]->out );
840 function addPart( $s = '' ) {
841 $this->parts[] = new PPDPart_HipHop( $s );
844 function getCurrentPart() {
845 return PPDPart_HipHop::cast( $this->parts[count($this->parts) - 1] );
851 function getFlags() {
852 $partCount = count( $this->parts );
853 $findPipe = $this->open !== "\n" && $this->open !== '[';
855 'findPipe' => $findPipe,
856 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
857 'inHeading' => $this->open === "\n",
862 * Get the accumulator that would result if the close is not found.
864 * @return PPDAccum_HipHop
866 function breakSyntax( $openingCount = false ) {
867 if ( $this->open === "\n" ) {
868 $accum = PPDAccum_HipHop::cast( $this->parts[0]->out );
870 if ( $openingCount === false ) {
871 $openingCount = $this->count;
873 $accum = new PPDAccum_HipHop;
874 $accum->addLiteral( str_repeat( $this->open, $openingCount ) );
876 foreach ( $this->parts as $part ) {
880 $accum->addLiteral( '|' );
882 $accum->addAccum( $part->out );
892 class PPDPart_HipHop {
893 var $out; // Output accumulator object
895 // Optional member variables:
896 // eqpos Position of equals sign in output accumulator
897 // commentEnd Past-the-end input pointer for the last comment encountered
898 // visualEnd Past-the-end input pointer for the end of the accumulator minus comments
900 function __construct( $out = '' ) {
901 $this->out = new PPDAccum_HipHop;
903 $this->out->addLiteral( $out );
907 static function cast( PPDPart_HipHop $obj ) {
915 class PPDAccum_HipHop {
916 var $firstNode, $lastNode;
918 function __construct() {
919 $this->firstNode = $this->lastNode = false;
922 static function cast( PPDAccum_HipHop $obj ) {
927 * Append a string literal
929 function addLiteral( string $s ) {
930 if ( $this->lastNode === false ) {
931 $this->firstNode = $this->lastNode = new PPNode_HipHop_Text( $s );
932 } elseif ( $this->lastNode instanceof PPNode_HipHop_Text ) {
933 $this->lastNode->value .= $s;
935 $this->lastNode->nextSibling = new PPNode_HipHop_Text( $s );
936 $this->lastNode = $this->lastNode->nextSibling;
943 function addNode( PPNode $node ) {
944 if ( $this->lastNode === false ) {
945 $this->firstNode = $this->lastNode = $node;
947 $this->lastNode->nextSibling = $node;
948 $this->lastNode = $node;
953 * Append a tree node with text contents
955 function addNodeWithText( string $name, string $value ) {
956 $node = PPNode_HipHop_Tree::newWithText( $name, $value );
957 $this->addNode( $node );
961 * Append a PPDAccum_HipHop
962 * Takes over ownership of the nodes in the source argument. These nodes may
963 * subsequently be modified, especially nextSibling.
965 function addAccum( PPDAccum_HipHop $accum ) {
966 if ( $accum->lastNode === false ) {
968 } elseif ( $this->lastNode === false ) {
969 $this->firstNode = $accum->firstNode;
970 $this->lastNode = $accum->lastNode;
972 $this->lastNode->nextSibling = $accum->firstNode;
973 $this->lastNode = $accum->lastNode;
979 * An expansion frame, used as a context to expand the result of preprocessToObj()
982 class PPFrame_HipHop implements PPFrame {
1001 * Hashtable listing templates which are disallowed for expansion in this frame,
1002 * having been encountered previously in parent frames.
1007 * Recursion depth of this frame, top = 0
1008 * Note that this is NOT the same as expansion depth in expand()
1013 * Construct a new preprocessor frame.
1014 * @param $preprocessor Preprocessor: the parent preprocessor
1016 function __construct( $preprocessor ) {
1017 $this->preprocessor = $preprocessor;
1018 $this->parser = $preprocessor->parser;
1019 $this->title = $this->parser->mTitle;
1020 $this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
1021 $this->loopCheckHash = array();
1026 * Create a new child frame
1027 * $args is optionally a multi-root PPNode or array containing the template arguments
1029 * @param $args PPNode_HipHop_Array|array
1030 * @param $title Title|false
1032 * @return PPTemplateFrame_HipHop
1034 function newChild( $args = false, $title = false ) {
1035 $namedArgs = array();
1036 $numberedArgs = array();
1037 if ( $title === false ) {
1038 $title = $this->title;
1040 if ( $args !== false ) {
1041 if ( $args instanceof PPNode_HipHop_Array ) {
1042 $args = $args->value;
1043 } elseif ( !is_array( $args ) ) {
1044 throw new MWException( __METHOD__ . ': $args must be array or PPNode_HipHop_Array' );
1046 foreach ( $args as $arg ) {
1047 $bits = $arg->splitArg();
1048 if ( $bits['index'] !== '' ) {
1049 // Numbered parameter
1050 $numberedArgs[$bits['index']] = $bits['value'];
1051 unset( $namedArgs[$bits['index']] );
1054 $name = trim( $this->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
1055 $namedArgs[$name] = $bits['value'];
1056 unset( $numberedArgs[$name] );
1060 return new PPTemplateFrame_HipHop( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
1064 * @throws MWException
1069 function expand( $root, $flags = 0 ) {
1070 static $expansionDepth = 0;
1071 if ( is_string( $root ) ) {
1075 if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
1076 return '<span class="error">Node-count limit exceeded</span>';
1078 if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
1079 return '<span class="error">Expansion depth limit exceeded</span>';
1083 $outStack = array( '', '' );
1084 $iteratorStack = array( false, $root );
1085 $indexStack = array( 0, 0 );
1087 while ( count( $iteratorStack ) > 1 ) {
1088 $level = count( $outStack ) - 1;
1089 $iteratorNode =& $iteratorStack[ $level ];
1090 $out =& $outStack[$level];
1091 $index =& $indexStack[$level];
1093 if ( is_array( $iteratorNode ) ) {
1094 if ( $index >= count( $iteratorNode ) ) {
1095 // All done with this iterator
1096 $iteratorStack[$level] = false;
1097 $contextNode = false;
1099 $contextNode = $iteratorNode[$index];
1102 } elseif ( $iteratorNode instanceof PPNode_HipHop_Array ) {
1103 if ( $index >= $iteratorNode->getLength() ) {
1104 // All done with this iterator
1105 $iteratorStack[$level] = false;
1106 $contextNode = false;
1108 $contextNode = $iteratorNode->item( $index );
1112 // Copy to $contextNode and then delete from iterator stack,
1113 // because this is not an iterator but we do have to execute it once
1114 $contextNode = $iteratorStack[$level];
1115 $iteratorStack[$level] = false;
1118 $newIterator = false;
1120 if ( $contextNode === false ) {
1122 } elseif ( is_string( $contextNode ) ) {
1123 $out .= $contextNode;
1124 } elseif ( is_array( $contextNode ) || $contextNode instanceof PPNode_HipHop_Array ) {
1125 $newIterator = $contextNode;
1126 } elseif ( $contextNode instanceof PPNode_HipHop_Attr ) {
1128 } elseif ( $contextNode instanceof PPNode_HipHop_Text ) {
1129 $out .= $contextNode->value;
1130 } elseif ( $contextNode instanceof PPNode_HipHop_Tree ) {
1131 if ( $contextNode->name === 'template' ) {
1132 # Double-brace expansion
1133 $bits = $contextNode->splitTemplate();
1134 if ( $flags & PPFrame::NO_TEMPLATES ) {
1135 $newIterator = $this->virtualBracketedImplode( '{{', '|', '}}', $bits['title'], $bits['parts'] );
1137 $ret = $this->parser->braceSubstitution( $bits, $this );
1138 if ( isset( $ret['object'] ) ) {
1139 $newIterator = $ret['object'];
1141 $out .= $ret['text'];
1144 } elseif ( $contextNode->name === 'tplarg' ) {
1145 # Triple-brace expansion
1146 $bits = $contextNode->splitTemplate();
1147 if ( $flags & PPFrame::NO_ARGS ) {
1148 $newIterator = $this->virtualBracketedImplode( '{{{', '|', '}}}', $bits['title'], $bits['parts'] );
1150 $ret = $this->parser->argSubstitution( $bits, $this );
1151 if ( isset( $ret['object'] ) ) {
1152 $newIterator = $ret['object'];
1154 $out .= $ret['text'];
1157 } elseif ( $contextNode->name === 'comment' ) {
1158 # HTML-style comment
1159 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1160 if ( $this->parser->ot['html']
1161 || ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() )
1162 || ( $flags & PPFrame::STRIP_COMMENTS ) )
1166 # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
1167 # Not in RECOVER_COMMENTS mode (extractSections) though
1168 elseif ( $this->parser->ot['wiki'] && ! ( $flags & PPFrame::RECOVER_COMMENTS ) ) {
1169 $out .= $this->parser->insertStripItem( $contextNode->firstChild->value );
1171 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1173 $out .= $contextNode->firstChild->value;
1175 } elseif ( $contextNode->name === 'ignore' ) {
1176 # Output suppression used by <includeonly> etc.
1177 # OT_WIKI will only respect <ignore> in substed templates.
1178 # The other output types respect it unless NO_IGNORE is set.
1179 # extractSections() sets NO_IGNORE and so never respects it.
1180 if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] ) || ( $flags & PPFrame::NO_IGNORE ) ) {
1181 $out .= $contextNode->firstChild->value;
1185 } elseif ( $contextNode->name === 'ext' ) {
1187 $bits = $contextNode->splitExt() + array( 'attr' => null, 'inner' => null, 'close' => null );
1188 $out .= $this->parser->extensionSubstitution( $bits, $this );
1189 } elseif ( $contextNode->name === 'h' ) {
1191 if ( $this->parser->ot['html'] ) {
1192 # Expand immediately and insert heading index marker
1194 for ( $node = $contextNode->firstChild; $node; $node = $node->nextSibling ) {
1195 $s .= $this->expand( $node, $flags );
1198 $bits = $contextNode->splitHeading();
1199 $titleText = $this->title->getPrefixedDBkey();
1200 $this->parser->mHeadings[] = array( $titleText, $bits['i'] );
1201 $serial = count( $this->parser->mHeadings ) - 1;
1202 $marker = "{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX;
1203 $s = substr( $s, 0, $bits['level'] ) . $marker . substr( $s, $bits['level'] );
1204 $this->parser->mStripState->addGeneral( $marker, '' );
1207 # Expand in virtual stack
1208 $newIterator = $contextNode->getChildren();
1211 # Generic recursive expansion
1212 $newIterator = $contextNode->getChildren();
1215 throw new MWException( __METHOD__.': Invalid parameter type' );
1218 if ( $newIterator !== false ) {
1220 $iteratorStack[] = $newIterator;
1222 } elseif ( $iteratorStack[$level] === false ) {
1223 // Return accumulated value to parent
1224 // With tail recursion
1225 while ( $iteratorStack[$level] === false && $level > 0 ) {
1226 $outStack[$level - 1] .= $out;
1227 array_pop( $outStack );
1228 array_pop( $iteratorStack );
1229 array_pop( $indexStack );
1235 return $outStack[0];
1243 function implodeWithFlags( $sep, $flags /*, ... */ ) {
1244 $args = array_slice( func_get_args(), 2 );
1248 foreach ( $args as $root ) {
1249 if ( $root instanceof PPNode_HipHop_Array ) {
1250 $root = $root->value;
1252 if ( !is_array( $root ) ) {
1253 $root = array( $root );
1255 foreach ( $root as $node ) {
1261 $s .= $this->expand( $node, $flags );
1268 * Implode with no flags specified
1269 * This previously called implodeWithFlags but has now been inlined to reduce stack depth
1272 function implode( $sep /*, ... */ ) {
1273 $args = array_slice( func_get_args(), 1 );
1277 foreach ( $args as $root ) {
1278 if ( $root instanceof PPNode_HipHop_Array ) {
1279 $root = $root->value;
1281 if ( !is_array( $root ) ) {
1282 $root = array( $root );
1284 foreach ( $root as $node ) {
1290 $s .= $this->expand( $node );
1297 * Makes an object that, when expand()ed, will be the same as one obtained
1300 * @return PPNode_HipHop_Array
1302 function virtualImplode( $sep /*, ... */ ) {
1303 $args = array_slice( func_get_args(), 1 );
1307 foreach ( $args as $root ) {
1308 if ( $root instanceof PPNode_HipHop_Array ) {
1309 $root = $root->value;
1311 if ( !is_array( $root ) ) {
1312 $root = array( $root );
1314 foreach ( $root as $node ) {
1323 return new PPNode_HipHop_Array( $out );
1327 * Virtual implode with brackets
1329 * @return PPNode_HipHop_Array
1331 function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
1332 $args = array_slice( func_get_args(), 3 );
1333 $out = array( $start );
1336 foreach ( $args as $root ) {
1337 if ( $root instanceof PPNode_HipHop_Array ) {
1338 $root = $root->value;
1340 if ( !is_array( $root ) ) {
1341 $root = array( $root );
1343 foreach ( $root as $node ) {
1353 return new PPNode_HipHop_Array( $out );
1356 function __toString() {
1361 * @param $level bool
1362 * @return array|bool|String
1364 function getPDBK( $level = false ) {
1365 if ( $level === false ) {
1366 return $this->title->getPrefixedDBkey();
1368 return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] : false;
1375 function getArguments() {
1382 function getNumberedArguments() {
1389 function getNamedArguments() {
1394 * Returns true if there are no arguments in this frame
1398 function isEmpty() {
1406 function getArgument( $name ) {
1411 * Returns true if the infinite loop check is OK, false if a loop is detected
1413 * @param $title Title
1417 function loopCheck( $title ) {
1418 return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
1422 * Return true if the frame is a template frame
1426 function isTemplate() {
1431 * Get a title of frame
1435 function getTitle() {
1436 return $this->title;
1441 * Expansion frame with template arguments
1444 class PPTemplateFrame_HipHop extends PPFrame_HipHop {
1445 var $numberedArgs, $namedArgs, $parent;
1446 var $numberedExpansionCache, $namedExpansionCache;
1449 * @param $preprocessor
1451 * @param $numberedArgs array
1452 * @param $namedArgs array
1453 * @param $title Title
1455 function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
1456 parent::__construct( $preprocessor );
1458 $this->parent = $parent;
1459 $this->numberedArgs = $numberedArgs;
1460 $this->namedArgs = $namedArgs;
1461 $this->title = $title;
1462 $pdbk = $title ? $title->getPrefixedDBkey() : false;
1463 $this->titleCache = $parent->titleCache;
1464 $this->titleCache[] = $pdbk;
1465 $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
1466 if ( $pdbk !== false ) {
1467 $this->loopCheckHash[$pdbk] = true;
1469 $this->depth = $parent->depth + 1;
1470 $this->numberedExpansionCache = $this->namedExpansionCache = array();
1473 function __toString() {
1476 $args = $this->numberedArgs + $this->namedArgs;
1477 foreach ( $args as $name => $value ) {
1483 $s .= "\"$name\":\"" .
1484 str_replace( '"', '\\"', $value->__toString() ) . '"';
1490 * Returns true if there are no arguments in this frame
1494 function isEmpty() {
1495 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
1501 function getArguments() {
1502 $arguments = array();
1503 foreach ( array_merge(
1504 array_keys($this->numberedArgs),
1505 array_keys($this->namedArgs)) as $key ) {
1506 $arguments[$key] = $this->getArgument($key);
1514 function getNumberedArguments() {
1515 $arguments = array();
1516 foreach ( array_keys($this->numberedArgs) as $key ) {
1517 $arguments[$key] = $this->getArgument($key);
1525 function getNamedArguments() {
1526 $arguments = array();
1527 foreach ( array_keys($this->namedArgs) as $key ) {
1528 $arguments[$key] = $this->getArgument($key);
1535 * @return array|bool
1537 function getNumberedArgument( $index ) {
1538 if ( !isset( $this->numberedArgs[$index] ) ) {
1541 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1542 # No trimming for unnamed arguments
1543 $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index], PPFrame::STRIP_COMMENTS );
1545 return $this->numberedExpansionCache[$index];
1552 function getNamedArgument( $name ) {
1553 if ( !isset( $this->namedArgs[$name] ) ) {
1556 if ( !isset( $this->namedExpansionCache[$name] ) ) {
1557 # Trim named arguments post-expand, for backwards compatibility
1558 $this->namedExpansionCache[$name] = trim(
1559 $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
1561 return $this->namedExpansionCache[$name];
1566 * @return array|bool
1568 function getArgument( $name ) {
1569 $text = $this->getNumberedArgument( $name );
1570 if ( $text === false ) {
1571 $text = $this->getNamedArgument( $name );
1577 * Return true if the frame is a template frame
1581 function isTemplate() {
1587 * Expansion frame with custom arguments
1590 class PPCustomFrame_HipHop extends PPFrame_HipHop {
1593 function __construct( $preprocessor, $args ) {
1594 parent::__construct( $preprocessor );
1595 $this->args = $args;
1598 function __toString() {
1601 foreach ( $this->args as $name => $value ) {
1607 $s .= "\"$name\":\"" .
1608 str_replace( '"', '\\"', $value->__toString() ) . '"';
1617 function isEmpty() {
1618 return !count( $this->args );
1625 function getArgument( $index ) {
1626 if ( !isset( $this->args[$index] ) ) {
1629 return $this->args[$index];
1636 class PPNode_HipHop_Tree implements PPNode {
1637 var $name, $firstChild, $lastChild, $nextSibling;
1639 function __construct( $name ) {
1640 $this->name = $name;
1641 $this->firstChild = $this->lastChild = $this->nextSibling = false;
1644 function __toString() {
1647 for ( $node = $this->firstChild; $node; $node = $node->nextSibling ) {
1648 if ( $node instanceof PPNode_HipHop_Attr ) {
1649 $attribs .= ' ' . $node->name . '="' . htmlspecialchars( $node->value ) . '"';
1651 $inner .= $node->__toString();
1654 if ( $inner === '' ) {
1655 return "<{$this->name}$attribs/>";
1657 return "<{$this->name}$attribs>$inner</{$this->name}>";
1664 * @return PPNode_HipHop_Tree
1666 static function newWithText( $name, $text ) {
1667 $obj = new self( $name );
1668 $obj->addChild( new PPNode_HipHop_Text( $text ) );
1672 function addChild( $node ) {
1673 if ( $this->lastChild === false ) {
1674 $this->firstChild = $this->lastChild = $node;
1676 $this->lastChild->nextSibling = $node;
1677 $this->lastChild = $node;
1682 * @return PPNode_HipHop_Array
1684 function getChildren() {
1685 $children = array();
1686 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1687 $children[] = $child;
1689 return new PPNode_HipHop_Array( $children );
1692 function getFirstChild() {
1693 return $this->firstChild;
1696 function getNextSibling() {
1697 return $this->nextSibling;
1700 function getChildrenOfType( $name ) {
1701 $children = array();
1702 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1703 if ( isset( $child->name ) && $child->name === $name ) {
1704 $children[] = $name;
1713 function getLength() {
1721 function item( $i ) {
1728 function getName() {
1733 * Split a <part> node into an associative array containing:
1735 * index String index
1736 * value PPNode value
1740 function splitArg() {
1742 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1743 if ( !isset( $child->name ) ) {
1746 if ( $child->name === 'name' ) {
1747 $bits['name'] = $child;
1748 if ( $child->firstChild instanceof PPNode_HipHop_Attr
1749 && $child->firstChild->name === 'index' )
1751 $bits['index'] = $child->firstChild->value;
1753 } elseif ( $child->name === 'value' ) {
1754 $bits['value'] = $child;
1758 if ( !isset( $bits['name'] ) ) {
1759 throw new MWException( 'Invalid brace node passed to ' . __METHOD__ );
1761 if ( !isset( $bits['index'] ) ) {
1762 $bits['index'] = '';
1768 * Split an <ext> node into an associative array containing name, attr, inner and close
1769 * All values in the resulting array are PPNodes. Inner and close are optional.
1773 function splitExt() {
1775 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1776 if ( !isset( $child->name ) ) {
1779 if ( $child->name === 'name' ) {
1780 $bits['name'] = $child;
1781 } elseif ( $child->name === 'attr' ) {
1782 $bits['attr'] = $child;
1783 } elseif ( $child->name === 'inner' ) {
1784 $bits['inner'] = $child;
1785 } elseif ( $child->name === 'close' ) {
1786 $bits['close'] = $child;
1789 if ( !isset( $bits['name'] ) ) {
1790 throw new MWException( 'Invalid ext node passed to ' . __METHOD__ );
1800 function splitHeading() {
1801 if ( $this->name !== 'h' ) {
1802 throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
1805 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1806 if ( !isset( $child->name ) ) {
1809 if ( $child->name === 'i' ) {
1810 $bits['i'] = $child->value;
1811 } elseif ( $child->name === 'level' ) {
1812 $bits['level'] = $child->value;
1815 if ( !isset( $bits['i'] ) ) {
1816 throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
1822 * Split a <template> or <tplarg> node
1826 function splitTemplate() {
1828 $bits = array( 'lineStart' => '' );
1829 for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) {
1830 if ( !isset( $child->name ) ) {
1833 if ( $child->name === 'title' ) {
1834 $bits['title'] = $child;
1836 if ( $child->name === 'part' ) {
1839 if ( $child->name === 'lineStart' ) {
1840 $bits['lineStart'] = '1';
1843 if ( !isset( $bits['title'] ) ) {
1844 throw new MWException( 'Invalid node passed to ' . __METHOD__ );
1846 $bits['parts'] = new PPNode_HipHop_Array( $parts );
1854 class PPNode_HipHop_Text implements PPNode {
1855 var $value, $nextSibling;
1857 function __construct( $value ) {
1858 if ( is_object( $value ) ) {
1859 throw new MWException( __CLASS__ . ' given object instead of string' );
1861 $this->value = $value;
1864 function __toString() {
1865 return htmlspecialchars( $this->value );
1868 function getNextSibling() {
1869 return $this->nextSibling;
1872 function getChildren() { return false; }
1873 function getFirstChild() { return false; }
1874 function getChildrenOfType( $name ) { return false; }
1875 function getLength() { return false; }
1876 function item( $i ) { return false; }
1877 function getName() { return '#text'; }
1878 function splitArg() { throw new MWException( __METHOD__ . ': not supported' ); }
1879 function splitExt() { throw new MWException( __METHOD__ . ': not supported' ); }
1880 function splitHeading() { throw new MWException( __METHOD__ . ': not supported' ); }
1886 class PPNode_HipHop_Array implements PPNode {
1887 var $value, $nextSibling;
1889 function __construct( $value ) {
1890 $this->value = $value;
1893 function __toString() {
1894 return var_export( $this, true );
1897 function getLength() {
1898 return count( $this->value );
1901 function item( $i ) {
1902 return $this->value[$i];
1905 function getName() { return '#nodelist'; }
1907 function getNextSibling() {
1908 return $this->nextSibling;
1911 function getChildren() { return false; }
1912 function getFirstChild() { return false; }
1913 function getChildrenOfType( $name ) { return false; }
1914 function splitArg() { throw new MWException( __METHOD__ . ': not supported' ); }
1915 function splitExt() { throw new MWException( __METHOD__ . ': not supported' ); }
1916 function splitHeading() { throw new MWException( __METHOD__ . ': not supported' ); }
1922 class PPNode_HipHop_Attr implements PPNode {
1923 var $name, $value, $nextSibling;
1925 function __construct( $name, $value ) {
1926 $this->name = $name;
1927 $this->value = $value;
1930 function __toString() {
1931 return "<@{$this->name}>" . htmlspecialchars( $this->value ) . "</@{$this->name}>";
1934 function getName() {
1938 function getNextSibling() {
1939 return $this->nextSibling;
1942 function getChildren() { return false; }
1943 function getFirstChild() { return false; }
1944 function getChildrenOfType( $name ) { return false; }
1945 function getLength() { return false; }
1946 function item( $i ) { return false; }
1947 function splitArg() { throw new MWException( __METHOD__ . ': not supported' ); }
1948 function splitExt() { throw new MWException( __METHOD__ . ': not supported' ); }
1949 function splitHeading() { throw new MWException( __METHOD__ . ': not supported' ); }