mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Merge "Add 'Mark all as read' button"
This commit is contained in:
commit
e74713a3ba
|
@ -65,6 +65,7 @@ class SpecialNotifications extends SpecialPage {
|
|||
// 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 @@ class SpecialNotifications extends SpecialPage {
|
|||
|
||||
// Collect unread IDs
|
||||
if ( !isset( $row['read'] ) ) {
|
||||
$anyUnread = true;
|
||||
$notifArray[ $dateHeader ][ 'unread' ][] = $row['id'];
|
||||
}
|
||||
|
||||
|
@ -114,6 +116,32 @@ class SpecialNotifications extends SpecialPage {
|
|||
$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
|
||||
$notices = new OOUI\Tag( 'ul' );
|
||||
$notices->addClasses( [ 'mw-echo-special-notifications' ] );
|
||||
|
@ -184,6 +212,7 @@ class SpecialNotifications extends SpecialPage {
|
|||
->addClasses( [ 'mw-echo-special-container' ] )
|
||||
->appendContent(
|
||||
$navTop,
|
||||
$markAllAsReadFormWrapper,
|
||||
$notices,
|
||||
$navBottom
|
||||
);
|
||||
|
|
|
@ -53,6 +53,9 @@ class SpecialNotificationsMarkRead extends FormSpecialPage {
|
|||
return $result;
|
||||
},
|
||||
'validation-callback' => function ( $value, $alldata ) {
|
||||
if ( $value === [ 'ALL' ] ) {
|
||||
return true;
|
||||
}
|
||||
if ( (int)$value <= 0 ) {
|
||||
return $this->msg( 'echo-specialpage-markasread-invalid-id' );
|
||||
}
|
||||
|
@ -130,10 +133,15 @@ class SpecialNotificationsMarkRead extends FormSpecialPage {
|
|||
* @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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue