00001 <?php
00002
00007 class CoreParserFunctions {
00008 static function register( $parser ) {
00009 global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;
00010
00011 # Syntax for arguments (see self::setFunctionHook):
00012 # "name for lookup in localized magic words array",
00013 # function callback,
00014 # optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}
00015 # instead of {{#int:...}})
00016
00017 $parser->setFunctionHook( 'int', array( __CLASS__, 'intFunction' ), SFH_NO_HASH );
00018 $parser->setFunctionHook( 'ns', array( __CLASS__, 'ns' ), SFH_NO_HASH );
00019 $parser->setFunctionHook( 'urlencode', array( __CLASS__, 'urlencode' ), SFH_NO_HASH );
00020 $parser->setFunctionHook( 'lcfirst', array( __CLASS__, 'lcfirst' ), SFH_NO_HASH );
00021 $parser->setFunctionHook( 'ucfirst', array( __CLASS__, 'ucfirst' ), SFH_NO_HASH );
00022 $parser->setFunctionHook( 'lc', array( __CLASS__, 'lc' ), SFH_NO_HASH );
00023 $parser->setFunctionHook( 'uc', array( __CLASS__, 'uc' ), SFH_NO_HASH );
00024 $parser->setFunctionHook( 'localurl', array( __CLASS__, 'localurl' ), SFH_NO_HASH );
00025 $parser->setFunctionHook( 'localurle', array( __CLASS__, 'localurle' ), SFH_NO_HASH );
00026 $parser->setFunctionHook( 'fullurl', array( __CLASS__, 'fullurl' ), SFH_NO_HASH );
00027 $parser->setFunctionHook( 'fullurle', array( __CLASS__, 'fullurle' ), SFH_NO_HASH );
00028 $parser->setFunctionHook( 'formatnum', array( __CLASS__, 'formatnum' ), SFH_NO_HASH );
00029 $parser->setFunctionHook( 'grammar', array( __CLASS__, 'grammar' ), SFH_NO_HASH );
00030 $parser->setFunctionHook( 'gender', array( __CLASS__, 'gender' ), SFH_NO_HASH );
00031 $parser->setFunctionHook( 'plural', array( __CLASS__, 'plural' ), SFH_NO_HASH );
00032 $parser->setFunctionHook( 'numberofpages', array( __CLASS__, 'numberofpages' ), SFH_NO_HASH );
00033 $parser->setFunctionHook( 'numberofusers', array( __CLASS__, 'numberofusers' ), SFH_NO_HASH );
00034 $parser->setFunctionHook( 'numberofactiveusers', array( __CLASS__, 'numberofactiveusers' ), SFH_NO_HASH );
00035 $parser->setFunctionHook( 'numberofarticles', array( __CLASS__, 'numberofarticles' ), SFH_NO_HASH );
00036 $parser->setFunctionHook( 'numberoffiles', array( __CLASS__, 'numberoffiles' ), SFH_NO_HASH );
00037 $parser->setFunctionHook( 'numberofadmins', array( __CLASS__, 'numberofadmins' ), SFH_NO_HASH );
00038 $parser->setFunctionHook( 'numberingroup', array( __CLASS__, 'numberingroup' ), SFH_NO_HASH );
00039 $parser->setFunctionHook( 'numberofedits', array( __CLASS__, 'numberofedits' ), SFH_NO_HASH );
00040 $parser->setFunctionHook( 'numberofviews', array( __CLASS__, 'numberofviews' ), SFH_NO_HASH );
00041 $parser->setFunctionHook( 'language', array( __CLASS__, 'language' ), SFH_NO_HASH );
00042 $parser->setFunctionHook( 'padleft', array( __CLASS__, 'padleft' ), SFH_NO_HASH );
00043 $parser->setFunctionHook( 'padright', array( __CLASS__, 'padright' ), SFH_NO_HASH );
00044 $parser->setFunctionHook( 'anchorencode', array( __CLASS__, 'anchorencode' ), SFH_NO_HASH );
00045 $parser->setFunctionHook( 'special', array( __CLASS__, 'special' ) );
00046 $parser->setFunctionHook( 'defaultsort', array( __CLASS__, 'defaultsort' ), SFH_NO_HASH );
00047 $parser->setFunctionHook( 'filepath', array( __CLASS__, 'filepath' ), SFH_NO_HASH );
00048 $parser->setFunctionHook( 'pagesincategory', array( __CLASS__, 'pagesincategory' ), SFH_NO_HASH );
00049 $parser->setFunctionHook( 'pagesize', array( __CLASS__, 'pagesize' ), SFH_NO_HASH );
00050 $parser->setFunctionHook( 'protectionlevel', array( __CLASS__, 'protectionlevel' ), SFH_NO_HASH );
00051 $parser->setFunctionHook( 'namespace', array( __CLASS__, 'mwnamespace' ), SFH_NO_HASH );
00052 $parser->setFunctionHook( 'namespacee', array( __CLASS__, 'namespacee' ), SFH_NO_HASH );
00053 $parser->setFunctionHook( 'talkspace', array( __CLASS__, 'talkspace' ), SFH_NO_HASH );
00054 $parser->setFunctionHook( 'talkspacee', array( __CLASS__, 'talkspacee' ), SFH_NO_HASH );
00055 $parser->setFunctionHook( 'subjectspace', array( __CLASS__, 'subjectspace' ), SFH_NO_HASH );
00056 $parser->setFunctionHook( 'subjectspacee', array( __CLASS__, 'subjectspacee' ), SFH_NO_HASH );
00057 $parser->setFunctionHook( 'pagename', array( __CLASS__, 'pagename' ), SFH_NO_HASH );
00058 $parser->setFunctionHook( 'pagenamee', array( __CLASS__, 'pagenamee' ), SFH_NO_HASH );
00059 $parser->setFunctionHook( 'fullpagename', array( __CLASS__, 'fullpagename' ), SFH_NO_HASH );
00060 $parser->setFunctionHook( 'fullpagenamee', array( __CLASS__, 'fullpagenamee' ), SFH_NO_HASH );
00061 $parser->setFunctionHook( 'basepagename', array( __CLASS__, 'basepagename' ), SFH_NO_HASH );
00062 $parser->setFunctionHook( 'basepagenamee', array( __CLASS__, 'basepagenamee' ), SFH_NO_HASH );
00063 $parser->setFunctionHook( 'subpagename', array( __CLASS__, 'subpagename' ), SFH_NO_HASH );
00064 $parser->setFunctionHook( 'subpagenamee', array( __CLASS__, 'subpagenamee' ), SFH_NO_HASH );
00065 $parser->setFunctionHook( 'talkpagename', array( __CLASS__, 'talkpagename' ), SFH_NO_HASH );
00066 $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__, 'talkpagenamee' ), SFH_NO_HASH );
00067 $parser->setFunctionHook( 'subjectpagename', array( __CLASS__, 'subjectpagename' ), SFH_NO_HASH );
00068 $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
00069 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
00070 $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
00071
00072 if ( $wgAllowDisplayTitle ) {
00073 $parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), SFH_NO_HASH );
00074 }
00075 if ( $wgAllowSlowParserFunctions ) {
00076 $parser->setFunctionHook( 'pagesinnamespace', array( __CLASS__, 'pagesinnamespace' ), SFH_NO_HASH );
00077 }
00078 }
00079
00080 static function intFunction( $parser, $part1 = '' ) {
00081 if ( strval( $part1 ) !== '' ) {
00082 $args = array_slice( func_get_args(), 2 );
00083 $message = wfMsgGetKey( $part1, true, false, false );
00084 $message = wfMsgReplaceArgs( $message, $args );
00085 $message = $parser->replaceVariables( $message );
00086 return $message;
00087 } else {
00088 return array( 'found' => false );
00089 }
00090 }
00091
00092 static function formatDate( $parser, $date, $defaultPref = null ) {
00093 $df = DateFormatter::getInstance();
00094
00095 $date = trim($date);
00096
00097 $pref = $parser->mOptions->getDateFormat();
00098
00099
00100
00101 if ($pref == 'default' && $defaultPref)
00102 $pref = $defaultPref;
00103
00104 $date = $df->reformat( $pref, $date, array('match-whole') );
00105 return $date;
00106 }
00107
00108 static function ns( $parser, $part1 = '' ) {
00109 global $wgContLang;
00110 if ( intval( $part1 ) || $part1 == "0" ) {
00111 $index = intval( $part1 );
00112 } else {
00113 $index = $wgContLang->getNsIndex( str_replace( ' ', '_', $part1 ) );
00114 }
00115 if ( $index !== false ) {
00116 return $wgContLang->getFormattedNsText( $index );
00117 } else {
00118 return array( 'found' => false );
00119 }
00120 }
00121
00122 static function urlencode( $parser, $s = '' ) {
00123 return urlencode( $s );
00124 }
00125
00126 static function lcfirst( $parser, $s = '' ) {
00127 global $wgContLang;
00128 return $wgContLang->lcfirst( $s );
00129 }
00130
00131 static function ucfirst( $parser, $s = '' ) {
00132 global $wgContLang;
00133 return $wgContLang->ucfirst( $s );
00134 }
00135
00136 static function lc( $parser, $s = '' ) {
00137 global $wgContLang;
00138 if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
00139 return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
00140 } else {
00141 return $wgContLang->lc( $s );
00142 }
00143 }
00144
00145 static function uc( $parser, $s = '' ) {
00146 global $wgContLang;
00147 if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
00148 return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
00149 } else {
00150 return $wgContLang->uc( $s );
00151 }
00152 }
00153
00154 static function localurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getLocalURL', $s, $arg ); }
00155 static function localurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeLocalURL', $s, $arg ); }
00156 static function fullurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getFullURL', $s, $arg ); }
00157 static function fullurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeFullURL', $s, $arg ); }
00158
00159 static function urlFunction( $func, $s = '', $arg = null ) {
00160 $title = Title::newFromText( $s );
00161 # Due to order of execution of a lot of bits, the values might be encoded
00162 # before arriving here; if that's true, then the title can't be created
00163 # and the variable will fail. If we can't get a decent title from the first
00164 # attempt, url-decode and try for a second.
00165 if( is_null( $title ) )
00166 $title = Title::newFromUrl( urldecode( $s ) );
00167 if( !is_null( $title ) ) {
00168 # Convert NS_MEDIA -> NS_FILE
00169 if( $title->getNamespace() == NS_MEDIA ) {
00170 $title = Title::makeTitle( NS_FILE, $title->getDBKey() );
00171 }
00172 if( !is_null( $arg ) ) {
00173 $text = $title->$func( $arg );
00174 } else {
00175 $text = $title->$func();
00176 }
00177 return $text;
00178 } else {
00179 return array( 'found' => false );
00180 }
00181 }
00182
00183 static function formatNum( $parser, $num = '', $raw = null) {
00184 if ( self::israw( $raw ) ) {
00185 return $parser->getFunctionLang()->parseFormattedNumber( $num );
00186 } else {
00187 return $parser->getFunctionLang()->formatNum( $num );
00188 }
00189 }
00190
00191 static function grammar( $parser, $case = '', $word = '' ) {
00192 return $parser->getFunctionLang()->convertGrammar( $word, $case );
00193 }
00194
00195 static function gender( $parser, $user ) {
00196 $forms = array_slice( func_get_args(), 2);
00197
00198
00199 $gender = User::getDefaultOption( 'gender' );
00200
00201
00202 $title = Title::newFromText( $user );
00203
00204 if (is_object( $title ) && $title->getNamespace() == NS_USER)
00205 $user = $title->getText();
00206
00207
00208 $user = User::newFromName( $user );
00209 if ( $user ) {
00210 $gender = $user->getOption( 'gender' );
00211 } elseif ( $parser->mOptions->getInterfaceMessage() ) {
00212 global $wgUser;
00213 $gender = $wgUser->getOption( 'gender' );
00214 }
00215 return $parser->getFunctionLang()->gender( $gender, $forms );
00216 }
00217 static function plural( $parser, $text = '') {
00218 $forms = array_slice( func_get_args(), 2);
00219 $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
00220 return $parser->getFunctionLang()->convertPlural( $text, $forms );
00221 }
00222
00231 static function displaytitle( $parser, $text = '' ) {
00232 global $wgRestrictDisplayTitle;
00233 $text = trim( Sanitizer::decodeCharReferences( $text ) );
00234
00235 if ( !$wgRestrictDisplayTitle ) {
00236 $parser->mOutput->setDisplayTitle( $text );
00237 } else {
00238 $title = Title::newFromText( $text );
00239 if( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) )
00240 $parser->mOutput->setDisplayTitle( $text );
00241 }
00242 return '';
00243 }
00244
00245 static function isRaw( $param ) {
00246 static $mwRaw;
00247 if ( !$mwRaw ) {
00248 $mwRaw =& MagicWord::get( 'rawsuffix' );
00249 }
00250 if ( is_null( $param ) ) {
00251 return false;
00252 } else {
00253 return $mwRaw->match( $param );
00254 }
00255 }
00256
00257 static function formatRaw( $num, $raw ) {
00258 if( self::isRaw( $raw ) ) {
00259 return $num;
00260 } else {
00261 global $wgContLang;
00262 return $wgContLang->formatNum( $num );
00263 }
00264 }
00265 static function numberofpages( $parser, $raw = null ) {
00266 return self::formatRaw( SiteStats::pages(), $raw );
00267 }
00268 static function numberofusers( $parser, $raw = null ) {
00269 return self::formatRaw( SiteStats::users(), $raw );
00270 }
00271 static function numberofactiveusers( $parser, $raw = null ) {
00272 return self::formatRaw( SiteStats::activeUsers(), $raw );
00273 }
00274 static function numberofarticles( $parser, $raw = null ) {
00275 return self::formatRaw( SiteStats::articles(), $raw );
00276 }
00277 static function numberoffiles( $parser, $raw = null ) {
00278 return self::formatRaw( SiteStats::images(), $raw );
00279 }
00280 static function numberofadmins( $parser, $raw = null ) {
00281 return self::formatRaw( SiteStats::numberingroup('sysop'), $raw );
00282 }
00283 static function numberofedits( $parser, $raw = null ) {
00284 return self::formatRaw( SiteStats::edits(), $raw );
00285 }
00286 static function numberofviews( $parser, $raw = null ) {
00287 return self::formatRaw( SiteStats::views(), $raw );
00288 }
00289 static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
00290 return self::formatRaw( SiteStats::pagesInNs( intval( $namespace ) ), $raw );
00291 }
00292 static function numberingroup( $parser, $name = '', $raw = null) {
00293 return self::formatRaw( SiteStats::numberingroup( strtolower( $name ) ), $raw );
00294 }
00295
00296
00303 static function mwnamespace( $parser, $title = null ) {
00304 $t = Title::newFromText( $title );
00305 if ( is_null($t) )
00306 return '';
00307 return str_replace( '_', ' ', $t->getNsText() );
00308 }
00309 static function namespacee( $parser, $title = null ) {
00310 $t = Title::newFromText( $title );
00311 if ( is_null($t) )
00312 return '';
00313 return wfUrlencode( $t->getNsText() );
00314 }
00315 static function talkspace( $parser, $title = null ) {
00316 $t = Title::newFromText( $title );
00317 if ( is_null($t) || !$t->canTalk() )
00318 return '';
00319 return str_replace( '_', ' ', $t->getTalkNsText() );
00320 }
00321 static function talkspacee( $parser, $title = null ) {
00322 $t = Title::newFromText( $title );
00323 if ( is_null($t) || !$t->canTalk() )
00324 return '';
00325 return wfUrlencode( $t->getTalkNsText() );
00326 }
00327 static function subjectspace( $parser, $title = null ) {
00328 $t = Title::newFromText( $title );
00329 if ( is_null($t) )
00330 return '';
00331 return str_replace( '_', ' ', $t->getSubjectNsText() );
00332 }
00333 static function subjectspacee( $parser, $title = null ) {
00334 $t = Title::newFromText( $title );
00335 if ( is_null($t) )
00336 return '';
00337 return wfUrlencode( $t->getSubjectNsText() );
00338 }
00339
00340
00341
00342
00343 static function pagename( $parser, $title = null ) {
00344 $t = Title::newFromText( $title );
00345 if ( is_null($t) )
00346 return '';
00347 return wfEscapeWikiText( $t->getText() );
00348 }
00349 static function pagenamee( $parser, $title = null ) {
00350 $t = Title::newFromText( $title );
00351 if ( is_null($t) )
00352 return '';
00353 return $t->getPartialURL();
00354 }
00355 static function fullpagename( $parser, $title = null ) {
00356 $t = Title::newFromText( $title );
00357 if ( is_null($t) || !$t->canTalk() )
00358 return '';
00359 return wfEscapeWikiText( $t->getPrefixedText() );
00360 }
00361 static function fullpagenamee( $parser, $title = null ) {
00362 $t = Title::newFromText( $title );
00363 if ( is_null($t) || !$t->canTalk() )
00364 return '';
00365 return $t->getPrefixedURL();
00366 }
00367 static function subpagename( $parser, $title = null ) {
00368 $t = Title::newFromText( $title );
00369 if ( is_null($t) )
00370 return '';
00371 return $t->getSubpageText();
00372 }
00373 static function subpagenamee( $parser, $title = null ) {
00374 $t = Title::newFromText( $title );
00375 if ( is_null($t) )
00376 return '';
00377 return $t->getSubpageUrlForm();
00378 }
00379 static function basepagename( $parser, $title = null ) {
00380 $t = Title::newFromText( $title );
00381 if ( is_null($t) )
00382 return '';
00383 return $t->getBaseText();
00384 }
00385 static function basepagenamee( $parser, $title = null ) {
00386 $t = Title::newFromText( $title );
00387 if ( is_null($t) )
00388 return '';
00389 return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) );
00390 }
00391 static function talkpagename( $parser, $title = null ) {
00392 $t = Title::newFromText( $title );
00393 if ( is_null($t) || !$t->canTalk() )
00394 return '';
00395 return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
00396 }
00397 static function talkpagenamee( $parser, $title = null ) {
00398 $t = Title::newFromText( $title );
00399 if ( is_null($t) || !$t->canTalk() )
00400 return '';
00401 return $t->getTalkPage()->getPrefixedUrl();
00402 }
00403 static function subjectpagename( $parser, $title = null ) {
00404 $t = Title::newFromText( $title );
00405 if ( is_null($t) )
00406 return '';
00407 return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
00408 }
00409 static function subjectpagenamee( $parser, $title = null ) {
00410 $t = Title::newFromText( $title );
00411 if ( is_null($t) )
00412 return '';
00413 return $t->getSubjectPage()->getPrefixedUrl();
00414 }
00415
00421 static function pagesincategory( $parser, $name = '', $raw = null ) {
00422 static $cache = array();
00423 $category = Category::newFromName( $name );
00424
00425 if( !is_object( $category ) ) {
00426 $cache[$name] = 0;
00427 return self::formatRaw( 0, $raw );
00428 }
00429
00430 # Normalize name for cache
00431 $name = $category->getName();
00432
00433 $count = 0;
00434 if( isset( $cache[$name] ) ) {
00435 $count = $cache[$name];
00436 } elseif( $parser->incrementExpensiveFunctionCount() ) {
00437 $count = $cache[$name] = (int)$category->getPageCount();
00438 }
00439 return self::formatRaw( $count, $raw );
00440 }
00441
00453 static function pagesize( $parser, $page = '', $raw = null ) {
00454 static $cache = array();
00455 $title = Title::newFromText($page);
00456
00457 if( !is_object( $title ) ) {
00458 $cache[$page] = 0;
00459 return self::formatRaw( 0, $raw );
00460 }
00461
00462 # Normalize name for cache
00463 $page = $title->getPrefixedText();
00464
00465 $length = 0;
00466 if( isset( $cache[$page] ) ) {
00467 $length = $cache[$page];
00468 } elseif( $parser->incrementExpensiveFunctionCount() ) {
00469 $rev = Revision::newFromTitle($title);
00470 $id = $rev ? $rev->getPage() : 0;
00471 $length = $cache[$page] = $rev ? $rev->getSize() : 0;
00472
00473
00474 $parser->mOutput->addTemplate( $title, $id, $rev ? $rev->getId() : 0 );
00475 }
00476 return self::formatRaw( $length, $raw );
00477 }
00478
00482 static function protectionlevel( $parser, $type = '' ) {
00483 $restrictions = $parser->mTitle->getRestrictions( strtolower( $type ) );
00484 # Title::getRestrictions returns an array, its possible it may have
00485 # multiple values in the future
00486 return implode( $restrictions, ',' );
00487 }
00488
00489 static function language( $parser, $arg = '' ) {
00490 global $wgContLang;
00491 $lang = $wgContLang->getLanguageName( strtolower( $arg ) );
00492 return $lang != '' ? $lang : $arg;
00493 }
00494
00498 static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
00499 $lengthOfPadding = mb_strlen( $padding );
00500 if ( $lengthOfPadding == 0 ) return $string;
00501
00502 # The remaining length to add counts down to 0 as padding is added
00503 $length = min( $length, 500 ) - mb_strlen( $string );
00504 # $finalPadding is just $padding repeated enough times so that
00505 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
00506 $finalPadding = '';
00507 while ( $length > 0 ) {
00508 # If $length < $lengthofPadding, truncate $padding so we get the
00509 # exact length desired.
00510 $finalPadding .= mb_substr( $padding, 0, $length );
00511 $length -= $lengthOfPadding;
00512 }
00513
00514 if ( $direction == STR_PAD_LEFT ) {
00515 return $finalPadding . $string;
00516 } else {
00517 return $string . $finalPadding;
00518 }
00519 }
00520
00521 static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
00522 return self::pad( $string, $length, $padding, STR_PAD_LEFT );
00523 }
00524
00525 static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
00526 return self::pad( $string, $length, $padding );
00527 }
00528
00529 static function anchorencode( $parser, $text ) {
00530 $a = urlencode( $text );
00531 $a = strtr( $a, array( '%' => '.', '+' => '_' ) );
00532 # leave colons alone, however
00533 $a = str_replace( '.3A', ':', $a );
00534 return $a;
00535 }
00536
00537 static function special( $parser, $text ) {
00538 $title = SpecialPage::getTitleForAlias( $text );
00539 if ( $title ) {
00540 return $title->getPrefixedText();
00541 } else {
00542 return wfMsgForContent( 'nosuchspecialpage' );
00543 }
00544 }
00545
00546 public static function defaultsort( $parser, $text ) {
00547 $text = trim( $text );
00548 if( strlen( $text ) == 0 )
00549 return '';
00550 $old = $parser->getCustomDefaultSort();
00551 $parser->setDefaultSort( $text );
00552 if( $old === false || $old == $text )
00553 return '';
00554 else
00555 return( '<span class="error">' .
00556 wfMsg( 'duplicate-defaultsort',
00557 htmlspecialchars( $old ),
00558 htmlspecialchars( $text ) ) .
00559 '</span>' );
00560 }
00561
00562 public static function filepath( $parser, $name='', $option='' ) {
00563 $file = wfFindFile( $name );
00564 if( $file ) {
00565 $url = $file->getFullUrl();
00566 if( $option == 'nowiki' ) {
00567 return array( $url, 'nowiki' => true );
00568 }
00569 return $url;
00570 } else {
00571 return '';
00572 }
00573 }
00574
00578 public static function tagObj( $parser, $frame, $args ) {
00579 $xpath = false;
00580 if ( !count( $args ) ) {
00581 return '';
00582 }
00583 $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
00584
00585 if ( count( $args ) ) {
00586 $inner = $frame->expand( array_shift( $args ) );
00587 } else {
00588 $inner = null;
00589 }
00590
00591 $stripList = $parser->getStripList();
00592 if ( !in_array( $tagName, $stripList ) ) {
00593 return '<span class="error">' .
00594 wfMsg( 'unknown_extension_tag', $tagName ) .
00595 '</span>';
00596 }
00597
00598 $attributes = array();
00599 foreach ( $args as $arg ) {
00600 $bits = $arg->splitArg();
00601 if ( strval( $bits['index'] ) === '' ) {
00602 $name = trim( $frame->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
00603 $value = trim( $frame->expand( $bits['value'] ) );
00604 if ( preg_match( '/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
00605 $value = isset( $m[1] ) ? $m[1] : '';
00606 }
00607 $attributes[$name] = $value;
00608 }
00609 }
00610
00611 $params = array(
00612 'name' => $tagName,
00613 'inner' => $inner,
00614 'attributes' => $attributes,
00615 'close' => "</$tagName>",
00616 );
00617 return $parser->extensionSubstitution( $params, $frame );
00618 }
00619 }