ChangeTags: Don't show UI when no editable tags exist
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 1 May 2015 15:05:32 +0000 (11:05 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 1 May 2015 15:12:31 +0000 (11:12 -0400)
Bug: T97773
Change-Id: I001f15ca6f58bc9318eed84aa8ace2bddcb1b315

includes/actions/HistoryAction.php
includes/changetags/ChangeTags.php
includes/logging/LogEventsList.php
includes/specials/SpecialLog.php

index 83185e4..f4f2a2a 100644 (file)
@@ -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 {
index cf33484..564feb6 100644 (file)
@@ -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();
+       }
 }
index dcddbd7..dfe3136 100644 (file)
@@ -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,
index fe6ce68..e44ce5f 100644 (file)
@@ -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(