r112402 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112401‎ | r112402 | r112403 >
Date:17:19, 25 February 2012
Author:robin
Status:ok
Tags:i18nreview 
Comment:
(Bug 34680) Make babel extension case aware in order to avoid clashes with existing user templates.
This gives precedence to existing templates when the code contains one or more uppercase letters (e.g. TeX). For lowercase codes, it still gives precedence to built-in boxes (introduced in r105540).
Modified paths:
  • /trunk/extensions/Babel/Babel.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Babel/Babel.class.php
@@ -40,17 +40,24 @@
4141 if ( $name === '' ) {
4242 continue;
4343 } elseif ( $components !== false ) {
44 - // Non-existent page and valid parameter syntax, babel box
 44+ // Valid parameter syntax (with lowercase language code), babel box
4545 $content .= self::mGenerateBox( $components['code'], $components['level'] );
4646 $content .= self::mGenerateCategories( $components['code'], $components['level'] );
4747 } elseif ( self::mPageExists( $template ) ) {
48 - // Check for a template
 48+ // Check for an existing template
4949 $templateParameters[0] = $template;
5050 $template = implode( '|', $templateParameters );
5151 $content .= self::mGenerateNotaBox( $parser->replaceVariables( "{{{$template}}}" ) );
5252 } elseif ( self::mValidTitle( $template ) ) {
53 - // Non-existent page and invalid parameter syntax, red link.
54 - $content .= self::mGenerateNotaBox( '[[' . $template . ']]' );
 53+ // Non-existing page, so try again as a babel box, with converting the code to lowercase
 54+ $components2 = self::mParseParameter( $name, /* code to lowercase */ true );
 55+ if ( $components2 !== false ) {
 56+ $content .= self::mGenerateBox( $components2['code'], $components2['level'] );
 57+ $content .= self::mGenerateCategories( $components2['code'], $components2['level'] );
 58+ } else {
 59+ // Non-existent page and invalid parameter syntax, red link.
 60+ $content .= self::mGenerateNotaBox( '[[' . $template . ']]' );
 61+ }
5562 } else {
5663 // Invalid title, output raw.
5764 $content .= self::mGenerateNotaBox( $template );
@@ -146,13 +153,14 @@
147154 * Parse a parameter, getting a language code and level.
148155 *
149156 * @param $parameter String: Parameter.
 157+ * @param $strtolower Boolean: Whether to convert the language code to lowercase
150158 * @return Array: { 'code' => xx, 'level' => xx }
151159 */
152 - protected static function mParseParameter( $parameter ) {
 160+ protected static function mParseParameter( $parameter, $strtolower = false ) {
153161 global $wgBabelDefaultLevel, $wgBabelCategoryNames;
154162 $return = array();
155163
156 - $babelcode = strtolower( $parameter );
 164+ $babelcode = $strtolower ? strtolower( $parameter ) : $parameter;
157165 // Try treating the paramter as a language code (for default level).
158166 $code = BabelLanguageCodes::getCode( $babelcode );
159167 if ( $code !== false ) {
@@ -168,7 +176,7 @@
169177 $code = substr( $parameter, 0, $lastSplit );
170178 $level = substr( $parameter, $lastSplit + 1 );
171179
172 - $babelcode = strtolower( $code );
 180+ $babelcode = $strtolower ? strtolower( $code ) : $code;
173181 // Validate code.
174182 $return['code'] = BabelLanguageCodes::getCode( $babelcode );
175183 if ( $return['code'] === false ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105540Bug 31330 - Do not prefer templates over built-in language boxes....nikerabbit11:53, 8 December 2011

Status & tagging log