Fix ChangeTags functions after split of definedTags from tagUsageStatistics
authorcenarium <cenarium.sysop@gmail.com>
Wed, 17 Jun 2015 13:22:37 +0000 (15:22 +0200)
committercenarium <cenarium.sysop@gmail.com>
Wed, 17 Jun 2015 13:29:27 +0000 (15:29 +0200)
This provides fixes to the can*Tag functions of ChangeTags following the
removal of listDefinedTags from the tagUsageStatistics function in
I410e9a935bd202faac92f430c0b4dae1a48e2d21.

Change-Id: I087bb7107ae0c83946f8e2f417a6121bb2da18b4

includes/changetags/ChangeTags.php

index 99385c8..95f4816 100644 (file)
@@ -749,12 +749,6 @@ class ChangeTags {
                        return Status::newFatal( 'tags-manage-no-permission' );
                }
 
-               // non-existing tags cannot be activated
-               $tagUsage = self::tagUsageStatistics();
-               if ( !isset( $tagUsage[$tag] ) ) {
-                       return Status::newFatal( 'tags-activate-not-found', $tag );
-               }
-
                // defined tags cannot be activated (a defined tag is either extension-
                // defined, in which case the extension chooses whether or not to active it;
                // or user-defined, in which case it is considered active)
@@ -763,6 +757,12 @@ class ChangeTags {
                        return Status::newFatal( 'tags-activate-not-allowed', $tag );
                }
 
+               // non-existing tags cannot be activated
+               $tagUsage = self::tagUsageStatistics();
+               if ( !isset( $tagUsage[$tag] ) ) { // we already know the tag is undefined
+                       return Status::newFatal( 'tags-activate-not-found', $tag );
+               }
+
                return Status::newGood();
        }
 
@@ -887,7 +887,7 @@ class ChangeTags {
 
                // does the tag already exist?
                $tagUsage = self::tagUsageStatistics();
-               if ( isset( $tagUsage[$tag] ) ) {
+               if ( isset( $tagUsage[$tag] ) || in_array( $tag, self::listDefinedTags() ) ) {
                        return Status::newFatal( 'tags-create-already-exists', $tag );
                }
 
@@ -997,11 +997,11 @@ class ChangeTags {
                        return Status::newFatal( 'tags-manage-no-permission' );
                }
 
-               if ( !isset( $tagUsage[$tag] ) ) {
+               if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self::listDefinedTags() ) ) {
                        return Status::newFatal( 'tags-delete-not-found', $tag );
                }
 
-               if ( $tagUsage[$tag] > self::MAX_DELETE_USES ) {
+               if ( isset( $tagUsage[$tag] ) && $tagUsage[$tag] > self::MAX_DELETE_USES ) {
                        return Status::newFatal( 'tags-delete-too-many-uses', $tag, self::MAX_DELETE_USES );
                }
 
@@ -1046,6 +1046,7 @@ class ChangeTags {
 
                // store the tag usage statistics
                $tagUsage = self::tagUsageStatistics();
+               $hitcount = isset( $tagUsage[$tag] ) ? $tagUsage[$tag] : 0;
 
                // do it!
                $deleteResult = self::deleteTagEverywhere( $tag );
@@ -1054,7 +1055,7 @@ class ChangeTags {
                }
 
                // log it
-               $logId = self::logTagManagementAction( 'delete', $tag, $reason, $user, $tagUsage[$tag] );
+               $logId = self::logTagManagementAction( 'delete', $tag, $reason, $user, $hitcount );
                $deleteResult->value = $logId;
                return $deleteResult;
        }