Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -194,35 +194,36 @@ |
195 | 195 | if ( !$status ) { |
196 | 196 | return ''; |
197 | 197 | } |
198 | | - // If the prioritylangs set, show those languages alone. |
199 | | - $priorityLangs = TranslateMetadata::get( $page->getMessageGroupId(), 'prioritylangs' ); |
200 | | - $priorityForce = TranslateMetadata::get( $page->getMessageGroupId(), 'priorityforce' ); |
| 198 | + |
| 199 | + // If priority languages have been set always show those languages |
| 200 | + $priorityLangs = TranslateMetadata::get( $page->getMessageGroupId(), 'prioritylangs' ); |
| 201 | + $priorityForce = TranslateMetadata::get( $page->getMessageGroupId(), 'priorityforce' ); |
201 | 202 | $filter = null; |
202 | | - if( strlen( $priorityLangs ) > 0 ) { |
203 | | - $filter = array_flip( explode( ',', $priorityLangs ) ); |
| 203 | + if ( strlen( $priorityLangs ) > 0 ) { |
| 204 | + $filter = array_flip( explode( ',', $priorityLangs ) ); |
204 | 205 | } |
205 | | - if ( $filter != null) { |
206 | | - if ( $priorityForce == 'on' ) { |
207 | | - // Show only the priority languages. |
| 206 | + if ( $filter !== null ) { |
| 207 | + // If translation is restricted to some languages, only show them |
| 208 | + if ( $priorityForce === 'on' ) { |
208 | 209 | $status = array_intersect_key( $status, $filter ); |
209 | 210 | } |
210 | | - foreach ( $filter as $langCode => $value) { |
| 211 | + foreach ( $filter as $langCode => $value ) { |
211 | 212 | if ( !isset( $status[$langCode] ) ) { |
212 | 213 | // We need to show all priority languages even if no translation started |
213 | | - $status[ $langCode] = 0; |
| 214 | + $status[$langCode] = 0; |
214 | 215 | } |
215 | 216 | } |
216 | 217 | } |
| 218 | + |
217 | 219 | // Fix title |
218 | 220 | $title = $page->getTitle(); |
219 | 221 | |
220 | 222 | // Sort by language code, which seems to be the only sane method |
221 | 223 | ksort( $status ); |
222 | 224 | |
223 | | - $options = $parser->getOptions(); |
| 225 | + // This way the parser knows to fragment the parser cache by language code |
| 226 | + $userLangCode = $parser->getOptions()->getUserLang(); |
224 | 227 | |
225 | | - $userLangCode = $options->getUserLang(); |
226 | | - |
227 | 228 | $languages = array(); |
228 | 229 | foreach ( $status as $code => $percent ) { |
229 | 230 | $name = TranslateUtils::getLanguageName( $code, false, $userLangCode ); |
— | — | @@ -246,6 +247,7 @@ |
247 | 248 | ) ); |
248 | 249 | |
249 | 250 | // Add links to other languages |
| 251 | + // @FIXME: 'en' should be the source language, not hardcoded |
250 | 252 | $suffix = ( $code === 'en' ) ? '' : "/$code"; |
251 | 253 | $_title = Title::makeTitle( $title->getNamespace(), $title->getDBkey() . $suffix ); |
252 | 254 | if ( intval( $percent ) === 0 ) { |
— | — | @@ -264,6 +266,7 @@ |
265 | 267 | ); |
266 | 268 | $languages[] = Linker::link( $translate, "$name $percentImage", $attribs, $params ); |
267 | 269 | } elseif ( $parser->getTitle()->getText() === $_title->getText() ) { |
| 270 | + // The page we are currently on |
268 | 271 | $name = Html::rawElement( 'span', array( 'class' => 'mw-pt-languages-selected' ), $name ); |
269 | 272 | $languages[] = "$name $percentImage"; |
270 | 273 | } else { |
— | — | @@ -360,8 +363,8 @@ |
361 | 364 | */ |
362 | 365 | public static function preventUnknownTranslations( Title $title, User $user, $action, &$result ) { |
363 | 366 | $handle = new MessageHandle( $title ); |
364 | | - if ( $handle->isPageTranslation() && $action === 'edit' ) { |
365 | | - if( !$handle->isValid() ) { |
| 367 | + if ( $handle->isPageTranslation() && $action === 'edit' ) { |
| 368 | + if ( !$handle->isValid() ) { |
366 | 369 | $result = array( 'tpt-unknown-page' ); |
367 | 370 | return false; |
368 | 371 | } |
— | — | @@ -369,7 +372,7 @@ |
370 | 373 | $priorityForce = TranslateMetadata::get( $handle->getGroup()->getId() , 'priorityforce' ); |
371 | 374 | if ( strlen( $priorityLangs ) > 0 && $priorityForce ) { |
372 | 375 | $filter = array_flip( explode ( ',', $priorityLangs ) ); |
373 | | - if ( count( $filter) > 0 && !isset( $filter[$handle->getCode()] ) ) { |
| 376 | + if ( count( $filter ) > 0 && !isset( $filter[$handle->getCode()] ) ) { |
374 | 377 | $result = array( 'tpt-translation-restricted' ); |
375 | 378 | return false; |
376 | 379 | } |