Jhernandez has uploaded a new change for review.

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

Change subject: WIP: Admin can hide a public list in Special:GatherLists
......................................................................

WIP: Admin can hide a public list in Special:GatherLists

TODO
* SpecialGatherLists.php: Implement function canHideLists
* ext.gather.lists/init.js: Call API for editing the list
         * Show toasts for success/failure

Bug: T91444
Change-Id: Icbd114a7473aa2361abdb989282ab0e95f1bd78a
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/specials/SpecialGatherLists.php
M resources/Resources.php
A resources/ext.gather.lists/init.js
M resources/ext.gather.styles/lists.less
7 files changed, 93 insertions(+), 5 deletions(-)


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

diff --git a/extension.json b/extension.json
index e009af5..85cdc6a 100644
--- a/extension.json
+++ b/extension.json
@@ -236,6 +236,12 @@
                        ],
                        "styles": [
                                "ext.gather.styles/lists.less"
+                       ],
+                       "messages": [
+                               "gather-lists-hide-collection"
+                       ],
+                       "scripts": [
+                               "ext.gather.lists/init.js"
                        ]
                }
        },
diff --git a/i18n/en.json b/i18n/en.json
index c7823a5..bd32f4c 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -6,6 +6,7 @@
        "gather-lists-collection-title": "Title",
        "gather-lists-collection-description": "Description",
        "gather-lists-collection-count": "Count",
+       "gather-lists-hide-collection": "Do you want to hide list \"$1\" by 
\"$2\"?",
        "gather-edit-collection-heading": "Edit collection",
        "gather-edit-collection-label-name": "Name",
        "gather-edit-collection-label-description": "Description",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0380b4c..3aef897 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -9,6 +9,7 @@
        "gather-lists-collection-title": "Label for title of collection on list 
of all collections",
        "gather-lists-collection-description": "Label for description of 
collection on list of all collections",
        "gather-lists-collection-count": "Label for count of collection on list 
of all collections",
+       "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-edit-collection-heading": "Heading for collection editor 
overlay",
        "gather-edit-collection-label-name": "Label above input field for name 
of collection\n{{Identical|Name}}",
        "gather-edit-collection-label-description": "Label above input field 
for description of collection\n{{Identical|Description}}",
diff --git a/includes/specials/SpecialGatherLists.php 
b/includes/specials/SpecialGatherLists.php
index d29bd7b..d8cf9d3 100644
--- a/includes/specials/SpecialGatherLists.php
+++ b/includes/specials/SpecialGatherLists.php
@@ -10,6 +10,7 @@
 use ApiMain;
 use FauxRequest;
 use Html;
+use Gather\views\helpers\CSS;
 
 /**
  * Render a collection of articles.
@@ -69,8 +70,11 @@
                . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-owner' ) )
                . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-title' ) )
                . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-description' ) )
-               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-count' ) )
-               . Html::closeElement( 'li' );
+               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-count' ) );
+               if ( $this->canHideLists() ) {
+                       $html .= Html::element( 'span', array(), '' );
+               }
+               $html .= Html::closeElement( 'li' );
                foreach ( $lists as $list ) {
                        $html .= $this->row( $list );
                }
@@ -80,21 +84,59 @@
                $out->addHTML( $html );
        }
 
+       /**
+        * Returns if the current user can hide public lists
+        * @return bool
+        */
+       private function canHideLists() {
+               // FIXME: Check permissions to see if $this->getUser() can make 
lists
+               // private
+               return true;
+       }
+
+       /**
+        * Renders a html row of data
+        * @param array $data
+        * @return string
+        */
        private function row( $data ) {
-               return Html::openElement( 'li', array( 'class' => 
$additionalClasses ) )
+               $html = Html::openElement( 'li', array( 'class' => 
$additionalClasses ) )
                        . $this->userLink( $data['owner'] )
                        . $this->collectionLink( $data['label'], 
$data['owner'], $data['id'] )
                        . Html::element( 'span', array(), $data['description'] )
-                       . Html::element( 'span', array(), $data['count'] )
-                       . Html::closeElement( 'li' );
+                       . Html::element( 'span', array(), $data['count'] );
+               if ( $this->canHideLists() ) {
+                       $html .= Html::openElement( 'span', array() )
+                               . Html::element( 'span', array(
+                                       'class' => CSS::iconClass( 'cancel', 
'element', 'hide-collection' ),
+                                       'data-id' => $data['id'],
+                                       'data-label' => $data['label'],
+                                       'data-owner' => $data['owner']
+                               ), '' )
+                               . Html::closeElement( 'span' );
+               }
+               $html .= Html::closeElement( 'li' );
+               return $html;
        }
 
+       /**
+        * Renders a html link for the user's gather page
+        * @param User $user
+        * @return string
+        */
        private function userLink( $user ) {
                return Html::element( 'a', array(
                        'href' => SpecialPage::getTitleFor( 'Gather', $user 
)->getLocalUrl()
                ), $user );
        }
 
+       /**
+        * Renders a html link for a collection page
+        * @param string $text of the link
+        * @param User $user owner of the collection
+        * @param int $id of the collection
+        * @return string
+        */
        private function collectionLink( $text, $user, $id ) {
                return Html::element( 'a', array(
                        'href' => SpecialPage::getTitleFor( 'Gather', 
$user.'/'.$id )->getLocalUrl()
diff --git a/resources/Resources.php b/resources/Resources.php
index 97d439a..563064e 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -201,6 +201,12 @@
                'styles' => array(
                        'ext.gather.styles/lists.less',
                ),
+               'messages' => array(
+                       'gather-lists-hide-collection',
+               ),
+               'scripts' => array(
+                       'ext.gather.lists/init.js',
+               ),
        )
 
 );
diff --git a/resources/ext.gather.lists/init.js 
b/resources/ext.gather.lists/init.js
new file mode 100644
index 0000000..b07b44c
--- /dev/null
+++ b/resources/ext.gather.lists/init.js
@@ -0,0 +1,25 @@
+( function ( M, $ ) {
+
+       /**
+        * Event handler for trying to hide a list
+        * @param {jQuery.Event} ev
+        */
+       function onHideCollection( ev ) {
+               var $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 );
+
+               if ( window.confirm( message ) ) {
+                       // TODO: Call API for editing the list with id, and on 
success:
+                       $row.fadeOut(function() {
+                               $row.remove();
+                       });
+               }
+       }
+
+       $( 'ul' ).on( 'click', '.hide-collection', onHideCollection );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/ext.gather.styles/lists.less 
b/resources/ext.gather.styles/lists.less
index b362968..ea59a41 100644
--- a/resources/ext.gather.styles/lists.less
+++ b/resources/ext.gather.styles/lists.less
@@ -47,4 +47,11 @@
                        }
                }
        }
+
+       .hide-collection {
+               min-width: 3em;
+               max-width: 3em;
+               vertical-align: bottom;
+               cursor: pointer;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbd114a7473aa2361abdb989282ab0e95f1bd78a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org>

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

Reply via email to