r88370 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88369‎ | r88370 | r88371 >
Date:16:58, 18 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on email notification and tweaks to special:semanticwatchlist
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css
@@ -10,4 +10,8 @@
1111
1212 .swl-watchlist-deletions {
1313 display: inline;
 14+}
 15+
 16+.swl-watchlist-prop {
 17+
1418 }
\ No newline at end of file
Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
@@ -172,8 +172,17 @@
173173 * @param array of SWLChangeSet $sets
174174 */
175175 protected function displayWatchlist( array $sets ) {
176 - global $wgOut, $wgLang;
 176+ global $wgOut, $wgLang, $wgUser;
177177
 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+
178187 $changeSetsHTML = array();
179188
180189 foreach ( $sets as $set ) {
@@ -183,7 +192,7 @@
184193 $changeSetsHTML[$dayKey] = array();
185194 }
186195
187 - $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( $set );
 196+ $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( $set, $lastViewed );
188197 }
189198
190199 krsort( $changeSetsHTML );
@@ -240,10 +249,11 @@
241250 * @since 0.1
242251 *
243252 * @param SWLChangeSet $changeSet
 253+ * @param integer $lastViewed The MW timestamp of when the user last viewed the watchlist
244254 *
245255 * @return string
246256 */
247 - protected function getChangeSetHTML( SWLChangeSet $changeSet ) {
 257+ protected function getChangeSetHTML( SWLChangeSet $changeSet, $lastViewed ) {
248258 global $wgLang;
249259
250260 $html = '';
@@ -284,7 +294,8 @@
285295 'a',
286296 array( 'href' => SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() )->getLocalURL() ),
287297 wfMsg( 'blocklink' )
288 - ) . ')' .
 298+ ) . ')' .
 299+ ( $changeSet->getTime() > $lastViewed ? ' [NEW]' : '' ) .
289300 '</p>'
290301 ;
291302
@@ -333,7 +344,7 @@
334345 $lines[] = Html::element( 'div', array( 'class' => 'swl-watchlist-deletions' ), wfMsg( 'swl-watchlist-deletions' ) ) . ' ' . implode( ', ', $deletions );
335346 }
336347
337 - $html = Html::element( 'b', array(), $property->getLabel() );
 348+ $html = Html::element( 'span', array( 'class' => 'swl-watchlist-prop' ), $property->getLabel() );
338349
339350 $html .= Html::rawElement(
340351 'div',
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
@@ -156,7 +156,7 @@
157157 */
158158 public function __construct( SMWChangeSet $changeSet, /* User */ $user = null, $time = null, $id = null ) {
159159 $this->changeSet = $changeSet;
160 - $this->time = $time;
 160+ $this->time = is_null( $time ) ? wfTimestampNow() : $time;
161161 $this->user = is_null( $user ) ? $GLOBALS['wgUser'] : $user;
162162 $this->id = $id;
163163 }
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
@@ -39,6 +39,10 @@
4040 'swl-watchlist-pagincontrol' => 'View ($1) ($2)',
4141 'swl-watchlist-firstn' => 'First $1',
4242 'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}',
 43+
 44+ // Email
 45+ 'swl-email-propschanged' => 'Properties have changed',
 46+ 'swl-email-propschanged' => 'Properties have changed',
4347 );
4448
4549 /** German (Deutsch)
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -40,8 +40,7 @@
4141 }
4242
4343 /**
44 - * Determines and returns if the specified watchlist group covers
45 - * the provided page or not.
 44+ * Handles group notification.
4645 *
4746 * @since 0.1
4847 *
@@ -52,17 +51,42 @@
5352 * @return true
5453 */
5554 public static function onGroupNotify( SWLGroup $group, array $userIDs, SWLChangeSet $changes ) {
56 -
5755 foreach ( $userIDs as $userID ) {
58 - self::notifyUser( $group, User::newFromId( $userID ), $changes );
 56+ $user = User::newFromId( $userID );
 57+
 58+ if ( Sanitizer::validateEmail( $user->getEmail() ) ) {
 59+ $lastNotify = $user->getOption( 'swl_last_notify' );
 60+ $lastWatch = $user->getOption( 'swl_last_watch' );
 61+
 62+ if ( is_null( $lastNotify ) || is_null( $lastWatch ) || $lastNotify < $lastWatch ) {
 63+ self::notifyUser( $group, $user, $changes );
 64+ $user->setOption( 'swl_last_notify', wfTimestampNow() );
 65+ $user->saveSettings();
 66+ }
 67+ }
5968 }
6069
6170 return true;
6271 }
6372
 73+ /**
 74+ * Notifies a single user of the changes made to properties in a single edit.
 75+ *
 76+ * @param SWLGroup $group
 77+ * @param User $user
 78+ * @param SWLChangeSet $changes
 79+ *
 80+ * @return Status
 81+ */
6482 protected static function notifyUser( SWLGroup $group, User $user, SWLChangeSet $changes ) {
 83+ $emailText = '';
 84+
6585 // TODO
66 - //var_dump($group);var_dump($user);var_dump($changes);exit;
 86+
 87+ return $user->sendMail(
 88+ wfMsgReal( 'swl-email-propschanged', array(), true, $user->getOption( 'language' ) ),
 89+ $emailText
 90+ );
6791 }
6892
6993 /**

Status & tagging log