r88375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88374‎ | r88375 | r88376 >
Date:17:53, 18 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some work on email notification limit
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
@@ -14,6 +14,15 @@
1515 class SpecialSemanticWatchlist extends SpecialPage {
1616
1717 /**
 18+ * MediaWiki timestamp of when the watchlist was last viewed by the current user.
 19+ *
 20+ * @since 0.1
 21+ *
 22+ * @var integer
 23+ */
 24+ protected $lastViewed;
 25+
 26+ /**
1827 * Constructor.
1928 *
2029 * @since 0.1
@@ -62,6 +71,8 @@
6372 return;
6473 }
6574
 75+ $this->registerUserView( $wgUser );
 76+
6677 $limit = $wgRequest->getInt( 'limit', 20 );
6778 $offset = $wgRequest->getInt( 'offset', 0 );
6879 $continue = $wgRequest->getVal( 'continue' );
@@ -93,8 +104,29 @@
94105 }
95106
96107 /**
 108+ * Register the user viewed the watchlist,
 109+ * so we know that following chnages should
 110+ * result into notification emails is desired.
 111+ *
97112 * @since 0.1
98113 *
 114+ * @param User $user
 115+ */
 116+ protected function registerUserView( User $user ) {
 117+ $this->lastViewed = $user->getOption( 'swl_last_view' );
 118+
 119+ if ( is_null( $this->lastViewed ) ) {
 120+ $this->lastViewed = wfTimestampNow();
 121+ }
 122+
 123+ $user->setOption( 'swl_last_view', wfTimestampNow() );
 124+ $user->setOption( 'swl_mail_count',0 );
 125+ $user->saveSettings();
 126+ }
 127+
 128+ /**
 129+ * @since 0.1
 130+ *
99131 * @return string
100132 */
101133 protected function getPagingControlHTML( $limit, $currentContinue, $subPage, $newContinue, $offset ) {
@@ -172,17 +204,8 @@
173205 * @param array of SWLChangeSet $sets
174206 */
175207 protected function displayWatchlist( array $sets ) {
176 - global $wgOut, $wgLang, $wgUser;
 208+ global $wgOut, $wgLang;
177209
178 - $lastViewed = $wgUser->getOption( 'swl_last_view' );
179 -
180 - if ( is_null( $lastViewed ) ) {
181 - $lastViewed = wfTimestampNow();
182 - }
183 -
184 - $wgUser->setOption( 'swl_last_view', wfTimestampNow() );
185 - $wgUser->saveSettings();
186 -
187210 $changeSetsHTML = array();
188211
189212 foreach ( $sets as $set ) {
@@ -192,7 +215,7 @@
193216 $changeSetsHTML[$dayKey] = array();
194217 }
195218
196 - $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( $set, $lastViewed );
 219+ $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( $set );
197220 }
198221
199222 krsort( $changeSetsHTML );
@@ -249,11 +272,10 @@
250273 * @since 0.1
251274 *
252275 * @param SWLChangeSet $changeSet
253 - * @param integer $lastViewed The MW timestamp of when the user last viewed the watchlist
254276 *
255277 * @return string
256278 */
257 - protected function getChangeSetHTML( SWLChangeSet $changeSet, $lastViewed ) {
 279+ protected function getChangeSetHTML( SWLChangeSet $changeSet ) {
258280 global $wgLang;
259281
260282 $html = '';
@@ -295,7 +317,7 @@
296318 array( 'href' => SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() )->getLocalURL() ),
297319 wfMsg( 'blocklink' )
298320 ) . ')' .
299 - ( $changeSet->getTime() > $lastViewed ? ' [NEW]' : '' ) .
 321+ ( $changeSet->getTime() > $this->lastViewed ? ' [NEW]' : '' ) .
300322 '</p>'
301323 ;
302324
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php
@@ -35,3 +35,6 @@
3636
3737 # Enable email notification or not?
3838 $egSWLEnableEmailNotify = true;
 39+
 40+# The maximum amount of emails to send about changes untill the user actually checks his semantic watchlist.
 41+$egSWLMaxMails = 1;
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -59,9 +59,14 @@
6060 $lastWatch = $user->getOption( 'swl_last_watch' );
6161
6262 if ( is_null( $lastNotify ) || is_null( $lastWatch ) || $lastNotify < $lastWatch ) {
63 - SWLEmailer::notifyUser( $group, $user, $changes );
64 - $user->setOption( 'swl_last_notify', wfTimestampNow() );
65 - $user->saveSettings();
 63+ $mailCount = $user->getOption( 'swl_mail_count', 0 );
 64+
 65+ if ( $mailCount < $egSWLMaxMails ) {
 66+ SWLEmailer::notifyUser( $group, $user, $changes );
 67+ $user->setOption( 'swl_last_notify', wfTimestampNow() );
 68+ $user->setOption( 'swl_mail_count', $mailCount + 1 );
 69+ $user->saveSettings();
 70+ }
6671 }
6772 }
6873 }

Status & tagging log