Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -844,6 +844,29 @@ |
845 | 845 | return $xvo; |
846 | 846 | } |
847 | 847 | |
| 848 | + /** bug 21672: Add Accept-Language to Vary and XVO headers |
| 849 | + if there's no 'variant' parameter existed in $_GET. |
| 850 | + |
| 851 | + For example: |
| 852 | + /w/index.php?title=Main_page should always be served; but |
| 853 | + /w/index.php?title=Main_page&variant=zh-cn should never be served. |
| 854 | + |
| 855 | + patched by Liangent and Philip */ |
| 856 | + function addAcceptLanguage() { |
| 857 | + global $wgContLang; |
| 858 | + if( !isset( $_GET['variant'] ) && $wgContLang->hasVariants() ) { |
| 859 | + $variants = $wgContLang->getVariants(); |
| 860 | + $aloption = array(); |
| 861 | + foreach ( $variants as $variant ) { |
| 862 | + if( $variant === $wgContLang->getCode() ) |
| 863 | + continue; |
| 864 | + else |
| 865 | + $aloption[] = "string-contains=$variant"; |
| 866 | + } |
| 867 | + $this->addVaryHeader( 'Accept-Language', $aloption ); |
| 868 | + } |
| 869 | + } |
| 870 | + |
848 | 871 | public function sendCacheControl() { |
849 | 872 | global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO; |
850 | 873 | |
— | — | @@ -851,6 +874,8 @@ |
852 | 875 | if ($wgUseETag && $this->mETag) |
853 | 876 | $response->header("ETag: $this->mETag"); |
854 | 877 | |
| 878 | + $this->addAcceptLanguage(); |
| 879 | + |
855 | 880 | # don't serve compressed data to clients who can't handle it |
856 | 881 | # maintain different caches for logged-in users and non-logged in ones |
857 | 882 | $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) ); |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -206,11 +206,11 @@ |
207 | 207 | wfProfileOut( __METHOD__ ); |
208 | 208 | throw new ErrorPageError( 'badtitle', 'badtitletext' ); |
209 | 209 | } |
210 | | - // Redirect loops, no title in URL, $wgUsePathInfo URLs |
| 210 | + // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant |
211 | 211 | } else if( $action == 'view' && !$request->wasPosted() && |
212 | 212 | ( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) || |
213 | 213 | // No valid variant in URL (if the main-language has multi-variants), to ensure |
214 | | - // the Accept-Language would only be added to XVO when a 301 redirection happened |
| 214 | + // anonymous access would always be redirect to a URL with 'variant' parameter |
215 | 215 | ( !isset($this->GET['variant']) && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) && |
216 | 216 | !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) ) |
217 | 217 | { |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -186,19 +186,6 @@ |
187 | 187 | // variable in case this is called before the user's |
188 | 188 | // preference is loaded |
189 | 189 | if( $fromHeader && array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) { |
190 | | - |
191 | | - // bug 21672: Add Accept-Language to Vary and XVO headers |
192 | | - // to help Squid to determine user's perferred local language |
193 | | - // ONLY add Accept-Language when a variant has been found out |
194 | | - // patched by Liangent |
195 | | - $aloption = array(); |
196 | | - foreach ( $this->mVariants as $variant ) { |
197 | | - if( $variant === $this->mMainLanguageCode ) |
198 | | - continue; |
199 | | - $aloption[] = "string-contains=$variant"; |
200 | | - } |
201 | | - $wgOut->addVaryHeader( 'Accept-Language', $aloption ); |
202 | | - |
203 | 190 | $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); |
204 | 191 | // explode by comma |
205 | 192 | $result = explode(',', $acceptLanguage); |
— | — | @@ -243,9 +230,10 @@ |
244 | 231 | } |
245 | 232 | } |
246 | 233 | } |
| 234 | + return $this->mMainLanguageCode; |
247 | 235 | } |
| 236 | + else return $this->mPreferredVariant; |
248 | 237 | |
249 | | - return $this->mMainLanguageCode; |
250 | 238 | } |
251 | 239 | |
252 | 240 | /** |