From: Philip Tzou Date: Sat, 30 May 2009 05:07:46 +0000 (+0000) Subject: 1. Follow up on r49157, r50902 and r50938. According RFC 2616 section 14.4, language... X-Git-Tag: 1.31.0-rc.0~41607 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=5336b9ba6fb19ccc54eec8ce05b46c0ba80822fd;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8af1dbc5f1..6f56a33f38 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -85,7 +85,14 @@ class OutputPage { array_push( $this->mMetatags, array( $name, $val ) ); } - function addKeyword( $text ) { array_push( $this->mKeywords, $text ); } + function addKeyword( $text ) { + if( is_array( $text )) { + $this->mKeywords = array_merge( $this->mKeywords, $text ); + } + else { + array_push( $this->mKeywords, $text ); + } + } function addScript( $script ) { $this->mScripts .= "\t\t".$script; } function addExtensionStyle( $url ) { @@ -1479,13 +1486,22 @@ class OutputPage { } /** - * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page + * This function takes the title (first item of mGoodLinks), categories, + * existing and broken links for the page * and uses the first 10 of them for META keywords * * @param ParserOutput &$parserOutput */ private function addKeywords( &$parserOutput ) { - $this->addKeyword( $this->getTitle()->getPrefixedText() ); + global $wgContLang; + // Get an array of keywords if there are more than one + // variant of the site language + $text = $wgContLang->autoConvertToAllVariants( $this->getTitle()->getPrefixedText()); + // array_values: We needn't to merge variant's code name + // into $this->mKeywords; + // array_unique: We should insert a keyword just for once + $text = array_unique( array_values( $text )); + $this->addKeyword( $text ); $count = 1; $links2d =& $parserOutput->getLinks(); if ( !is_array( $links2d ) ) { @@ -1493,6 +1509,8 @@ class OutputPage { } foreach ( $links2d as $dbkeys ) { foreach( $dbkeys as $dbkey => $unused ) { + $dbkey = $wgContLang->autoConvertToAllVariants( $dbkey ); + $dbkey = array_unique( array_values( $dbkey )); $this->addKeyword( $dbkey ); if ( ++$count > 10 ) { break 2; diff --git a/languages/Language.php b/languages/Language.php index aee11d34fb..418afa7f9a 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -35,6 +35,7 @@ if( function_exists( 'mb_strtoupper' ) ) { class FakeConverter { var $mLang; function FakeConverter($langobj) {$this->mLang = $langobj;} + function autoConvertToAllVariants($text) {return $text;} function convert($t, $i) {return $t;} function parserConvert($t, $p) {return $t;} function getVariants() { return array( $this->mLang->getCode() ); } @@ -2243,6 +2244,11 @@ class Language { return $text; } + # convert text to all supported variants + function autoConvertToAllVariants($text) { + return $this->mConverter->autoConvertToAllVariants($text); + } + # convert text to different variants of a language. function convert( $text, $isTitle = false) { return $this->mConverter->convert($text, $isTitle); diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 09b0963d19..fcbb01ed93 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -183,7 +183,7 @@ class LanguageConverter { // variable in case this is called before the user's // preference is loaded if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) { - $acceptLanguage = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"])); + $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); // explode by comma $result = explode(',', $acceptLanguage);