Index: trunk/extensions/StringFunctions/StringFunctions.php |
— | — | @@ -117,25 +117,24 @@ |
118 | 118 | $wgHooks['LanguageGetMagic'][] = 'wfStringFunctionsLanguageGetMagic'; |
119 | 119 | |
120 | 120 | function wfStringFunctions() { |
121 | | - global $wgParser, $wgExtStringFunctions; |
| 121 | + global $wgParser; |
122 | 122 | global $wgStringFunctionsLimitSearch; |
123 | 123 | global $wgStringFunctionsLimitReplace; |
124 | 124 | global $wgStringFunctionsLimitPad; |
125 | 125 | |
126 | | - $wgExtStringFunctions = new ExtStringFunctions(); |
127 | 126 | $wgStringFunctionsLimitSearch = 30; |
128 | 127 | $wgStringFunctionsLimitReplace = 30; |
129 | 128 | $wgStringFunctionsLimitPad = 100; |
130 | 129 | |
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' ) ); |
140 | 139 | } |
141 | 140 | |
142 | 141 | function wfStringFunctionsLanguageGetMagic( &$magicWords, $langCode = 'en' ) { |
— | — | @@ -160,7 +159,7 @@ |
161 | 160 | * Returns part of the perl regexp pattern that matches a marker. |
162 | 161 | * Unfortunatelly, we are still backward-supporting old versions. |
163 | 162 | */ |
164 | | - function mwMarkerRE( &$parser ) { |
| 163 | + static protected function mwMarkerRE( &$parser ) { |
165 | 164 | if ( defined( 'Parser::MARKER_SUFFIX' ) ) { |
166 | 165 | $suffix = preg_quote( Parser::MARKER_SUFFIX, '/' ); |
167 | 166 | } elseif ( isset( $parser->mMarkerSuffix ) ) { |
— | — | @@ -179,11 +178,11 @@ |
180 | 179 | * |
181 | 180 | * Main idea: Count multibytes. Find markers. Substract. |
182 | 181 | */ |
183 | | - function runLen( &$parser, $inStr = '' ) { |
| 182 | + static function runLen( &$parser, $inStr = '' ) { |
184 | 183 | $len = mb_strlen( (string)$inStr ); |
185 | 184 | |
186 | 185 | $count = preg_match_all ( |
187 | | - '/' . $this->mwMarkerRE( $parser ) . '/', |
| 186 | + '/' . self::mwMarkerRE( $parser ) . '/', |
188 | 187 | (string) $inStr, $matches |
189 | 188 | ); |
190 | 189 | |
— | — | @@ -199,7 +198,7 @@ |
200 | 199 | * $chars is set to the resulting array of multibyte characters. |
201 | 200 | * Returns count($chars). |
202 | 201 | */ |
203 | | - function mwSplit( &$parser, $str, &$chars ) { |
| 202 | + static protected function mwSplit( &$parser, $str, &$chars ) { |
204 | 203 | # Get marker prefix & suffix |
205 | 204 | $prefix = preg_quote( $parser->mUniqPrefix, '/' ); |
206 | 205 | if ( defined( 'Parser::MARKER_SUFFIX' ) ) { |
— | — | @@ -224,7 +223,7 @@ |
225 | 224 | * Note: If the needle is not found, empty string is returned. |
226 | 225 | * Note: The needle is limited to specific length. |
227 | 226 | */ |
228 | | - function runPos( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
| 227 | + static function runPos( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
229 | 228 | global $wgStringFunctionsLimitSearch; |
230 | 229 | |
231 | 230 | if ( $inNeedle === '' ) { |
— | — | @@ -233,7 +232,7 @@ |
234 | 233 | $nSize = 1; |
235 | 234 | } else { |
236 | 235 | # convert needle |
237 | | - $nSize = $this->mwSplit( $parser, $inNeedle, $needle ); |
| 236 | + $nSize = self::mwSplit( $parser, $inNeedle, $needle ); |
238 | 237 | |
239 | 238 | if ( $nSize > $wgStringFunctionsLimitSearch ) { |
240 | 239 | $nSize = $wgStringFunctionsLimitSearch; |
— | — | @@ -242,7 +241,7 @@ |
243 | 242 | } |
244 | 243 | |
245 | 244 | # convert string |
246 | | - $size = $this->mwSplit( $parser, $inStr, $chars ) - $nSize; |
| 245 | + $size = self::mwSplit( $parser, $inStr, $chars ) - $nSize; |
247 | 246 | $inOffset = max( intval( $inOffset ), 0 ); |
248 | 247 | |
249 | 248 | # find needle |
— | — | @@ -270,7 +269,7 @@ |
271 | 270 | * Note: If the needle is not found, -1 is returned. |
272 | 271 | * Note: The needle is limited to specific length. |
273 | 272 | */ |
274 | | - function runRPos( &$parser, $inStr = '', $inNeedle = '' ) { |
| 273 | + static function runRPos( &$parser, $inStr = '', $inNeedle = '' ) { |
275 | 274 | global $wgStringFunctionsLimitSearch; |
276 | 275 | |
277 | 276 | if ( $inNeedle === '' ) { |
— | — | @@ -279,7 +278,7 @@ |
280 | 279 | $nSize = 1; |
281 | 280 | } else { |
282 | 281 | # convert needle |
283 | | - $nSize = $this->mwSplit( $parser, $inNeedle, $needle ); |
| 282 | + $nSize = self::mwSplit( $parser, $inNeedle, $needle ); |
284 | 283 | |
285 | 284 | if ( $nSize > $wgStringFunctionsLimitSearch ) { |
286 | 285 | $nSize = $wgStringFunctionsLimitSearch; |
— | — | @@ -288,7 +287,7 @@ |
289 | 288 | } |
290 | 289 | |
291 | 290 | # convert string |
292 | | - $size = $this->mwSplit( $parser, $inStr, $chars ) - $nSize; |
| 291 | + $size = self::mwSplit( $parser, $inStr, $chars ) - $nSize; |
293 | 292 | |
294 | 293 | # find needle |
295 | 294 | for ( $i = $size; $i >= 0; $i-- ) { |
— | — | @@ -313,9 +312,9 @@ |
314 | 313 | * {{#sub:value|start|length}} |
315 | 314 | * Note: If length is zero, the rest of the input is returned. |
316 | 315 | */ |
317 | | - function runSub( &$parser, $inStr = '', $inStart = 0, $inLength = 0 ) { |
| 316 | + static function runSub( &$parser, $inStr = '', $inStart = 0, $inLength = 0 ) { |
318 | 317 | # convert string |
319 | | - $this->mwSplit( $parser, $inStr, $chars ); |
| 318 | + self::mwSplit( $parser, $inStr, $chars ); |
320 | 319 | |
321 | 320 | # zero length |
322 | 321 | if ( intval( $inLength ) == 0 ) { |
— | — | @@ -330,7 +329,7 @@ |
331 | 330 | * {{#pad:value|length|with|direction}} |
332 | 331 | * Note: Length of the resulting string is limited. |
333 | 332 | */ |
334 | | - function runPad( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) { |
| 333 | + static function runPad( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) { |
335 | 334 | global $wgStringFunctionsLimitPad; |
336 | 335 | |
337 | 336 | # direction |
— | — | @@ -362,7 +361,7 @@ |
363 | 362 | } |
364 | 363 | |
365 | 364 | # adjust for multibyte strings |
366 | | - $inLen += strlen( $inStr ) - $this->mwSplit( $parser, $inStr, $a ); |
| 365 | + $inLen += strlen( $inStr ) - self::mwSplit( $parser, $inStr, $a ); |
367 | 366 | |
368 | 367 | # pad |
369 | 368 | return str_pad( $inStr, $inLen, $inWith, $direction ); |
— | — | @@ -374,7 +373,7 @@ |
375 | 374 | * Note: The needle is limited to specific length. |
376 | 375 | * Note: The product is limited to specific length. |
377 | 376 | */ |
378 | | - function runReplace( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
| 377 | + static function runReplace( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
379 | 378 | global $wgStringFunctionsLimitSearch, $wgStringFunctionsLimitReplace; |
380 | 379 | |
381 | 380 | if ( $inReplaceFrom === '' ) { |
— | — | @@ -383,7 +382,7 @@ |
384 | 383 | $nSize = 1; |
385 | 384 | } else { |
386 | 385 | # convert needle |
387 | | - $nSize = $this->mwSplit( $parser, $inReplaceFrom, $needle ); |
| 386 | + $nSize = self::mwSplit( $parser, $inReplaceFrom, $needle ); |
388 | 387 | if ( $nSize > $wgStringFunctionsLimitSearch ) { |
389 | 388 | $nSize = $wgStringFunctionsLimitSearch; |
390 | 389 | $needle = array_slice( $needle, 0, $nSize ); |
— | — | @@ -391,7 +390,7 @@ |
392 | 391 | } |
393 | 392 | |
394 | 393 | # convert product |
395 | | - $pSize = $this->mwSplit( $parser, $inReplaceTo, $product ); |
| 394 | + $pSize = self::mwSplit( $parser, $inReplaceTo, $product ); |
396 | 395 | if ( $pSize > $wgStringFunctionsLimitReplace ) { |
397 | 396 | $pSize = $wgStringFunctionsLimitReplace; |
398 | 397 | $product = array_slice( $product, 0, $pSize ); |
— | — | @@ -405,7 +404,7 @@ |
406 | 405 | } |
407 | 406 | |
408 | 407 | # convert string |
409 | | - $size = $this->mwSplit( $parser, $inStr, $chars ) - $nSize; |
| 408 | + $size = self::mwSplit( $parser, $inStr, $chars ) - $nSize; |
410 | 409 | |
411 | 410 | # replace |
412 | 411 | for ( $i = 0; $i <= $size; $i++ ) { |
— | — | @@ -434,7 +433,7 @@ |
435 | 434 | * Note: The divider is limited to specific length. |
436 | 435 | * Note: Empty string is returned, if there is not enough exploded chunks. |
437 | 436 | */ |
438 | | - function runExplode( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
| 437 | + static function runExplode( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
439 | 438 | global $wgStringFunctionsLimitSearch; |
440 | 439 | |
441 | 440 | if ( $inDiv === '' ) { |
— | — | @@ -443,7 +442,7 @@ |
444 | 443 | $dSize = 1; |
445 | 444 | } else { |
446 | 445 | # convert divider |
447 | | - $dSize = $this->mwSplit( $parser, $inDiv, $div ); |
| 446 | + $dSize = self::mwSplit( $parser, $inDiv, $div ); |
448 | 447 | if ( $dSize > $wgStringFunctionsLimitSearch ) { |
449 | 448 | $dSize = $wgStringFunctionsLimitSearch; |
450 | 449 | $div = array_slice ( $div, 0, $dSize ); |
— | — | @@ -451,7 +450,7 @@ |
452 | 451 | } |
453 | 452 | |
454 | 453 | # convert string |
455 | | - $size = $this->mwSplit( $parser, $inStr, $chars ) - $dSize; |
| 454 | + $size = self::mwSplit( $parser, $inStr, $chars ) - $dSize; |
456 | 455 | |
457 | 456 | # explode |
458 | 457 | $inPos = intval( $inPos ); |
— | — | @@ -499,7 +498,7 @@ |
500 | 499 | /** |
501 | 500 | * {{#urlencode:value}} |
502 | 501 | */ |
503 | | - function runUrlEncode( &$parser, $inStr = '' ) { |
| 502 | + static function runUrlEncode( &$parser, $inStr = '' ) { |
504 | 503 | # encode |
505 | 504 | return urlencode( $inStr ); |
506 | 505 | } |
— | — | @@ -507,7 +506,7 @@ |
508 | 507 | /** |
509 | 508 | * {{#urldecode:value}} |
510 | 509 | */ |
511 | | - function runUrlDecode( &$parser, $inStr = '' ) { |
| 510 | + static function runUrlDecode( &$parser, $inStr = '' ) { |
512 | 511 | # decode |
513 | 512 | return urldecode( $inStr ); |
514 | 513 | } |