1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Static class holding functions for sending emails. |
5
|
|
|
* |
6
|
|
|
* @since 0.1 |
7
|
|
|
* |
8
|
|
|
* @file SWL_Emailer.php |
9
|
|
|
* @ingroup SemanticWatchlist |
10
|
|
|
* |
11
|
|
|
* @licence GNU GPL v3 or later |
12
|
|
|
* @author Jeroen De Dauw < [email protected] > |
13
|
|
|
*/ |
14
|
|
|
final class SWLEmailer { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Notifies a single user of the changes made to properties in a single edit. |
18
|
|
|
* |
19
|
|
|
* @since 0.1 |
20
|
|
|
* |
21
|
|
|
* @param SWLGroup $group |
22
|
|
|
* @param User $user |
23
|
|
|
* @param SWLChangeSet $changeSet |
24
|
|
|
* @param boolean $describeChanges |
25
|
|
|
* |
26
|
|
|
* @return Status |
27
|
|
|
*/ |
28
|
|
|
public static function notifyUser( SWLGroup $group, User $user, SWLChangeSet $changeSet, $describeChanges ) { |
29
|
|
|
global $wgLang, $wgPasswordSender, $wgPasswordSenderName; |
30
|
|
|
|
31
|
|
|
$emailText = wfMessage( |
32
|
|
|
'swl-email-propschanged-long', |
33
|
|
|
$GLOBALS['wgSitename'], |
34
|
|
|
$changeSet->getEdit()->getUser()->getName(), |
35
|
|
|
SpecialPage::getTitleFor( 'SemanticWatchlist' )->getFullURL(), |
36
|
|
|
$wgLang->time( $changeSet->getEdit()->getTime() ), |
37
|
|
|
$wgLang->date( $changeSet->getEdit()->getTime() ) |
38
|
|
|
)->parseAsBlock(); |
39
|
|
|
|
40
|
|
|
if ( $describeChanges ) { |
41
|
|
|
$emailText .= Html::rawElement( 'h3', array(), wfMessage( |
42
|
|
|
'swl-email-changes', |
43
|
|
|
$changeSet->getEdit()->getTitle()->getFullText(), |
44
|
|
|
$changeSet->getEdit()->getTitle()->getFullURL() |
45
|
|
|
)->parseAsBlock() ); |
46
|
|
|
|
47
|
|
|
$emailText .= self::getChangeListHTML( $changeSet, $group ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$title = wfMessage( 'swl-email-propschanged', array( $changeSet->getEdit()->getTitle()->getFullText() ) )->text(); |
51
|
|
|
|
52
|
|
|
wfRunHooks( 'SWLBeforeEmailNotify', array( $group, $user, $changeSet, $describeChanges, &$title, &$emailText ) ); |
53
|
|
|
|
54
|
|
|
if ( version_compare( $GLOBALS['wgVersion'], '1.27', '<' ) ) { |
55
|
|
|
return UserMailer::send( |
56
|
|
|
new MailAddress( $user ), |
57
|
|
|
new MailAddress( $wgPasswordSender, $wgPasswordSenderName ), |
58
|
|
|
$title, |
59
|
|
|
$emailText, |
60
|
|
|
null, |
61
|
|
|
'text/html; charset=ISO-8859-1' |
62
|
|
|
); |
63
|
|
|
} else { |
64
|
|
|
return UserMailer::send( |
65
|
|
|
new MailAddress( $user ), |
66
|
|
|
new MailAddress( $wgPasswordSender, $wgPasswordSenderName ), |
67
|
|
|
$title, |
68
|
|
|
$emailText, |
69
|
|
|
array( 'contentType' => 'text/html; charset=ISO-8859-1' ) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Creates and returns the HTML representation of the change set. |
76
|
|
|
* |
77
|
|
|
* @since 0.1 |
78
|
|
|
* |
79
|
|
|
* @param SWLChangeSet $changeSet |
80
|
|
|
* @param SWLGroup $group |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
private static function getChangeListHTML( SWLChangeSet $changeSet, SWLGroup $group ) { |
85
|
|
|
$propertyHTML = array(); |
86
|
|
|
$customTexts = new SWLCustomTexts( $group ); |
87
|
|
|
foreach ( $changeSet->getAllProperties() as /* SMWDIProperty */ $property ) { |
88
|
|
|
$propertyHTML[] = self::getPropertyHTML( $property, $changeSet->getAllPropertyChanges( $property ), $customTexts ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return implode( '', $propertyHTML ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Creates and returns the HTML representation of the property and it's changes. |
96
|
|
|
* |
97
|
|
|
* @since 0.1 |
98
|
|
|
* |
99
|
|
|
* @param SMWDIProperty $property |
100
|
|
|
* @param array $changes |
101
|
|
|
* @param SWLCustomTexts $customTexts |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
private static function getPropertyHTML( SMWDIProperty $property, array $changes, $customTexts ) { |
105
|
|
|
$insertions = array(); |
106
|
|
|
$deletions = array(); |
107
|
|
|
$customMessages = array(); |
108
|
|
|
$justCustomMessage = false; |
|
|
|
|
109
|
|
|
|
110
|
|
|
// Convert the changes into a list of insertions and a list of deletions. |
111
|
|
|
foreach ( $changes as /* SWLPropertyChange */ $change ) { |
112
|
|
|
$justCustomMessage = false; |
113
|
|
|
if ( !is_null( $change->getNewValue() ) && $customTexts->getPropertyCustomText( $property, $change->getNewValue()->getSerialization() ) ) { |
114
|
|
|
$customMessages[] = $customTexts->getPropertyCustomText( $property, $change->getNewValue()->getSerialization() ); |
115
|
|
|
$justCustomMessage = true; |
116
|
|
|
} |
117
|
|
|
if( !$justCustomMessage ) { |
118
|
|
|
if ( !is_null( $change->getOldValue() ) ) { |
119
|
|
|
$deletions[] = SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property )->getShortHTMLText(); |
120
|
|
|
} |
121
|
|
|
if ( !is_null( $change->getNewValue() ) ) { |
122
|
|
|
$insertions[] = SMWDataValueFactory::newDataItemValue( $change->getNewValue(), $property )->getShortHTMLText(); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$lines = array(); |
128
|
|
|
|
129
|
|
|
if ( count( $insertions ) > 0 ) { |
130
|
|
|
$lines[] = Html::element( 'span', array(), wfMessage( 'swl-watchlist-insertions' )->text() ) . ' ' . implode( ', ', $insertions ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if ( count( $deletions ) > 0 ) { |
134
|
|
|
$lines[] = Html::element( 'span', array(), wfMessage( 'swl-watchlist-deletions' )->text() ) . ' ' . implode( ', ', $deletions ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
foreach( $customMessages as $customMessage ) { |
138
|
|
|
$lines[] = Html::element( 'span', array(), $customMessage ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$html = Html::element( 'b', array(), $property->getLabel() ); |
142
|
|
|
|
143
|
|
|
$html .= Html::rawElement( |
144
|
|
|
'div', |
145
|
|
|
array( 'class' => 'swl-prop-div' ), |
146
|
|
|
implode( '<br />', $lines ) |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
return $html; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.