r55656 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55655‎ | r55656 | r55657 >
Date:17:58, 28 August 2009
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
Reverted breakage of non-ASCII message keys, Domas says that's not allowed. Optimised Language::lcfirst and Language::ucfirst() instead.
Timings in microseconds for ASCII no-change, ASCII change, non-ASCII no-change, non-ASCII change:
lcfirst: 1.8, 3.6, 21.2, 22.1
ucfirst: 1.5, 2.3, 21.1, 21.7
Modified paths:
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MessageCache.php
@@ -509,10 +509,15 @@
510510
511511 $message = false;
512512
513 - # Normalise title-case input
 513+ # Normalise title-case input (with some inlining)
514514 $lckey = str_replace( ' ', '_', $key );
515 - $lckey[0] = strtolower( $lckey[0] );
516 - $uckey = ucfirst( $lckey );
 515+ if ( ord( $key ) < 128 ) {
 516+ $lckey[0] = strtolower( $lckey[0] );
 517+ $uckey = ucfirst( $lckey );
 518+ } else {
 519+ $lckey = $wgContLang->lcfirst( $lckey );
 520+ $uckey = $wgContLang->ucfirst( $lckey );
 521+ }
517522
518523 # Try the MediaWiki namespace
519524 if( !$this->mDisable && $useDB ) {
Index: trunk/phase3/languages/Language.php
@@ -1509,9 +1509,15 @@
15101510 }
15111511
15121512 function ucfirst( $str ) {
1513 - if ( empty($str) ) return $str;
1514 - if ( ord($str[0]) < 128 ) return ucfirst($str);
1515 - else return self::uc($str,true); // fall back to more complex logic in case of multibyte strings
 1513+ $o = ord( $str );
 1514+ if ( $o < 96 ) {
 1515+ return $str;
 1516+ } elseif ( $o < 128 ) {
 1517+ return ucfirst($str);
 1518+ } else {
 1519+ // fall back to more complex logic in case of multibyte strings
 1520+ return self::uc($str,true);
 1521+ }
15161522 }
15171523
15181524 function uc( $str, $first = false ) {
@@ -1541,13 +1547,17 @@
15421548 }
15431549
15441550 function lcfirst( $str ) {
1545 - if ( empty($str) ) return $str;
1546 - if ( is_string( $str ) && ord($str[0]) < 128 ) {
1547 - // editing string in place = cool
1548 - $str[0]=strtolower($str[0]);
 1551+ $o = ord( $str );
 1552+ if ( !$o ) {
 1553+ return strval( $str );
 1554+ } elseif ( $o >= 128 ) {
 1555+ return self::lc( $str, true );
 1556+ } elseif ( $o > 96 ) {
15491557 return $str;
 1558+ } else {
 1559+ $str[0] = strtolower( $str[0] );
 1560+ return $str;
15501561 }
1551 - else return self::lc( $str, true );
15521562 }
15531563
15541564 function lc( $str, $first = false ) {

Comments

#Comment by Raymond (talk | contribs)   17:54, 27 April 2010

Seen on translatewiki since a few days (~ 2010-05-24):

PHP Notice: Array to string conversion in /www/w/includes/MessageCache.php  on line 514
#Comment by Tim Starling (talk | contribs)   20:46, 27 April 2010

That sounds like not my fault.

Status & tagging log