r88374 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88373‎ | r88374 | r88375 >
Date:17:40, 18 May 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
work on email stuff
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Emailer.php (added) (history)

Diff [purge]

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
1120 + native
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
@@ -41,8 +41,9 @@
4242 'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}',
4343
4444 // 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]:',
4748 );
4849
4950 /** German (Deutsch)
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
@@ -61,9 +61,7 @@
6262 $wgAutoloadClasses['ApiSemanticWatchlist'] = dirname( __FILE__ ) . '/api/ApiSemanticWatchlist.php';
6363
6464 $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';
6866 $wgAutoloadClasses['SWLGroup'] = dirname( __FILE__ ) . '/includes/SWL_Group.php';
6967 $wgAutoloadClasses['SWLGroups'] = dirname( __FILE__ ) . '/includes/SWL_Groups.php';
7068
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.hooks.php
@@ -59,7 +59,7 @@
6060 $lastWatch = $user->getOption( 'swl_last_watch' );
6161
6262 if ( is_null( $lastNotify ) || is_null( $lastWatch ) || $lastNotify < $lastWatch ) {
63 - self::notifyUser( $group, $user, $changes );
 63+ SWLEmailer::notifyUser( $group, $user, $changes );
6464 $user->setOption( 'swl_last_notify', wfTimestampNow() );
6565 $user->saveSettings();
6666 }
@@ -68,26 +68,6 @@
6969
7070 return true;
7171 }
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 - }
9272
9373 /**
9474 * Schema update to set up the needed database tables.

Follow-up revisions

RevisionCommit summaryAuthorDate
r88409follow up to r88374, added message docs and split date/time as per request by...jeroendedauw15:11, 19 May 2011

Comments

#Comment by Jeroen De Dauw (talk | contribs)   15:12, 19 May 2011

Should be fixed in follow up

Status & tagging log