Index: trunk/phase3/tests/LanguageConverterTest.php |
— | — | @@ -81,10 +81,11 @@ |
82 | 82 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true)); |
83 | 83 | |
84 | 84 | $wgRequest->setVal('variant', 'tg'); |
| 85 | + $wgUser->setOption('variant', 'tg-latn'); |
85 | 86 | $this->lc = new TestConverter( $this->lang, 'tg', |
86 | 87 | array( 'tg', 'tg-latn' ) ); |
87 | | - $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
88 | | - $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
| 88 | + $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false)); |
| 89 | + $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true)); |
89 | 90 | |
90 | 91 | $wgRequest->setVal('variant', null); |
91 | 92 | $wgDefaultLanguageVariant = 'tg-latn'; |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | * @public |
126 | 126 | */ |
127 | 127 | function getVariantFallbacks( $v ) { |
128 | | - if ( isset( $this->mVariantFallbacks[$v] ) ) { |
| 128 | + if ( array_key_exists( $v, $this->mVariantFallbacks ) ) { |
129 | 129 | return $this->mVariantFallbacks[$v]; |
130 | 130 | } |
131 | 131 | return $this->mMainLanguageCode; |
— | — | @@ -142,15 +142,15 @@ |
143 | 143 | |
144 | 144 | $req = $this->getURLVariant(); |
145 | 145 | |
146 | | - if ( $fromUser && !isset( $req ) ) { |
| 146 | + if ( $fromUser && !$req ) { |
147 | 147 | $req = $this->getUserVariant(); |
148 | 148 | } |
149 | 149 | |
150 | | - if ( $fromHeader && !isset( $req ) ) { |
| 150 | + if ( $fromHeader && !$req ) { |
151 | 151 | $req = $this->getHeaderVariant(); |
152 | 152 | } |
153 | 153 | |
154 | | - if ( $wgDefaultLanguageVariant && !isset( $req ) ) { |
| 154 | + if ( $wgDefaultLanguageVariant && !$req ) { |
155 | 155 | $req = $this->validateVariant( $wgDefaultLanguageVariant ); |
156 | 156 | } |
157 | 157 | |
— | — | @@ -158,7 +158,7 @@ |
159 | 159 | // not memoized (i.e. there return value is not cached) since |
160 | 160 | // new information might appear during processing after this |
161 | 161 | // is first called. |
162 | | - if ( isset( $req ) ) { |
| 162 | + if ( $req ) { |
163 | 163 | return $req; |
164 | 164 | } |
165 | 165 | return $this->mMainLanguageCode; |
— | — | @@ -170,7 +170,7 @@ |
171 | 171 | * @returns mixed returns the variant if it is valid, null otherwise |
172 | 172 | */ |
173 | 173 | function validateVariant( $v = null ) { |
174 | | - if ( isset( $v ) && in_array( $v, $this->mVariants ) ) { |
| 174 | + if ( $v !== null && in_array( $v, $this->mVariants ) ) { |
175 | 175 | return $v; |
176 | 176 | } |
177 | 177 | return null; |
— | — | @@ -192,7 +192,7 @@ |
193 | 193 | // see if the preference is set in the request |
194 | 194 | $ret = $wgRequest->getText( 'variant' ); |
195 | 195 | |
196 | | - if ( !isset( $ret ) ) { |
| 196 | + if ( $ret ) { |
197 | 197 | $ret = $wgRequest->getVal( 'uselang' ); |
198 | 198 | } |
199 | 199 | |
— | — | @@ -246,7 +246,7 @@ |
247 | 247 | // http header. |
248 | 248 | |
249 | 249 | $acceptLanguage = $wgRequest->getHeader( 'Accept-Language' ); |
250 | | - if ( !$acceptLanguage ) { // not using isset because getHeader returns false |
| 250 | + if ( !$acceptLanguage ) { |
251 | 251 | return null; |
252 | 252 | } |
253 | 253 | |
— | — | @@ -269,7 +269,7 @@ |
270 | 270 | // strip whitespace |
271 | 271 | $language = trim( $language ); |
272 | 272 | $this->mHeaderVariant = $this->validateVariant( $language ); |
273 | | - if ( isset( $this->mHeaderVariant ) ) { |
| 273 | + if ( $this->mHeaderVariant ) { |
274 | 274 | break; |
275 | 275 | } |
276 | 276 | |
— | — | @@ -286,12 +286,12 @@ |
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | | - if ( !isset( $this->mHeaderVariant ) ) { |
| 290 | + if ( !$this->mHeaderVariant ) { |
291 | 291 | // process fallback languages now |
292 | 292 | $fallback_languages = array_unique( $fallback_languages ); |
293 | 293 | foreach ( $fallback_languages as $language ) { |
294 | 294 | $this->mHeaderVariant = $this->validateVariant( $language ); |
295 | | - if ( isset( $this->mHeaderVariant ) ) { |
| 295 | + if ( $this->mHeaderVariant ) { |
296 | 296 | break; |
297 | 297 | } |
298 | 298 | } |
— | — | @@ -710,7 +710,7 @@ |
711 | 711 | wfProfileOut( __METHOD__ . '-cache' ); |
712 | 712 | } |
713 | 713 | if ( !$this->mTables |
714 | | - || !isset( $this->mTables[self::CACHE_VERSION_KEY] ) ) { |
| 714 | + || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) { |
715 | 715 | wfProfileIn( __METHOD__ . '-recache' ); |
716 | 716 | // not in cache, or we need a fresh reload. |
717 | 717 | // we will first load the default tables |