Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php |
— | — | @@ -7,6 +7,10 @@ |
8 | 8 | static $mTimeChars = 0; |
9 | 9 | static $mMaxTimeChars = 6000; # ~10 seconds |
10 | 10 | |
| 11 | + /** |
| 12 | + * @param $parser Parser |
| 13 | + * @return bool |
| 14 | + */ |
11 | 15 | public static function clearState( $parser ) { |
12 | 16 | self::$mTimeChars = 0; |
13 | 17 | $parser->pf_ifexist_breakdown = array(); |
— | — | @@ -30,6 +34,8 @@ |
31 | 35 | |
32 | 36 | /** |
33 | 37 | * Get the marker regex. Cached. |
| 38 | + * @param $parser Parser |
| 39 | + * @return |
34 | 40 | */ |
35 | 41 | public static function getMarkerRegex( $parser ) { |
36 | 42 | self::registerClearHook(); |
— | — | @@ -41,16 +47,7 @@ |
42 | 48 | |
43 | 49 | $prefix = preg_quote( $parser->uniqPrefix(), '/' ); |
44 | 50 | |
45 | | - // The first line represents Parser from release 1.12 forward. |
46 | | - // subsequent lines are hacks to accomodate old Mediawiki versions. |
47 | | - if ( defined( 'Parser::MARKER_SUFFIX' ) ) |
48 | | - $suffix = preg_quote( Parser::MARKER_SUFFIX, '/' ); |
49 | | - elseif ( isset( $parser->mMarkerSuffix ) ) |
50 | | - $suffix = preg_quote( $parser->mMarkerSuffix, '/' ); |
51 | | - elseif ( defined( 'MW_PARSER_VERSION' ) && |
52 | | - strcmp( MW_PARSER_VERSION, '1.6.1' ) > 0 ) |
53 | | - $suffix = "QINU\x07"; |
54 | | - else $suffix = 'QINU'; |
| 51 | + $suffix = preg_quote( Parser::MARKER_SUFFIX, '/' ); |
55 | 52 | |
56 | 53 | $parser->pf_markerRegex = '/' . $prefix . '(?:(?!' . $suffix . ').)*' . $suffix . '/us'; |
57 | 54 | |
— | — | @@ -58,7 +55,11 @@ |
59 | 56 | return $parser->pf_markerRegex; |
60 | 57 | } |
61 | 58 | |
62 | | - // Removes unique markers from passed parameters, used by string functions. |
| 59 | + /** |
| 60 | + * @param $parser Parser |
| 61 | + * @param $text string |
| 62 | + * @return string |
| 63 | + */ |
63 | 64 | private static function killMarkers ( $parser, $text ) { |
64 | 65 | return preg_replace( self::getMarkerRegex( $parser ), '' , $text ); |
65 | 66 | } |
— | — | @@ -73,6 +74,11 @@ |
74 | 75 | return self::$mExprParser; |
75 | 76 | } |
76 | 77 | |
| 78 | + /** |
| 79 | + * @param $parser Parser |
| 80 | + * @param $expr string |
| 81 | + * @return string |
| 82 | + */ |
77 | 83 | public static function expr( $parser, $expr = '' ) { |
78 | 84 | try { |
79 | 85 | return self::getExprParser()->doExpression( $expr ); |
— | — | @@ -81,6 +87,13 @@ |
82 | 88 | } |
83 | 89 | } |
84 | 90 | |
| 91 | + /** |
| 92 | + * @param $parser Parser |
| 93 | + * @param $expr string |
| 94 | + * @param $then string |
| 95 | + * @param $else string |
| 96 | + * @return string |
| 97 | + */ |
85 | 98 | public static function ifexpr( $parser, $expr = '', $then = '', $else = '' ) { |
86 | 99 | try { |
87 | 100 | $ret = self::getExprParser()->doExpression( $expr ); |
— | — | @@ -97,6 +110,12 @@ |
98 | 111 | } |
99 | 112 | } |
100 | 113 | |
| 114 | + /** |
| 115 | + * @param $parser Parser |
| 116 | + * @param $frame PPFrame |
| 117 | + * @param $args array |
| 118 | + * @return string |
| 119 | + */ |
101 | 120 | public static function ifexprObj( $parser, $frame, $args ) { |
102 | 121 | $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
103 | 122 | $then = isset( $args[1] ) ? $args[1] : ''; |
— | — | @@ -108,6 +127,12 @@ |
109 | 128 | return $result; |
110 | 129 | } |
111 | 130 | |
| 131 | + /** |
| 132 | + * @param $parser Parser |
| 133 | + * @param $frame PPFrame |
| 134 | + * @param $args array |
| 135 | + * @return string |
| 136 | + */ |
112 | 137 | public static function ifObj( $parser, $frame, $args ) { |
113 | 138 | $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
114 | 139 | if ( $test !== '' ) { |
— | — | @@ -117,6 +142,12 @@ |
118 | 143 | } |
119 | 144 | } |
120 | 145 | |
| 146 | + /** |
| 147 | + * @param $parser Parser |
| 148 | + * @param $frame PPFrame |
| 149 | + * @param $args array |
| 150 | + * @return string |
| 151 | + */ |
121 | 152 | public static function ifeqObj( $parser, $frame, $args ) { |
122 | 153 | $left = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
123 | 154 | $right = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ''; |
— | — | @@ -127,6 +158,13 @@ |
128 | 159 | } |
129 | 160 | } |
130 | 161 | |
| 162 | + /** |
| 163 | + * @param $parser Parser |
| 164 | + * @param $test string |
| 165 | + * @param $then string |
| 166 | + * @param $else bool |
| 167 | + * @return bool|string |
| 168 | + */ |
131 | 169 | public static function iferror( $parser, $test = '', $then = '', $else = false ) { |
132 | 170 | if ( preg_match( '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/', $test ) ) { |
133 | 171 | return $then; |
— | — | @@ -137,6 +175,12 @@ |
138 | 176 | } |
139 | 177 | } |
140 | 178 | |
| 179 | + /** |
| 180 | + * @param $parser Parser |
| 181 | + * @param $frame PPFrame |
| 182 | + * @param $args array |
| 183 | + * @return string |
| 184 | + */ |
141 | 185 | public static function iferrorObj( $parser, $frame, $args ) { |
142 | 186 | $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
143 | 187 | $then = isset( $args[1] ) ? $args[1] : false; |
— | — | @@ -216,6 +260,10 @@ |
217 | 261 | * initial slash is treated as a relative path, and vice versa. |
218 | 262 | * |
219 | 263 | * @param $parser Parser |
| 264 | + * @param $to string |
| 265 | + * @param $from string |
| 266 | + * |
| 267 | + * @return string |
220 | 268 | */ |
221 | 269 | public static function rel2abs( $parser , $to = '' , $from = '' ) { |
222 | 270 | |
— | — | @@ -272,7 +320,6 @@ |
273 | 321 | } |
274 | 322 | |
275 | 323 | /** |
276 | | - * @static |
277 | 324 | * @param $parser Parser |
278 | 325 | * @param $frame PPFrame |
279 | 326 | * @return bool |
— | — | @@ -292,6 +339,15 @@ |
293 | 340 | return $parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit; |
294 | 341 | } |
295 | 342 | |
| 343 | + /** |
| 344 | + * @param $parser Parser |
| 345 | + * @param $frame PPFrame |
| 346 | + * @param $titletext string |
| 347 | + * @param $then string |
| 348 | + * @param $else string |
| 349 | + * |
| 350 | + * @return string |
| 351 | + */ |
296 | 352 | public static function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) { |
297 | 353 | global $wgContLang; |
298 | 354 | $title = Title::newFromText( $titletext ); |
— | — | @@ -347,6 +403,12 @@ |
348 | 404 | return $else; |
349 | 405 | } |
350 | 406 | |
| 407 | + /** |
| 408 | + * @param $parser Parser |
| 409 | + * @param $frame PPFrame |
| 410 | + * @param $args array |
| 411 | + * @return string |
| 412 | + */ |
351 | 413 | public static function ifexistObj( $parser, $frame, $args ) { |
352 | 414 | $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
353 | 415 | $then = isset( $args[1] ) ? $args[1] : null; |
— | — | @@ -360,8 +422,16 @@ |
361 | 423 | } |
362 | 424 | } |
363 | 425 | |
| 426 | + /** |
| 427 | + * @param $parser Parser |
| 428 | + * @param $format string |
| 429 | + * @param $date string |
| 430 | + * @param $language string |
| 431 | + * @param $local string|bool |
| 432 | + * @return string |
| 433 | + */ |
364 | 434 | public static function time( $parser, $format = '', $date = '', $language = '', $local = false ) { |
365 | | - global $wgLang, $wgContLang, $wgLocaltimezone; |
| 435 | + global $wgLocaltimezone; |
366 | 436 | self::registerClearHook(); |
367 | 437 | if ( isset( self::$mTimeCache[$format][$date][$language][$local] ) ) { |
368 | 438 | return self::$mTimeCache[$format][$date][$language][$local]; |
— | — | @@ -464,6 +534,13 @@ |
465 | 535 | return $result; |
466 | 536 | } |
467 | 537 | |
| 538 | + /** |
| 539 | + * @param $parser Parser |
| 540 | + * @param $format string |
| 541 | + * @param $date string |
| 542 | + * @param $language string |
| 543 | + * @return string |
| 544 | + */ |
468 | 545 | public static function localTime( $parser, $format = '', $date = '', $language = '' ) { |
469 | 546 | return self::time( $parser, $format, $date, $language, true ); |
470 | 547 | } |
— | — | @@ -472,10 +549,10 @@ |
473 | 550 | * Obtain a specified number of slash-separated parts of a title, |
474 | 551 | * e.g. {{#titleparts:Hello/World|1}} => "Hello" |
475 | 552 | * |
476 | | - * @param Parser $parser Parent parser |
477 | | - * @param string $title Title to split |
478 | | - * @param int $parts Number of parts to keep |
479 | | - * @param int $offset Offset starting at 1 |
| 553 | + * @param $parser Parent parser |
| 554 | + * @param $title string Title to split |
| 555 | + * @param $parts int Number of parts to keep |
| 556 | + * @param $offset int Offset starting at 1 |
480 | 557 | * @return string |
481 | 558 | */ |
482 | 559 | public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) { |
— | — | @@ -512,6 +589,9 @@ |
513 | 590 | return self::$mConvertParser; |
514 | 591 | } |
515 | 592 | |
| 593 | + /** |
| 594 | + * @return string |
| 595 | + */ |
516 | 596 | public static function convert( /*...*/ ) { |
517 | 597 | try { |
518 | 598 | $args = func_get_args(); |
— | — | @@ -521,13 +601,20 @@ |
522 | 602 | } |
523 | 603 | } |
524 | 604 | |
525 | | - // Verifies parameter is less than max string length. |
| 605 | + /** |
| 606 | + * Verifies parameter is less than max string length. |
| 607 | + * @param $text |
| 608 | + * @return bool |
| 609 | + */ |
526 | 610 | private static function checkLength( $text ) { |
527 | 611 | global $wgPFStringLengthLimit; |
528 | 612 | return ( mb_strlen( $text ) < $wgPFStringLengthLimit ); |
529 | 613 | } |
530 | 614 | |
531 | | - // Generates error message. Called when string is too long. |
| 615 | + /** |
| 616 | + * Generates error message. Called when string is too long. |
| 617 | + * @return string |
| 618 | + */ |
532 | 619 | private static function tooLongError() { |
533 | 620 | global $wgPFStringLengthLimit, $wgContLang; |
534 | 621 | return '<strong class="error">' . |
— | — | @@ -541,6 +628,9 @@ |
542 | 629 | * {{#len:string}} |
543 | 630 | * |
544 | 631 | * Reports number of characters in string. |
| 632 | + * @param $parser Parser |
| 633 | + * @param $inStr string |
| 634 | + * @return int |
545 | 635 | */ |
546 | 636 | public static function runLen ( $parser, $inStr = '' ) { |
547 | 637 | wfProfileIn( __METHOD__ ); |
— | — | @@ -559,6 +649,11 @@ |
560 | 650 | * |
561 | 651 | * Note: If the needle is an empty string, single space is used instead. |
562 | 652 | * Note: If the needle is not found, empty string is returned. |
| 653 | + * @param $parser Parser |
| 654 | + * @param $inStr string |
| 655 | + * @param $inNeedle int |
| 656 | + * @param $inOffset int |
| 657 | + * @return int|string |
563 | 658 | */ |
564 | 659 | public static function runPos ( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
565 | 660 | wfProfileIn( __METHOD__ ); |
— | — | @@ -588,6 +683,10 @@ |
589 | 684 | * |
590 | 685 | * Note: If the needle is an empty string, single space is used instead. |
591 | 686 | * Note: If the needle is not found, -1 is returned. |
| 687 | + * @param $parser Parser |
| 688 | + * @param $inStr string |
| 689 | + * @param $inNeedle int |
| 690 | + * @return int|string |
592 | 691 | */ |
593 | 692 | public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) { |
594 | 693 | wfProfileIn( __METHOD__ ); |
— | — | @@ -621,6 +720,12 @@ |
622 | 721 | * "string". |
623 | 722 | * Note: A negative value for "length" returns a string reduced in |
624 | 723 | * length by that amount. |
| 724 | + * |
| 725 | + * @param $parser Parser |
| 726 | + * @param $inStr string |
| 727 | + * @param $inStart int |
| 728 | + * @param $inLength int |
| 729 | + * @return string |
625 | 730 | */ |
626 | 731 | public static function runSub ( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) { |
627 | 732 | wfProfileIn( __METHOD__ ); |
— | — | @@ -648,6 +753,10 @@ |
649 | 754 | * Returns number of occurrences of "substr" in "string". |
650 | 755 | * |
651 | 756 | * Note: If "substr" is empty, a single space is used. |
| 757 | + * @param $parser |
| 758 | + * @param $inStr string |
| 759 | + * @param $inSubStr string |
| 760 | + * @return int|string |
652 | 761 | */ |
653 | 762 | public static function runCount ( $parser, $inStr = '', $inSubStr = '' ) { |
654 | 763 | wfProfileIn( __METHOD__ ); |
— | — | @@ -656,12 +765,14 @@ |
657 | 766 | $inSubStr = self::killMarkers( $parser, (string)$inSubStr ); |
658 | 767 | |
659 | 768 | if ( !self::checkLength( $inStr ) || |
660 | | - !self::checkLength( $inSubStr ) ) { |
| 769 | + !self::checkLength( $inSubStr ) ) { |
661 | 770 | wfProfileOut( __METHOD__ ); |
662 | 771 | return self::tooLongError(); |
663 | 772 | } |
664 | 773 | |
665 | | - if ( $inSubStr == '' ) { $inSubStr = ' '; } |
| 774 | + if ( $inSubStr == '' ) { |
| 775 | + $inSubStr = ' '; |
| 776 | + } |
666 | 777 | |
667 | 778 | $result = mb_substr_count( $inStr, $inSubStr ); |
668 | 779 | |
— | — | @@ -677,6 +788,12 @@ |
678 | 789 | * |
679 | 790 | * Note: Armored against replacements that would generate huge strings. |
680 | 791 | * Note: If "from" is an empty string, single space is used instead. |
| 792 | + * @param $parser Parser |
| 793 | + * @param $inStr string |
| 794 | + * @param $inReplaceFrom string |
| 795 | + * @param $inReplaceTo string |
| 796 | + * @param $inLimit int |
| 797 | + * @return mixed|string |
681 | 798 | */ |
682 | 799 | public static function runReplace( $parser, $inStr = '', |
683 | 800 | $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) { |
— | — | @@ -735,6 +852,12 @@ |
736 | 853 | * Note: Negative position can be used to specify tokens from the end. |
737 | 854 | * Note: If the divider is an empty string, single space is used instead. |
738 | 855 | * Note: Empty string is returned if there are not enough exploded chunks. |
| 856 | + * @param $parser Parser |
| 857 | + * @param $inStr string |
| 858 | + * @param $inDiv string |
| 859 | + * @param $inPos int |
| 860 | + * @param $inLim int|null |
| 861 | + * @return string |
739 | 862 | */ |
740 | 863 | public static function runExplode ( $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null ) { |
741 | 864 | wfProfileIn( __METHOD__ ); |
— | — | @@ -742,7 +865,9 @@ |
743 | 866 | $inStr = self::killMarkers( $parser, (string)$inStr ); |
744 | 867 | $inDiv = self::killMarkers( $parser, (string)$inDiv ); |
745 | 868 | |
746 | | - if ( $inDiv == '' ) { $inDiv = ' '; } |
| 869 | + if ( $inDiv == '' ) { |
| 870 | + $inDiv = ' '; |
| 871 | + } |
747 | 872 | |
748 | 873 | if ( !self::checkLength( $inStr ) || |
749 | 874 | !self::checkLength( $inDiv ) ) { |
— | — | @@ -770,6 +895,9 @@ |
771 | 896 | * {{#urldecode:string}} |
772 | 897 | * |
773 | 898 | * Decodes URL-encoded (like%20that) strings. |
| 899 | + * @param $parser Parser |
| 900 | + * @param $inStr string |
| 901 | + * @return string |
774 | 902 | */ |
775 | 903 | public static function runUrlDecode( $parser, $inStr = '' ) { |
776 | 904 | wfProfileIn( __METHOD__ ); |