Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php |
— | — | @@ -14,6 +14,15 @@ |
15 | 15 | class SpecialSemanticWatchlist extends SpecialPage { |
16 | 16 | |
17 | 17 | /** |
| 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 | + /** |
18 | 27 | * Constructor. |
19 | 28 | * |
20 | 29 | * @since 0.1 |
— | — | @@ -62,6 +71,8 @@ |
63 | 72 | return; |
64 | 73 | } |
65 | 74 | |
| 75 | + $this->registerUserView( $wgUser ); |
| 76 | + |
66 | 77 | $limit = $wgRequest->getInt( 'limit', 20 ); |
67 | 78 | $offset = $wgRequest->getInt( 'offset', 0 ); |
68 | 79 | $continue = $wgRequest->getVal( 'continue' ); |
— | — | @@ -93,8 +104,29 @@ |
94 | 105 | } |
95 | 106 | |
96 | 107 | /** |
| 108 | + * Register the user viewed the watchlist, |
| 109 | + * so we know that following chnages should |
| 110 | + * result into notification emails is desired. |
| 111 | + * |
97 | 112 | * @since 0.1 |
98 | 113 | * |
| 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 | + * |
99 | 131 | * @return string |
100 | 132 | */ |
101 | 133 | protected function getPagingControlHTML( $limit, $currentContinue, $subPage, $newContinue, $offset ) { |
— | — | @@ -172,17 +204,8 @@ |
173 | 205 | * @param array of SWLChangeSet $sets |
174 | 206 | */ |
175 | 207 | protected function displayWatchlist( array $sets ) { |
176 | | - global $wgOut, $wgLang, $wgUser; |
| 208 | + global $wgOut, $wgLang; |
177 | 209 | |
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 | | - |
187 | 210 | $changeSetsHTML = array(); |
188 | 211 | |
189 | 212 | foreach ( $sets as $set ) { |
— | — | @@ -192,7 +215,7 @@ |
193 | 216 | $changeSetsHTML[$dayKey] = array(); |
194 | 217 | } |
195 | 218 | |
196 | | - $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( $set, $lastViewed ); |
| 219 | + $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( $set ); |
197 | 220 | } |
198 | 221 | |
199 | 222 | krsort( $changeSetsHTML ); |
— | — | @@ -249,11 +272,10 @@ |
250 | 273 | * @since 0.1 |
251 | 274 | * |
252 | 275 | * @param SWLChangeSet $changeSet |
253 | | - * @param integer $lastViewed The MW timestamp of when the user last viewed the watchlist |
254 | 276 | * |
255 | 277 | * @return string |
256 | 278 | */ |
257 | | - protected function getChangeSetHTML( SWLChangeSet $changeSet, $lastViewed ) { |
| 279 | + protected function getChangeSetHTML( SWLChangeSet $changeSet ) { |
258 | 280 | global $wgLang; |
259 | 281 | |
260 | 282 | $html = ''; |
— | — | @@ -295,7 +317,7 @@ |
296 | 318 | array( 'href' => SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() )->getLocalURL() ), |
297 | 319 | wfMsg( 'blocklink' ) |
298 | 320 | ) . ')' . |
299 | | - ( $changeSet->getTime() > $lastViewed ? ' [NEW]' : '' ) . |
| 321 | + ( $changeSet->getTime() > $this->lastViewed ? ' [NEW]' : '' ) . |
300 | 322 | '</p>' |
301 | 323 | ; |
302 | 324 | |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php |
— | — | @@ -35,3 +35,6 @@ |
36 | 36 | |
37 | 37 | # Enable email notification or not? |
38 | 38 | $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 @@ |
60 | 60 | $lastWatch = $user->getOption( 'swl_last_watch' ); |
61 | 61 | |
62 | 62 | 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 | + } |
66 | 71 | } |
67 | 72 | } |
68 | 73 | } |