MediaWiki  1.29.1
ParserFunctions_body.php
Go to the documentation of this file.
1 <?php
2 
4  public static $mExprParser;
5  public static $mTimeCache = array();
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( '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/', $test ) ) {
138  return $then;
139  } elseif ( $else === false ) {
140  return $test;
141  } else {
142  return $else;
143  }
144  }
145 
152  public static function iferrorObj( $parser, $frame, $args ) {
153  $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
154  $then = isset( $args[1] ) ? $args[1] : false;
155  $else = isset( $args[2] ) ? $args[2] : false;
156  $result = self::iferror( $parser, $test, $then, $else );
157  if ( $result === false ) {
158  return '';
159  } else {
160  return trim( $frame->expand( $result ) );
161  }
162  }
163 
170  public static function switchObj( $parser, $frame, $args ) {
171  if ( count( $args ) === 0 ) {
172  return '';
173  }
174  $primary = self::decodeTrimExpand( array_shift( $args ), $frame );
175  $found = $defaultFound = false;
176  $default = null;
177  $lastItemHadNoEquals = false;
178  $lastItem = '';
179  $mwDefault =& MagicWord::get( 'default' );
180  foreach ( $args as $arg ) {
181  $bits = $arg->splitArg();
182  $nameNode = $bits['name'];
183  $index = $bits['index'];
184  $valueNode = $bits['value'];
185 
186  if ( $index === '' ) {
187  # Found "="
188  $lastItemHadNoEquals = false;
189  if ( $found ) {
190  # Multiple input match
191  return trim( $frame->expand( $valueNode ) );
192  } else {
193  $test = self::decodeTrimExpand( $nameNode, $frame );
195  if ( $test == $primary ) {
196  # Found a match, return now
197  return trim( $frame->expand( $valueNode ) );
198  } elseif ( $defaultFound || $mwDefault->matchStartToEnd( $test ) ) {
199  $default = $valueNode;
200  $defaultFound = false;
201  } # else wrong case, continue
202  }
203  } else {
204  # Multiple input, single output
205  # If the value matches, set a flag and continue
206  $lastItemHadNoEquals = true;
207  // $lastItem is an "out" variable
208  $decodedTest = self::decodeTrimExpand( $valueNode, $frame, $lastItem );
210  if ( $decodedTest == $primary ) {
211  $found = true;
212  } elseif ( $mwDefault->matchStartToEnd( $decodedTest ) ) {
213  $defaultFound = true;
214  }
215  }
216  }
217  # Default case
218  # Check if the last item had no = sign, thus specifying the default case
219  if ( $lastItemHadNoEquals ) {
220  return $lastItem;
221  } elseif ( !is_null( $default ) ) {
222  return trim( $frame->expand( $default ) );
223  } else {
224  return '';
225  }
226  }
227 
241  public static function rel2abs( $parser , $to = '' , $from = '' ) {
242 
243  $from = trim( $from );
244  if ( $from === '' ) {
245  $from = $parser->getTitle()->getPrefixedText();
246  }
247 
248  $to = rtrim( $to , ' /' );
249 
250  // if we have an empty path, or just one containing a dot
251  if ( $to === '' || $to === '.' ) {
252  return $from;
253  }
254 
255  // if the path isn't relative
256  if ( substr( $to , 0 , 1 ) !== '/' &&
257  substr( $to , 0 , 2 ) !== './' &&
258  substr( $to , 0 , 3 ) !== '../' &&
259  $to !== '..' )
260  {
261  $from = '';
262  }
263  // Make a long path, containing both, enclose it in /.../
264  $fullPath = '/' . $from . '/' . $to . '/';
265 
266  // remove redundant current path dots
267  $fullPath = preg_replace( '!/(\./)+!', '/', $fullPath );
268 
269  // remove double slashes
270  $fullPath = preg_replace( '!/{2,}!', '/', $fullPath );
271 
272  // remove the enclosing slashes now
273  $fullPath = trim( $fullPath , '/' );
274  $exploded = explode ( '/' , $fullPath );
275  $newExploded = array();
276 
277  foreach ( $exploded as $current ) {
278  if ( $current === '..' ) { // removing one level
279  if ( !count( $newExploded ) ) {
280  // attempted to access a node above root node
281  $msg = wfMessage( 'pfunc_rel2abs_invalid_depth', $fullPath )->inContentLanguage()->escaped();
282  return '<strong class="error">' . $msg . '</strong>';
283  }
284  // remove last level from the stack
285  array_pop( $newExploded );
286  } else {
287  // add the current level to the stack
288  $newExploded[] = $current;
289  }
290  }
291 
292  // we can now join it again
293  return implode( '/' , $newExploded );
294  }
295 
305  public static function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) {
307  $title = Title::newFromText( $titletext );
308  $wgContLang->findVariantLink( $titletext, $title, true );
309  if ( $title ) {
310  if ( $title->getNamespace() === NS_MEDIA ) {
311  /* If namespace is specified as NS_MEDIA, then we want to
312  * check the physical file, not the "description" page.
313  */
314  if ( !$parser->incrementExpensiveFunctionCount() ) {
315  return $else;
316  }
317  $file = wfFindFile( $title );
318  if ( !$file ) {
319  return $else;
320  }
321  $parser->mOutput->addImage(
322  $file->getName(), $file->getTimestamp(), $file->getSha1() );
323  return $file->exists() ? $then : $else;
324  } elseif ( $title->getNamespace() === NS_SPECIAL ) {
325  /* Don't bother with the count for special pages,
326  * since their existence can be checked without
327  * accessing the database.
328  */
329  return SpecialPageFactory::exists( $title->getDBkey() ) ? $then : $else;
330  } elseif ( $title->isExternal() ) {
331  /* Can't check the existence of pages on other sites,
332  * so just return $else. Makes a sort of sense, since
333  * they don't exist _locally_.
334  */
335  return $else;
336  } else {
337  $pdbk = $title->getPrefixedDBkey();
338  $lc = LinkCache::singleton();
339  $id = $lc->getGoodLinkID( $pdbk );
340  if ( $id !== 0 ) {
341  $parser->mOutput->addLink( $title, $id );
342  return $then;
343  } elseif ( $lc->isBadLink( $pdbk ) ) {
344  $parser->mOutput->addLink( $title, 0 );
345  return $else;
346  }
347  if ( !$parser->incrementExpensiveFunctionCount() ) {
348  return $else;
349  }
350  $id = $title->getArticleID();
351  $parser->mOutput->addLink( $title, $id );
352 
353  // bug 70495: don't just check whether the ID != 0
354  if ( $title->exists() ) {
355  return $then;
356  }
357  }
358  }
359  return $else;
360  }
361 
368  public static function ifexistObj( $parser, $frame, $args ) {
369  $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
370  $then = isset( $args[1] ) ? $args[1] : null;
371  $else = isset( $args[2] ) ? $args[2] : null;
372 
373  $result = self::ifexistCommon( $parser, $frame, $title, $then, $else );
374  if ( $result === null ) {
375  return '';
376  } else {
377  return trim( $frame->expand( $result ) );
378  }
379  }
380 
390  public static function timeCommon( $parser, $frame = null, $format = '', $date = '', $language = '', $local = false ) {
391  global $wgLocaltimezone;
393  if ( $date === '' ) {
394  $cacheKey = $parser->getOptions()->getTimestamp();
395  $timestamp = new MWTimestamp( $cacheKey );
396  $date = $timestamp->getTimestamp( TS_ISO_8601 );
397  $useTTL = true;
398  } else {
399  $cacheKey = $date;
400  $useTTL = false;
401  }
402  if ( isset( self::$mTimeCache[$format][$cacheKey][$language][$local] ) ) {
403  $cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local];
404  if ( $useTTL && $cachedVal[1] !== null && $frame && is_callable( array( $frame, 'setTTL' ) ) ) {
405  $frame->setTTL( $cachedVal[1] );
406  }
407  return $cachedVal[0];
408  }
409 
410  # compute the timestamp string $ts
411  # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
412 
413  $invalidTime = false;
414 
415  # the DateTime constructor must be used because it throws exceptions
416  # when errors occur, whereas date_create appears to just output a warning
417  # that can't really be detected from within the code
418  try {
419 
420  # Default input timezone is UTC.
421  $utc = new DateTimeZone( 'UTC' );
422 
423  # Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
424  if ( preg_match( '/^[0-9]{4}$/', $date ) ) {
425  $date = '00:00 '.$date;
426  }
427 
428  # Parse date
429  # UTC is a default input timezone.
430  $dateObject = new DateTime( $date, $utc );
431 
432  # Set output timezone.
433  if ( $local ) {
434  if ( isset( $wgLocaltimezone ) ) {
435  $tz = new DateTimeZone( $wgLocaltimezone );
436  } else {
437  $tz = new DateTimeZone( date_default_timezone_get() );
438  }
439  } else {
440  $tz = $utc;
441  }
442  $dateObject->setTimezone( $tz );
443  # Generate timestamp
444  $ts = $dateObject->format( 'YmdHis' );
445 
446  } catch ( Exception $ex ) {
447  $invalidTime = true;
448  }
449 
450  $ttl = null;
451  # format the timestamp and return the result
452  if ( $invalidTime ) {
453  $result = '<strong class="error">' . wfMessage( 'pfunc_time_error' )->inContentLanguage()->escaped() . '</strong>';
454  } else {
455  self::$mTimeChars += strlen( $format );
456  if ( self::$mTimeChars > self::$mMaxTimeChars ) {
457  return '<strong class="error">' . wfMessage( 'pfunc_time_too_long' )->inContentLanguage()->escaped() . '</strong>';
458  } else {
459  if ( $ts < 0 ) { // Language can't deal with BC years
460  return '<strong class="error">' . wfMessage( 'pfunc_time_too_small' )->inContentLanguage()->escaped() . '</strong>';
461  } elseif ( $ts < 100000000000000 ) { // Language can't deal with years after 9999
462  if ( $language !== '' && Language::isValidBuiltInCode( $language ) ) {
463  // use whatever language is passed as a parameter
464  $langObject = Language::factory( $language );
465  } else {
466  // use wiki's content language
467  $langObject = $parser->getFunctionLang();
468  StubObject::unstub( $langObject ); // $ttl is passed by reference, which doesn't work right on stub objects
469  }
470  $result = $langObject->sprintfDate( $format, $ts, $tz, $ttl );
471  } else {
472  return '<strong class="error">' . wfMessage( 'pfunc_time_too_big' )->inContentLanguage()->escaped() . '</strong>';
473  }
474  }
475  }
476  self::$mTimeCache[$format][$cacheKey][$language][$local] = array( $result, $ttl );
477  if ( $useTTL && $ttl !== null && $frame && is_callable( array( $frame, 'setTTL' ) ) ) {
478  $frame->setTTL( $ttl );
479  }
480  return $result;
481  }
482 
491  public static function time( $parser, $format = '', $date = '', $language = '', $local = false ) {
492  return self::timeCommon( $parser, null, $format, $date, $language, $local );
493  }
494 
495 
502  public static function timeObj( $parser, $frame, $args ) {
503  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
504  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
505  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
506  $local = isset( $args[3] ) && trim( $frame->expand( $args[3] ) );
507  return self::timeCommon( $parser, $frame, $format, $date, $language, $local );
508  }
509 
517  public static function localTime( $parser, $format = '', $date = '', $language = '' ) {
518  return self::timeCommon( $parser, null, $format, $date, $language, true );
519  }
520 
527  public static function localTimeObj( $parser, $frame, $args ) {
528  $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
529  $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
530  $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
531  return self::timeCommon( $parser, $frame, $format, $date, $language, true );
532  }
533 
544  public static function titleparts( $parser, $title = '', $parts = 0, $offset = 0 ) {
545  $parts = (int)$parts;
546  $offset = (int)$offset;
547  $ntitle = Title::newFromText( $title );
548  if ( $ntitle instanceof Title ) {
549  $bits = explode( '/', $ntitle->getPrefixedText(), 25 );
550  if ( count( $bits ) <= 0 ) {
551  return $ntitle->getPrefixedText();
552  } else {
553  if ( $offset > 0 ) {
554  --$offset;
555  }
556  if ( $parts === 0 ) {
557  return implode( '/', array_slice( $bits, $offset ) );
558  } else {
559  return implode( '/', array_slice( $bits, $offset, $parts ) );
560  }
561  }
562  } else {
563  return $title;
564  }
565  }
566 
572  private static function checkLength( $text ) {
573  global $wgPFStringLengthLimit;
574  return ( mb_strlen( $text ) < $wgPFStringLengthLimit );
575  }
576 
581  private static function tooLongError() {
582  global $wgPFStringLengthLimit;
583  $msg = wfMessage( 'pfunc_string_too_long' )->numParams( $wgPFStringLengthLimit );
584  return '<strong class="error">' . $msg->inContentLanguage()->escaped() . '</strong>';
585  }
586 
595  public static function runLen ( $parser, $inStr = '' ) {
596  $inStr = $parser->killMarkers( (string)$inStr );
597  return mb_strlen( $inStr );
598  }
599 
613  public static function runPos ( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
614  $inStr = $parser->killMarkers( (string)$inStr );
615  $inNeedle = $parser->killMarkers( (string)$inNeedle );
616 
617  if ( !self::checkLength( $inStr ) ||
618  !self::checkLength( $inNeedle ) ) {
619  return self::tooLongError();
620  }
621 
622  if ( $inNeedle === '' ) { $inNeedle = ' '; }
623 
624  $pos = mb_strpos( $inStr, $inNeedle, (int)$inOffset );
625  if ( $pos === false ) { $pos = ''; }
626 
627  return $pos;
628  }
629 
642  public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) {
643  $inStr = $parser->killMarkers( (string)$inStr );
644  $inNeedle = $parser->killMarkers( (string)$inNeedle );
645 
646  if ( !self::checkLength( $inStr ) ||
647  !self::checkLength( $inNeedle ) ) {
648  return self::tooLongError();
649  }
650 
651  if ( $inNeedle === '' ) { $inNeedle = ' '; }
652 
653  $pos = mb_strrpos( $inStr, $inNeedle );
654  if ( $pos === false ) { $pos = -1; }
655 
656  return $pos;
657  }
658 
677  public static function runSub ( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
678  $inStr = $parser->killMarkers( (string)$inStr );
679 
680  if ( !self::checkLength( $inStr ) ) {
681  return self::tooLongError();
682  }
683 
684  if ( (int)$inLength === 0 ) {
685  $result = mb_substr( $inStr, (int)$inStart );
686  } else {
687  $result = mb_substr( $inStr, (int)$inStart, (int)$inLength );
688  }
689 
690  return $result;
691  }
692 
704  public static function runCount ( $parser, $inStr = '', $inSubStr = '' ) {
705  $inStr = $parser->killMarkers( (string)$inStr );
706  $inSubStr = $parser->killMarkers( (string)$inSubStr );
707 
708  if ( !self::checkLength( $inStr ) ||
709  !self::checkLength( $inSubStr ) ) {
710  return self::tooLongError();
711  }
712 
713  if ( $inSubStr === '' ) {
714  $inSubStr = ' ';
715  }
716 
717  $result = mb_substr_count( $inStr, $inSubStr );
718 
719  return $result;
720  }
721 
737  public static function runReplace( $parser, $inStr = '',
738  $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
739  global $wgPFStringLengthLimit;
740 
741  $inStr = $parser->killMarkers( (string)$inStr );
742  $inReplaceFrom = $parser->killMarkers( (string)$inReplaceFrom );
743  $inReplaceTo = $parser->killMarkers( (string)$inReplaceTo );
744 
745  if ( !self::checkLength( $inStr ) ||
746  !self::checkLength( $inReplaceFrom ) ||
747  !self::checkLength( $inReplaceTo ) ) {
748  return self::tooLongError();
749  }
750 
751  if ( $inReplaceFrom === '' ) { $inReplaceFrom = ' '; }
752 
753  // Precompute limit to avoid generating enormous string:
754  $diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom );
755  if ( $diff > 0 ) {
756  $limit = ( ( $wgPFStringLengthLimit - mb_strlen( $inStr ) ) / $diff ) + 1;
757  } else {
758  $limit = -1;
759  }
760 
761  $inLimit = (int)$inLimit;
762  if ( $inLimit >= 0 ) {
763  if ( $limit > $inLimit || $limit == -1 ) {
764  $limit = $inLimit;
765  }
766  }
767 
768  // Use regex to allow limit and handle UTF-8 correctly.
769  $inReplaceFrom = preg_quote( $inReplaceFrom, '/' );
770  $inReplaceTo = StringUtils::escapeRegexReplacement( $inReplaceTo );
771 
772  $result = preg_replace( '/' . $inReplaceFrom . '/u',
773  $inReplaceTo, $inStr, $limit );
774 
775  if ( !self::checkLength( $result ) ) {
776  return self::tooLongError();
777  }
778 
779  return $result;
780  }
781 
782 
799  public static function runExplode ( $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null ) {
800  $inStr = $parser->killMarkers( (string)$inStr );
801  $inDiv = $parser->killMarkers( (string)$inDiv );
802 
803  if ( $inDiv === '' ) {
804  $inDiv = ' ';
805  }
806 
807  if ( !self::checkLength( $inStr ) ||
808  !self::checkLength( $inDiv ) ) {
809  return self::tooLongError();
810  }
811 
812  $inDiv = preg_quote( $inDiv, '/' );
813 
814  $matches = preg_split( '/' . $inDiv . '/u', $inStr, $inLim );
815 
816  if ( $inPos >= 0 && isset( $matches[$inPos] ) ) {
817  $result = $matches[$inPos];
818  } elseif ( $inPos < 0 && isset( $matches[count( $matches ) + $inPos] ) ) {
819  $result = $matches[count( $matches ) + $inPos];
820  } else {
821  $result = '';
822  }
823 
824  return $result;
825  }
826 
835  public static function runUrlDecode( $parser, $inStr = '' ) {
836  $inStr = $parser->killMarkers( (string)$inStr );
837  if ( !self::checkLength( $inStr ) ) {
838  return self::tooLongError();
839  }
840 
841  return urldecode( $inStr );
842  }
843 
855  private static function decodeTrimExpand( $obj, $frame, &$trimExpanded = null ) {
856  $expanded = $frame->expand( $obj );
857  $trimExpanded = trim( $expanded );
858  return trim( Sanitizer::decodeCharReferences( $expanded ) );
859  }
860 }
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:704
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:265
captcha-old.count
count
Definition: captcha-old.py:225
ExtParserFunctions\ifexistObj
static ifexistObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:368
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:1954
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:241
ExtParserFunctions\runRPos
static runRPos( $parser, $inStr='', $inNeedle='')
{{#rpos: string | needle}}
Definition: ParserFunctions_body.php:642
ExtParserFunctions\localTime
static localTime( $parser, $format='', $date='', $language='')
Definition: ParserFunctions_body.php:517
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:51
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
ExtParserFunctions\runUrlDecode
static runUrlDecode( $parser, $inStr='')
{{#urldecode:string}}
Definition: ParserFunctions_body.php:835
ExtParserFunctions\$mTimeChars
static $mTimeChars
Definition: ParserFunctions_body.php:6
$matches
$matches
Definition: NoLocalSettings.php:24
ExtParserFunctions
Definition: ParserFunctions_body.php:3
$limit
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers please use GetContentModels hook to make them known to core if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1049
ExtParserFunctions\ifexistCommon
static ifexistCommon( $parser, $frame, $titletext='', $then='', $else='')
Definition: ParserFunctions_body.php:305
ExtParserFunctions\localTimeObj
static localTimeObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:527
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2536
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:152
ExtParserFunctions\runReplace
static runReplace( $parser, $inStr='', $inReplaceFrom='', $inReplaceTo='', $inLimit=-1)
{{replace:string | from | to | limit }}
Definition: ParserFunctions_body.php:737
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:544
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:362
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
ExtParserFunctions\$mExprParser
static $mExprParser
Definition: ParserFunctions_body.php:4
ExtParserFunctions\switchObj
static switchObj( $parser, $frame, $args)
Definition: ParserFunctions_body.php:170
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:50
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:1956
ExtParserFunctions\runLen
static runLen( $parser, $inStr='')
{{#len:string}}
Definition: ParserFunctions_body.php:595
ExtParserFunctions\time
static time( $parser, $format='', $date='', $language='', $local=false)
Definition: ParserFunctions_body.php:491
ExtParserFunctions\runPos
static runPos( $parser, $inStr='', $inNeedle='', $inOffset=0)
{{#pos: string | needle | offset}}
Definition: ParserFunctions_body.php:613
wfFindFile
wfFindFile( $title, $options=[])
Find a file.
Definition: GlobalFunctions.php:3101
ExtParserFunctions\checkLength
static checkLength( $text)
Verifies parameter is less than max string length.
Definition: ParserFunctions_body.php:572
ExtParserFunctions\tooLongError
static tooLongError()
Generates error message.
Definition: ParserFunctions_body.php:581
$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:677
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:110
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:855
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:502
ExtParserFunctions\timeCommon
static timeCommon( $parser, $frame=null, $format='', $date='', $language='', $local=false)
Definition: ParserFunctions_body.php:390
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:94
ExtParserFunctions\runExplode
static runExplode( $parser, $inStr='', $inDiv='', $inPos=0, $inLim=null)
{{#explode:string | delimiter | position | limit}}
Definition: ParserFunctions_body.php:799
ExtParserFunctions\clearState
static clearState( $parser)
Definition: ParserFunctions_body.php:13
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$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