Index: trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php |
— | — | @@ -0,0 +1,118 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Static class holding functions for sending emails. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SWL_Emailer.php |
| 10 | + * @ingroup SemanticWatchlist |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +final class SWLEmailer { |
| 16 | + |
| 17 | + /** |
| 18 | + * Notifies a single user of the changes made to properties in a single edit. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * |
| 22 | + * @param SWLGroup $group |
| 23 | + * @param User $user |
| 24 | + * @param SWLChangeSet $changeSet |
| 25 | + * |
| 26 | + * @return Status |
| 27 | + */ |
| 28 | + public static function notifyUser( SWLGroup $group, User $user, SWLChangeSet $changeSet ) { |
| 29 | + $emailText = wfMsgExt( |
| 30 | + 'swl-email-propschanged-long', |
| 31 | + 'parse', |
| 32 | + $GLOBALS['wgSitename'], |
| 33 | + $changeSet->getUser()->getName(), |
| 34 | + SpecialPage::getTitleFor( 'SemanticWatchlist' )->getFullURL(), |
| 35 | + $GLOBALS['wgLang']->timeanddate( $changeSet->getTime() ) |
| 36 | + ); |
| 37 | + |
| 38 | + $emailText .= '<h3> ' . wfMsgExt( |
| 39 | + 'swl-email-changes', |
| 40 | + 'parse', |
| 41 | + $changeSet->getTitle()->getFullText(), |
| 42 | + $changeSet->getTitle()->getFullURL() |
| 43 | + ) . ' </h3>'; |
| 44 | + |
| 45 | + $emailText .= self::getChangeListHTML( $changeSet ); |
| 46 | + |
| 47 | + //echo $emailText;exit; |
| 48 | + |
| 49 | + return $user->sendMail( |
| 50 | + wfMsgReal( 'swl-email-propschanged', array(), true, $user->getOption( 'language' ) ), |
| 51 | + $emailText |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Creates and returns the HTML representatation of the change set. |
| 57 | + * |
| 58 | + * @since 0.1 |
| 59 | + * |
| 60 | + * @param SWLChangeSet $changeSet |
| 61 | + * |
| 62 | + * @return string |
| 63 | + */ |
| 64 | + protected static function getChangeListHTML( SWLChangeSet $changeSet ) { |
| 65 | + $propertyHTML = array(); |
| 66 | + |
| 67 | + foreach ( $changeSet->getAllProperties() as /* SMWDIProperty */ $property ) { |
| 68 | + $propertyHTML[] = self::getPropertyHTML( $property, $changeSet->getAllPropertyChanges( $property ) ); |
| 69 | + } |
| 70 | + |
| 71 | + return implode( '', $propertyHTML ); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Creates and returns the HTML representatation of the property and it's changes. |
| 76 | + * |
| 77 | + * @since 0.1 |
| 78 | + * |
| 79 | + * @param SMWDIProperty $property |
| 80 | + * @param array $changes |
| 81 | + * |
| 82 | + * @return string |
| 83 | + */ |
| 84 | + protected static function getPropertyHTML( SMWDIProperty $property, array $changes ) { |
| 85 | + $insertions = array(); |
| 86 | + $deletions = array(); |
| 87 | + |
| 88 | + // Convert the changes into a list of insertions and a list of deletions. |
| 89 | + foreach ( $changes as /* SMWPropertyChange */ $change ) { |
| 90 | + if ( !is_null( $change->getOldValue() ) ) { |
| 91 | + $deletions[] = SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property )->getShortHTMLText(); |
| 92 | + } |
| 93 | + if ( !is_null( $change->getNewValue() ) ) { |
| 94 | + $insertions[] = SMWDataValueFactory::newDataItemValue( $change->getNewValue(), $property )->getShortHTMLText(); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + $lines = array(); |
| 99 | + |
| 100 | + if ( count( $insertions ) > 0 ) { |
| 101 | + $lines[] = Html::element( 'span', array(), wfMsg( 'swl-watchlist-insertions' ) ) . ' ' . implode( ', ', $insertions ); |
| 102 | + } |
| 103 | + |
| 104 | + if ( count( $deletions ) > 0 ) { |
| 105 | + $lines[] = Html::element( 'span', array(), wfMsg( 'swl-watchlist-deletions' ) ) . ' ' . implode( ', ', $deletions ); |
| 106 | + } |
| 107 | + |
| 108 | + $html = Html::element( 'b', array(), $property->getLabel() ); |
| 109 | + |
| 110 | + $html .= Html::rawElement( |
| 111 | + 'div', |
| 112 | + array( 'class' => 'swl-prop-div' ), |
| 113 | + implode( '<br />', $lines ) |
| 114 | + ); |
| 115 | + |
| 116 | + return $html; |
| 117 | + } |
| 118 | + |
| 119 | +} |
Property changes on: trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 120 | + native |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php |
— | — | @@ -41,8 +41,9 @@ |
42 | 42 | 'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}', |
43 | 43 | |
44 | 44 | // Email |
45 | | - 'swl-email-propschanged' => 'Properties have changed', |
46 | | - 'swl-email-propschanged' => 'Properties have changed', |
| 45 | + 'swl-email-propschanged' => 'Properties have changed at $1', |
| 46 | + '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].", |
| 47 | + 'swl-email-changes' => 'Property changes on [$2 $1]:', |
47 | 48 | ); |
48 | 49 | |
49 | 50 | /** German (Deutsch) |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php |
— | — | @@ -61,9 +61,7 @@ |
62 | 62 | $wgAutoloadClasses['ApiSemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiSemanticWatchlist.php'; |
63 | 63 | |
64 | 64 | $wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php'; |
65 | | -$wgAutoloadClasses['SWLChange'] = dirname( __FILE__ ) . '/includes/SWL_Change.php'; |
66 | | -$wgAutoloadClasses['SWLChanges'] = dirname( __FILE__ ) . '/includes/SWL_Changes.php'; |
67 | | -$wgAutoloadClasses['SWLChangeSet'] = dirname( __FILE__ ) . '/includes/SWL_ChangeSet.php'; |
| 65 | +$wgAutoloadClasses['SWLEmailer'] = dirname( __FILE__ ) . '/includes/SWL_Emailer.php'; |
68 | 66 | $wgAutoloadClasses['SWLGroup'] = dirname( __FILE__ ) . '/includes/SWL_Group.php'; |
69 | 67 | $wgAutoloadClasses['SWLGroups'] = dirname( __FILE__ ) . '/includes/SWL_Groups.php'; |
70 | 68 | |
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php |
— | — | @@ -59,7 +59,7 @@ |
60 | 60 | $lastWatch = $user->getOption( 'swl_last_watch' ); |
61 | 61 | |
62 | 62 | if ( is_null( $lastNotify ) || is_null( $lastWatch ) || $lastNotify < $lastWatch ) { |
63 | | - self::notifyUser( $group, $user, $changes ); |
| 63 | + SWLEmailer::notifyUser( $group, $user, $changes ); |
64 | 64 | $user->setOption( 'swl_last_notify', wfTimestampNow() ); |
65 | 65 | $user->saveSettings(); |
66 | 66 | } |
— | — | @@ -68,26 +68,6 @@ |
69 | 69 | |
70 | 70 | return true; |
71 | 71 | } |
72 | | - |
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 | | - */ |
82 | | - protected static function notifyUser( SWLGroup $group, User $user, SWLChangeSet $changes ) { |
83 | | - $emailText = ''; |
84 | | - |
85 | | - // TODO |
86 | | - |
87 | | - return $user->sendMail( |
88 | | - wfMsgReal( 'swl-email-propschanged', array(), true, $user->getOption( 'language' ) ), |
89 | | - $emailText |
90 | | - ); |
91 | | - } |
92 | 72 | |
93 | 73 | /** |
94 | 74 | * Schema update to set up the needed database tables. |