From: Tim Starling Date: Tue, 31 Oct 2006 13:25:47 +0000 (+0000) Subject: Added {{#special:}} parser function, to give the local default title for special... X-Git-Tag: 1.31.0-rc.0~55345 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=ac28d6f10a68683f5534b79fc0be6446a851a0a2;p=lhc%2Fweb%2Fwiklou.git Added {{#special:}} parser function, to give the local default title for special pages --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b8a63bfcd0..af2ff62a0e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -108,6 +108,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Used special page subpages in a few more places, instead of query parameters. * (bug 7758) Added wrapper span to "templates used" explanation to allow CSS styling (class="mw-templatesUsedExplanation"). +* Added {{#special:}} parser function, to give the local default title for + special pages == Languages updated == diff --git a/includes/CoreParserFunctions.php b/includes/CoreParserFunctions.php index 2081b3f203..b2ee789dd2 100644 --- a/includes/CoreParserFunctions.php +++ b/includes/CoreParserFunctions.php @@ -174,7 +174,15 @@ class CoreParserFunctions { function anchorencode( $parser, $text ) { return str_replace( '%', '.', str_replace('+', '_', urlencode( $text ) ) ); } - + + function special( $parser, $text ) { + $title = SpecialPage::getTitleForAlias( $text ); + if ( $title ) { + return $title->getPrefixedText(); + } else { + return wfMsgForContent( 'nosuchspecialpage' ); + } + } } ?> diff --git a/includes/Parser.php b/includes/Parser.php index cfe1d70b2e..336b6f8f32 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -164,6 +164,7 @@ class Parser $this->setFunctionHook( 'padleft', array( 'CoreParserFunctions', 'padleft' ), SFH_NO_HASH ); $this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH ); $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH ); + $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) ); if ( $wgAllowDisplayTitle ) { $this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH ); diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 73b6233f50..e8db18b742 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -475,7 +475,11 @@ class SpecialPage */ static function getTitleFor( $name, $subpage = false ) { $name = self::getLocalNameFor( $name, $subpage ); - return Title::makeTitle( NS_SPECIAL, $name ); + if ( $name ) { + return Title::makeTitle( NS_SPECIAL, $name ); + } else { + throw new MWException( "Invalid special page name \"$name\"" ); + } } /** @@ -483,15 +487,24 @@ class SpecialPage */ static function getSafeTitleFor( $name, $subpage = false ) { $name = self::getLocalNameFor( $name, $subpage ); - return Title::makeTitleSafe( NS_SPECIAL, $name ); + if ( $name ) { + return Title::makeTitleSafe( NS_SPECIAL, $name ); + } else { + return null; + } } /** * Get a title for a given alias + * @return Title or null if there is no such alias */ static function getTitleForAlias( $alias ) { $name = self::resolveAlias( $alias ); - return self::getTitleFor( $name ); + if ( $name ) { + return self::getTitleFor( $name ); + } else { + return null; + } } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 9a174ea208..9ecdf287ae 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -318,6 +318,7 @@ $magicWords = array( 'formatnum' => array( 0, 'FORMATNUM' ), 'padleft' => array( 0, 'PADLEFT' ), 'padright' => array( 0, 'PADRIGHT' ), + 'special' => array( 0, 'special', ), ); /**