|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
|
4
|
|
|
* * |
|
5
|
|
|
* All code in this file is released into the public domain by the ACC * |
|
6
|
|
|
* Development Team. Please see team.json for a list of contributors. * |
|
7
|
|
|
******************************************************************************/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Waca\Helpers\SearchHelpers; |
|
10
|
|
|
|
|
11
|
|
|
use Waca\DataObjects\Request; |
|
12
|
|
|
use Waca\PdoDatabase; |
|
13
|
|
|
use Waca\RequestStatus; |
|
14
|
|
|
use Waca\SiteConfiguration; |
|
15
|
|
|
|
|
16
|
|
|
class RequestSearchHelper extends SearchHelperBase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* RequestSearchHelper constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param PdoDatabase $database |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function __construct(PdoDatabase $database) |
|
24
|
|
|
{ |
|
25
|
|
|
parent::__construct($database, 'request', Request::class); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Initiates a search for requests |
|
30
|
|
|
* |
|
31
|
|
|
* @param PdoDatabase $database |
|
32
|
|
|
* |
|
33
|
|
|
* @return RequestSearchHelper |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function get(PdoDatabase $database) |
|
36
|
|
|
{ |
|
37
|
|
|
$helper = new RequestSearchHelper($database); |
|
38
|
|
|
|
|
39
|
|
|
return $helper; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Filters the results by IP address |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $ipAddress |
|
46
|
|
|
* @param bool $getRange |
|
47
|
|
|
* |
|
48
|
|
|
* @return $this |
|
49
|
|
|
*/ |
|
50
|
|
|
public function byIp($ipAddress, $getRange = false) |
|
51
|
|
|
{ |
|
52
|
|
|
if ($getRange) { |
|
53
|
|
|
//Split the IP address in to an array, pop the last octet off, and rebuild variable. |
|
54
|
|
|
//Should end up with the query doing 'LIKE x.x.x%' which will get 0-255 on the last octet. |
|
55
|
|
|
$ipSplit = explode('.', $ipAddress); |
|
56
|
|
|
array_pop($ipSplit); |
|
57
|
|
|
$ipAddress = implode('.', $ipSplit); |
|
58
|
|
|
} |
|
59
|
|
|
$this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)'; |
|
60
|
|
|
$this->parameterList[] = $ipAddress; |
|
61
|
|
|
$this->parameterList[] = '%' . trim($ipAddress, '%') . '%'; |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Filters the results by email address |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $emailAddress |
|
70
|
|
|
* |
|
71
|
|
|
* @return $this |
|
72
|
|
|
*/ |
|
73
|
|
|
public function byEmailAddress($emailAddress) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->whereClause .= ' AND email LIKE ?'; |
|
76
|
|
|
$this->parameterList[] = $emailAddress; |
|
77
|
|
|
|
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Filters the results by name |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $name |
|
85
|
|
|
* |
|
86
|
|
|
* @return $this |
|
87
|
|
|
*/ |
|
88
|
|
|
public function byName($name) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->whereClause .= ' AND name LIKE ?'; |
|
91
|
|
|
$this->parameterList[] = $name; |
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Filters the results by comment |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $comment |
|
100
|
|
|
* |
|
101
|
|
|
* @return $this |
|
102
|
|
|
*/ |
|
103
|
|
|
public function byComment($comment) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->modifiersClause = 'DISTINCT'; |
|
106
|
|
|
$this->joinClause .= ' INNER JOIN comment c ON origin.id = c.request'; |
|
107
|
|
|
$this->whereClause .= ' AND c.comment LIKE ?'; |
|
108
|
|
|
$this->parameterList[] = $comment; |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Filters the results by comment security |
|
115
|
|
|
* |
|
116
|
|
|
* @param array $security List of allowed values for the security clause |
|
117
|
|
|
* |
|
118
|
|
|
* @return $this |
|
119
|
|
|
*/ |
|
120
|
|
|
public function byCommentSecurity(array $security) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->inClause('c.visibility', $security); |
|
123
|
|
|
|
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Filters the requests to those with a defined status |
|
129
|
|
|
* |
|
130
|
|
|
* @param $status |
|
131
|
|
|
* |
|
132
|
|
|
* @return $this |
|
133
|
|
|
*/ |
|
134
|
|
|
public function byStatus($status) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->whereClause .= ' AND status = ?'; |
|
137
|
|
|
$this->parameterList[] = $status; |
|
138
|
|
|
|
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Excludes a request from the results |
|
144
|
|
|
* |
|
145
|
|
|
* @param int $requestId |
|
146
|
|
|
* |
|
147
|
|
|
* @return $this |
|
148
|
|
|
*/ |
|
149
|
|
|
public function excludingRequest($requestId) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->whereClause .= ' AND id <> ?'; |
|
152
|
|
|
$this->parameterList[] = $requestId; |
|
153
|
|
|
|
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Excludes an IP from the results |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $ipAddress |
|
161
|
|
|
* |
|
162
|
|
|
* @return $this |
|
163
|
|
|
*/ |
|
164
|
|
|
public function excludingIP($ipAddress) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->whereClause .= ' AND ip <> ? AND forwardedip <> ?'; |
|
167
|
|
|
$this->parameterList[] = $ipAddress; |
|
168
|
|
|
$this->parameterList[] = $ipAddress; |
|
169
|
|
|
|
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Filters the results to only those with a confirmed email address |
|
176
|
|
|
* |
|
177
|
|
|
* @return $this |
|
178
|
|
|
*/ |
|
179
|
|
|
public function withConfirmedEmail() |
|
180
|
|
|
{ |
|
181
|
|
|
$this->whereClause .= ' AND emailconfirm = ?'; |
|
182
|
|
|
$this->parameterList[] = 'Confirmed'; |
|
183
|
|
|
|
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Filters the results to exclude purged data |
|
189
|
|
|
* |
|
190
|
|
|
* @param SiteConfiguration $configuration |
|
191
|
|
|
* |
|
192
|
|
|
* @return $this |
|
193
|
|
|
*/ |
|
194
|
|
|
public function excludingPurgedData(SiteConfiguration $configuration) |
|
195
|
|
|
{ |
|
196
|
|
|
$this->whereClause .= ' AND ip <> ? AND email <> ?'; |
|
197
|
|
|
$this->parameterList[] = $configuration->getDataClearIp(); |
|
198
|
|
|
$this->parameterList[] = $configuration->getDataClearEmail(); |
|
199
|
|
|
|
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Filters the requests to those without a defined status |
|
205
|
|
|
* |
|
206
|
|
|
* @param $status |
|
207
|
|
|
* |
|
208
|
|
|
* @return $this |
|
209
|
|
|
*/ |
|
210
|
|
|
public function excludingStatus($status) |
|
211
|
|
|
{ |
|
212
|
|
|
$this->whereClause .= ' AND status <> ?'; |
|
213
|
|
|
$this->parameterList[] = $status; |
|
214
|
|
|
|
|
215
|
|
|
return $this; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Filters the requests to those which have failed an auto-creation |
|
220
|
|
|
* |
|
221
|
|
|
* @return $this |
|
222
|
|
|
*/ |
|
223
|
|
|
public function isHospitalised() |
|
224
|
|
|
{ |
|
225
|
|
|
$this->whereClause .= ' AND status = ?'; |
|
226
|
|
|
$this->parameterList[] = RequestStatus::HOSPITAL; |
|
227
|
|
|
|
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Filters the requests to those which have not failed an auto-creation |
|
233
|
|
|
* |
|
234
|
|
|
* @return $this |
|
235
|
|
|
*/ |
|
236
|
|
|
public function notHospitalised() |
|
237
|
|
|
{ |
|
238
|
|
|
$this->whereClause .= ' AND status <> ?'; |
|
239
|
|
|
$this->parameterList[] = RequestStatus::HOSPITAL; |
|
240
|
|
|
|
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function fetchByQueue($queues) |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->fetchByParameter(' AND queue = ?', $queues); |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|