|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SMW\Notifications\ValueChange; |
|
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() !== ChangeNotifications::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
|
1 |
|
); |
|
75
|
|
|
|
|
76
|
|
|
// Plural indicator |
|
77
|
1 |
|
$msg->params( |
|
78
|
1 |
|
( isset( $extra['properties'] ) ? count( $extra['properties'] ) : 0 ) |
|
79
|
1 |
|
); |
|
80
|
|
|
|
|
81
|
1 |
|
$count = $this->getNotificationCountForOutput( |
|
82
|
1 |
|
false, // we need only other pages count |
|
83
|
1 |
|
[ $this, 'callbackForBundleCount' ] |
|
84
|
1 |
|
); |
|
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
|
2 |
|
$labels[] = $prefix . DIProperty::newFromUserLabel( $dataItem->getDBKey() )->getLabel(); |
|
118
|
2 |
|
} |
|
119
|
|
|
|
|
120
|
2 |
|
$msg = wfMessage( "notification-body-{$this->type}" ); |
|
121
|
2 |
|
$msg->params( $this->language->listToText( $labels ) ); |
|
122
|
2 |
|
$msg->params( count( $labels ) ); |
|
123
|
|
|
|
|
124
|
2 |
|
return $msg; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @see EchoEventPresentationModel::getPrimaryLink |
|
129
|
|
|
*/ |
|
130
|
3 |
|
public function getPrimaryLink() { |
|
131
|
3 |
|
$title = $this->event->getTitle(); |
|
132
|
|
|
return array( |
|
133
|
3 |
|
'url' => $title->getFullURL(), |
|
134
|
3 |
|
'label' => $title->getFullText() |
|
135
|
3 |
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @see EchoEventPresentationModel::getSecondaryLinks |
|
140
|
|
|
*/ |
|
141
|
3 |
|
public function getSecondaryLinks() { |
|
142
|
|
|
|
|
143
|
3 |
|
$extra = $this->event->getExtra(); |
|
|
|
|
|
|
144
|
3 |
|
$title = $this->event->getTitle(); |
|
145
|
|
|
|
|
146
|
3 |
|
$queryParameters['oldid'] = 'prev'; |
|
|
|
|
|
|
147
|
|
|
|
|
148
|
3 |
|
if ( $this->event->getExtraParam( 'revid' ) > 0 ) { |
|
149
|
3 |
|
$queryParameters['diff'] = $this->event->getExtraParam( 'revid' ); |
|
150
|
3 |
|
} |
|
151
|
|
|
|
|
152
|
|
|
$viewChangesLink = array( |
|
153
|
3 |
|
'url' => $title->getLocalURL( $queryParameters ), |
|
154
|
3 |
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(), |
|
155
|
3 |
|
'description' => '', |
|
156
|
3 |
|
'icon' => 'changes', |
|
157
|
3 |
|
'prioritized' => true, |
|
158
|
3 |
|
); |
|
159
|
|
|
|
|
160
|
3 |
|
return array( $this->getAgentLink(), $viewChangesLink ); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.