r99074 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99073‎ | r99074 | r99075 >
Date:02:31, 6 October 2011
Author:tstarling
Status:ok
Tags:
Comment:
Fixes for r84057 LanguageTr uc/lc:
* Fixed inappropriate use of empty(), see style guide
* Made uc() and lc() respect the $first parameter. Not doing this completely broke the Turkish wikipedia, sending links like [[İngilizce]] to [[İngİlİzce]].
* Use str_replace() instead of preg_replace(). It's not necessary to use a unicode-aware replacement algorithm to do UTF-8 string replacements, due to details of the UTF-8 encoding format. I'm not sure how Hashar concluded that strtr() will produce garbage.
Modified paths:
  • /trunk/phase3/languages/classes/LanguageTr.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/classes/LanguageTr.php
@@ -17,7 +17,7 @@
1818 * @return string
1919 */
2020 function ucfirst ( $string ) {
21 - if ( !empty( $string ) && $string[0] == 'i' ) {
 21+ if ( strlen( $string ) && $string[0] == 'i' ) {
2222 return 'İ' . substr( $string, 1 );
2323 } else {
2424 return parent::ucfirst( $string );
@@ -29,7 +29,7 @@
3030 * @return mixed|string
3131 */
3232 function lcfirst ( $string ) {
33 - if ( !empty( $string ) && $string[0] == 'I' ) {
 33+ if ( strlen( $string ) && $string[0] == 'I' ) {
3434 return 'ı' . substr( $string, 1 );
3535 } else {
3636 return parent::lcfirst( $string );
@@ -45,7 +45,15 @@
4646 * @return string
4747 */
4848 function uc( $string, $first = false ) {
49 - $string = preg_replace( '/i/', 'İ', $string );
 49+ if ( strlen( $string ) ) {
 50+ if ( $first ) {
 51+ if ( $string[0] === 'i' ) {
 52+ $string = 'İ' . substr( $string, 1 );
 53+ }
 54+ } else {
 55+ $string = str_replace( 'i', 'İ', $string );
 56+ }
 57+ }
5058 return parent::uc( $string, $first );
5159 }
5260
@@ -58,7 +66,15 @@
5967 * @return string
6068 */
6169 function lc( $string, $first = false ) {
62 - $string = preg_replace( '/I/', 'ı', $string );
 70+ if ( strlen( $string ) ) {
 71+ if ( $first ) {
 72+ if ( $string[0] == 'I' ) {
 73+ $string = 'ı' . substr( $string, 1 );
 74+ }
 75+ } else {
 76+ $string = str_replace( 'I', 'ı', $string );
 77+ }
 78+ }
6379 return parent::lc( $string, $first );
6480 }
6581

Follow-up revisions

RevisionCommit summaryAuthorDate
r99075MFT r99074 (LanguageTr::uc() breakage)tstarling02:34, 6 October 2011
r99290Revert r84057, r84080, part of r99074: lc() and uc() custom handling for Turk...brion00:30, 8 October 2011
r102466Readd Names.php and other files removed in r102465...platonides23:35, 8 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84057bug 28040 Turkish: properly handle dotted and dotless i...hashar21:56, 15 March 2011

Status & tagging log