Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/208112

Change subject: ChangeTags: Don't show UI when no editable tags exist
......................................................................

ChangeTags: Don't show UI when no editable tags exist

This also picks up I72ca7371, which was necessary for a successful
merge.

Bug: T97773
Change-Id: I001f15ca6f58bc9318eed84aa8ace2bddcb1b315
(cherry picked from commit a2415baa1a3c94abe83d0e2af274c4753775515e)
---
M includes/actions/HistoryAction.php
M includes/changetags/ChangeTags.php
M includes/logging/LogEventsList.php
M includes/specials/SpecialLog.php
4 files changed, 47 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/12/208112/1

diff --git a/includes/actions/HistoryAction.php 
b/includes/actions/HistoryAction.php
index 83185e4..f4f2a2a 100644
--- a/includes/actions/HistoryAction.php
+++ b/includes/actions/HistoryAction.php
@@ -504,7 +504,7 @@
                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 @@
                $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 43f957c..5b0c234 100644
--- a/includes/changetags/ChangeTags.php
+++ b/includes/changetags/ChangeTags.php
@@ -1219,4 +1219,22 @@
                $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 8b28821..dfe3136 100644
--- a/includes/logging/LogEventsList.php
+++ b/includes/logging/LogEventsList.php
@@ -26,7 +26,7 @@
 class LogEventsList extends ContextSource {
        const NO_ACTION_LINK = 1;
        const NO_EXTRA_USER_LINKS = 2;
-       const USE_REVDEL_CHECKBOXES = 4;
+       const USE_CHECKBOXES = 4;
 
        public $flags;
 
@@ -44,7 +44,7 @@
         *   a Skin object. Use of Skin is deprecated.
         * @param null $unused Unused; used to be an OutputPage object.
         * @param int $flags Can be a combination of self::NO_ACTION_LINK,
-        *   self::NO_EXTRA_USER_LINKS or self::USE_REVDEL_CHECKBOXES.
+        *   self::NO_EXTRA_USER_LINKS or self::USE_CHECKBOXES.
         */
        public function __construct( $context, $unused = null, $flags = 0 ) {
                if ( $context instanceof IContextSource ) {
@@ -341,14 +341,27 @@
         */
        private function getShowHideLinks( $row ) {
                // We don't want to see the links and
-               // no one can hide items from the suppress log.
-               if ( ( $this->flags == self::NO_ACTION_LINK )
-                       || $row->log_type == 'suppress'
-               ) {
+               if ( $this->flags == self::NO_ACTION_LINK ) {
                        return '';
                }
-               $del = '';
+
                $user = $this->getUser();
+
+               // If change tag editing is available to this user, return the 
checkbox
+               if ( $this->flags & self::USE_CHECKBOXES && 
ChangeTags::showTagEditingUI( $user ) ) {
+                       return Xml::check(
+                               'showhiderevisions',
+                               false,
+                               array( 'name' => 'ids[' . $row->log_id . ']' )
+                       );
+               }
+
+               // no one can hide items from the suppress log.
+               if ( $row->log_type == 'suppress' ) {
+                       return '';
+               }
+
+               $del = '';
                // Don't show useless checkbox to people who cannot hide log 
entries
                if ( $user->isAllowed( 'deletedhistory' ) ) {
                        $canHide = $user->isAllowed( 'deletelogentry' );
@@ -358,7 +371,7 @@
                        $canViewThisSuppressedEntry = $canViewSuppressedOnly && 
$entryIsSuppressed;
                        if ( $row->log_deleted || $canHide ) {
                                // Show checkboxes instead of links.
-                               if ( $canHide && $this->flags & 
self::USE_REVDEL_CHECKBOXES && !$canViewThisSuppressedEntry ) {
+                               if ( $canHide && $this->flags & 
self::USE_CHECKBOXES && !$canViewThisSuppressedEntry ) {
                                        // If event was hidden from sysops
                                        if ( !self::userCan( $row, 
LogPage::DELETED_RESTRICTED, $user ) ) {
                                                $del = Xml::check( 
'deleterevisions', false, array( 'disabled' => 'disabled' ) );
diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php
index f16e5ba..e44ce5f 100644
--- a/includes/specials/SpecialLog.php
+++ b/includes/specials/SpecialLog.php
@@ -165,7 +165,7 @@
                $loglist = new LogEventsList(
                        $this->getContext(),
                        null,
-                       LogEventsList::USE_REVDEL_CHECKBOXES
+                       LogEventsList::USE_CHECKBOXES
                );
                $pager = new LogPager(
                        $loglist,
@@ -218,10 +218,10 @@
        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 @@
                                $this->msg( 'showhideselectedlogentries' 
)->text()
                        ) . "\n";
                }
-               if ( $canModifyTags ) {
+               if ( $showTagEditUI ) {
                        $buttons .= Html::element(
                                'button',
                                array(

-- 
To view, visit https://gerrit.wikimedia.org/r/208112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I001f15ca6f58bc9318eed84aa8ace2bddcb1b315
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.26wmf3
Gerrit-Owner: Anomie <bjor...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to