Index: trunk/phase3/includes/parser/Preprocessor_DOM.php |
— | — | @@ -10,8 +10,14 @@ |
11 | 11 | * @ingroup Parser |
12 | 12 | */ |
13 | 13 | class Preprocessor_DOM implements Preprocessor { |
14 | | - var $parser, $memoryLimit; |
15 | 14 | |
| 15 | + /** |
| 16 | + * @var Parser |
| 17 | + */ |
| 18 | + var $parser; |
| 19 | + |
| 20 | + var $memoryLimit; |
| 21 | + |
16 | 22 | const CACHE_VERSION = 1; |
17 | 23 | |
18 | 24 | function __construct( $parser ) { |
— | — | @@ -42,6 +48,10 @@ |
43 | 49 | return new PPCustomFrame_DOM( $this, $args ); |
44 | 50 | } |
45 | 51 | |
| 52 | + /** |
| 53 | + * @param $values |
| 54 | + * @return PPNode_DOM |
| 55 | + */ |
46 | 56 | function newPartNodeArray( $values ) { |
47 | 57 | //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais) |
48 | 58 | $xml = "<list>"; |
— | — | @@ -65,6 +75,10 @@ |
66 | 76 | return $node; |
67 | 77 | } |
68 | 78 | |
| 79 | + /** |
| 80 | + * @throws MWException |
| 81 | + * @return bool |
| 82 | + */ |
69 | 83 | function memCheck() { |
70 | 84 | if ( $this->memoryLimit === false ) { |
71 | 85 | return; |
— | — | @@ -97,7 +111,7 @@ |
98 | 112 | * cache may be implemented at a later date which takes further advantage of these strict |
99 | 113 | * dependency requirements. |
100 | 114 | * |
101 | | - * @private |
| 115 | + * @return PPNode_DOM |
102 | 116 | */ |
103 | 117 | function preprocessToObj( $text, $flags = 0 ) { |
104 | 118 | wfProfileIn( __METHOD__ ); |
— | — | @@ -154,6 +168,11 @@ |
155 | 169 | return $obj; |
156 | 170 | } |
157 | 171 | |
| 172 | + /** |
| 173 | + * @param $text string |
| 174 | + * @param $flags int |
| 175 | + * @return string |
| 176 | + */ |
158 | 177 | function preprocessToXml( $text, $flags = 0 ) { |
159 | 178 | wfProfileIn( __METHOD__ ); |
160 | 179 | $rules = array( |
— | — | @@ -430,9 +449,7 @@ |
431 | 450 | $accum .= '<inner>' . htmlspecialchars( $inner ) . '</inner>'; |
432 | 451 | } |
433 | 452 | $accum .= $close . '</ext>'; |
434 | | - } |
435 | | - |
436 | | - elseif ( $found == 'line-start' ) { |
| 453 | + } elseif ( $found == 'line-start' ) { |
437 | 454 | // Is this the start of a heading? |
438 | 455 | // Line break belongs before the heading element in any case |
439 | 456 | if ( $fakeLineStart ) { |
— | — | @@ -460,9 +477,7 @@ |
461 | 478 | extract( $flags ); |
462 | 479 | $i += $count; |
463 | 480 | } |
464 | | - } |
465 | | - |
466 | | - elseif ( $found == 'line-end' ) { |
| 481 | + } elseif ( $found == 'line-end' ) { |
467 | 482 | $piece = $stack->top; |
468 | 483 | // A heading must be open, otherwise \n wouldn't have been in the search list |
469 | 484 | assert( $piece->open == "\n" ); |
— | — | @@ -564,7 +579,7 @@ |
565 | 580 | } |
566 | 581 | } |
567 | 582 | |
568 | | - if ($matchingCount <= 0) { |
| 583 | + if ( $matchingCount <= 0 ) { |
569 | 584 | # No matching element found in callback array |
570 | 585 | # Output a literal closing brace and continue |
571 | 586 | $accum .= htmlspecialchars( str_repeat( $curChar, $count ) ); |
— | — | @@ -614,7 +629,7 @@ |
615 | 630 | $accum =& $stack->getAccum(); |
616 | 631 | |
617 | 632 | # Re-add the old stack element if it still has unmatched opening characters remaining |
618 | | - if ($matchingCount < $piece->count) { |
| 633 | + if ( $matchingCount < $piece->count ) { |
619 | 634 | $piece->parts = array( new PPDPart ); |
620 | 635 | $piece->count -= $matchingCount; |
621 | 636 | # do we still qualify for any callback with remaining count? |
— | — | @@ -637,16 +652,12 @@ |
638 | 653 | |
639 | 654 | # Add XML element to the enclosing accumulator |
640 | 655 | $accum .= $element; |
641 | | - } |
642 | | - |
643 | | - elseif ( $found == 'pipe' ) { |
| 656 | + } elseif ( $found == 'pipe' ) { |
644 | 657 | $findEquals = true; // shortcut for getFlags() |
645 | 658 | $stack->addPart(); |
646 | 659 | $accum =& $stack->getAccum(); |
647 | 660 | ++$i; |
648 | | - } |
649 | | - |
650 | | - elseif ( $found == 'equals' ) { |
| 661 | + } elseif ( $found == 'equals' ) { |
651 | 662 | $findEquals = false; // shortcut for getFlags() |
652 | 663 | $stack->getCurrentPart()->eqpos = strlen( $accum ); |
653 | 664 | $accum .= '='; |
— | — | @@ -672,7 +683,12 @@ |
673 | 684 | * @ingroup Parser |
674 | 685 | */ |
675 | 686 | class PPDStack { |
676 | | - var $stack, $rootAccum, $top; |
| 687 | + var $stack, $rootAccum; |
| 688 | + |
| 689 | + /** |
| 690 | + * @var PPDStack |
| 691 | + */ |
| 692 | + var $top; |
677 | 693 | var $out; |
678 | 694 | var $elementClass = 'PPDStackElement'; |
679 | 695 | |
— | — | @@ -685,6 +701,9 @@ |
686 | 702 | $this->accum =& $this->rootAccum; |
687 | 703 | } |
688 | 704 | |
| 705 | + /** |
| 706 | + * @return int |
| 707 | + */ |
689 | 708 | function count() { |
690 | 709 | return count( $this->stack ); |
691 | 710 | } |
— | — | @@ -733,6 +752,9 @@ |
734 | 753 | $this->accum =& $this->top->getAccum(); |
735 | 754 | } |
736 | 755 | |
| 756 | + /** |
| 757 | + * @return array |
| 758 | + */ |
737 | 759 | function getFlags() { |
738 | 760 | if ( !count( $this->stack ) ) { |
739 | 761 | return array( |
— | — | @@ -780,6 +802,9 @@ |
781 | 803 | return $this->parts[count($this->parts) - 1]; |
782 | 804 | } |
783 | 805 | |
| 806 | + /** |
| 807 | + * @return array |
| 808 | + */ |
784 | 809 | function getFlags() { |
785 | 810 | $partCount = count( $this->parts ); |
786 | 811 | $findPipe = $this->open != "\n" && $this->open != '['; |
— | — | @@ -792,6 +817,8 @@ |
793 | 818 | |
794 | 819 | /** |
795 | 820 | * Get the output string that would result if the close is not found. |
| 821 | + * |
| 822 | + * @return string |
796 | 823 | */ |
797 | 824 | function breakSyntax( $openingCount = false ) { |
798 | 825 | if ( $this->open == "\n" ) { |
— | — | @@ -836,7 +863,21 @@ |
837 | 864 | * @ingroup Parser |
838 | 865 | */ |
839 | 866 | class PPFrame_DOM implements PPFrame { |
840 | | - var $preprocessor, $parser, $title; |
| 867 | + |
| 868 | + /** |
| 869 | + * @var Preprocessor |
| 870 | + */ |
| 871 | + var $preprocessor; |
| 872 | + |
| 873 | + /** |
| 874 | + * @var Parser |
| 875 | + */ |
| 876 | + var $parser; |
| 877 | + |
| 878 | + /** |
| 879 | + * @var Title |
| 880 | + */ |
| 881 | + var $title; |
841 | 882 | var $titleCache; |
842 | 883 | |
843 | 884 | /** |
— | — | @@ -854,7 +895,7 @@ |
855 | 896 | |
856 | 897 | /** |
857 | 898 | * Construct a new preprocessor frame. |
858 | | - * @param $preprocessor Preprocessor: The parent preprocessor |
| 899 | + * @param $preprocessor Preprocessor The parent preprocessor |
859 | 900 | */ |
860 | 901 | function __construct( $preprocessor ) { |
861 | 902 | $this->preprocessor = $preprocessor; |
— | — | @@ -868,6 +909,8 @@ |
869 | 910 | /** |
870 | 911 | * Create a new child frame |
871 | 912 | * $args is optionally a multi-root PPNode or array containing the template arguments |
| 913 | + * |
| 914 | + * @return PPTemplateFrame_DOM |
872 | 915 | */ |
873 | 916 | function newChild( $args = false, $title = false ) { |
874 | 917 | $namedArgs = array(); |
— | — | @@ -903,6 +946,12 @@ |
904 | 947 | return new PPTemplateFrame_DOM( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title ); |
905 | 948 | } |
906 | 949 | |
| 950 | + /** |
| 951 | + * @throws MWException |
| 952 | + * @param $root |
| 953 | + * @param $flags int |
| 954 | + * @return string |
| 955 | + */ |
907 | 956 | function expand( $root, $flags = 0 ) { |
908 | 957 | static $expansionDepth = 0; |
909 | 958 | if ( is_string( $root ) ) { |
— | — | @@ -1114,6 +1163,11 @@ |
1115 | 1164 | return $outStack[0]; |
1116 | 1165 | } |
1117 | 1166 | |
| 1167 | + /** |
| 1168 | + * @param $sep |
| 1169 | + * @param $flags |
| 1170 | + * @return string |
| 1171 | + */ |
1118 | 1172 | function implodeWithFlags( $sep, $flags /*, ... */ ) { |
1119 | 1173 | $args = array_slice( func_get_args(), 2 ); |
1120 | 1174 | |
— | — | @@ -1139,6 +1193,8 @@ |
1140 | 1194 | /** |
1141 | 1195 | * Implode with no flags specified |
1142 | 1196 | * This previously called implodeWithFlags but has now been inlined to reduce stack depth |
| 1197 | + * |
| 1198 | + * @return string |
1143 | 1199 | */ |
1144 | 1200 | function implode( $sep /*, ... */ ) { |
1145 | 1201 | $args = array_slice( func_get_args(), 1 ); |
— | — | @@ -1234,20 +1290,31 @@ |
1235 | 1291 | } |
1236 | 1292 | } |
1237 | 1293 | |
| 1294 | + /** |
| 1295 | + * @return array |
| 1296 | + */ |
1238 | 1297 | function getArguments() { |
1239 | 1298 | return array(); |
1240 | 1299 | } |
1241 | 1300 | |
| 1301 | + /** |
| 1302 | + * @return array |
| 1303 | + */ |
1242 | 1304 | function getNumberedArguments() { |
1243 | 1305 | return array(); |
1244 | 1306 | } |
1245 | 1307 | |
| 1308 | + /** |
| 1309 | + * @return array |
| 1310 | + */ |
1246 | 1311 | function getNamedArguments() { |
1247 | 1312 | return array(); |
1248 | 1313 | } |
1249 | 1314 | |
1250 | 1315 | /** |
1251 | 1316 | * Returns true if there are no arguments in this frame |
| 1317 | + * |
| 1318 | + * @return bool |
1252 | 1319 | */ |
1253 | 1320 | function isEmpty() { |
1254 | 1321 | return true; |
— | — | @@ -1259,6 +1326,8 @@ |
1260 | 1327 | |
1261 | 1328 | /** |
1262 | 1329 | * Returns true if the infinite loop check is OK, false if a loop is detected |
| 1330 | + * |
| 1331 | + * @return bool |
1263 | 1332 | */ |
1264 | 1333 | function loopCheck( $title ) { |
1265 | 1334 | return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] ); |
— | — | @@ -1266,6 +1335,8 @@ |
1267 | 1336 | |
1268 | 1337 | /** |
1269 | 1338 | * Return true if the frame is a template frame |
| 1339 | + * |
| 1340 | + * @return bool |
1270 | 1341 | */ |
1271 | 1342 | function isTemplate() { |
1272 | 1343 | return false; |
— | — | @@ -1277,9 +1348,21 @@ |
1278 | 1349 | * @ingroup Parser |
1279 | 1350 | */ |
1280 | 1351 | class PPTemplateFrame_DOM extends PPFrame_DOM { |
1281 | | - var $numberedArgs, $namedArgs, $parent; |
| 1352 | + var $numberedArgs, $namedArgs; |
| 1353 | + |
| 1354 | + /** |
| 1355 | + * @var PPFrame_DOM |
| 1356 | + */ |
| 1357 | + var $parent; |
1282 | 1358 | var $numberedExpansionCache, $namedExpansionCache; |
1283 | 1359 | |
| 1360 | + /** |
| 1361 | + * @param $preprocessor |
| 1362 | + * @param $parent PPFrame_DOM |
| 1363 | + * @param $numberedArgs array |
| 1364 | + * @param $namedArgs array |
| 1365 | + * @param $title Title |
| 1366 | + */ |
1284 | 1367 | function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) { |
1285 | 1368 | parent::__construct( $preprocessor ); |
1286 | 1369 | |
— | — | @@ -1314,8 +1397,11 @@ |
1315 | 1398 | $s .= '}'; |
1316 | 1399 | return $s; |
1317 | 1400 | } |
| 1401 | + |
1318 | 1402 | /** |
1319 | 1403 | * Returns true if there are no arguments in this frame |
| 1404 | + * |
| 1405 | + * @return bool |
1320 | 1406 | */ |
1321 | 1407 | function isEmpty() { |
1322 | 1408 | return !count( $this->numberedArgs ) && !count( $this->namedArgs ); |
— | — | @@ -1380,6 +1466,8 @@ |
1381 | 1467 | |
1382 | 1468 | /** |
1383 | 1469 | * Return true if the frame is a template frame |
| 1470 | + * |
| 1471 | + * @return bool |
1384 | 1472 | */ |
1385 | 1473 | function isTemplate() { |
1386 | 1474 | return true; |
— | — | @@ -1414,6 +1502,9 @@ |
1415 | 1503 | return $s; |
1416 | 1504 | } |
1417 | 1505 | |
| 1506 | + /** |
| 1507 | + * @return bool |
| 1508 | + */ |
1418 | 1509 | function isEmpty() { |
1419 | 1510 | return !count( $this->args ); |
1420 | 1511 | } |
— | — | @@ -1430,8 +1521,13 @@ |
1431 | 1522 | * @ingroup Parser |
1432 | 1523 | */ |
1433 | 1524 | class PPNode_DOM implements PPNode { |
1434 | | - var $node, $xpath; |
1435 | 1525 | |
| 1526 | + /** |
| 1527 | + * @var DOMElement |
| 1528 | + */ |
| 1529 | + var $node; |
| 1530 | + var $xpath; |
| 1531 | + |
1436 | 1532 | function __construct( $node, $xpath = false ) { |
1437 | 1533 | $this->node = $node; |
1438 | 1534 | } |