http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88370
Revision: 88370
Author: jeroendedauw
Date: 2011-05-18 16:58:52 +0000 (Wed, 18 May 2011)
Log Message:
-----------
work on email notification and tweaks to special:semanticwatchlist
Modified Paths:
--------------
trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
2011-05-18 14:30:12 UTC (rev 88369)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
2011-05-18 16:58:52 UTC (rev 88370)
@@ -40,8 +40,7 @@
}
/**
- * Determines and returns if the specified watchlist group covers
- * the provided page or not.
+ * Handles group notification.
*
* @since 0.1
*
@@ -52,17 +51,42 @@
* @return true
*/
public static function onGroupNotify( SWLGroup $group, array $userIDs,
SWLChangeSet $changes ) {
-
foreach ( $userIDs as $userID ) {
- self::notifyUser( $group, User::newFromId( $userID ), $changes
);
+ $user = User::newFromId( $userID );
+
+ if ( Sanitizer::validateEmail( $user->getEmail() ) ) {
+ $lastNotify = $user->getOption(
'swl_last_notify' );
+ $lastWatch = $user->getOption( 'swl_last_watch'
);
+
+ if ( is_null( $lastNotify ) || is_null( $lastWatch ) ||
$lastNotify < $lastWatch ) {
+ self::notifyUser( $group, $user, $changes );
+ $user->setOption( 'swl_last_notify',
wfTimestampNow() );
+ $user->saveSettings();
+ }
+ }
}
return true;
}
+ /**
+ * Notifies a single user of the changes made to properties in a single
edit.
+ *
+ * @param SWLGroup $group
+ * @param User $user
+ * @param SWLChangeSet $changes
+ *
+ * @return Status
+ */
protected static function notifyUser( SWLGroup $group, User $user,
SWLChangeSet $changes ) {
+ $emailText = '';
+
// TODO
- //var_dump($group);var_dump($user);var_dump($changes);exit;
+
+ return $user->sendMail(
+ wfMsgReal( 'swl-email-propschanged', array(), true,
$user->getOption( 'language' ) ),
+ $emailText
+ );
}
/**
Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
2011-05-18 14:30:12 UTC (rev 88369)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
2011-05-18 16:58:52 UTC (rev 88370)
@@ -39,6 +39,10 @@
'swl-watchlist-pagincontrol' => 'View ($1) ($2)',
'swl-watchlist-firstn' => 'First $1',
'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}',
+
+ // Email
+ 'swl-email-propschanged' => 'Properties have changed',
+ 'swl-email-propschanged' => 'Properties have changed',
);
/** German (Deutsch)
Modified: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-18 14:30:12 UTC (rev 88369)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
2011-05-18 16:58:52 UTC (rev 88370)
@@ -156,7 +156,7 @@
*/
public function __construct( SMWChangeSet $changeSet, /* User */ $user
= null, $time = null, $id = null ) {
$this->changeSet = $changeSet;
- $this->time = $time;
+ $this->time = is_null( $time ) ? wfTimestampNow() : $time;
$this->user = is_null( $user ) ? $GLOBALS['wgUser'] : $user;
$this->id = $id;
}
Modified:
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-18 14:30:12 UTC (rev 88369)
+++ trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
2011-05-18 16:58:52 UTC (rev 88370)
@@ -172,8 +172,17 @@
* @param array of SWLChangeSet $sets
*/
protected function displayWatchlist( array $sets ) {
- global $wgOut, $wgLang;
+ global $wgOut, $wgLang, $wgUser;
+ $lastViewed = $wgUser->getOption( 'swl_last_view' );
+
+ if ( is_null( $lastViewed ) ) {
+ $lastViewed = wfTimestampNow();
+ }
+
+ $wgUser->setOption( 'swl_last_view', wfTimestampNow() );
+ $wgUser->saveSettings();
+
$changeSetsHTML = array();
foreach ( $sets as $set ) {
@@ -183,7 +192,7 @@
$changeSetsHTML[$dayKey] = array();
}
- $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML(
$set );
+ $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML(
$set, $lastViewed );
}
krsort( $changeSetsHTML );
@@ -240,10 +249,11 @@
* @since 0.1
*
* @param SWLChangeSet $changeSet
+ * @param integer $lastViewed The MW timestamp of when the user last
viewed the watchlist
*
* @return string
*/
- protected function getChangeSetHTML( SWLChangeSet $changeSet ) {
+ protected function getChangeSetHTML( SWLChangeSet $changeSet,
$lastViewed ) {
global $wgLang;
$html = '';
@@ -284,7 +294,8 @@
'a',
array( 'href' =>
SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName()
)->getLocalURL() ),
wfMsg( 'blocklink' )
- ) . ')' .
+ ) . ')' .
+ ( $changeSet->getTime() > $lastViewed ? '
[NEW]' : '' ) .
'</p>'
;
@@ -333,7 +344,7 @@
$lines[] = Html::element( 'div', array( 'class' =>
'swl-watchlist-deletions' ), wfMsg( 'swl-watchlist-deletions' ) ) . ' ' .
implode( ', ', $deletions );
}
- $html = Html::element( 'b', array(), $property->getLabel() );
+ $html = Html::element( 'span', array( 'class' =>
'swl-watchlist-prop' ), $property->getLabel() );
$html .= Html::rawElement(
'div',
Modified: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css
2011-05-18 14:30:12 UTC (rev 88369)
+++ trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css
2011-05-18 16:58:52 UTC (rev 88370)
@@ -10,4 +10,8 @@
.swl-watchlist-deletions {
display: inline;
+}
+
+.swl-watchlist-prop {
+
}
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs