r17321 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17320‎ | r17321 | r17322 >
Date:13:25, 31 October 2006
Author:tstarling
Status:old
Tags:
Comment:
Added {{#special:}} parser function, to give the local default title for special pages
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES
@@ -108,6 +108,8 @@
109109 * Used special page subpages in a few more places, instead of query parameters.
110110 * (bug 7758) Added wrapper span to "templates used" explanation to allow CSS
111111 styling (class="mw-templatesUsedExplanation").
 112+* Added {{#special:}} parser function, to give the local default title for
 113+ special pages
112114
113115 == Languages updated ==
114116
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -318,6 +318,7 @@
319319 'formatnum' => array( 0, 'FORMATNUM' ),
320320 'padleft' => array( 0, 'PADLEFT' ),
321321 'padright' => array( 0, 'PADRIGHT' ),
 322+ 'special' => array( 0, 'special', ),
322323 );
323324
324325 /**
Index: trunk/phase3/includes/Parser.php
@@ -164,6 +164,7 @@
165165 $this->setFunctionHook( 'padleft', array( 'CoreParserFunctions', 'padleft' ), SFH_NO_HASH );
166166 $this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH );
167167 $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH );
 168+ $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) );
168169
169170 if ( $wgAllowDisplayTitle ) {
170171 $this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH );
Index: trunk/phase3/includes/CoreParserFunctions.php
@@ -174,7 +174,15 @@
175175 function anchorencode( $parser, $text ) {
176176 return str_replace( '%', '.', str_replace('+', '_', urlencode( $text ) ) );
177177 }
178 -
 178+
 179+ function special( $parser, $text ) {
 180+ $title = SpecialPage::getTitleForAlias( $text );
 181+ if ( $title ) {
 182+ return $title->getPrefixedText();
 183+ } else {
 184+ return wfMsgForContent( 'nosuchspecialpage' );
 185+ }
 186+ }
179187 }
180188
181189 ?>
Index: trunk/phase3/includes/SpecialPage.php
@@ -475,7 +475,11 @@
476476 */
477477 static function getTitleFor( $name, $subpage = false ) {
478478 $name = self::getLocalNameFor( $name, $subpage );
479 - return Title::makeTitle( NS_SPECIAL, $name );
 479+ if ( $name ) {
 480+ return Title::makeTitle( NS_SPECIAL, $name );
 481+ } else {
 482+ throw new MWException( "Invalid special page name \"$name\"" );
 483+ }
480484 }
481485
482486 /**
@@ -483,15 +487,24 @@
484488 */
485489 static function getSafeTitleFor( $name, $subpage = false ) {
486490 $name = self::getLocalNameFor( $name, $subpage );
487 - return Title::makeTitleSafe( NS_SPECIAL, $name );
 491+ if ( $name ) {
 492+ return Title::makeTitleSafe( NS_SPECIAL, $name );
 493+ } else {
 494+ return null;
 495+ }
488496 }
489497
490498 /**
491499 * Get a title for a given alias
 500+ * @return Title or null if there is no such alias
492501 */
493502 static function getTitleForAlias( $alias ) {
494503 $name = self::resolveAlias( $alias );
495 - return self::getTitleFor( $name );
 504+ if ( $name ) {
 505+ return self::getTitleFor( $name );
 506+ } else {
 507+ return null;
 508+ }
496509 }
497510
498511 /**