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
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
|
|
public function byIp($ipAddress) |
50
|
|
|
{ |
51
|
|
|
$this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)'; |
52
|
|
|
$this->parameterList[] = $ipAddress; |
53
|
|
|
$this->parameterList[] = '%' . trim($ipAddress, '%') . '%'; |
54
|
|
|
|
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Filters the results by email address |
60
|
|
|
* |
61
|
|
|
* @param string $emailAddress |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
public function byEmailAddress($emailAddress) |
66
|
|
|
{ |
67
|
|
|
$this->whereClause .= ' AND email LIKE ?'; |
68
|
|
|
$this->parameterList[] = $emailAddress; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Filters the results by name |
75
|
|
|
* |
76
|
|
|
* @param string $name |
77
|
|
|
* |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
|
|
public function byName($name) |
81
|
|
|
{ |
82
|
|
|
$this->whereClause .= ' AND name LIKE ?'; |
83
|
|
|
$this->parameterList[] = $name; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Filters the requests to those with a defined status |
90
|
|
|
* |
91
|
|
|
* @param $status |
92
|
|
|
* |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function byStatus($status) |
96
|
|
|
{ |
97
|
|
|
$this->whereClause .= ' AND status = ?'; |
98
|
|
|
$this->parameterList[] = $status; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Excludes a request from the results |
105
|
|
|
* |
106
|
|
|
* @param int $requestId |
107
|
|
|
* |
108
|
|
|
* @return $this |
109
|
|
|
*/ |
110
|
|
|
public function excludingRequest($requestId) |
111
|
|
|
{ |
112
|
|
|
$this->whereClause .= ' AND id <> ?'; |
113
|
|
|
$this->parameterList[] = $requestId; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Filters the results to only those with a confirmed email address |
120
|
|
|
* |
121
|
|
|
* @return $this |
122
|
|
|
*/ |
123
|
|
|
public function withConfirmedEmail() |
124
|
|
|
{ |
125
|
|
|
$this->whereClause .= ' AND emailconfirm = ?'; |
126
|
|
|
$this->parameterList[] = 'Confirmed'; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Filters the results to exclude purged data |
133
|
|
|
* |
134
|
|
|
* @param SiteConfiguration $configuration |
135
|
|
|
* |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
|
|
public function excludingPurgedData(SiteConfiguration $configuration) |
139
|
|
|
{ |
140
|
|
|
$this->whereClause .= ' AND ip <> ? AND email <> ?'; |
141
|
|
|
$this->parameterList[] = $configuration->getDataClearIp(); |
142
|
|
|
$this->parameterList[] = $configuration->getDataClearEmail(); |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Filters the requests to those without a defined status |
149
|
|
|
* |
150
|
|
|
* @param $status |
151
|
|
|
* |
152
|
|
|
* @return $this |
153
|
|
|
*/ |
154
|
|
|
public function excludingStatus($status) |
155
|
|
|
{ |
156
|
|
|
$this->whereClause .= ' AND status <> ?'; |
157
|
|
|
$this->parameterList[] = $status; |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Filters the requests to those which have failed an auto-creation |
164
|
|
|
* |
165
|
|
|
* @return $this |
166
|
|
|
*/ |
167
|
|
|
public function isHospitalised() |
168
|
|
|
{ |
169
|
|
|
$this->whereClause .= ' AND status = ?'; |
170
|
|
|
$this->parameterList[] = RequestStatus::HOSPITAL; |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Filters the requests to those which have not failed an auto-creation |
177
|
|
|
* |
178
|
|
|
* @return $this |
179
|
|
|
*/ |
180
|
|
|
public function notHospitalised() |
181
|
|
|
{ |
182
|
|
|
$this->whereClause .= ' AND status <> ?'; |
183
|
|
|
$this->parameterList[] = RequestStatus::HOSPITAL; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function fetchByQueue($queues) |
189
|
|
|
{ |
190
|
|
|
return $this->fetchByParameter(' AND queue = ?', $queues); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|