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

Revision: 88374
Author:   jeroendedauw
Date:     2011-05-18 17:40:24 +0000 (Wed, 18 May 2011)
Log Message:
-----------
work on email stuff

Modified Paths:
--------------
    trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
    trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
    trunk/extensions/SemanticWatchlist/SemanticWatchlist.php

Added Paths:
-----------
    trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php      
2011-05-18 17:31:35 UTC (rev 88373)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php      
2011-05-18 17:40:24 UTC (rev 88374)
@@ -59,7 +59,7 @@
                                $lastWatch = $user->getOption( 'swl_last_watch' 
);
                
                        if ( is_null( $lastNotify ) || is_null( $lastWatch ) || 
$lastNotify < $lastWatch ) {
-                               self::notifyUser( $group, $user, $changes );
+                               SWLEmailer::notifyUser( $group, $user, $changes 
);
                                $user->setOption( 'swl_last_notify', 
wfTimestampNow() );
                                $user->saveSettings();
                        }                       
@@ -68,26 +68,6 @@
        
         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
-       
-       return $user->sendMail(
-               wfMsgReal( 'swl-email-propschanged', array(), true, 
$user->getOption( 'language' ) ),
-               $emailText
-       );
-    }
 
        /**
         * Schema update to set up the needed database tables.

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php       
2011-05-18 17:31:35 UTC (rev 88373)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php       
2011-05-18 17:40:24 UTC (rev 88374)
@@ -41,8 +41,9 @@
        'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}',
 
        // Email
-       'swl-email-propschanged' => 'Properties have changed',
-       'swl-email-propschanged' => 'Properties have changed',
+       'swl-email-propschanged' => 'Properties have changed at $1',
+       'swl-email-propschanged-long' => "One or more properties you watch at 
'''$1''' have been changed by user '''$2''' at $4. You can view these and other 
changes on [$3 your semantic watchlist].",
+       'swl-email-changes' => 'Property changes on [$2 $1]:',
 );
 
 /** German (Deutsch)

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.php    2011-05-18 
17:31:35 UTC (rev 88373)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.php    2011-05-18 
17:40:24 UTC (rev 88374)
@@ -61,9 +61,7 @@
 $wgAutoloadClasses['ApiSemanticWatchlist']          = dirname( __FILE__ ) . 
'/api/ApiSemanticWatchlist.php';
 
 $wgAutoloadClasses['SWLChangeSet']                     = dirname( __FILE__ ) . 
'/includes/SWL_ChangeSet.php';
-$wgAutoloadClasses['SWLChange']                                = dirname( 
__FILE__ ) . '/includes/SWL_Change.php';
-$wgAutoloadClasses['SWLChanges']                               = dirname( 
__FILE__ ) . '/includes/SWL_Changes.php';
-$wgAutoloadClasses['SWLChangeSet']                     = dirname( __FILE__ ) . 
'/includes/SWL_ChangeSet.php';
+$wgAutoloadClasses['SWLEmailer']                               = dirname( 
__FILE__ ) . '/includes/SWL_Emailer.php';
 $wgAutoloadClasses['SWLGroup']                                 = dirname( 
__FILE__ ) . '/includes/SWL_Group.php';
 $wgAutoloadClasses['SWLGroups']                                = dirname( 
__FILE__ ) . '/includes/SWL_Groups.php';
 

Added: trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php
===================================================================
--- trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php                 
        (rev 0)
+++ trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php 2011-05-18 
17:40:24 UTC (rev 88374)
@@ -0,0 +1,118 @@
+<?php
+
+/**
+ * Static class holding functions for sending emails.
+ * 
+ * @since 0.1
+ * 
+ * @file SWL_Emailer.php
+ * @ingroup SemanticWatchlist
+ * 
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+final class SWLEmailer {
+       
+    /**
+     * Notifies a single user of the changes made to properties in a single 
edit.
+     * 
+     * @since 0.1
+     * 
+     * @param SWLGroup $group
+     * @param User $user
+     * @param SWLChangeSet $changeSet
+     * 
+     * @return Status
+     */
+    public static function notifyUser( SWLGroup $group, User $user, 
SWLChangeSet $changeSet ) {
+       $emailText = wfMsgExt(
+               'swl-email-propschanged-long',
+               'parse', 
+               $GLOBALS['wgSitename'],
+               $changeSet->getUser()->getName(),
+               SpecialPage::getTitleFor( 'SemanticWatchlist' )->getFullURL(),
+               $GLOBALS['wgLang']->timeanddate( $changeSet->getTime() )
+       );
+       
+       $emailText .= '<h3> ' . wfMsgExt(
+               'swl-email-changes',
+               'parse', 
+               $changeSet->getTitle()->getFullText(),
+               $changeSet->getTitle()->getFullURL()
+       ) . ' </h3>';
+       
+       $emailText .= self::getChangeListHTML( $changeSet );
+       
+       //echo $emailText;exit;
+       
+       return $user->sendMail(
+               wfMsgReal( 'swl-email-propschanged', array(), true, 
$user->getOption( 'language' ) ),
+               $emailText
+       );
+    }
+    
+    /**
+     * Creates and returns the HTML representatation of the change set.
+     * 
+     * @since 0.1
+     * 
+     * @param SWLChangeSet $changeSet
+     * 
+     * @return string
+     */
+    protected static function getChangeListHTML( SWLChangeSet $changeSet ) {
+       $propertyHTML = array();
+       
+       foreach ( $changeSet->getAllProperties() as /* SMWDIProperty */ 
$property ) {
+               $propertyHTML[] = self::getPropertyHTML( $property, 
$changeSet->getAllPropertyChanges( $property ) );
+       }
+       
+       return implode( '', $propertyHTML );
+    }
+    
+    /**
+     * Creates and returns the HTML representatation of the property and it's 
changes.
+     * 
+     * @since 0.1
+     * 
+     * @param SMWDIProperty $property
+     * @param array $changes
+     * 
+     * @return string
+     */
+    protected static function getPropertyHTML( SMWDIProperty $property, array 
$changes ) {
+               $insertions = array();
+               $deletions = array();
+               
+               // Convert the changes into a list of insertions and a list of 
deletions.
+               foreach ( $changes as /* SMWPropertyChange */ $change ) {
+                       if ( !is_null( $change->getOldValue() ) ) {
+                               $deletions[] = 
SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property 
)->getShortHTMLText();
+                       }
+                       if ( !is_null( $change->getNewValue() ) ) {
+                               $insertions[] = 
SMWDataValueFactory::newDataItemValue( $change->getNewValue(), $property 
)->getShortHTMLText();
+                       }
+               }
+               
+               $lines = array();
+               
+               if ( count( $insertions ) > 0 ) {
+                       $lines[] = Html::element( 'span', array(), wfMsg( 
'swl-watchlist-insertions' ) ) . ' ' . implode( ', ', $insertions );
+               }
+               
+               if ( count( $deletions ) > 0 ) {
+                       $lines[] = Html::element( 'span', array(), wfMsg( 
'swl-watchlist-deletions' ) ) . ' ' . implode( ', ', $deletions );
+               }               
+               
+               $html = Html::element( 'b', array(), $property->getLabel() );
+               
+               $html .= Html::rawElement(
+                       'div',
+                       array( 'class' => 'swl-prop-div' ),
+                       implode( '<br />', $lines )
+               );
+               
+               return $html;           
+    }
+       
+}


Property changes on: trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php
___________________________________________________________________
Added: svn:eol-style
   + native


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

Reply via email to