MediaWiki  1.33.0
ParserFunctions.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use DateTime;
6 use DateTimeZone;
7 use Exception;
12 use Parser;
13 use PPFrame;
14 use PPNode;
15 use Sanitizer;
18 use Title;
19 
21  public static $mExprParser;
22  public static $mTimeCache = [];
23  public static $mTimeChars = 0;
24 
26  const MAX_TIME_CHARS = 6000;
27 
33  public static function registerClearHook() {
34  static $done = false;
35  if ( !$done ) {
36  global $wgHooks;
37  $wgHooks['ParserClearState'][] = function () {
38  self::$mTimeChars = 0;
39  };
40  $done = true;
41  }
42  }
43 
47  public static function &getExprParser() {
48  if ( !isset( self::$mExprParser ) ) {
49  self::$mExprParser = new ExprParser;
50  }
51  return self::$mExprParser;
52  }
53 
59  public static function expr( $parser, $expr = '' ) {
60  try {
61  return self::getExprParser()->doExpression( $expr );
62  } catch ( ExprError $e ) {
63  return '<strong class="error">' . htmlspecialchars( $e->getMessage() ) . '</strong>';
64  }
65  }
66 
74  public static function ifexpr( $parser, $expr = '', $then = '', $else = '' ) {
75  try {
76  $ret = self::getExprParser()->doExpression( $expr );
77  if ( is_numeric( $ret ) ) {
78  $ret = (float)$ret;
79  }
80  if ( $ret ) {
81  return $then;
82  } else {
83  return $else;
84  }
85  } catch ( ExprError $e ) {
86  return '<strong class="error">' . htmlspecialchars( $e->getMessage() ) . '</strong>';
87  }
88  }
89 
96  public static function ifexprObj( $parser, $frame, $args ) {
97  $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
98  $then = $args[1] ?? '';
99  $else = $args[2] ?? '';
100  $result = self::ifexpr( $parser, $expr, $then, $else );
101  if ( is_object( $result ) ) {
102  $result = trim( $frame->expand( $result ) );
103  }
104  return $result;
105  }
106 
113  public static function ifObj( $parser, $frame, $args ) {
114  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
115  if ( $test !== '' ) {
116  return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
117  } else {
118  return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
119  }
120  }
121 
128  public static function ifeqObj( $parser, $frame, $args ) {
129  $left = isset( $args[0] ) ? self::decodeTrimExpand( $args[0], $frame ) : '';
130  $right = isset( $args[1] ) ? self::decodeTrimExpand( $args[1], $frame ) : '';
131 
132  // Strict compare is not possible here. 01 should equal 1 for example.
134  if ( $left == $right ) {
135  return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
136  } else {
137  return isset( $args[3] ) ? trim( $frame->expand( $args[3] ) ) : '';
138  }
139  }
140 
148  public static function iferror( $parser, $test = '', $then = '', $else = false ) {
149  if ( preg_match(
150  '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/',
151  $test )
152  ) {
153  return $then;
154  } elseif ( $else === false ) {
155  return $test;
156  } else {
157  return $else;
158  }
159  }
160 
167  public static function iferrorObj( $parser, $frame, $args ) {
168  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
169  $then = $args[1] ?? false;
170  $else = $args[2] ?? false;
171  $result = self::iferror( $parser, $test, $then, $else );
172  if ( $result === false ) {
173  return '';
174  } else {
175  return trim( $frame->expand( $result ) );
176  }
177  }
178 
185  public static function switchObj( $parser, $frame, $args ) {
186  if ( count( $args ) === 0 ) {
187  return '';
188  }
189  $primary = self::decodeTrimExpand( array_shift( $args ), $frame );
190  $found = $defaultFound = false;
191  $default = null;
192  $lastItemHadNoEquals = false;
193  $lastItem = '';
194  $mwDefault = $parser->getMagicWordFactory()->get( 'default' );
195  foreach ( $args as $arg ) {
196  $bits = $arg->splitArg();
197  $nameNode = $bits['name'];
198  $index = $bits['index'];
199  $valueNode = $bits['value'];
200 
201  if ( $index === '' ) {
202  # Found "="
203  $lastItemHadNoEquals = false;
204  if ( $found ) {
205  # Multiple input match
206  return trim( $frame->expand( $valueNode ) );
207  } else {
208  $test = self::decodeTrimExpand( $nameNode, $frame );
210  if ( $test == $primary ) {
211  # Found a match, return now
212  return trim( $frame->expand( $valueNode ) );
213  } elseif ( $defaultFound || $mwDefault->matchStartToEnd( $test ) ) {
214  $default = $valueNode;
215  $defaultFound = false;
216  } # else wrong case, continue
217  }
218  } else {
219  # Multiple input, single output
220  # If the value matches, set a flag and continue
221  $lastItemHadNoEquals = true;
222  // $lastItem is an "out" variable
223  $decodedTest = self::decodeTrimExpand( $valueNode, $frame, $lastItem );
225  if ( $decodedTest == $primary ) {
226  $found = true;
227  } elseif ( $mwDefault->matchStartToEnd( $decodedTest ) ) {
228  $defaultFound = true;
229  }
230  }
231  }
232  # Default case
233  # Check if the last item had no = sign, thus specifying the default case
234  if ( $lastItemHadNoEquals ) {
235  return $lastItem;
236  } elseif ( !is_null( $default ) ) {
237  return trim( $frame->expand( $default ) );
238  } else {
239  return '';
240  }
241  }
242 
256  public static function rel2abs( $parser, $to = '', $from = '' ) {
257  $from = trim( $from );
258  if ( $from === '' ) {
259  $from = $parser->getTitle()->getPrefixedText();
260  }
261 
262  $to = rtrim( $to, ' /' );
263 
264  // if we have an empty path, or just one containing a dot
265  if ( $to === '' || $to === '.' ) {
266  return $from;
267  }
268 
269  // if the path isn't relative
270  if ( substr( $to, 0, 1 ) !== '/' &&
271  substr( $to, 0, 2 ) !== './' &&
272  substr( $to, 0, 3 ) !== '../' &&
273  $to !== '..'
274  ) {
275  $from = '';
276  }
277  // Make a long path, containing both, enclose it in /.../
278  $fullPath = '/' . $from . '/' . $to . '/';
279 
280  // remove redundant current path dots
281  $fullPath = preg_replace( '!/(\./)+!', '/', $fullPath );
282 
283  // remove double slashes
284  $fullPath = preg_replace( '!/{2,}!', '/', $fullPath );
285 
286  // remove the enclosing slashes now
287  $fullPath = trim( $fullPath, '/' );
288  $exploded = explode( '/', $fullPath );
289  $newExploded = [];
290 
291  foreach ( $exploded as $current ) {
292  if ( $current === '..' ) { // removing one level
293  if ( !count( $newExploded ) ) {
294  // attempted to access a node above root node
295  $msg = wfMessage( 'pfunc_rel2abs_invalid_depth', $fullPath )
296  ->inContentLanguage()->escaped();
297  return '<strong class="error">' . $msg . '</strong>';
298  }
299  // remove last level from the stack
300  array_pop( $newExploded );
301  } else {
302  // add the current level to the stack
303  $newExploded[] = $current;
304  }
305  }
306 
307  // we can now join it again
308  return implode( '/', $newExploded );
309  }
310 
320  public static function ifexistCommon(
321  $parser, $frame, $titletext = '', $then = '', $else = ''
322  ) {
323  $title = Title::newFromText( $titletext );
324  $parser->getContentLanguage()->findVariantLink( $titletext, $title, true );
325  if ( $title ) {
326  if ( $title->getNamespace() === NS_MEDIA ) {
327  /* If namespace is specified as NS_MEDIA, then we want to
328  * check the physical file, not the "description" page.
329  */
330  if ( !$parser->incrementExpensiveFunctionCount() ) {
331  return $else;
332  }
333  $file = wfFindFile( $title );
334  if ( !$file ) {
335  return $else;
336  }
337  $parser->mOutput->addImage(
338  $file->getName(), $file->getTimestamp(), $file->getSha1() );
339  return $file->exists() ? $then : $else;
340  } elseif ( $title->isSpecialPage() ) {
341  /* Don't bother with the count for special pages,
342  * since their existence can be checked without
343  * accessing the database.
344  */
345  return MediaWikiServices::getInstance()->getSpecialPageFactory()
346  ->exists( $title->getDBkey() ) ? $then : $else;
347  } elseif ( $title->isExternal() ) {
348  /* Can't check the existence of pages on other sites,
349  * so just return $else. Makes a sort of sense, since
350  * they don't exist _locally_.
351  */
352  return $else;
353  } else {
354  $pdbk = $title->getPrefixedDBkey();
355  $lc = LinkCache::singleton();
356  $id = $lc->getGoodLinkID( $pdbk );
357  if ( $id !== 0 ) {
358  $parser->mOutput->addLink( $title, $id );
359  return $then;
360  } elseif ( $lc->isBadLink( $pdbk ) ) {
361  $parser->mOutput->addLink( $title, 0 );
362  return $else;
363  }
364  if ( !$parser->incrementExpensiveFunctionCount() ) {
365  return $else;
366  }
367  $id = $title->getArticleID();
368  $parser->mOutput->addLink( $title, $id );
369 
370  // bug 70495: don't just check whether the ID != 0
371  if ( $title->exists() ) {
372  return $then;
373  }
374  }
375  }
376  return $else;
377  }
378 
385  public static function ifexistObj( $parser, $frame, $args ) {
386  $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
387  $then = $args[1] ?? null;
388  $else = $args[2] ?? null;
389 
390  $result = self::ifexistCommon( $parser, $frame, $title, $then, $else );
391  if ( $result === null ) {
392  return '';
393  } else {
394  return trim( $frame->expand( $result ) );
395  }
396  }
397 
407  public static function timeCommon(
408  $parser, $frame = null, $format = '', $date = '', $language = '', $local = false
409  ) {
410  global $wgLocaltimezone;
412  if ( $date === '' ) {
413  $cacheKey = $parser->getOptions()->getTimestamp();
414  $timestamp = new MWTimestamp( $cacheKey );
415  $date = $timestamp->getTimestamp( TS_ISO_8601 );
416  $useTTL = true;
417  } else {
418  $cacheKey = $date;
419  $useTTL = false;
420  }
421  if ( isset( self::$mTimeCache[$format][$cacheKey][$language][$local] ) ) {
422  $cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local];
423  if ( $useTTL
424  && $cachedVal[1] !== null && $frame && is_callable( [ $frame, 'setTTL' ] )
425  ) {
426  $frame->setTTL( $cachedVal[1] );
427  }
428  return $cachedVal[0];
429  }
430 
431  # compute the timestamp string $ts
432  # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
433 
434  $invalidTime = false;
435 
436  # the DateTime constructor must be used because it throws exceptions
437  # when errors occur, whereas date_create appears to just output a warning
438  # that can't really be detected from within the code
439  try {
440 
441  # Default input timezone is UTC.
442  $utc = new DateTimeZone( 'UTC' );
443 
444  # Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
445  if ( preg_match( '/^[0-9]{4}$/', $date ) ) {
446  $date = '00:00 ' . $date;
447  }
448 
449  # Parse date
450  # UTC is a default input timezone.
451  $dateObject = new DateTime( $date, $utc );
452 
453  # Set output timezone.
454  if ( $local ) {
455  if ( isset( $wgLocaltimezone ) ) {
456  $tz = new DateTimeZone( $wgLocaltimezone );
457  } else {
458  $tz = new DateTimeZone( date_default_timezone_get() );
459  }
460  } else {
461  $tz = $utc;
462  }
463  $dateObject->setTimezone( $tz );
464  # Generate timestamp
465  $ts = $dateObject->format( 'YmdHis' );
466 
467  } catch ( Exception $ex ) {
468  $invalidTime = true;
469  }
470 
471  $ttl = null;
472  # format the timestamp and return the result
473  if ( $invalidTime ) {
474  $result = '<strong class="error">' .
475  wfMessage( 'pfunc_time_error' )->inContentLanguage()->escaped() .
476  '</strong>';
477  } else {
478  self::$mTimeChars += strlen( $format );
479  if ( self::$mTimeChars > self::MAX_TIME_CHARS ) {
480  return '<strong class="error">' .
481  wfMessage( 'pfunc_time_too_long' )->inContentLanguage()->escaped() .
482  '</strong>';
483  } else {
484  if ( $ts < 0 ) { // Language can't deal with BC years
485  return '<strong class="error">' .
486  wfMessage( 'pfunc_time_too_small' )->inContentLanguage()->escaped() .
487  '</strong>';
488  } elseif ( $ts < 100000000000000 ) { // Language can't deal with years after 9999
489  if ( $language !== '' && Language::isValidBuiltInCode( $language ) ) {
490  // use whatever language is passed as a parameter
491  $langObject = Language::factory( $language );
492  } else {
493  // use wiki's content language
494  $langObject = $parser->getFunctionLang();
495  // $ttl is passed by reference, which doesn't work right on stub objects
496  StubObject::unstub( $langObject );
497  }
498  $result = $langObject->sprintfDate( $format, $ts, $tz, $ttl );
499  } else {
500  return '<strong class="error">' .
501  wfMessage( 'pfunc_time_too_big' )->inContentLanguage()->escaped() .
502  '</strong>';
503  }
504  }
505  }
506  self::$mTimeCache[$format][$cacheKey][$language][$local] = [ $result, $ttl ];
507  if ( $useTTL && $ttl !== null && $frame && is_callable( [ $frame, 'setTTL' ] ) ) {
508  $frame->setTTL( $ttl );
509  }
510  return $result;
511  }
512 
521  public static function time(
522  $parser, $format = '', $date = '', $language = '', $local = false
523  ) {
524  return self::timeCommon( $parser, null, $format, $date, $language, $local );
525  }
526 
533  public static function timeObj( $parser, $frame, $args ) {
534  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
535  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
536  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
537  $local = isset( $args[3] ) && trim( $frame->expand( $args[3] ) );
538  return self::timeCommon( $parser, $frame, $format, $date, $language, $local );
539  }
540 
548  public static function localTime( $parser, $format = '', $date = '', $language = '' ) {
549  return self::timeCommon( $parser, null, $format, $date, $language, true );
550  }
551 
558  public static function localTimeObj( $parser, $frame, $args ) {
559  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
560  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
561  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
562  return self::timeCommon( $parser, $frame, $format, $date, $language, true );
563  }
564 
575  public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
576  $parts = (int)$parts;
577  $offset = (int)$offset;
578  $ntitle = Title::newFromText( $title );
579  if ( $ntitle instanceof Title ) {
580  $bits = explode( '/', $ntitle->getPrefixedText(), 25 );
581  if ( count( $bits ) <= 0 ) {
582  return $ntitle->getPrefixedText();
583  } else {
584  if ( $offset > 0 ) {
585  --$offset;
586  }
587  if ( $parts === 0 ) {
588  return implode( '/', array_slice( $bits, $offset ) );
589  } else {
590  return implode( '/', array_slice( $bits, $offset, $parts ) );
591  }
592  }
593  } else {
594  return $title;
595  }
596  }
597 
603  private static function checkLength( $text ) {
604  global $wgPFStringLengthLimit;
605  return ( mb_strlen( $text ) < $wgPFStringLengthLimit );
606  }
607 
612  private static function tooLongError() {
613  global $wgPFStringLengthLimit;
614  $msg = wfMessage( 'pfunc_string_too_long' )->numParams( $wgPFStringLengthLimit );
615  return '<strong class="error">' . $msg->inContentLanguage()->escaped() . '</strong>';
616  }
617 
626  public static function runLen( $parser, $inStr = '' ) {
627  $inStr = $parser->killMarkers( (string)$inStr );
628  return mb_strlen( $inStr );
629  }
630 
644  public static function runPos( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
645  $inStr = $parser->killMarkers( (string)$inStr );
646  $inNeedle = $parser->killMarkers( (string)$inNeedle );
647 
648  if ( !self::checkLength( $inStr ) ||
649  !self::checkLength( $inNeedle ) ) {
650  return self::tooLongError();
651  }
652 
653  if ( $inNeedle === '' ) {
654  $inNeedle = ' ';
655  }
656 
657  $pos = mb_strpos( $inStr, $inNeedle, min( (int)$inOffset, mb_strlen( $inStr ) ) );
658  if ( $pos === false ) {
659  $pos = '';
660  }
661 
662  return $pos;
663  }
664 
677  public static function runRPos( $parser, $inStr = '', $inNeedle = '' ) {
678  $inStr = $parser->killMarkers( (string)$inStr );
679  $inNeedle = $parser->killMarkers( (string)$inNeedle );
680 
681  if ( !self::checkLength( $inStr ) ||
682  !self::checkLength( $inNeedle ) ) {
683  return self::tooLongError();
684  }
685 
686  if ( $inNeedle === '' ) {
687  $inNeedle = ' ';
688  }
689 
690  $pos = mb_strrpos( $inStr, $inNeedle );
691  if ( $pos === false ) {
692  $pos = -1;
693  }
694 
695  return $pos;
696  }
697 
716  public static function runSub( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
717  $inStr = $parser->killMarkers( (string)$inStr );
718 
719  if ( !self::checkLength( $inStr ) ) {
720  return self::tooLongError();
721  }
722 
723  if ( (int)$inLength === 0 ) {
724  $result = mb_substr( $inStr, (int)$inStart );
725  } else {
726  $result = mb_substr( $inStr, (int)$inStart, (int)$inLength );
727  }
728 
729  return $result;
730  }
731 
743  public static function runCount( $parser, $inStr = '', $inSubStr = '' ) {
744  $inStr = $parser->killMarkers( (string)$inStr );
745  $inSubStr = $parser->killMarkers( (string)$inSubStr );
746 
747  if ( !self::checkLength( $inStr ) ||
748  !self::checkLength( $inSubStr ) ) {
749  return self::tooLongError();
750  }
751 
752  if ( $inSubStr === '' ) {
753  $inSubStr = ' ';
754  }
755 
756  $result = mb_substr_count( $inStr, $inSubStr );
757 
758  return $result;
759  }
760 
776  public static function runReplace( $parser, $inStr = '',
777  $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
778  global $wgPFStringLengthLimit;
779 
780  $inStr = $parser->killMarkers( (string)$inStr );
781  $inReplaceFrom = $parser->killMarkers( (string)$inReplaceFrom );
782  $inReplaceTo = $parser->killMarkers( (string)$inReplaceTo );
783 
784  if ( !self::checkLength( $inStr ) ||
785  !self::checkLength( $inReplaceFrom ) ||
786  !self::checkLength( $inReplaceTo ) ) {
787  return self::tooLongError();
788  }
789 
790  if ( $inReplaceFrom === '' ) {
791  $inReplaceFrom = ' ';
792  }
793 
794  // Precompute limit to avoid generating enormous string:
795  $diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom );
796  if ( $diff > 0 ) {
797  $limit = ( ( $wgPFStringLengthLimit - mb_strlen( $inStr ) ) / $diff ) + 1;
798  } else {
799  $limit = -1;
800  }
801 
802  $inLimit = (int)$inLimit;
803  if ( $inLimit >= 0 ) {
804  if ( $limit > $inLimit || $limit == -1 ) {
805  $limit = $inLimit;
806  }
807  }
808 
809  // Use regex to allow limit and handle UTF-8 correctly.
810  $inReplaceFrom = preg_quote( $inReplaceFrom, '/' );
811  $inReplaceTo = StringUtils::escapeRegexReplacement( $inReplaceTo );
812 
813  $result = preg_replace( '/' . $inReplaceFrom . '/u',
814  $inReplaceTo, $inStr, $limit );
815 
816  if ( !self::checkLength( $result ) ) {
817  return self::tooLongError();
818  }
819 
820  return $result;
821  }
822 
839  public static function runExplode(
840  $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null
841  ) {
842  $inStr = $parser->killMarkers( (string)$inStr );
843  $inDiv = $parser->killMarkers( (string)$inDiv );
844 
845  if ( $inDiv === '' ) {
846  $inDiv = ' ';
847  }
848 
849  if ( !self::checkLength( $inStr ) ||
850  !self::checkLength( $inDiv ) ) {
851  return self::tooLongError();
852  }
853 
854  $inDiv = preg_quote( $inDiv, '/' );
855 
856  $matches = preg_split( '/' . $inDiv . '/u', $inStr, $inLim );
857 
858  if ( $inPos >= 0 && isset( $matches[$inPos] ) ) {
859  $result = $matches[$inPos];
860  } elseif ( $inPos < 0 && isset( $matches[count( $matches ) + $inPos] ) ) {
861  $result = $matches[count( $matches ) + $inPos];
862  } else {
863  $result = '';
864  }
865 
866  return $result;
867  }
868 
877  public static function runUrlDecode( $parser, $inStr = '' ) {
878  $inStr = $parser->killMarkers( (string)$inStr );
879  if ( !self::checkLength( $inStr ) ) {
880  return self::tooLongError();
881  }
882 
883  return urldecode( $inStr );
884  }
885 
898  private static function decodeTrimExpand( $obj, $frame, &$trimExpanded = null ) {
899  $expanded = $frame->expand( $obj );
900  $trimExpanded = trim( $expanded );
901  return trim( Sanitizer::decodeCharReferences( $expanded ) );
902  }
903 }
MediaWiki\Extensions\ParserFunctions\ParserFunctions\localTimeObj
static localTimeObj( $parser, $frame, $args)
Definition: ParserFunctions.php:558
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:32
LinkCache
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition: LinkCache.php:34
MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifexprObj
static ifexprObj( $parser, $frame, $args)
Definition: ParserFunctions.php:96
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:306
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runLen
static runLen( $parser, $inStr='')
{{#len:string}}
Definition: ParserFunctions.php:626
MediaWiki\Extensions\ParserFunctions\ParserFunctions\registerClearHook
static registerClearHook()
Register ParserClearState hook.
Definition: ParserFunctions.php:33
MediaWiki\Extensions\ParserFunctions\ExprParser
Definition: ExprParser.php:67
StubObject
Class to implement stub globals, which are globals that delay loading the their associated module cod...
Definition: StubObject.php:45
MediaWiki\Extensions\ParserFunctions\ParserFunctions\timeCommon
static timeCommon( $parser, $frame=null, $format='', $date='', $language='', $local=false)
Definition: ParserFunctions.php:407
captcha-old.count
count
Definition: captcha-old.py:249
StringUtils
A collection of static methods to play with strings.
Definition: StringUtils.php:26
$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. '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 '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:1983
MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifObj
static ifObj( $parser, $frame, $args)
Definition: ParserFunctions.php:113
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runCount
static runCount( $parser, $inStr='', $inSubStr='')
{{#count: string | substr }}
Definition: ParserFunctions.php:743
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runReplace
static runReplace( $parser, $inStr='', $inReplaceFrom='', $inReplaceTo='', $inLimit=-1)
{{replace:string | from | to | limit }}
Definition: ParserFunctions.php:776
StringUtils\escapeRegexReplacement
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
Definition: StringUtils.php:323
MediaWiki\Extensions\ParserFunctions\ParserFunctions\rel2abs
static rel2abs( $parser, $to='', $from='')
Returns the absolute path to a subpage, relative to the current article title.
Definition: ParserFunctions.php:256
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
MediaWiki\Extensions\ParserFunctions\ParserFunctions\$mExprParser
static $mExprParser
Definition: ParserFunctions.php:21
MediaWiki\Extensions\ParserFunctions\ParserFunctions\MAX_TIME_CHARS
const MAX_TIME_CHARS
~10 seconds
Definition: ParserFunctions.php:26
MediaWiki\Extensions\ParserFunctions\ParserFunctions\iferror
static iferror( $parser, $test='', $then='', $else=false)
Definition: ParserFunctions.php:148
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
MediaWiki\Extensions\ParserFunctions\ParserFunctions\$mTimeCache
static $mTimeCache
Definition: ParserFunctions.php:22
MediaWiki\Extensions\ParserFunctions\ParserFunctions\timeObj
static timeObj( $parser, $frame, $args)
Definition: ParserFunctions.php:533
MediaWiki\Extensions\ParserFunctions\ParserFunctions\getExprParser
static & getExprParser()
Definition: ParserFunctions.php:47
$matches
$matches
Definition: NoLocalSettings.php:24
PPNode
There are three types of nodes:
Definition: Preprocessor.php:360
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runSub
static runSub( $parser, $inStr='', $inStart=0, $inLength=0)
{{#sub: string | start | length }}
Definition: ParserFunctions.php:716
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
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1802
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runPos
static runPos( $parser, $inStr='', $inNeedle='', $inOffset=0)
{{#pos: string | needle | offset}}
Definition: ParserFunctions.php:644
MediaWiki\Extensions\ParserFunctions\ParserFunctions\iferrorObj
static iferrorObj( $parser, $frame, $args)
Definition: ParserFunctions.php:167
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:124
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:412
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runExplode
static runExplode( $parser, $inStr='', $inDiv='', $inPos=0, $inLim=null)
{{#explode:string | delimiter | position | limit}}
Definition: ParserFunctions.php:839
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
PPFrame
Definition: Preprocessor.php:166
MediaWiki\Extensions\ParserFunctions
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: ExprError.php:19
$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:1985
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runRPos
static runRPos( $parser, $inStr='', $inNeedle='')
{{#rpos: string | needle}}
Definition: ParserFunctions.php:677
MediaWiki\Extensions\ParserFunctions\ParserFunctions\expr
static expr( $parser, $expr='')
Definition: ParserFunctions.php:59
MediaWiki\Extensions\ParserFunctions\ParserFunctions\$mTimeChars
static $mTimeChars
Definition: ParserFunctions.php:23
MediaWiki\Extensions\ParserFunctions\ParserFunctions\runUrlDecode
static runUrlDecode( $parser, $inStr='')
{{#urldecode:string}}
Definition: ParserFunctions.php:877
wfFindFile
wfFindFile( $title, $options=[])
Find a file.
Definition: GlobalFunctions.php:2677
MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifexistCommon
static ifexistCommon( $parser, $frame, $titletext='', $then='', $else='')
Definition: ParserFunctions.php:320
MediaWiki\Extensions\ParserFunctions\ParserFunctions\switchObj
static switchObj( $parser, $frame, $args)
Definition: ParserFunctions.php:185
MediaWiki\Extensions\ParserFunctions\ParserFunctions\tooLongError
static tooLongError()
Generates error message.
Definition: ParserFunctions.php:612
$args
if( $line===false) $args
Definition: cdb.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:40
MediaWiki\Extensions\ParserFunctions\ParserFunctions\titleparts
static titleparts( $parser, $title='', $parts=0, $offset=0)
Obtain a specified number of slash-separated parts of a title, e.g.
Definition: ParserFunctions.php:575
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
$wgLocaltimezone
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
Definition: DefaultSettings.php:3184
LinkCache\singleton
static singleton()
Get an instance of this class.
Definition: LinkCache.php:67
MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifeqObj
static ifeqObj( $parser, $frame, $args)
Definition: ParserFunctions.php:128
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
MediaWiki\Extensions\ParserFunctions\ParserFunctions\localTime
static localTime( $parser, $format='', $date='', $language='')
Definition: ParserFunctions.php:548
MediaWiki\Extensions\ParserFunctions\ParserFunctions\decodeTrimExpand
static decodeTrimExpand( $obj, $frame, &$trimExpanded=null)
Take a PPNode (-ish thing), expand it, remove entities, and trim.
Definition: ParserFunctions.php:898
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
MediaWiki\Extensions\ParserFunctions\ExprError
Definition: ExprError.php:23
MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifexpr
static ifexpr( $parser, $expr='', $then='', $else='')
Definition: ParserFunctions.php:74
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
MediaWiki\Extensions\ParserFunctions\ParserFunctions\time
static time( $parser, $format='', $date='', $language='', $local=false)
Definition: ParserFunctions.php:521
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
MediaWiki\Extensions\ParserFunctions\ParserFunctions\checkLength
static checkLength( $text)
Verifies parameter is less than max string length.
Definition: ParserFunctions.php:603
StubObject\unstub
static unstub(&$obj)
Unstubs an object, if it is a stub object.
Definition: StubObject.php:93
MediaWiki\Extensions\ParserFunctions\ParserFunctions\ifexistObj
static ifexistObj( $parser, $frame, $args)
Definition: ParserFunctions.php:385
Language
Internationalisation code.
Definition: Language.php:36
MediaWiki\Extensions\ParserFunctions\ParserFunctions
Definition: ParserFunctions.php:20