r112785 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112784‎ | r112785 | r112786 >
Date:09:27, 1 March 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
Split the new code into different hook. Also provide reason.
Ping r112576
Modified paths:
  • /trunk/extensions/Translate/PageTranslation.i18n.php (modified) (history)
  • /trunk/extensions/Translate/TranslateHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -370,20 +370,41 @@
371371 $result = array( 'tpt-unknown-page' );
372372 return false;
373373 }
374 - $priorityLangs = TranslateMetadata::get( $handle->getGroup()->getId() , 'prioritylangs' );
375 - $priorityForce = TranslateMetadata::get( $handle->getGroup()->getId() , 'priorityforce' );
376 - if ( strlen( $priorityLangs ) > 0 && $priorityForce ) {
377 - $filter = array_flip( explode ( ',', $priorityLangs ) );
378 - if ( count( $filter ) > 0 && !isset( $filter[$handle->getCode()] ) ) {
379 - $result = array( 'tpt-translation-restricted' );
380 - return false;
381 - }
382 - }
383374 }
384375 return true;
385376 }
386377
387378 /**
 379+ * Prevent editing of restricted languages
 380+ * Hook: getUserPermissionsErrorsExpensive
 381+ * @since 2012-03-01
 382+ */
 383+ public static function preventRestrictedTranslations( Title $title, User $user, $action, &$result ) {
 384+ $handle = new MessageHandle( $title );
 385+ if ( !$handle->isValid() ) {
 386+ return true;
 387+ }
 388+
 389+ $groupId = $handle->getGroup()->getId();
 390+ $priorityForce = TranslateMetadata::get( $groupId, 'priorityforce' );
 391+ if ( !$priorityForce ) {
 392+ return true;
 393+ }
 394+
 395+ $priorityLangs = TranslateMetadata::get( $groupId, 'prioritylangs' );
 396+ $priorityReason = TranslateMetadata::get( $groupId, 'priorityreason' );
 397+ $filter = array_flip( explode( ',', $priorityLangs ) );
 398+ if ( !isset( $filter[$handle->getCode()] ) ) {
 399+ $result = array( 'tpt-translation-restricted', $priorityReason );
 400+ return false;
 401+ }
 402+
 403+ return true;
 404+ }
 405+
 406+
 407+
 408+ /**
388409 * Prevent editing of translation pages directly.
389410 * Hook: getUserPermissionsErrorsExpensive
390411 */
Index: trunk/extensions/Translate/TranslateHooks.php
@@ -118,6 +118,8 @@
119119
120120 // Prevent editing of unknown pages in Translations namespace
121121 $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventUnknownTranslations';
 122+ // Prevent editing of translation in restricted languages
 123+ $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventRestrictedTranslations';
122124 // Prevent editing of translation pages directly
123125 $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventDirectEditing';
124126
Index: trunk/extensions/Translate/PageTranslation.i18n.php
@@ -97,7 +97,9 @@
9898 This page is a translation of page [[$1]] and the translation can be updated using [$2 the translation tool].',
9999 'tpt-unknown-page' => 'This namespace is reserved for content page translations.
100100 The page you are trying to edit does not seem to correspond any page marked for translation.',
101 - 'tpt-translation-restricted' => 'Translation of this message group to this language has been prevented by translation administrator.',
 101+ 'tpt-translation-restricted' => 'Translation of this message group to this language has been prevented by translation administrator.
 102+
 103+Reason for limiting: $1',
102104 'tpt-discouraged-language-force' => 'Translation administrator has limited the languages this message group can be translated to. This language is not among those languages.
103105
104106 Reason for limiting: $1',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r1125761. Restrict translation to a language if the group has a different priority l...santhosh05:03, 28 February 2012

Status & tagging log