4 * Various core parser functions, registered in Parser::firstCallInit()
7 class CoreParserFunctions
{
8 static function register( $parser ) {
9 global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;
11 # Syntax for arguments (see self::setFunctionHook):
12 # "name for lookup in localized magic words array",
14 # optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}
15 # instead of {{#int:...}})
17 $parser->setFunctionHook( 'int', array( __CLASS__
, 'intFunction' ), SFH_NO_HASH
);
18 $parser->setFunctionHook( 'ns', array( __CLASS__
, 'ns' ), SFH_NO_HASH
);
19 $parser->setFunctionHook( 'nse', array( __CLASS__
, 'nse' ), SFH_NO_HASH
);
20 $parser->setFunctionHook( 'urlencode', array( __CLASS__
, 'urlencode' ), SFH_NO_HASH
);
21 $parser->setFunctionHook( 'lcfirst', array( __CLASS__
, 'lcfirst' ), SFH_NO_HASH
);
22 $parser->setFunctionHook( 'ucfirst', array( __CLASS__
, 'ucfirst' ), SFH_NO_HASH
);
23 $parser->setFunctionHook( 'lc', array( __CLASS__
, 'lc' ), SFH_NO_HASH
);
24 $parser->setFunctionHook( 'uc', array( __CLASS__
, 'uc' ), SFH_NO_HASH
);
25 $parser->setFunctionHook( 'localurl', array( __CLASS__
, 'localurl' ), SFH_NO_HASH
);
26 $parser->setFunctionHook( 'localurle', array( __CLASS__
, 'localurle' ), SFH_NO_HASH
);
27 $parser->setFunctionHook( 'fullurl', array( __CLASS__
, 'fullurl' ), SFH_NO_HASH
);
28 $parser->setFunctionHook( 'fullurle', array( __CLASS__
, 'fullurle' ), SFH_NO_HASH
);
29 $parser->setFunctionHook( 'formatnum', array( __CLASS__
, 'formatnum' ), SFH_NO_HASH
);
30 $parser->setFunctionHook( 'grammar', array( __CLASS__
, 'grammar' ), SFH_NO_HASH
);
31 $parser->setFunctionHook( 'gender', array( __CLASS__
, 'gender' ), SFH_NO_HASH
);
32 $parser->setFunctionHook( 'plural', array( __CLASS__
, 'plural' ), SFH_NO_HASH
);
33 $parser->setFunctionHook( 'numberofpages', array( __CLASS__
, 'numberofpages' ), SFH_NO_HASH
);
34 $parser->setFunctionHook( 'numberofusers', array( __CLASS__
, 'numberofusers' ), SFH_NO_HASH
);
35 $parser->setFunctionHook( 'numberofactiveusers', array( __CLASS__
, 'numberofactiveusers' ), SFH_NO_HASH
);
36 $parser->setFunctionHook( 'numberofarticles', array( __CLASS__
, 'numberofarticles' ), SFH_NO_HASH
);
37 $parser->setFunctionHook( 'numberoffiles', array( __CLASS__
, 'numberoffiles' ), SFH_NO_HASH
);
38 $parser->setFunctionHook( 'numberofadmins', array( __CLASS__
, 'numberofadmins' ), SFH_NO_HASH
);
39 $parser->setFunctionHook( 'numberingroup', array( __CLASS__
, 'numberingroup' ), SFH_NO_HASH
);
40 $parser->setFunctionHook( 'numberofedits', array( __CLASS__
, 'numberofedits' ), SFH_NO_HASH
);
41 $parser->setFunctionHook( 'numberofviews', array( __CLASS__
, 'numberofviews' ), SFH_NO_HASH
);
42 $parser->setFunctionHook( 'language', array( __CLASS__
, 'language' ), SFH_NO_HASH
);
43 $parser->setFunctionHook( 'padleft', array( __CLASS__
, 'padleft' ), SFH_NO_HASH
);
44 $parser->setFunctionHook( 'padright', array( __CLASS__
, 'padright' ), SFH_NO_HASH
);
45 $parser->setFunctionHook( 'anchorencode', array( __CLASS__
, 'anchorencode' ), SFH_NO_HASH
);
46 $parser->setFunctionHook( 'special', array( __CLASS__
, 'special' ) );
47 $parser->setFunctionHook( 'defaultsort', array( __CLASS__
, 'defaultsort' ), SFH_NO_HASH
);
48 $parser->setFunctionHook( 'filepath', array( __CLASS__
, 'filepath' ), SFH_NO_HASH
);
49 $parser->setFunctionHook( 'pagesincategory', array( __CLASS__
, 'pagesincategory' ), SFH_NO_HASH
);
50 $parser->setFunctionHook( 'pagesize', array( __CLASS__
, 'pagesize' ), SFH_NO_HASH
);
51 $parser->setFunctionHook( 'protectionlevel', array( __CLASS__
, 'protectionlevel' ), SFH_NO_HASH
);
52 $parser->setFunctionHook( 'namespace', array( __CLASS__
, 'mwnamespace' ), SFH_NO_HASH
);
53 $parser->setFunctionHook( 'namespacee', array( __CLASS__
, 'namespacee' ), SFH_NO_HASH
);
54 $parser->setFunctionHook( 'talkspace', array( __CLASS__
, 'talkspace' ), SFH_NO_HASH
);
55 $parser->setFunctionHook( 'talkspacee', array( __CLASS__
, 'talkspacee' ), SFH_NO_HASH
);
56 $parser->setFunctionHook( 'subjectspace', array( __CLASS__
, 'subjectspace' ), SFH_NO_HASH
);
57 $parser->setFunctionHook( 'subjectspacee', array( __CLASS__
, 'subjectspacee' ), SFH_NO_HASH
);
58 $parser->setFunctionHook( 'pagename', array( __CLASS__
, 'pagename' ), SFH_NO_HASH
);
59 $parser->setFunctionHook( 'pagenamee', array( __CLASS__
, 'pagenamee' ), SFH_NO_HASH
);
60 $parser->setFunctionHook( 'fullpagename', array( __CLASS__
, 'fullpagename' ), SFH_NO_HASH
);
61 $parser->setFunctionHook( 'fullpagenamee', array( __CLASS__
, 'fullpagenamee' ), SFH_NO_HASH
);
62 $parser->setFunctionHook( 'basepagename', array( __CLASS__
, 'basepagename' ), SFH_NO_HASH
);
63 $parser->setFunctionHook( 'basepagenamee', array( __CLASS__
, 'basepagenamee' ), SFH_NO_HASH
);
64 $parser->setFunctionHook( 'subpagename', array( __CLASS__
, 'subpagename' ), SFH_NO_HASH
);
65 $parser->setFunctionHook( 'subpagenamee', array( __CLASS__
, 'subpagenamee' ), SFH_NO_HASH
);
66 $parser->setFunctionHook( 'talkpagename', array( __CLASS__
, 'talkpagename' ), SFH_NO_HASH
);
67 $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__
, 'talkpagenamee' ), SFH_NO_HASH
);
68 $parser->setFunctionHook( 'subjectpagename', array( __CLASS__
, 'subjectpagename' ), SFH_NO_HASH
);
69 $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__
, 'subjectpagenamee' ), SFH_NO_HASH
);
70 $parser->setFunctionHook( 'pipetrick', array( __CLASS__
, 'pipetrick' ), SFH_NO_HASH
);
71 $parser->setFunctionHook( 'pipetricke', array( __CLASS__
, 'pipetricke' ), SFH_NO_HASH
);
72 $parser->setFunctionHook( 'tag', array( __CLASS__
, 'tagObj' ), SFH_OBJECT_ARGS
);
73 $parser->setFunctionHook( 'formatdate', array( __CLASS__
, 'formatDate' ) );
75 if ( $wgAllowDisplayTitle ) {
76 $parser->setFunctionHook( 'displaytitle', array( __CLASS__
, 'displaytitle' ), SFH_NO_HASH
);
78 if ( $wgAllowSlowParserFunctions ) {
79 $parser->setFunctionHook( 'pagesinnamespace', array( __CLASS__
, 'pagesinnamespace' ), SFH_NO_HASH
);
83 static function intFunction( $parser, $part1 = '' /*, ... */ ) {
84 if ( strval( $part1 ) !== '' ) {
85 $args = array_slice( func_get_args(), 2 );
86 $message = wfMsgGetKey( $part1, true, false, false );
87 $message = wfMsgReplaceArgs( $message, $args );
88 $message = $parser->replaceVariables( $message ); // like $wgMessageCache->transform()
91 return array( 'found' => false );
95 static function formatDate( $parser, $date, $defaultPref = null ) {
96 $df = DateFormatter
::getInstance();
100 $pref = $parser->mOptions
->getDateFormat();
102 // Specify a different default date format other than the the normal default
103 // iff the user has 'default' for their setting
104 if ($pref == 'default' && $defaultPref)
105 $pref = $defaultPref;
107 $date = $df->reformat( $pref, $date, array('match-whole') );
111 static function ns( $parser, $part1 = '' ) {
113 if ( intval( $part1 ) ||
$part1 == "0" ) {
114 $index = intval( $part1 );
116 $index = $wgContLang->getNsIndex( str_replace( ' ', '_', $part1 ) );
118 if ( $index !== false ) {
119 return $wgContLang->getFormattedNsText( $index );
121 return array( 'found' => false );
125 static function nse( $parser, $part1 = '' ) {
126 return wfUrlencode( str_replace( ' ', '_', self
::ns( $parser, $part1 ) ) );
129 static function urlencode( $parser, $s = '' ) {
130 return urlencode( $s );
133 static function lcfirst( $parser, $s = '' ) {
135 return $wgContLang->lcfirst( $s );
138 static function ucfirst( $parser, $s = '' ) {
140 return $wgContLang->ucfirst( $s );
143 static function lc( $parser, $s = '' ) {
145 if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
146 return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
148 return $wgContLang->lc( $s );
152 static function uc( $parser, $s = '' ) {
154 if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
155 return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
157 return $wgContLang->uc( $s );
161 static function localurl( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'getLocalURL', $s, $arg ); }
162 static function localurle( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'escapeLocalURL', $s, $arg ); }
163 static function fullurl( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'getFullURL', $s, $arg ); }
164 static function fullurle( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'escapeFullURL', $s, $arg ); }
166 static function urlFunction( $func, $s = '', $arg = null ) {
167 $title = Title
::newFromText( $s );
168 # Due to order of execution of a lot of bits, the values might be encoded
169 # before arriving here; if that's true, then the title can't be created
170 # and the variable will fail. If we can't get a decent title from the first
171 # attempt, url-decode and try for a second.
172 if( is_null( $title ) )
173 $title = Title
::newFromUrl( urldecode( $s ) );
174 if( !is_null( $title ) ) {
175 # Convert NS_MEDIA -> NS_FILE
176 if( $title->getNamespace() == NS_MEDIA
) {
177 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
179 if( !is_null( $arg ) ) {
180 $text = $title->$func( $arg );
182 $text = $title->$func();
186 return array( 'found' => false );
190 static function formatNum( $parser, $num = '', $raw = null) {
191 if ( self
::israw( $raw ) ) {
192 return $parser->getFunctionLang()->parseFormattedNumber( $num );
194 return $parser->getFunctionLang()->formatNum( $num );
198 static function grammar( $parser, $case = '', $word = '' ) {
199 return $parser->getFunctionLang()->convertGrammar( $word, $case );
202 static function gender( $parser, $user ) {
203 wfProfileIn( __METHOD__
);
204 $forms = array_slice( func_get_args(), 2);
207 $gender = User
::getDefaultOption( 'gender' );
210 $title = Title
::newFromText( $user );
212 if (is_object( $title ) && $title->getNamespace() == NS_USER
)
213 $user = $title->getText();
215 // check parameter, or use $wgUser if in interface message
216 $user = User
::newFromName( $user );
218 $gender = $user->getOption( 'gender' );
219 } elseif ( $parser->mOptions
->getInterfaceMessage() ) {
221 $gender = $wgUser->getOption( 'gender' );
223 $ret = $parser->getFunctionLang()->gender( $gender, $forms );
224 wfProfileOut( __METHOD__
);
227 static function plural( $parser, $text = '') {
228 $forms = array_slice( func_get_args(), 2);
229 $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
230 return $parser->getFunctionLang()->convertPlural( $text, $forms );
234 * Override the title of the page when viewed, provided we've been given a
235 * title which will normalise to the canonical title
237 * @param Parser $parser Parent parser
238 * @param string $text Desired title text
241 static function displaytitle( $parser, $text = '' ) {
242 global $wgRestrictDisplayTitle;
244 #parse a limited subset of wiki markup (just the single quote items)
245 $text = $parser->doQuotes( $text );
247 #remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
248 $text = preg_replace( '/' . preg_quote( $parser->uniqPrefix(), '/' ) . '.*?'
249 . preg_quote( Parser
::MARKER_SUFFIX
, '/' ) . '/', '', $text );
251 #list of disallowed tags for DISPLAYTITLE
252 #these will be escaped even though they are allowed in normal wiki text
253 $bad = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
254 'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rp', 'br' );
256 #only requested titles that normalize to the actual title are allowed through
257 #if $wgRestrictDisplayTitle is true (it is by default)
258 #mimic the escaping process that occurs in OutputPage::setPageTitle
259 $text = Sanitizer
::normalizeCharReferences( Sanitizer
::removeHTMLtags( $text, null, array(), array(), $bad ) );
260 $title = Title
::newFromText( Sanitizer
::stripAllTags( $text ) );
262 if( !$wgRestrictDisplayTitle ) {
263 $parser->mOutput
->setDisplayTitle( $text );
265 if ( $title instanceof Title
&& $title->getFragment() == '' && $title->equals( $parser->mTitle
) ) {
266 $parser->mOutput
->setDisplayTitle( $text );
273 static function isRaw( $param ) {
276 $mwRaw =& MagicWord
::get( 'rawsuffix' );
278 if ( is_null( $param ) ) {
281 return $mwRaw->match( $param );
285 static function formatRaw( $num, $raw ) {
286 if( self
::isRaw( $raw ) ) {
290 return $wgContLang->formatNum( $num );
293 static function numberofpages( $parser, $raw = null ) {
294 return self
::formatRaw( SiteStats
::pages(), $raw );
296 static function numberofusers( $parser, $raw = null ) {
297 return self
::formatRaw( SiteStats
::users(), $raw );
299 static function numberofactiveusers( $parser, $raw = null ) {
300 return self
::formatRaw( SiteStats
::activeUsers(), $raw );
302 static function numberofarticles( $parser, $raw = null ) {
303 return self
::formatRaw( SiteStats
::articles(), $raw );
305 static function numberoffiles( $parser, $raw = null ) {
306 return self
::formatRaw( SiteStats
::images(), $raw );
308 static function numberofadmins( $parser, $raw = null ) {
309 return self
::formatRaw( SiteStats
::numberingroup('sysop'), $raw );
311 static function numberofedits( $parser, $raw = null ) {
312 return self
::formatRaw( SiteStats
::edits(), $raw );
314 static function numberofviews( $parser, $raw = null ) {
315 return self
::formatRaw( SiteStats
::views(), $raw );
317 static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
318 return self
::formatRaw( SiteStats
::pagesInNs( intval( $namespace ) ), $raw );
320 static function numberingroup( $parser, $name = '', $raw = null) {
321 return self
::formatRaw( SiteStats
::numberingroup( strtolower( $name ) ), $raw );
326 * Given a title, return the namespace name that would be given by the
327 * corresponding magic word
328 * Note: function name changed to "mwnamespace" rather than "namespace"
329 * to not break PHP 5.3
331 static function mwnamespace( $parser, $title = null ) {
332 $t = Title
::newFromText( $title );
335 return str_replace( '_', ' ', $t->getNsText() );
337 static function namespacee( $parser, $title = null ) {
338 $t = Title
::newFromText( $title );
341 return wfUrlencode( $t->getNsText() );
343 static function talkspace( $parser, $title = null ) {
344 $t = Title
::newFromText( $title );
345 if ( is_null($t) ||
!$t->canTalk() )
347 return str_replace( '_', ' ', $t->getTalkNsText() );
349 static function talkspacee( $parser, $title = null ) {
350 $t = Title
::newFromText( $title );
351 if ( is_null($t) ||
!$t->canTalk() )
353 return wfUrlencode( $t->getTalkNsText() );
355 static function subjectspace( $parser, $title = null ) {
356 $t = Title
::newFromText( $title );
359 return str_replace( '_', ' ', $t->getSubjectNsText() );
361 static function subjectspacee( $parser, $title = null ) {
362 $t = Title
::newFromText( $title );
365 return wfUrlencode( $t->getSubjectNsText() );
368 * Functions to get and normalize pagenames, corresponding to the magic words
371 static function pagename( $parser, $title = null ) {
372 $t = Title
::newFromText( $title );
375 return wfEscapeWikiText( $t->getText() );
377 static function pagenamee( $parser, $title = null ) {
378 $t = Title
::newFromText( $title );
381 return $t->getPartialURL();
383 static function fullpagename( $parser, $title = null ) {
384 $t = Title
::newFromText( $title );
385 if ( is_null($t) ||
!$t->canTalk() )
387 return wfEscapeWikiText( $t->getPrefixedText() );
389 static function fullpagenamee( $parser, $title = null ) {
390 $t = Title
::newFromText( $title );
391 if ( is_null($t) ||
!$t->canTalk() )
393 return $t->getPrefixedURL();
395 static function subpagename( $parser, $title = null ) {
396 $t = Title
::newFromText( $title );
399 return $t->getSubpageText();
401 static function subpagenamee( $parser, $title = null ) {
402 $t = Title
::newFromText( $title );
405 return $t->getSubpageUrlForm();
407 static function basepagename( $parser, $title = null ) {
408 $t = Title
::newFromText( $title );
411 return $t->getBaseText();
413 static function basepagenamee( $parser, $title = null ) {
414 $t = Title
::newFromText( $title );
417 return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) );
419 static function talkpagename( $parser, $title = null ) {
420 $t = Title
::newFromText( $title );
421 if ( is_null($t) ||
!$t->canTalk() )
423 return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
425 static function talkpagenamee( $parser, $title = null ) {
426 $t = Title
::newFromText( $title );
427 if ( is_null($t) ||
!$t->canTalk() )
429 return $t->getTalkPage()->getPrefixedUrl();
431 static function subjectpagename( $parser, $title = null ) {
432 $t = Title
::newFromText( $title );
435 return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
437 static function subjectpagenamee( $parser, $title = null ) {
438 $t = Title
::newFromText( $title );
441 return $t->getSubjectPage()->getPrefixedUrl();
445 * Performs the pipe trick in the same manner as [[title|]] or [[|title]].
446 * {{#pipetrick:title}} == {{#pipetrick:title|}} -> Parser::getPipeTrickText
447 * {{#pipetrick:|title}} -> Parser::getPipeTrickLink (rarer)
448 * See http://en.wikipedia.org/wiki/Help:Pipe_trick and the Parser documentation
449 * for more information.
451 static function pipetrick( $parser, $link = '', $text = '' ) {
453 return $parser->getPipeTrickText( $link );
455 return $parser->getPipeTrickLink( $text );
459 * Performs the pipetrick and then url encodes the result
461 static function pipetricke( $parser, $link = '', $text = '' ) {
462 return wfUrlEncode( str_replace( ' ', '_', self
::pipetrick( $parser, $link, $text ) ) );
466 * Return the number of pages in the given category, or 0 if it's nonexis-
467 * tent. This is an expensive parser function and can't be called too many
470 static function pagesincategory( $parser, $name = '', $raw = null ) {
471 static $cache = array();
472 $category = Category
::newFromName( $name );
474 if( !is_object( $category ) ) {
476 return self
::formatRaw( 0, $raw );
479 # Normalize name for cache
480 $name = $category->getName();
483 if( isset( $cache[$name] ) ) {
484 $count = $cache[$name];
485 } elseif( $parser->incrementExpensiveFunctionCount() ) {
486 $count = $cache[$name] = (int)$category->getPageCount();
488 return self
::formatRaw( $count, $raw );
492 * Return the size of the given page, or 0 if it's nonexistent. This is an
493 * expensive parser function and can't be called too many times per page.
495 * @FIXME This doesn't work correctly on preview for getting the size of
497 * @FIXME Title::getLength() documentation claims that it adds things to
498 * the link cache, so the local cache here should be unnecessary, but in
499 * fact calling getLength() repeatedly for the same $page does seem to
500 * run one query for each call?
502 static function pagesize( $parser, $page = '', $raw = null ) {
503 static $cache = array();
504 $title = Title
::newFromText($page);
506 if( !is_object( $title ) ) {
508 return self
::formatRaw( 0, $raw );
511 # Normalize name for cache
512 $page = $title->getPrefixedText();
515 if( isset( $cache[$page] ) ) {
516 $length = $cache[$page];
517 } elseif( $parser->incrementExpensiveFunctionCount() ) {
518 $rev = Revision
::newFromTitle($title);
519 $id = $rev ?
$rev->getPage() : 0;
520 $length = $cache[$page] = $rev ?
$rev->getSize() : 0;
522 // Register dependency in templatelinks
523 $parser->mOutput
->addTemplate( $title, $id, $rev ?
$rev->getId() : 0 );
525 return self
::formatRaw( $length, $raw );
529 * Returns the requested protection level for the current page
531 static function protectionlevel( $parser, $type = '' ) {
532 $restrictions = $parser->mTitle
->getRestrictions( strtolower( $type ) );
533 # Title::getRestrictions returns an array, its possible it may have
534 # multiple values in the future
535 return implode( $restrictions, ',' );
538 static function language( $parser, $arg = '' ) {
540 $lang = $wgContLang->getLanguageName( strtolower( $arg ) );
541 return $lang != '' ?
$lang : $arg;
545 * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
547 static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
) {
548 $lengthOfPadding = mb_strlen( $padding );
549 if ( $lengthOfPadding == 0 ) return $string;
551 # The remaining length to add counts down to 0 as padding is added
552 $length = min( $length, 500 ) - mb_strlen( $string );
553 # $finalPadding is just $padding repeated enough times so that
554 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
556 while ( $length > 0 ) {
557 # If $length < $lengthofPadding, truncate $padding so we get the
558 # exact length desired.
559 $finalPadding .= mb_substr( $padding, 0, $length );
560 $length -= $lengthOfPadding;
563 if ( $direction == STR_PAD_LEFT
) {
564 return $finalPadding . $string;
566 return $string . $finalPadding;
570 static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
571 return self
::pad( $string, $length, $padding, STR_PAD_LEFT
);
574 static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
575 return self
::pad( $string, $length, $padding );
578 static function anchorencode( $parser, $text ) {
579 $a = urlencode( $text );
580 $a = strtr( $a, array( '%' => '.', '+' => '_' ) );
581 # leave colons alone, however
582 $a = str_replace( '.3A', ':', $a );
586 static function special( $parser, $text ) {
587 $title = SpecialPage
::getTitleForAlias( $text );
589 return $title->getPrefixedText();
591 return wfMsgForContent( 'nosuchspecialpage' );
595 public static function defaultsort( $parser, $text ) {
596 $text = trim( $text );
597 if( strlen( $text ) == 0 )
599 $old = $parser->getCustomDefaultSort();
600 $parser->setDefaultSort( $text );
601 if( $old === false ||
$old == $text )
604 return( '<span class="error">' .
605 wfMsg( 'duplicate-defaultsort',
606 htmlspecialchars( $old ),
607 htmlspecialchars( $text ) ) .
611 public static function filepath( $parser, $name='', $option='' ) {
612 $file = wfFindFile( $name );
614 $url = $file->getFullUrl();
615 if( $option == 'nowiki' ) {
616 return array( $url, 'nowiki' => true );
625 * Parser function to extension tag adaptor
627 public static function tagObj( $parser, $frame, $args ) {
629 if ( !count( $args ) ) {
632 $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
634 if ( count( $args ) ) {
635 $inner = $frame->expand( array_shift( $args ) );
640 $stripList = $parser->getStripList();
641 if ( !in_array( $tagName, $stripList ) ) {
642 return '<span class="error">' .
643 wfMsg( 'unknown_extension_tag', $tagName ) .
647 $attributes = array();
648 foreach ( $args as $arg ) {
649 $bits = $arg->splitArg();
650 if ( strval( $bits['index'] ) === '' ) {
651 $name = trim( $frame->expand( $bits['name'], PPFrame
::STRIP_COMMENTS
) );
652 $value = trim( $frame->expand( $bits['value'] ) );
653 if ( preg_match( '/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
654 $value = isset( $m[1] ) ?
$m[1] : '';
656 $attributes[$name] = $value;
663 'attributes' => $attributes,
664 'close' => "</$tagName>",
666 return $parser->extensionSubstitution( $params, $frame );