3 * Parser functions provided by MediaWiki core
9 * Various core parser functions, registered in Parser::firstCallInit()
12 class CoreParserFunctions
{
13 static function register( $parser ) {
14 global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;
16 # Syntax for arguments (see self::setFunctionHook):
17 # "name for lookup in localized magic words array",
19 # optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
20 # instead of {{#int:...}})
22 $parser->setFunctionHook( 'int', array( __CLASS__
, 'intFunction' ), SFH_NO_HASH
);
23 $parser->setFunctionHook( 'ns', array( __CLASS__
, 'ns' ), SFH_NO_HASH
);
24 $parser->setFunctionHook( 'nse', array( __CLASS__
, 'nse' ), SFH_NO_HASH
);
25 $parser->setFunctionHook( 'urlencode', array( __CLASS__
, 'urlencode' ), SFH_NO_HASH
);
26 $parser->setFunctionHook( 'lcfirst', array( __CLASS__
, 'lcfirst' ), SFH_NO_HASH
);
27 $parser->setFunctionHook( 'ucfirst', array( __CLASS__
, 'ucfirst' ), SFH_NO_HASH
);
28 $parser->setFunctionHook( 'lc', array( __CLASS__
, 'lc' ), SFH_NO_HASH
);
29 $parser->setFunctionHook( 'uc', array( __CLASS__
, 'uc' ), SFH_NO_HASH
);
30 $parser->setFunctionHook( 'localurl', array( __CLASS__
, 'localurl' ), SFH_NO_HASH
);
31 $parser->setFunctionHook( 'localurle', array( __CLASS__
, 'localurle' ), SFH_NO_HASH
);
32 $parser->setFunctionHook( 'fullurl', array( __CLASS__
, 'fullurl' ), SFH_NO_HASH
);
33 $parser->setFunctionHook( 'fullurle', array( __CLASS__
, 'fullurle' ), SFH_NO_HASH
);
34 $parser->setFunctionHook( 'linkurl', array( __CLASS__
, 'linkurl' ), SFH_NO_HASH
);
35 $parser->setFunctionHook( 'formatnum', array( __CLASS__
, 'formatnum' ), SFH_NO_HASH
);
36 $parser->setFunctionHook( 'grammar', array( __CLASS__
, 'grammar' ), SFH_NO_HASH
);
37 $parser->setFunctionHook( 'gender', array( __CLASS__
, 'gender' ), SFH_NO_HASH
);
38 $parser->setFunctionHook( 'plural', array( __CLASS__
, 'plural' ), SFH_NO_HASH
);
39 $parser->setFunctionHook( 'numberofpages', array( __CLASS__
, 'numberofpages' ), SFH_NO_HASH
);
40 $parser->setFunctionHook( 'numberofusers', array( __CLASS__
, 'numberofusers' ), SFH_NO_HASH
);
41 $parser->setFunctionHook( 'numberofactiveusers', array( __CLASS__
, 'numberofactiveusers' ), SFH_NO_HASH
);
42 $parser->setFunctionHook( 'numberofarticles', array( __CLASS__
, 'numberofarticles' ), SFH_NO_HASH
);
43 $parser->setFunctionHook( 'numberoffiles', array( __CLASS__
, 'numberoffiles' ), SFH_NO_HASH
);
44 $parser->setFunctionHook( 'numberofadmins', array( __CLASS__
, 'numberofadmins' ), SFH_NO_HASH
);
45 $parser->setFunctionHook( 'numberingroup', array( __CLASS__
, 'numberingroup' ), SFH_NO_HASH
);
46 $parser->setFunctionHook( 'numberofedits', array( __CLASS__
, 'numberofedits' ), SFH_NO_HASH
);
47 $parser->setFunctionHook( 'numberofviews', array( __CLASS__
, 'numberofviews' ), SFH_NO_HASH
);
48 $parser->setFunctionHook( 'language', array( __CLASS__
, 'language' ), SFH_NO_HASH
);
49 $parser->setFunctionHook( 'padleft', array( __CLASS__
, 'padleft' ), SFH_NO_HASH
);
50 $parser->setFunctionHook( 'padright', array( __CLASS__
, 'padright' ), SFH_NO_HASH
);
51 $parser->setFunctionHook( 'anchorencode', array( __CLASS__
, 'anchorencode' ), SFH_NO_HASH
);
52 $parser->setFunctionHook( 'special', array( __CLASS__
, 'special' ) );
53 $parser->setFunctionHook( 'defaultsort', array( __CLASS__
, 'defaultsort' ), SFH_NO_HASH
);
54 $parser->setFunctionHook( 'filepath', array( __CLASS__
, 'filepath' ), SFH_NO_HASH
);
55 $parser->setFunctionHook( 'pagesincategory', array( __CLASS__
, 'pagesincategory' ), SFH_NO_HASH
);
56 $parser->setFunctionHook( 'pagesize', array( __CLASS__
, 'pagesize' ), SFH_NO_HASH
);
57 $parser->setFunctionHook( 'protectionlevel', array( __CLASS__
, 'protectionlevel' ), SFH_NO_HASH
);
58 $parser->setFunctionHook( 'namespace', array( __CLASS__
, 'mwnamespace' ), SFH_NO_HASH
);
59 $parser->setFunctionHook( 'namespacee', array( __CLASS__
, 'namespacee' ), SFH_NO_HASH
);
60 $parser->setFunctionHook( 'talkspace', array( __CLASS__
, 'talkspace' ), SFH_NO_HASH
);
61 $parser->setFunctionHook( 'talkspacee', array( __CLASS__
, 'talkspacee' ), SFH_NO_HASH
);
62 $parser->setFunctionHook( 'subjectspace', array( __CLASS__
, 'subjectspace' ), SFH_NO_HASH
);
63 $parser->setFunctionHook( 'subjectspacee', array( __CLASS__
, 'subjectspacee' ), SFH_NO_HASH
);
64 $parser->setFunctionHook( 'pagename', array( __CLASS__
, 'pagename' ), SFH_NO_HASH
);
65 $parser->setFunctionHook( 'pagenamee', array( __CLASS__
, 'pagenamee' ), SFH_NO_HASH
);
66 $parser->setFunctionHook( 'fullpagename', array( __CLASS__
, 'fullpagename' ), SFH_NO_HASH
);
67 $parser->setFunctionHook( 'fullpagenamee', array( __CLASS__
, 'fullpagenamee' ), SFH_NO_HASH
);
68 $parser->setFunctionHook( 'basepagename', array( __CLASS__
, 'basepagename' ), SFH_NO_HASH
);
69 $parser->setFunctionHook( 'basepagenamee', array( __CLASS__
, 'basepagenamee' ), SFH_NO_HASH
);
70 $parser->setFunctionHook( 'subpagename', array( __CLASS__
, 'subpagename' ), SFH_NO_HASH
);
71 $parser->setFunctionHook( 'subpagenamee', array( __CLASS__
, 'subpagenamee' ), SFH_NO_HASH
);
72 $parser->setFunctionHook( 'talkpagename', array( __CLASS__
, 'talkpagename' ), SFH_NO_HASH
);
73 $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__
, 'talkpagenamee' ), SFH_NO_HASH
);
74 $parser->setFunctionHook( 'subjectpagename', array( __CLASS__
, 'subjectpagename' ), SFH_NO_HASH
);
75 $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__
, 'subjectpagenamee' ), SFH_NO_HASH
);
76 $parser->setFunctionHook( 'tag', array( __CLASS__
, 'tagObj' ), SFH_OBJECT_ARGS
);
77 $parser->setFunctionHook( 'formatdate', array( __CLASS__
, 'formatDate' ) );
79 if ( $wgAllowDisplayTitle ) {
80 $parser->setFunctionHook( 'displaytitle', array( __CLASS__
, 'displaytitle' ), SFH_NO_HASH
);
82 if ( $wgAllowSlowParserFunctions ) {
83 $parser->setFunctionHook( 'pagesinnamespace', array( __CLASS__
, 'pagesinnamespace' ), SFH_NO_HASH
);
87 static function intFunction( $parser, $part1 = '' /*, ... */ ) {
88 if ( strval( $part1 ) !== '' ) {
89 $args = array_slice( func_get_args(), 2 );
90 $message = wfMsgGetKey( $part1, true, $parser->getOptions()->getUserLang(), false );
91 $message = wfMsgReplaceArgs( $message, $args );
92 $message = $parser->replaceVariables( $message ); // like $wgMessageCache->transform()
95 return array( 'found' => false );
99 static function formatDate( $parser, $date, $defaultPref = null ) {
100 $df = DateFormatter
::getInstance();
102 $date = trim( $date );
104 $pref = $parser->getOptions()->getDateFormat();
106 // Specify a different default date format other than the the normal default
107 // iff the user has 'default' for their setting
108 if ( $pref == 'default' && $defaultPref )
109 $pref = $defaultPref;
111 $date = $df->reformat( $pref, $date, array( 'match-whole' ) );
115 static function ns( $parser, $part1 = '' ) {
117 if ( intval( $part1 ) ||
$part1 == "0" ) {
118 $index = intval( $part1 );
120 $index = $wgContLang->getNsIndex( str_replace( ' ', '_', $part1 ) );
122 if ( $index !== false ) {
123 return $wgContLang->getFormattedNsText( $index );
125 return array( 'found' => false );
129 static function nse( $parser, $part1 = '' ) {
130 return wfUrlencode( str_replace( ' ', '_', self
::ns( $parser, $part1 ) ) );
134 * urlencodes a string according to one of three patterns: (bug 22474)
136 * By default (for HTTP "query" strings), spaces are encoded as '+'.
137 * Or to encode a value for the HTTP "path", spaces are encoded as '%20'.
138 * For links to "wiki"s, or similar software, spaces are encoded as '_',
140 * @param $parser Parser object
141 * @param $s String: The text to encode.
142 * @param $arg String (optional): The type of encoding.
144 static function urlencode( $parser, $s = '', $arg = null ) {
145 static $magicWords = null;
146 if ( is_null( $magicWords ) ) {
147 $magicWords = new MagicWordArray( array( 'url_path', 'url_query', 'url_wiki' ) );
149 switch( $magicWords->matchStartToEnd( $arg ) ) {
151 // Encode as though it's a wiki page, '_' for ' '.
153 return wfUrlencode( str_replace( ' ', '_', $s ) );
155 // Encode for an HTTP Path, '%20' for ' '.
157 return rawurlencode( $s );
159 // Encode for HTTP query, '+' for ' '.
162 return urlencode( $s );
166 static function lcfirst( $parser, $s = '' ) {
168 return $wgContLang->lcfirst( $s );
171 static function ucfirst( $parser, $s = '' ) {
173 return $wgContLang->ucfirst( $s );
176 static function lc( $parser, $s = '' ) {
178 if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
179 return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
181 return $wgContLang->lc( $s );
185 static function uc( $parser, $s = '' ) {
187 if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
188 return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
190 return $wgContLang->uc( $s );
194 static function localurl( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'getLocalURL', $s, $arg ); }
195 static function localurle( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'escapeLocalURL', $s, $arg ); }
196 static function fullurl( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'getFullURL', $s, $arg ); }
197 static function fullurle( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'escapeFullURL', $s, $arg ); }
198 static function linkurl( $parser, $s = '', $arg = null ) { return self
::urlFunction( 'getLinkUrl', $s, $arg ); }
200 static function urlFunction( $func, $s = '', $arg = null ) {
201 $title = Title
::newFromText( $s );
202 # Due to order of execution of a lot of bits, the values might be encoded
203 # before arriving here; if that's true, then the title can't be created
204 # and the variable will fail. If we can't get a decent title from the first
205 # attempt, url-decode and try for a second.
206 if( is_null( $title ) )
207 $title = Title
::newFromURL( urldecode( $s ) );
208 if( !is_null( $title ) ) {
209 # Convert NS_MEDIA -> NS_FILE
210 if( $title->getNamespace() == NS_MEDIA
) {
211 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
213 if( !is_null( $arg ) ) {
214 $text = $title->$func( $arg );
216 $text = $title->$func();
220 return array( 'found' => false );
224 static function formatNum( $parser, $num = '', $raw = null) {
225 if ( self
::israw( $raw ) ) {
226 return $parser->getFunctionLang()->parseFormattedNumber( $num );
228 return $parser->getFunctionLang()->formatNum( $num );
232 static function grammar( $parser, $case = '', $word = '' ) {
233 return $parser->getFunctionLang()->convertGrammar( $word, $case );
236 static function gender( $parser, $user ) {
237 wfProfileIn( __METHOD__
);
238 $forms = array_slice( func_get_args(), 2);
241 $gender = User
::getDefaultOption( 'gender' );
244 $title = Title
::newFromText( $user );
246 if ( is_object( $title ) && $title->getNamespace() == NS_USER
)
247 $user = $title->getText();
249 // check parameter, or use $wgUser if in interface message
250 $user = User
::newFromName( $user );
252 $gender = $user->getOption( 'gender' );
253 } elseif ( $parser->getOptions()->getInterfaceMessage() ) {
255 $gender = $wgUser->getOption( 'gender' );
257 $ret = $parser->getFunctionLang()->gender( $gender, $forms );
258 wfProfileOut( __METHOD__
);
261 static function plural( $parser, $text = '' ) {
262 $forms = array_slice( func_get_args(), 2 );
263 $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
264 return $parser->getFunctionLang()->convertPlural( $text, $forms );
268 * Override the title of the page when viewed, provided we've been given a
269 * title which will normalise to the canonical title
271 * @param $parser Parser: parent parser
272 * @param $text String: desired title text
275 static function displaytitle( $parser, $text = '' ) {
276 global $wgRestrictDisplayTitle;
278 #parse a limited subset of wiki markup (just the single quote items)
279 $text = $parser->doQuotes( $text );
281 #remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
282 $text = preg_replace( '/' . preg_quote( $parser->uniqPrefix(), '/' ) . '.*?'
283 . preg_quote( Parser
::MARKER_SUFFIX
, '/' ) . '/', '', $text );
285 #list of disallowed tags for DISPLAYTITLE
286 #these will be escaped even though they are allowed in normal wiki text
287 $bad = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
288 'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rp', 'br' );
290 #only requested titles that normalize to the actual title are allowed through
291 #if $wgRestrictDisplayTitle is true (it is by default)
292 #mimic the escaping process that occurs in OutputPage::setPageTitle
293 $text = Sanitizer
::normalizeCharReferences( Sanitizer
::removeHTMLtags( $text, null, array(), array(), $bad ) );
294 $title = Title
::newFromText( Sanitizer
::stripAllTags( $text ) );
296 if( !$wgRestrictDisplayTitle ) {
297 $parser->mOutput
->setDisplayTitle( $text );
299 if ( $title instanceof Title
&& $title->getFragment() == '' && $title->equals( $parser->mTitle
) ) {
300 $parser->mOutput
->setDisplayTitle( $text );
307 static function isRaw( $param ) {
310 $mwRaw =& MagicWord
::get( 'rawsuffix' );
312 if ( is_null( $param ) ) {
315 return $mwRaw->match( $param );
319 static function formatRaw( $num, $raw ) {
320 if( self
::isRaw( $raw ) ) {
324 return $wgContLang->formatNum( $num );
327 static function numberofpages( $parser, $raw = null ) {
328 return self
::formatRaw( SiteStats
::pages(), $raw );
330 static function numberofusers( $parser, $raw = null ) {
331 return self
::formatRaw( SiteStats
::users(), $raw );
333 static function numberofactiveusers( $parser, $raw = null ) {
334 return self
::formatRaw( SiteStats
::activeUsers(), $raw );
336 static function numberofarticles( $parser, $raw = null ) {
337 return self
::formatRaw( SiteStats
::articles(), $raw );
339 static function numberoffiles( $parser, $raw = null ) {
340 return self
::formatRaw( SiteStats
::images(), $raw );
342 static function numberofadmins( $parser, $raw = null ) {
343 return self
::formatRaw( SiteStats
::numberingroup('sysop'), $raw );
345 static function numberofedits( $parser, $raw = null ) {
346 return self
::formatRaw( SiteStats
::edits(), $raw );
348 static function numberofviews( $parser, $raw = null ) {
349 return self
::formatRaw( SiteStats
::views(), $raw );
351 static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
352 return self
::formatRaw( SiteStats
::pagesInNs( intval( $namespace ) ), $raw );
354 static function numberingroup( $parser, $name = '', $raw = null) {
355 return self
::formatRaw( SiteStats
::numberingroup( strtolower( $name ) ), $raw );
360 * Given a title, return the namespace name that would be given by the
361 * corresponding magic word
362 * Note: function name changed to "mwnamespace" rather than "namespace"
363 * to not break PHP 5.3
365 static function mwnamespace( $parser, $title = null ) {
366 $t = Title
::newFromText( $title );
369 return str_replace( '_', ' ', $t->getNsText() );
371 static function namespacee( $parser, $title = null ) {
372 $t = Title
::newFromText( $title );
375 return wfUrlencode( $t->getNsText() );
377 static function talkspace( $parser, $title = null ) {
378 $t = Title
::newFromText( $title );
379 if ( is_null( $t ) ||
!$t->canTalk() )
381 return str_replace( '_', ' ', $t->getTalkNsText() );
383 static function talkspacee( $parser, $title = null ) {
384 $t = Title
::newFromText( $title );
385 if ( is_null( $t ) ||
!$t->canTalk() )
387 return wfUrlencode( $t->getTalkNsText() );
389 static function subjectspace( $parser, $title = null ) {
390 $t = Title
::newFromText( $title );
393 return str_replace( '_', ' ', $t->getSubjectNsText() );
395 static function subjectspacee( $parser, $title = null ) {
396 $t = Title
::newFromText( $title );
399 return wfUrlencode( $t->getSubjectNsText() );
402 * Functions to get and normalize pagenames, corresponding to the magic words
405 static function pagename( $parser, $title = null ) {
406 $t = Title
::newFromText( $title );
409 return wfEscapeWikiText( $t->getText() );
411 static function pagenamee( $parser, $title = null ) {
412 $t = Title
::newFromText( $title );
415 return $t->getPartialURL();
417 static function fullpagename( $parser, $title = null ) {
418 $t = Title
::newFromText( $title );
419 if ( is_null( $t ) ||
!$t->canTalk() )
421 return wfEscapeWikiText( $t->getPrefixedText() );
423 static function fullpagenamee( $parser, $title = null ) {
424 $t = Title
::newFromText( $title );
425 if ( is_null( $t ) ||
!$t->canTalk() )
427 return $t->getPrefixedURL();
429 static function subpagename( $parser, $title = null ) {
430 $t = Title
::newFromText( $title );
433 return $t->getSubpageText();
435 static function subpagenamee( $parser, $title = null ) {
436 $t = Title
::newFromText( $title );
439 return $t->getSubpageUrlForm();
441 static function basepagename( $parser, $title = null ) {
442 $t = Title
::newFromText( $title );
445 return $t->getBaseText();
447 static function basepagenamee( $parser, $title = null ) {
448 $t = Title
::newFromText( $title );
451 return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) );
453 static function talkpagename( $parser, $title = null ) {
454 $t = Title
::newFromText( $title );
455 if ( is_null( $t ) ||
!$t->canTalk() )
457 return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
459 static function talkpagenamee( $parser, $title = null ) {
460 $t = Title
::newFromText( $title );
461 if ( is_null( $t ) ||
!$t->canTalk() )
463 return $t->getTalkPage()->getPrefixedUrl();
465 static function subjectpagename( $parser, $title = null ) {
466 $t = Title
::newFromText( $title );
469 return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
471 static function subjectpagenamee( $parser, $title = null ) {
472 $t = Title
::newFromText( $title );
475 return $t->getSubjectPage()->getPrefixedUrl();
479 * Return the number of pages in the given category, or 0 if it's nonexis-
480 * tent. This is an expensive parser function and can't be called too many
483 static function pagesincategory( $parser, $name = '', $raw = null ) {
484 static $cache = array();
485 $category = Category
::newFromName( $name );
487 if( !is_object( $category ) ) {
489 return self
::formatRaw( 0, $raw );
492 # Normalize name for cache
493 $name = $category->getName();
496 if( isset( $cache[$name] ) ) {
497 $count = $cache[$name];
498 } elseif( $parser->incrementExpensiveFunctionCount() ) {
499 $count = $cache[$name] = (int)$category->getPageCount();
501 return self
::formatRaw( $count, $raw );
505 * Return the size of the given page, or 0 if it's nonexistent. This is an
506 * expensive parser function and can't be called too many times per page.
508 * @todo Fixme: This doesn't work correctly on preview for getting the size
509 * of the current page.
510 * @todo Fixme: Title::getLength() documentation claims that it adds things
511 * to the link cache, so the local cache here should be unnecessary, but
512 * in fact calling getLength() repeatedly for the same $page does seem to
513 * run one query for each call?
515 static function pagesize( $parser, $page = '', $raw = null ) {
516 static $cache = array();
517 $title = Title
::newFromText( $page );
519 if( !is_object( $title ) ) {
521 return self
::formatRaw( 0, $raw );
524 # Normalize name for cache
525 $page = $title->getPrefixedText();
528 if( isset( $cache[$page] ) ) {
529 $length = $cache[$page];
530 } elseif( $parser->incrementExpensiveFunctionCount() ) {
531 $rev = Revision
::newFromTitle( $title );
532 $id = $rev ?
$rev->getPage() : 0;
533 $length = $cache[$page] = $rev ?
$rev->getSize() : 0;
535 // Register dependency in templatelinks
536 $parser->mOutput
->addTemplate( $title, $id, $rev ?
$rev->getId() : 0 );
538 return self
::formatRaw( $length, $raw );
542 * Returns the requested protection level for the current page
544 static function protectionlevel( $parser, $type = '' ) {
545 $restrictions = $parser->mTitle
->getRestrictions( strtolower( $type ) );
546 # Title::getRestrictions returns an array, its possible it may have
547 # multiple values in the future
548 return implode( $restrictions, ',' );
551 static function language( $parser, $arg = '' ) {
553 $lang = $wgContLang->getLanguageName( strtolower( $arg ) );
554 return $lang != '' ?
$lang : $arg;
558 * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
560 static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
) {
561 $lengthOfPadding = mb_strlen( $padding );
562 if ( $lengthOfPadding == 0 ) return $string;
564 # The remaining length to add counts down to 0 as padding is added
565 $length = min( $length, 500 ) - mb_strlen( $string );
566 # $finalPadding is just $padding repeated enough times so that
567 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
569 while ( $length > 0 ) {
570 # If $length < $lengthofPadding, truncate $padding so we get the
571 # exact length desired.
572 $finalPadding .= mb_substr( $padding, 0, $length );
573 $length -= $lengthOfPadding;
576 if ( $direction == STR_PAD_LEFT
) {
577 return $finalPadding . $string;
579 return $string . $finalPadding;
583 static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
584 return self
::pad( $string, $length, $padding, STR_PAD_LEFT
);
587 static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
588 return self
::pad( $string, $length, $padding );
591 static function anchorencode( $parser, $text ) {
592 return substr( $parser->guessSectionNameFromWikiText( $text ), 1);
595 static function special( $parser, $text ) {
596 list( $page, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $text );
598 $title = SpecialPage
::getTitleFor( $page, $subpage );
601 return wfMsgForContent( 'nosuchspecialpage' );
605 public static function defaultsort( $parser, $text ) {
606 $text = trim( $text );
607 if( strlen( $text ) == 0 )
609 $old = $parser->getCustomDefaultSort();
610 $parser->setDefaultSort( $text );
611 if( $old === false ||
$old == $text )
614 return( '<span class="error">' .
615 wfMsgForContent( 'duplicate-defaultsort',
616 htmlspecialchars( $old ),
617 htmlspecialchars( $text ) ) .
621 public static function filepath( $parser, $name='', $option='' ) {
622 $file = wfFindFile( $name );
624 $url = $file->getFullUrl();
625 if( $option == 'nowiki' ) {
626 return array( $url, 'nowiki' => true );
635 * Parser function to extension tag adaptor
637 public static function tagObj( $parser, $frame, $args ) {
638 if ( !count( $args ) ) {
641 $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
643 if ( count( $args ) ) {
644 $inner = $frame->expand( array_shift( $args ) );
649 $stripList = $parser->getStripList();
650 if ( !in_array( $tagName, $stripList ) ) {
651 return '<span class="error">' .
652 wfMsgForContent( 'unknown_extension_tag', $tagName ) .
656 $attributes = array();
657 foreach ( $args as $arg ) {
658 $bits = $arg->splitArg();
659 if ( strval( $bits['index'] ) === '' ) {
660 $name = trim( $frame->expand( $bits['name'], PPFrame
::STRIP_COMMENTS
) );
661 $value = trim( $frame->expand( $bits['value'] ) );
662 if ( preg_match( '/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
663 $value = isset( $m[1] ) ?
$m[1] : '';
665 $attributes[$name] = $value;
672 'attributes' => $attributes,
673 'close' => "</$tagName>",
675 return $parser->extensionSubstitution( $params, $frame );