Merge "HTMLTitleTextField: Remove incorrect check for unsubmitted GET forms"
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 0f6e232..ba6cb2c 100644 (file)
@@ -520,11 +520,11 @@ class ChangeTags {
         */
        public static function canAddTagsAccompanyingChange( array $tags, User $user = null ) {
                if ( !is_null( $user ) ) {
-                       if ( !$user->isAllowed( 'applychangetags' ) ) {
+                       if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->userHasRight( $user, 'applychangetags' )
+                       ) {
                                return Status::newFatal( 'tags-apply-no-permission' );
-                       } elseif ( $user->getBlock() ) {
-                               // @TODO Ensure that the block does not apply to the `applychangetags`
-                               //       right.
+                       } elseif ( $user->getBlock() && $user->getBlock()->isSitewide() ) {
                                return Status::newFatal( 'tags-apply-blocked', $user->getName() );
                        }
                }
@@ -595,11 +595,11 @@ class ChangeTags {
                User $user = null
        ) {
                if ( !is_null( $user ) ) {
-                       if ( !$user->isAllowed( 'changetags' ) ) {
+                       if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->userHasRight( $user, 'changetags' )
+                       ) {
                                return Status::newFatal( 'tags-update-no-permission' );
-                       } elseif ( $user->getBlock() ) {
-                               // @TODO Ensure that the block does not apply to the `changetags`
-                               //       right.
+                       } elseif ( $user->getBlock() && $user->getBlock()->isSitewide() ) {
                                return Status::newFatal( 'tags-update-blocked', $user->getName() );
                        }
                }
@@ -997,7 +997,7 @@ class ChangeTags {
                }
                $logEntry->setParameters( $params );
                $logEntry->setRelations( [ 'Tag' => $tag ] );
-               $logEntry->setTags( $logEntryTags );
+               $logEntry->addTags( $logEntryTags );
 
                $logId = $logEntry->insert( $dbw );
                $logEntry->publish( $logId );
@@ -1015,11 +1015,11 @@ class ChangeTags {
         */
        public static function canActivateTag( $tag, User $user = null ) {
                if ( !is_null( $user ) ) {
-                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                       if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->userHasRight( $user, 'managechangetags' )
+                       ) {
                                return Status::newFatal( 'tags-manage-no-permission' );
-                       } elseif ( $user->getBlock() ) {
-                               // @TODO Ensure that the block does not apply to the `managechangetags`
-                               //       right.
+                       } elseif ( $user->getBlock() && $user->getBlock()->isSitewide() ) {
                                return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
@@ -1089,11 +1089,11 @@ class ChangeTags {
         */
        public static function canDeactivateTag( $tag, User $user = null ) {
                if ( !is_null( $user ) ) {
-                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                       if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->userHasRight( $user, 'managechangetags' )
+                       ) {
                                return Status::newFatal( 'tags-manage-no-permission' );
-                       } elseif ( $user->getBlock() ) {
-                               // @TODO Ensure that the block does not apply to the `managechangetags`
-                               //       right.
+                       } elseif ( $user->getBlock() && $user->getBlock()->isSitewide() ) {
                                return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
@@ -1188,11 +1188,11 @@ class ChangeTags {
         */
        public static function canCreateTag( $tag, User $user = null ) {
                if ( !is_null( $user ) ) {
-                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                       if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->userHasRight( $user, 'managechangetags' )
+                       ) {
                                return Status::newFatal( 'tags-manage-no-permission' );
-                       } elseif ( $user->getBlock() ) {
-                               // @TODO Ensure that the block does not apply to the `managechangetags`
-                               //       right.
+                       } elseif ( $user->getBlock() && $user->getBlock()->isSitewide() ) {
                                return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
@@ -1308,11 +1308,11 @@ class ChangeTags {
                $tagUsage = self::tagUsageStatistics();
 
                if ( !is_null( $user ) ) {
-                       if ( !$user->isAllowed( 'deletechangetags' ) ) {
+                       if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->userHasRight( $user, 'deletechangetags' )
+                       ) {
                                return Status::newFatal( 'tags-delete-no-permission' );
-                       } elseif ( $user->getBlock() ) {
-                               // @TODO Ensure that the block does not apply to the `deletechangetags`
-                               //       right.
+                       } elseif ( $user->getBlock() && $user->getBlock()->isSitewide() ) {
                                return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
@@ -1566,6 +1566,8 @@ class ChangeTags {
         * @return bool
         */
        public static function showTagEditingUI( User $user ) {
-               return $user->isAllowed( 'changetags' ) && (bool)self::listExplicitlyDefinedTags();
+               return MediaWikiServices::getInstance()->getPermissionManager()
+                                  ->userHasRight( $user, 'changetags' ) &&
+                          (bool)self::listExplicitlyDefinedTags();
        }
 }