1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Notifications\ChangeNotification; |
4
|
|
|
|
5
|
|
|
use EchoEvent; |
6
|
|
|
use EchoEventPresentationModel; |
7
|
|
|
use Title; |
8
|
|
|
use SMW\DIProperty; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class ChangeNotificationPresentationModel extends EchoEventPresentationModel { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see EchoEventPresentationModel::getIconType |
20
|
|
|
*/ |
21
|
4 |
|
public function getIconType() { |
22
|
|
|
|
23
|
4 |
|
if ( $this->event->getType() !== ChangeNotificationFilter::SPECIFICATION_CHANGE ) { |
24
|
1 |
|
return $this->event->getType(); |
25
|
|
|
} |
26
|
|
|
|
27
|
3 |
|
$namespace = $this->event->getTitle()->getNamespace(); |
28
|
|
|
|
29
|
|
|
// @see EchoNotificationsManager::addNotificationsDefinitions for the icons |
30
|
3 |
|
if ( $namespace === NS_CATEGORY || $namespace === SMW_NS_CONCEPT ) { |
31
|
2 |
|
return $this->event->getType() . '-category'; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
return $this->event->getType() . '-property'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @see EchoEventPresentationModel::canRender |
39
|
|
|
*/ |
40
|
1 |
|
public function canRender() { |
41
|
1 |
|
return (bool)$this->event->getTitle(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param EchoEvent |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
2 |
|
public function callbackForBundleCount( EchoEvent $event ) { |
49
|
2 |
|
return $event->getTitle()->getPrefixedText(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @see EchoEventPresentationModel::getHeaderMessageKey |
54
|
|
|
*/ |
55
|
2 |
|
public function getHeaderMessageKey() { |
56
|
|
|
|
57
|
2 |
|
if ( $this->getBundleCount( true, [ $this, 'callbackForBundleCount' ] ) > 1 ) { |
58
|
|
|
return "notification-bundle-header-{$this->type}"; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
return "notification-header-{$this->type}"; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @see EchoEventPresentationModel::getHeaderMessage |
66
|
|
|
*/ |
67
|
1 |
|
public function getHeaderMessage() { |
68
|
|
|
|
69
|
1 |
|
$extra = $this->event->getExtra(); |
70
|
1 |
|
$msg = parent::getHeaderMessage(); |
71
|
|
|
|
72
|
1 |
|
$msg->params( |
73
|
1 |
|
$this->getTruncatedTitleText( $this->event->getTitle(), true ) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
// Plural indicator |
77
|
1 |
|
$msg->params( |
78
|
1 |
|
( isset( $extra['properties'] ) ? count( $extra['properties'] ) : 0 ) |
79
|
|
|
); |
80
|
|
|
|
81
|
1 |
|
$count = $this->getNotificationCountForOutput( |
82
|
1 |
|
false, // we need only other pages count |
83
|
1 |
|
[ $this, 'callbackForBundleCount' ] |
84
|
|
|
); |
85
|
|
|
|
86
|
1 |
|
if ( $count > 0 ) { |
87
|
|
|
$msg->numParams( $count ); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
return $msg; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @see EchoEventPresentationModel::getBodyMessage |
95
|
|
|
*/ |
96
|
5 |
|
public function getBodyMessage() { |
97
|
|
|
|
98
|
5 |
|
$extra = $this->event->getExtra(); |
99
|
5 |
|
$labels = array(); |
100
|
|
|
|
101
|
5 |
|
if ( !isset( $extra['properties'] ) || $extra['properties'] === array() ) { |
102
|
3 |
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
foreach ( $extra['properties'] as $dataItem ) { |
106
|
|
|
|
107
|
2 |
|
$prefix = ''; |
108
|
|
|
|
109
|
2 |
|
if ( $dataItem->getDBKey() === '' ) { |
110
|
1 |
|
continue; |
111
|
|
|
} |
112
|
|
|
|
113
|
2 |
|
if ( $dataItem->getNamespace() === NS_CATEGORY ) { |
114
|
|
|
$prefix = $this->language->getNsText( NS_CATEGORY ) . ':'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
try { |
118
|
2 |
|
$labels[] = $prefix . DIProperty::newFromUserLabel( $dataItem->getDBKey() )->getLabel(); |
119
|
|
|
} catch ( \SMW\Exception\PredefinedPropertyLabelMismatchException $e ) { |
120
|
|
|
continue; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
$msg = wfMessage( "notification-body-{$this->type}" ); |
125
|
2 |
|
$msg->params( $this->language->listToText( $labels ) ); |
126
|
2 |
|
$msg->params( count( $labels ) ); |
127
|
|
|
|
128
|
2 |
|
return $msg; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @see EchoEventPresentationModel::getPrimaryLink |
133
|
|
|
*/ |
134
|
3 |
|
public function getPrimaryLink() { |
135
|
3 |
|
$title = $this->event->getTitle(); |
136
|
|
|
return array( |
137
|
3 |
|
'url' => $title->getFullURL(), |
138
|
3 |
|
'label' => $title->getFullText() |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @see EchoEventPresentationModel::getSecondaryLinks |
144
|
|
|
*/ |
145
|
3 |
|
public function getSecondaryLinks() { |
146
|
|
|
|
147
|
3 |
|
$extra = $this->event->getExtra(); |
|
|
|
|
148
|
3 |
|
$title = $this->event->getTitle(); |
149
|
|
|
|
150
|
3 |
|
$queryParameters['oldid'] = 'prev'; |
|
|
|
|
151
|
|
|
|
152
|
3 |
|
if ( $this->event->getExtraParam( 'revid' ) > 0 ) { |
153
|
3 |
|
$queryParameters['diff'] = $this->event->getExtraParam( 'revid' ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
$viewChangesLink = array( |
157
|
3 |
|
'url' => $title->getLocalURL( $queryParameters ), |
158
|
3 |
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(), |
159
|
3 |
|
'description' => '', |
160
|
3 |
|
'icon' => 'changes', |
161
|
|
|
'prioritized' => true, |
162
|
|
|
); |
163
|
|
|
|
164
|
3 |
|
return array( $this->getAgentLink(), $viewChangesLink ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
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.