Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -50,6 +50,8 @@ |
51 | 51 | |
52 | 52 | private $mIndexPolicy = 'index'; |
53 | 53 | private $mFollowPolicy = 'follow'; |
| 54 | + private $mVaryHeader = array( 'Accept-Encoding', 'Cookie' ); |
| 55 | + private $mXVOHeader = array( 'Accept-Encoding' => array('list-contains=gzip') ); |
54 | 56 | |
55 | 57 | /** |
56 | 58 | * Constructor |
— | — | @@ -805,19 +807,45 @@ |
806 | 808 | return false; |
807 | 809 | } |
808 | 810 | |
| 811 | + public function addXVOHeader( $header, $option = null ) { |
| 812 | + if ( !array_key_exists( $header, $this->mXVOHeader ) ) { |
| 813 | + $this->mXVOHeader[$header] = $option; |
| 814 | + } |
| 815 | + elseif( is_array( $option ) ) { |
| 816 | + if( is_array( $this->mXVOHeader[$header] ) ) { |
| 817 | + $this->mXVOHeader[$header] = array_merge( $this->mXVOHeader[$header], $option ); |
| 818 | + } |
| 819 | + else { |
| 820 | + $this->mXVOHeader[$header] = $option; |
| 821 | + } |
| 822 | + } |
| 823 | + } |
| 824 | + |
| 825 | + public function addVaryHeader( $header ) { |
| 826 | + if ( !in_array( $header, $this->mVaryHeader ) ) { |
| 827 | + $this->mVaryHeader[] = $header; |
| 828 | + } |
| 829 | + } |
| 830 | + |
809 | 831 | /** Get a complete X-Vary-Options header */ |
810 | 832 | public function getXVO() { |
811 | 833 | $cvCookies = $this->getCacheVaryCookies(); |
812 | | - $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;'; |
813 | | - $first = true; |
| 834 | + |
| 835 | + $cookiesOption = array(); |
814 | 836 | foreach ( $cvCookies as $cookieName ) { |
815 | | - if ( $first ) { |
816 | | - $first = false; |
817 | | - } else { |
818 | | - $xvo .= ';'; |
819 | | - } |
820 | | - $xvo .= 'string-contains=' . $cookieName; |
| 837 | + $cookiesOption[] = 'string-contains=' . $cookieName; |
821 | 838 | } |
| 839 | + $this->addXVOHeader( 'Cookie', $cookiesOption ); |
| 840 | + |
| 841 | + $headers = array(); |
| 842 | + foreach( $this->mXVOHeader as $header => $option ) { |
| 843 | + $newheader = $header; |
| 844 | + if( is_array( $option ) ) |
| 845 | + $newheader .= ';' . implode( ';', $option ); |
| 846 | + $headers[] = $newheader; |
| 847 | + } |
| 848 | + $xvo = 'X-Vary-Options: ' . implode( ',', $headers ); |
| 849 | + |
822 | 850 | return $xvo; |
823 | 851 | } |
824 | 852 | |
— | — | @@ -830,7 +858,7 @@ |
831 | 859 | |
832 | 860 | # don't serve compressed data to clients who can't handle it |
833 | 861 | # maintain different caches for logged-in users and non-logged in ones |
834 | | - $response->header( 'Vary: Accept-Encoding, Cookie' ); |
| 862 | + $response->header( 'Vary: ' . join( ', ', $this->mVaryHeader ) ); |
835 | 863 | |
836 | 864 | if ( $wgUseXVO ) { |
837 | 865 | # Add an X-Vary-Options header for Squid with Wikimedia patches |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -185,6 +185,12 @@ |
186 | 186 | // variable in case this is called before the user's |
187 | 187 | // preference is loaded |
188 | 188 | if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) { |
| 189 | + // bug 21672: Add Accept-Language to Vary and XVO headers |
| 190 | + // to help Squid to determine user's perferred local language |
| 191 | + global $wgOut, $wgUseXVO; |
| 192 | + $wgOut->addVaryHeader( 'Accept-Language' ); |
| 193 | + if( $wgUseXVO ) |
| 194 | + $wgOut->addXVOHeader( 'Accept-Language' ); |
189 | 195 | $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); |
190 | 196 | |
191 | 197 | // explode by comma |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -649,6 +649,7 @@ |
650 | 650 | * (bug 21403) memcached class renamed to MWMemecached to avoid conflict with |
651 | 651 | PHP's memcached extension |
652 | 652 | * (bug 21650) Both calls to SkinTemplateTabs hook are now compatible |
| 653 | +* (bug 21672) Add missing Accept-Language to both Vary and XVO headers |
653 | 654 | |
654 | 655 | == API changes in 1.16 == |
655 | 656 | |