jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/371614 )

Change subject: Add 'Mark all as read' button
......................................................................


Add 'Mark all as read' button

Currently, the 'Mark all as read' button exists only for JS users.
This patch adds the button for no-JS users as well.

Bug: T96061
Change-Id: I1a62c56306597209540ffd694c8fb7b2a92885c9
---
M includes/special/SpecialNotifications.php
M includes/special/SpecialNotificationsMarkRead.php
M modules/nojs/mw.echo.special.less
3 files changed, 43 insertions(+), 4 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/special/SpecialNotifications.php 
b/includes/special/SpecialNotifications.php
index a03a83d..e6552ee 100644
--- a/includes/special/SpecialNotifications.php
+++ b/includes/special/SpecialNotifications.php
@@ -65,6 +65,7 @@
                // Add the notifications to the page (interspersed with date 
headers)
                $dateHeader = '';
                $unread = [];
+               $anyUnread = false;
                $echoSeenTime = EchoSeenTime::newFromUser( $user );
                $seenTime = $echoSeenTime->getTime();
                $notifArray = [];
@@ -97,6 +98,7 @@
 
                        // Collect unread IDs
                        if ( !isset( $row['read'] ) ) {
+                               $anyUnread = true;
                                $notifArray[ $dateHeader ][ 'unread' ][] = 
$row['id'];
                        }
 
@@ -112,6 +114,32 @@
 
                        // Store
                        $notifArray[ $dateHeader ][ 'notices' ][] = $li;
+               }
+
+               $markAllAsReadFormWrapper = '';
+               // Ensure there are some unread notifications
+               if ( $anyUnread ) {
+                       $markReadSpecialPage = new 
SpecialNotificationsMarkRead();
+
+                       $markAllAsReadText = $this->msg( 
'echo-mark-all-as-read' )->text();
+                       $markAllAsReadLabelIcon = new EchoOOUI\LabelIconWidget( 
[
+                               'label' => $markAllAsReadText,
+                               'icon' => 'doubleCheck',
+                       ] );
+
+                       $markAllAsReadForm = 
$markReadSpecialPage->getMinimalForm(
+                               [ 'ALL' ],
+                               $markAllAsReadText,
+                               true,
+                               $markAllAsReadLabelIcon->toString()
+                       );
+
+                       $formHtml = $markAllAsReadForm->prepareForm()->getHTML( 
/* First submission attempt */ false );
+
+                       $markAllAsReadFormWrapper = new OOUI\Tag();
+                       $markAllAsReadFormWrapper
+                               ->addClasses( [ 
'mw-echo-special-markAllReadButton' ] )
+                               ->appendContent( new OOUI\HtmlSnippet( 
$formHtml ) );
                }
 
                // Build the list
@@ -184,6 +212,7 @@
                        ->addClasses( [ 'mw-echo-special-container' ] )
                        ->appendContent(
                                $navTop,
+                               $markAllAsReadFormWrapper,
                                $notices,
                                $navBottom
                        );
diff --git a/includes/special/SpecialNotificationsMarkRead.php 
b/includes/special/SpecialNotificationsMarkRead.php
index 955fce6..dd95f34 100644
--- a/includes/special/SpecialNotificationsMarkRead.php
+++ b/includes/special/SpecialNotificationsMarkRead.php
@@ -53,6 +53,9 @@
                                        return $result;
                                },
                                'validation-callback' => function ( $value, 
$alldata ) {
+                                       if ( $value === [ 'ALL' ] ) {
+                                               return true;
+                                       }
                                        if ( (int)$value <= 0 ) {
                                                return $this->msg( 
'echo-specialpage-markasread-invalid-id' );
                                        }
@@ -129,10 +132,15 @@
         * @return bool|string|array|Status As documented for 
HTMLForm::trySubmit.
         */
        public function onSubmit( array $data /* $form = null */ ) {
+               $notifUser = MWEchoNotifUser::newFromUser( $this->getUser() );
+
+               // Allow for all IDs
+               if ( $data['id'] === [ 'ALL' ] ) {
+                       return $notifUser->markAllRead();
+               }
+
                // Allow for multiple IDs or a single ID
                $ids = $data['id'];
-
-               $notifUser = MWEchoNotifUser::newFromUser( $this->getUser() );
                return $notifUser->markRead( $ids );
        }
 
diff --git a/modules/nojs/mw.echo.special.less 
b/modules/nojs/mw.echo.special.less
index 681a952..87a7655 100644
--- a/modules/nojs/mw.echo.special.less
+++ b/modules/nojs/mw.echo.special.less
@@ -1,6 +1,10 @@
 /* Echo specific CSS */
 @import '../echo.variables';
 
+.mw-echo-special-container {
+       max-width: 600px;
+}
+
 .client-js .mw-echo-special-nojs {
        min-height: 5em;
        /* @embed */
@@ -59,8 +63,6 @@
 }
 
 ul.mw-echo-special-notifications {
-       max-width: 600px;
-
        div.mw-htmlform-submit-buttons {
                margin: 0;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a62c56306597209540ffd694c8fb7b2a92885c9
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: MtDu <justin.d...@gmail.com>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org>
Gerrit-Reviewer: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: MtDu <justin.d...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to