r49157 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49156‎ | r49157 | r49158 >
Date:17:35, 3 April 2009
Author:philip
Status:resolved (Comments)
Tags:
Comment:
1. Rewrite code for parsing http request header to get supported language variant. Now the current code is written for every language if they do need this.
2. Fixed a bug caused by LanguageConverter.php, which brings an abnormal '}-' after some parsed math syntax.
3. Update the Chinese conversion table.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/ZhConversion.php (modified) (history)
  • /trunk/phase3/includes/zhtable/simpphrases.manual (modified) (history)
  • /trunk/phase3/includes/zhtable/toTrad.manual (modified) (history)
  • /trunk/phase3/includes/zhtable/tradphrases.manual (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/zhtable/tradphrases.manual
@@ -3123,7 +3123,7 @@
31243124 皆可作澱
31253125 澱山
31263126 澱澱
3127 -掛鈎
 3127+掛鉤
31283128 薴悴
31293129 絡腮鬍
31303130 落腮鬍
@@ -3138,4 +3138,6 @@
31393139 鬍髯
31403140 髯鬍
31413141 髭鬍
3142 -鬚鬍
\ No newline at end of file
 3142+鬚鬍
 3143+范文瀾
 3144+發表
\ No newline at end of file
Index: trunk/phase3/includes/zhtable/toTrad.manual
@@ -65,4 +65,6 @@
6666 不干預 不干預
6767 不干擾 不干擾
6868 不干牠 不干牠
69 -矽谷 矽谷
\ No newline at end of file
 69+矽谷 矽谷
 70+范文瀾 范文瀾
 71+發表 發表
\ No newline at end of file
Index: trunk/phase3/includes/zhtable/simpphrases.manual
@@ -2200,4 +2200,5 @@
22012201 幺谦
22022202 麴义
22032203 麴英
2204 -麯崇裕
\ No newline at end of file
 2204+麯崇裕
 2205+阿部正瞭
\ No newline at end of file
Index: trunk/phase3/includes/ZhConversion.php
@@ -5279,7 +5279,7 @@
52805280 '掌柜' => '掌柜',
52815281 '排骨面' => '排骨麵',
52825282 '挂帘' => '掛帘',
5283 -'挂钩' => '掛鈎',
 5283+'挂钩' => '掛鉤',
52845284 '挂钟' => '掛鐘',
52855285 '采下' => '採下',
52865286 '采伐' => '採伐',
@@ -6376,6 +6376,8 @@
63776377 '发签' => '發籤',
63786378 '发庄' => '發莊',
63796379 '发着' => '發著',
 6380+'发表' => '發表',
 6381+'發表' => '發表',
63806382 '发松' => '發鬆',
63816383 '发面' => '發麵',
63826384 '白干' => '白乾',
@@ -7055,6 +7057,8 @@
70567058 '英占' => '英佔',
70577059 '苹萦' => '苹縈',
70587060 '茂都淀' => '茂都澱',
 7061+'范文瀾' => '范文瀾',
 7062+'范文澜' => '范文瀾',
70597063 '范登堡' => '范登堡',
70607064 '茶几' => '茶几',
70617065 '茶庄' => '茶莊',
@@ -14051,6 +14055,7 @@
1405214056 '閑著稱' => '闲著称',
1405314057 '閑著者' => '闲著者',
1405414058 '閑著述' => '闲著述',
 14059+'阿部正瞭' => '阿部正瞭',
1405514060 '附著' => '附着',
1405614061 '附睪' => '附睾',
1405714062 '附著書' => '附著书',
Index: trunk/phase3/languages/LanguageConverter.php
@@ -177,25 +177,22 @@
178178 return $this->mPreferredVariant;
179179 }
180180
181 - # FIXME rewrite code for parsing http header. The current code
182 - # is written specific for detecting zh- variants
183181 if( !$this->mPreferredVariant ) {
184182 // see if some supported language variant is set in the
185183 // http header, but we don't set the mPreferredVariant
186184 // variable in case this is called before the user's
187185 // preference is loaded
188 - $pv=$this->mMainLanguageCode;
189 - if(array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
190 - $header = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
191 - $zh = strstr($header, $pv.'-');
192 - if($zh) {
193 - $ary = split("[,;]",$zh);
194 - $pv = $ary[0];
 186+ $preferredVariant = $this->mMainLanguageCode;
 187+ if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
 188+ $acceptLanguage = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
 189+ $languages = preg_split('/[,;]/', $acceptLanguage);
 190+ foreach( $languages as $language ) {
 191+ if( in_array( $language, $this->mVariants ) ) {
 192+ return $language;
 193+ break;
 194+ }
195195 }
196196 }
197 - // don't try to return bad variant
198 - if(in_array( $pv, $this->mVariants ))
199 - return $pv;
200197 }
201198
202199 return $this->mMainLanguageCode;
@@ -870,6 +867,9 @@
871868 * @public
872869 */
873870 function armourMath($text){
 871+ // we need to convert '-{' and '}-' to '-{' and '}-'
 872+ // to avoid a unwanted '}-' appeared after the math-image.
 873+ $text = strtr( $text, array('-{' => '-{', '}-' => '}-') );
874874 $ret = $this->mMarkup['begin'] . 'R|' . $text . $this->mMarkup['end'];
875875 return $ret;
876876 }
Index: trunk/phase3/RELEASE-NOTES
@@ -372,6 +372,8 @@
373373 * Added uiprop=changeablegroups to meta=userinfo
374374 * Added usprop=gender to list=users
375375 * (bug 18311) action=purge now works for images too
 376+* Fixed a bug caused by LanguageConverter.php, which brings an abnormal '}-'
 377+ after some parsed math syntax.
376378
377379 === Languages updated in 1.15 ===
378380

Follow-up revisions

RevisionCommit summaryAuthorDate
r49158Follow up on r49157, remove an unused variable.philip17:51, 3 April 2009
r50902Follow up on r49157. Fixed the header parsing code to conform to RFC 2616 sec...philip17:40, 22 May 2009
r50938Follow up on r49157 and r50902. Fixed the header parsing code to conform to RFC.philip15:27, 23 May 2009
r511771. Follow up on r49157, r50902 and r50938. According RFC 2616 section 14.4, l...philip05:07, 30 May 2009

Comments

#Comment by Tim Starling (talk | contribs)   08:29, 19 May 2009

Please fix the header parsing code to conform to RFC 2616 section 14.4:

http://tools.ietf.org/rfcmarkup?doc=2616#section-14.4

Treating comma and semicolon as the same is lazy and incorrect. Split by comma, then take the part of the string up to the first semicolon, and strip whitespace.

#Comment by PhiLiP (talk | contribs)   19:19, 22 May 2009

Fixed on

#Comment by PhiLiP (talk | contribs)   19:19, 22 May 2009

Fixed on r50902.

Status & tagging log