Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2189,6 +2189,18 @@ |
2190 | 2190 | $wgExtensionMessagesFiles = array(); |
2191 | 2191 | |
2192 | 2192 | /** |
| 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 | +/** |
2193 | 2205 | * Parser output hooks. |
2194 | 2206 | * This is an associative array where the key is an extension-defined tag |
2195 | 2207 | * (typically the extension name), and the value is a PHP callback. |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -1719,15 +1719,70 @@ |
1720 | 1720 | */ |
1721 | 1721 | function getSpecialPageAliases() { |
1722 | 1722 | $this->load(); |
| 1723 | + |
| 1724 | + // Cache aliases because it may be slow to load them |
1723 | 1725 | if ( !isset( $this->mExtendedSpecialPageAliases ) ) { |
| 1726 | + |
| 1727 | + // Initialise array |
1724 | 1728 | $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 ) ); |
1727 | 1767 | } |
| 1768 | + |
1728 | 1769 | return $this->mExtendedSpecialPageAliases; |
1729 | 1770 | } |
1730 | 1771 | |
1731 | 1772 | /** |
| 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 | + /** |
1732 | 1787 | * Italic is unsuitable for some languages |
1733 | 1788 | * |
1734 | 1789 | * @param $text String: the text to be emphasized. |
— | — | @@ -2250,12 +2305,9 @@ |
2251 | 2306 | # Replace spaces with underscores in namespace names |
2252 | 2307 | $cache['namespaceNames'] = str_replace( ' ', '_', $cache['namespaceNames'] ); |
2253 | 2308 | |
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'] ); |
2260 | 2312 | |
2261 | 2313 | # Save to both caches |
2262 | 2314 | self::$mLocalisationCache[$code] = $cache; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -62,6 +62,8 @@ |
63 | 63 | is no longer possible. |
64 | 64 | * $wgMessageCacheType defines now the type of cache used by the MessageCache class, |
65 | 65 | 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 |
66 | 68 | |
67 | 69 | === New features in 1.13 === |
68 | 70 | |