r74599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74598‎ | r74599 | r74600 >
Date:15:41, 10 October 2010
Author:platonides
Status:deferred
Tags:
Comment:
Make everything static
Modified paths:
  • /trunk/extensions/StringFunctions/StringFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/StringFunctions/StringFunctions.php
@@ -117,25 +117,24 @@
118118 $wgHooks['LanguageGetMagic'][] = 'wfStringFunctionsLanguageGetMagic';
119119
120120 function wfStringFunctions() {
121 - global $wgParser, $wgExtStringFunctions;
 121+ global $wgParser;
122122 global $wgStringFunctionsLimitSearch;
123123 global $wgStringFunctionsLimitReplace;
124124 global $wgStringFunctionsLimitPad;
125125
126 - $wgExtStringFunctions = new ExtStringFunctions();
127126 $wgStringFunctionsLimitSearch = 30;
128127 $wgStringFunctionsLimitReplace = 30;
129128 $wgStringFunctionsLimitPad = 100;
130129
131 - $wgParser->setFunctionHook( 'len', array( &$wgExtStringFunctions, 'runLen' ) );
132 - $wgParser->setFunctionHook( 'pos', array( &$wgExtStringFunctions, 'runPos' ) );
133 - $wgParser->setFunctionHook( 'rpos', array( &$wgExtStringFunctions, 'runRPos' ) );
134 - $wgParser->setFunctionHook( 'sub', array( &$wgExtStringFunctions, 'runSub' ) );
135 - $wgParser->setFunctionHook( 'pad', array( &$wgExtStringFunctions, 'runPad' ) );
136 - $wgParser->setFunctionHook( 'replace', array( &$wgExtStringFunctions, 'runReplace' ) );
137 - $wgParser->setFunctionHook( 'explode', array( &$wgExtStringFunctions, 'runExplode' ) );
138 - $wgParser->setFunctionHook( 'urlencode', array( &$wgExtStringFunctions, 'runUrlEncode' ) );
139 - $wgParser->setFunctionHook( 'urldecode', array( &$wgExtStringFunctions, 'runUrlDecode' ) );
 130+ $wgParser->setFunctionHook( 'len', array( 'ExtStringFunctions', 'runLen' ) );
 131+ $wgParser->setFunctionHook( 'pos', array( 'ExtStringFunctions', 'runPos' ) );
 132+ $wgParser->setFunctionHook( 'rpos', array( 'ExtStringFunctions', 'runRPos' ) );
 133+ $wgParser->setFunctionHook( 'sub', array( 'ExtStringFunctions', 'runSub' ) );
 134+ $wgParser->setFunctionHook( 'pad', array( 'ExtStringFunctions', 'runPad' ) );
 135+ $wgParser->setFunctionHook( 'replace', array( 'ExtStringFunctions', 'runReplace' ) );
 136+ $wgParser->setFunctionHook( 'explode', array( 'ExtStringFunctions', 'runExplode' ) );
 137+ $wgParser->setFunctionHook( 'urlencode', array( 'ExtStringFunctions', 'runUrlEncode' ) );
 138+ $wgParser->setFunctionHook( 'urldecode', array( 'ExtStringFunctions', 'runUrlDecode' ) );
140139 }
141140
142141 function wfStringFunctionsLanguageGetMagic( &$magicWords, $langCode = 'en' ) {
@@ -160,7 +159,7 @@
161160 * Returns part of the perl regexp pattern that matches a marker.
162161 * Unfortunatelly, we are still backward-supporting old versions.
163162 */
164 - function mwMarkerRE( &$parser ) {
 163+ static protected function mwMarkerRE( &$parser ) {
165164 if ( defined( 'Parser::MARKER_SUFFIX' ) ) {
166165 $suffix = preg_quote( Parser::MARKER_SUFFIX, '/' );
167166 } elseif ( isset( $parser->mMarkerSuffix ) ) {
@@ -179,11 +178,11 @@
180179 *
181180 * Main idea: Count multibytes. Find markers. Substract.
182181 */
183 - function runLen( &$parser, $inStr = '' ) {
 182+ static function runLen( &$parser, $inStr = '' ) {
184183 $len = mb_strlen( (string)$inStr );
185184
186185 $count = preg_match_all (
187 - '/' . $this->mwMarkerRE( $parser ) . '/',
 186+ '/' . self::mwMarkerRE( $parser ) . '/',
188187 (string) $inStr, $matches
189188 );
190189
@@ -199,7 +198,7 @@
200199 * $chars is set to the resulting array of multibyte characters.
201200 * Returns count($chars).
202201 */
203 - function mwSplit( &$parser, $str, &$chars ) {
 202+ static protected function mwSplit( &$parser, $str, &$chars ) {
204203 # Get marker prefix & suffix
205204 $prefix = preg_quote( $parser->mUniqPrefix, '/' );
206205 if ( defined( 'Parser::MARKER_SUFFIX' ) ) {
@@ -224,7 +223,7 @@
225224 * Note: If the needle is not found, empty string is returned.
226225 * Note: The needle is limited to specific length.
227226 */
228 - function runPos( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
 227+ static function runPos( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
229228 global $wgStringFunctionsLimitSearch;
230229
231230 if ( $inNeedle === '' ) {
@@ -233,7 +232,7 @@
234233 $nSize = 1;
235234 } else {
236235 # convert needle
237 - $nSize = $this->mwSplit( $parser, $inNeedle, $needle );
 236+ $nSize = self::mwSplit( $parser, $inNeedle, $needle );
238237
239238 if ( $nSize > $wgStringFunctionsLimitSearch ) {
240239 $nSize = $wgStringFunctionsLimitSearch;
@@ -242,7 +241,7 @@
243242 }
244243
245244 # convert string
246 - $size = $this->mwSplit( $parser, $inStr, $chars ) - $nSize;
 245+ $size = self::mwSplit( $parser, $inStr, $chars ) - $nSize;
247246 $inOffset = max( intval( $inOffset ), 0 );
248247
249248 # find needle
@@ -270,7 +269,7 @@
271270 * Note: If the needle is not found, -1 is returned.
272271 * Note: The needle is limited to specific length.
273272 */
274 - function runRPos( &$parser, $inStr = '', $inNeedle = '' ) {
 273+ static function runRPos( &$parser, $inStr = '', $inNeedle = '' ) {
275274 global $wgStringFunctionsLimitSearch;
276275
277276 if ( $inNeedle === '' ) {
@@ -279,7 +278,7 @@
280279 $nSize = 1;
281280 } else {
282281 # convert needle
283 - $nSize = $this->mwSplit( $parser, $inNeedle, $needle );
 282+ $nSize = self::mwSplit( $parser, $inNeedle, $needle );
284283
285284 if ( $nSize > $wgStringFunctionsLimitSearch ) {
286285 $nSize = $wgStringFunctionsLimitSearch;
@@ -288,7 +287,7 @@
289288 }
290289
291290 # convert string
292 - $size = $this->mwSplit( $parser, $inStr, $chars ) - $nSize;
 291+ $size = self::mwSplit( $parser, $inStr, $chars ) - $nSize;
293292
294293 # find needle
295294 for ( $i = $size; $i >= 0; $i-- ) {
@@ -313,9 +312,9 @@
314313 * {{#sub:value|start|length}}
315314 * Note: If length is zero, the rest of the input is returned.
316315 */
317 - function runSub( &$parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
 316+ static function runSub( &$parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
318317 # convert string
319 - $this->mwSplit( $parser, $inStr, $chars );
 318+ self::mwSplit( $parser, $inStr, $chars );
320319
321320 # zero length
322321 if ( intval( $inLength ) == 0 ) {
@@ -330,7 +329,7 @@
331330 * {{#pad:value|length|with|direction}}
332331 * Note: Length of the resulting string is limited.
333332 */
334 - function runPad( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) {
 333+ static function runPad( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) {
335334 global $wgStringFunctionsLimitPad;
336335
337336 # direction
@@ -362,7 +361,7 @@
363362 }
364363
365364 # adjust for multibyte strings
366 - $inLen += strlen( $inStr ) - $this->mwSplit( $parser, $inStr, $a );
 365+ $inLen += strlen( $inStr ) - self::mwSplit( $parser, $inStr, $a );
367366
368367 # pad
369368 return str_pad( $inStr, $inLen, $inWith, $direction );
@@ -374,7 +373,7 @@
375374 * Note: The needle is limited to specific length.
376375 * Note: The product is limited to specific length.
377376 */
378 - function runReplace( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) {
 377+ static function runReplace( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) {
379378 global $wgStringFunctionsLimitSearch, $wgStringFunctionsLimitReplace;
380379
381380 if ( $inReplaceFrom === '' ) {
@@ -383,7 +382,7 @@
384383 $nSize = 1;
385384 } else {
386385 # convert needle
387 - $nSize = $this->mwSplit( $parser, $inReplaceFrom, $needle );
 386+ $nSize = self::mwSplit( $parser, $inReplaceFrom, $needle );
388387 if ( $nSize > $wgStringFunctionsLimitSearch ) {
389388 $nSize = $wgStringFunctionsLimitSearch;
390389 $needle = array_slice( $needle, 0, $nSize );
@@ -391,7 +390,7 @@
392391 }
393392
394393 # convert product
395 - $pSize = $this->mwSplit( $parser, $inReplaceTo, $product );
 394+ $pSize = self::mwSplit( $parser, $inReplaceTo, $product );
396395 if ( $pSize > $wgStringFunctionsLimitReplace ) {
397396 $pSize = $wgStringFunctionsLimitReplace;
398397 $product = array_slice( $product, 0, $pSize );
@@ -405,7 +404,7 @@
406405 }
407406
408407 # convert string
409 - $size = $this->mwSplit( $parser, $inStr, $chars ) - $nSize;
 408+ $size = self::mwSplit( $parser, $inStr, $chars ) - $nSize;
410409
411410 # replace
412411 for ( $i = 0; $i <= $size; $i++ ) {
@@ -434,7 +433,7 @@
435434 * Note: The divider is limited to specific length.
436435 * Note: Empty string is returned, if there is not enough exploded chunks.
437436 */
438 - function runExplode( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) {
 437+ static function runExplode( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) {
439438 global $wgStringFunctionsLimitSearch;
440439
441440 if ( $inDiv === '' ) {
@@ -443,7 +442,7 @@
444443 $dSize = 1;
445444 } else {
446445 # convert divider
447 - $dSize = $this->mwSplit( $parser, $inDiv, $div );
 446+ $dSize = self::mwSplit( $parser, $inDiv, $div );
448447 if ( $dSize > $wgStringFunctionsLimitSearch ) {
449448 $dSize = $wgStringFunctionsLimitSearch;
450449 $div = array_slice ( $div, 0, $dSize );
@@ -451,7 +450,7 @@
452451 }
453452
454453 # convert string
455 - $size = $this->mwSplit( $parser, $inStr, $chars ) - $dSize;
 454+ $size = self::mwSplit( $parser, $inStr, $chars ) - $dSize;
456455
457456 # explode
458457 $inPos = intval( $inPos );
@@ -499,7 +498,7 @@
500499 /**
501500 * {{#urlencode:value}}
502501 */
503 - function runUrlEncode( &$parser, $inStr = '' ) {
 502+ static function runUrlEncode( &$parser, $inStr = '' ) {
504503 # encode
505504 return urlencode( $inStr );
506505 }
@@ -507,7 +506,7 @@
508507 /**
509508 * {{#urldecode:value}}
510509 */
511 - function runUrlDecode( &$parser, $inStr = '' ) {
 510+ static function runUrlDecode( &$parser, $inStr = '' ) {
512511 # decode
513512 return urldecode( $inStr );
514513 }

Status & tagging log