r106618 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106617‎ | r106618 | r106619 >
Date:00:54, 19 December 2011
Author:reedy
Status:ok
Tags:
Comment:
Flesh out documentation

Remove some more < 1.12 back compat code
Modified paths:
  • /trunk/extensions/ParserFunctions/ParserFunctions_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php
@@ -7,6 +7,10 @@
88 static $mTimeChars = 0;
99 static $mMaxTimeChars = 6000; # ~10 seconds
1010
 11+ /**
 12+ * @param $parser Parser
 13+ * @return bool
 14+ */
1115 public static function clearState( $parser ) {
1216 self::$mTimeChars = 0;
1317 $parser->pf_ifexist_breakdown = array();
@@ -30,6 +34,8 @@
3135
3236 /**
3337 * Get the marker regex. Cached.
 38+ * @param $parser Parser
 39+ * @return
3440 */
3541 public static function getMarkerRegex( $parser ) {
3642 self::registerClearHook();
@@ -41,16 +47,7 @@
4248
4349 $prefix = preg_quote( $parser->uniqPrefix(), '/' );
4450
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, '/' );
5552
5653 $parser->pf_markerRegex = '/' . $prefix . '(?:(?!' . $suffix . ').)*' . $suffix . '/us';
5754
@@ -58,7 +55,11 @@
5956 return $parser->pf_markerRegex;
6057 }
6158
62 - // Removes unique markers from passed parameters, used by string functions.
 59+ /**
 60+ * @param $parser Parser
 61+ * @param $text string
 62+ * @return string
 63+ */
6364 private static function killMarkers ( $parser, $text ) {
6465 return preg_replace( self::getMarkerRegex( $parser ), '' , $text );
6566 }
@@ -73,6 +74,11 @@
7475 return self::$mExprParser;
7576 }
7677
 78+ /**
 79+ * @param $parser Parser
 80+ * @param $expr string
 81+ * @return string
 82+ */
7783 public static function expr( $parser, $expr = '' ) {
7884 try {
7985 return self::getExprParser()->doExpression( $expr );
@@ -81,6 +87,13 @@
8288 }
8389 }
8490
 91+ /**
 92+ * @param $parser Parser
 93+ * @param $expr string
 94+ * @param $then string
 95+ * @param $else string
 96+ * @return string
 97+ */
8598 public static function ifexpr( $parser, $expr = '', $then = '', $else = '' ) {
8699 try {
87100 $ret = self::getExprParser()->doExpression( $expr );
@@ -97,6 +110,12 @@
98111 }
99112 }
100113
 114+ /**
 115+ * @param $parser Parser
 116+ * @param $frame PPFrame
 117+ * @param $args array
 118+ * @return string
 119+ */
101120 public static function ifexprObj( $parser, $frame, $args ) {
102121 $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
103122 $then = isset( $args[1] ) ? $args[1] : '';
@@ -108,6 +127,12 @@
109128 return $result;
110129 }
111130
 131+ /**
 132+ * @param $parser Parser
 133+ * @param $frame PPFrame
 134+ * @param $args array
 135+ * @return string
 136+ */
112137 public static function ifObj( $parser, $frame, $args ) {
113138 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
114139 if ( $test !== '' ) {
@@ -117,6 +142,12 @@
118143 }
119144 }
120145
 146+ /**
 147+ * @param $parser Parser
 148+ * @param $frame PPFrame
 149+ * @param $args array
 150+ * @return string
 151+ */
121152 public static function ifeqObj( $parser, $frame, $args ) {
122153 $left = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
123154 $right = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
@@ -127,6 +158,13 @@
128159 }
129160 }
130161
 162+ /**
 163+ * @param $parser Parser
 164+ * @param $test string
 165+ * @param $then string
 166+ * @param $else bool
 167+ * @return bool|string
 168+ */
131169 public static function iferror( $parser, $test = '', $then = '', $else = false ) {
132170 if ( preg_match( '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/', $test ) ) {
133171 return $then;
@@ -137,6 +175,12 @@
138176 }
139177 }
140178
 179+ /**
 180+ * @param $parser Parser
 181+ * @param $frame PPFrame
 182+ * @param $args array
 183+ * @return string
 184+ */
141185 public static function iferrorObj( $parser, $frame, $args ) {
142186 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
143187 $then = isset( $args[1] ) ? $args[1] : false;
@@ -216,6 +260,10 @@
217261 * initial slash is treated as a relative path, and vice versa.
218262 *
219263 * @param $parser Parser
 264+ * @param $to string
 265+ * @param $from string
 266+ *
 267+ * @return string
220268 */
221269 public static function rel2abs( $parser , $to = '' , $from = '' ) {
222270
@@ -272,7 +320,6 @@
273321 }
274322
275323 /**
276 - * @static
277324 * @param $parser Parser
278325 * @param $frame PPFrame
279326 * @return bool
@@ -292,6 +339,15 @@
293340 return $parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit;
294341 }
295342
 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+ */
296352 public static function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) {
297353 global $wgContLang;
298354 $title = Title::newFromText( $titletext );
@@ -347,6 +403,12 @@
348404 return $else;
349405 }
350406
 407+ /**
 408+ * @param $parser Parser
 409+ * @param $frame PPFrame
 410+ * @param $args array
 411+ * @return string
 412+ */
351413 public static function ifexistObj( $parser, $frame, $args ) {
352414 $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
353415 $then = isset( $args[1] ) ? $args[1] : null;
@@ -360,8 +422,16 @@
361423 }
362424 }
363425
 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+ */
364434 public static function time( $parser, $format = '', $date = '', $language = '', $local = false ) {
365 - global $wgLang, $wgContLang, $wgLocaltimezone;
 435+ global $wgLocaltimezone;
366436 self::registerClearHook();
367437 if ( isset( self::$mTimeCache[$format][$date][$language][$local] ) ) {
368438 return self::$mTimeCache[$format][$date][$language][$local];
@@ -464,6 +534,13 @@
465535 return $result;
466536 }
467537
 538+ /**
 539+ * @param $parser Parser
 540+ * @param $format string
 541+ * @param $date string
 542+ * @param $language string
 543+ * @return string
 544+ */
468545 public static function localTime( $parser, $format = '', $date = '', $language = '' ) {
469546 return self::time( $parser, $format, $date, $language, true );
470547 }
@@ -472,10 +549,10 @@
473550 * Obtain a specified number of slash-separated parts of a title,
474551 * e.g. {{#titleparts:Hello/World|1}} => "Hello"
475552 *
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
480557 * @return string
481558 */
482559 public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
@@ -512,6 +589,9 @@
513590 return self::$mConvertParser;
514591 }
515592
 593+ /**
 594+ * @return string
 595+ */
516596 public static function convert( /*...*/ ) {
517597 try {
518598 $args = func_get_args();
@@ -521,13 +601,20 @@
522602 }
523603 }
524604
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+ */
526610 private static function checkLength( $text ) {
527611 global $wgPFStringLengthLimit;
528612 return ( mb_strlen( $text ) < $wgPFStringLengthLimit );
529613 }
530614
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+ */
532619 private static function tooLongError() {
533620 global $wgPFStringLengthLimit, $wgContLang;
534621 return '<strong class="error">' .
@@ -541,6 +628,9 @@
542629 * {{#len:string}}
543630 *
544631 * Reports number of characters in string.
 632+ * @param $parser Parser
 633+ * @param $inStr string
 634+ * @return int
545635 */
546636 public static function runLen ( $parser, $inStr = '' ) {
547637 wfProfileIn( __METHOD__ );
@@ -559,6 +649,11 @@
560650 *
561651 * Note: If the needle is an empty string, single space is used instead.
562652 * 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
563658 */
564659 public static function runPos ( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
565660 wfProfileIn( __METHOD__ );
@@ -588,6 +683,10 @@
589684 *
590685 * Note: If the needle is an empty string, single space is used instead.
591686 * 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
592691 */
593692 public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) {
594693 wfProfileIn( __METHOD__ );
@@ -621,6 +720,12 @@
622721 * "string".
623722 * Note: A negative value for "length" returns a string reduced in
624723 * length by that amount.
 724+ *
 725+ * @param $parser Parser
 726+ * @param $inStr string
 727+ * @param $inStart int
 728+ * @param $inLength int
 729+ * @return string
625730 */
626731 public static function runSub ( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
627732 wfProfileIn( __METHOD__ );
@@ -648,6 +753,10 @@
649754 * Returns number of occurrences of "substr" in "string".
650755 *
651756 * 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
652761 */
653762 public static function runCount ( $parser, $inStr = '', $inSubStr = '' ) {
654763 wfProfileIn( __METHOD__ );
@@ -656,12 +765,14 @@
657766 $inSubStr = self::killMarkers( $parser, (string)$inSubStr );
658767
659768 if ( !self::checkLength( $inStr ) ||
660 - !self::checkLength( $inSubStr ) ) {
 769+ !self::checkLength( $inSubStr ) ) {
661770 wfProfileOut( __METHOD__ );
662771 return self::tooLongError();
663772 }
664773
665 - if ( $inSubStr == '' ) { $inSubStr = ' '; }
 774+ if ( $inSubStr == '' ) {
 775+ $inSubStr = ' ';
 776+ }
666777
667778 $result = mb_substr_count( $inStr, $inSubStr );
668779
@@ -677,6 +788,12 @@
678789 *
679790 * Note: Armored against replacements that would generate huge strings.
680791 * 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
681798 */
682799 public static function runReplace( $parser, $inStr = '',
683800 $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
@@ -735,6 +852,12 @@
736853 * Note: Negative position can be used to specify tokens from the end.
737854 * Note: If the divider is an empty string, single space is used instead.
738855 * 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
739862 */
740863 public static function runExplode ( $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null ) {
741864 wfProfileIn( __METHOD__ );
@@ -742,7 +865,9 @@
743866 $inStr = self::killMarkers( $parser, (string)$inStr );
744867 $inDiv = self::killMarkers( $parser, (string)$inDiv );
745868
746 - if ( $inDiv == '' ) { $inDiv = ' '; }
 869+ if ( $inDiv == '' ) {
 870+ $inDiv = ' ';
 871+ }
747872
748873 if ( !self::checkLength( $inStr ) ||
749874 !self::checkLength( $inDiv ) ) {
@@ -770,6 +895,9 @@
771896 * {{#urldecode:string}}
772897 *
773898 * Decodes URL-encoded (like%20that) strings.
 899+ * @param $parser Parser
 900+ * @param $inStr string
 901+ * @return string
774902 */
775903 public static function runUrlDecode( $parser, $inStr = '' ) {
776904 wfProfileIn( __METHOD__ );

Status & tagging log