MediaWiki  1.32.5
ExprParser.php
Go to the documentation of this file.
1 <?php
19 use UtfNormal\Validator;
20 
21 // Character classes
22 define( 'EXPR_WHITE_CLASS', " \t\r\n" );
23 define( 'EXPR_NUMBER_CLASS', '0123456789.' );
24 
25 // Token types
26 define( 'EXPR_WHITE', 1 );
27 define( 'EXPR_NUMBER', 2 );
28 define( 'EXPR_NEGATIVE', 3 );
29 define( 'EXPR_POSITIVE', 4 );
30 define( 'EXPR_PLUS', 5 );
31 define( 'EXPR_MINUS', 6 );
32 define( 'EXPR_TIMES', 7 );
33 define( 'EXPR_DIVIDE', 8 );
34 define( 'EXPR_MOD', 9 );
35 define( 'EXPR_OPEN', 10 );
36 define( 'EXPR_CLOSE', 11 );
37 define( 'EXPR_AND', 12 );
38 define( 'EXPR_OR', 13 );
39 define( 'EXPR_NOT', 14 );
40 define( 'EXPR_EQUALITY', 15 );
41 define( 'EXPR_LESS', 16 );
42 define( 'EXPR_GREATER', 17 );
43 define( 'EXPR_LESSEQ', 18 );
44 define( 'EXPR_GREATEREQ', 19 );
45 define( 'EXPR_NOTEQ', 20 );
46 define( 'EXPR_ROUND', 21 );
47 define( 'EXPR_EXPONENT', 22 );
48 define( 'EXPR_SINE', 23 );
49 define( 'EXPR_COSINE', 24 );
50 define( 'EXPR_TANGENS', 25 );
51 define( 'EXPR_ARCSINE', 26 );
52 define( 'EXPR_ARCCOS', 27 );
53 define( 'EXPR_ARCTAN', 28 );
54 define( 'EXPR_EXP', 29 );
55 define( 'EXPR_LN', 30 );
56 define( 'EXPR_ABS', 31 );
57 define( 'EXPR_FLOOR', 32 );
58 define( 'EXPR_TRUNC', 33 );
59 define( 'EXPR_CEIL', 34 );
60 define( 'EXPR_POW', 35 );
61 define( 'EXPR_PI', 36 );
62 define( 'EXPR_FMOD', 37 );
63 define( 'EXPR_SQRT', 38 );
64 
65 class ExprParser {
66  public $maxStackSize = 100;
67 
68  public $precedence = [
69  EXPR_NEGATIVE => 10,
70  EXPR_POSITIVE => 10,
71  EXPR_EXPONENT => 10,
72  EXPR_SINE => 9,
73  EXPR_COSINE => 9,
74  EXPR_TANGENS => 9,
75  EXPR_ARCSINE => 9,
76  EXPR_ARCCOS => 9,
77  EXPR_ARCTAN => 9,
78  EXPR_EXP => 9,
79  EXPR_LN => 9,
80  EXPR_ABS => 9,
81  EXPR_FLOOR => 9,
82  EXPR_TRUNC => 9,
83  EXPR_CEIL => 9,
84  EXPR_NOT => 9,
85  EXPR_SQRT => 9,
86  EXPR_POW => 8,
87  EXPR_TIMES => 7,
88  EXPR_DIVIDE => 7,
89  EXPR_MOD => 7,
90  EXPR_FMOD => 7,
91  EXPR_PLUS => 6,
92  EXPR_MINUS => 6,
93  EXPR_ROUND => 5,
94  EXPR_EQUALITY => 4,
95  EXPR_LESS => 4,
96  EXPR_GREATER => 4,
97  EXPR_LESSEQ => 4,
98  EXPR_GREATEREQ => 4,
99  EXPR_NOTEQ => 4,
100  EXPR_AND => 3,
101  EXPR_OR => 2,
102  EXPR_PI => 0,
103  EXPR_OPEN => -1,
104  EXPR_CLOSE => -1,
105  ];
106 
107  public $names = [
108  EXPR_NEGATIVE => '-',
109  EXPR_POSITIVE => '+',
110  EXPR_NOT => 'not',
111  EXPR_TIMES => '*',
112  EXPR_DIVIDE => '/',
113  EXPR_MOD => 'mod',
114  EXPR_FMOD => 'fmod',
115  EXPR_PLUS => '+',
116  EXPR_MINUS => '-',
117  EXPR_ROUND => 'round',
118  EXPR_EQUALITY => '=',
119  EXPR_LESS => '<',
120  EXPR_GREATER => '>',
121  EXPR_LESSEQ => '<=',
122  EXPR_GREATEREQ => '>=',
123  EXPR_NOTEQ => '<>',
124  EXPR_AND => 'and',
125  EXPR_OR => 'or',
126  EXPR_EXPONENT => 'e',
127  EXPR_SINE => 'sin',
128  EXPR_COSINE => 'cos',
129  EXPR_TANGENS => 'tan',
130  EXPR_ARCSINE => 'asin',
131  EXPR_ARCCOS => 'acos',
132  EXPR_ARCTAN => 'atan',
133  EXPR_LN => 'ln',
134  EXPR_EXP => 'exp',
135  EXPR_ABS => 'abs',
136  EXPR_FLOOR => 'floor',
137  EXPR_TRUNC => 'trunc',
138  EXPR_CEIL => 'ceil',
139  EXPR_POW => '^',
140  EXPR_PI => 'pi',
141  EXPR_SQRT => 'sqrt',
142  ];
143 
144  public $words = [
145  'mod' => EXPR_MOD,
146  'fmod' => EXPR_FMOD,
147  'and' => EXPR_AND,
148  'or' => EXPR_OR,
149  'not' => EXPR_NOT,
150  'round' => EXPR_ROUND,
151  'div' => EXPR_DIVIDE,
152  'e' => EXPR_EXPONENT,
153  'sin' => EXPR_SINE,
154  'cos' => EXPR_COSINE,
155  'tan' => EXPR_TANGENS,
156  'asin' => EXPR_ARCSINE,
157  'acos' => EXPR_ARCCOS,
158  'atan' => EXPR_ARCTAN,
159  'exp' => EXPR_EXP,
160  'ln' => EXPR_LN,
161  'abs' => EXPR_ABS,
162  'trunc' => EXPR_TRUNC,
163  'floor' => EXPR_FLOOR,
164  'ceil' => EXPR_CEIL,
165  'pi' => EXPR_PI,
166  'sqrt' => EXPR_SQRT,
167  ];
168 
179  public function doExpression( $expr ) {
180  $operands = [];
181  $operators = [];
182 
183  # Unescape inequality operators
184  $expr = strtr( $expr, [ '&lt;' => '<', '&gt;' => '>',
185  '&minus;' => '-', '−' => '-' ] );
186 
187  $p = 0;
188  $end = strlen( $expr );
189  $expecting = 'expression';
190  $name = '';
191 
192  while ( $p < $end ) {
193  if ( count( $operands ) > $this->maxStackSize || count( $operators ) > $this->maxStackSize ) {
194  throw new ExprError( 'stack_exhausted' );
195  }
196  $char = $expr[$p];
197  $char2 = substr( $expr, $p, 2 );
198 
199  // Mega if-elseif-else construct
200  // Only binary operators fall through for processing at the bottom, the rest
201  // finish their processing and continue
202 
203  // First the unlimited length classes
204 
205  if ( false !== strpos( EXPR_WHITE_CLASS, $char ) ) {
206  // Whitespace
207  $p += strspn( $expr, EXPR_WHITE_CLASS, $p );
208  continue;
209  } elseif ( false !== strpos( EXPR_NUMBER_CLASS, $char ) ) {
210  // Number
211  if ( $expecting !== 'expression' ) {
212  throw new ExprError( 'unexpected_number' );
213  }
214 
215  // Find the rest of it
216  $length = strspn( $expr, EXPR_NUMBER_CLASS, $p );
217  // Convert it to float, silently removing double decimal points
218  $operands[] = (float)substr( $expr, $p, $length );
219  $p += $length;
220  $expecting = 'operator';
221  continue;
222  } elseif ( ctype_alpha( $char ) ) {
223  // Word
224  // Find the rest of it
225  $remaining = substr( $expr, $p );
226  if ( !preg_match( '/^[A-Za-z]*/', $remaining, $matches ) ) {
227  // This should be unreachable
228  throw new ExprError( 'preg_match_failure' );
229  }
230  $word = strtolower( $matches[0] );
231  $p += strlen( $word );
232 
233  // Interpret the word
234  if ( !isset( $this->words[$word] ) ) {
235  throw new ExprError( 'unrecognised_word', $word );
236  }
237  $op = $this->words[$word];
238  switch ( $op ) {
239  // constant
240  case EXPR_EXPONENT:
241  if ( $expecting !== 'expression' ) {
242  break;
243  }
244  $operands[] = exp( 1 );
245  $expecting = 'operator';
246  continue 2;
247  case EXPR_PI:
248  if ( $expecting !== 'expression' ) {
249  throw new ExprError( 'unexpected_number' );
250  }
251  $operands[] = pi();
252  $expecting = 'operator';
253  continue 2;
254  // Unary operator
255  case EXPR_NOT:
256  case EXPR_SINE:
257  case EXPR_COSINE:
258  case EXPR_TANGENS:
259  case EXPR_ARCSINE:
260  case EXPR_ARCCOS:
261  case EXPR_ARCTAN:
262  case EXPR_EXP:
263  case EXPR_LN:
264  case EXPR_ABS:
265  case EXPR_FLOOR:
266  case EXPR_TRUNC:
267  case EXPR_CEIL:
268  case EXPR_SQRT:
269  if ( $expecting !== 'expression' ) {
270  throw new ExprError( 'unexpected_operator', $word );
271  }
272  $operators[] = $op;
273  continue 2;
274  }
275  // Binary operator, fall through
276  $name = $word;
277  } elseif ( $char2 === '<=' ) {
278  $name = $char2;
279  $op = EXPR_LESSEQ;
280  $p += 2;
281  } elseif ( $char2 === '>=' ) {
282  $name = $char2;
283  $op = EXPR_GREATEREQ;
284  $p += 2;
285  } elseif ( $char2 === '<>' || $char2 === '!=' ) {
286  $name = $char2;
287  $op = EXPR_NOTEQ;
288  $p += 2;
289  } elseif ( $char === '+' ) {
290  ++$p;
291  if ( $expecting === 'expression' ) {
292  // Unary plus
293  $operators[] = EXPR_POSITIVE;
294  continue;
295  } else {
296  // Binary plus
297  $op = EXPR_PLUS;
298  }
299  } elseif ( $char === '-' ) {
300  ++$p;
301  if ( $expecting === 'expression' ) {
302  // Unary minus
303  $operators[] = EXPR_NEGATIVE;
304  continue;
305  } else {
306  // Binary minus
307  $op = EXPR_MINUS;
308  }
309  } elseif ( $char === '*' ) {
310  $name = $char;
311  $op = EXPR_TIMES;
312  ++$p;
313  } elseif ( $char === '/' ) {
314  $name = $char;
315  $op = EXPR_DIVIDE;
316  ++$p;
317  } elseif ( $char === '^' ) {
318  $name = $char;
319  $op = EXPR_POW;
320  ++$p;
321  } elseif ( $char === '(' ) {
322  if ( $expecting === 'operator' ) {
323  throw new ExprError( 'unexpected_operator', '(' );
324  }
325  $operators[] = EXPR_OPEN;
326  ++$p;
327  continue;
328  } elseif ( $char === ')' ) {
329  $lastOp = end( $operators );
330  while ( $lastOp && $lastOp != EXPR_OPEN ) {
331  $this->doOperation( $lastOp, $operands );
332  array_pop( $operators );
333  $lastOp = end( $operators );
334  }
335  if ( $lastOp ) {
336  array_pop( $operators );
337  } else {
338  throw new ExprError( 'unexpected_closing_bracket' );
339  }
340  $expecting = 'operator';
341  ++$p;
342  continue;
343  } elseif ( $char === '=' ) {
344  $name = $char;
345  $op = EXPR_EQUALITY;
346  ++$p;
347  } elseif ( $char === '<' ) {
348  $name = $char;
349  $op = EXPR_LESS;
350  ++$p;
351  } elseif ( $char === '>' ) {
352  $name = $char;
353  $op = EXPR_GREATER;
354  ++$p;
355  } else {
356  $utfExpr = Validator::cleanUp( substr( $expr, $p ) );
357  throw new ExprError( 'unrecognised_punctuation', mb_substr( $utfExpr, 0, 1 ) );
358  }
359 
360  // Binary operator processing
361  if ( $expecting === 'expression' ) {
362  throw new ExprError( 'unexpected_operator', $name );
363  }
364 
365  // Shunting yard magic
366  $lastOp = end( $operators );
367  while ( $lastOp && $this->precedence[$op] <= $this->precedence[$lastOp] ) {
368  $this->doOperation( $lastOp, $operands );
369  array_pop( $operators );
370  $lastOp = end( $operators );
371  }
372  $operators[] = $op;
373  $expecting = 'expression';
374  }
375 
376  // Finish off the operator array
377  // @codingStandardsIgnoreStart
378  while ( $op = array_pop( $operators ) ) {
379  // @codingStandardsIgnoreEnd
380  if ( $op == EXPR_OPEN ) {
381  throw new ExprError( 'unclosed_bracket' );
382  }
383  $this->doOperation( $op, $operands );
384  }
385 
386  return implode( "<br />\n", $operands );
387  }
388 
394  public function doOperation( $op, &$stack ) {
395  switch ( $op ) {
396  case EXPR_NEGATIVE:
397  if ( count( $stack ) < 1 ) {
398  throw new ExprError( 'missing_operand', $this->names[$op] );
399  }
400  $arg = array_pop( $stack );
401  $stack[] = -$arg;
402  break;
403  case EXPR_POSITIVE:
404  if ( count( $stack ) < 1 ) {
405  throw new ExprError( 'missing_operand', $this->names[$op] );
406  }
407  break;
408  case EXPR_TIMES:
409  if ( count( $stack ) < 2 ) {
410  throw new ExprError( 'missing_operand', $this->names[$op] );
411  }
412  $right = array_pop( $stack );
413  $left = array_pop( $stack );
414  $stack[] = $left * $right;
415  break;
416  case EXPR_DIVIDE:
417  if ( count( $stack ) < 2 ) {
418  throw new ExprError( 'missing_operand', $this->names[$op] );
419  }
420  $right = array_pop( $stack );
421  $left = array_pop( $stack );
422  if ( !$right ) {
423  throw new ExprError( 'division_by_zero', $this->names[$op] );
424  }
425  $stack[] = $left / $right;
426  break;
427  case EXPR_MOD:
428  if ( count( $stack ) < 2 ) {
429  throw new ExprError( 'missing_operand', $this->names[$op] );
430  }
431  $right = (int)array_pop( $stack );
432  $left = (int)array_pop( $stack );
433  if ( !$right ) {
434  throw new ExprError( 'division_by_zero', $this->names[$op] );
435  }
436  $stack[] = $left % $right;
437  break;
438  case EXPR_FMOD:
439  if ( count( $stack ) < 2 ) {
440  throw new ExprError( 'missing_operand', $this->names[$op] );
441  }
442  $right = (double)array_pop( $stack );
443  $left = (double)array_pop( $stack );
444  if ( !$right ) {
445  throw new ExprError( 'division_by_zero', $this->names[$op] );
446  }
447  $stack[] = fmod( $left, $right );
448  break;
449  case EXPR_PLUS:
450  if ( count( $stack ) < 2 ) {
451  throw new ExprError( 'missing_operand', $this->names[$op] );
452  }
453  $right = array_pop( $stack );
454  $left = array_pop( $stack );
455  $stack[] = $left + $right;
456  break;
457  case EXPR_MINUS:
458  if ( count( $stack ) < 2 ) {
459  throw new ExprError( 'missing_operand', $this->names[$op] );
460  }
461  $right = array_pop( $stack );
462  $left = array_pop( $stack );
463  $stack[] = $left - $right;
464  break;
465  case EXPR_AND:
466  if ( count( $stack ) < 2 ) {
467  throw new ExprError( 'missing_operand', $this->names[$op] );
468  }
469  $right = array_pop( $stack );
470  $left = array_pop( $stack );
471  $stack[] = ( $left && $right ) ? 1 : 0;
472  break;
473  case EXPR_OR:
474  if ( count( $stack ) < 2 ) {
475  throw new ExprError( 'missing_operand', $this->names[$op] );
476  }
477  $right = array_pop( $stack );
478  $left = array_pop( $stack );
479  $stack[] = ( $left || $right ) ? 1 : 0;
480  break;
481  case EXPR_EQUALITY:
482  if ( count( $stack ) < 2 ) {
483  throw new ExprError( 'missing_operand', $this->names[$op] );
484  }
485  $right = array_pop( $stack );
486  $left = array_pop( $stack );
487  $stack[] = ( $left == $right ) ? 1 : 0;
488  break;
489  case EXPR_NOT:
490  if ( count( $stack ) < 1 ) {
491  throw new ExprError( 'missing_operand', $this->names[$op] );
492  }
493  $arg = array_pop( $stack );
494  $stack[] = ( !$arg ) ? 1 : 0;
495  break;
496  case EXPR_ROUND:
497  if ( count( $stack ) < 2 ) {
498  throw new ExprError( 'missing_operand', $this->names[$op] );
499  }
500  $digits = (int)array_pop( $stack );
501  $value = array_pop( $stack );
502  $stack[] = round( $value, $digits );
503  break;
504  case EXPR_LESS:
505  if ( count( $stack ) < 2 ) {
506  throw new ExprError( 'missing_operand', $this->names[$op] );
507  }
508  $right = array_pop( $stack );
509  $left = array_pop( $stack );
510  $stack[] = ( $left < $right ) ? 1 : 0;
511  break;
512  case EXPR_GREATER:
513  if ( count( $stack ) < 2 ) {
514  throw new ExprError( 'missing_operand', $this->names[$op] );
515  }
516  $right = array_pop( $stack );
517  $left = array_pop( $stack );
518  $stack[] = ( $left > $right ) ? 1 : 0;
519  break;
520  case EXPR_LESSEQ:
521  if ( count( $stack ) < 2 ) {
522  throw new ExprError( 'missing_operand', $this->names[$op] );
523  }
524  $right = array_pop( $stack );
525  $left = array_pop( $stack );
526  $stack[] = ( $left <= $right ) ? 1 : 0;
527  break;
528  case EXPR_GREATEREQ:
529  if ( count( $stack ) < 2 ) {
530  throw new ExprError( 'missing_operand', $this->names[$op] );
531  }
532  $right = array_pop( $stack );
533  $left = array_pop( $stack );
534  $stack[] = ( $left >= $right ) ? 1 : 0;
535  break;
536  case EXPR_NOTEQ:
537  if ( count( $stack ) < 2 ) {
538  throw new ExprError( 'missing_operand', $this->names[$op] );
539  }
540  $right = array_pop( $stack );
541  $left = array_pop( $stack );
542  $stack[] = ( $left != $right ) ? 1 : 0;
543  break;
544  case EXPR_EXPONENT:
545  if ( count( $stack ) < 2 ) {
546  throw new ExprError( 'missing_operand', $this->names[$op] );
547  }
548  $right = array_pop( $stack );
549  $left = array_pop( $stack );
550  $stack[] = $left * pow( 10, $right );
551  break;
552  case EXPR_SINE:
553  if ( count( $stack ) < 1 ) {
554  throw new ExprError( 'missing_operand', $this->names[$op] );
555  }
556  $arg = array_pop( $stack );
557  $stack[] = sin( $arg );
558  break;
559  case EXPR_COSINE:
560  if ( count( $stack ) < 1 ) {
561  throw new ExprError( 'missing_operand', $this->names[$op] );
562  }
563  $arg = array_pop( $stack );
564  $stack[] = cos( $arg );
565  break;
566  case EXPR_TANGENS:
567  if ( count( $stack ) < 1 ) {
568  throw new ExprError( 'missing_operand', $this->names[$op] );
569  }
570  $arg = array_pop( $stack );
571  $stack[] = tan( $arg );
572  break;
573  case EXPR_ARCSINE:
574  if ( count( $stack ) < 1 ) {
575  throw new ExprError( 'missing_operand', $this->names[$op] );
576  }
577  $arg = array_pop( $stack );
578  if ( $arg < -1 || $arg > 1 ) {
579  throw new ExprError( 'invalid_argument', $this->names[$op] );
580  }
581  $stack[] = asin( $arg );
582  break;
583  case EXPR_ARCCOS:
584  if ( count( $stack ) < 1 ) {
585  throw new ExprError( 'missing_operand', $this->names[$op] );
586  }
587  $arg = array_pop( $stack );
588  if ( $arg < -1 || $arg > 1 ) {
589  throw new ExprError( 'invalid_argument', $this->names[$op] );
590  }
591  $stack[] = acos( $arg );
592  break;
593  case EXPR_ARCTAN:
594  if ( count( $stack ) < 1 ) {
595  throw new ExprError( 'missing_operand', $this->names[$op] );
596  }
597  $arg = array_pop( $stack );
598  $stack[] = atan( $arg );
599  break;
600  case EXPR_EXP:
601  if ( count( $stack ) < 1 ) {
602  throw new ExprError( 'missing_operand', $this->names[$op] );
603  }
604  $arg = array_pop( $stack );
605  $stack[] = exp( $arg );
606  break;
607  case EXPR_LN:
608  if ( count( $stack ) < 1 ) {
609  throw new ExprError( 'missing_operand', $this->names[$op] );
610  }
611  $arg = array_pop( $stack );
612  if ( $arg <= 0 ) {
613  throw new ExprError( 'invalid_argument_ln', $this->names[$op] );
614  }
615  $stack[] = log( $arg );
616  break;
617  case EXPR_ABS:
618  if ( count( $stack ) < 1 ) {
619  throw new ExprError( 'missing_operand', $this->names[$op] );
620  }
621  $arg = array_pop( $stack );
622  $stack[] = abs( $arg );
623  break;
624  case EXPR_FLOOR:
625  if ( count( $stack ) < 1 ) {
626  throw new ExprError( 'missing_operand', $this->names[$op] );
627  }
628  $arg = array_pop( $stack );
629  $stack[] = floor( $arg );
630  break;
631  case EXPR_TRUNC:
632  if ( count( $stack ) < 1 ) {
633  throw new ExprError( 'missing_operand', $this->names[$op] );
634  }
635  $arg = array_pop( $stack );
636  $stack[] = (int)$arg;
637  break;
638  case EXPR_CEIL:
639  if ( count( $stack ) < 1 ) {
640  throw new ExprError( 'missing_operand', $this->names[$op] );
641  }
642  $arg = array_pop( $stack );
643  $stack[] = ceil( $arg );
644  break;
645  case EXPR_POW:
646  if ( count( $stack ) < 2 ) {
647  throw new ExprError( 'missing_operand', $this->names[$op] );
648  }
649  $right = array_pop( $stack );
650  $left = array_pop( $stack );
651  $result = pow( $left, $right );
652  if ( $result === false ) {
653  throw new ExprError( 'division_by_zero', $this->names[$op] );
654  }
655  $stack[] = $result;
656  break;
657  case EXPR_SQRT:
658  if ( count( $stack ) < 1 ) {
659  throw new ExprError( 'missing_operand', $this->names[$op] );
660  }
661  $arg = array_pop( $stack );
662  $result = sqrt( $arg );
663  if ( is_nan( $result ) ) {
664  throw new ExprError( 'not_a_number', $this->names[$op] );
665  }
666  $stack[] = $result;
667  break;
668  default:
669  // Should be impossible to reach here.
670  throw new ExprError( 'unknown_error' );
671  }
672  }
673 }
EXPR_NOTEQ
const EXPR_NOTEQ
Definition: ExprParser.php:45
EXPR_EXPONENT
const EXPR_EXPONENT
Definition: ExprParser.php:47
EXPR_COSINE
const EXPR_COSINE
Definition: ExprParser.php:49
EXPR_NOT
const EXPR_NOT
Definition: ExprParser.php:39
captcha-old.count
count
Definition: captcha-old.py:249
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED since 1.16! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:2042
EXPR_SQRT
const EXPR_SQRT
Definition: ExprParser.php:63
EXPR_PLUS
const EXPR_PLUS
Definition: ExprParser.php:30
EXPR_NUMBER_CLASS
const EXPR_NUMBER_CLASS
Definition: ExprParser.php:23
EXPR_FLOOR
const EXPR_FLOOR
Definition: ExprParser.php:57
EXPR_MINUS
const EXPR_MINUS
Definition: ExprParser.php:31
EXPR_FMOD
const EXPR_FMOD
Definition: ExprParser.php:62
names
alter the names
Definition: COPYING.txt:329
EXPR_POSITIVE
const EXPR_POSITIVE
Definition: ExprParser.php:29
ExprParser\$names
$names
Definition: ExprParser.php:107
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ExprParser\doExpression
doExpression( $expr)
Evaluate a mathematical expression.
Definition: ExprParser.php:179
EXPR_EQUALITY
const EXPR_EQUALITY
Definition: ExprParser.php:40
EXPR_NEGATIVE
const EXPR_NEGATIVE
Definition: ExprParser.php:28
ExprParser\$words
$words
Definition: ExprParser.php:144
ExprParser\$maxStackSize
$maxStackSize
Definition: ExprParser.php:66
$matches
$matches
Definition: NoLocalSettings.php:24
EXPR_DIVIDE
const EXPR_DIVIDE
Definition: ExprParser.php:33
EXPR_ARCTAN
const EXPR_ARCTAN
Definition: ExprParser.php:53
EXPR_TANGENS
const EXPR_TANGENS
Definition: ExprParser.php:50
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
EXPR_SINE
const EXPR_SINE
Definition: ExprParser.php:48
EXPR_CLOSE
const EXPR_CLOSE
Definition: ExprParser.php:36
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
EXPR_PI
const EXPR_PI
Definition: ExprParser.php:61
$value
$value
Definition: styleTest.css.php:49
captcha-old.words
words
Definition: captcha-old.py:259
ExprParser
Definition: ExprParser.php:65
EXPR_CEIL
const EXPR_CEIL
Definition: ExprParser.php:59
EXPR_ROUND
const EXPR_ROUND
Definition: ExprParser.php:46
EXPR_EXP
const EXPR_EXP
Definition: ExprParser.php:54
EXPR_ARCSINE
const EXPR_ARCSINE
Definition: ExprParser.php:51
EXPR_OR
const EXPR_OR
Definition: ExprParser.php:38
EXPR_ARCCOS
const EXPR_ARCCOS
Definition: ExprParser.php:52
ExprParser\doOperation
doOperation( $op, &$stack)
Definition: ExprParser.php:394
EXPR_MOD
const EXPR_MOD
Definition: ExprParser.php:34
EXPR_LESS
const EXPR_LESS
Definition: ExprParser.php:41
ExprError
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: ExprError.php:19
EXPR_TRUNC
const EXPR_TRUNC
Definition: ExprParser.php:58
EXPR_LESSEQ
const EXPR_LESSEQ
Definition: ExprParser.php:43
ExprParser\$precedence
$precedence
Definition: ExprParser.php:68
EXPR_OPEN
const EXPR_OPEN
Definition: ExprParser.php:35
EXPR_GREATEREQ
const EXPR_GREATEREQ
Definition: ExprParser.php:44
EXPR_LN
const EXPR_LN
Definition: ExprParser.php:55
EXPR_TIMES
const EXPR_TIMES
Definition: ExprParser.php:32
EXPR_AND
const EXPR_AND
Definition: ExprParser.php:37
EXPR_POW
const EXPR_POW
Definition: ExprParser.php:60
EXPR_GREATER
const EXPR_GREATER
Definition: ExprParser.php:42
EXPR_ABS
const EXPR_ABS
Definition: ExprParser.php:56
EXPR_WHITE_CLASS
const EXPR_WHITE_CLASS
Definition: ExprParser.php:22