Added {{#special:}} parser function, to give the local default title for special...
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 31 Oct 2006 13:25:47 +0000 (13:25 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 31 Oct 2006 13:25:47 +0000 (13:25 +0000)
RELEASE-NOTES
includes/CoreParserFunctions.php
includes/Parser.php
includes/SpecialPage.php
languages/messages/MessagesEn.php

index b8a63bf..af2ff62 100644 (file)
@@ -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 ==
 
index 2081b3f..b2ee789 100644 (file)
@@ -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' );
+               }
+       }
 }
 
 ?>
index cfe1d70..336b6f8 100644 (file)
@@ -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 );
index 73b6233..e8db18b 100644 (file)
@@ -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;
+               }
        }
 
        /**
index 9a174ea..9ecdf28 100644 (file)
@@ -318,6 +318,7 @@ $magicWords = array(
        'formatnum'              => array( 0,    'FORMATNUM'              ),
        'padleft'                => array( 0,    'PADLEFT'                ),
        'padright'               => array( 0,    'PADRIGHT'               ),
+       'special'                => array( 0,    'special',               ),
 );
 
 /**