Index: trunk/extensions/ParserFunctions/SprintfDateCompat.php |
— | — | @@ -1,221 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -# sprintfDate support for MW<1.8 installations |
5 | | -class SprintfDateCompat { |
6 | | - |
7 | | - static function sprintfDate( $format, $ts ) { |
8 | | - global $wgContLang; |
9 | | - |
10 | | - $s = ''; |
11 | | - $raw = false; |
12 | | - $roman = false; |
13 | | - $unix = false; |
14 | | - $rawToggle = false; |
15 | | - for ( $p = 0; $p < strlen( $format ); $p++ ) { |
16 | | - $num = false; |
17 | | - $code = $format[$p]; |
18 | | - if ( $code == 'x' && $p < strlen( $format ) - 1 ) { |
19 | | - $code .= $format[++$p]; |
20 | | - } |
21 | | - |
22 | | - switch ( $code ) { |
23 | | - case 'xx': |
24 | | - $s .= 'x'; |
25 | | - break; |
26 | | - case 'xn': |
27 | | - $raw = true; |
28 | | - break; |
29 | | - case 'xN': |
30 | | - $rawToggle = !$rawToggle; |
31 | | - break; |
32 | | - case 'xr': |
33 | | - $roman = true; |
34 | | - break; |
35 | | - case 'xg': |
36 | | - $s .= $wgContLang->getMonthNameGen( substr( $ts, 4, 2 ) ); |
37 | | - break; |
38 | | - case 'd': |
39 | | - $num = substr( $ts, 6, 2 ); |
40 | | - break; |
41 | | - case 'D': |
42 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
43 | | - # Weekday abbreviations are not available in MW<1.8 |
44 | | - #$s .= $this->getWeekdayAbbreviation( date( 'w', $unix ) + 1 ); |
45 | | - $s .= date( 'D', $unix ); |
46 | | - break; |
47 | | - case 'j': |
48 | | - $num = intval( substr( $ts, 6, 2 ) ); |
49 | | - break; |
50 | | - case 'l': |
51 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
52 | | - $s .= $wgContLang->getWeekdayName( date( 'w', $unix ) + 1 ); |
53 | | - break; |
54 | | - case 'N': |
55 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
56 | | - $w = date( 'w', $unix ); |
57 | | - $num = $w ? $w : 7; |
58 | | - break; |
59 | | - case 'w': |
60 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
61 | | - $num = date( 'w', $unix ); |
62 | | - break; |
63 | | - case 'z': |
64 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
65 | | - $num = date( 'z', $unix ); |
66 | | - break; |
67 | | - case 'W': |
68 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
69 | | - $num = date( 'W', $unix ); |
70 | | - break; |
71 | | - case 'F': |
72 | | - $s .= $wgContLang->getMonthName( substr( $ts, 4, 2 ) ); |
73 | | - break; |
74 | | - case 'm': |
75 | | - $num = substr( $ts, 4, 2 ); |
76 | | - break; |
77 | | - case 'M': |
78 | | - $s .= $wgContLang->getMonthAbbreviation( substr( $ts, 4, 2 ) ); |
79 | | - break; |
80 | | - case 'n': |
81 | | - $num = intval( substr( $ts, 4, 2 ) ); |
82 | | - break; |
83 | | - case 't': |
84 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
85 | | - $num = date( 't', $unix ); |
86 | | - break; |
87 | | - case 'L': |
88 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
89 | | - $num = date( 'L', $unix ); |
90 | | - break; |
91 | | - # 'o' is supported since PHP 5.1.0 |
92 | | - # return literal if not supported |
93 | | - # TODO: emulation for pre 5.1.0 versions |
94 | | - case 'o': |
95 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
96 | | - if ( version_compare(PHP_VERSION, '5.1.0') === 1 ) |
97 | | - $num = date( 'o', $unix ); |
98 | | - else |
99 | | - $s .= 'o'; |
100 | | - break; |
101 | | - case 'Y': |
102 | | - $num = substr( $ts, 0, 4 ); |
103 | | - break; |
104 | | - case 'y': |
105 | | - $num = substr( $ts, 2, 2 ); |
106 | | - break; |
107 | | - case 'a': |
108 | | - $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'am' : 'pm'; |
109 | | - break; |
110 | | - case 'A': |
111 | | - $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'AM' : 'PM'; |
112 | | - break; |
113 | | - case 'g': |
114 | | - $h = substr( $ts, 8, 2 ); |
115 | | - $num = $h % 12 ? $h % 12 : 12; |
116 | | - break; |
117 | | - case 'G': |
118 | | - $num = intval( substr( $ts, 8, 2 ) ); |
119 | | - break; |
120 | | - case 'h': |
121 | | - $h = substr( $ts, 8, 2 ); |
122 | | - $num = sprintf( '%02d', $h % 12 ? $h % 12 : 12 ); |
123 | | - break; |
124 | | - case 'H': |
125 | | - $num = substr( $ts, 8, 2 ); |
126 | | - break; |
127 | | - case 'i': |
128 | | - $num = substr( $ts, 10, 2 ); |
129 | | - break; |
130 | | - case 's': |
131 | | - $num = substr( $ts, 12, 2 ); |
132 | | - break; |
133 | | - case 'c': |
134 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
135 | | - $s .= date( 'c', $unix ); |
136 | | - break; |
137 | | - case 'r': |
138 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
139 | | - $s .= date( 'r', $unix ); |
140 | | - break; |
141 | | - case 'U': |
142 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
143 | | - $num = $unix; |
144 | | - break; |
145 | | - case 'B': |
146 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
147 | | - $num = date( 'B', $unix ); |
148 | | - break; |
149 | | - case 'S': |
150 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
151 | | - $num = date( 'S', $unix ); |
152 | | - break; |
153 | | - |
154 | | - case '\\': |
155 | | - # Backslash escaping |
156 | | - if ( $p < strlen( $format ) - 1 ) { |
157 | | - $s .= $format[++$p]; |
158 | | - } else { |
159 | | - $s .= '\\'; |
160 | | - } |
161 | | - break; |
162 | | - case '"': |
163 | | - # Quoted literal |
164 | | - if ( $p < strlen( $format ) - 1 ) { |
165 | | - $endQuote = strpos( $format, '"', $p + 1 ); |
166 | | - if ( $endQuote === false ) { |
167 | | - # No terminating quote, assume literal " |
168 | | - $s .= '"'; |
169 | | - } else { |
170 | | - $s .= substr( $format, $p + 1, $endQuote - $p - 1 ); |
171 | | - $p = $endQuote; |
172 | | - } |
173 | | - } else { |
174 | | - # Quote at end of string, assume literal " |
175 | | - $s .= '"'; |
176 | | - } |
177 | | - break; |
178 | | - default: |
179 | | - $s .= $format[$p]; |
180 | | - } |
181 | | - if ( $num !== false ) { |
182 | | - if ( $rawToggle || $raw ) { |
183 | | - $s .= $num; |
184 | | - $raw = false; |
185 | | - } elseif ( $roman ) { |
186 | | - $s .= self::romanNumeral( $num ); |
187 | | - $roman = false; |
188 | | - } else { |
189 | | - $s .= $wgContLang->formatNum( $num, true ); |
190 | | - } |
191 | | - $num = false; |
192 | | - } |
193 | | - } |
194 | | - return $s; |
195 | | - } |
196 | | - |
197 | | - /** |
198 | | - * Roman number formatting up to 3000 |
199 | | - */ |
200 | | - static function romanNumeral( $num ) { |
201 | | - static $table = array( |
202 | | - array( '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ), |
203 | | - array( '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ), |
204 | | - array( '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ), |
205 | | - array( '', 'M', 'MM', 'MMM' ) |
206 | | - ); |
207 | | - |
208 | | - $num = intval( $num ); |
209 | | - if ( $num > 3000 || $num <= 0 ) { |
210 | | - return $num; |
211 | | - } |
212 | | - |
213 | | - $s = ''; |
214 | | - for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) { |
215 | | - if ( $num >= $pow10 ) { |
216 | | - $s .= $table[$i][floor($num / $pow10)]; |
217 | | - } |
218 | | - $num = $num % $pow10; |
219 | | - } |
220 | | - return $s; |
221 | | - } |
222 | | -} |
Index: trunk/extensions/ParserFunctions/Expr.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | define( 'EXPR_PI', 36 ); |
49 | 49 | |
50 | 50 | class ExprError extends Exception { |
51 | | - public function __construct($msg, $parameter = ''){ |
| 51 | + public function __construct( $msg, $parameter = '' ) { |
52 | 52 | wfLoadExtensionMessages( 'ParserFunctions' ); |
53 | 53 | $this->message = '<strong class="error">' . wfMsgForContent( "pfunc_expr_$msg", htmlspecialchars( $parameter ) ) . '</strong>'; |
54 | 54 | } |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | |
175 | 175 | while ( $p < $end ) { |
176 | 176 | if ( count( $operands ) > $this->maxStackSize || count( $operators ) > $this->maxStackSize ) { |
177 | | - throw new ExprError('stack_exhausted'); |
| 177 | + throw new ExprError( 'stack_exhausted' ); |
178 | 178 | } |
179 | 179 | $char = $expr[$p]; |
180 | 180 | $char2 = substr( $expr, $p, 2 ); |
— | — | @@ -191,7 +191,7 @@ |
192 | 192 | } elseif ( false !== strpos( EXPR_NUMBER_CLASS, $char ) ) { |
193 | 193 | // Number |
194 | 194 | if ( $expecting != 'expression' ) { |
195 | | - throw new ExprError('unexpected_number'); |
| 195 | + throw new ExprError( 'unexpected_number' ); |
196 | 196 | } |
197 | 197 | |
198 | 198 | // Find the rest of it |
— | — | @@ -207,14 +207,14 @@ |
208 | 208 | $remaining = substr( $expr, $p ); |
209 | 209 | if ( !preg_match( '/^[A-Za-z]*/', $remaining, $matches ) ) { |
210 | 210 | // This should be unreachable |
211 | | - throw new ExprError('preg_match_failure'); |
| 211 | + throw new ExprError( 'preg_match_failure' ); |
212 | 212 | } |
213 | 213 | $word = strtolower( $matches[0] ); |
214 | 214 | $p += strlen( $word ); |
215 | 215 | |
216 | 216 | // Interpret the word |
217 | | - if ( !isset( $this->words[$word] ) ){ |
218 | | - throw new ExprError('unrecognised_word', $word); |
| 217 | + if ( !isset( $this->words[$word] ) ) { |
| 218 | + throw new ExprError( 'unrecognised_word', $word ); |
219 | 219 | } |
220 | 220 | $op = $this->words[$word]; |
221 | 221 | switch( $op ) { |
— | — | @@ -223,7 +223,7 @@ |
224 | 224 | if ( $expecting != 'expression' ) { |
225 | 225 | continue; |
226 | 226 | } |
227 | | - $operands[] = exp(1); |
| 227 | + $operands[] = exp( 1 ); |
228 | 228 | $expecting = 'operator'; |
229 | 229 | continue 2; |
230 | 230 | case EXPR_PI: |
— | — | @@ -274,7 +274,7 @@ |
275 | 275 | } |
276 | 276 | |
277 | 277 | // Finally the single-character operators |
278 | | - |
| 278 | + |
279 | 279 | elseif ( $char == '+' ) { |
280 | 280 | ++$p; |
281 | 281 | if ( $expecting == 'expression' ) { |
— | — | @@ -309,7 +309,7 @@ |
310 | 310 | ++$p; |
311 | 311 | } elseif ( $char == '(' ) { |
312 | 312 | if ( $expecting == 'operator' ) { |
313 | | - throw new ExprError('unexpected_operator', '('); |
| 313 | + throw new ExprError( 'unexpected_operator', '(' ); |
314 | 314 | } |
315 | 315 | $operators[] = EXPR_OPEN; |
316 | 316 | ++$p; |
— | — | @@ -324,7 +324,7 @@ |
325 | 325 | if ( $lastOp ) { |
326 | 326 | array_pop( $operators ); |
327 | 327 | } else { |
328 | | - throw new ExprError('unexpected_closing_bracket'); |
| 328 | + throw new ExprError( 'unexpected_closing_bracket' ); |
329 | 329 | } |
330 | 330 | $expecting = 'operator'; |
331 | 331 | ++$p; |
— | — | @@ -342,12 +342,12 @@ |
343 | 343 | $op = EXPR_GREATER; |
344 | 344 | ++$p; |
345 | 345 | } else { |
346 | | - throw new ExprError('unrecognised_punctuation', UtfNormal::cleanUp( $char )); |
| 346 | + throw new ExprError( 'unrecognised_punctuation', UtfNormal::cleanUp( $char ) ); |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Binary operator processing |
350 | 350 | if ( $expecting == 'expression' ) { |
351 | | - throw new ExprError('unexpected_operator', $name); |
| 351 | + throw new ExprError( 'unexpected_operator', $name ); |
352 | 352 | } |
353 | 353 | |
354 | 354 | // Shunting yard magic |
— | — | @@ -364,7 +364,7 @@ |
365 | 365 | // Finish off the operator array |
366 | 366 | while ( $op = array_pop( $operators ) ) { |
367 | 367 | if ( $op == EXPR_OPEN ) { |
368 | | - throw new ExprError('unclosed_bracket'); |
| 368 | + throw new ExprError( 'unclosed_bracket' ); |
369 | 369 | } |
370 | 370 | $this->doOperation( $op, $operands ); |
371 | 371 | } |
— | — | @@ -375,182 +375,182 @@ |
376 | 376 | function doOperation( $op, &$stack ) { |
377 | 377 | switch ( $op ) { |
378 | 378 | case EXPR_NEGATIVE: |
379 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 379 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
380 | 380 | $arg = array_pop( $stack ); |
381 | 381 | $stack[] = -$arg; |
382 | 382 | break; |
383 | 383 | case EXPR_POSITIVE: |
384 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 384 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
385 | 385 | break; |
386 | 386 | case EXPR_TIMES: |
387 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 387 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
388 | 388 | $right = array_pop( $stack ); |
389 | 389 | $left = array_pop( $stack ); |
390 | 390 | $stack[] = $left * $right; |
391 | 391 | break; |
392 | 392 | case EXPR_DIVIDE: |
393 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 393 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
394 | 394 | $right = array_pop( $stack ); |
395 | 395 | $left = array_pop( $stack ); |
396 | | - if ( $right == 0 ) throw new ExprError('division_by_zero', $this->names[$op]); |
| 396 | + if ( $right == 0 ) throw new ExprError( 'division_by_zero', $this->names[$op] ); |
397 | 397 | $stack[] = $left / $right; |
398 | 398 | break; |
399 | 399 | case EXPR_MOD: |
400 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 400 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
401 | 401 | $right = array_pop( $stack ); |
402 | 402 | $left = array_pop( $stack ); |
403 | | - if ( $right == 0 ) throw new ExprError('division_by_zero', $this->names[$op]); |
| 403 | + if ( $right == 0 ) throw new ExprError( 'division_by_zero', $this->names[$op] ); |
404 | 404 | $stack[] = $left % $right; |
405 | 405 | break; |
406 | 406 | case EXPR_PLUS: |
407 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 407 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
408 | 408 | $right = array_pop( $stack ); |
409 | 409 | $left = array_pop( $stack ); |
410 | 410 | $stack[] = $left + $right; |
411 | 411 | break; |
412 | 412 | case EXPR_MINUS: |
413 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 413 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
414 | 414 | $right = array_pop( $stack ); |
415 | 415 | $left = array_pop( $stack ); |
416 | 416 | $stack[] = $left - $right; |
417 | 417 | break; |
418 | 418 | case EXPR_AND: |
419 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 419 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
420 | 420 | $right = array_pop( $stack ); |
421 | 421 | $left = array_pop( $stack ); |
422 | 422 | $stack[] = ( $left && $right ) ? 1 : 0; |
423 | 423 | break; |
424 | 424 | case EXPR_OR: |
425 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 425 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
426 | 426 | $right = array_pop( $stack ); |
427 | 427 | $left = array_pop( $stack ); |
428 | 428 | $stack[] = ( $left || $right ) ? 1 : 0; |
429 | 429 | break; |
430 | 430 | case EXPR_EQUALITY: |
431 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 431 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
432 | 432 | $right = array_pop( $stack ); |
433 | 433 | $left = array_pop( $stack ); |
434 | 434 | $stack[] = ( $left == $right ) ? 1 : 0; |
435 | 435 | break; |
436 | 436 | case EXPR_NOT: |
437 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 437 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
438 | 438 | $arg = array_pop( $stack ); |
439 | | - $stack[] = (!$arg) ? 1 : 0; |
| 439 | + $stack[] = ( !$arg ) ? 1 : 0; |
440 | 440 | break; |
441 | 441 | case EXPR_ROUND: |
442 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 442 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
443 | 443 | $digits = intval( array_pop( $stack ) ); |
444 | 444 | $value = array_pop( $stack ); |
445 | 445 | $stack[] = round( $value, $digits ); |
446 | 446 | break; |
447 | 447 | case EXPR_LESS: |
448 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 448 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
449 | 449 | $right = array_pop( $stack ); |
450 | 450 | $left = array_pop( $stack ); |
451 | 451 | $stack[] = ( $left < $right ) ? 1 : 0; |
452 | 452 | break; |
453 | 453 | case EXPR_GREATER: |
454 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 454 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
455 | 455 | $right = array_pop( $stack ); |
456 | 456 | $left = array_pop( $stack ); |
457 | 457 | $stack[] = ( $left > $right ) ? 1 : 0; |
458 | 458 | break; |
459 | 459 | case EXPR_LESSEQ: |
460 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 460 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
461 | 461 | $right = array_pop( $stack ); |
462 | 462 | $left = array_pop( $stack ); |
463 | 463 | $stack[] = ( $left <= $right ) ? 1 : 0; |
464 | 464 | break; |
465 | 465 | case EXPR_GREATEREQ: |
466 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 466 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
467 | 467 | $right = array_pop( $stack ); |
468 | 468 | $left = array_pop( $stack ); |
469 | 469 | $stack[] = ( $left >= $right ) ? 1 : 0; |
470 | 470 | break; |
471 | 471 | case EXPR_NOTEQ: |
472 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 472 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
473 | 473 | $right = array_pop( $stack ); |
474 | 474 | $left = array_pop( $stack ); |
475 | 475 | $stack[] = ( $left != $right ) ? 1 : 0; |
476 | 476 | break; |
477 | 477 | case EXPR_EXPONENT: |
478 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 478 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
479 | 479 | $right = array_pop( $stack ); |
480 | 480 | $left = array_pop( $stack ); |
481 | | - $stack[] = $left * pow(10,$right); |
| 481 | + $stack[] = $left * pow( 10, $right ); |
482 | 482 | break; |
483 | 483 | case EXPR_SINE: |
484 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 484 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
485 | 485 | $arg = array_pop( $stack ); |
486 | | - $stack[] = sin($arg); |
| 486 | + $stack[] = sin( $arg ); |
487 | 487 | break; |
488 | 488 | case EXPR_COSINE: |
489 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 489 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
490 | 490 | $arg = array_pop( $stack ); |
491 | | - $stack[] = cos($arg); |
| 491 | + $stack[] = cos( $arg ); |
492 | 492 | break; |
493 | 493 | case EXPR_TANGENS: |
494 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 494 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
495 | 495 | $arg = array_pop( $stack ); |
496 | | - $stack[] = tan($arg); |
| 496 | + $stack[] = tan( $arg ); |
497 | 497 | break; |
498 | 498 | case EXPR_ARCSINE: |
499 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 499 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
500 | 500 | $arg = array_pop( $stack ); |
501 | | - if ( $arg < -1 || $arg > 1 ) throw new ExprError('invalid_argument', $this->names[$op] ); |
502 | | - $stack[] = asin($arg); |
| 501 | + if ( $arg < -1 || $arg > 1 ) throw new ExprError( 'invalid_argument', $this->names[$op] ); |
| 502 | + $stack[] = asin( $arg ); |
503 | 503 | break; |
504 | 504 | case EXPR_ARCCOS: |
505 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 505 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
506 | 506 | $arg = array_pop( $stack ); |
507 | | - if ( $arg < -1 || $arg > 1 ) throw new ExprError('invalid_argument', $this->names[$op] ); |
508 | | - $stack[] = acos($arg); |
| 507 | + if ( $arg < -1 || $arg > 1 ) throw new ExprError( 'invalid_argument', $this->names[$op] ); |
| 508 | + $stack[] = acos( $arg ); |
509 | 509 | break; |
510 | 510 | case EXPR_ARCTAN: |
511 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 511 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
512 | 512 | $arg = array_pop( $stack ); |
513 | | - $stack[] = atan($arg); |
| 513 | + $stack[] = atan( $arg ); |
514 | 514 | break; |
515 | 515 | case EXPR_EXP: |
516 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 516 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
517 | 517 | $arg = array_pop( $stack ); |
518 | | - $stack[] = exp($arg); |
| 518 | + $stack[] = exp( $arg ); |
519 | 519 | break; |
520 | 520 | case EXPR_LN: |
521 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 521 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
522 | 522 | $arg = array_pop( $stack ); |
523 | | - if ( $arg <= 0 ) throw new ExprError('invalid_argument_ln', $this->names[$op]); |
524 | | - $stack[] = log($arg); |
| 523 | + if ( $arg <= 0 ) throw new ExprError( 'invalid_argument_ln', $this->names[$op] ); |
| 524 | + $stack[] = log( $arg ); |
525 | 525 | break; |
526 | 526 | case EXPR_ABS: |
527 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 527 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
528 | 528 | $arg = array_pop( $stack ); |
529 | | - $stack[] = abs($arg); |
| 529 | + $stack[] = abs( $arg ); |
530 | 530 | break; |
531 | 531 | case EXPR_FLOOR: |
532 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 532 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
533 | 533 | $arg = array_pop( $stack ); |
534 | | - $stack[] = floor($arg); |
| 534 | + $stack[] = floor( $arg ); |
535 | 535 | break; |
536 | 536 | case EXPR_TRUNC: |
537 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 537 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
538 | 538 | $arg = array_pop( $stack ); |
539 | 539 | $stack[] = (int)$arg; |
540 | 540 | break; |
541 | 541 | case EXPR_CEIL: |
542 | | - if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 542 | + if ( count( $stack ) < 1 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
543 | 543 | $arg = array_pop( $stack ); |
544 | | - $stack[] = ceil($arg); |
| 544 | + $stack[] = ceil( $arg ); |
545 | 545 | break; |
546 | 546 | case EXPR_POW: |
547 | | - if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 547 | + if ( count( $stack ) < 2 ) throw new ExprError( 'missing_operand', $this->names[$op] ); |
548 | 548 | $right = array_pop( $stack ); |
549 | 549 | $left = array_pop( $stack ); |
550 | | - if ( false === ($stack[] = pow($left, $right)) ) throw new ExprError('division_by_zero', $this->names[$op]); |
| 550 | + if ( false === ( $stack[] = pow( $left, $right ) ) ) throw new ExprError( 'division_by_zero', $this->names[$op] ); |
551 | 551 | break; |
552 | 552 | default: |
553 | 553 | // Should be impossible to reach here. |
554 | | - throw new ExprError('unknown_error'); |
| 554 | + throw new ExprError( 'unknown_error' ); |
555 | 555 | } |
556 | 556 | } |
557 | 557 | } |
Index: trunk/extensions/ParserFunctions/testExpr.php |
— | — | @@ -1,30 +1,30 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once ( getenv('MW_INSTALL_PATH') !== false |
5 | | - ? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc" |
| 4 | +require_once ( getenv( 'MW_INSTALL_PATH' ) !== false |
| 5 | + ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" |
6 | 6 | : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' ); |
7 | 7 | require( 'Expr.php' ); |
8 | | - |
| 8 | + |
9 | 9 | $tests = file( 'exprTests.txt' ); |
10 | 10 | |
11 | 11 | $pass = $fail = 0; |
12 | 12 | |
13 | 13 | // Each test is on one line. The test must always evaluate to '1'. |
14 | 14 | $parser = new ExprParser; |
15 | | -foreach( $tests as $test ) { |
16 | | - $test = trim($test); |
| 15 | +foreach ( $tests as $test ) { |
| 16 | + $test = trim( $test ); |
17 | 17 | if ( in_string( ';', $test ) ) |
18 | | - list($input,$expected) = explode(';', $test); |
| 18 | + list( $input, $expected ) = explode( ';', $test ); |
19 | 19 | else { |
20 | 20 | $input = $test; |
21 | 21 | $expected = 1; |
22 | 22 | } |
23 | | - |
24 | | - $expected = trim($expected); |
25 | | - $input = trim($input); |
26 | 23 | |
| 24 | + $expected = trim( $expected ); |
| 25 | + $input = trim( $input ); |
| 26 | + |
27 | 27 | $result = $parser->doExpression( $input ); |
28 | | - if ($result != $expected) { |
| 28 | + if ( $result != $expected ) { |
29 | 29 | print |
30 | 30 | "FAILING test -- $input |
31 | 31 | gave a final result of $result, instead of $expected.\n"; |
— | — | @@ -35,4 +35,4 @@ |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | | -print "Passed $pass tests, failed $fail tests, out of a total of ".($pass+$fail)."\n"; |
\ No newline at end of file |
| 39 | +print "Passed $pass tests, failed $fail tests, out of a total of " . ( $pass + $fail ) . "\n"; |
\ No newline at end of file |
Index: trunk/extensions/ParserFunctions/COPYING |
— | — | @@ -1,4 +1,4 @@ |
2 | | -The ParserFunctions extension may be copied and redistributed under the GNU |
| 2 | +The ParserFunctions extension may be copied and redistributed under the GNU |
3 | 3 | General Public License. |
4 | 4 | |
5 | 5 | ------------------------------------------------------------------------------- |
— | — | @@ -281,4 +281,3 @@ |
282 | 282 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
283 | 283 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
284 | 284 | POSSIBILITY OF SUCH DAMAGES. |
285 | | - |
Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | var $mTimeChars = 0; |
8 | 8 | var $mMaxTimeChars = 6000; # ~10 seconds |
9 | 9 | |
10 | | - function clearState( $parser) { |
| 10 | + function clearState( $parser ) { |
11 | 11 | $this->mTimeChars = 0; |
12 | 12 | $parser->pf_ifexist_breakdown = array(); |
13 | 13 | $parser->pf_markerRegex = null; |
— | — | @@ -27,17 +27,17 @@ |
28 | 28 | |
29 | 29 | // The first line represents Parser from release 1.12 forward. |
30 | 30 | // subsequent lines are hacks to accomodate old Mediawiki versions. |
31 | | - if ( defined('Parser::MARKER_SUFFIX') ) |
| 31 | + if ( defined( 'Parser::MARKER_SUFFIX' ) ) |
32 | 32 | $suffix = preg_quote( Parser::MARKER_SUFFIX, '/' ); |
33 | | - elseif ( isset($parser->mMarkerSuffix) ) |
| 33 | + elseif ( isset( $parser->mMarkerSuffix ) ) |
34 | 34 | $suffix = preg_quote( $parser->mMarkerSuffix, '/' ); |
35 | | - elseif ( defined('MW_PARSER_VERSION') && |
| 35 | + elseif ( defined( 'MW_PARSER_VERSION' ) && |
36 | 36 | strcmp( MW_PARSER_VERSION, '1.6.1' ) > 0 ) |
37 | 37 | $suffix = "QINU\x07"; |
38 | 38 | else $suffix = 'QINU'; |
39 | | - |
40 | | - $parser->pf_markerRegex = '/' .$prefix. '(?:(?!' .$suffix. ').)*' . $suffix . '/us'; |
41 | 39 | |
| 40 | + $parser->pf_markerRegex = '/' . $prefix . '(?:(?!' . $suffix . ').)*' . $suffix . '/us'; |
| 41 | + |
42 | 42 | wfProfileOut( __METHOD__ ); |
43 | 43 | return $parser->pf_markerRegex; |
44 | 44 | } |
— | — | @@ -60,23 +60,23 @@ |
61 | 61 | function expr( $parser, $expr = '' ) { |
62 | 62 | try { |
63 | 63 | return $this->getExprParser()->doExpression( $expr ); |
64 | | - } catch(ExprError $e) { |
| 64 | + } catch ( ExprError $e ) { |
65 | 65 | return $e->getMessage(); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | 69 | function ifexpr( $parser, $expr = '', $then = '', $else = '' ) { |
70 | | - try{ |
| 70 | + try { |
71 | 71 | $ret = $this->getExprParser()->doExpression( $expr ); |
72 | 72 | if ( is_numeric( $ret ) ) { |
73 | 73 | $ret = floatval( $ret ); |
74 | 74 | } |
75 | | - if( $ret ) { |
| 75 | + if ( $ret ) { |
76 | 76 | return $then; |
77 | 77 | } else { |
78 | 78 | return $else; |
79 | 79 | } |
80 | | - } catch (ExprError $e){ |
| 80 | + } catch ( ExprError $e ) { |
81 | 81 | return $e->getMessage(); |
82 | 82 | } |
83 | 83 | } |
— | — | @@ -152,12 +152,12 @@ |
153 | 153 | function switchHook( $parser /*,...*/ ) { |
154 | 154 | $args = func_get_args(); |
155 | 155 | array_shift( $args ); |
156 | | - $primary = trim(array_shift($args)); |
| 156 | + $primary = trim( array_shift( $args ) ); |
157 | 157 | $found = $defaultFound = false; |
158 | 158 | $parts = null; |
159 | 159 | $default = null; |
160 | 160 | $mwDefault =& MagicWord::get( 'default' ); |
161 | | - foreach( $args as $arg ) { |
| 161 | + foreach ( $args as $arg ) { |
162 | 162 | $parts = array_map( 'trim', explode( '=', $arg, 2 ) ); |
163 | 163 | if ( count( $parts ) == 2 ) { |
164 | 164 | # Found "=" |
— | — | @@ -179,7 +179,7 @@ |
180 | 180 | } |
181 | 181 | # Default case |
182 | 182 | # Check if the last item had no = sign, thus specifying the default case |
183 | | - if ( count( $parts ) == 1) { |
| 183 | + if ( count( $parts ) == 1 ) { |
184 | 184 | return $parts[0]; |
185 | 185 | } elseif ( !is_null( $default ) ) { |
186 | 186 | return $default; |
— | — | @@ -250,22 +250,22 @@ |
251 | 251 | */ |
252 | 252 | public function rel2abs( $parser , $to = '' , $from = '' ) { |
253 | 253 | |
254 | | - $from = trim($from); |
255 | | - if( $from == '' ) { |
| 254 | + $from = trim( $from ); |
| 255 | + if ( $from == '' ) { |
256 | 256 | $from = $parser->getTitle()->getPrefixedText(); |
257 | 257 | } |
258 | 258 | |
259 | 259 | $to = rtrim( $to , ' /' ); |
260 | 260 | |
261 | 261 | // if we have an empty path, or just one containing a dot |
262 | | - if( $to == '' || $to == '.' ) { |
| 262 | + if ( $to == '' || $to == '.' ) { |
263 | 263 | return $from; |
264 | 264 | } |
265 | 265 | |
266 | 266 | // if the path isn't relative |
267 | | - if ( substr( $to , 0 , 1) != '/' && |
268 | | - substr( $to , 0 , 2) != './' && |
269 | | - substr( $to , 0 , 3) != '../' && |
| 267 | + if ( substr( $to , 0 , 1 ) != '/' && |
| 268 | + substr( $to , 0 , 2 ) != './' && |
| 269 | + substr( $to , 0 , 3 ) != '../' && |
270 | 270 | $to != '..' ) |
271 | 271 | { |
272 | 272 | $from = ''; |
— | — | @@ -285,8 +285,8 @@ |
286 | 286 | $newExploded = array(); |
287 | 287 | |
288 | 288 | foreach ( $exploded as $current ) { |
289 | | - if( $current == '..' ) { // removing one level |
290 | | - if( !count( $newExploded ) ){ |
| 289 | + if ( $current == '..' ) { // removing one level |
| 290 | + if ( !count( $newExploded ) ) { |
291 | 291 | // attempted to access a node above root node |
292 | 292 | wfLoadExtensionMessages( 'ParserFunctions' ); |
293 | 293 | return '<strong class="error">' . wfMsgForContent( 'pfunc_rel2abs_invalid_depth', $fullPath ) . '</strong>'; |
— | — | @@ -326,26 +326,26 @@ |
327 | 327 | $title = Title::newFromText( $titletext ); |
328 | 328 | $wgContLang->findVariantLink( $titletext, $title, true ); |
329 | 329 | if ( $title ) { |
330 | | - if( $title->getNamespace() == NS_MEDIA ) { |
| 330 | + if ( $title->getNamespace() == NS_MEDIA ) { |
331 | 331 | /* If namespace is specified as NS_MEDIA, then we want to |
332 | 332 | * check the physical file, not the "description" page. |
333 | 333 | */ |
334 | 334 | if ( !$this->incrementIfexistCount( $parser, $frame ) ) { |
335 | 335 | return $else; |
336 | 336 | } |
337 | | - $file = wfFindFile($title); |
| 337 | + $file = wfFindFile( $title ); |
338 | 338 | if ( !$file ) { |
339 | 339 | return $else; |
340 | 340 | } |
341 | | - $parser->mOutput->addImage($file->getName()); |
| 341 | + $parser->mOutput->addImage( $file->getName() ); |
342 | 342 | return $file->exists() ? $then : $else; |
343 | | - } elseif( $title->getNamespace() == NS_SPECIAL ) { |
| 343 | + } elseif ( $title->getNamespace() == NS_SPECIAL ) { |
344 | 344 | /* Don't bother with the count for special pages, |
345 | 345 | * since their existence can be checked without |
346 | 346 | * accessing the database. |
347 | 347 | */ |
348 | 348 | return SpecialPage::exists( $title->getDBkey() ) ? $then : $else; |
349 | | - } elseif( $title->isExternal() ) { |
| 349 | + } elseif ( $title->isExternal() ) { |
350 | 350 | /* Can't check the existence of pages on other sites, |
351 | 351 | * so just return $else. Makes a sort of sense, since |
352 | 352 | * they don't exist _locally_. |
— | — | @@ -392,16 +392,16 @@ |
393 | 393 | if ( isset( $this->mTimeCache[$format][$date][$local] ) ) { |
394 | 394 | return $this->mTimeCache[$format][$date][$local]; |
395 | 395 | } |
396 | | - |
397 | | - #compute the timestamp string $ts |
398 | | - #PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object |
399 | | - #PHP < 5.2 is limited to dates between 1970 and 2038 |
400 | | - |
| 396 | + |
| 397 | + # compute the timestamp string $ts |
| 398 | + # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object |
| 399 | + # PHP < 5.2 is limited to dates between 1970 and 2038 |
| 400 | + |
401 | 401 | $invalidTime = false; |
402 | | - |
403 | | - if ( class_exists( 'DateTime' ) ) { #PHP >= 5.2 |
404 | | - # the DateTime constructor must be used because it throws exceptions |
405 | | - # when errors occur, whereas date_create appears to just output a warning |
| 402 | + |
| 403 | + if ( class_exists( 'DateTime' ) ) { # PHP >= 5.2 |
| 404 | + # the DateTime constructor must be used because it throws exceptions |
| 405 | + # when errors occur, whereas date_create appears to just output a warning |
406 | 406 | # that can't really be detected from within the code |
407 | 407 | try { |
408 | 408 | # Determine timezone |
— | — | @@ -427,16 +427,16 @@ |
428 | 428 | |
429 | 429 | # Generate timestamp |
430 | 430 | $ts = $dateObject->format( 'YmdHis' ); |
431 | | - } catch (Exception $ex) { |
| 431 | + } catch ( Exception $ex ) { |
432 | 432 | $invalidTime = true; |
433 | 433 | } |
434 | | - } else { #PHP < 5.2 |
| 434 | + } else { # PHP < 5.2 |
435 | 435 | if ( $date !== '' ) { |
436 | 436 | $unix = @strtotime( $date ); |
437 | 437 | } else { |
438 | 438 | $unix = time(); |
439 | 439 | } |
440 | | - |
| 440 | + |
441 | 441 | if ( $unix == -1 || $unix == false ) { |
442 | 442 | $invalidTime = true; |
443 | 443 | } else { |
— | — | @@ -444,21 +444,21 @@ |
445 | 445 | # Use the time zone |
446 | 446 | if ( isset( $wgLocaltimezone ) ) { |
447 | 447 | $oldtz = getenv( 'TZ' ); |
448 | | - putenv( 'TZ='.$wgLocaltimezone ); |
| 448 | + putenv( 'TZ=' . $wgLocaltimezone ); |
449 | 449 | } |
450 | 450 | wfSuppressWarnings(); // E_STRICT system time bitching |
451 | 451 | $ts = date( 'YmdHis', $unix ); |
452 | 452 | wfRestoreWarnings(); |
453 | 453 | if ( isset( $wgLocaltimezone ) ) { |
454 | | - putenv( 'TZ='.$oldtz ); |
| 454 | + putenv( 'TZ=' . $oldtz ); |
455 | 455 | } |
456 | 456 | } else { |
457 | 457 | $ts = wfTimestamp( TS_MW, $unix ); |
458 | 458 | } |
459 | 459 | } |
460 | 460 | } |
461 | | - |
462 | | - #format the timestamp and return the result |
| 461 | + |
| 462 | + # format the timestamp and return the result |
463 | 463 | if ( $invalidTime ) { |
464 | 464 | wfLoadExtensionMessages( 'ParserFunctions' ); |
465 | 465 | $result = '<strong class="error">' . wfMsgForContent( 'pfunc_time_error' ) . '</strong>'; |
— | — | @@ -468,16 +468,7 @@ |
469 | 469 | wfLoadExtensionMessages( 'ParserFunctions' ); |
470 | 470 | return '<strong class="error">' . wfMsgForContent( 'pfunc_time_too_long' ) . '</strong>'; |
471 | 471 | } else { |
472 | | - |
473 | | - if ( method_exists( $wgContLang, 'sprintfDate' ) ) { |
474 | | - $result = $wgContLang->sprintfDate( $format, $ts ); |
475 | | - } else { |
476 | | - if ( !class_exists( 'SprintfDateCompat' ) ) { |
477 | | - require( dirname( __FILE__ ) . '/SprintfDateCompat.php' ); |
478 | | - } |
479 | | - |
480 | | - $result = SprintfDateCompat::sprintfDate( $format, $ts ); |
481 | | - } |
| 472 | + $result = $wgContLang->sprintfDate( $format, $ts ); |
482 | 473 | } |
483 | 474 | } |
484 | 475 | $this->mTimeCache[$format][$date][$local] = $result; |
— | — | @@ -498,7 +489,7 @@ |
499 | 490 | * @param int $offset Offset starting at 1 |
500 | 491 | * @return string |
501 | 492 | */ |
502 | | - public function titleparts( $parser, $title = '', $parts = 0, $offset = 0) { |
| 493 | + public function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) { |
503 | 494 | $parts = intval( $parts ); |
504 | 495 | $offset = intval( $offset ); |
505 | 496 | $ntitle = Title::newFromText( $title ); |
— | — | @@ -531,17 +522,17 @@ |
532 | 523 | private function tooLongError() { |
533 | 524 | global $wgPFStringLengthLimit, $wgContLang; |
534 | 525 | wfLoadExtensionMessages( 'ParserFunctions' ); |
535 | | - |
536 | | - return '<strong class="error">' . |
| 526 | + |
| 527 | + return '<strong class="error">' . |
537 | 528 | wfMsgExt( 'pfunc_string_too_long', |
538 | | - array( 'escape', 'parsemag', 'content' ), |
| 529 | + array( 'escape', 'parsemag', 'content' ), |
539 | 530 | $wgContLang->formatNum( $wgPFStringLengthLimit ) ) . |
540 | 531 | '</strong>'; |
541 | 532 | } |
542 | 533 | |
543 | 534 | /** |
544 | 535 | * {{#len:string}} |
545 | | - * |
| 536 | + * |
546 | 537 | * Reports number of characters in string. |
547 | 538 | */ |
548 | 539 | function runLen ( $parser, $inStr = '' ) { |
— | — | @@ -567,17 +558,17 @@ |
568 | 559 | |
569 | 560 | $inStr = $this->killMarkers( $parser, (string)$inStr ); |
570 | 561 | $inNeedle = $this->killMarkers( $parser, (string)$inNeedle ); |
571 | | - |
572 | | - if( !$this->checkLength( $inStr ) || |
| 562 | + |
| 563 | + if ( !$this->checkLength( $inStr ) || |
573 | 564 | !$this->checkLength( $inNeedle ) ) { |
574 | 565 | wfProfileOut( __METHOD__ ); |
575 | 566 | return $this->tooLongError(); |
576 | 567 | } |
577 | 568 | |
578 | | - if( $inNeedle == '' ) { $inNeedle = ' '; } |
| 569 | + if ( $inNeedle == '' ) { $inNeedle = ' '; } |
579 | 570 | |
580 | 571 | $pos = mb_strpos( $inStr, $inNeedle, $inOffset ); |
581 | | - if( $pos === false ) { $pos = ""; } |
| 572 | + if ( $pos === false ) { $pos = ""; } |
582 | 573 | |
583 | 574 | wfProfileOut( __METHOD__ ); |
584 | 575 | return $pos; |
— | — | @@ -596,17 +587,17 @@ |
597 | 588 | |
598 | 589 | $inStr = $this->killMarkers( $parser, (string)$inStr ); |
599 | 590 | $inNeedle = $this->killMarkers( $parser, (string)$inNeedle ); |
600 | | - |
601 | | - if( !$this->checkLength( $inStr ) || |
| 591 | + |
| 592 | + if ( !$this->checkLength( $inStr ) || |
602 | 593 | !$this->checkLength( $inNeedle ) ) { |
603 | 594 | wfProfileOut( __METHOD__ ); |
604 | 595 | return $this->tooLongError(); |
605 | 596 | } |
606 | 597 | |
607 | | - if( $inNeedle == '' ) { $inNeedle = ' '; } |
| 598 | + if ( $inNeedle == '' ) { $inNeedle = ' '; } |
608 | 599 | |
609 | 600 | $pos = mb_strrpos( $inStr, $inNeedle ); |
610 | | - if( $pos === false ) { $pos = -1; } |
| 601 | + if ( $pos === false ) { $pos = -1; } |
611 | 602 | |
612 | 603 | wfProfileOut( __METHOD__ ); |
613 | 604 | return $pos; |
— | — | @@ -616,10 +607,10 @@ |
617 | 608 | * {{#sub: string | start | length }} |
618 | 609 | * |
619 | 610 | * Returns substring of "string" starting at "start" and having |
620 | | - * "length" characters. |
| 611 | + * "length" characters. |
621 | 612 | * |
622 | 613 | * Note: If length is zero, the rest of the input is returned. |
623 | | - * Note: A negative value for "start" operates from the end of the |
| 614 | + * Note: A negative value for "start" operates from the end of the |
624 | 615 | * "string". |
625 | 616 | * Note: A negative value for "length" returns a string reduced in |
626 | 617 | * length by that amount. |
— | — | @@ -629,19 +620,19 @@ |
630 | 621 | |
631 | 622 | $inStr = $this->killMarkers( $parser, (string)$inStr ); |
632 | 623 | |
633 | | - if( !$this->checkLength( $inStr ) ) { |
| 624 | + if ( !$this->checkLength( $inStr ) ) { |
634 | 625 | wfProfileOut( __METHOD__ ); |
635 | 626 | return $this->tooLongError(); |
636 | 627 | } |
637 | | - |
638 | | - if ( intval($inLength) == 0 ) { |
| 628 | + |
| 629 | + if ( intval( $inLength ) == 0 ) { |
639 | 630 | $result = mb_substr( $inStr, $inStart ); |
640 | 631 | } else { |
641 | 632 | $result = mb_substr( $inStr, $inStart, $inLength ); |
642 | 633 | } |
643 | 634 | |
644 | 635 | wfProfileOut( __METHOD__ ); |
645 | | - return $result; |
| 636 | + return $result; |
646 | 637 | } |
647 | 638 | |
648 | 639 | /** |
— | — | @@ -657,18 +648,18 @@ |
658 | 649 | $inStr = $this->killMarkers( $parser, (string)$inStr ); |
659 | 650 | $inSubStr = $this->killMarkers( $parser, (string)$inSubStr ); |
660 | 651 | |
661 | | - if( !$this->checkLength( $inStr ) || |
| 652 | + if ( !$this->checkLength( $inStr ) || |
662 | 653 | !$this->checkLength( $inSubStr ) ) { |
663 | 654 | wfProfileOut( __METHOD__ ); |
664 | 655 | return $this->tooLongError(); |
665 | 656 | } |
666 | 657 | |
667 | | - if( $inSubStr == '' ) { $inSubStr = ' '; } |
668 | | - |
| 658 | + if ( $inSubStr == '' ) { $inSubStr = ' '; } |
| 659 | + |
669 | 660 | $result = mb_substr_count( $inStr, $inSubStr ); |
670 | 661 | |
671 | 662 | wfProfileOut( __METHOD__ ); |
672 | | - return $result; |
| 663 | + return $result; |
673 | 664 | } |
674 | 665 | |
675 | 666 | /** |
— | — | @@ -676,11 +667,11 @@ |
677 | 668 | * |
678 | 669 | * Replaces each occurrence of "from" in "string" with "to". |
679 | 670 | * At most "limit" replacements are performed. |
680 | | - * |
| 671 | + * |
681 | 672 | * Note: Armored against replacements that would generate huge strings. |
682 | 673 | * Note: If "from" is an empty string, single space is used instead. |
683 | 674 | */ |
684 | | - function runReplace( $parser, $inStr = '', |
| 675 | + function runReplace( $parser, $inStr = '', |
685 | 676 | $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) { |
686 | 677 | global $wgPFStringLengthLimit; |
687 | 678 | wfProfileIn( __METHOD__ ); |
— | — | @@ -689,36 +680,36 @@ |
690 | 681 | $inReplaceFrom = $this->killMarkers( $parser, (string)$inReplaceFrom ); |
691 | 682 | $inReplaceTo = $this->killMarkers( $parser, (string)$inReplaceTo ); |
692 | 683 | |
693 | | - if( !$this->checkLength( $inStr ) || |
| 684 | + if ( !$this->checkLength( $inStr ) || |
694 | 685 | !$this->checkLength( $inReplaceFrom ) || |
695 | | - !$this->checkLength( $inReplaceTo ) ) { |
| 686 | + !$this->checkLength( $inReplaceTo ) ) { |
696 | 687 | wfProfileOut( __METHOD__ ); |
697 | 688 | return $this->tooLongError(); |
698 | 689 | } |
699 | 690 | |
700 | | - if( $inReplaceFrom == '' ) { $inReplaceFrom = ' '; } |
| 691 | + if ( $inReplaceFrom == '' ) { $inReplaceFrom = ' '; } |
701 | 692 | |
702 | 693 | // Precompute limit to avoid generating enormous string: |
703 | 694 | $diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom ); |
704 | | - if( $diff > 0 ) { |
| 695 | + if ( $diff > 0 ) { |
705 | 696 | $limit = ( ( $wgPFStringLengthLimit - mb_strlen( $inStr ) ) / $diff ) + 1; |
706 | 697 | } else { |
707 | 698 | $limit = -1; |
708 | 699 | } |
709 | 700 | |
710 | | - $inLimit = intval($inLimit); |
711 | | - if( $inLimit >= 0 ) { |
712 | | - if( $limit > $inLimit || $limit == -1 ) { $limit = $inLimit; } |
| 701 | + $inLimit = intval( $inLimit ); |
| 702 | + if ( $inLimit >= 0 ) { |
| 703 | + if ( $limit > $inLimit || $limit == -1 ) { $limit = $inLimit; } |
713 | 704 | } |
714 | 705 | |
715 | 706 | // Use regex to allow limit and handle UTF-8 correctly. |
716 | 707 | $inReplaceFrom = preg_quote( $inReplaceFrom, '/' ); |
717 | 708 | $inReplaceTo = StringUtils::escapeRegexReplacement( $inReplaceTo ); |
718 | 709 | |
719 | | - $result = preg_replace( '/' . $inReplaceFrom . '/u', |
720 | | - $inReplaceTo, $inStr, $limit); |
| 710 | + $result = preg_replace( '/' . $inReplaceFrom . '/u', |
| 711 | + $inReplaceTo, $inStr, $limit ); |
721 | 712 | |
722 | | - if( !$this->checkLength( $result ) ) { |
| 713 | + if ( !$this->checkLength( $result ) ) { |
723 | 714 | wfProfileOut( __METHOD__ ); |
724 | 715 | return $this->tooLongError(); |
725 | 716 | } |
— | — | @@ -744,22 +735,22 @@ |
745 | 736 | $inStr = $this->killMarkers( $parser, (string)$inStr ); |
746 | 737 | $inDiv = $this->killMarkers( $parser, (string)$inDiv ); |
747 | 738 | |
748 | | - if( $inDiv == '' ) { $inDiv = ' '; } |
| 739 | + if ( $inDiv == '' ) { $inDiv = ' '; } |
749 | 740 | |
750 | | - if( !$this->checkLength( $inStr ) || |
751 | | - !$this->checkLength( $inDiv ) ) { |
| 741 | + if ( !$this->checkLength( $inStr ) || |
| 742 | + !$this->checkLength( $inDiv ) ) { |
752 | 743 | wfProfileOut( __METHOD__ ); |
753 | 744 | return $this->tooLongError(); |
754 | 745 | } |
755 | 746 | |
756 | 747 | $inDiv = preg_quote( $inDiv, '/' ); |
757 | | - |
758 | | - $matches = preg_split( '/'.$inDiv.'/u', $inStr, $inLim ); |
759 | | - |
760 | | - if( $inPos >= 0 && isset( $matches[$inPos] ) ) { |
| 748 | + |
| 749 | + $matches = preg_split( '/' . $inDiv . '/u', $inStr, $inLim ); |
| 750 | + |
| 751 | + if ( $inPos >= 0 && isset( $matches[$inPos] ) ) { |
761 | 752 | $result = $matches[$inPos]; |
762 | | - } elseif ( $inPos < 0 && isset( $matches[count($matches) + $inPos] ) ) { |
763 | | - $result = $matches[count($matches) + $inPos]; |
| 753 | + } elseif ( $inPos < 0 && isset( $matches[count( $matches ) + $inPos] ) ) { |
| 754 | + $result = $matches[count( $matches ) + $inPos]; |
764 | 755 | } else { |
765 | 756 | $result = ''; |
766 | 757 | } |
Index: trunk/extensions/ParserFunctions/ParserFunctions.php |
— | — | @@ -4,9 +4,8 @@ |
5 | 5 | die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
6 | 6 | } |
7 | 7 | |
8 | | - |
9 | 8 | /** |
10 | | - * CONFIGURATION |
| 9 | + * CONFIGURATION |
11 | 10 | * These variables may be overridden in LocalSettings.php after you include the |
12 | 11 | * extension file. |
13 | 12 | */ |
— | — | @@ -20,12 +19,12 @@ |
21 | 20 | /** |
22 | 21 | * Enable string functions. |
23 | 22 | * |
24 | | - * Set this to true if you want your users to be able to implement their own |
25 | | - * parsers in the ugliest, most inefficient programming language known to man: |
| 23 | + * Set this to true if you want your users to be able to implement their own |
| 24 | + * parsers in the ugliest, most inefficient programming language known to man: |
26 | 25 | * MediaWiki wikitext with ParserFunctions. |
27 | 26 | * |
28 | 27 | * WARNING: enabling this may have an adverse impact on the sanity of your users. |
29 | | - * An alternative, saner solution for embedding complex text processing in |
| 28 | + * An alternative, saner solution for embedding complex text processing in |
30 | 29 | * MediaWiki templates can be found at: http://www.mediawiki.org/wiki/Extension:Lua |
31 | 30 | */ |
32 | 31 | $wgPFEnableStringFunctions = false; |
— | — | @@ -35,15 +34,15 @@ |
36 | 35 | $wgExtensionCredits['parserhook'][] = array( |
37 | 36 | 'path' => __FILE__, |
38 | 37 | 'name' => 'ParserFunctions', |
39 | | - 'version' => '1.3.0', |
| 38 | + 'version' => '1.4.0', |
40 | 39 | 'url' => 'http://www.mediawiki.org/wiki/Extension:ParserFunctions', |
41 | | - 'author' => array('Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic'), |
| 40 | + 'author' => array( 'Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic' ), |
42 | 41 | 'descriptionmsg' => 'pfunc_desc', |
43 | 42 | ); |
44 | 43 | |
45 | | -$wgAutoloadClasses['ExtParserFunctions'] = dirname(__FILE__).'/ParserFunctions_body.php'; |
46 | | -$wgExtensionMessagesFiles['ParserFunctions'] = dirname(__FILE__) . '/ParserFunctions.i18n.php'; |
47 | | -$wgExtensionMessagesFiles['ParserFunctionsMagic'] = dirname(__FILE__) . '/ParserFunctions.i18n.magic.php'; |
| 44 | +$wgAutoloadClasses['ExtParserFunctions'] = dirname( __FILE__ ) . '/ParserFunctions_body.php'; |
| 45 | +$wgExtensionMessagesFiles['ParserFunctions'] = dirname( __FILE__ ) . '/ParserFunctions.i18n.php'; |
| 46 | +$wgExtensionMessagesFiles['ParserFunctionsMagic'] = dirname( __FILE__ ) . '/ParserFunctions.i18n.magic.php'; |
48 | 47 | |
49 | 48 | $wgParserTestFiles[] = dirname( __FILE__ ) . "/funcsParserTests.txt"; |
50 | 49 | $wgParserTestFiles[] = dirname( __FILE__ ) . "/stringFunctionTests.txt"; |
— | — | @@ -91,7 +90,7 @@ |
92 | 91 | $parser->setFunctionHook( 'rel2abs', array( &$this, 'rel2abs' ) ); |
93 | 92 | $parser->setFunctionHook( 'titleparts', array( &$this, 'titleparts' ) ); |
94 | 93 | |
95 | | - //String Functions |
| 94 | + // String Functions |
96 | 95 | if ( $wgPFEnableStringFunctions ) { |
97 | 96 | $parser->setFunctionHook( 'len', array( &$this, 'runLen' ) ); |
98 | 97 | $parser->setFunctionHook( 'pos', array( &$this, 'runPos' ) ); |
Index: trunk/extensions/ParserFunctions/README |
— | — | @@ -1,4 +1,4 @@ |
2 | | -ParserFunctions v1.1.1 |
| 2 | +ParserFunctions v1.4.0 |
3 | 3 | |
4 | 4 | 1. Licensing |
5 | 5 | 2. How to install |
— | — | @@ -18,4 +18,4 @@ |
19 | 19 | ParserFunctions ships with two tests |
20 | 20 | - Parser tests. These get added to the main parser tests, see there for docs |
21 | 21 | - Expression tests. These are designed to test the math-related functions |
22 | | - See testExpr.php |
\ No newline at end of file |
| 22 | + See testExpr.php |