From: Kunal Mehta Date: Tue, 9 Aug 2016 22:27:29 +0000 (-0700) Subject: Add SpecialPage::getTitleValueFor() X-Git-Tag: 1.31.0-rc.0~6091^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=00c57269011c558ea892b4b8d4dd039d18881119;p=lhc%2Fweb%2Fwiklou.git Add SpecialPage::getTitleValueFor() One of the most frequent instances of Title being used where TitleValue could be used instead is for special pages, since there is no convenience function that returns a TitleValue object. Hopefully this will make it easier. Because TitleValue is stricer about validation, we need to ensure that $subpage is in dbkey form. Change-Id: I50457620e25dfe03eb44d6fda5aabebcbf314863 --- diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index 35ecc6e4b6..44b8fff819 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -67,6 +67,8 @@ class SpecialPage { /** * Get a localised Title object for a specified special page name + * If you don't need a full Title object, consider using TitleValue through + * getTitleValueFor() below. * * @since 1.9 * @since 1.21 $fragment parameter added @@ -78,9 +80,24 @@ class SpecialPage { * @throws MWException */ public static function getTitleFor( $name, $subpage = false, $fragment = '' ) { + return Title::newFromTitleValue( + self::getTitleValueFor( $name, $subpage, $fragment ) + ); + } + + /** + * Get a localised TitleValue object for a specified special page name + * + * @since 1.28 + * @param string $name + * @param string|bool $subpage Subpage string, or false to not use a subpage + * @param string $fragment The link fragment (after the "#") + * @return TitleValue + */ + public static function getTitleValueFor( $name, $subpage = false, $fragment = '' ) { $name = SpecialPageFactory::getLocalNameFor( $name, $subpage ); - return Title::makeTitle( NS_SPECIAL, $name, $fragment ); + return new TitleValue( NS_SPECIAL, $name, $fragment ); } /** diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index b69b28afb4..68c817c87f 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -714,6 +714,8 @@ class SpecialPageFactory { } if ( $subpage !== false && !is_null( $subpage ) ) { + // Make sure it's in dbkey form + $subpage = str_replace( ' ', '_', $subpage ); $name = "$name/$subpage"; }