MediaWiki  1.32.0
ExtParserFunctions.php
Go to the documentation of this file.
1 <?php
2 
4 
6  public static $mExprParser;
7  public static $mTimeCache = [];
8  public static $mTimeChars = 0;
9  public static $mMaxTimeChars = 6000; # ~10 seconds
10 
15  public static function clearState( $parser ) {
16  self::$mTimeChars = 0;
17  return true;
18  }
19 
25  public static function registerClearHook() {
26  static $done = false;
27  if ( !$done ) {
28  global $wgHooks;
29  $wgHooks['ParserClearState'][] = __CLASS__ . '::clearState';
30  $done = true;
31  }
32  }
33 
37  public static function &getExprParser() {
38  if ( !isset( self::$mExprParser ) ) {
39  self::$mExprParser = new ExprParser;
40  }
41  return self::$mExprParser;
42  }
43 
49  public static function expr( $parser, $expr = '' ) {
50  try {
51  return self::getExprParser()->doExpression( $expr );
52  } catch ( ExprError $e ) {
53  return '<strong class="error">' . htmlspecialchars( $e->getMessage() ) . '</strong>';
54  }
55  }
56 
64  public static function ifexpr( $parser, $expr = '', $then = '', $else = '' ) {
65  try {
66  $ret = self::getExprParser()->doExpression( $expr );
67  if ( is_numeric( $ret ) ) {
68  $ret = (float)$ret;
69  }
70  if ( $ret ) {
71  return $then;
72  } else {
73  return $else;
74  }
75  } catch ( ExprError $e ) {
76  return '<strong class="error">' . htmlspecialchars( $e->getMessage() ) . '</strong>';
77  }
78  }
79 
86  public static function ifexprObj( $parser, $frame, $args ) {
87  $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
88  $then = isset( $args[1] ) ? $args[1] : '';
89  $else = isset( $args[2] ) ? $args[2] : '';
90  $result = self::ifexpr( $parser, $expr, $then, $else );
91  if ( is_object( $result ) ) {
92  $result = trim( $frame->expand( $result ) );
93  }
94  return $result;
95  }
96 
103  public static function ifObj( $parser, $frame, $args ) {
104  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
105  if ( $test !== '' ) {
106  return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
107  } else {
108  return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
109  }
110  }
111 
118  public static function ifeqObj( $parser, $frame, $args ) {
119  $left = isset( $args[0] ) ? self::decodeTrimExpand( $args[0], $frame ) : '';
120  $right = isset( $args[1] ) ? self::decodeTrimExpand( $args[1], $frame ) : '';
121 
122  // Strict compare is not possible here. 01 should equal 1 for example.
124  if ( $left == $right ) {
125  return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
126  } else {
127  return isset( $args[3] ) ? trim( $frame->expand( $args[3] ) ) : '';
128  }
129  }
130 
138  public static function iferror( $parser, $test = '', $then = '', $else = false ) {
139  if ( preg_match(
140  '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/',
141  $test )
142  ) {
143  return $then;
144  } elseif ( $else === false ) {
145  return $test;
146  } else {
147  return $else;
148  }
149  }
150 
157  public static function iferrorObj( $parser, $frame, $args ) {
158  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
159  $then = isset( $args[1] ) ? $args[1] : false;
160  $else = isset( $args[2] ) ? $args[2] : false;
161  $result = self::iferror( $parser, $test, $then, $else );
162  if ( $result === false ) {
163  return '';
164  } else {
165  return trim( $frame->expand( $result ) );
166  }
167  }
168 
175  public static function switchObj( $parser, $frame, $args ) {
176  if ( count( $args ) === 0 ) {
177  return '';
178  }
179  $primary = self::decodeTrimExpand( array_shift( $args ), $frame );
180  $found = $defaultFound = false;
181  $default = null;
182  $lastItemHadNoEquals = false;
183  $lastItem = '';
184  if ( class_exists( MagicWordFactory::class ) ) {
185  $mwDefault = $parser->getMagicWordFactory()->get( 'default' );
186  } else {
187  $mwDefault = MagicWord::get( 'default' );
188  }
189  foreach ( $args as $arg ) {
190  $bits = $arg->splitArg();
191  $nameNode = $bits['name'];
192  $index = $bits['index'];
193  $valueNode = $bits['value'];
194 
195  if ( $index === '' ) {
196  # Found "="
197  $lastItemHadNoEquals = false;
198  if ( $found ) {
199  # Multiple input match
200  return trim( $frame->expand( $valueNode ) );
201  } else {
202  $test = self::decodeTrimExpand( $nameNode, $frame );
204  if ( $test == $primary ) {
205  # Found a match, return now
206  return trim( $frame->expand( $valueNode ) );
207  } elseif ( $defaultFound || $mwDefault->matchStartToEnd( $test ) ) {
208  $default = $valueNode;
209  $defaultFound = false;
210  } # else wrong case, continue
211  }
212  } else {
213  # Multiple input, single output
214  # If the value matches, set a flag and continue
215  $lastItemHadNoEquals = true;
216  // $lastItem is an "out" variable
217  $decodedTest = self::decodeTrimExpand( $valueNode, $frame, $lastItem );
219  if ( $decodedTest == $primary ) {
220  $found = true;
221  } elseif ( $mwDefault->matchStartToEnd( $decodedTest ) ) {
222  $defaultFound = true;
223  }
224  }
225  }
226  # Default case
227  # Check if the last item had no = sign, thus specifying the default case
228  if ( $lastItemHadNoEquals ) {
229  return $lastItem;
230  } elseif ( !is_null( $default ) ) {
231  return trim( $frame->expand( $default ) );
232  } else {
233  return '';
234  }
235  }
236 
250  public static function rel2abs( $parser, $to = '', $from = '' ) {
251  $from = trim( $from );
252  if ( $from === '' ) {
253  $from = $parser->getTitle()->getPrefixedText();
254  }
255 
256  $to = rtrim( $to, ' /' );
257 
258  // if we have an empty path, or just one containing a dot
259  if ( $to === '' || $to === '.' ) {
260  return $from;
261  }
262 
263  // if the path isn't relative
264  if ( substr( $to, 0, 1 ) !== '/' &&
265  substr( $to, 0, 2 ) !== './' &&
266  substr( $to, 0, 3 ) !== '../' &&
267  $to !== '..'
268  ) {
269  $from = '';
270  }
271  // Make a long path, containing both, enclose it in /.../
272  $fullPath = '/' . $from . '/' . $to . '/';
273 
274  // remove redundant current path dots
275  $fullPath = preg_replace( '!/(\./)+!', '/', $fullPath );
276 
277  // remove double slashes
278  $fullPath = preg_replace( '!/{2,}!', '/', $fullPath );
279 
280  // remove the enclosing slashes now
281  $fullPath = trim( $fullPath, '/' );
282  $exploded = explode( '/', $fullPath );
283  $newExploded = [];
284 
285  foreach ( $exploded as $current ) {
286  if ( $current === '..' ) { // removing one level
287  if ( !count( $newExploded ) ) {
288  // attempted to access a node above root node
289  $msg = wfMessage( 'pfunc_rel2abs_invalid_depth', $fullPath )
290  ->inContentLanguage()->escaped();
291  return '<strong class="error">' . $msg . '</strong>';
292  }
293  // remove last level from the stack
294  array_pop( $newExploded );
295  } else {
296  // add the current level to the stack
297  $newExploded[] = $current;
298  }
299  }
300 
301  // we can now join it again
302  return implode( '/', $newExploded );
303  }
304 
314  public static function ifexistCommon(
315  $parser, $frame, $titletext = '', $then = '', $else = ''
316  ) {
317  global $wgContLang;
318  $title = Title::newFromText( $titletext );
319  $wgContLang->findVariantLink( $titletext, $title, true );
320  if ( $title ) {
321  if ( $title->getNamespace() === NS_MEDIA ) {
322  /* If namespace is specified as NS_MEDIA, then we want to
323  * check the physical file, not the "description" page.
324  */
325  if ( !$parser->incrementExpensiveFunctionCount() ) {
326  return $else;
327  }
328  $file = wfFindFile( $title );
329  if ( !$file ) {
330  return $else;
331  }
332  $parser->mOutput->addImage(
333  $file->getName(), $file->getTimestamp(), $file->getSha1() );
334  return $file->exists() ? $then : $else;
335  } elseif ( $title->isSpecialPage() ) {
336  /* Don't bother with the count for special pages,
337  * since their existence can be checked without
338  * accessing the database.
339  */
340  return MediaWikiServices::getInstance()->getSpecialPageFactory()
341  ->exists( $title->getDBkey() ) ? $then : $else;
342  } elseif ( $title->isExternal() ) {
343  /* Can't check the existence of pages on other sites,
344  * so just return $else. Makes a sort of sense, since
345  * they don't exist _locally_.
346  */
347  return $else;
348  } else {
349  $pdbk = $title->getPrefixedDBkey();
350  $lc = LinkCache::singleton();
351  $id = $lc->getGoodLinkID( $pdbk );
352  if ( $id !== 0 ) {
353  $parser->mOutput->addLink( $title, $id );
354  return $then;
355  } elseif ( $lc->isBadLink( $pdbk ) ) {
356  $parser->mOutput->addLink( $title, 0 );
357  return $else;
358  }
359  if ( !$parser->incrementExpensiveFunctionCount() ) {
360  return $else;
361  }
362  $id = $title->getArticleID();
363  $parser->mOutput->addLink( $title, $id );
364 
365  // bug 70495: don't just check whether the ID != 0
366  if ( $title->exists() ) {
367  return $then;
368  }
369  }
370  }
371  return $else;
372  }
373 
380  public static function ifexistObj( $parser, $frame, $args ) {
381  $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
382  $then = isset( $args[1] ) ? $args[1] : null;
383  $else = isset( $args[2] ) ? $args[2] : null;
384 
385  $result = self::ifexistCommon( $parser, $frame, $title, $then, $else );
386  if ( $result === null ) {
387  return '';
388  } else {
389  return trim( $frame->expand( $result ) );
390  }
391  }
392 
402  public static function timeCommon(
403  $parser, $frame = null, $format = '', $date = '', $language = '', $local = false
404  ) {
405  global $wgLocaltimezone;
407  if ( $date === '' ) {
408  $cacheKey = $parser->getOptions()->getTimestamp();
409  $timestamp = new MWTimestamp( $cacheKey );
410  $date = $timestamp->getTimestamp( TS_ISO_8601 );
411  $useTTL = true;
412  } else {
413  $cacheKey = $date;
414  $useTTL = false;
415  }
416  if ( isset( self::$mTimeCache[$format][$cacheKey][$language][$local] ) ) {
417  $cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local];
418  if ( $useTTL
419  && $cachedVal[1] !== null && $frame && is_callable( [ $frame, 'setTTL' ] )
420  ) {
421  $frame->setTTL( $cachedVal[1] );
422  }
423  return $cachedVal[0];
424  }
425 
426  # compute the timestamp string $ts
427  # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
428 
429  $invalidTime = false;
430 
431  # the DateTime constructor must be used because it throws exceptions
432  # when errors occur, whereas date_create appears to just output a warning
433  # that can't really be detected from within the code
434  try {
435 
436  # Default input timezone is UTC.
437  $utc = new DateTimeZone( 'UTC' );
438 
439  # Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
440  if ( preg_match( '/^[0-9]{4}$/', $date ) ) {
441  $date = '00:00 ' . $date;
442  }
443 
444  # Parse date
445  # UTC is a default input timezone.
446  $dateObject = new DateTime( $date, $utc );
447 
448  # Set output timezone.
449  if ( $local ) {
450  if ( isset( $wgLocaltimezone ) ) {
451  $tz = new DateTimeZone( $wgLocaltimezone );
452  } else {
453  $tz = new DateTimeZone( date_default_timezone_get() );
454  }
455  } else {
456  $tz = $utc;
457  }
458  $dateObject->setTimezone( $tz );
459  # Generate timestamp
460  $ts = $dateObject->format( 'YmdHis' );
461 
462  } catch ( Exception $ex ) {
463  $invalidTime = true;
464  }
465 
466  $ttl = null;
467  # format the timestamp and return the result
468  if ( $invalidTime ) {
469  $result = '<strong class="error">' .
470  wfMessage( 'pfunc_time_error' )->inContentLanguage()->escaped() .
471  '</strong>';
472  } else {
473  self::$mTimeChars += strlen( $format );
474  if ( self::$mTimeChars > self::$mMaxTimeChars ) {
475  return '<strong class="error">' .
476  wfMessage( 'pfunc_time_too_long' )->inContentLanguage()->escaped() .
477  '</strong>';
478  } else {
479  if ( $ts < 0 ) { // Language can't deal with BC years
480  return '<strong class="error">' .
481  wfMessage( 'pfunc_time_too_small' )->inContentLanguage()->escaped() .
482  '</strong>';
483  } elseif ( $ts < 100000000000000 ) { // Language can't deal with years after 9999
484  if ( $language !== '' && Language::isValidBuiltInCode( $language ) ) {
485  // use whatever language is passed as a parameter
486  $langObject = Language::factory( $language );
487  } else {
488  // use wiki's content language
489  $langObject = $parser->getFunctionLang();
490  // $ttl is passed by reference, which doesn't work right on stub objects
491  StubObject::unstub( $langObject );
492  }
493  $result = $langObject->sprintfDate( $format, $ts, $tz, $ttl );
494  } else {
495  return '<strong class="error">' .
496  wfMessage( 'pfunc_time_too_big' )->inContentLanguage()->escaped() .
497  '</strong>';
498  }
499  }
500  }
501  self::$mTimeCache[$format][$cacheKey][$language][$local] = [ $result, $ttl ];
502  if ( $useTTL && $ttl !== null && $frame && is_callable( [ $frame, 'setTTL' ] ) ) {
503  $frame->setTTL( $ttl );
504  }
505  return $result;
506  }
507 
516  public static function time(
517  $parser, $format = '', $date = '', $language = '', $local = false
518  ) {
519  return self::timeCommon( $parser, null, $format, $date, $language, $local );
520  }
521 
528  public static function timeObj( $parser, $frame, $args ) {
529  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
530  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
531  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
532  $local = isset( $args[3] ) && trim( $frame->expand( $args[3] ) );
533  return self::timeCommon( $parser, $frame, $format, $date, $language, $local );
534  }
535 
543  public static function localTime( $parser, $format = '', $date = '', $language = '' ) {
544  return self::timeCommon( $parser, null, $format, $date, $language, true );
545  }
546 
553  public static function localTimeObj( $parser, $frame, $args ) {
554  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
555  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
556  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
557  return self::timeCommon( $parser, $frame, $format, $date, $language, true );
558  }
559 
570  public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
571  $parts = (int)$parts;
572  $offset = (int)$offset;
573  $ntitle = Title::newFromText( $title );
574  if ( $ntitle instanceof Title ) {
575  $bits = explode( '/', $ntitle->getPrefixedText(), 25 );
576  if ( count( $bits ) <= 0 ) {
577  return $ntitle->getPrefixedText();
578  } else {
579  if ( $offset > 0 ) {
580  --$offset;
581  }
582  if ( $parts === 0 ) {
583  return implode( '/', array_slice( $bits, $offset ) );
584  } else {
585  return implode( '/', array_slice( $bits, $offset, $parts ) );
586  }
587  }
588  } else {
589  return $title;
590  }
591  }
592 
598  private static function checkLength( $text ) {
599  global $wgPFStringLengthLimit;
600  return ( mb_strlen( $text ) < $wgPFStringLengthLimit );
601  }
602 
607  private static function tooLongError() {
608  global $wgPFStringLengthLimit;
609  $msg = wfMessage( 'pfunc_string_too_long' )->numParams( $wgPFStringLengthLimit );
610  return '<strong class="error">' . $msg->inContentLanguage()->escaped() . '</strong>';
611  }
612 
621  public static function runLen( $parser, $inStr = '' ) {
622  $inStr = $parser->killMarkers( (string)$inStr );
623  return mb_strlen( $inStr );
624  }
625 
639  public static function runPos( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
640  $inStr = $parser->killMarkers( (string)$inStr );
641  $inNeedle = $parser->killMarkers( (string)$inNeedle );
642 
643  if ( !self::checkLength( $inStr ) ||
644  !self::checkLength( $inNeedle ) ) {
645  return self::tooLongError();
646  }
647 
648  if ( $inNeedle === '' ) {
649  $inNeedle = ' ';
650  }
651 
652  $pos = mb_strpos( $inStr, $inNeedle, min( (int)$inOffset, mb_strlen( $inStr ) ) );
653  if ( $pos === false ) {
654  $pos = '';
655  }
656 
657  return $pos;
658  }
659 
672  public static function runRPos( $parser, $inStr = '', $inNeedle = '' ) {
673  $inStr = $parser->killMarkers( (string)$inStr );
674  $inNeedle = $parser->killMarkers( (string)$inNeedle );
675 
676  if ( !self::checkLength( $inStr ) ||
677  !self::checkLength( $inNeedle ) ) {
678  return self::tooLongError();
679  }
680 
681  if ( $inNeedle === '' ) {
682  $inNeedle = ' ';
683  }
684 
685  $pos = mb_strrpos( $inStr, $inNeedle );
686  if ( $pos === false ) {
687  $pos = -1;
688  }
689 
690  return $pos;
691  }
692 
711  public static function runSub( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
712  $inStr = $parser->killMarkers( (string)$inStr );
713 
714  if ( !self::checkLength( $inStr ) ) {
715  return self::tooLongError();
716  }
717 
718  if ( (int)$inLength === 0 ) {
719  $result = mb_substr( $inStr, (int)$inStart );
720  } else {
721  $result = mb_substr( $inStr, (int)$inStart, (int)$inLength );
722  }
723 
724  return $result;
725  }
726 
738  public static function runCount( $parser, $inStr = '', $inSubStr = '' ) {
739  $inStr = $parser->killMarkers( (string)$inStr );
740  $inSubStr = $parser->killMarkers( (string)$inSubStr );
741 
742  if ( !self::checkLength( $inStr ) ||
743  !self::checkLength( $inSubStr ) ) {
744  return self::tooLongError();
745  }
746 
747  if ( $inSubStr === '' ) {
748  $inSubStr = ' ';
749  }
750 
751  $result = mb_substr_count( $inStr, $inSubStr );
752 
753  return $result;
754  }
755 
771  public static function runReplace( $parser, $inStr = '',
772  $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
773  global $wgPFStringLengthLimit;
774 
775  $inStr = $parser->killMarkers( (string)$inStr );
776  $inReplaceFrom = $parser->killMarkers( (string)$inReplaceFrom );
777  $inReplaceTo = $parser->killMarkers( (string)$inReplaceTo );
778 
779  if ( !self::checkLength( $inStr ) ||
780  !self::checkLength( $inReplaceFrom ) ||
781  !self::checkLength( $inReplaceTo ) ) {
782  return self::tooLongError();
783  }
784 
785  if ( $inReplaceFrom === '' ) {
786  $inReplaceFrom = ' ';
787  }
788 
789  // Precompute limit to avoid generating enormous string:
790  $diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom );
791  if ( $diff > 0 ) {
792  $limit = ( ( $wgPFStringLengthLimit - mb_strlen( $inStr ) ) / $diff ) + 1;
793  } else {
794  $limit = -1;
795  }
796 
797  $inLimit = (int)$inLimit;
798  if ( $inLimit >= 0 ) {
799  if ( $limit > $inLimit || $limit == -1 ) {
800  $limit = $inLimit;
801  }
802  }
803 
804  // Use regex to allow limit and handle UTF-8 correctly.
805  $inReplaceFrom = preg_quote( $inReplaceFrom, '/' );
806  $inReplaceTo = StringUtils::escapeRegexReplacement( $inReplaceTo );
807 
808  $result = preg_replace( '/' . $inReplaceFrom . '/u',
809  $inReplaceTo, $inStr, $limit );
810 
811  if ( !self::checkLength( $result ) ) {
812  return self::tooLongError();
813  }
814 
815  return $result;
816  }
817 
834  public static function runExplode(
835  $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null
836  ) {
837  $inStr = $parser->killMarkers( (string)$inStr );
838  $inDiv = $parser->killMarkers( (string)$inDiv );
839 
840  if ( $inDiv === '' ) {
841  $inDiv = ' ';
842  }
843 
844  if ( !self::checkLength( $inStr ) ||
845  !self::checkLength( $inDiv ) ) {
846  return self::tooLongError();
847  }
848 
849  $inDiv = preg_quote( $inDiv, '/' );
850 
851  $matches = preg_split( '/' . $inDiv . '/u', $inStr, $inLim );
852 
853  if ( $inPos >= 0 && isset( $matches[$inPos] ) ) {
854  $result = $matches[$inPos];
855  } elseif ( $inPos < 0 && isset( $matches[count( $matches ) + $inPos] ) ) {
856  $result = $matches[count( $matches ) + $inPos];
857  } else {
858  $result = '';
859  }
860 
861  return $result;
862  }
863 
872  public static function runUrlDecode( $parser, $inStr = '' ) {
873  $inStr = $parser->killMarkers( (string)$inStr );
874  if ( !self::checkLength( $inStr ) ) {
875  return self::tooLongError();
876  }
877 
878  return urldecode( $inStr );
879  }
880 
893  private static function decodeTrimExpand( $obj, $frame, &$trimExpanded = null ) {
894  $expanded = $frame->expand( $obj );
895  $trimExpanded = trim( $expanded );
896  return trim( Sanitizer::decodeCharReferences( $expanded ) );
897  }
898 }
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:32
ExtParserFunctions\runCount
static runCount( $parser, $inStr='', $inSubStr='')
{{#count: string | substr }}
Definition: ExtParserFunctions.php:738
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:280
MagicWord\get
static get( $id)
Factory: creates an object representing an ID.
Definition: MagicWord.php:127
captcha-old.count
count
Definition: captcha-old.py:249
ExtParserFunctions\ifexistObj
static ifexistObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:380
ExtParserFunctions\$mMaxTimeChars
static $mMaxTimeChars
Definition: ExtParserFunctions.php:9
$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. '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:2034
StringUtils\escapeRegexReplacement
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
Definition: StringUtils.php:323
ExtParserFunctions\rel2abs
static rel2abs( $parser, $to='', $from='')
Returns the absolute path to a subpage, relative to the current article title.
Definition: ExtParserFunctions.php:250
ExtParserFunctions\runRPos
static runRPos( $parser, $inStr='', $inNeedle='')
{{#rpos: string | needle}}
Definition: ExtParserFunctions.php:672
ExtParserFunctions\localTime
static localTime( $parser, $format='', $date='', $language='')
Definition: ExtParserFunctions.php:543
ExtParserFunctions\iferror
static iferror( $parser, $test='', $then='', $else=false)
Definition: ExtParserFunctions.php:138
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
ExtParserFunctions\ifObj
static ifObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:103
ExtParserFunctions\$mTimeCache
static $mTimeCache
Definition: ExtParserFunctions.php:7
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
ExtParserFunctions\runUrlDecode
static runUrlDecode( $parser, $inStr='')
{{#urldecode:string}}
Definition: ExtParserFunctions.php:872
ExtParserFunctions\$mTimeChars
static $mTimeChars
Definition: ExtParserFunctions.php:8
$matches
$matches
Definition: NoLocalSettings.php:24
ExtParserFunctions
Definition: ExtParserFunctions.php:5
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
ExtParserFunctions\ifexistCommon
static ifexistCommon( $parser, $frame, $titletext='', $then='', $else='')
Definition: ExtParserFunctions.php:314
ExtParserFunctions\localTimeObj
static localTimeObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:553
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1841
ExtParserFunctions\iferrorObj
static iferrorObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:157
ExtParserFunctions\runReplace
static runReplace( $parser, $inStr='', $inReplaceFrom='', $inReplaceTo='', $inLimit=-1)
{{replace:string | from | to | limit }}
Definition: ExtParserFunctions.php:771
ExtParserFunctions\titleparts
static titleparts( $parser, $title='', $parts=0, $offset=0)
Obtain a specified number of slash-separated parts of a title, e.g.
Definition: ExtParserFunctions.php:570
ExtParserFunctions\ifexpr
static ifexpr( $parser, $expr='', $then='', $else='')
Definition: ExtParserFunctions.php:64
Language\isValidBuiltInCode
static isValidBuiltInCode( $code)
Returns true if a language code is of a valid form for the purposes of internal customisation of Medi...
Definition: Language.php:411
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2213
ExtParserFunctions\$mExprParser
static $mExprParser
Definition: ExtParserFunctions.php:6
ExtParserFunctions\switchObj
static switchObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:175
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
ExprParser
Definition: ExprParser.php:65
ExtParserFunctions\ifexprObj
static ifexprObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:86
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:2036
ExtParserFunctions\runLen
static runLen( $parser, $inStr='')
{{#len:string}}
Definition: ExtParserFunctions.php:621
ExtParserFunctions\time
static time( $parser, $format='', $date='', $language='', $local=false)
Definition: ExtParserFunctions.php:516
ExtParserFunctions\runPos
static runPos( $parser, $inStr='', $inNeedle='', $inOffset=0)
{{#pos: string | needle | offset}}
Definition: ExtParserFunctions.php:639
wfFindFile
wfFindFile( $title, $options=[])
Find a file.
Definition: GlobalFunctions.php:2734
ExtParserFunctions\checkLength
static checkLength( $text)
Verifies parameter is less than max string length.
Definition: ExtParserFunctions.php:598
ExtParserFunctions\tooLongError
static tooLongError()
Generates error message.
Definition: ExtParserFunctions.php:607
$args
if( $line===false) $args
Definition: cdb.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:39
ExtParserFunctions\getExprParser
static & getExprParser()
Definition: ExtParserFunctions.php:37
ExtParserFunctions\runSub
static runSub( $parser, $inStr='', $inStart=0, $inLength=0)
{{#sub: string | start | length }}
Definition: ExtParserFunctions.php:711
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
$wgLocaltimezone
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
Definition: DefaultSettings.php:3210
LinkCache\singleton
static singleton()
Get an instance of this class.
Definition: LinkCache.php:67
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
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ExtParserFunctions\decodeTrimExpand
static decodeTrimExpand( $obj, $frame, &$trimExpanded=null)
Take a PPNode (-ish thing), expand it, remove entities, and trim.
Definition: ExtParserFunctions.php:893
ExtParserFunctions\expr
static expr( $parser, $expr='')
Definition: ExtParserFunctions.php:49
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:214
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
ExtParserFunctions\timeObj
static timeObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:528
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
ExtParserFunctions\timeCommon
static timeCommon( $parser, $frame=null, $format='', $date='', $language='', $local=false)
Definition: ExtParserFunctions.php:402
ExtParserFunctions\ifeqObj
static ifeqObj( $parser, $frame, $args)
Definition: ExtParserFunctions.php:118
StubObject\unstub
static unstub(&$obj)
Unstubs an object, if it is a stub object.
Definition: StubObject.php:93
$wgContLang
$wgContLang
Definition: Setup.php:809
ExtParserFunctions\runExplode
static runExplode( $parser, $inStr='', $inDiv='', $inPos=0, $inLim=null)
{{#explode:string | delimiter | position | limit}}
Definition: ExtParserFunctions.php:834
ExtParserFunctions\clearState
static clearState( $parser)
Definition: ExtParserFunctions.php:15
ExtParserFunctions\registerClearHook
static registerClearHook()
Register ParserClearState hook.
Definition: ExtParserFunctions.php:25