r60721 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60720‎ | r60721 | r60722 >
Date:10:20, 6 January 2010
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Per CR on r58358, refactor obtaining the language code from a filename into Language::getCodeFromFileName() and use it in Language::getLanguageNames() and LocalisationUpdate
Modified paths:
  • /trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -465,12 +465,9 @@
466466 $names = array();
467467 $dir = opendir( "$IP/languages/messages" );
468468 while( false !== ( $file = readdir( $dir ) ) ) {
469 - $m = array();
470 - if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $file, $m ) ) {
471 - $code = str_replace( '_', '-', strtolower( $m[1] ) );
472 - if ( isset( $allNames[$code] ) ) {
473 - $names[$code] = $allNames[$code];
474 - }
 469+ $code = self::getCodeFromFileName( $file, 'Messages' );
 470+ if ( $code && isset( $allNames[$code] ) ) {
 471+ $names[$code] = $allNames[$code];
475472 }
476473 }
477474 closedir( $dir );
@@ -2492,9 +2489,33 @@
24932490 $this->mCode = $code;
24942491 }
24952492
 2493+ /**
 2494+ * Get the name of a file for a certain language code
 2495+ * @param $prefix string Prepend this to the filename
 2496+ * @param $code string Language code
 2497+ * @param $suffix string Append this to the filename
 2498+ * @return string $prefix . $mangledCode . $suffix
 2499+ */
24962500 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
24972501 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
24982502 }
 2503+
 2504+ /**
 2505+ * Get the language code from a file name. Inverse of getFileName()
 2506+ * @param $filename string $prefix . $languageCode . $suffix
 2507+ * @param $prefix string Prefix before the language code
 2508+ * @param $suffix string Suffix after the language code
 2509+ * @return Language code, or false if $prefix or $suffix isn't found
 2510+ */
 2511+ static function getCodeFromFileName( $filename, $prefix = 'Language', $suffix = '.php' ) {
 2512+ $m = null;
 2513+ preg_match( '/' . preg_quote( $prefix ) . '([A-Z][a-z_])' .
 2514+ preg_quote( $suffix ) . '/', $filename, $m );
 2515+ if ( !count( $m ) ) {
 2516+ return false;
 2517+ }
 2518+ return str_replace( '_', '-', strtolower( $m[1] ) );
 2519+ }
24992520
25002521 static function getMessagesFileName( $code ) {
25012522 global $IP;
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php
@@ -190,9 +190,7 @@
191191 $base_messages = array();
192192
193193 // Get the languagecode
194 - $m = array();
195 - preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $basefile, $m );
196 - $langcode = str_replace( '_', '-', strtolower( $m[1] ) );
 194+ $langcode = Language::getCodeFromFileName( $basefile, 'Messages' );
197195
198196 $basefilecontents = self::getFileContents( $basefile );
199197 if ( $basefilecontents === false || $basefilecontents === "" ) return array(); // Failed

Follow-up revisions

RevisionCommit summaryAuthorDate
r60740Follow-up to r60721. Broken maintanance/language/rebuildLanguage.php and prob...siebrand18:59, 6 January 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r58358LocalisationUpdate: Fix bug where languages with '-' in their name would not ...catrope12:07, 30 October 2009

Comments

#Comment by Nikerabbit (talk | contribs)   18:55, 6 January 2010

Pass the delimiter too to preg_quote()?

#Comment by Tim Starling (talk | contribs)   06:12, 20 January 2010

The preg_quote() fix was done in r60741.

Status & tagging log