-
Notifications
You must be signed in to change notification settings - Fork 0
/
DpleFeatureUser.php
264 lines (202 loc) · 6.88 KB
/
DpleFeatureUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
/**
* @brief Class DpleFeatureUser.
*
* @file
*
* @ingroup Extensions
* @ingroup Extensions-DynamicPageListEngine
*
* @author [RV1971](http://www.mediawiki.org/wiki/User:RV1971)
*/
/**
* @brief Selection by modifying user.
*
* Recognizes the parameters `createdby, notcreatedby, modifiedby,
* notmodifiedby, lastmodifiedby` and `notlastmodifiedby`, each of which
* may be a title substring or an array thereof.
*
* If `createdby, modifiedby, lastmodifiedby` is an array, the result
* is (obviously) the union of the record sets satisfying its
* elements, unlike other parameters (including `notcreatedby`) where
* the result is the intersection.
*
* If the parameters contradict each other (e.g. the same user is
* nominated in `createdby` and in `notcreatedby`), the results are
* undefined.
*
* @ingroup Extensions
* @ingroup Extensions-DynamicPageListEngine
*
* @todo Implement [not]majormodifiedby to select pages that have [no]
* major edits from specified users.
*/
class DpleFeatureUser extends DpleFeatureBase
implements DpleFeatureInterface {
/* == private variables == */
/** @brief Array of User objects for users that should have
* created the pages to select.*/
private $createdby_;
/** @brief Array of User objects for users that should not have
* created the pages to select.*/
private $notCreatedby_;
/** @brief Array of User objects for users that should have
* modified the pages to select.*/
private $modifiedby_;
/** @brief Array of User objects for users that should not have
* modified the pages to select.*/
private $notModifiedby_;
/** @brief Array of User objects for users that should be the
* users that have modified the pages to select.*/
private $lastmodifiedby_;
/** @brief Array of User objects for users that should not be the
* users that have modified the pages to select.*/
private $notLastmodifiedby_;
/* == magic methods == */
/// Constructor. Evaluate parameters.
public function __construct( array $params, array &$features ) {
parent::__construct( $features );
foreach ( array(
'createdby' => 'createdby_',
'notcreatedby' => 'notCreatedby_',
'modifiedby' => 'modifiedby_',
'notmodifiedby' => 'notModifiedby_',
'lastmodifiedby' => 'lastmodifiedby_',
'notlastmodifiedby' => 'notLastmodifiedby_'
) as $key => $member ) {
if ( isset( $params[$key] ) ) {
$this->$member =
array_map( array( $this, 'parseUser' ),
(array)$params[$key] );
}
}
}
/* == accessors == */
/// Get @ref $createdby_.
public function getCreatedby() {
return $this->createdby_;
}
/// Get @ref $notCreatedby_.
public function getNotCreatedby() {
return $this->notCreatedby_;
}
/// Get @ref $modifiedby_.
public function getModifiedby() {
return $this->modifiedby_;
}
/// Get @ref $notModifiedby_.
public function getNotModifiedby() {
return $this->notModifiedby_;
}
/// Get @ref $lastmodifiedby_.
public function getLastmodifiedby() {
return $this->lastmodifiedby_;
}
/// Get @ref $notLastmodifiedby_.
public function getNotLastmodifiedby() {
return $this->notLastmodifiedby_;
}
/// Get the database cost generated by this feature instance.
public function getCost() {
global $wgDpleCondCostMap;
/** When selecting by `[not]modifiedby`, the record sets
* selected from the joined tables may be very large, unlike
* selection by `lastmodifiedby`. Therefore, the cost per
* condition for this is stored in an extra entry with an
* "Expensive" appended to the key.
*/
$highCostKey = get_class( $this ) . 'Expensive';
$highCost = isset( $wgDpleCondCostMap[$highCostKey] )
? $wgDpleCondCostMap[$highCostKey]
: parent::getCost();
return ((int)(bool)$this->createdby_
+ (int)(bool)$this->notCreatedby_
+ (int)(bool)$this->lastmodifiedby_
+ (int)(bool)$this->notLastmodifiedby_) * parent::getCost()
+ ((int)(bool)$this->modifiedby_
+ (int)(bool)$this->notModifiedby_) * $highCost;
}
/* == operations == */
/// Modify a given query. @copydetails DpleFeatureBase::modifyQuery()
public function modifyQuery( DpleQuery &$query ) {
$dbr = $query->getDbr();
$tableName = $dbr->tableName( 'revision' );
/** Add condition based on @ref $createdby_. */
if ( $this->createdby_ ) {
$table = "$tableName AS rev_c";
$query->addTables( $table );
$cond = $this->buildIn( $this->createdby_ );
$query->addJoinCond( $table, 'INNER JOIN',
array( 'page_id = rev_c.rev_page',
'rev_c.rev_parent_id = 0' ) );
$query->addConds( "rev_c.rev_user $cond" );
}
/** Add condition based on @ref $notCreatedby_. */
if ( $this->notCreatedby_ ) {
$table = "$tableName AS rev_nc";
$query->addTables( $table );
$cond = 'NOT' . $this->buildIn( $this->notCreatedby_ );
$query->addJoinCond( $table, 'INNER JOIN',
array( 'page_id = rev_nc.rev_page',
'rev_nc.rev_parent_id = 0' ) );
$query->addConds( "rev_nc.rev_user $cond" );
}
/** Add condition based on @ref $lastmodifiedby_. */
if ( $this->lastmodifiedby_ ) {
$table = "$tableName AS rev_l";
$query->addTables( $table );
$cond = $this->buildIn( $this->lastmodifiedby_ );
$query->addJoinCond( $table, 'INNER JOIN',
array( 'page_latest = rev_l.rev_id' ) );
$query->addConds( "rev_l.rev_user $cond" );
}
/** Add condition based on @ref $notLastmodifiedby_. */
if ( $this->notLastmodifiedby_ ) {
$table = "$tableName AS rev_nl";
$query->addTables( $table );
$cond = 'NOT' . $this->buildIn( $this->notLastmodifiedby_ );
$query->addJoinCond( $table, 'INNER JOIN',
array( 'page_latest = rev_nl.rev_id' ) );
$query->addConds( "rev_nl.rev_user $cond" );
}
/** Add condition based on @ref $modifiedby_. */
if ( $this->modifiedby_ ) {
$table = "$tableName AS rev_m";
$query->addTables( $table );
$cond = $this->buildIn( $this->modifiedby_ );
$query->addJoinCond( $table, 'INNER JOIN',
array( 'page_id = rev_m.rev_page' ) );
$query->addConds( "rev_m.rev_user $cond" );
$query->setOption( 'DISTINCT' );
}
/** Add condition based on @ref $notModifiedby_. */
if ( $this->notModifiedby_ ) {
$table = "$tableName AS rev_nm";
$query->addTables( $table );
$cond = $this->buildIn( $this->notModifiedby_ );
$query->addJoinCond( $table, 'LEFT OUTER JOIN',
array( 'page_id = rev_nm.rev_page',
"rev_nm.rev_user $cond" ) );
$query->addConds( array( 'rev_nm.rev_page' => null ) );
$query->setOption( 'DISTINCT' );
}
}
/**
* @brief Build an IN expression for user IDs.
*
* @param array $users Array of User objects.
*
* @return string ' IN (...)' where ... is a list of user IDs.
*/
public function buildIn( array $users ) {
$list = array();
foreach ( $users as $user ) {
$list[] = $user->getId();
}
return ' IN (' . implode( ',', $list ) . ')';
}
}