MtDu has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371614 )

Change subject: [WIP] Add 'Mark all as read' button
......................................................................

[WIP] 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
2 files changed, 46 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/14/371614/1

diff --git a/includes/special/SpecialNotifications.php 
b/includes/special/SpecialNotifications.php
index a03a83d..d96d1ba 100644
--- a/includes/special/SpecialNotifications.php
+++ b/includes/special/SpecialNotifications.php
@@ -114,6 +114,40 @@
                        $notifArray[ $dateHeader ][ 'notices' ][] = $li;
                }
 
+               // Ensure there are some unread notifications
+               $markAllRead = false;
+               foreach ( $notifArray as $section => $data ) {
+                       if ( count( $data[ 'unread' ] ) > 0 ) {
+                               $markAllRead = true;
+                       }
+               }
+
+               if ( $markAllRead ) {
+                       $markReadSpecialPage = new 
SpecialNotificationsMarkRead();
+
+                       $markReadSectionText = $this->msg( 
'echo-mark-all-as-read' )->text();
+                       $markAsReadLabelIcon = new EchoOOUI\LabelIconWidget( [
+                               'label' => $markReadSectionText,
+                               'icon' => 'doubleCheck',
+                       ] );
+
+                       $markSectionAsReadForm = 
$markReadSpecialPage->getMinimalForm(
+                               [ 'ALL' ],
+                               $markReadSectionText,
+                               true,
+                               $markAsReadLabelIcon->toString()
+                       );
+
+                       $formHtml = 
$markSectionAsReadForm->prepareForm()->getHTML( /* First submission attempt */ 
false );
+
+                       $markAllAsReadFormWrapper = new OOUI\Tag();
+                       $markAllAsReadFormWrapper
+                               ->appendContent( new OOUI\HtmlSnippet( 
$formHtml ) );
+
+                       // $heading->appendContent( $formWrapper );
+               }
+               // End
+
                // Build the list
                $notices = new OOUI\Tag( 'ul' );
                $notices->addClasses( [ 'mw-echo-special-notifications' ] );
@@ -184,6 +218,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..9f17534 100644
--- a/includes/special/SpecialNotificationsMarkRead.php
+++ b/includes/special/SpecialNotificationsMarkRead.php
@@ -53,6 +53,10 @@
                                        return $result;
                                },
                                'validation-callback' => function ( $value, 
$alldata ) {
+                                       if ( $value === [ 'ALL' ] ) {
+                                               // Gotta be a better way to 
handle this
+                                               return true;
+                                       }
                                        if ( (int)$value <= 0 ) {
                                                return $this->msg( 
'echo-specialpage-markasread-invalid-id' );
                                        }
@@ -129,10 +133,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 );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a62c56306597209540ffd694c8fb7b2a92885c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: MtDu <justin.d...@gmail.com>

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

Reply via email to