http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88375

Revision: 88375
Author:   jeroendedauw
Date:     2011-05-18 17:53:36 +0000 (Wed, 18 May 2011)
Log Message:
-----------
some work on email notification limit

Modified Paths:
--------------
    trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
    trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php
    trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php      
2011-05-18 17:40:24 UTC (rev 88374)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php      
2011-05-18 17:53:36 UTC (rev 88375)
@@ -59,9 +59,14 @@
                                $lastWatch = $user->getOption( 'swl_last_watch' 
);
                
                        if ( is_null( $lastNotify ) || is_null( $lastWatch ) || 
$lastNotify < $lastWatch ) {
-                               SWLEmailer::notifyUser( $group, $user, $changes 
);
-                               $user->setOption( 'swl_last_notify', 
wfTimestampNow() );
-                               $user->saveSettings();
+                               $mailCount = $user->getOption( 
'swl_mail_count', 0 );
+                               
+                               if ( $mailCount < $egSWLMaxMails ) {
+                                       SWLEmailer::notifyUser( $group, $user, 
$changes );
+                                       $user->setOption( 'swl_last_notify', 
wfTimestampNow() );
+                                       $user->setOption( 'swl_mail_count', 
$mailCount + 1 );
+                                       $user->saveSettings();                  
                
+                               }
                        }                       
                }
        }

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php   
2011-05-18 17:40:24 UTC (rev 88374)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.settings.php   
2011-05-18 17:53:36 UTC (rev 88375)
@@ -35,3 +35,6 @@
 
 # Enable email notification or not?
 $egSWLEnableEmailNotify = true;
+
+# The maximum amount of emails to send about changes untill the user actually 
checks his semantic watchlist.
+$egSWLMaxMails = 1;

Modified: 
trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php    
2011-05-18 17:40:24 UTC (rev 88374)
+++ trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php    
2011-05-18 17:53:36 UTC (rev 88375)
@@ -14,6 +14,15 @@
 class SpecialSemanticWatchlist extends SpecialPage {
        
        /**
+        * MediaWiki timestamp of when the watchlist was last viewed by the 
current user.
+        * 
+        * @since 0.1
+        * 
+        * @var integer
+        */
+       protected $lastViewed;
+       
+       /**
         * Constructor.
         * 
         * @since 0.1
@@ -62,6 +71,8 @@
                        return;
                }
                
+               $this->registerUserView( $wgUser );
+               
                $limit = $wgRequest->getInt( 'limit', 20 );
                $offset = $wgRequest->getInt( 'offset', 0 );
                $continue = $wgRequest->getVal( 'continue' );
@@ -93,8 +104,29 @@
        }
        
        /**
+        * Register the user viewed the watchlist,
+        * so we know that following chnages should
+        * result into notification emails is desired.
+        * 
         * @since 0.1
         * 
+        * @param User $user
+        */
+       protected function registerUserView( User $user ) {
+               $this->lastViewed = $user->getOption( 'swl_last_view' );
+               
+               if ( is_null( $this->lastViewed ) ) {
+                       $this->lastViewed = wfTimestampNow();
+               }
+               
+               $user->setOption( 'swl_last_view', wfTimestampNow() );
+               $user->setOption( 'swl_mail_count',0 );
+               $user->saveSettings();          
+       }
+       
+       /**
+        * @since 0.1
+        * 
         * @return string
         */
        protected function getPagingControlHTML( $limit, $currentContinue, 
$subPage, $newContinue, $offset ) {
@@ -172,17 +204,8 @@
         * @param array of SWLChangeSet $sets
         */
        protected function displayWatchlist( array $sets ) {
-               global $wgOut, $wgLang, $wgUser;
+               global $wgOut, $wgLang;
                
-               $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 ) {
@@ -192,7 +215,7 @@
                                $changeSetsHTML[$dayKey] = array();
                        }
                        
-                       $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( 
$set, $lastViewed );
+                       $changeSetsHTML[$dayKey][] = $this->getChangeSetHTML( 
$set );
                }
                
                krsort( $changeSetsHTML );
@@ -249,11 +272,10 @@
         * @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, 
$lastViewed ) {
+       protected function getChangeSetHTML( SWLChangeSet $changeSet ) {
                global $wgLang;
                
                $html = '';
@@ -295,7 +317,7 @@
                                        array( 'href' => 
SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() 
)->getLocalURL() ),
                                        wfMsg( 'blocklink' )
                                ) . ')' .
-                               ( $changeSet->getTime() > $lastViewed ? ' 
[NEW]' : '' ) .
+                               ( $changeSet->getTime() > $this->lastViewed ? ' 
[NEW]' : '' )   .
                        '</p>'
                ;
                


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to