MediaWiki REL1_34
ParserFunctions.php
Go to the documentation of this file.
1<?php
2
4
5use DateTime;
6use DateTimeZone;
7use Exception;
8use Language;
9use LinkCache;
11use MWTimestamp;
12use Parser;
13use PPFrame;
14use PPNode;
15use Sanitizer;
16use StringUtils;
17use StubObject;
18use Title;
19
26 private static $mExprParser;
27 private static $mTimeCache = [];
28 private static $mTimeChars = 0;
29
31 const MAX_TIME_CHARS = 6000;
32
38 private static function registerClearHook() {
39 static $done = false;
40 if ( !$done ) {
41 global $wgHooks;
42 $wgHooks['ParserClearState'][] = function () {
43 self::$mTimeChars = 0;
44 };
45 $done = true;
46 }
47 }
48
52 private static function &getExprParser() {
53 if ( !isset( self::$mExprParser ) ) {
54 self::$mExprParser = new ExprParser;
55 }
56 return self::$mExprParser;
57 }
58
68 public static function expr( Parser $parser, $expr = '' ) {
69 try {
70 return self::getExprParser()->doExpression( $expr );
71 } catch ( ExprError $e ) {
72 return '<strong class="error">' . htmlspecialchars( $e->getUserFriendlyMessage() ) . '</strong>';
73 }
74 }
75
86 public static function ifexpr( Parser $parser, PPFrame $frame, array $args ) {
87 $expr = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
88 $then = $args[1] ?? '';
89 $else = $args[2] ?? '';
90
91 try {
92 $result = self::getExprParser()->doExpression( $expr );
93 if ( is_numeric( $result ) ) {
94 $result = (float)$result;
95 }
96 $result = $result ? $then : $else;
97 } catch ( ExprError $e ) {
98 return '<strong class="error">' . htmlspecialchars( $e->getUserFriendlyMessage() ) . '</strong>';
99 }
100
101 if ( is_object( $result ) ) {
102 $result = trim( $frame->expand( $result ) );
103 }
104
105 return $result;
106 }
107
118 public static function if( Parser $parser, PPFrame $frame, array $args ) {
119 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
120 if ( $test !== '' ) {
121 return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
122 } else {
123 return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
124 }
125 }
126
137 public static function ifeq( Parser $parser, PPFrame $frame, array $args ) {
138 $left = isset( $args[0] ) ? self::decodeTrimExpand( $args[0], $frame ) : '';
139 $right = isset( $args[1] ) ? self::decodeTrimExpand( $args[1], $frame ) : '';
140
141 // Strict compare is not possible here. 01 should equal 1 for example.
143 if ( $left == $right ) {
144 return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
145 } else {
146 return isset( $args[3] ) ? trim( $frame->expand( $args[3] ) ) : '';
147 }
148 }
149
163 public static function iferror( Parser $parser, PPFrame $frame, array $args ) {
164 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
165 $then = $args[1] ?? false;
166 $else = $args[2] ?? false;
167
168 if ( preg_match(
169 '/<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"/',
170 $test )
171 ) {
172 $result = $then;
173 } elseif ( $else === false ) {
174 $result = $test;
175 } else {
176 $result = $else;
177 }
178 if ( $result === false ) {
179 return '';
180 }
181
182 return trim( $frame->expand( $result ) );
183 }
184
200 public static function switch( Parser $parser, PPFrame $frame, array $args ) {
201 if ( count( $args ) === 0 ) {
202 return '';
203 }
204 $primary = self::decodeTrimExpand( array_shift( $args ), $frame );
205 $found = $defaultFound = false;
206 $default = null;
207 $lastItemHadNoEquals = false;
208 $lastItem = '';
209 $mwDefault = $parser->getMagicWordFactory()->get( 'default' );
210 foreach ( $args as $arg ) {
211 $bits = $arg->splitArg();
212 $nameNode = $bits['name'];
213 $index = $bits['index'];
214 $valueNode = $bits['value'];
215
216 if ( $index === '' ) {
217 # Found "="
218 $lastItemHadNoEquals = false;
219 if ( $found ) {
220 # Multiple input match
221 return trim( $frame->expand( $valueNode ) );
222 } else {
223 $test = self::decodeTrimExpand( $nameNode, $frame );
225 if ( $test == $primary ) {
226 # Found a match, return now
227 return trim( $frame->expand( $valueNode ) );
228 } elseif ( $defaultFound || $mwDefault->matchStartToEnd( $test ) ) {
229 $default = $valueNode;
230 $defaultFound = false;
231 } # else wrong case, continue
232 }
233 } else {
234 # Multiple input, single output
235 # If the value matches, set a flag and continue
236 $lastItemHadNoEquals = true;
237 // $lastItem is an "out" variable
238 $decodedTest = self::decodeTrimExpand( $valueNode, $frame, $lastItem );
240 if ( $decodedTest == $primary ) {
241 $found = true;
242 } elseif ( $mwDefault->matchStartToEnd( $decodedTest ) ) {
243 $defaultFound = true;
244 }
245 }
246 }
247 # Default case
248 # Check if the last item had no = sign, thus specifying the default case
249 if ( $lastItemHadNoEquals ) {
250 return $lastItem;
251 } elseif ( !is_null( $default ) ) {
252 return trim( $frame->expand( $default ) );
253 } else {
254 return '';
255 }
256 }
257
275 public static function rel2abs( Parser $parser, $to = '', $from = '' ) {
276 $from = trim( $from );
277 if ( $from === '' ) {
278 $from = $parser->getTitle()->getPrefixedText();
279 }
280
281 $to = rtrim( $to, ' /' );
282
283 // if we have an empty path, or just one containing a dot
284 if ( $to === '' || $to === '.' ) {
285 return $from;
286 }
287
288 // if the path isn't relative
289 if ( substr( $to, 0, 1 ) !== '/' &&
290 substr( $to, 0, 2 ) !== './' &&
291 substr( $to, 0, 3 ) !== '../' &&
292 $to !== '..'
293 ) {
294 $from = '';
295 }
296 // Make a long path, containing both, enclose it in /.../
297 $fullPath = '/' . $from . '/' . $to . '/';
298
299 // remove redundant current path dots
300 $fullPath = preg_replace( '!/(\./)+!', '/', $fullPath );
301
302 // remove double slashes
303 $fullPath = preg_replace( '!/{2,}!', '/', $fullPath );
304
305 // remove the enclosing slashes now
306 $fullPath = trim( $fullPath, '/' );
307 $exploded = explode( '/', $fullPath );
308 $newExploded = [];
309
310 foreach ( $exploded as $current ) {
311 if ( $current === '..' ) { // removing one level
312 if ( !count( $newExploded ) ) {
313 // attempted to access a node above root node
314 $msg = wfMessage( 'pfunc_rel2abs_invalid_depth', $fullPath )
315 ->inContentLanguage()->escaped();
316 return '<strong class="error">' . $msg . '</strong>';
317 }
318 // remove last level from the stack
319 array_pop( $newExploded );
320 } else {
321 // add the current level to the stack
322 $newExploded[] = $current;
323 }
324 }
325
326 // we can now join it again
327 return implode( '/', $newExploded );
328 }
329
339 private static function ifexistInternal(
340 Parser $parser, PPFrame $frame, $titletext = '', $then = '', $else = ''
341 ) {
342 $title = Title::newFromText( $titletext );
343 $parser->getContentLanguage()->findVariantLink( $titletext, $title, true );
344 if ( $title ) {
345 if ( $title->getNamespace() === NS_MEDIA ) {
346 /* If namespace is specified as NS_MEDIA, then we want to
347 * check the physical file, not the "description" page.
348 */
349 if ( !$parser->incrementExpensiveFunctionCount() ) {
350 return $else;
351 }
353 if ( !$file ) {
354 return $else;
355 }
356 $parser->mOutput->addImage(
357 $file->getName(), $file->getTimestamp(), $file->getSha1() );
358 return $file->exists() ? $then : $else;
359 } elseif ( $title->isSpecialPage() ) {
360 /* Don't bother with the count for special pages,
361 * since their existence can be checked without
362 * accessing the database.
363 */
364 return MediaWikiServices::getInstance()->getSpecialPageFactory()
365 ->exists( $title->getDBkey() ) ? $then : $else;
366 } elseif ( $title->isExternal() ) {
367 /* Can't check the existence of pages on other sites,
368 * so just return $else. Makes a sort of sense, since
369 * they don't exist _locally_.
370 */
371 return $else;
372 } else {
373 $pdbk = $title->getPrefixedDBkey();
374 $lc = LinkCache::singleton();
375 $id = $lc->getGoodLinkID( $pdbk );
376 if ( $id !== 0 ) {
377 $parser->mOutput->addLink( $title, $id );
378 return $then;
379 } elseif ( $lc->isBadLink( $pdbk ) ) {
380 $parser->mOutput->addLink( $title, 0 );
381 return $else;
382 }
383 if ( !$parser->incrementExpensiveFunctionCount() ) {
384 return $else;
385 }
386 $id = $title->getArticleID();
387 $parser->mOutput->addLink( $title, $id );
388
389 // bug 70495: don't just check whether the ID != 0
390 if ( $title->exists() ) {
391 return $then;
392 }
393 }
394 }
395 return $else;
396 }
397
408 public static function ifexist( Parser $parser, PPFrame $frame, array $args ) {
409 $title = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
410 $then = $args[1] ?? null;
411 $else = $args[2] ?? null;
412
413 $result = self::ifexistInternal( $parser, $frame, $title, $then, $else );
414 if ( $result === null ) {
415 return '';
416 } else {
417 return trim( $frame->expand( $result ) );
418 }
419 }
420
432 private static function timeCommon(
433 Parser $parser, PPFrame $frame = null, $format = '', $date = '', $language = '', $local = false
434 ) {
435 global $wgLocaltimezone;
437 if ( $date === '' ) {
438 $cacheKey = $parser->getOptions()->getTimestamp();
439 $timestamp = new MWTimestamp( $cacheKey );
440 $date = $timestamp->getTimestamp( TS_ISO_8601 );
441 $useTTL = true;
442 } else {
443 $cacheKey = $date;
444 $useTTL = false;
445 }
446 if ( isset( self::$mTimeCache[$format][$cacheKey][$language][$local] ) ) {
447 $cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local];
448 if ( $useTTL && $cachedVal[1] !== null && $frame ) {
449 $frame->setTTL( $cachedVal[1] );
450 }
451 return $cachedVal[0];
452 }
453
454 # compute the timestamp string $ts
455 # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
456
457 $invalidTime = false;
458
459 # the DateTime constructor must be used because it throws exceptions
460 # when errors occur, whereas date_create appears to just output a warning
461 # that can't really be detected from within the code
462 try {
463
464 # Default input timezone is UTC.
465 $utc = new DateTimeZone( 'UTC' );
466
467 # Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
468 if ( preg_match( '/^[0-9]{4}$/', $date ) ) {
469 $date = '00:00 ' . $date;
470 }
471
472 # Parse date
473 # UTC is a default input timezone.
474 $dateObject = new DateTime( $date, $utc );
475
476 # Set output timezone.
477 if ( $local ) {
478 if ( isset( $wgLocaltimezone ) ) {
479 $tz = new DateTimeZone( $wgLocaltimezone );
480 } else {
481 $tz = new DateTimeZone( date_default_timezone_get() );
482 }
483 } else {
484 $tz = $utc;
485 }
486 $dateObject->setTimezone( $tz );
487 # Generate timestamp
488 $ts = $dateObject->format( 'YmdHis' );
489
490 } catch ( Exception $ex ) {
491 $invalidTime = true;
492 }
493
494 $ttl = null;
495 # format the timestamp and return the result
496 if ( $invalidTime ) {
497 $result = '<strong class="error">' .
498 wfMessage( 'pfunc_time_error' )->inContentLanguage()->escaped() .
499 '</strong>';
500 } else {
501 self::$mTimeChars += strlen( $format );
502 if ( self::$mTimeChars > self::MAX_TIME_CHARS ) {
503 return '<strong class="error">' .
504 wfMessage( 'pfunc_time_too_long' )->inContentLanguage()->escaped() .
505 '</strong>';
506 } else {
507 if ( $ts < 0 ) { // Language can't deal with BC years
508 return '<strong class="error">' .
509 wfMessage( 'pfunc_time_too_small' )->inContentLanguage()->escaped() .
510 '</strong>';
511 } elseif ( $ts < 100000000000000 ) { // Language can't deal with years after 9999
512 if ( $language !== '' && Language::isValidBuiltInCode( $language ) ) {
513 // use whatever language is passed as a parameter
514 $langObject = Language::factory( $language );
515 } else {
516 // use wiki's content language
517 $langObject = $parser->getFunctionLang();
518 // $ttl is passed by reference, which doesn't work right on stub objects
519 StubObject::unstub( $langObject );
520 }
521 $result = $langObject->sprintfDate( $format, $ts, $tz, $ttl );
522 } else {
523 return '<strong class="error">' .
524 wfMessage( 'pfunc_time_too_big' )->inContentLanguage()->escaped() .
525 '</strong>';
526 }
527 }
528 }
529 self::$mTimeCache[$format][$cacheKey][$language][$local] = [ $result, $ttl ];
530 if ( $useTTL && $ttl !== null && $frame ) {
531 $frame->setTTL( $ttl );
532 }
533 return $result;
534 }
535
548 public static function time( Parser $parser, PPFrame $frame, array $args ) {
549 $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
550 $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
551 $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
552 $local = isset( $args[3] ) && trim( $frame->expand( $args[3] ) );
553 return self::timeCommon( $parser, $frame, $format, $date, $language, $local );
554 }
555
569 public static function localTime( Parser $parser, PPFrame $frame, array $args ) {
570 $format = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
571 $date = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
572 $language = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
573 return self::timeCommon( $parser, $frame, $format, $date, $language, true );
574 }
575
588 public static function titleparts( Parser $parser, $title = '', $parts = 0, $offset = 0 ) {
589 $parts = (int)$parts;
590 $offset = (int)$offset;
591 $ntitle = Title::newFromText( $title );
592 if ( $ntitle instanceof Title ) {
593 $bits = explode( '/', $ntitle->getPrefixedText(), 25 );
594 if ( count( $bits ) <= 0 ) {
595 return $ntitle->getPrefixedText();
596 } else {
597 if ( $offset > 0 ) {
598 --$offset;
599 }
600 if ( $parts === 0 ) {
601 return implode( '/', array_slice( $bits, $offset ) );
602 } else {
603 return implode( '/', array_slice( $bits, $offset, $parts ) );
604 }
605 }
606 } else {
607 return $title;
608 }
609 }
610
617 private static function checkLength( $text ) {
618 global $wgPFStringLengthLimit;
619 return ( mb_strlen( $text ) < $wgPFStringLengthLimit );
620 }
621
626 private static function tooLongError() {
627 global $wgPFStringLengthLimit;
628 $msg = wfMessage( 'pfunc_string_too_long' )->numParams( $wgPFStringLengthLimit );
629 return '<strong class="error">' . $msg->inContentLanguage()->escaped() . '</strong>';
630 }
631
641 public static function runLen( Parser $parser, $inStr = '' ) {
642 $inStr = $parser->killMarkers( (string)$inStr );
643 return mb_strlen( $inStr );
644 }
645
659 public static function runPos( Parser $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
660 $inStr = $parser->killMarkers( (string)$inStr );
661 $inNeedle = $parser->killMarkers( (string)$inNeedle );
662
663 if ( !self::checkLength( $inStr ) ||
664 !self::checkLength( $inNeedle ) ) {
665 return self::tooLongError();
666 }
667
668 if ( $inNeedle === '' ) {
669 $inNeedle = ' ';
670 }
671
672 $pos = mb_strpos( $inStr, $inNeedle, min( (int)$inOffset, mb_strlen( $inStr ) ) );
673 if ( $pos === false ) {
674 $pos = '';
675 }
676
677 return $pos;
678 }
679
692 public static function runRPos( Parser $parser, $inStr = '', $inNeedle = '' ) {
693 $inStr = $parser->killMarkers( (string)$inStr );
694 $inNeedle = $parser->killMarkers( (string)$inNeedle );
695
696 if ( !self::checkLength( $inStr ) ||
697 !self::checkLength( $inNeedle ) ) {
698 return self::tooLongError();
699 }
700
701 if ( $inNeedle === '' ) {
702 $inNeedle = ' ';
703 }
704
705 $pos = mb_strrpos( $inStr, $inNeedle );
706 if ( $pos === false ) {
707 $pos = -1;
708 }
709
710 return $pos;
711 }
712
731 public static function runSub( Parser $parser, $inStr = '', $inStart = 0, $inLength = 0 ) {
732 $inStr = $parser->killMarkers( (string)$inStr );
733
734 if ( !self::checkLength( $inStr ) ) {
735 return self::tooLongError();
736 }
737
738 if ( (int)$inLength === 0 ) {
739 $result = mb_substr( $inStr, (int)$inStart );
740 } else {
741 $result = mb_substr( $inStr, (int)$inStart, (int)$inLength );
742 }
743
744 return $result;
745 }
746
759 public static function runCount( Parser $parser, $inStr = '', $inSubStr = '' ) {
760 $inStr = $parser->killMarkers( (string)$inStr );
761 $inSubStr = $parser->killMarkers( (string)$inSubStr );
762
763 if ( !self::checkLength( $inStr ) ||
764 !self::checkLength( $inSubStr ) ) {
765 return self::tooLongError();
766 }
767
768 if ( $inSubStr === '' ) {
769 $inSubStr = ' ';
770 }
771
772 $result = mb_substr_count( $inStr, $inSubStr );
773
774 return $result;
775 }
776
793 public static function runReplace( Parser $parser, $inStr = '',
794 $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) {
795 global $wgPFStringLengthLimit;
796
797 $inStr = $parser->killMarkers( (string)$inStr );
798 $inReplaceFrom = $parser->killMarkers( (string)$inReplaceFrom );
799 $inReplaceTo = $parser->killMarkers( (string)$inReplaceTo );
800
801 if ( !self::checkLength( $inStr ) ||
802 !self::checkLength( $inReplaceFrom ) ||
803 !self::checkLength( $inReplaceTo ) ) {
804 return self::tooLongError();
805 }
806
807 if ( $inReplaceFrom === '' ) {
808 $inReplaceFrom = ' ';
809 }
810
811 // Precompute limit to avoid generating enormous string:
812 $diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom );
813 if ( $diff > 0 ) {
814 $limit = ( ( $wgPFStringLengthLimit - mb_strlen( $inStr ) ) / $diff ) + 1;
815 } else {
816 $limit = -1;
817 }
818
819 $inLimit = (int)$inLimit;
820 if ( $inLimit >= 0 ) {
821 if ( $limit > $inLimit || $limit == -1 ) {
822 $limit = $inLimit;
823 }
824 }
825
826 // Use regex to allow limit and handle UTF-8 correctly.
827 $inReplaceFrom = preg_quote( $inReplaceFrom, '/' );
828 $inReplaceTo = StringUtils::escapeRegexReplacement( $inReplaceTo );
829
830 $result = preg_replace( '/' . $inReplaceFrom . '/u',
831 $inReplaceTo, $inStr, $limit );
832
833 if ( !self::checkLength( $result ) ) {
834 return self::tooLongError();
835 }
836
837 return $result;
838 }
839
857 public static function runExplode(
858 Parser $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null
859 ) {
860 $inStr = $parser->killMarkers( (string)$inStr );
861 $inDiv = $parser->killMarkers( (string)$inDiv );
862
863 if ( $inDiv === '' ) {
864 $inDiv = ' ';
865 }
866
867 if ( !self::checkLength( $inStr ) ||
868 !self::checkLength( $inDiv ) ) {
869 return self::tooLongError();
870 }
871
872 $inDiv = preg_quote( $inDiv, '/' );
873
874 $matches = preg_split( '/' . $inDiv . '/u', $inStr, $inLim );
875
876 if ( $inPos >= 0 && isset( $matches[$inPos] ) ) {
877 $result = $matches[$inPos];
878 } elseif ( $inPos < 0 && isset( $matches[count( $matches ) + $inPos] ) ) {
879 $result = $matches[count( $matches ) + $inPos];
880 } else {
881 $result = '';
882 }
883
884 return $result;
885 }
886
896 public static function runUrlDecode( Parser $parser, $inStr = '' ) {
897 $inStr = $parser->killMarkers( (string)$inStr );
898 if ( !self::checkLength( $inStr ) ) {
899 return self::tooLongError();
900 }
901
902 return urldecode( $inStr );
903 }
904
917 private static function decodeTrimExpand( $obj, PPFrame $frame, &$trimExpanded = null ) {
918 $expanded = $frame->expand( $obj );
919 $trimExpanded = trim( $expanded );
920 return trim( Sanitizer::decodeCharReferences( $expanded ) );
921 }
922}
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
wfFindFile( $title, $options=[])
Find a file.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
$wgHooks['AdminLinks'][]
if( $line===false) $args
Definition cdb.php:64
Internationalisation code.
Definition Language.php:37
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:400
static factory( $code)
Get a cached or new language object for a given language code.
Definition Language.php:217
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition LinkCache.php:34
static singleton()
Get an instance of this class.
Definition LinkCache.php:79
Library for creating and parsing MW-style timestamps.
getUserFriendlyMessage()
Replacement for getMessage() to prevent message parsing during tests which initializes whole bloody M...
Definition ExprError.php:48
static runLen(Parser $parser, $inStr='')
{{#len:string}}
static ifexist(Parser $parser, PPFrame $frame, array $args)
{{#ifexist: page title | value if exists | value if doesn't exist }}
static titleparts(Parser $parser, $title='', $parts=0, $offset=0)
Obtain a specified number of slash-separated parts of a title, e.g.
static expr(Parser $parser, $expr='')
{{#expr: expression }}
static runPos(Parser $parser, $inStr='', $inNeedle='', $inOffset=0)
{{#pos: string | needle | offset}}
static runExplode(Parser $parser, $inStr='', $inDiv='', $inPos=0, $inLim=null)
{{#explode:string | delimiter | position | limit}}
static runReplace(Parser $parser, $inStr='', $inReplaceFrom='', $inReplaceTo='', $inLimit=-1)
{{#replace:string | from | to | limit }}
static runUrlDecode(Parser $parser, $inStr='')
{{#urldecode:string}}
static runCount(Parser $parser, $inStr='', $inSubStr='')
{{#count: string | substr }}
static time(Parser $parser, PPFrame $frame, array $args)
{{#time: format string }} {{#time: format string | date/time object }} {{#time: format string | date/...
static ifexistInternal(Parser $parser, PPFrame $frame, $titletext='', $then='', $else='')
static runRPos(Parser $parser, $inStr='', $inNeedle='')
{{#rpos: string | needle}}
static runSub(Parser $parser, $inStr='', $inStart=0, $inLength=0)
{{#sub: string | start | length }}
static timeCommon(Parser $parser, PPFrame $frame=null, $format='', $date='', $language='', $local=false)
Used by time() and localTime()
static localTime(Parser $parser, PPFrame $frame, array $args)
{{#timel: ... }}
static registerClearHook()
Register ParserClearState hook.
static ifexpr(Parser $parser, PPFrame $frame, array $args)
{{#ifexpr: expression | value if true | value if false }}
static iferror(Parser $parser, PPFrame $frame, array $args)
{{#iferror: test string | value if error | value if no error }}
static rel2abs(Parser $parser, $to='', $from='')
{{#rel2abs: path }} or {{#rel2abs: path | base path }}
static checkLength( $text)
Verifies parameter is less than max string length.
static ifeq(Parser $parser, PPFrame $frame, array $args)
{{#ifeq: string 1 | string 2 | value if identical | value if different }}
static decodeTrimExpand( $obj, PPFrame $frame, &$trimExpanded=null)
Take a PPNode (-ish thing), expand it, remove entities, and trim.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:74
getMagicWordFactory()
Get the MagicWordFactory that this Parser is using.
Definition Parser.php:1111
getOptions()
Get the ParserOptions object.
Definition Parser.php:992
getTitle()
Accessor for the Title object.
Definition Parser.php:935
getFunctionLang()
Get a language object for use in parser functions such as {{FORMATNUM:}}.
Definition Parser.php:1024
getContentLanguage()
Get the content language that this Parser is using.
Definition Parser.php:1121
incrementExpensiveFunctionCount()
Increment the expensive function count.
Definition Parser.php:4368
killMarkers( $text)
Remove any strip markers found in the given text.
Definition Parser.php:6651
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:33
static decodeCharReferences( $text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string.
A collection of static methods to play with strings.
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
Class to implement stub globals, which are globals that delay loading the their associated module cod...
static unstub(&$obj)
Unstubs an object, if it is a stub object.
Represents a title within MediaWiki.
Definition Title.php:42
const NS_MEDIA
Definition Defines.php:57
setTTL( $ttl)
Set the TTL of the output of this frame and all of its ancestors.
expand( $root, $flags=0)
Expand a document tree node.
There are three types of nodes:
Definition PPNode.php:35
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition ExprError.php:19
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42