X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fparser%2FCoreParserFunctions.php;h=67abb10dfc7ccc151ed2179ebaff5bfd7648f0c1;hb=d761eab34985f57a3e304198db60a1d9b1fc51bc;hp=88349b6412dd6f8ce8aa1d3380ccbce096a03d63;hpb=dfd6988313d7033c8294d4b1ce7d9e92604501dc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 88349b6412..67abb10dfc 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -10,6 +10,10 @@ * @ingroup Parser */ class CoreParserFunctions { + /** + * @param $parser Parser + * @return void + */ static function register( $parser ) { global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions; @@ -83,6 +87,11 @@ class CoreParserFunctions { } } + /** + * @param $parser Parser + * @param string $part1 + * @return array + */ static function intFunction( $parser, $part1 = '' /*, ... */ ) { if ( strval( $part1 ) !== '' ) { $args = array_slice( func_get_args(), 2 ); @@ -94,6 +103,12 @@ class CoreParserFunctions { } } + /** + * @param $parser Parser + * @param $date + * @param null $defaultPref + * @return mixed|string + */ static function formatDate( $parser, $date, $defaultPref = null ) { $df = DateFormatter::getInstance(); @@ -171,6 +186,11 @@ class CoreParserFunctions { return $wgContLang->ucfirst( $s ); } + /** + * @param $parser Parser + * @param string $s + * @return + */ static function lc( $parser, $s = '' ) { global $wgContLang; if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) { @@ -180,6 +200,11 @@ class CoreParserFunctions { } } + /** + * @param $parser Parser + * @param string $s + * @return + */ static function uc( $parser, $s = '' ) { global $wgContLang; if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) { @@ -218,6 +243,12 @@ class CoreParserFunctions { } } + /** + * @param $parser Parser + * @param string $num + * @param null $raw + * @return + */ static function formatNum( $parser, $num = '', $raw = null) { if ( self::israw( $raw ) ) { return $parser->getFunctionLang()->parseFormattedNumber( $num ); @@ -226,34 +257,54 @@ class CoreParserFunctions { } } + /** + * @param $parser Parser + * @param string $case + * @param string $word + * @return + */ static function grammar( $parser, $case = '', $word = '' ) { return $parser->getFunctionLang()->convertGrammar( $word, $case ); } - static function gender( $parser, $user ) { + /** + * @param $parser Parser + * @param $username string + * @return + */ + static function gender( $parser, $username ) { wfProfileIn( __METHOD__ ); $forms = array_slice( func_get_args(), 2); + $username = trim( $username ); + // default $gender = User::getDefaultOption( 'gender' ); // allow prefix. - $title = Title::newFromText( $user ); + $title = Title::newFromText( $username ); - if ( is_object( $title ) && $title->getNamespace() == NS_USER ) - $user = $title->getText(); + if ( $title && $title->getNamespace() == NS_USER ) { + $username = $title->getText(); + } // check parameter, or use the ParserOptions if in interface message - $user = User::newFromName( $user ); + $user = User::newFromName( $username ); if ( $user ) { $gender = $user->getOption( 'gender' ); - } elseif ( $parser->getOptions()->getInterfaceMessage() ) { + } elseif ( $username === '' && $parser->getOptions()->getInterfaceMessage() ) { $gender = $parser->getOptions()->getUser()->getOption( 'gender' ); } $ret = $parser->getFunctionLang()->gender( $gender, $forms ); wfProfileOut( __METHOD__ ); return $ret; } + + /** + * @param $parser Parser + * @param string $text + * @return + */ static function plural( $parser, $text = '' ) { $forms = array_slice( func_get_args(), 2 ); $text = $parser->getFunctionLang()->parseFormattedNumber( $text ); @@ -394,10 +445,11 @@ class CoreParserFunctions { return ''; return wfUrlencode( $t->getSubjectNsText() ); } - /* + + /** * Functions to get and normalize pagenames, corresponding to the magic words * of the same names - */ + */ static function pagename( $parser, $title = null ) { $t = Title::newFromText( $title ); if ( is_null( $t ) ) @@ -501,12 +553,13 @@ class CoreParserFunctions { * Return the size of the given page, or 0 if it's nonexistent. This is an * expensive parser function and can't be called too many times per page. * - * @todo Fixme: This doesn't work correctly on preview for getting the size + * @todo FIXME: This doesn't work correctly on preview for getting the size * of the current page. - * @todo Fixme: Title::getLength() documentation claims that it adds things + * @todo FIXME: Title::getLength() documentation claims that it adds things * to the link cache, so the local cache here should be unnecessary, but * in fact calling getLength() repeatedly for the same $page does seem to * run one query for each call? + * @param $parser Parser */ static function pagesize( $parser, $page = '', $raw = null ) { static $cache = array(); @@ -584,12 +637,17 @@ class CoreParserFunctions { return self::pad( $string, $length, $padding ); } + /** + * @param $parser Parser + * @param $text + * @return string + */ static function anchorencode( $parser, $text ) { return substr( $parser->guessSectionNameFromWikiText( $text ), 1); } static function special( $parser, $text ) { - list( $page, $subpage ) = SpecialPage::resolveAliasWithSubpage( $text ); + list( $page, $subpage ) = SpecialPageFactory::resolveAlias( $text ); if ( $page ) { $title = SpecialPage::getTitleFor( $page, $subpage ); return $title; @@ -598,6 +656,11 @@ class CoreParserFunctions { } } + /** + * @param $parser Parser + * @param $text + * @return string + */ public static function defaultsort( $parser, $text ) { $text = trim( $text ); if( strlen( $text ) == 0 ) @@ -637,7 +700,7 @@ class CoreParserFunctions { } if ( $file ) { - $url = $file->getUrl(); + $url = $file->getFullUrl(); // If a size is requested... if ( is_integer( $size ) ) {