MediaWiki  1.30.0
ParserFunctions_body.php
Go to the documentation of this file.
1 <?php
2 
4  public static $mExprParser;
5  public static $mTimeCache = [];
6  public static $mTimeChars = 0;
7  public static $mMaxTimeChars = 6000; # ~10 seconds
8 
13  public static function clearState( $parser ) {
14  self::$mTimeChars = 0;
15  return true;
16  }
17 
23  public static function registerClearHook() {
24  static $done = false;
25  if ( !$done ) {
27  $wgHooks['ParserClearState'][] = __CLASS__ . '::clearState';
28  $done = true;
29  }
30  }
31 
35  public static function &getExprParser() {
36  if ( !isset( self::$mExprParser ) ) {
37  self::$mExprParser = new ExprParser;
38  }
39  return self::$mExprParser;
40  }
41 
47  public static function expr( $parser, $expr = '' ) {
48  try {
49  return self::getExprParser()->doExpression( $expr );
50  } catch ( ExprError $e ) {
51  return '<strong class="error">' . htmlspecialchars( $e->getMessage() ) . '</strong>';
52  }
53  }
54 
62  public static function ifexpr( $parser, $expr = '', $then = '', $else = '' ) {
63  try {
64  $ret = self::getExprParser()->doExpression( $expr );
65  if ( is_numeric( $ret ) ) {
66  $ret = (float)$ret;
67  }
68  if ( $ret ) {
69  return $then;
70  } else {
71  return $else;
72  }
73  } catch ( ExprError $e ) {
74  return '<strong class="error">' . htmlspecialchars( $e->getMessage() ) . '</strong>';
75  }
76  }
77 
84  public static function ifexprObj( $parser, $frame, $args ) {
85  $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
86  $then = isset( $args[1] ) ? $args[1] : '';
87  $else = isset( $args[2] ) ? $args[2] : '';
88  $result = self::ifexpr( $parser, $expr, $then, $else );
89  if ( is_object( $result ) ) {
90  $result = trim( $frame->expand( $result ) );
91  }
92  return $result;
93  }
94 
101  public static function ifObj( $parser, $frame, $args ) {
102  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
103  if ( $test !== '' ) {
104  return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
105  } else {
106  return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
107  }
108  }
109 
116  public static function ifeqObj( $parser, $frame, $args ) {
117  $left = isset( $args[0] ) ? self::decodeTrimExpand( $args[0], $frame ) : '';
118  $right = isset( $args[1] ) ? self::decodeTrimExpand( $args[1], $frame ) : '';
119 
120  // Strict compare is not possible here. 01 should equal 1 for example.
122  if ( $left == $right ) {
123  return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
124  } else {
125  return isset( $args[3] ) ? trim( $frame->expand( $args[3] ) ) : '';
126  }
127  }
128 
136  public static function iferror( $parser, $test = '', $then = '', $else = false ) {
137  if ( preg_match(
138  '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/',
139  $test )
140  ) {
141  return $then;
142  } elseif ( $else === false ) {
143  return $test;
144  } else {
145  return $else;
146  }
147  }
148 
155  public static function iferrorObj( $parser, $frame, $args ) {
156  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
157  $then = isset( $args[1] ) ? $args[1] : false;
158  $else = isset( $args[2] ) ? $args[2] : false;
159  $result = self::iferror( $parser, $test, $then, $else );
160  if ( $result === false ) {
161  return '';
162  } else {
163  return trim( $frame->expand( $result ) );
164  }
165  }
166 
173  public static function switchObj( $parser, $frame, $args ) {
174  if ( count( $args ) === 0 ) {
175  return '';
176  }
177  $primary = self::decodeTrimExpand( array_shift( $args ), $frame );
178  $found = $defaultFound = false;
179  $default = null;
180  $lastItemHadNoEquals = false;
181  $lastItem = '';
182  $mwDefault =& MagicWord::get( 'default' );
183  foreach ( $args as $arg ) {
184  $bits = $arg->splitArg();
185  $nameNode = $bits['name'];
186  $index = $bits['index'];
187  $valueNode = $bits['value'];
188 
189  if ( $index === '' ) {
190  # Found "="
191  $lastItemHadNoEquals = false;
192  if ( $found ) {
193  # Multiple input match
194  return trim( $frame->expand( $valueNode ) );
195  } else {
196  $test = self::decodeTrimExpand( $nameNode, $frame );
198  if ( $test == $primary ) {
199  # Found a match, return now
200  return trim( $frame->expand( $valueNode ) );
201  } elseif ( $defaultFound || $mwDefault->matchStartToEnd( $test ) ) {
202  $default = $valueNode;
203  $defaultFound = false;
204  } # else wrong case, continue
205  }
206  } else {
207  # Multiple input, single output
208  # If the value matches, set a flag and continue
209  $lastItemHadNoEquals = true;
210  // $lastItem is an "out" variable
211  $decodedTest = self::decodeTrimExpand( $valueNode, $frame, $lastItem );
213  if ( $decodedTest == $primary ) {
214  $found = true;
215  } elseif ( $mwDefault->matchStartToEnd( $decodedTest ) ) {
216  $defaultFound = true;
217  }
218  }
219  }
220  # Default case
221  # Check if the last item had no = sign, thus specifying the default case
222  if ( $lastItemHadNoEquals ) {
223  return $lastItem;
224  } elseif ( !is_null( $default ) ) {
225  return trim( $frame->expand( $default ) );
226  } else {
227  return '';
228  }
229  }
230 
244  public static function rel2abs( $parser , $to = '' , $from = '' ) {
245  $from = trim( $from );
246  if ( $from === '' ) {
247  $from = $parser->getTitle()->getPrefixedText();
248  }
249 
250  $to = rtrim( $to, ' /' );
251 
252  // if we have an empty path, or just one containing a dot
253  if ( $to === '' || $to === '.' ) {
254  return $from;
255  }
256 
257  // if the path isn't relative
258  if ( substr( $to, 0, 1 ) !== '/' &&
259  substr( $to, 0, 2 ) !== './' &&
260  substr( $to, 0, 3 ) !== '../' &&
261  $to !== '..'
262  ) {
263  $from = '';
264  }
265  // Make a long path, containing both, enclose it in /.../
266  $fullPath = '/' . $from . '/' . $to . '/';
267 
268  // remove redundant current path dots
269  $fullPath = preg_replace( '!/(\./)+!', '/', $fullPath );
270 
271  // remove double slashes
272  $fullPath = preg_replace( '!/{2,}!', '/', $fullPath );
273 
274  // remove the enclosing slashes now
275  $fullPath = trim( $fullPath, '/' );
276  $exploded = explode( '/', $fullPath );
277  $newExploded = [];
278 
279  foreach ( $exploded as $current ) {
280  if ( $current === '..' ) { // removing one level
281  if ( !count( $newExploded ) ) {
282  // attempted to access a node above root node
283  $msg = wfMessage( 'pfunc_rel2abs_invalid_depth', $fullPath )
284  ->inContentLanguage()->escaped();
285  return '<strong class="error">' . $msg . '</strong>';
286  }
287  // remove last level from the stack
288  array_pop( $newExploded );
289  } else {
290  // add the current level to the stack
291  $newExploded[] = $current;
292  }
293  }
294 
295  // we can now join it again
296  return implode( '/', $newExploded );
297  }
298 
308  public static function ifexistCommon(
309  $parser, $frame, $titletext = '', $then = '', $else = ''
310  ) {
312  $title = Title::newFromText( $titletext );
313  $wgContLang->findVariantLink( $titletext, $title, true );
314  if ( $title ) {
315  if ( $title->getNamespace() === NS_MEDIA ) {
316  /* If namespace is specified as NS_MEDIA, then we want to
317  * check the physical file, not the "description" page.
318  */
319  if ( !$parser->incrementExpensiveFunctionCount() ) {
320  return $else;
321  }
322  $file = wfFindFile( $title );
323  if ( !$file ) {
324  return $else;
325  }
326  $parser->mOutput->addImage(
327  $file->getName(), $file->getTimestamp(), $file->getSha1() );
328  return $file->exists() ? $then : $else;
329  } elseif ( $title->getNamespace() === NS_SPECIAL ) {
330  /* Don't bother with the count for special pages,
331  * since their existence can be checked without
332  * accessing the database.
333  */
334  return SpecialPageFactory::exists( $title->getDBkey() ) ? $then : $else;
335  } elseif ( $title->isExternal() ) {
336  /* Can't check the existence of pages on other sites,
337  * so just return $else. Makes a sort of sense, since
338  * they don't exist _locally_.
339  */
340  return $else;
341  } else {
342  $pdbk = $title->getPrefixedDBkey();
343  $lc = LinkCache::singleton();
344  $id = $lc->getGoodLinkID( $pdbk );
345  if ( $id !== 0 ) {
346  $parser->mOutput->addLink( $title, $id );
347  return $then;
348  } elseif ( $lc->isBadLink( $pdbk ) ) {
349  $parser->mOutput->addLink( $title, 0 );
350  return $else;
351  }
352  if ( !$parser->incrementExpensiveFunctionCount() ) {
353  return $else;
354  }
355  $id = $title->getArticleID();
356  $parser->mOutput->addLink( $title, $id );
357 
358  // bug 70495: don't just check whether the ID != 0
359  if ( $title->exists() ) {
360  return $then;
361  }
362  }
363  }
364  return $else;
365  }
366 
373  public static function ifexistObj( $parser, $frame, $args ) {
374  $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
375  $then = isset( $args[1] ) ? $args[1] : null;
376  $else = isset( $args[2] ) ? $args[2] : null;
377 
378  $result = self::ifexistCommon( $parser, $frame, $title, $then, $else );
379  if ( $result === null ) {
380  return '';
381  } else {
382  return trim( $frame->expand( $result ) );
383  }
384  }
385 
395  public static function timeCommon(
396  $parser, $frame = null, $format = '', $date = '', $language = '', $local = false
397  ) {
400  if ( $date === '' ) {
401  $cacheKey = $parser->getOptions()->getTimestamp();
402  $timestamp = new MWTimestamp( $cacheKey );
403  $date = $timestamp->getTimestamp( TS_ISO_8601 );
404  $useTTL = true;
405  } else {
406  $cacheKey = $date;
407  $useTTL = false;
408  }
409  if ( isset( self::$mTimeCache[$format][$cacheKey][$language][$local] ) ) {
410  $cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local];
411  if ( $useTTL
412  && $cachedVal[1] !== null && $frame && is_callable( [ $frame, 'setTTL' ] )
413  ) {
414  $frame->setTTL( $cachedVal[1] );
415  }
416  return $cachedVal[0];
417  }
418 
419  # compute the timestamp string $ts
420  # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
421 
422  $invalidTime = false;
423 
424  # the DateTime constructor must be used because it throws exceptions
425  # when errors occur, whereas date_create appears to just output a warning
426  # that can't really be detected from within the code
427  try {
428 
429  # Default input timezone is UTC.
430  $utc = new DateTimeZone( 'UTC' );
431 
432  # Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
433  if ( preg_match( '/^[0-9]{4}$/', $date ) ) {
434  $date = '00:00 '.$date;
435  }
436 
437  # Parse date
438  # UTC is a default input timezone.
439  $dateObject = new DateTime( $date, $utc );
440 
441  # Set output timezone.
442  if ( $local ) {
443  if ( isset( $wgLocaltimezone ) ) {
444  $tz = new DateTimeZone( $wgLocaltimezone );
445  } else {
446  $tz = new DateTimeZone( date_default_timezone_get() );
447  }
448  } else {
449  $tz = $utc;
450  }
451  $dateObject->setTimezone( $tz );
452  # Generate timestamp
453  $ts = $dateObject->format( 'YmdHis' );
454 
455  } catch ( Exception $ex ) {
456  $invalidTime = true;
457  }
458 
459  $ttl = null;
460  # format the timestamp and return the result
461  if ( $invalidTime ) {
462  $result = '<strong class="error">' .
463  wfMessage( 'pfunc_time_error' )->inContentLanguage()->escaped() .
464  '</strong>';
465  } else {
466  self::$mTimeChars += strlen( $format );
467  if ( self::$mTimeChars > self::$mMaxTimeChars ) {
468  return '<strong class="error">' .
469  wfMessage( 'pfunc_time_too_long' )->inContentLanguage()->escaped() .
470  '</strong>';
471  } else {
472  if ( $ts < 0 ) { // Language can't deal with BC years
473  return '<strong class="error">' .
474  wfMessage( 'pfunc_time_too_small' )->inContentLanguage()->escaped() .
475  '</strong>';
476  } elseif ( $ts < 100000000000000 ) { // Language can't deal with years after 9999
477  if ( $language !== '' && Language::isValidBuiltInCode( $language ) ) {
478  // use whatever language is passed as a parameter
479  $langObject = Language::factory( $language );
480  } else {
481  // use wiki's content language
482  $langObject = $parser->getFunctionLang();
483  // $ttl is passed by reference, which doesn't work right on stub objects
484  StubObject::unstub( $langObject );
485  }
486  $result = $langObject->sprintfDate( $format, $ts, $tz, $ttl );
487  } else {
488  return '<strong class="error">' .
489  wfMessage( 'pfunc_time_too_big' )->inContentLanguage()->escaped() .
490  '</strong>';
491  }
492  }
493  }
494  self::$mTimeCache[$format][$cacheKey][$language][$local] = [ $result, $ttl ];
495  if ( $useTTL && $ttl !== null && $frame && is_callable( [ $frame, 'setTTL' ] ) ) {
496  $frame->setTTL( $ttl );
497  }
498  return $result;
499  }
500 
509  public static function time(
510  $parser, $format = '', $date = '', $language = '', $local = false
511  ) {
512  return self::timeCommon( $parser, null, $format, $date, $language, $local );
513  }
514 
521  public static function timeObj( $parser, $frame, $args ) {
522  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
523  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
524  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
525  $local = isset( $args[3] ) && trim( $frame->expand( $args[3] ) );
526  return self::timeCommon( $parser, $frame, $format, $date, $language, $local );
527  }
528 
536  public static function localTime( $parser, $format = '', $date = '', $language = '' ) {
537  return self::timeCommon( $parser, null, $format, $date, $language, true );
538  }
539 
546  public static function localTimeObj( $parser, $frame, $args ) {
547  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
548  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
549  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
550  return self::timeCommon( $parser, $frame, $format, $date, $language, true );
551  }
552 
563  public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
564  $parts = (int)$parts;
565  $offset = (int)$offset;
566  $ntitle = Title::newFromText( $title );
567  if ( $ntitle instanceof Title ) {
568  $bits = explode( '/', $ntitle->getPrefixedText(), 25 );
569  if ( count( $bits ) <= 0 ) {
570  return $ntitle->getPrefixedText();
571  } else {
572  if ( $offset > 0 ) {
573  --$offset;
574  }
575  if ( $parts === 0 ) {
576  return implode( '/', array_slice( $bits, $offset ) );
577  } else {
578  return implode( '/', array_slice( $bits, $offset, $parts ) );
579  }
580  }
581  } else {
582  return $title;
583  }
584  }
585 
591  private static function checkLength( $text ) {
592  global $wgPFStringLengthLimit;
593  return ( mb_strlen( $text ) < $wgPFStringLengthLimit );
594  }
595 
600  private static function tooLongError() {
601  global $wgPFStringLengthLimit;
602  $msg = wfMessage( 'pfunc_string_too_long' )->numParams( $wgPFStringLengthLimit );
603  return '<strong class="error">' . $msg->inContentLanguage()->escaped() . '</strong>';
604  }
605 
614  public static function runLen( $parser, $inStr = '' ) {
615  $inStr = $parser->killMarkers( (string)$inStr );
616  return mb_strlen( $inStr );
617  }
618 
632  public static function runPos( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
633  $inStr = $parser->killMarkers( (string)$inStr );
634  $inNeedle = $parser->killMarkers( (string)$inNeedle );
635 
636  if ( !self::checkLength( $inStr ) ||
637  !self::checkLength( $inNeedle ) ) {
638  return self::tooLongError();
639  }
640 
641  if ( $inNeedle === '' ) {
642  $inNeedle = ' ';
643  }
644 
645  $pos = mb_strpos( $inStr, $inNeedle, (int)$inOffset );
646  if ( $pos === false ) {
647  $pos = '';
648  }
649 
650  return $pos;
651  }
652 
665  public static function runRPos( $parser, $inStr = '', $inNeedle = '' ) {
666  $inStr = $parser->killMarkers( (string)$inStr );
667  $inNeedle = $parser->killMarkers( (string)$inNeedle );
668 
669  if ( !self::checkLength( $inStr ) ||
670  !self::checkLength( $inNeedle ) ) {
671  return self::tooLongError();
672  }
673 
674  if ( $inNeedle === '' ) {
675  $inNeedle = ' ';
676  }
677 
678  $pos = mb_strrpos( $inStr, $inNeedle );
679  if ( $pos === false ) {
680  $pos = -1;
681  }
682 
683  return $pos;
684  }
685 
704  public static function runSub( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
705  $inStr = $parser->killMarkers( (string)$inStr );
706 
707  if ( !self::checkLength( $inStr ) ) {
708  return self::tooLongError();
709  }
710 
711  if ( (int)$inLength === 0 ) {
712  $result = mb_substr( $inStr, (int)$inStart );
713  } else {
714  $result = mb_substr( $inStr, (int)$inStart, (int)$inLength );
715  }
716 
717  return $result;
718  }
719 
731  public static function runCount( $parser, $inStr = '', $inSubStr = '' ) {
732  $inStr = $parser->killMarkers( (string)$inStr );
733  $inSubStr = $parser->killMarkers( (string)$inSubStr );
734 
735  if ( !self::checkLength( $inStr ) ||
736  !self::checkLength( $inSubStr ) ) {
737  return self::tooLongError();
738  }
739 
740  if ( $inSubStr === '' ) {
741  $inSubStr = ' ';
742  }
743 
744  $result = mb_substr_count( $inStr, $inSubStr );
745 
746  return $result;
747  }
748 
764  public static function runReplace( $parser, $inStr = '',
765  $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
766  global $wgPFStringLengthLimit;
767 
768  $inStr = $parser->killMarkers( (string)$inStr );
769  $inReplaceFrom = $parser->killMarkers( (string)$inReplaceFrom );
770  $inReplaceTo = $parser->killMarkers( (string)$inReplaceTo );
771 
772  if ( !self::checkLength( $inStr ) ||
773  !self::checkLength( $inReplaceFrom ) ||
774  !self::checkLength( $inReplaceTo ) ) {
775  return self::tooLongError();
776  }
777 
778  if ( $inReplaceFrom === '' ) {
779  $inReplaceFrom = ' ';
780  }
781 
782  // Precompute limit to avoid generating enormous string:
783  $diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom );
784  if ( $diff > 0 ) {
785  $limit = ( ( $wgPFStringLengthLimit - mb_strlen( $inStr ) ) / $diff ) + 1;
786  } else {
787  $limit = -1;
788  }
789 
790  $inLimit = (int)$inLimit;
791  if ( $inLimit >= 0 ) {
792  if ( $limit > $inLimit || $limit == -1 ) {
793  $limit = $inLimit;
794  }
795  }
796 
797  // Use regex to allow limit and handle UTF-8 correctly.
798  $inReplaceFrom = preg_quote( $inReplaceFrom, '/' );
799  $inReplaceTo = StringUtils::escapeRegexReplacement( $inReplaceTo );
800 
801  $result = preg_replace( '/' . $inReplaceFrom . '/u',
802  $inReplaceTo, $inStr, $limit );
803 
804  if ( !self::checkLength( $result ) ) {
805  return self::tooLongError();
806  }
807 
808  return $result;
809  }
810 
827  public static function runExplode(
828  $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null
829  ) {
830  $inStr = $parser->killMarkers( (string)$inStr );
831  $inDiv = $parser->killMarkers( (string)$inDiv );
832 
833  if ( $inDiv === '' ) {
834  $inDiv = ' ';
835  }
836 
837  if ( !self::checkLength( $inStr ) ||
838  !self::checkLength( $inDiv ) ) {
839  return self::tooLongError();
840  }
841 
842  $inDiv = preg_quote( $inDiv, '/' );
843 
844  $matches = preg_split( '/' . $inDiv . '/u', $inStr, $inLim );
845 
846  if ( $inPos >= 0 && isset( $matches[$inPos] ) ) {
847  $result = $matches[$inPos];
848  } elseif ( $inPos < 0 && isset( $matches[count( $matches ) + $inPos] ) ) {
849  $result = $matches[count( $matches ) + $inPos];
850  } else {
851  $result = '';
852  }
853 
854  return $result;
855  }
856 
865  public static function runUrlDecode( $parser, $inStr = '' ) {
866  $inStr = $parser->killMarkers( (string)$inStr );
867  if ( !self::checkLength( $inStr ) ) {
868  return self::tooLongError();
869  }
870 
871  return urldecode( $inStr );
872  }
873 
886  private static function decodeTrimExpand( $obj, $frame, &$trimExpanded = null ) {
887  $expanded = $frame->expand( $obj );
888  $trimExpanded = trim( $expanded );
889  return trim( Sanitizer::decodeCharReferences( $expanded ) );
890  }
891 }
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:32
ExtParserFunctions\runCount
static runCount( $parser, $inStr='', $inSubStr='')
{{#count: string | substr }}
Definition: ParserFunctions_body.php:731
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:268
captcha-old.count
count
Definition: captcha-old.py:249
ExtParserFunctions\ifexistObj
static ifexistObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:373
ExtParserFunctions\$mMaxTimeChars
static $mMaxTimeChars
Definition: ParserFunctions_body.php:7
$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 '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! 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! 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:1963
StringUtils\escapeRegexReplacement
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
Definition: StringUtils.php:322
MagicWord\get
static & get( $id)
Factory: creates an object representing an ID.
Definition: MagicWord.php:258
ExtParserFunctions\rel2abs
static rel2abs( $parser, $to='', $from='')
Returns the absolute path to a subpage, relative to the current article title.
Definition: ParserFunctions_body.php:244
ExtParserFunctions\runRPos
static runRPos( $parser, $inStr='', $inNeedle='')
{{#rpos: string | needle}}
Definition: ParserFunctions_body.php:665
ExtParserFunctions\localTime
static localTime( $parser, $format='', $date='', $language='')
Definition: ParserFunctions_body.php:536
ExtParserFunctions\iferror
static iferror( $parser, $test='', $then='', $else=false)
Definition: ParserFunctions_body.php:136
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: ParserFunctions_body.php:101
ExtParserFunctions\$mTimeCache
static $mTimeCache
Definition: ParserFunctions_body.php:5
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:54
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
ExtParserFunctions\runUrlDecode
static runUrlDecode( $parser, $inStr='')
{{#urldecode:string}}
Definition: ParserFunctions_body.php:865
ExtParserFunctions\$mTimeChars
static $mTimeChars
Definition: ParserFunctions_body.php:6
$matches
$matches
Definition: NoLocalSettings.php:24
ExtParserFunctions
Definition: ParserFunctions_body.php:3
ExtParserFunctions\ifexistCommon
static ifexistCommon( $parser, $frame, $titletext='', $then='', $else='')
Definition: ParserFunctions_body.php:308
ExtParserFunctions\localTimeObj
static localTimeObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:546
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2572
SpecialPageFactory\exists
static exists( $name)
Check if a given name exist as a special page or as a special page alias.
Definition: SpecialPageFactory.php:366
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ExtParserFunctions\iferrorObj
static iferrorObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:155
ExtParserFunctions\runReplace
static runReplace( $parser, $inStr='', $inReplaceFrom='', $inReplaceTo='', $inLimit=-1)
{{replace:string | from | to | limit }}
Definition: ParserFunctions_body.php:764
ExtParserFunctions\titleparts
static titleparts( $parser, $title='', $parts=0, $offset=0)
Obtain a specified number of slash-separated parts of a title, e.g.
Definition: ParserFunctions_body.php:563
ExtParserFunctions\ifexpr
static ifexpr( $parser, $expr='', $then='', $else='')
Definition: ParserFunctions_body.php:62
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:363
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
ExtParserFunctions\$mExprParser
static $mExprParser
Definition: ParserFunctions_body.php:4
ExtParserFunctions\switchObj
static switchObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:173
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:53
ExprParser
Definition: Expr.php:69
ExtParserFunctions\ifexprObj
static ifexprObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:84
$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:1965
ExtParserFunctions\runLen
static runLen( $parser, $inStr='')
{{#len:string}}
Definition: ParserFunctions_body.php:614
ExtParserFunctions\time
static time( $parser, $format='', $date='', $language='', $local=false)
Definition: ParserFunctions_body.php:509
ExtParserFunctions\runPos
static runPos( $parser, $inStr='', $inNeedle='', $inOffset=0)
{{#pos: string | needle | offset}}
Definition: ParserFunctions_body.php:632
wfFindFile
wfFindFile( $title, $options=[])
Find a file.
Definition: GlobalFunctions.php:2897
ExtParserFunctions\checkLength
static checkLength( $text)
Verifies parameter is less than max string length.
Definition: ParserFunctions_body.php:591
ExtParserFunctions\tooLongError
static tooLongError()
Generates error message.
Definition: ParserFunctions_body.php:600
$args
if( $line===false) $args
Definition: cdb.php:63
Title
Represents a title within MediaWiki.
Definition: Title.php:39
ExtParserFunctions\getExprParser
static & getExprParser()
Definition: ParserFunctions_body.php:35
ExtParserFunctions\runSub
static runSub( $parser, $inStr='', $inStart=0, $inLength=0)
{{#sub: string | start | length }}
Definition: ParserFunctions_body.php:704
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
$wgLocaltimezone
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
Definition: DefaultSettings.php:3131
LinkCache\singleton
static singleton()
Get an instance of this class.
Definition: LinkCache.php:67
ExprError
Definition: Expr.php:53
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: ParserFunctions_body.php:886
ExtParserFunctions\expr
static expr( $parser, $expr='')
Definition: ParserFunctions_body.php:47
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
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 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\timeObj
static timeObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:521
ExtParserFunctions\timeCommon
static timeCommon( $parser, $frame=null, $format='', $date='', $language='', $local=false)
Definition: ParserFunctions_body.php:395
ExtParserFunctions\ifeqObj
static ifeqObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:116
StubObject\unstub
static unstub(&$obj)
Unstubs an object, if it is a stub object.
Definition: StubObject.php:92
ExtParserFunctions\runExplode
static runExplode( $parser, $inStr='', $inDiv='', $inPos=0, $inLim=null)
{{#explode:string | delimiter | position | limit}}
Definition: ParserFunctions_body.php:827
ExtParserFunctions\clearState
static clearState( $parser)
Definition: ParserFunctions_body.php:13
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
ExtParserFunctions\registerClearHook
static registerClearHook()
Register ParserClearState hook.
Definition: ParserFunctions_body.php:23