From d2344425f90dd2dc62cd7dc7704c149f4e0946c8 Mon Sep 17 00:00:00 2001 From: cenarium Date: Wed, 17 Jun 2015 15:22:37 +0200 Subject: [PATCH] Fix ChangeTags functions after split of definedTags from tagUsageStatistics 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 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 99385c857a..95f48161d9 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -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; } -- 2.20.1