From 6f926c59df30a325ebefd7022fa85c28b2e646eb Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 18 Dec 2004 07:16:11 +0000 Subject: [PATCH] Refactor a bit; move a couple methods from UserMailer (?!) to User. Use the proper $wgRequest for checking reset var, avoid notice warning. --- includes/Article.php | 4 +--- includes/SpecialWatchlist.php | 6 ++--- includes/User.php | 44 +++++++++++++++++++++++++++++++++++ includes/UserMailer.php | 35 ---------------------------- 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 870238220c..572583d12e 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -808,9 +808,7 @@ class Article { $this->viewUpdates(); wfProfileOut( $fname ); - include_once( "UserMailer.php" ); - $wgEnotif = new EmailNotification (); - $wgEnotif->Clear( $wgUser->getID(), $this->mTitle->getDBkey(), $this->mTitle->getNamespace() ); + $wgUser->clearNotification( $this->mTitle ); } /** diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index 046dabb14a..f2f4378c35 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -41,9 +41,9 @@ function wfSpecialWatchlist() { $wgOut->addHTML( wfMsg( "email_notification_infotext" ) ); - include_once( "UserMailer.php" ); - $wgEnotif = new EmailNotification (); - $wgEnotif->ClearAll($wgUser->getID()); + if( $wgRequest->getVal( 'reset' ) == 'all' ) { + $wgUser->clearAllNotifications(); + } if(($action == "submit") && isset($remove) && is_array($id)) { $wgOut->addHTML( wfMsg( "removingchecked" ) ); diff --git a/includes/User.php b/includes/User.php index 58fb9db37e..5b75fad299 100644 --- a/includes/User.php +++ b/includes/User.php @@ -795,8 +795,52 @@ class User { $wl->removeWatch(); $this->invalidateCache(); } + + /** + * Clear the user's notification timestamp for the given title. + * If e-notif e-mails are on, they will receive notification mails on + * the next change of the page if it's watched etc. + */ + function clearNotification( $title ) { + $dbw =& wfGetDB( DB_MASTER ); + $success = $dbw->update( 'watchlist', + array( /* SET */ + 'wl_notificationtimestamp' => 0 + ), array( /* WHERE */ + 'wl_title' => $title->getDBkey(), + 'wl_namespace' => $title->getNamespace(), + 'wl_user' => $this->getId() + ), 'User::clearLastVisited' + ); + } + /**#@-*/ + /** + * Resets all of the given user's page-change notification timestamps. + * If e-notif e-mails are on, they will receive notification mails on + * the next change of any watched page. + * + * @param int $currentUser user ID number + * @access public + */ + function clearAllNotifications( $currentUser ) { + if( $currentUser != 0 ) { + + $dbw =& wfGetDB( DB_MASTER ); + $success = $dbw->update( 'watchlist', + array( /* SET */ + 'wl_notificationtimestamp' => 0 + ), array( /* WHERE */ + 'wl_user' => $currentUser + ), 'UserMailer::clearAll' + ); + + # we also need to clear here the "you have new message" notification for the own user_talk page + # This is cleared one page view later in Article::viewUpdates(); + } + } + /** * @access private * @return string Encoding options diff --git a/includes/UserMailer.php b/includes/UserMailer.php index 422f1a8b47..d1f9255a17 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -335,40 +335,5 @@ function ComposeAndSendPersonalisedMail( $watchingUser, $mail, $article) { return (userMailer($to, $mail->from, $mail->subject, $body, $mail->replyto) == ''); } -function Clear($currentUser, $currentPage, $currentNs) { - $dbw =& wfGetDB( DB_MASTER ); - $success = $dbw->update( 'watchlist', - array( /* SET */ - 'wl_notificationtimestamp' => 0 - ), array( /* WHERE */ - 'wl_title' => $currentPage, - 'wl_namespace' => $currentNs, - 'wl_user' => $currentUser - ), 'UserMailer::Clear' - ); -} - -function ClearAll($currentUser) { - global $_REQUEST; - - if ($currentUser != 0) { - - if( $_REQUEST['reset'] == 'all') { - - $dbw =& wfGetDB( DB_MASTER ); - $success = $dbw->update( 'watchlist', - array( /* SET */ - 'wl_notificationtimestamp' => 0 - ), array( /* WHERE */ - 'wl_user' => $currentUser - ), 'UserMailer::ClearAll' - ); - - # we also need to clear here the "you have new message" notification for the own user_talk page - # This is cleared one page view later in Article::viewUpdates(); - } - } -} - } # end of class EmailNotification ?> -- 2.20.1