Glaisher has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/307054

Change subject: Prevent saving translations when if it matches 
$wgTranslateBlacklist
......................................................................

Prevent saving translations when if it matches $wgTranslateBlacklist

This is currently only checked in Special:Translate but users can
translate through the normal edit page and API. To prevent it
completely, use the getUserPermissionsErrorsExpensive hook.

Bug: T124013
Change-Id: I02a6108e45ede94a7d86f7752c1e6179de84e756
---
M TranslateEditAddons.php
1 file changed, 19 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/54/307054/1

diff --git a/TranslateEditAddons.php b/TranslateEditAddons.php
index 957614d..20e63a0 100644
--- a/TranslateEditAddons.php
+++ b/TranslateEditAddons.php
@@ -39,6 +39,8 @@
        public static function disallowLangTranslations( Title $title, User 
$user,
                $action, &$result
        ) {
+               global $wgTranslateBlacklist;
+
                if ( $action !== 'edit' ) {
                        return true;
                }
@@ -50,11 +52,27 @@
 
                $group = $handle->getGroup();
                $languages = $group->getTranslatableLanguages();
-               if ( $languages !== null && $handle->getCode() && !isset( 
$languages[$handle->getCode()] ) ) {
+               $langCode = $handle->getCode();
+               if ( $languages !== null && $langCode && !isset( 
$languages[$langCode] ) ) {
                        $result = array( 'translate-language-disabled' );
                        return false;
                }
 
+               $groupId = $group->getId();
+               $checks = array(
+                       $groupId,
+                       strtok( $groupId, '-' ),
+                       '*'
+               );
+
+               foreach ( $checks as $check ) {
+                       if ( isset( $wgTranslateBlacklist[$check][$langCode] ) 
) {
+                               $reason = 
$wgTranslateBlacklist[$check][$langCode];
+                               $result = array( 'translate-page-disabled', 
$reason );
+                               return false;
+                       }
+               }
+
                return true;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/307054
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I02a6108e45ede94a7d86f7752c1e6179de84e756
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Glaisher <glaisher.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to