r50938 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50937‎ | r50938 | r50939 >
Date:15:27, 23 May 2009
Author:philip
Status:ok
Tags:
Comment:
Follow up on r49157 and r50902. Fixed the header parsing code to conform to RFC.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -185,13 +185,22 @@
186186 if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
187187 $acceptLanguage = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
188188
189 - // take the part of the string up to the first semicolon
190 - if($semiPos = strpos( $acceptLanguage, ';' ) !== false )
191 - $acceptLanguage = substr( $acceptLanguage, 0, $semiPos );
192 -
193189 // explode by comma
194 - $languages = explode(',', $acceptLanguage);
 190+ $result = explode(',', $acceptLanguage);
 191+
 192+ $languages = array();
195193
 194+ foreach( $result as $elem ) {
 195+ // if $elem likes 'zh-cn;q=0.9'
 196+ if(($posi = strpos( $elem, ';' )) !== false ) {
 197+ // get the real language code likes 'zh-cn'
 198+ $languages[] = substr( $elem, 0, $posi );
 199+ }
 200+ else {
 201+ $languages[] = $elem;
 202+ }
 203+ }
 204+
196205 foreach( $languages as $language ) {
197206 // strip whitespace
198207 $language = trim( $language );

Follow-up revisions

RevisionCommit summaryAuthorDate
r511771. Follow up on r49157, r50902 and r50938. According RFC 2616 section 14.4, l...philip05:07, 30 May 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r491571. Rewrite code for parsing http request header to get supported language var...philip17:35, 3 April 2009
r50902Follow up on r49157. Fixed the header parsing code to conform to RFC 2616 sec...philip17:40, 22 May 2009

Status & tagging log