r112576 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112575‎ | r112576 | r112577 >
Date:05:03, 28 February 2012
Author:santhosh
Status:resolved (Comments)
Tags:i18nreview 
Comment:
1. Restrict translation to a language if the group has a different priority language list
2. Display all the priority languages in the languages listed on top of a translated page. Show red link if translation percent is zero.
Modified paths:
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -196,12 +196,22 @@
197197 }
198198 // If the prioritylangs set, show those languages alone.
199199 $priorityLangs = TranslateMetadata::get( $page->getMessageGroupId(), 'prioritylangs' );
 200+ $priorityForce = TranslateMetadata::get( $page->getMessageGroupId(), 'priorityforce' );
200201 $filter = null;
201202 if( strlen( $priorityLangs ) > 0 ) {
202 - $filter = explode( ',', $priorityLangs );
 203+ $filter = array_flip( explode( ',', $priorityLangs ) );
203204 }
204205 if ( $filter != null) {
205 - $status = array_intersect_key( $status, array_flip( $filter ) );
 206+ if ( $priorityForce == 'on' ) {
 207+ // Show only the priority languages.
 208+ $status = array_intersect_key( $status, $filter );
 209+ }
 210+ foreach ( $filter as $langCode => $value) {
 211+ if ( !isset( $status[$langCode] ) ) {
 212+ // We need to show all priority languages even if no translation started
 213+ $status[ $langCode] = 0;
 214+ }
 215+ }
206216 }
207217 // Fix title
208218 $title = $page->getTitle();
@@ -227,7 +237,7 @@
228238 elseif ( $percent < 80 ) { $image = 4; }
229239 else { $image = 5; }
230240
231 - $percent = Xml::element( 'img', array(
 241+ $percentImage = Xml::element( 'img', array(
232242 'src' => TranslateUtils::assetPath( "resources/images/prog-$image.png" ),
233243 'alt' => "$percent%", // @todo i18n missing.
234244 'title' => "$percent%", // @todo i18n missing.
@@ -241,12 +251,12 @@
242252
243253 if ( $parser->getTitle()->getText() === $_title->getText() ) {
244254 $name = Html::rawElement( 'span', array( 'class' => 'mw-pt-languages-selected' ), $name );
245 - $languages[] = "$name $percent";
 255+ $languages[] = "$name $percentImage";
246256 } else {
247257 if ( $code === $userLangCode ) {
248258 $name = Html::rawElement( 'span', array( 'class' => 'mw-pt-languages-ui' ), $name );
249259 }
250 - $languages[] = Linker::linkKnown( $_title, "$name $percent" );
 260+ $languages[] = Linker::link( $_title, "$name $percentImage" );
251261 }
252262 }
253263
@@ -336,11 +346,21 @@
337347 */
338348 public static function preventUnknownTranslations( Title $title, User $user, $action, &$result ) {
339349 $handle = new MessageHandle( $title );
340 - if ( $handle->isPageTranslation() && $action === 'edit' && !$handle->isValid() ) {
341 - $result = array( 'tpt-unknown-page' );
342 - return false;
 350+ if ( $handle->isPageTranslation() && $action === 'edit' ) {
 351+ if( !$handle->isValid() ) {
 352+ $result = array( 'tpt-unknown-page' );
 353+ return false;
 354+ }
 355+ $priorityLangs = TranslateMetadata::get( $handle->getGroup()->getId() , 'prioritylangs' );
 356+ $priorityForce = TranslateMetadata::get( $handle->getGroup()->getId() , 'priorityforce' );
 357+ if ( strlen( $priorityLangs ) > 0 && $priorityForce ) {
 358+ $filter = array_flip( explode ( ',', $priorityLangs ) );
 359+ if ( count( $filter) > 0 && !isset( $filter[$handle->getCode()] ) ) {
 360+ $result = array( 'tpt-translation-restricted' );
 361+ return false;
 362+ }
 363+ }
343364 }
344 -
345365 return true;
346366 }
347367

Follow-up revisions

RevisionCommit summaryAuthorDate
r112578Error message to be shown when user tried to edit a restricted page....santhosh05:32, 28 February 2012
r112606Make the zero languages link to translation viewnikerabbit15:46, 28 February 2012
r112783Do not hide source language link, followup r112576nikerabbit09:16, 1 March 2012
r112785Split the new code into different hook. Also provide reason....nikerabbit09:27, 1 March 2012

Comments

#Comment by Nikerabbit (talk | contribs)   10:04, 28 February 2012

Can you use two different functions than combining two things into preventUnknownTranslations function?

#Comment by Nikerabbit (talk | contribs)   09:28, 1 March 2012

Fixed in r112785.

#Comment by Nikerabbit (talk | contribs)   10:06, 28 February 2012

Also we could delay loading the list of languages if force is not set. This is only a minor thing.

#Comment by Nikerabbit (talk | contribs)   15:58, 28 February 2012

Actually we can't, since we need to always show the languages regardless of force.

#Comment by Nikerabbit (talk | contribs)   10:28, 28 February 2012

Changing Link::linkKnown to plain Link:: might cause lots of new queries. In anyway, the non-existing languages should link directly to translation interface (we can check if percentage is zero to determine if that is the case).

#Comment by Nikerabbit (talk | contribs)   15:47, 28 February 2012

Fixed in r112606.

#Comment by Nikerabbit (talk | contribs)   10:30, 28 February 2012

When force is active, there is no link to the source text version of the page. I think it should stay there even in that case.

#Comment by Nikerabbit (talk | contribs)   09:28, 1 March 2012

Fixed in r112783.

#Comment by Nikerabbit (talk | contribs)   10:31, 28 February 2012

Please also run stylize.php (preferably before you commit) and remove extra spaces according to coding style guideline.

Status & tagging log