From: cenarium Date: Sat, 13 Jun 2015 16:32:51 +0000 (+0200) Subject: Simplify canUpdateTags function in ChangeTags X-Git-Tag: 1.31.0-rc.0~11076^2 X-Git-Url: http://git.cyclocoop.org//%27http:/code.google.com/p/ie7-js//%27?a=commitdiff_plain;h=1a6f5dbe851a01e409dee0406c64050617d8242b;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 );