Jdlrobson has uploaded a new change for review.

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

Change subject: Add Special:GatherLists/hidden
......................................................................

Add Special:GatherLists/hidden

Allow admins to make lists non-hidden because accidents happen.
Add labels to buttons so this works on Vector

Bug: T93795
Bug: T93821
Change-Id: Ie70864353f1f69390936019a463f70fc49654c92
---
M i18n/en.json
M i18n/qqq.json
M includes/specials/SpecialGatherLists.php
M resources/Resources.php
M resources/ext.gather.lists/init.js
M resources/ext.gather.watchstar/CollectionsApi.js
6 files changed, 74 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/47/199547/1

diff --git a/i18n/en.json b/i18n/en.json
index 8e4e831..28a871e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -11,9 +11,14 @@
        "gather-lists-collection-title": "Title",
        "gather-lists-collection-description": "Description",
        "gather-lists-collection-count": "Count",
+       "gather-lists-hide-collection-label": "Hide",
        "gather-lists-hide-collection": "Do you want to hide list \"$1\" by 
\"$2\"?",
        "gather-lists-hide-success-toast": "List \"$1\" was hidden 
successfully.",
        "gather-lists-hide-failure-toast": "Failed to hide list \"$1\".",
+       "gather-lists-show-collection-label": "Reveal",
+       "gather-lists-show-collection": "Do you want to make list \"$1\" by 
\"$2\" public again?",
+       "gather-lists-show-success-toast": "List \"$1\" was made public again 
successfully.",
+       "gather-lists-show-failure-toast": "Failed to show list \"$1\".",
        "gather-remove-from-collection-failed-toast": "Unable to remove page 
from collection.",
        "gather-add-to-collection-failed-toast": "Unable to add page to 
collection.",
        "gather-edit-collection-heading": "Edit collection",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 1747ac3..82c4280 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -15,9 +15,14 @@
        "gather-lists-collection-description": "Label for description of 
collection on list of all collections\n{{Identical|Description}}",
        "gather-lists-collection-last-updated": "Label for last updated time of 
a collection",
        "gather-lists-collection-count": "Label for count of collection on list 
of all collections\n{{Identical|Count}}",
+       "gather-lists-hide-collection-label": "Label for button that performs 
moderation hide action which sets list from public to hidden.",
        "gather-lists-hide-collection": "Label asking for confirmation when 
hiding a user's collection for moderation purposes. Parameters:\n* $1 - Title 
of the collection.\n* $2 - User name of the owner.",
        "gather-lists-hide-success-toast": "Label for toast displaying that 
specified list was hidden successfully. Parameters:\n* $1 - Title of the 
collection.",
        "gather-lists-hide-failure-toast": "Label for toast diaplaying that 
hiding specified list failed. Parameters:\n* $1 - Title of the collection.",
+       "gather-lists-show-collection-label": "Label for button that performs 
moderation reveal/show action which resets list from hidden to public.",
+       "gather-lists-show-collection": "Label asking for confirmation when 
revealing a user's collection for moderation purposes. Parameters:\n* $1 - 
Title of the collection.\n* $2 - User name of the owner.",
+       "gather-lists-show-success-toast": "Label for toast displaying that 
specified list was shown successfully. Only shown to admins. Parameters:\n* $1 
- Title of the collection.",
+       "gather-lists-show-failure-toast": "Label for toast diaplaying that 
showing specified list failed. Only shown to admins. Parameters:\n* $1 - Title 
of the collection.",
        "gather-remove-from-collection-failed-toast": "Error message displayed 
to user when remove from collection action fails.",
        "gather-add-to-collection-failed-toast": "Error message displayed to 
user when add to collection action fails",
        "gather-edit-collection-heading": "Heading for collection editor 
overlay",
diff --git a/includes/specials/SpecialGatherLists.php 
b/includes/specials/SpecialGatherLists.php
index d6f84cc..0156efa 100644
--- a/includes/specials/SpecialGatherLists.php
+++ b/includes/specials/SpecialGatherLists.php
@@ -34,15 +34,27 @@
                );
        }
 
+       public function renderError() {
+               $out = $this->getOutput();
+               // FIXME: Get better i18n message for this view.
+               $view = new views\NoPublic();
+               $out->setPageTitle( $view->getTitle() );
+               $view->render( $out );
+       }
+
        /**
         * Render the special page
         */
        public function execute( $subPage ) {
+               if ( $subPage === 'hidden' && !$this->canHideLists() ) {
+                       $this->renderError();
+                       return;
+               }
                // FIXME: Make method on CollectionsList
                $api = new ApiMain( new FauxRequest( array(
                        'action' => 'query',
                        'list' => 'lists',
-                       'lstmode' => 'allpublic',
+                       'lstmode' => $subPage === 'hidden' ? 'allhidden' : 
'allpublic',
                        // FIXME: Need owner to link to collection
                        'lstprop' => 'label|description|image|count|updated',
                        // TODO: Pagination
@@ -52,7 +64,7 @@
                $data = $api->getResultData();
                if ( isset( $data['query']['lists'] ) ) {
                        $lists = $data['query']['lists'];
-                       $this->render( $lists );
+                       $this->render( $lists, $subPage === 'hidden' ? 'show' : 
'hide' );
                }
        }
 
@@ -60,8 +72,9 @@
         * Render the special page
         *
         * @param array $lists
+        * @param string [$action] hide or show - action to associate with the 
row.
         */
-       public function render( $lists ) {
+       public function render( $lists, $action ) {
                $out = $this->getOutput();
                $this->setHeaders();
                $out->setProperty( 'unstyledContent', true );
@@ -82,7 +95,7 @@
                }
                $html .= Html::closeElement( 'li' );
                foreach ( $lists as $list ) {
-                       $html .= $this->row( $list );
+                       $html .= $this->row( $list, $action );
                }
                $html .= Html::closeElement( 'ul' );
                $html .= Html::closeElement( 'div' );
@@ -101,9 +114,10 @@
        /**
         * Renders a html row of data
         * @param array $data
+        * @param string [$action] hide or show - action to associate with the 
row.
         * @return string
         */
-       private function row( $data ) {
+       private function row( $data, $action = 'hide' ) {
                $lang = $this->getLanguage();
                $user = $this->getUser();
                $ts = $lang->userTimeAndDate( new MWTimestamp( $data['updated'] 
), $user );
@@ -116,14 +130,22 @@
                        . Html::element( 'span', array(), $ts );
 
                if ( $this->canHideLists() ) {
+                       $className = $action === 'hide' ? CSS::iconClass( 
'cancel', 'element', 'moderate-collection' ) :
+                               // FIXME: style
+                               'moderate-collection';
+
+                       $label = $action === 'hide' ? $this->msg( 
'gather-lists-hide-collection-label' ) :
+                               $this->msg( 
'gather-lists-show-collection-label' );
+
                        $html .= Html::openElement( 'span', array() )
                                . Html::openElement( 'button', array() )
                                . Html::element( 'span', array(
-                                       'class' => CSS::iconClass( 'cancel', 
'element', 'hide-collection' ),
+                                       'class' => $className,
                                        'data-id' => $data['id'],
+                                       'data-action' => $action,
                                        'data-label' => $data['label'],
                                        'data-owner' => $data['owner']
-                               ), '' )
+                               ), $label )
                                . Html::closeElement( 'button' )
                                . Html::closeElement( 'span' );
                }
diff --git a/resources/Resources.php b/resources/Resources.php
index 89f7df4..f0f15e4 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -227,6 +227,9 @@
                        'gather-lists-hide-collection',
                        'gather-lists-hide-success-toast',
                        'gather-lists-hide-failure-toast',
+                       'gather-lists-show-collection',
+                       'gather-lists-show-success-toast',
+                       'gather-lists-show-failure-toast',
                ),
                'scripts' => array(
                        'ext.gather.lists/init.js',
diff --git a/resources/ext.gather.lists/init.js 
b/resources/ext.gather.lists/init.js
index ec22998..3143c8f 100644
--- a/resources/ext.gather.lists/init.js
+++ b/resources/ext.gather.lists/init.js
@@ -7,22 +7,25 @@
         * Initialize the moderation buttons
         */
        function init() {
-               $( 'ul' ).on( 'click', '.hide-collection', onHideCollection );
+               $( 'ul' ).on( 'click', '.moderate-collection', 
onModerateCollection );
        }
 
        /**
         * Event handler for trying to hide a list
         * @param {jQuery.Event} ev
         */
-       function onHideCollection( ev ) {
-               var $btn = $( ev.currentTarget ),
+       function onModerateCollection( ev ) {
+               var method,
+                       $btn = $( ev.currentTarget ),
                        $row = $btn.closest( 'li' ),
                        id = $btn.data( 'id' ),
                        label = $btn.data( 'label' ),
                        owner = $btn.data( 'owner' ),
-                       message = mw.msg( 'gather-lists-hide-collection', 
label, owner );
+                       action = $btn.data( 'action' ),
+                       msgKey = action === 'hide' ? 
'gather-lists-hide-collection' : 'gather-lists-show-collection',
+                       message = mw.msg( msgKey, label, owner );
 
-               if ( window.confirm( message ) ) {
+               if ( action === 'hide' && window.confirm( message ) ) {
                        api.hideCollection( id ).done( function () {
                                $row.fadeOut( function () {
                                        $row.remove();
@@ -32,6 +35,17 @@
                                toast.show( mw.msg( 
'gather-lists-hide-failure-toast', label ), 'toast fail' );
                        } );
                }
+
+               if ( action === 'show' && window.confirm( message ) ) {
+                       api.showCollection( id ).done( function () {
+                               $row.fadeOut( function () {
+                                       $row.remove();
+                                       toast.show( mw.msg( 
'gather-lists-show-success-toast', label ), 'toast' );
+                               } );
+                       } ).fail( function () {
+                               toast.show( mw.msg( 
'gather-lists-show-failure-toast', label ), 'toast fail' );
+                       } );
+               }
        }
 
        init();
diff --git a/resources/ext.gather.watchstar/CollectionsApi.js 
b/resources/ext.gather.watchstar/CollectionsApi.js
index 48b6535..fe9dd03 100644
--- a/resources/ext.gather.watchstar/CollectionsApi.js
+++ b/resources/ext.gather.watchstar/CollectionsApi.js
@@ -157,8 +157,20 @@
                                id: id,
                                mode: 'hidelist'
                        } );
+               },
+               /**
+                * Show list (moderation purposes)
+                * @method
+                * @param {Number} id unique identifier of collection
+                * @return {jQuery.Deferred}
+                */
+               showCollection: function ( id ) {
+                       return this.postWithToken( 'watch', {
+                               action: 'editlist',
+                               id: id,
+                               mode: 'showlist'
+                       } );
                }
-
        } );
 
        M.define( 'ext.gather.watchstar/CollectionsApi', CollectionsApi );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie70864353f1f69390936019a463f70fc49654c92
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

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

Reply via email to