r36631 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36630‎ | r36631 | r36632 >
Date:10:59, 25 June 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* $wgExtensionAliasesFiles option to simplify adding aliases for special pages provided by extensions
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -2189,6 +2189,18 @@
21902190 $wgExtensionMessagesFiles = array();
21912191
21922192 /**
 2193+ * Aliases for special pages provided by extensions.
 2194+ * Associative array mapping special page to array of aliases. First alternative
 2195+ * for each special page will be used as the normalised name for it. English
 2196+ * aliases will be added to the end of the list so that they always work. The
 2197+ * file must define a variable $aliases.
 2198+ *
 2199+ * Example:
 2200+ * $wgExtensionAliasesFiles['Translate'] = dirname(__FILE__).'/Translate.alias.php';
 2201+ */
 2202+$wgExtensionAliasesFiles = array();
 2203+
 2204+/**
21932205 * Parser output hooks.
21942206 * This is an associative array where the key is an extension-defined tag
21952207 * (typically the extension name), and the value is a PHP callback.
Index: trunk/phase3/languages/Language.php
@@ -1719,15 +1719,70 @@
17201720 */
17211721 function getSpecialPageAliases() {
17221722 $this->load();
 1723+
 1724+ // Cache aliases because it may be slow to load them
17231725 if ( !isset( $this->mExtendedSpecialPageAliases ) ) {
 1726+
 1727+ // Initialise array
17241728 $this->mExtendedSpecialPageAliases = $this->specialPageAliases;
1725 - wfRunHooks( 'LanguageGetSpecialPageAliases',
1726 - array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
 1729+
 1730+ global $wgExtensionAliasesFiles;
 1731+ foreach ( $wgExtensionAliasesFiles as $file ) {
 1732+
 1733+ // Fail fast
 1734+ if ( !file_exists($file) )
 1735+ throw new MWException( 'Aliases file does not exist' );
 1736+
 1737+ $aliases = array();
 1738+ require($file);
 1739+
 1740+ // Check the availability of aliases
 1741+ if ( !isset($aliases['en']) )
 1742+ throw new MWException( 'Malformed aliases file' );
 1743+
 1744+ $code = $this->getCode();
 1745+
 1746+ if ( isset($aliases[$code]) ) {
 1747+ $aliases[$code] = $this->fixSpecialPageAliases( $aliases[$code] );
 1748+ /* Merge the aliases, THIS will break if there is special page name
 1749+ * which looks like a numerical key, thanks to PHP...
 1750+ * See the comments for wfArrayMerge in GlobalSettings.php. */
 1751+ $this->mExtendedSpecialPageAliases = array_merge_recursive(
 1752+ $this->mExtendedSpecialPageAliases, $aliases[$code] );
 1753+ }
 1754+
 1755+ /* Add the English aliases to the end of list as aliases... unless we
 1756+ * already added them! */
 1757+ if ( $code !== 'en' ) {
 1758+ $aliases['en'] = $this->fixSpecialPageAliases( $aliases['en'] );
 1759+ $this->mExtendedSpecialPageAliases = array_merge_recursive(
 1760+ $this->mExtendedSpecialPageAliases, $aliases['en'] );
 1761+ }
 1762+
 1763+ }
 1764+
 1765+ wfRunHooks( 'LanguageGetSpecialPageAliases',
 1766+ array( &$this->mExtendedSpecialPageAliases, $code ) );
17271767 }
 1768+
17281769 return $this->mExtendedSpecialPageAliases;
17291770 }
17301771
17311772 /**
 1773+ * Function to fix special page aliases. Will convert the first letter to
 1774+ * upper case and spaces to underscores. Can be given a full aliases array,
 1775+ * in which case it will recursively fix all aliases.
 1776+ */
 1777+ public function fixSpecialPageAliases( $mixed ) {
 1778+ // Work recursively until in string level
 1779+ if ( is_array($mixed) ) {
 1780+ $callback = array( $this, 'fixSpecialPageAliases' );
 1781+ return array_map( $callback, $mixed );
 1782+ }
 1783+ return str_replace( ' ', '_', $this->ucfirst( $mixed ) );
 1784+ }
 1785+
 1786+ /**
17321787 * Italic is unsuitable for some languages
17331788 *
17341789 * @param $text String: the text to be emphasized.
@@ -2250,12 +2305,9 @@
22512306 # Replace spaces with underscores in namespace names
22522307 $cache['namespaceNames'] = str_replace( ' ', '_', $cache['namespaceNames'] );
22532308
2254 - # And do the same for specialpage aliases. $page is an array.
2255 - foreach ( $cache['specialPageAliases'] as &$page ) {
2256 - $page = str_replace( ' ', '_', $page );
2257 - }
2258 - # Decouple the reference to prevent accidental damage
2259 - unset($page);
 2309+ # And do the same for specialpage aliases.
 2310+ $cache['specialPageAliases'] =
 2311+ $this->fixSpecialPageAliases( $cache['specialPageAliases'] );
22602312
22612313 # Save to both caches
22622314 self::$mLocalisationCache[$code] = $cache;
Index: trunk/phase3/RELEASE-NOTES
@@ -62,6 +62,8 @@
6363 is no longer possible.
6464 * $wgMessageCacheType defines now the type of cache used by the MessageCache class,
6565 previously it was choosen based on $wgParserCacheType
 66+* $wgExtensionAliasesFiles option to simplify adding aliases to special pages
 67+* provided by extensions, in a similar way to $wgExtensionMessagesFiles
6668
6769 === New features in 1.13 ===
6870

Status & tagging log