r112607 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112606‎ | r112607 | r112608 >
Date:15:57, 28 February 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
Whitespace cleanup, comment tweaking
Modified paths:
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -194,35 +194,36 @@
195195 if ( !$status ) {
196196 return '';
197197 }
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' );
201202 $filter = null;
202 - if( strlen( $priorityLangs ) > 0 ) {
203 - $filter = array_flip( explode( ',', $priorityLangs ) );
 203+ if ( strlen( $priorityLangs ) > 0 ) {
 204+ $filter = array_flip( explode( ',', $priorityLangs ) );
204205 }
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' ) {
208209 $status = array_intersect_key( $status, $filter );
209210 }
210 - foreach ( $filter as $langCode => $value) {
 211+ foreach ( $filter as $langCode => $value ) {
211212 if ( !isset( $status[$langCode] ) ) {
212213 // We need to show all priority languages even if no translation started
213 - $status[ $langCode] = 0;
 214+ $status[$langCode] = 0;
214215 }
215216 }
216217 }
 218+
217219 // Fix title
218220 $title = $page->getTitle();
219221
220222 // Sort by language code, which seems to be the only sane method
221223 ksort( $status );
222224
223 - $options = $parser->getOptions();
 225+ // This way the parser knows to fragment the parser cache by language code
 226+ $userLangCode = $parser->getOptions()->getUserLang();
224227
225 - $userLangCode = $options->getUserLang();
226 -
227228 $languages = array();
228229 foreach ( $status as $code => $percent ) {
229230 $name = TranslateUtils::getLanguageName( $code, false, $userLangCode );
@@ -246,6 +247,7 @@
247248 ) );
248249
249250 // Add links to other languages
 251+ // @FIXME: 'en' should be the source language, not hardcoded
250252 $suffix = ( $code === 'en' ) ? '' : "/$code";
251253 $_title = Title::makeTitle( $title->getNamespace(), $title->getDBkey() . $suffix );
252254 if ( intval( $percent ) === 0 ) {
@@ -264,6 +266,7 @@
265267 );
266268 $languages[] = Linker::link( $translate, "$name $percentImage", $attribs, $params );
267269 } elseif ( $parser->getTitle()->getText() === $_title->getText() ) {
 270+ // The page we are currently on
268271 $name = Html::rawElement( 'span', array( 'class' => 'mw-pt-languages-selected' ), $name );
269272 $languages[] = "$name $percentImage";
270273 } else {
@@ -360,8 +363,8 @@
361364 */
362365 public static function preventUnknownTranslations( Title $title, User $user, $action, &$result ) {
363366 $handle = new MessageHandle( $title );
364 - if ( $handle->isPageTranslation() && $action === 'edit' ) {
365 - if( !$handle->isValid() ) {
 367+ if ( $handle->isPageTranslation() && $action === 'edit' ) {
 368+ if ( !$handle->isValid() ) {
366369 $result = array( 'tpt-unknown-page' );
367370 return false;
368371 }
@@ -369,7 +372,7 @@
370373 $priorityForce = TranslateMetadata::get( $handle->getGroup()->getId() , 'priorityforce' );
371374 if ( strlen( $priorityLangs ) > 0 && $priorityForce ) {
372375 $filter = array_flip( explode ( ',', $priorityLangs ) );
373 - if ( count( $filter) > 0 && !isset( $filter[$handle->getCode()] ) ) {
 376+ if ( count( $filter ) > 0 && !isset( $filter[$handle->getCode()] ) ) {
374377 $result = array( 'tpt-translation-restricted' );
375378 return false;
376379 }

Status & tagging log