<?php
+/**
+ * Parser functions provided by MediaWiki core
+ *
+ * @file
+ */
/**
* Various core parser functions, registered in Parser::firstCallInit()
static function intFunction( $parser, $part1 = '' /*, ... */ ) {
if ( strval( $part1 ) !== '' ) {
$args = array_slice( func_get_args(), 2 );
- $message = wfMsgGetKey( $part1, true, false, false );
+ $message = wfMsgGetKey( $part1, true, $parser->getOptions()->getUserLang(), false );
$message = wfMsgReplaceArgs( $message, $args );
- $message = $parser->replaceVariables( $message ); // like $wgMessageCache->transform()
+ $message = $parser->replaceVariables( $message ); // like MessageCache::transform()
return $message;
} else {
return array( 'found' => false );
$date = trim( $date );
- $pref = $parser->mOptions->getDateFormat();
+ $pref = $parser->getOptions()->getDateFormat();
// Specify a different default date format other than the the normal default
// iff the user has 'default' for their setting
* Or to encode a value for the HTTP "path", spaces are encoded as '%20'.
* For links to "wiki"s, or similar software, spaces are encoded as '_',
*
- * @param $parser.
+ * @param $parser Parser object
* @param $s String: The text to encode.
* @param $arg String (optional): The type of encoding.
*/
if ( is_object( $title ) && $title->getNamespace() == NS_USER )
$user = $title->getText();
- // check parameter, or use $wgUser if in interface message
+ // check parameter, or use the ParserOptions if in interface message
$user = User::newFromName( $user );
if ( $user ) {
$gender = $user->getOption( 'gender' );
- } elseif ( $parser->mOptions->getInterfaceMessage() ) {
- global $wgUser;
- $gender = $wgUser->getOption( 'gender' );
+ } elseif ( $parser->getOptions()->getInterfaceMessage() ) {
+ $gender = $parser->getOptions()->getUser()->getOption( 'gender' );
}
$ret = $parser->getFunctionLang()->gender( $gender, $forms );
wfProfileOut( __METHOD__ );
$t = Title::newFromText( $title );
if ( is_null( $t ) )
return '';
- return $t->getPartialURL();
+ return wfEscapeWikiText( $t->getPartialURL() );
}
static function fullpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
$t = Title::newFromText( $title );
if ( is_null( $t ) || !$t->canTalk() )
return '';
- return $t->getPrefixedURL();
+ return wfEscapeWikiText( $t->getPrefixedURL() );
}
static function subpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
if ( is_null( $t ) )
return '';
- return $t->getSubpageText();
+ return wfEscapeWikiText( $t->getSubpageText() );
}
static function subpagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
if ( is_null( $t ) )
return '';
- return $t->getSubpageUrlForm();
+ return wfEscapeWikiText( $t->getSubpageUrlForm() );
}
static function basepagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
if ( is_null( $t ) )
return '';
- return $t->getBaseText();
+ return wfEscapeWikiText( $t->getBaseText() );
}
static function basepagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
if ( is_null( $t ) )
return '';
- return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) );
+ return wfEscapeWikiText( wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) ) );
}
static function talkpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
$t = Title::newFromText( $title );
if ( is_null( $t ) || !$t->canTalk() )
return '';
- return $t->getTalkPage()->getPrefixedUrl();
+ return wfEscapeWikiText( $t->getTalkPage()->getPrefixedUrl() );
}
static function subjectpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
$t = Title::newFromText( $title );
if ( is_null( $t ) )
return '';
- return $t->getSubjectPage()->getPrefixedUrl();
+ return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedUrl() );
}
/**
}
static function anchorencode( $parser, $text ) {
- $a = urlencode( $text );
- $a = strtr( $a, array( '%' => '.', '+' => '_' ) );
- # leave colons alone, however
- $a = str_replace( '.3A', ':', $a );
- return $a;
+ return substr( $parser->guessSectionNameFromWikiText( $text ), 1);
}
static function special( $parser, $text ) {
return '';
else
return( '<span class="error">' .
- wfMsg( 'duplicate-defaultsort',
+ wfMsgForContent( 'duplicate-defaultsort',
htmlspecialchars( $old ),
htmlspecialchars( $text ) ) .
'</span>' );
}
- public static function filepath( $parser, $name='', $option='' ) {
+ // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}}
+ public static function filepath( $parser, $name='', $argA='', $argB='' ) {
$file = wfFindFile( $name );
- if( $file ) {
- $url = $file->getFullUrl();
- if( $option == 'nowiki' ) {
+ $size = '';
+ $argA_int = intval( $argA );
+ $argB_int = intval( $argB );
+
+ if ( $argB_int > 0 ) {
+ // {{filepath: | option | size }}
+ $size = $argB_int;
+ $option = $argA;
+
+ } elseif ( $argA_int > 0 ) {
+ // {{filepath: | size [|option] }}
+ $size = $argA_int;
+ $option = $argB;
+
+ } else {
+ // {{filepath: [|option] }}
+ $option = $argA;
+ }
+
+ if ( $file ) {
+ $url = $file->getUrl();
+
+ // If a size is requested...
+ if ( is_integer( $size ) ) {
+ $mto = $file->transform( array( 'width' => $size ) );
+ // ... and we can
+ if ( $mto && !$mto->isError() ) {
+ // ... change the URL to point to a thumbnail.
+ $url = wfExpandUrl( $mto->getUrl() );
+ }
+ }
+ if ( $option == 'nowiki' ) {
return array( $url, 'nowiki' => true );
}
return $url;
* Parser function to extension tag adaptor
*/
public static function tagObj( $parser, $frame, $args ) {
- $xpath = false;
if ( !count( $args ) ) {
return '';
}
$stripList = $parser->getStripList();
if ( !in_array( $tagName, $stripList ) ) {
return '<span class="error">' .
- wfMsg( 'unknown_extension_tag', $tagName ) .
+ wfMsgForContent( 'unknown_extension_tag', $tagName ) .
'</span>';
}