r51177 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51176‎ | r51177 | r51178 >
Date:05:07, 30 May 2009
Author:philip
Status:ok
Tags:
Comment:
1. Follow up on r49157, r50902 and r50938. According RFC 2616 section 14.4, language code name should always use '-' but not '_'.

2. metadata 'keywords' should have all variant forms of keyword.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -85,7 +85,14 @@
8686 array_push( $this->mMetatags, array( $name, $val ) );
8787 }
8888
89 - function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
 89+ function addKeyword( $text ) {
 90+ if( is_array( $text )) {
 91+ $this->mKeywords = array_merge( $this->mKeywords, $text );
 92+ }
 93+ else {
 94+ array_push( $this->mKeywords, $text );
 95+ }
 96+ }
9097 function addScript( $script ) { $this->mScripts .= "\t\t".$script; }
9198
9299 function addExtensionStyle( $url ) {
@@ -1479,13 +1486,22 @@
14801487 }
14811488
14821489 /**
1483 - * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
 1490+ * This function takes the title (first item of mGoodLinks), categories,
 1491+ * existing and broken links for the page
14841492 * and uses the first 10 of them for META keywords
14851493 *
14861494 * @param ParserOutput &$parserOutput
14871495 */
14881496 private function addKeywords( &$parserOutput ) {
1489 - $this->addKeyword( $this->getTitle()->getPrefixedText() );
 1497+ global $wgContLang;
 1498+ // Get an array of keywords if there are more than one
 1499+ // variant of the site language
 1500+ $text = $wgContLang->autoConvertToAllVariants( $this->getTitle()->getPrefixedText());
 1501+ // array_values: We needn't to merge variant's code name
 1502+ // into $this->mKeywords;
 1503+ // array_unique: We should insert a keyword just for once
 1504+ $text = array_unique( array_values( $text ));
 1505+ $this->addKeyword( $text );
14901506 $count = 1;
14911507 $links2d =& $parserOutput->getLinks();
14921508 if ( !is_array( $links2d ) ) {
@@ -1493,6 +1509,8 @@
14941510 }
14951511 foreach ( $links2d as $dbkeys ) {
14961512 foreach( $dbkeys as $dbkey => $unused ) {
 1513+ $dbkey = $wgContLang->autoConvertToAllVariants( $dbkey );
 1514+ $dbkey = array_unique( array_values( $dbkey ));
14971515 $this->addKeyword( $dbkey );
14981516 if ( ++$count > 10 ) {
14991517 break 2;
Index: trunk/phase3/languages/LanguageConverter.php
@@ -183,7 +183,7 @@
184184 // variable in case this is called before the user's
185185 // preference is loaded
186186 if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
187 - $acceptLanguage = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));
 187+ $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
188188
189189 // explode by comma
190190 $result = explode(',', $acceptLanguage);
Index: trunk/phase3/languages/Language.php
@@ -35,6 +35,7 @@
3636 class FakeConverter {
3737 var $mLang;
3838 function FakeConverter($langobj) {$this->mLang = $langobj;}
 39+ function autoConvertToAllVariants($text) {return $text;}
3940 function convert($t, $i) {return $t;}
4041 function parserConvert($t, $p) {return $t;}
4142 function getVariants() { return array( $this->mLang->getCode() ); }
@@ -2243,6 +2244,11 @@
22442245 return $text;
22452246 }
22462247
 2248+ # convert text to all supported variants
 2249+ function autoConvertToAllVariants($text) {
 2250+ return $this->mConverter->autoConvertToAllVariants($text);
 2251+ }
 2252+
22472253 # convert text to different variants of a language.
22482254 function convert( $text, $isTitle = false) {
22492255 return $this->mConverter->convert($text, $isTitle);

Follow-up revisions

RevisionCommit summaryAuthorDate
r51178Follow up on r51177. Need use is_array().philip05:14, 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
r50938Follow up on r49157 and r50902. Fixed the header parsing code to conform to RFC.philip15:27, 23 May 2009

Status & tagging log