From a2415baa1a3c94abe83d0e2af274c4753775515e Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 1 May 2015 11:05:32 -0400 Subject: [PATCH] ChangeTags: Don't show UI when no editable tags exist Bug: T97773 Change-Id: I001f15ca6f58bc9318eed84aa8ace2bddcb1b315 --- includes/actions/HistoryAction.php | 8 ++++---- includes/changetags/ChangeTags.php | 18 ++++++++++++++++++ includes/logging/LogEventsList.php | 2 +- includes/specials/SpecialLog.php | 6 +++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 83185e4d61..f4f2a2a18c 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -504,7 +504,7 @@ class HistoryPager extends ReverseChronologicalPager { if ( $user->isAllowed( 'deleterevision' ) ) { $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' ); } - if ( $user->isAllowed( 'changetags' ) ) { + if ( ChangeTags::showTagEditingUI( $user ) ) { $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' ); } if ( $actionButtons ) { @@ -631,14 +631,14 @@ class HistoryPager extends ReverseChronologicalPager { $del = ''; $user = $this->getUser(); $canRevDelete = $user->isAllowed( 'deleterevision' ); - $canModifyTags = $user->isAllowed( 'changetags' ); + $showTagEditUI = ChangeTags::showTagEditingUI( $user ); // Show checkboxes for each revision, to allow for revision deletion and // change tags - if ( $canRevDelete || $canModifyTags ) { + if ( $canRevDelete || $showTagEditUI ) { $this->preventClickjacking(); // If revision was hidden from sysops and we don't need the checkbox // for anything else, disable it - if ( !$canModifyTags && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) { + if ( !$showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) { $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) ); // Otherwise, enable the checkbox... } else { diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index cf33484f0b..564feb6509 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -1220,4 +1220,22 @@ class ChangeTags { $wgMemc->set( $key, $out, 300 ); return $out; } + + /** + * Indicate whether change tag editing UI is relevant + * + * Returns true if the user has the necessary right and there are any + * editable tags defined. + * + * This intentionally doesn't check "any addable || any deletable", because + * it seems like it would be more confusing than useful if the checkboxes + * suddenly showed up because some abuse filter stopped defining a tag and + * then suddenly disappeared when someone deleted all uses of that tag. + * + * @param User $user + * @return bool + */ + public static function showTagEditingUI( User $user ) { + return $user->isAllowed( 'changetags' ) && (bool)self::listExplicitlyDefinedTags(); + } } diff --git a/includes/logging/LogEventsList.php b/includes/logging/LogEventsList.php index dcddbd776b..dfe31365af 100644 --- a/includes/logging/LogEventsList.php +++ b/includes/logging/LogEventsList.php @@ -348,7 +348,7 @@ class LogEventsList extends ContextSource { $user = $this->getUser(); // If change tag editing is available to this user, return the checkbox - if ( $this->flags & self::USE_CHECKBOXES && $user->isAllowed( 'changetags' ) ) { + if ( $this->flags & self::USE_CHECKBOXES && ChangeTags::showTagEditingUI( $user ) ) { return Xml::check( 'showhiderevisions', false, diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index fe6ce68d27..e44ce5f5b2 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -218,10 +218,10 @@ class SpecialLog extends SpecialPage { private function getActionButtons( $formcontents ) { $user = $this->getUser(); $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' ); - $canModifyTags = $user->isAllowed( 'changetags' ); + $showTagEditUI = ChangeTags::showTagEditingUI( $user ); # If the user doesn't have the ability to delete log entries nor edit tags, # don't bother showing them the button(s). - if ( !$canRevDelete && !$canModifyTags ) { + if ( !$canRevDelete && !$showTagEditUI ) { return $formcontents; } @@ -246,7 +246,7 @@ class SpecialLog extends SpecialPage { $this->msg( 'showhideselectedlogentries' )->text() ) . "\n"; } - if ( $canModifyTags ) { + if ( $showTagEditUI ) { $buttons .= Html::element( 'button', array( -- 2.20.1