From 1a6f5dbe851a01e409dee0406c64050617d8242b Mon Sep 17 00:00:00 2001 From: cenarium Date: Sat, 13 Jun 2015 18:32:51 +0200 Subject: [PATCH] Simplify canUpdateTags function in ChangeTags This simplifies the function canUpdateTags by checking that none of the tags are defined by an extension instead of checking that all of them are either manually defined or not defined at all. Doing so avoids a cache call and makes it easy to propose only relevant tags for addition/removal to users at Special:EditTags. This also makes the respective checks for adding/removing tags only when necessary. Change-Id: Iddee4d4efb109b0fccf1ece400d166147e1700fc --- includes/changetags/ChangeTags.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 79763bd2d3..f712b26cb7 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -417,21 +417,23 @@ class ChangeTags { return Status::newFatal( 'tags-update-no-permission' ); } - // to be added, a tag has to be explicitly defined - // @todo Allow extensions to define tags that can be applied by users... - $explicitlyDefinedTags = self::listExplicitlyDefinedTags(); - $diff = array_diff( $tagsToAdd, $explicitlyDefinedTags ); - if ( $diff ) { - return self::restrictedTagError( 'tags-update-add-not-allowed-one', - 'tags-update-add-not-allowed-multi', $diff ); + if ( $tagsToAdd ) { + // to be added, a tag has to be explicitly defined + // @todo Allow extensions to define tags that can be applied by users... + $explicitlyDefinedTags = self::listExplicitlyDefinedTags(); + $diff = array_diff( $tagsToAdd, $explicitlyDefinedTags ); + if ( $diff ) { + return self::restrictedTagError( 'tags-update-add-not-allowed-one', + 'tags-update-add-not-allowed-multi', $diff ); + } } - // to be removed, a tag has to be either explicitly defined or not defined - // at all - $definedTags = self::listDefinedTags(); - $diff = array_diff( $tagsToRemove, $explicitlyDefinedTags ); - if ( $diff ) { - $intersect = array_intersect( $diff, $definedTags ); + if ( $tagsToRemove ) { + // to be removed, a tag must not be defined by an extension, or equivalently it + // has to be either explicitly defined or not defined at all + // (assuming no edge case of a tag both explicitly-defined and extension-defined) + $extensionDefinedTags = self::listExtensionDefinedTags(); + $intersect = array_intersect( $tagsToRemove, $extensionDefinedTags ); if ( $intersect ) { return self::restrictedTagError( 'tags-update-remove-not-allowed-one', 'tags-update-remove-not-allowed-multi', $intersect ); -- 2.20.1