@@ -17,254 +17,254 @@ discard block |
||
17 | 17 | |
18 | 18 | class RequestQueue extends DataObject |
19 | 19 | { |
20 | - const DEFAULT_DEFAULT = 'default'; |
|
21 | - const DEFAULT_ANTISPOOF = 'antispoof'; |
|
22 | - const DEFAULT_TITLEBLACKLIST = 'titleblacklist'; |
|
23 | - |
|
24 | - /** @var int */ |
|
25 | - private $enabled = 0; |
|
26 | - /** @var int */ |
|
27 | - private $isdefault = 0; |
|
28 | - /** @var int */ |
|
29 | - private $defaultantispoof = 0; |
|
30 | - /** @var int */ |
|
31 | - private $defaulttitleblacklist = 0; |
|
32 | - /** @var int */ |
|
33 | - private $domain; |
|
34 | - /** @var string */ |
|
35 | - private $apiname; |
|
36 | - /** @var string */ |
|
37 | - private $displayname; |
|
38 | - /** @var string */ |
|
39 | - private $header; |
|
40 | - /** @var string|null */ |
|
41 | - private $help; |
|
42 | - /** |
|
43 | - * @var string |
|
44 | - * @deprecated Removal due as part of #607 |
|
45 | - */ |
|
46 | - private $logname; |
|
47 | - /** |
|
48 | - * @param PdoDatabase $database |
|
49 | - * |
|
50 | - * @return RequestQueue[] |
|
51 | - */ |
|
52 | - public static function getAllQueues(PdoDatabase $database) |
|
53 | - { |
|
54 | - $statement = $database->prepare(<<<SQL |
|
20 | + const DEFAULT_DEFAULT = 'default'; |
|
21 | + const DEFAULT_ANTISPOOF = 'antispoof'; |
|
22 | + const DEFAULT_TITLEBLACKLIST = 'titleblacklist'; |
|
23 | + |
|
24 | + /** @var int */ |
|
25 | + private $enabled = 0; |
|
26 | + /** @var int */ |
|
27 | + private $isdefault = 0; |
|
28 | + /** @var int */ |
|
29 | + private $defaultantispoof = 0; |
|
30 | + /** @var int */ |
|
31 | + private $defaulttitleblacklist = 0; |
|
32 | + /** @var int */ |
|
33 | + private $domain; |
|
34 | + /** @var string */ |
|
35 | + private $apiname; |
|
36 | + /** @var string */ |
|
37 | + private $displayname; |
|
38 | + /** @var string */ |
|
39 | + private $header; |
|
40 | + /** @var string|null */ |
|
41 | + private $help; |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + * @deprecated Removal due as part of #607 |
|
45 | + */ |
|
46 | + private $logname; |
|
47 | + /** |
|
48 | + * @param PdoDatabase $database |
|
49 | + * |
|
50 | + * @return RequestQueue[] |
|
51 | + */ |
|
52 | + public static function getAllQueues(PdoDatabase $database) |
|
53 | + { |
|
54 | + $statement = $database->prepare(<<<SQL |
|
55 | 55 | SELECT * FROM requestqueue; |
56 | 56 | SQL |
57 | - ); |
|
58 | - $statement->execute(); |
|
59 | - |
|
60 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
61 | - |
|
62 | - /** @var RequestQueue $t */ |
|
63 | - foreach ($resultObject as $t) { |
|
64 | - $t->setDatabase($database); |
|
65 | - } |
|
66 | - |
|
67 | - return $resultObject; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param PdoDatabase $database |
|
72 | - * |
|
73 | - * @return RequestQueue[] |
|
74 | - */ |
|
75 | - public static function getEnabledQueues(PdoDatabase $database) |
|
76 | - { |
|
77 | - $statement = $database->prepare(<<<SQL |
|
57 | + ); |
|
58 | + $statement->execute(); |
|
59 | + |
|
60 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
61 | + |
|
62 | + /** @var RequestQueue $t */ |
|
63 | + foreach ($resultObject as $t) { |
|
64 | + $t->setDatabase($database); |
|
65 | + } |
|
66 | + |
|
67 | + return $resultObject; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param PdoDatabase $database |
|
72 | + * |
|
73 | + * @return RequestQueue[] |
|
74 | + */ |
|
75 | + public static function getEnabledQueues(PdoDatabase $database) |
|
76 | + { |
|
77 | + $statement = $database->prepare(<<<SQL |
|
78 | 78 | SELECT * FROM requestqueue WHERE enabled = 1; |
79 | 79 | SQL |
80 | - ); |
|
81 | - $statement->execute(); |
|
82 | - |
|
83 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
84 | - |
|
85 | - /** @var RequestQueue $t */ |
|
86 | - foreach ($resultObject as $t) { |
|
87 | - $t->setDatabase($database); |
|
88 | - } |
|
89 | - |
|
90 | - return $resultObject; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param PdoDatabase $database |
|
95 | - * @param string $apiName |
|
96 | - * @param int $domain |
|
97 | - * |
|
98 | - * @return false|RequestQueue |
|
99 | - */ |
|
100 | - public static function getByApiName(PdoDatabase $database, string $apiName, int $domain) |
|
101 | - { |
|
102 | - $statement = $database->prepare(<<<SQL |
|
80 | + ); |
|
81 | + $statement->execute(); |
|
82 | + |
|
83 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
84 | + |
|
85 | + /** @var RequestQueue $t */ |
|
86 | + foreach ($resultObject as $t) { |
|
87 | + $t->setDatabase($database); |
|
88 | + } |
|
89 | + |
|
90 | + return $resultObject; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param PdoDatabase $database |
|
95 | + * @param string $apiName |
|
96 | + * @param int $domain |
|
97 | + * |
|
98 | + * @return false|RequestQueue |
|
99 | + */ |
|
100 | + public static function getByApiName(PdoDatabase $database, string $apiName, int $domain) |
|
101 | + { |
|
102 | + $statement = $database->prepare(<<<SQL |
|
103 | 103 | SELECT * FROM requestqueue WHERE apiname = :apiName AND domain = :domain; |
104 | 104 | SQL |
105 | - ); |
|
106 | - |
|
107 | - $statement->execute([ |
|
108 | - ':apiName' => $apiName, |
|
109 | - ':domain' => $domain, |
|
110 | - ]); |
|
111 | - |
|
112 | - /** @var RequestQueue|false $result */ |
|
113 | - $result = $statement->fetchObject(get_called_class()); |
|
114 | - |
|
115 | - if ($result !== false) { |
|
116 | - $result->setDatabase($database); |
|
117 | - } |
|
118 | - |
|
119 | - return $result; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param PdoDatabase $database |
|
124 | - * @param string $displayName |
|
125 | - * @param int $domain |
|
126 | - * |
|
127 | - * @return false|RequestQueue |
|
128 | - */ |
|
129 | - public static function getByDisplayName(PdoDatabase $database, string $displayName, int $domain) |
|
130 | - { |
|
131 | - $statement = $database->prepare(<<<SQL |
|
105 | + ); |
|
106 | + |
|
107 | + $statement->execute([ |
|
108 | + ':apiName' => $apiName, |
|
109 | + ':domain' => $domain, |
|
110 | + ]); |
|
111 | + |
|
112 | + /** @var RequestQueue|false $result */ |
|
113 | + $result = $statement->fetchObject(get_called_class()); |
|
114 | + |
|
115 | + if ($result !== false) { |
|
116 | + $result->setDatabase($database); |
|
117 | + } |
|
118 | + |
|
119 | + return $result; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param PdoDatabase $database |
|
124 | + * @param string $displayName |
|
125 | + * @param int $domain |
|
126 | + * |
|
127 | + * @return false|RequestQueue |
|
128 | + */ |
|
129 | + public static function getByDisplayName(PdoDatabase $database, string $displayName, int $domain) |
|
130 | + { |
|
131 | + $statement = $database->prepare(<<<SQL |
|
132 | 132 | SELECT * FROM requestqueue WHERE displayname = :displayName AND domain = :domain; |
133 | 133 | SQL |
134 | - ); |
|
135 | - |
|
136 | - $statement->execute([ |
|
137 | - ':displayName' => $displayName, |
|
138 | - ':domain' => $domain, |
|
139 | - ]); |
|
140 | - |
|
141 | - /** @var RequestQueue|false $result */ |
|
142 | - $result = $statement->fetchObject(get_called_class()); |
|
143 | - |
|
144 | - if ($result !== false) { |
|
145 | - $result->setDatabase($database); |
|
146 | - } |
|
147 | - |
|
148 | - return $result; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param PdoDatabase $database |
|
153 | - * @param string $header |
|
154 | - * @param int $domain |
|
155 | - * |
|
156 | - * @return false|RequestQueue |
|
157 | - */ |
|
158 | - public static function getByHeader(PdoDatabase $database, string $header, int $domain) |
|
159 | - { |
|
160 | - $statement = $database->prepare(<<<SQL |
|
134 | + ); |
|
135 | + |
|
136 | + $statement->execute([ |
|
137 | + ':displayName' => $displayName, |
|
138 | + ':domain' => $domain, |
|
139 | + ]); |
|
140 | + |
|
141 | + /** @var RequestQueue|false $result */ |
|
142 | + $result = $statement->fetchObject(get_called_class()); |
|
143 | + |
|
144 | + if ($result !== false) { |
|
145 | + $result->setDatabase($database); |
|
146 | + } |
|
147 | + |
|
148 | + return $result; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param PdoDatabase $database |
|
153 | + * @param string $header |
|
154 | + * @param int $domain |
|
155 | + * |
|
156 | + * @return false|RequestQueue |
|
157 | + */ |
|
158 | + public static function getByHeader(PdoDatabase $database, string $header, int $domain) |
|
159 | + { |
|
160 | + $statement = $database->prepare(<<<SQL |
|
161 | 161 | SELECT * FROM requestqueue WHERE header = :header AND domain = :domain; |
162 | 162 | SQL |
163 | - ); |
|
164 | - |
|
165 | - $statement->execute([ |
|
166 | - ':header' => $header, |
|
167 | - ':domain' => $domain, |
|
168 | - ]); |
|
169 | - |
|
170 | - /** @var RequestQueue|false $result */ |
|
171 | - $result = $statement->fetchObject(get_called_class()); |
|
172 | - |
|
173 | - if ($result !== false) { |
|
174 | - $result->setDatabase($database); |
|
175 | - } |
|
176 | - |
|
177 | - return $result; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param PdoDatabase $database |
|
182 | - * @param int $domain |
|
183 | - * |
|
184 | - * @param string $defaultType The type of default queue to get. |
|
185 | - * |
|
186 | - * @return false|RequestQueue |
|
187 | - * @throws ApplicationLogicException |
|
188 | - */ |
|
189 | - public static function getDefaultQueue(PdoDatabase $database, int $domain, string $defaultType = 'default') |
|
190 | - { |
|
191 | - switch ($defaultType) { |
|
192 | - case self::DEFAULT_DEFAULT: |
|
193 | - $sql = 'SELECT * FROM requestqueue WHERE isdefault = 1 AND domain = :domain;'; |
|
194 | - break; |
|
195 | - case self::DEFAULT_ANTISPOOF: |
|
196 | - $sql = 'SELECT * FROM requestqueue WHERE defaultantispoof = 1 AND domain = :domain;'; |
|
197 | - break; |
|
198 | - case self::DEFAULT_TITLEBLACKLIST: |
|
199 | - $sql = 'SELECT * FROM requestqueue WHERE defaulttitleblacklist = 1 AND domain = :domain;'; |
|
200 | - break; |
|
201 | - default: |
|
202 | - throw new ApplicationLogicException('Unknown request for default queue'); |
|
203 | - } |
|
204 | - |
|
205 | - $statement = $database->prepare($sql); |
|
206 | - |
|
207 | - $statement->execute([':domain' => $domain]); |
|
208 | - |
|
209 | - /** @var RequestQueue|false $result */ |
|
210 | - $result = $statement->fetchObject(get_called_class()); |
|
211 | - |
|
212 | - if ($result !== false) { |
|
213 | - $result->setDatabase($database); |
|
214 | - } |
|
215 | - |
|
216 | - return $result; |
|
217 | - } |
|
218 | - |
|
219 | - public function save() |
|
220 | - { |
|
221 | - // find and squish existing defaults |
|
222 | - if ($this->isDefault()) { |
|
223 | - $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET isdefault = 0 WHERE isdefault = 1 AND domain = :domain;'); |
|
224 | - $squishStatement->execute([':domain' => $this->domain]); |
|
225 | - } |
|
226 | - |
|
227 | - if ($this->isDefaultAntispoof()) { |
|
228 | - $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaultantispoof = 0 WHERE defaultantispoof = 1 AND domain = :domain;'); |
|
229 | - $squishStatement->execute([':domain' => $this->domain]); |
|
230 | - } |
|
231 | - |
|
232 | - if ($this->isDefaultTitleBlacklist()) { |
|
233 | - $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaulttitleblacklist = 0 WHERE defaulttitleblacklist = 1 AND domain = :domain;'); |
|
234 | - $squishStatement->execute([':domain' => $this->domain]); |
|
235 | - } |
|
236 | - |
|
237 | - if ($this->isNew()) { |
|
238 | - // insert |
|
239 | - $statement = $this->dbObject->prepare(<<<SQL |
|
163 | + ); |
|
164 | + |
|
165 | + $statement->execute([ |
|
166 | + ':header' => $header, |
|
167 | + ':domain' => $domain, |
|
168 | + ]); |
|
169 | + |
|
170 | + /** @var RequestQueue|false $result */ |
|
171 | + $result = $statement->fetchObject(get_called_class()); |
|
172 | + |
|
173 | + if ($result !== false) { |
|
174 | + $result->setDatabase($database); |
|
175 | + } |
|
176 | + |
|
177 | + return $result; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param PdoDatabase $database |
|
182 | + * @param int $domain |
|
183 | + * |
|
184 | + * @param string $defaultType The type of default queue to get. |
|
185 | + * |
|
186 | + * @return false|RequestQueue |
|
187 | + * @throws ApplicationLogicException |
|
188 | + */ |
|
189 | + public static function getDefaultQueue(PdoDatabase $database, int $domain, string $defaultType = 'default') |
|
190 | + { |
|
191 | + switch ($defaultType) { |
|
192 | + case self::DEFAULT_DEFAULT: |
|
193 | + $sql = 'SELECT * FROM requestqueue WHERE isdefault = 1 AND domain = :domain;'; |
|
194 | + break; |
|
195 | + case self::DEFAULT_ANTISPOOF: |
|
196 | + $sql = 'SELECT * FROM requestqueue WHERE defaultantispoof = 1 AND domain = :domain;'; |
|
197 | + break; |
|
198 | + case self::DEFAULT_TITLEBLACKLIST: |
|
199 | + $sql = 'SELECT * FROM requestqueue WHERE defaulttitleblacklist = 1 AND domain = :domain;'; |
|
200 | + break; |
|
201 | + default: |
|
202 | + throw new ApplicationLogicException('Unknown request for default queue'); |
|
203 | + } |
|
204 | + |
|
205 | + $statement = $database->prepare($sql); |
|
206 | + |
|
207 | + $statement->execute([':domain' => $domain]); |
|
208 | + |
|
209 | + /** @var RequestQueue|false $result */ |
|
210 | + $result = $statement->fetchObject(get_called_class()); |
|
211 | + |
|
212 | + if ($result !== false) { |
|
213 | + $result->setDatabase($database); |
|
214 | + } |
|
215 | + |
|
216 | + return $result; |
|
217 | + } |
|
218 | + |
|
219 | + public function save() |
|
220 | + { |
|
221 | + // find and squish existing defaults |
|
222 | + if ($this->isDefault()) { |
|
223 | + $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET isdefault = 0 WHERE isdefault = 1 AND domain = :domain;'); |
|
224 | + $squishStatement->execute([':domain' => $this->domain]); |
|
225 | + } |
|
226 | + |
|
227 | + if ($this->isDefaultAntispoof()) { |
|
228 | + $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaultantispoof = 0 WHERE defaultantispoof = 1 AND domain = :domain;'); |
|
229 | + $squishStatement->execute([':domain' => $this->domain]); |
|
230 | + } |
|
231 | + |
|
232 | + if ($this->isDefaultTitleBlacklist()) { |
|
233 | + $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaulttitleblacklist = 0 WHERE defaulttitleblacklist = 1 AND domain = :domain;'); |
|
234 | + $squishStatement->execute([':domain' => $this->domain]); |
|
235 | + } |
|
236 | + |
|
237 | + if ($this->isNew()) { |
|
238 | + // insert |
|
239 | + $statement = $this->dbObject->prepare(<<<SQL |
|
240 | 240 | INSERT INTO requestqueue ( |
241 | 241 | enabled, isdefault, defaultantispoof, defaulttitleblacklist, domain, apiname, displayname, header, help, logname |
242 | 242 | ) VALUES ( |
243 | 243 | :enabled, :isdefault, :defaultantispoof, :defaulttitleblacklist, :domain, :apiname, :displayname, :header, :help, :logname |
244 | 244 | ); |
245 | 245 | SQL |
246 | - ); |
|
247 | - |
|
248 | - $statement->bindValue(":enabled", $this->enabled); |
|
249 | - $statement->bindValue(":isdefault", $this->isdefault); |
|
250 | - $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
251 | - $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
252 | - $statement->bindValue(":domain", $this->domain); |
|
253 | - $statement->bindValue(":apiname", $this->apiname); |
|
254 | - $statement->bindValue(":displayname", $this->displayname); |
|
255 | - $statement->bindValue(":header", $this->header); |
|
256 | - $statement->bindValue(":help", $this->help); |
|
257 | - $statement->bindValue(":logname", $this->logname); |
|
258 | - |
|
259 | - if ($statement->execute()) { |
|
260 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
261 | - } |
|
262 | - else { |
|
263 | - throw new Exception($statement->errorInfo()); |
|
264 | - } |
|
265 | - } |
|
266 | - else { |
|
267 | - $statement = $this->dbObject->prepare(<<<SQL |
|
246 | + ); |
|
247 | + |
|
248 | + $statement->bindValue(":enabled", $this->enabled); |
|
249 | + $statement->bindValue(":isdefault", $this->isdefault); |
|
250 | + $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
251 | + $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
252 | + $statement->bindValue(":domain", $this->domain); |
|
253 | + $statement->bindValue(":apiname", $this->apiname); |
|
254 | + $statement->bindValue(":displayname", $this->displayname); |
|
255 | + $statement->bindValue(":header", $this->header); |
|
256 | + $statement->bindValue(":help", $this->help); |
|
257 | + $statement->bindValue(":logname", $this->logname); |
|
258 | + |
|
259 | + if ($statement->execute()) { |
|
260 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
261 | + } |
|
262 | + else { |
|
263 | + throw new Exception($statement->errorInfo()); |
|
264 | + } |
|
265 | + } |
|
266 | + else { |
|
267 | + $statement = $this->dbObject->prepare(<<<SQL |
|
268 | 268 | UPDATE requestqueue SET |
269 | 269 | enabled = :enabled, |
270 | 270 | isdefault = :isdefault, |
@@ -280,194 +280,194 @@ discard block |
||
280 | 280 | updateversion = updateversion + 1 |
281 | 281 | WHERE id = :id AND updateversion = :updateversion; |
282 | 282 | SQL |
283 | - ); |
|
284 | - |
|
285 | - $statement->bindValue(":enabled", $this->enabled); |
|
286 | - $statement->bindValue(":isdefault", $this->isdefault); |
|
287 | - $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
288 | - $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
289 | - $statement->bindValue(":domain", $this->domain); |
|
290 | - $statement->bindValue(":apiname", $this->apiname); |
|
291 | - $statement->bindValue(":displayname", $this->displayname); |
|
292 | - $statement->bindValue(":header", $this->header); |
|
293 | - $statement->bindValue(":help", $this->help); |
|
294 | - $statement->bindValue(":logname", $this->logname); |
|
295 | - |
|
296 | - $statement->bindValue(':id', $this->id); |
|
297 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
298 | - |
|
299 | - if (!$statement->execute()) { |
|
300 | - throw new Exception($statement->errorInfo()); |
|
301 | - } |
|
302 | - |
|
303 | - if ($statement->rowCount() !== 1) { |
|
304 | - throw new OptimisticLockFailedException(); |
|
305 | - } |
|
306 | - |
|
307 | - $this->updateversion++; |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @return bool |
|
313 | - */ |
|
314 | - public function isEnabled(): bool |
|
315 | - { |
|
316 | - return $this->enabled == 1; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @param bool $enabled |
|
321 | - */ |
|
322 | - public function setEnabled(bool $enabled): void |
|
323 | - { |
|
324 | - $this->enabled = $enabled ? 1 : 0; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * @return bool |
|
329 | - */ |
|
330 | - public function isDefault(): bool |
|
331 | - { |
|
332 | - return $this->isdefault == 1; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * @param bool $isDefault |
|
337 | - */ |
|
338 | - public function setDefault(bool $isDefault): void |
|
339 | - { |
|
340 | - $this->isdefault = $isDefault ? 1 : 0; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @return bool |
|
345 | - */ |
|
346 | - public function isDefaultAntispoof(): bool |
|
347 | - { |
|
348 | - return $this->defaultantispoof == 1; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * @param bool $isDefault |
|
353 | - */ |
|
354 | - public function setDefaultAntispoof(bool $isDefault): void |
|
355 | - { |
|
356 | - $this->defaultantispoof = $isDefault ? 1 : 0; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * @return bool |
|
361 | - */ |
|
362 | - public function isDefaultTitleBlacklist(): bool |
|
363 | - { |
|
364 | - return $this->defaulttitleblacklist == 1; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @param bool $isDefault |
|
369 | - */ |
|
370 | - public function setDefaultTitleBlacklist(bool $isDefault): void |
|
371 | - { |
|
372 | - $this->defaulttitleblacklist = $isDefault ? 1 : 0; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * @return int |
|
377 | - */ |
|
378 | - public function getDomain(): int |
|
379 | - { |
|
380 | - return $this->domain; |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * @param int $domain |
|
385 | - */ |
|
386 | - public function setDomain(int $domain): void |
|
387 | - { |
|
388 | - $this->domain = $domain; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public function getApiName(): string |
|
395 | - { |
|
396 | - return $this->apiname; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * @param string $apiName |
|
401 | - */ |
|
402 | - public function setApiName(string $apiName): void |
|
403 | - { |
|
404 | - $this->apiname = $apiName; |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * @return string |
|
409 | - */ |
|
410 | - public function getDisplayName(): string |
|
411 | - { |
|
412 | - return $this->displayname; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $displayName |
|
417 | - */ |
|
418 | - public function setDisplayName(string $displayName): void |
|
419 | - { |
|
420 | - $this->displayname = $displayName; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function getHeader(): string |
|
427 | - { |
|
428 | - return $this->header; |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * @param string $header |
|
433 | - */ |
|
434 | - public function setHeader(string $header): void |
|
435 | - { |
|
436 | - $this->header = $header; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @return string|null |
|
441 | - */ |
|
442 | - public function getHelp(): ?string |
|
443 | - { |
|
444 | - return $this->help; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * @param string|null $help |
|
449 | - */ |
|
450 | - public function setHelp(?string $help): void |
|
451 | - { |
|
452 | - $this->help = $help; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * @return string |
|
457 | - * @deprecated |
|
458 | - */ |
|
459 | - public function getLogName(): string |
|
460 | - { |
|
461 | - return $this->logname; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * @param string $logName |
|
466 | - * |
|
467 | - * @deprecated |
|
468 | - */ |
|
469 | - public function setLogName(string $logName): void |
|
470 | - { |
|
471 | - $this->logname = $logName; |
|
472 | - } |
|
283 | + ); |
|
284 | + |
|
285 | + $statement->bindValue(":enabled", $this->enabled); |
|
286 | + $statement->bindValue(":isdefault", $this->isdefault); |
|
287 | + $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
288 | + $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
289 | + $statement->bindValue(":domain", $this->domain); |
|
290 | + $statement->bindValue(":apiname", $this->apiname); |
|
291 | + $statement->bindValue(":displayname", $this->displayname); |
|
292 | + $statement->bindValue(":header", $this->header); |
|
293 | + $statement->bindValue(":help", $this->help); |
|
294 | + $statement->bindValue(":logname", $this->logname); |
|
295 | + |
|
296 | + $statement->bindValue(':id', $this->id); |
|
297 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
298 | + |
|
299 | + if (!$statement->execute()) { |
|
300 | + throw new Exception($statement->errorInfo()); |
|
301 | + } |
|
302 | + |
|
303 | + if ($statement->rowCount() !== 1) { |
|
304 | + throw new OptimisticLockFailedException(); |
|
305 | + } |
|
306 | + |
|
307 | + $this->updateversion++; |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @return bool |
|
313 | + */ |
|
314 | + public function isEnabled(): bool |
|
315 | + { |
|
316 | + return $this->enabled == 1; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @param bool $enabled |
|
321 | + */ |
|
322 | + public function setEnabled(bool $enabled): void |
|
323 | + { |
|
324 | + $this->enabled = $enabled ? 1 : 0; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * @return bool |
|
329 | + */ |
|
330 | + public function isDefault(): bool |
|
331 | + { |
|
332 | + return $this->isdefault == 1; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * @param bool $isDefault |
|
337 | + */ |
|
338 | + public function setDefault(bool $isDefault): void |
|
339 | + { |
|
340 | + $this->isdefault = $isDefault ? 1 : 0; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @return bool |
|
345 | + */ |
|
346 | + public function isDefaultAntispoof(): bool |
|
347 | + { |
|
348 | + return $this->defaultantispoof == 1; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * @param bool $isDefault |
|
353 | + */ |
|
354 | + public function setDefaultAntispoof(bool $isDefault): void |
|
355 | + { |
|
356 | + $this->defaultantispoof = $isDefault ? 1 : 0; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * @return bool |
|
361 | + */ |
|
362 | + public function isDefaultTitleBlacklist(): bool |
|
363 | + { |
|
364 | + return $this->defaulttitleblacklist == 1; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @param bool $isDefault |
|
369 | + */ |
|
370 | + public function setDefaultTitleBlacklist(bool $isDefault): void |
|
371 | + { |
|
372 | + $this->defaulttitleblacklist = $isDefault ? 1 : 0; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * @return int |
|
377 | + */ |
|
378 | + public function getDomain(): int |
|
379 | + { |
|
380 | + return $this->domain; |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * @param int $domain |
|
385 | + */ |
|
386 | + public function setDomain(int $domain): void |
|
387 | + { |
|
388 | + $this->domain = $domain; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public function getApiName(): string |
|
395 | + { |
|
396 | + return $this->apiname; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * @param string $apiName |
|
401 | + */ |
|
402 | + public function setApiName(string $apiName): void |
|
403 | + { |
|
404 | + $this->apiname = $apiName; |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * @return string |
|
409 | + */ |
|
410 | + public function getDisplayName(): string |
|
411 | + { |
|
412 | + return $this->displayname; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $displayName |
|
417 | + */ |
|
418 | + public function setDisplayName(string $displayName): void |
|
419 | + { |
|
420 | + $this->displayname = $displayName; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function getHeader(): string |
|
427 | + { |
|
428 | + return $this->header; |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * @param string $header |
|
433 | + */ |
|
434 | + public function setHeader(string $header): void |
|
435 | + { |
|
436 | + $this->header = $header; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @return string|null |
|
441 | + */ |
|
442 | + public function getHelp(): ?string |
|
443 | + { |
|
444 | + return $this->help; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * @param string|null $help |
|
449 | + */ |
|
450 | + public function setHelp(?string $help): void |
|
451 | + { |
|
452 | + $this->help = $help; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * @return string |
|
457 | + * @deprecated |
|
458 | + */ |
|
459 | + public function getLogName(): string |
|
460 | + { |
|
461 | + return $this->logname; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * @param string $logName |
|
466 | + * |
|
467 | + * @deprecated |
|
468 | + */ |
|
469 | + public function setLogName(string $logName): void |
|
470 | + { |
|
471 | + $this->logname = $logName; |
|
472 | + } |
|
473 | 473 | } |
474 | 474 | \ No newline at end of file |
@@ -258,12 +258,10 @@ |
||
258 | 258 | |
259 | 259 | if ($statement->execute()) { |
260 | 260 | $this->id = (int)$this->dbObject->lastInsertId(); |
261 | - } |
|
262 | - else { |
|
261 | + } else { |
|
263 | 262 | throw new Exception($statement->errorInfo()); |
264 | 263 | } |
265 | - } |
|
266 | - else { |
|
264 | + } else { |
|
267 | 265 | $statement = $this->dbObject->prepare(<<<SQL |
268 | 266 | UPDATE requestqueue SET |
269 | 267 | enabled = :enabled, |
@@ -52,12 +52,10 @@ discard block |
||
52 | 52 | |
53 | 53 | if ($domain === false) { |
54 | 54 | self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
55 | - } |
|
56 | - else { |
|
55 | + } else { |
|
57 | 56 | self::$currentDomain = $domain; |
58 | 57 | } |
59 | - } |
|
60 | - else { |
|
58 | + } else { |
|
61 | 59 | self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
62 | 60 | } |
63 | 61 | } |
@@ -86,7 +84,8 @@ discard block |
||
86 | 84 | return $result; |
87 | 85 | } |
88 | 86 | |
89 | - public static function getAll(PdoDatabase $database) { |
|
87 | + public static function getAll(PdoDatabase $database) |
|
88 | + { |
|
90 | 89 | $statement = $database->prepare("SELECT * FROM domain;"); |
91 | 90 | $statement->execute(); |
92 | 91 | |
@@ -155,12 +154,10 @@ discard block |
||
155 | 154 | |
156 | 155 | if ($statement->execute()) { |
157 | 156 | $this->id = (int)$this->dbObject->lastInsertId(); |
158 | - } |
|
159 | - else { |
|
157 | + } else { |
|
160 | 158 | throw new Exception($statement->errorInfo()); |
161 | 159 | } |
162 | - } |
|
163 | - else { |
|
160 | + } else { |
|
164 | 161 | $statement = $this->dbObject->prepare(<<<SQL |
165 | 162 | UPDATE domain SET |
166 | 163 | longname = :longname, |
@@ -18,94 +18,94 @@ discard block |
||
18 | 18 | |
19 | 19 | class Domain extends DataObject |
20 | 20 | { |
21 | - /** @var string */ |
|
22 | - private $shortname; |
|
23 | - /** @var string */ |
|
24 | - private $longname; |
|
25 | - /** @var string */ |
|
26 | - private $wikiarticlepath; |
|
27 | - /** @var string */ |
|
28 | - private $wikiapipath; |
|
29 | - /** @var int */ |
|
30 | - private $enabled = 0; |
|
31 | - /** @var int|null */ |
|
32 | - private $defaultclose; |
|
33 | - /** @var string */ |
|
34 | - private $defaultlanguage = 'en'; |
|
35 | - /** @var string */ |
|
36 | - private $emailreplyaddress; |
|
37 | - /** @var string|null */ |
|
38 | - private $notificationtarget; |
|
39 | - /** @var string */ |
|
40 | - private $localdocumentation; |
|
41 | - |
|
42 | - /** @var Domain Cache variable of the current domain */ |
|
43 | - private static $currentDomain; |
|
44 | - |
|
45 | - public static function getCurrent(PdoDatabase $database) |
|
46 | - { |
|
47 | - if (self::$currentDomain === null) { |
|
48 | - $sessionDomain = WebRequest::getSessionDomain(); |
|
49 | - |
|
50 | - if ($sessionDomain !== null) { |
|
51 | - /** @var Domain $domain */ |
|
52 | - $domain = self::getById($sessionDomain, $database); |
|
53 | - |
|
54 | - if ($domain === false) { |
|
55 | - self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
56 | - } |
|
57 | - else { |
|
58 | - self::$currentDomain = $domain; |
|
59 | - } |
|
60 | - } |
|
61 | - else { |
|
62 | - self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - return self::$currentDomain; |
|
67 | - } |
|
68 | - |
|
69 | - public static function getByShortName(string $shortName, PdoDatabase $database) |
|
70 | - { |
|
71 | - $statement = $database->prepare(<<<SQL |
|
21 | + /** @var string */ |
|
22 | + private $shortname; |
|
23 | + /** @var string */ |
|
24 | + private $longname; |
|
25 | + /** @var string */ |
|
26 | + private $wikiarticlepath; |
|
27 | + /** @var string */ |
|
28 | + private $wikiapipath; |
|
29 | + /** @var int */ |
|
30 | + private $enabled = 0; |
|
31 | + /** @var int|null */ |
|
32 | + private $defaultclose; |
|
33 | + /** @var string */ |
|
34 | + private $defaultlanguage = 'en'; |
|
35 | + /** @var string */ |
|
36 | + private $emailreplyaddress; |
|
37 | + /** @var string|null */ |
|
38 | + private $notificationtarget; |
|
39 | + /** @var string */ |
|
40 | + private $localdocumentation; |
|
41 | + |
|
42 | + /** @var Domain Cache variable of the current domain */ |
|
43 | + private static $currentDomain; |
|
44 | + |
|
45 | + public static function getCurrent(PdoDatabase $database) |
|
46 | + { |
|
47 | + if (self::$currentDomain === null) { |
|
48 | + $sessionDomain = WebRequest::getSessionDomain(); |
|
49 | + |
|
50 | + if ($sessionDomain !== null) { |
|
51 | + /** @var Domain $domain */ |
|
52 | + $domain = self::getById($sessionDomain, $database); |
|
53 | + |
|
54 | + if ($domain === false) { |
|
55 | + self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
56 | + } |
|
57 | + else { |
|
58 | + self::$currentDomain = $domain; |
|
59 | + } |
|
60 | + } |
|
61 | + else { |
|
62 | + self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + return self::$currentDomain; |
|
67 | + } |
|
68 | + |
|
69 | + public static function getByShortName(string $shortName, PdoDatabase $database) |
|
70 | + { |
|
71 | + $statement = $database->prepare(<<<SQL |
|
72 | 72 | SELECT * FROM domain WHERE shortname = :name; |
73 | 73 | SQL |
74 | - ); |
|
74 | + ); |
|
75 | 75 | |
76 | - $statement->execute([ |
|
77 | - ':name' => $shortName, |
|
78 | - ]); |
|
76 | + $statement->execute([ |
|
77 | + ':name' => $shortName, |
|
78 | + ]); |
|
79 | 79 | |
80 | - /** @var RequestForm|false $result */ |
|
81 | - $result = $statement->fetchObject(get_called_class()); |
|
80 | + /** @var RequestForm|false $result */ |
|
81 | + $result = $statement->fetchObject(get_called_class()); |
|
82 | 82 | |
83 | - if ($result !== false) { |
|
84 | - $result->setDatabase($database); |
|
85 | - } |
|
83 | + if ($result !== false) { |
|
84 | + $result->setDatabase($database); |
|
85 | + } |
|
86 | 86 | |
87 | - return $result; |
|
88 | - } |
|
87 | + return $result; |
|
88 | + } |
|
89 | 89 | |
90 | - public static function getAll(PdoDatabase $database) { |
|
91 | - $statement = $database->prepare("SELECT * FROM domain;"); |
|
92 | - $statement->execute(); |
|
90 | + public static function getAll(PdoDatabase $database) { |
|
91 | + $statement = $database->prepare("SELECT * FROM domain;"); |
|
92 | + $statement->execute(); |
|
93 | 93 | |
94 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
94 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
95 | 95 | |
96 | - /** @var Domain $t */ |
|
97 | - foreach ($resultObject as $t) { |
|
98 | - $t->setDatabase($database); |
|
99 | - } |
|
96 | + /** @var Domain $t */ |
|
97 | + foreach ($resultObject as $t) { |
|
98 | + $t->setDatabase($database); |
|
99 | + } |
|
100 | 100 | |
101 | - return $resultObject; |
|
102 | - } |
|
101 | + return $resultObject; |
|
102 | + } |
|
103 | 103 | |
104 | - public function save() |
|
105 | - { |
|
106 | - if ($this->isNew()) { |
|
107 | - // insert |
|
108 | - $statement = $this->dbObject->prepare(<<<SQL |
|
104 | + public function save() |
|
105 | + { |
|
106 | + if ($this->isNew()) { |
|
107 | + // insert |
|
108 | + $statement = $this->dbObject->prepare(<<<SQL |
|
109 | 109 | INSERT INTO domain ( |
110 | 110 | shortname, longname, wikiarticlepath, wikiapipath, enabled, defaultclose, defaultlanguage, |
111 | 111 | emailreplyaddress, notificationtarget, localdocumentation |
@@ -114,29 +114,29 @@ discard block |
||
114 | 114 | :emailreplyaddress, :notificationtarget, :localdocumentation |
115 | 115 | ); |
116 | 116 | SQL |
117 | - ); |
|
118 | - |
|
119 | - $statement->bindValue(":shortname", $this->shortname); |
|
120 | - $statement->bindValue(":longname", $this->longname); |
|
121 | - $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
122 | - $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
123 | - $statement->bindValue(":enabled", $this->enabled); |
|
124 | - $statement->bindValue(":defaultclose", $this->defaultclose); |
|
125 | - $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
126 | - $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
127 | - $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
128 | - $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
129 | - |
|
130 | - |
|
131 | - if ($statement->execute()) { |
|
132 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
133 | - } |
|
134 | - else { |
|
135 | - throw new Exception($statement->errorInfo()); |
|
136 | - } |
|
137 | - } |
|
138 | - else { |
|
139 | - $statement = $this->dbObject->prepare(<<<SQL |
|
117 | + ); |
|
118 | + |
|
119 | + $statement->bindValue(":shortname", $this->shortname); |
|
120 | + $statement->bindValue(":longname", $this->longname); |
|
121 | + $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
122 | + $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
123 | + $statement->bindValue(":enabled", $this->enabled); |
|
124 | + $statement->bindValue(":defaultclose", $this->defaultclose); |
|
125 | + $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
126 | + $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
127 | + $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
128 | + $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
129 | + |
|
130 | + |
|
131 | + if ($statement->execute()) { |
|
132 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
133 | + } |
|
134 | + else { |
|
135 | + throw new Exception($statement->errorInfo()); |
|
136 | + } |
|
137 | + } |
|
138 | + else { |
|
139 | + $statement = $this->dbObject->prepare(<<<SQL |
|
140 | 140 | UPDATE domain SET |
141 | 141 | longname = :longname, |
142 | 142 | wikiarticlepath = :wikiarticlepath, |
@@ -151,190 +151,190 @@ discard block |
||
151 | 151 | updateversion = updateversion + 1 |
152 | 152 | WHERE id = :id AND updateversion = :updateversion; |
153 | 153 | SQL |
154 | - ); |
|
155 | - |
|
156 | - $statement->bindValue(":longname", $this->longname); |
|
157 | - $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
158 | - $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
159 | - $statement->bindValue(":enabled", $this->enabled); |
|
160 | - $statement->bindValue(":defaultclose", $this->defaultclose); |
|
161 | - $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
162 | - $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
163 | - $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
164 | - $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
165 | - |
|
166 | - $statement->bindValue(':id', $this->id); |
|
167 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
168 | - |
|
169 | - if (!$statement->execute()) { |
|
170 | - throw new Exception($statement->errorInfo()); |
|
171 | - } |
|
172 | - |
|
173 | - if ($statement->rowCount() !== 1) { |
|
174 | - throw new OptimisticLockFailedException(); |
|
175 | - } |
|
176 | - |
|
177 | - $this->updateversion++; |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function getShortName(): string |
|
185 | - { |
|
186 | - return $this->shortname; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @param string $shortName |
|
191 | - */ |
|
192 | - public function setShortName(string $shortName): void |
|
193 | - { |
|
194 | - $this->shortname = $shortName; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - public function getLongName(): string |
|
201 | - { |
|
202 | - return $this->longname; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * @param string $longName |
|
207 | - */ |
|
208 | - public function setLongName(string $longName): void |
|
209 | - { |
|
210 | - $this->longname = $longName; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public function getWikiArticlePath(): string |
|
217 | - { |
|
218 | - return $this->wikiarticlepath; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $wikiArticlePath |
|
223 | - */ |
|
224 | - public function setWikiArticlePath(string $wikiArticlePath): void |
|
225 | - { |
|
226 | - $this->wikiarticlepath = $wikiArticlePath; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @return string |
|
231 | - */ |
|
232 | - public function getWikiApiPath(): string |
|
233 | - { |
|
234 | - return $this->wikiapipath; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string $wikiApiPath |
|
239 | - */ |
|
240 | - public function setWikiApiPath(string $wikiApiPath): void |
|
241 | - { |
|
242 | - $this->wikiapipath = $wikiApiPath; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function isEnabled(): bool |
|
249 | - { |
|
250 | - return $this->enabled == 1; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @param bool $enabled |
|
255 | - */ |
|
256 | - public function setEnabled(bool $enabled): void |
|
257 | - { |
|
258 | - $this->enabled = $enabled ? 1 : 0; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * @return int |
|
263 | - */ |
|
264 | - public function getDefaultClose(): ?int |
|
265 | - { |
|
266 | - return $this->defaultclose; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * @param int $defaultClose |
|
271 | - */ |
|
272 | - public function setDefaultClose(?int $defaultClose): void |
|
273 | - { |
|
274 | - $this->defaultclose = $defaultClose; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function getDefaultLanguage(): string |
|
281 | - { |
|
282 | - return $this->defaultlanguage; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * @param string $defaultLanguage |
|
287 | - */ |
|
288 | - public function setDefaultLanguage(string $defaultLanguage): void |
|
289 | - { |
|
290 | - $this->defaultlanguage = $defaultLanguage; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function getEmailReplyAddress(): string |
|
297 | - { |
|
298 | - return $this->emailreplyaddress; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @param string $emailReplyAddress |
|
303 | - */ |
|
304 | - public function setEmailReplyAddress(string $emailReplyAddress): void |
|
305 | - { |
|
306 | - $this->emailreplyaddress = $emailReplyAddress; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * @return string|null |
|
311 | - */ |
|
312 | - public function getNotificationTarget(): ?string |
|
313 | - { |
|
314 | - return $this->notificationtarget; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @param string|null $notificationTarget |
|
319 | - */ |
|
320 | - public function setNotificationTarget(?string $notificationTarget): void |
|
321 | - { |
|
322 | - $this->notificationtarget = $notificationTarget; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public function getLocalDocumentation(): string |
|
329 | - { |
|
330 | - return $this->localdocumentation; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @param string $localDocumentation |
|
335 | - */ |
|
336 | - public function setLocalDocumentation(string $localDocumentation): void |
|
337 | - { |
|
338 | - $this->localdocumentation = $localDocumentation; |
|
339 | - } |
|
154 | + ); |
|
155 | + |
|
156 | + $statement->bindValue(":longname", $this->longname); |
|
157 | + $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
158 | + $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
159 | + $statement->bindValue(":enabled", $this->enabled); |
|
160 | + $statement->bindValue(":defaultclose", $this->defaultclose); |
|
161 | + $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
162 | + $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
163 | + $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
164 | + $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
165 | + |
|
166 | + $statement->bindValue(':id', $this->id); |
|
167 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
168 | + |
|
169 | + if (!$statement->execute()) { |
|
170 | + throw new Exception($statement->errorInfo()); |
|
171 | + } |
|
172 | + |
|
173 | + if ($statement->rowCount() !== 1) { |
|
174 | + throw new OptimisticLockFailedException(); |
|
175 | + } |
|
176 | + |
|
177 | + $this->updateversion++; |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function getShortName(): string |
|
185 | + { |
|
186 | + return $this->shortname; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @param string $shortName |
|
191 | + */ |
|
192 | + public function setShortName(string $shortName): void |
|
193 | + { |
|
194 | + $this->shortname = $shortName; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + public function getLongName(): string |
|
201 | + { |
|
202 | + return $this->longname; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * @param string $longName |
|
207 | + */ |
|
208 | + public function setLongName(string $longName): void |
|
209 | + { |
|
210 | + $this->longname = $longName; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public function getWikiArticlePath(): string |
|
217 | + { |
|
218 | + return $this->wikiarticlepath; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @param string $wikiArticlePath |
|
223 | + */ |
|
224 | + public function setWikiArticlePath(string $wikiArticlePath): void |
|
225 | + { |
|
226 | + $this->wikiarticlepath = $wikiArticlePath; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @return string |
|
231 | + */ |
|
232 | + public function getWikiApiPath(): string |
|
233 | + { |
|
234 | + return $this->wikiapipath; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string $wikiApiPath |
|
239 | + */ |
|
240 | + public function setWikiApiPath(string $wikiApiPath): void |
|
241 | + { |
|
242 | + $this->wikiapipath = $wikiApiPath; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function isEnabled(): bool |
|
249 | + { |
|
250 | + return $this->enabled == 1; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @param bool $enabled |
|
255 | + */ |
|
256 | + public function setEnabled(bool $enabled): void |
|
257 | + { |
|
258 | + $this->enabled = $enabled ? 1 : 0; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * @return int |
|
263 | + */ |
|
264 | + public function getDefaultClose(): ?int |
|
265 | + { |
|
266 | + return $this->defaultclose; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * @param int $defaultClose |
|
271 | + */ |
|
272 | + public function setDefaultClose(?int $defaultClose): void |
|
273 | + { |
|
274 | + $this->defaultclose = $defaultClose; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function getDefaultLanguage(): string |
|
281 | + { |
|
282 | + return $this->defaultlanguage; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * @param string $defaultLanguage |
|
287 | + */ |
|
288 | + public function setDefaultLanguage(string $defaultLanguage): void |
|
289 | + { |
|
290 | + $this->defaultlanguage = $defaultLanguage; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function getEmailReplyAddress(): string |
|
297 | + { |
|
298 | + return $this->emailreplyaddress; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @param string $emailReplyAddress |
|
303 | + */ |
|
304 | + public function setEmailReplyAddress(string $emailReplyAddress): void |
|
305 | + { |
|
306 | + $this->emailreplyaddress = $emailReplyAddress; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * @return string|null |
|
311 | + */ |
|
312 | + public function getNotificationTarget(): ?string |
|
313 | + { |
|
314 | + return $this->notificationtarget; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @param string|null $notificationTarget |
|
319 | + */ |
|
320 | + public function setNotificationTarget(?string $notificationTarget): void |
|
321 | + { |
|
322 | + $this->notificationtarget = $notificationTarget; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public function getLocalDocumentation(): string |
|
329 | + { |
|
330 | + return $this->localdocumentation; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @param string $localDocumentation |
|
335 | + */ |
|
336 | + public function setLocalDocumentation(string $localDocumentation): void |
|
337 | + { |
|
338 | + $this->localdocumentation = $localDocumentation; |
|
339 | + } |
|
340 | 340 | } |
341 | 341 | \ No newline at end of file |
@@ -24,378 +24,378 @@ |
||
24 | 24 | |
25 | 25 | abstract class PageBase extends TaskBase implements IRoutedTask |
26 | 26 | { |
27 | - use TemplateOutput; |
|
28 | - /** @var string Smarty template to display */ |
|
29 | - protected $template = "base.tpl"; |
|
30 | - /** @var string HTML title. Currently unused. */ |
|
31 | - protected $htmlTitle; |
|
32 | - /** @var bool Determines if the page is a redirect or not */ |
|
33 | - protected $isRedirecting = false; |
|
34 | - /** @var array Queue of headers to be sent on successful completion */ |
|
35 | - protected $headerQueue = array(); |
|
36 | - /** @var string The name of the route to use, as determined by the request router. */ |
|
37 | - private $routeName = null; |
|
38 | - /** @var TokenManager */ |
|
39 | - protected $tokenManager; |
|
40 | - /** @var ContentSecurityPolicyManager */ |
|
41 | - private $cspManager; |
|
42 | - /** @var string[] Extra JS files to include */ |
|
43 | - private $extraJs = array(); |
|
44 | - /** @var bool Don't show (and hence clear) session alerts when this page is displayed */ |
|
45 | - private $hideAlerts = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
49 | - * |
|
50 | - * @param string $routeName The name of the route |
|
51 | - * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
52 | - * |
|
53 | - * @throws Exception |
|
54 | - * @category Security-Critical |
|
55 | - */ |
|
56 | - final public function setRoute($routeName, $skipCallableTest = false) |
|
57 | - { |
|
58 | - // Test the new route is callable before adopting it. |
|
59 | - if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
60 | - throw new Exception("Proposed route '$routeName' is not callable."); |
|
61 | - } |
|
62 | - |
|
63 | - // Adopt the new route |
|
64 | - $this->routeName = $routeName; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Gets the name of the route that has been passed from the request router. |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - final public function getRouteName() |
|
72 | - { |
|
73 | - return $this->routeName; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Performs generic page setup actions |
|
78 | - */ |
|
79 | - final protected function setupPage() |
|
80 | - { |
|
81 | - $this->setUpSmarty(); |
|
82 | - |
|
83 | - $database = $this->getDatabase(); |
|
84 | - $currentUser = User::getCurrent($database); |
|
85 | - $this->assign('currentUser', $currentUser); |
|
86 | - $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN)); |
|
87 | - $this->assign('currentDomain', Domain::getCurrent($database)); |
|
88 | - $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Runs the page logic as routed by the RequestRouter |
|
93 | - * |
|
94 | - * Only should be called after a security barrier! That means only from execute(). |
|
95 | - */ |
|
96 | - final protected function runPage() |
|
97 | - { |
|
98 | - $database = $this->getDatabase(); |
|
99 | - |
|
100 | - // initialise a database transaction |
|
101 | - if (!$database->beginTransaction()) { |
|
102 | - throw new Exception('Failed to start transaction on primary database.'); |
|
103 | - } |
|
104 | - |
|
105 | - try { |
|
106 | - // run the page code |
|
107 | - $this->{$this->getRouteName()}(); |
|
108 | - |
|
109 | - $database->commit(); |
|
110 | - } |
|
111 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
112 | - catch (ApplicationLogicException $ex) { |
|
113 | - // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
114 | - // standard templating system for this. |
|
115 | - |
|
116 | - // Firstly, let's undo anything that happened to the database. |
|
117 | - $database->rollBack(); |
|
118 | - |
|
119 | - // Reset smarty |
|
120 | - $this->setupPage(); |
|
121 | - |
|
122 | - $this->skipAlerts(); |
|
123 | - |
|
124 | - // Set the template |
|
125 | - $this->setTemplate('exception/application-logic.tpl'); |
|
126 | - $this->assign('message', $ex->getMessage()); |
|
127 | - |
|
128 | - // Force this back to false |
|
129 | - $this->isRedirecting = false; |
|
130 | - $this->headerQueue = array(); |
|
131 | - } |
|
132 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
133 | - catch (OptimisticLockFailedException $ex) { |
|
134 | - // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
135 | - // standard templating system for this. |
|
136 | - |
|
137 | - // Firstly, let's undo anything that happened to the database. |
|
138 | - $database->rollBack(); |
|
139 | - |
|
140 | - // Reset smarty |
|
141 | - $this->setupPage(); |
|
142 | - |
|
143 | - // Set the template |
|
144 | - $this->skipAlerts(); |
|
145 | - $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
146 | - $this->assign('message', $ex->getMessage()); |
|
147 | - |
|
148 | - $this->assign('debugTrace', false); |
|
149 | - |
|
150 | - if ($this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
151 | - ob_start(); |
|
152 | - var_dump(ExceptionHandler::getExceptionData($ex)); |
|
153 | - $textErrorData = ob_get_contents(); |
|
154 | - ob_end_clean(); |
|
155 | - |
|
156 | - $this->assign('exceptionData', $textErrorData); |
|
157 | - $this->assign('debugTrace', true); |
|
158 | - } |
|
159 | - |
|
160 | - // Force this back to false |
|
161 | - $this->isRedirecting = false; |
|
162 | - $this->headerQueue = array(); |
|
163 | - } |
|
164 | - finally { |
|
165 | - // Catch any hanging on transactions |
|
166 | - if ($database->hasActiveTransaction()) { |
|
167 | - $database->rollBack(); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - // run any finalisation code needed before we send the output to the browser. |
|
172 | - $this->finalisePage(); |
|
173 | - |
|
174 | - // Send the headers |
|
175 | - $this->sendResponseHeaders(); |
|
176 | - |
|
177 | - // Check we have a template to use! |
|
178 | - if ($this->template !== null) { |
|
179 | - $content = $this->fetchTemplate($this->template); |
|
180 | - ob_clean(); |
|
181 | - print($content); |
|
182 | - ob_flush(); |
|
183 | - |
|
184 | - return; |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Performs final tasks needed before rendering the page. |
|
190 | - */ |
|
191 | - protected function finalisePage() |
|
192 | - { |
|
193 | - if ($this->isRedirecting) { |
|
194 | - $this->template = null; |
|
195 | - |
|
196 | - return; |
|
197 | - } |
|
198 | - |
|
199 | - $this->assign('extraJs', $this->extraJs); |
|
200 | - |
|
201 | - if (!$this->hideAlerts) { |
|
202 | - // If we're actually displaying content, we want to add the session alerts here! |
|
203 | - $this->assign('alerts', SessionAlert::getAlerts()); |
|
204 | - SessionAlert::clearAlerts(); |
|
205 | - } |
|
206 | - |
|
207 | - $this->assign('htmlTitle', $this->htmlTitle); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @return TokenManager |
|
212 | - */ |
|
213 | - public function getTokenManager() |
|
214 | - { |
|
215 | - return $this->tokenManager; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @param TokenManager $tokenManager |
|
220 | - */ |
|
221 | - public function setTokenManager($tokenManager) |
|
222 | - { |
|
223 | - $this->tokenManager = $tokenManager; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return ContentSecurityPolicyManager |
|
228 | - */ |
|
229 | - public function getCspManager(): ContentSecurityPolicyManager |
|
230 | - { |
|
231 | - return $this->cspManager; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @param ContentSecurityPolicyManager $cspManager |
|
236 | - */ |
|
237 | - public function setCspManager(ContentSecurityPolicyManager $cspManager): void |
|
238 | - { |
|
239 | - $this->cspManager = $cspManager; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Skip the display of session alerts in this page |
|
244 | - */ |
|
245 | - public function skipAlerts(): void |
|
246 | - { |
|
247 | - $this->hideAlerts = true; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Sends the redirect headers to perform a GET at the destination page. |
|
252 | - * |
|
253 | - * Also nullifies the set template so Smarty does not render it. |
|
254 | - * |
|
255 | - * @param string $page The page to redirect requests to (as used in the UR) |
|
256 | - * @param null|string $action The action to use on the page. |
|
257 | - * @param null|array $parameters |
|
258 | - * @param null|string $script The script (relative to index.php) to redirect to |
|
259 | - */ |
|
260 | - final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
261 | - { |
|
262 | - $currentScriptName = WebRequest::scriptName(); |
|
263 | - |
|
264 | - // Are we changing script? |
|
265 | - if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
266 | - $targetScriptName = $currentScriptName; |
|
267 | - } |
|
268 | - else { |
|
269 | - $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
270 | - } |
|
271 | - |
|
272 | - $pathInfo = array($targetScriptName); |
|
273 | - |
|
274 | - $pathInfo[1] = $page; |
|
275 | - |
|
276 | - if ($action !== null) { |
|
277 | - $pathInfo[2] = $action; |
|
278 | - } |
|
279 | - |
|
280 | - $url = implode('/', $pathInfo); |
|
281 | - |
|
282 | - if (is_array($parameters) && count($parameters) > 0) { |
|
283 | - $url .= '?' . http_build_query($parameters); |
|
284 | - } |
|
285 | - |
|
286 | - $this->redirectUrl($url); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Sends the redirect headers to perform a GET at the new address. |
|
291 | - * |
|
292 | - * Also nullifies the set template so Smarty does not render it. |
|
293 | - * |
|
294 | - * @param string $path URL to redirect to |
|
295 | - */ |
|
296 | - final protected function redirectUrl($path) |
|
297 | - { |
|
298 | - // 303 See Other = re-request at new address with a GET. |
|
299 | - $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
300 | - $this->headerQueue[] = "Location: $path"; |
|
301 | - |
|
302 | - $this->setTemplate(null); |
|
303 | - $this->isRedirecting = true; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Sets the name of the template this page should display. |
|
308 | - * |
|
309 | - * @param string $name |
|
310 | - * |
|
311 | - * @throws Exception |
|
312 | - */ |
|
313 | - final protected function setTemplate($name) |
|
314 | - { |
|
315 | - if ($this->isRedirecting) { |
|
316 | - throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
317 | - } |
|
318 | - |
|
319 | - $this->template = $name; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Adds an extra JS file to to the page |
|
324 | - * |
|
325 | - * @param string $path The path (relative to the application root) of the file |
|
326 | - */ |
|
327 | - final protected function addJs($path) |
|
328 | - { |
|
329 | - if (in_array($path, $this->extraJs)) { |
|
330 | - // nothing to do |
|
331 | - return; |
|
332 | - } |
|
333 | - |
|
334 | - $this->extraJs[] = $path; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Main function for this page, when no specific actions are called. |
|
339 | - * @return void |
|
340 | - */ |
|
341 | - abstract protected function main(); |
|
342 | - |
|
343 | - /** |
|
344 | - * Takes a smarty template string and sets the HTML title to that value |
|
345 | - * |
|
346 | - * @param string $title |
|
347 | - * |
|
348 | - * @throws SmartyException |
|
349 | - */ |
|
350 | - final protected function setHtmlTitle($title) |
|
351 | - { |
|
352 | - $this->htmlTitle = $this->smarty->fetch('string:' . $title); |
|
353 | - } |
|
354 | - |
|
355 | - public function execute() |
|
356 | - { |
|
357 | - if ($this->getRouteName() === null) { |
|
358 | - throw new Exception('Request is unrouted.'); |
|
359 | - } |
|
360 | - |
|
361 | - if ($this->getSiteConfiguration() === null) { |
|
362 | - throw new Exception('Page has no configuration!'); |
|
363 | - } |
|
364 | - |
|
365 | - $this->setupPage(); |
|
366 | - |
|
367 | - $this->runPage(); |
|
368 | - } |
|
369 | - |
|
370 | - public function assignCSRFToken() |
|
371 | - { |
|
372 | - $token = $this->tokenManager->getNewToken(); |
|
373 | - $this->assign('csrfTokenData', $token->getTokenData()); |
|
374 | - } |
|
375 | - |
|
376 | - public function validateCSRFToken() |
|
377 | - { |
|
378 | - if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
379 | - throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - protected function sendResponseHeaders() |
|
384 | - { |
|
385 | - if (headers_sent()) { |
|
386 | - throw new ApplicationLogicException('Headers have already been sent! This is likely a bug in the application.'); |
|
387 | - } |
|
388 | - |
|
389 | - // send the CSP headers now |
|
390 | - header($this->getCspManager()->getHeader()); |
|
391 | - |
|
392 | - foreach ($this->headerQueue as $item) { |
|
393 | - if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
394 | - // Oops. We're not allowed to do this. |
|
395 | - throw new Exception('Unable to split header'); |
|
396 | - } |
|
397 | - |
|
398 | - header($item); |
|
399 | - } |
|
400 | - } |
|
27 | + use TemplateOutput; |
|
28 | + /** @var string Smarty template to display */ |
|
29 | + protected $template = "base.tpl"; |
|
30 | + /** @var string HTML title. Currently unused. */ |
|
31 | + protected $htmlTitle; |
|
32 | + /** @var bool Determines if the page is a redirect or not */ |
|
33 | + protected $isRedirecting = false; |
|
34 | + /** @var array Queue of headers to be sent on successful completion */ |
|
35 | + protected $headerQueue = array(); |
|
36 | + /** @var string The name of the route to use, as determined by the request router. */ |
|
37 | + private $routeName = null; |
|
38 | + /** @var TokenManager */ |
|
39 | + protected $tokenManager; |
|
40 | + /** @var ContentSecurityPolicyManager */ |
|
41 | + private $cspManager; |
|
42 | + /** @var string[] Extra JS files to include */ |
|
43 | + private $extraJs = array(); |
|
44 | + /** @var bool Don't show (and hence clear) session alerts when this page is displayed */ |
|
45 | + private $hideAlerts = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
49 | + * |
|
50 | + * @param string $routeName The name of the route |
|
51 | + * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
52 | + * |
|
53 | + * @throws Exception |
|
54 | + * @category Security-Critical |
|
55 | + */ |
|
56 | + final public function setRoute($routeName, $skipCallableTest = false) |
|
57 | + { |
|
58 | + // Test the new route is callable before adopting it. |
|
59 | + if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
60 | + throw new Exception("Proposed route '$routeName' is not callable."); |
|
61 | + } |
|
62 | + |
|
63 | + // Adopt the new route |
|
64 | + $this->routeName = $routeName; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Gets the name of the route that has been passed from the request router. |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + final public function getRouteName() |
|
72 | + { |
|
73 | + return $this->routeName; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Performs generic page setup actions |
|
78 | + */ |
|
79 | + final protected function setupPage() |
|
80 | + { |
|
81 | + $this->setUpSmarty(); |
|
82 | + |
|
83 | + $database = $this->getDatabase(); |
|
84 | + $currentUser = User::getCurrent($database); |
|
85 | + $this->assign('currentUser', $currentUser); |
|
86 | + $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN)); |
|
87 | + $this->assign('currentDomain', Domain::getCurrent($database)); |
|
88 | + $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Runs the page logic as routed by the RequestRouter |
|
93 | + * |
|
94 | + * Only should be called after a security barrier! That means only from execute(). |
|
95 | + */ |
|
96 | + final protected function runPage() |
|
97 | + { |
|
98 | + $database = $this->getDatabase(); |
|
99 | + |
|
100 | + // initialise a database transaction |
|
101 | + if (!$database->beginTransaction()) { |
|
102 | + throw new Exception('Failed to start transaction on primary database.'); |
|
103 | + } |
|
104 | + |
|
105 | + try { |
|
106 | + // run the page code |
|
107 | + $this->{$this->getRouteName()}(); |
|
108 | + |
|
109 | + $database->commit(); |
|
110 | + } |
|
111 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
112 | + catch (ApplicationLogicException $ex) { |
|
113 | + // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
114 | + // standard templating system for this. |
|
115 | + |
|
116 | + // Firstly, let's undo anything that happened to the database. |
|
117 | + $database->rollBack(); |
|
118 | + |
|
119 | + // Reset smarty |
|
120 | + $this->setupPage(); |
|
121 | + |
|
122 | + $this->skipAlerts(); |
|
123 | + |
|
124 | + // Set the template |
|
125 | + $this->setTemplate('exception/application-logic.tpl'); |
|
126 | + $this->assign('message', $ex->getMessage()); |
|
127 | + |
|
128 | + // Force this back to false |
|
129 | + $this->isRedirecting = false; |
|
130 | + $this->headerQueue = array(); |
|
131 | + } |
|
132 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
133 | + catch (OptimisticLockFailedException $ex) { |
|
134 | + // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
135 | + // standard templating system for this. |
|
136 | + |
|
137 | + // Firstly, let's undo anything that happened to the database. |
|
138 | + $database->rollBack(); |
|
139 | + |
|
140 | + // Reset smarty |
|
141 | + $this->setupPage(); |
|
142 | + |
|
143 | + // Set the template |
|
144 | + $this->skipAlerts(); |
|
145 | + $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
146 | + $this->assign('message', $ex->getMessage()); |
|
147 | + |
|
148 | + $this->assign('debugTrace', false); |
|
149 | + |
|
150 | + if ($this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
151 | + ob_start(); |
|
152 | + var_dump(ExceptionHandler::getExceptionData($ex)); |
|
153 | + $textErrorData = ob_get_contents(); |
|
154 | + ob_end_clean(); |
|
155 | + |
|
156 | + $this->assign('exceptionData', $textErrorData); |
|
157 | + $this->assign('debugTrace', true); |
|
158 | + } |
|
159 | + |
|
160 | + // Force this back to false |
|
161 | + $this->isRedirecting = false; |
|
162 | + $this->headerQueue = array(); |
|
163 | + } |
|
164 | + finally { |
|
165 | + // Catch any hanging on transactions |
|
166 | + if ($database->hasActiveTransaction()) { |
|
167 | + $database->rollBack(); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + // run any finalisation code needed before we send the output to the browser. |
|
172 | + $this->finalisePage(); |
|
173 | + |
|
174 | + // Send the headers |
|
175 | + $this->sendResponseHeaders(); |
|
176 | + |
|
177 | + // Check we have a template to use! |
|
178 | + if ($this->template !== null) { |
|
179 | + $content = $this->fetchTemplate($this->template); |
|
180 | + ob_clean(); |
|
181 | + print($content); |
|
182 | + ob_flush(); |
|
183 | + |
|
184 | + return; |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Performs final tasks needed before rendering the page. |
|
190 | + */ |
|
191 | + protected function finalisePage() |
|
192 | + { |
|
193 | + if ($this->isRedirecting) { |
|
194 | + $this->template = null; |
|
195 | + |
|
196 | + return; |
|
197 | + } |
|
198 | + |
|
199 | + $this->assign('extraJs', $this->extraJs); |
|
200 | + |
|
201 | + if (!$this->hideAlerts) { |
|
202 | + // If we're actually displaying content, we want to add the session alerts here! |
|
203 | + $this->assign('alerts', SessionAlert::getAlerts()); |
|
204 | + SessionAlert::clearAlerts(); |
|
205 | + } |
|
206 | + |
|
207 | + $this->assign('htmlTitle', $this->htmlTitle); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @return TokenManager |
|
212 | + */ |
|
213 | + public function getTokenManager() |
|
214 | + { |
|
215 | + return $this->tokenManager; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @param TokenManager $tokenManager |
|
220 | + */ |
|
221 | + public function setTokenManager($tokenManager) |
|
222 | + { |
|
223 | + $this->tokenManager = $tokenManager; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return ContentSecurityPolicyManager |
|
228 | + */ |
|
229 | + public function getCspManager(): ContentSecurityPolicyManager |
|
230 | + { |
|
231 | + return $this->cspManager; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @param ContentSecurityPolicyManager $cspManager |
|
236 | + */ |
|
237 | + public function setCspManager(ContentSecurityPolicyManager $cspManager): void |
|
238 | + { |
|
239 | + $this->cspManager = $cspManager; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Skip the display of session alerts in this page |
|
244 | + */ |
|
245 | + public function skipAlerts(): void |
|
246 | + { |
|
247 | + $this->hideAlerts = true; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Sends the redirect headers to perform a GET at the destination page. |
|
252 | + * |
|
253 | + * Also nullifies the set template so Smarty does not render it. |
|
254 | + * |
|
255 | + * @param string $page The page to redirect requests to (as used in the UR) |
|
256 | + * @param null|string $action The action to use on the page. |
|
257 | + * @param null|array $parameters |
|
258 | + * @param null|string $script The script (relative to index.php) to redirect to |
|
259 | + */ |
|
260 | + final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
261 | + { |
|
262 | + $currentScriptName = WebRequest::scriptName(); |
|
263 | + |
|
264 | + // Are we changing script? |
|
265 | + if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
266 | + $targetScriptName = $currentScriptName; |
|
267 | + } |
|
268 | + else { |
|
269 | + $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
270 | + } |
|
271 | + |
|
272 | + $pathInfo = array($targetScriptName); |
|
273 | + |
|
274 | + $pathInfo[1] = $page; |
|
275 | + |
|
276 | + if ($action !== null) { |
|
277 | + $pathInfo[2] = $action; |
|
278 | + } |
|
279 | + |
|
280 | + $url = implode('/', $pathInfo); |
|
281 | + |
|
282 | + if (is_array($parameters) && count($parameters) > 0) { |
|
283 | + $url .= '?' . http_build_query($parameters); |
|
284 | + } |
|
285 | + |
|
286 | + $this->redirectUrl($url); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Sends the redirect headers to perform a GET at the new address. |
|
291 | + * |
|
292 | + * Also nullifies the set template so Smarty does not render it. |
|
293 | + * |
|
294 | + * @param string $path URL to redirect to |
|
295 | + */ |
|
296 | + final protected function redirectUrl($path) |
|
297 | + { |
|
298 | + // 303 See Other = re-request at new address with a GET. |
|
299 | + $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
300 | + $this->headerQueue[] = "Location: $path"; |
|
301 | + |
|
302 | + $this->setTemplate(null); |
|
303 | + $this->isRedirecting = true; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Sets the name of the template this page should display. |
|
308 | + * |
|
309 | + * @param string $name |
|
310 | + * |
|
311 | + * @throws Exception |
|
312 | + */ |
|
313 | + final protected function setTemplate($name) |
|
314 | + { |
|
315 | + if ($this->isRedirecting) { |
|
316 | + throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
317 | + } |
|
318 | + |
|
319 | + $this->template = $name; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Adds an extra JS file to to the page |
|
324 | + * |
|
325 | + * @param string $path The path (relative to the application root) of the file |
|
326 | + */ |
|
327 | + final protected function addJs($path) |
|
328 | + { |
|
329 | + if (in_array($path, $this->extraJs)) { |
|
330 | + // nothing to do |
|
331 | + return; |
|
332 | + } |
|
333 | + |
|
334 | + $this->extraJs[] = $path; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Main function for this page, when no specific actions are called. |
|
339 | + * @return void |
|
340 | + */ |
|
341 | + abstract protected function main(); |
|
342 | + |
|
343 | + /** |
|
344 | + * Takes a smarty template string and sets the HTML title to that value |
|
345 | + * |
|
346 | + * @param string $title |
|
347 | + * |
|
348 | + * @throws SmartyException |
|
349 | + */ |
|
350 | + final protected function setHtmlTitle($title) |
|
351 | + { |
|
352 | + $this->htmlTitle = $this->smarty->fetch('string:' . $title); |
|
353 | + } |
|
354 | + |
|
355 | + public function execute() |
|
356 | + { |
|
357 | + if ($this->getRouteName() === null) { |
|
358 | + throw new Exception('Request is unrouted.'); |
|
359 | + } |
|
360 | + |
|
361 | + if ($this->getSiteConfiguration() === null) { |
|
362 | + throw new Exception('Page has no configuration!'); |
|
363 | + } |
|
364 | + |
|
365 | + $this->setupPage(); |
|
366 | + |
|
367 | + $this->runPage(); |
|
368 | + } |
|
369 | + |
|
370 | + public function assignCSRFToken() |
|
371 | + { |
|
372 | + $token = $this->tokenManager->getNewToken(); |
|
373 | + $this->assign('csrfTokenData', $token->getTokenData()); |
|
374 | + } |
|
375 | + |
|
376 | + public function validateCSRFToken() |
|
377 | + { |
|
378 | + if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
379 | + throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + protected function sendResponseHeaders() |
|
384 | + { |
|
385 | + if (headers_sent()) { |
|
386 | + throw new ApplicationLogicException('Headers have already been sent! This is likely a bug in the application.'); |
|
387 | + } |
|
388 | + |
|
389 | + // send the CSP headers now |
|
390 | + header($this->getCspManager()->getHeader()); |
|
391 | + |
|
392 | + foreach ($this->headerQueue as $item) { |
|
393 | + if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
394 | + // Oops. We're not allowed to do this. |
|
395 | + throw new Exception('Unable to split header'); |
|
396 | + } |
|
397 | + |
|
398 | + header($item); |
|
399 | + } |
|
400 | + } |
|
401 | 401 | } |
@@ -264,8 +264,7 @@ |
||
264 | 264 | // Are we changing script? |
265 | 265 | if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
266 | 266 | $targetScriptName = $currentScriptName; |
267 | - } |
|
268 | - else { |
|
267 | + } else { |
|
269 | 268 | $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
270 | 269 | } |
271 | 270 |
@@ -14,69 +14,69 @@ |
||
14 | 14 | |
15 | 15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
16 | 16 | { |
17 | - /** |
|
18 | - * Main function for this page, when no specific actions are called. |
|
19 | - * |
|
20 | - * @return void |
|
21 | - * @throws ApiException |
|
22 | - */ |
|
23 | - final protected function main() |
|
24 | - { |
|
25 | - if (headers_sent()) { |
|
26 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | - } |
|
17 | + /** |
|
18 | + * Main function for this page, when no specific actions are called. |
|
19 | + * |
|
20 | + * @return void |
|
21 | + * @throws ApiException |
|
22 | + */ |
|
23 | + final protected function main() |
|
24 | + { |
|
25 | + if (headers_sent()) { |
|
26 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | + } |
|
28 | 28 | |
29 | - // javascript access control |
|
30 | - $httpOrigin = WebRequest::origin(); |
|
29 | + // javascript access control |
|
30 | + $httpOrigin = WebRequest::origin(); |
|
31 | 31 | |
32 | - if ($httpOrigin !== null) { |
|
33 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
32 | + if ($httpOrigin !== null) { |
|
33 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
34 | 34 | |
35 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | - } |
|
38 | - } |
|
35 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - $responseData = $this->runApiPage(); |
|
40 | + $responseData = $this->runApiPage(); |
|
41 | 41 | |
42 | - ob_end_clean(); |
|
43 | - print($responseData); |
|
44 | - ob_start(); |
|
45 | - } |
|
42 | + ob_end_clean(); |
|
43 | + print($responseData); |
|
44 | + ob_start(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Method that runs API action |
|
49 | - * |
|
50 | - * @return object|array The modified API document |
|
51 | - */ |
|
52 | - public abstract function executeApiAction(); |
|
47 | + /** |
|
48 | + * Method that runs API action |
|
49 | + * |
|
50 | + * @return object|array The modified API document |
|
51 | + */ |
|
52 | + public abstract function executeApiAction(); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - final public function runApiPage() |
|
58 | - { |
|
59 | - try { |
|
60 | - $apiDocument = $this->executeApiAction(); |
|
61 | - } |
|
62 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
63 | - catch (ApiException $ex) { |
|
64 | - $apiDocument = [ |
|
65 | - 'error' => $ex->getMessage(), |
|
66 | - ]; |
|
67 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + final public function runApiPage() |
|
58 | + { |
|
59 | + try { |
|
60 | + $apiDocument = $this->executeApiAction(); |
|
61 | + } |
|
62 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
63 | + catch (ApiException $ex) { |
|
64 | + $apiDocument = [ |
|
65 | + 'error' => $ex->getMessage(), |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
69 | + $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
70 | 70 | |
71 | - $targetVar = WebRequest::getString('targetVariable'); |
|
72 | - if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
74 | - header("Content-Type: text/javascript"); |
|
75 | - } |
|
76 | - else { |
|
77 | - header("Content-Type: application/json"); |
|
78 | - } |
|
71 | + $targetVar = WebRequest::getString('targetVariable'); |
|
72 | + if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | + $data = $targetVar . ' = ' . $data . ';'; |
|
74 | + header("Content-Type: text/javascript"); |
|
75 | + } |
|
76 | + else { |
|
77 | + header("Content-Type: application/json"); |
|
78 | + } |
|
79 | 79 | |
80 | - return $data; |
|
81 | - } |
|
80 | + return $data; |
|
81 | + } |
|
82 | 82 | } |
@@ -72,8 +72,7 @@ |
||
72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
73 | 73 | $data = $targetVar . ' = ' . $data . ';'; |
74 | 74 | header("Content-Type: text/javascript"); |
75 | - } |
|
76 | - else { |
|
75 | + } else { |
|
77 | 76 | header("Content-Type: application/json"); |
78 | 77 | } |
79 | 78 |
@@ -22,211 +22,211 @@ |
||
22 | 22 | |
23 | 23 | abstract class TaskBase implements ITask |
24 | 24 | { |
25 | - /** @var SiteConfiguration */ |
|
26 | - private $siteConfiguration; |
|
27 | - /** @var IEmailHelper */ |
|
28 | - private $emailHelper; |
|
29 | - /** @var HttpHelper */ |
|
30 | - private $httpHelper; |
|
31 | - /** @var ILocationProvider */ |
|
32 | - private $locationProvider; |
|
33 | - /** @var IXffTrustProvider */ |
|
34 | - private $xffTrustProvider; |
|
35 | - /** @var IRDnsProvider */ |
|
36 | - private $rdnsProvider; |
|
37 | - /** @var IAntiSpoofProvider */ |
|
38 | - private $antiSpoofProvider; |
|
39 | - /** @var IOAuthProtocolHelper */ |
|
40 | - private $oauthHelper; |
|
41 | - /** @var PdoDatabase */ |
|
42 | - private $database; |
|
43 | - /** @var IrcNotificationHelper */ |
|
44 | - private $notificationHelper; |
|
45 | - /** @var TorExitProvider */ |
|
46 | - private $torExitProvider; |
|
47 | - |
|
48 | - /** |
|
49 | - * @return IEmailHelper |
|
50 | - */ |
|
51 | - final public function getEmailHelper() |
|
52 | - { |
|
53 | - return $this->emailHelper; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param IEmailHelper $emailHelper |
|
58 | - */ |
|
59 | - final public function setEmailHelper($emailHelper) |
|
60 | - { |
|
61 | - $this->emailHelper = $emailHelper; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return HttpHelper |
|
66 | - */ |
|
67 | - final public function getHttpHelper() |
|
68 | - { |
|
69 | - return $this->httpHelper; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param HttpHelper $httpHelper |
|
74 | - */ |
|
75 | - final public function setHttpHelper($httpHelper) |
|
76 | - { |
|
77 | - $this->httpHelper = $httpHelper; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return ILocationProvider |
|
82 | - */ |
|
83 | - final public function getLocationProvider() |
|
84 | - { |
|
85 | - return $this->locationProvider; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param ILocationProvider $locationProvider |
|
90 | - */ |
|
91 | - final public function setLocationProvider(ILocationProvider $locationProvider) |
|
92 | - { |
|
93 | - $this->locationProvider = $locationProvider; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return IXffTrustProvider |
|
98 | - */ |
|
99 | - final public function getXffTrustProvider() |
|
100 | - { |
|
101 | - return $this->xffTrustProvider; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param IXffTrustProvider $xffTrustProvider |
|
106 | - */ |
|
107 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
108 | - { |
|
109 | - $this->xffTrustProvider = $xffTrustProvider; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return IRDnsProvider |
|
114 | - */ |
|
115 | - final public function getRdnsProvider() |
|
116 | - { |
|
117 | - return $this->rdnsProvider; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param IRDnsProvider $rdnsProvider |
|
122 | - */ |
|
123 | - public function setRdnsProvider($rdnsProvider) |
|
124 | - { |
|
125 | - $this->rdnsProvider = $rdnsProvider; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @return IAntiSpoofProvider |
|
130 | - */ |
|
131 | - public function getAntiSpoofProvider() |
|
132 | - { |
|
133 | - return $this->antiSpoofProvider; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
138 | - */ |
|
139 | - public function setAntiSpoofProvider($antiSpoofProvider) |
|
140 | - { |
|
141 | - $this->antiSpoofProvider = $antiSpoofProvider; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return PdoDatabase |
|
146 | - */ |
|
147 | - final public function getDatabase() |
|
148 | - { |
|
149 | - return $this->database; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param PdoDatabase $database |
|
154 | - */ |
|
155 | - final public function setDatabase($database) |
|
156 | - { |
|
157 | - $this->database = $database; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @return IOAuthProtocolHelper |
|
162 | - */ |
|
163 | - public function getOAuthProtocolHelper() |
|
164 | - { |
|
165 | - return $this->oauthHelper; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
170 | - */ |
|
171 | - public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
172 | - { |
|
173 | - $this->oauthHelper = $oauthProtocolHelper; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return void |
|
178 | - */ |
|
179 | - abstract public function execute(); |
|
180 | - |
|
181 | - /** |
|
182 | - * @return IrcNotificationHelper |
|
183 | - */ |
|
184 | - public function getNotificationHelper() |
|
185 | - { |
|
186 | - return $this->notificationHelper; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @param IrcNotificationHelper $notificationHelper |
|
191 | - */ |
|
192 | - public function setNotificationHelper($notificationHelper) |
|
193 | - { |
|
194 | - $this->notificationHelper = $notificationHelper; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @return TorExitProvider |
|
199 | - */ |
|
200 | - public function getTorExitProvider() |
|
201 | - { |
|
202 | - return $this->torExitProvider; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * @param TorExitProvider $torExitProvider |
|
207 | - */ |
|
208 | - public function setTorExitProvider($torExitProvider) |
|
209 | - { |
|
210 | - $this->torExitProvider = $torExitProvider; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Gets the site configuration object |
|
215 | - * |
|
216 | - * @return SiteConfiguration |
|
217 | - */ |
|
218 | - final protected function getSiteConfiguration() |
|
219 | - { |
|
220 | - return $this->siteConfiguration; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Sets the site configuration object for this page |
|
225 | - * |
|
226 | - * @param SiteConfiguration $configuration |
|
227 | - */ |
|
228 | - final public function setSiteConfiguration($configuration) |
|
229 | - { |
|
230 | - $this->siteConfiguration = $configuration; |
|
231 | - } |
|
25 | + /** @var SiteConfiguration */ |
|
26 | + private $siteConfiguration; |
|
27 | + /** @var IEmailHelper */ |
|
28 | + private $emailHelper; |
|
29 | + /** @var HttpHelper */ |
|
30 | + private $httpHelper; |
|
31 | + /** @var ILocationProvider */ |
|
32 | + private $locationProvider; |
|
33 | + /** @var IXffTrustProvider */ |
|
34 | + private $xffTrustProvider; |
|
35 | + /** @var IRDnsProvider */ |
|
36 | + private $rdnsProvider; |
|
37 | + /** @var IAntiSpoofProvider */ |
|
38 | + private $antiSpoofProvider; |
|
39 | + /** @var IOAuthProtocolHelper */ |
|
40 | + private $oauthHelper; |
|
41 | + /** @var PdoDatabase */ |
|
42 | + private $database; |
|
43 | + /** @var IrcNotificationHelper */ |
|
44 | + private $notificationHelper; |
|
45 | + /** @var TorExitProvider */ |
|
46 | + private $torExitProvider; |
|
47 | + |
|
48 | + /** |
|
49 | + * @return IEmailHelper |
|
50 | + */ |
|
51 | + final public function getEmailHelper() |
|
52 | + { |
|
53 | + return $this->emailHelper; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param IEmailHelper $emailHelper |
|
58 | + */ |
|
59 | + final public function setEmailHelper($emailHelper) |
|
60 | + { |
|
61 | + $this->emailHelper = $emailHelper; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return HttpHelper |
|
66 | + */ |
|
67 | + final public function getHttpHelper() |
|
68 | + { |
|
69 | + return $this->httpHelper; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param HttpHelper $httpHelper |
|
74 | + */ |
|
75 | + final public function setHttpHelper($httpHelper) |
|
76 | + { |
|
77 | + $this->httpHelper = $httpHelper; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return ILocationProvider |
|
82 | + */ |
|
83 | + final public function getLocationProvider() |
|
84 | + { |
|
85 | + return $this->locationProvider; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param ILocationProvider $locationProvider |
|
90 | + */ |
|
91 | + final public function setLocationProvider(ILocationProvider $locationProvider) |
|
92 | + { |
|
93 | + $this->locationProvider = $locationProvider; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return IXffTrustProvider |
|
98 | + */ |
|
99 | + final public function getXffTrustProvider() |
|
100 | + { |
|
101 | + return $this->xffTrustProvider; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param IXffTrustProvider $xffTrustProvider |
|
106 | + */ |
|
107 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
108 | + { |
|
109 | + $this->xffTrustProvider = $xffTrustProvider; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return IRDnsProvider |
|
114 | + */ |
|
115 | + final public function getRdnsProvider() |
|
116 | + { |
|
117 | + return $this->rdnsProvider; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param IRDnsProvider $rdnsProvider |
|
122 | + */ |
|
123 | + public function setRdnsProvider($rdnsProvider) |
|
124 | + { |
|
125 | + $this->rdnsProvider = $rdnsProvider; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @return IAntiSpoofProvider |
|
130 | + */ |
|
131 | + public function getAntiSpoofProvider() |
|
132 | + { |
|
133 | + return $this->antiSpoofProvider; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
138 | + */ |
|
139 | + public function setAntiSpoofProvider($antiSpoofProvider) |
|
140 | + { |
|
141 | + $this->antiSpoofProvider = $antiSpoofProvider; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return PdoDatabase |
|
146 | + */ |
|
147 | + final public function getDatabase() |
|
148 | + { |
|
149 | + return $this->database; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param PdoDatabase $database |
|
154 | + */ |
|
155 | + final public function setDatabase($database) |
|
156 | + { |
|
157 | + $this->database = $database; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @return IOAuthProtocolHelper |
|
162 | + */ |
|
163 | + public function getOAuthProtocolHelper() |
|
164 | + { |
|
165 | + return $this->oauthHelper; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
170 | + */ |
|
171 | + public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
172 | + { |
|
173 | + $this->oauthHelper = $oauthProtocolHelper; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return void |
|
178 | + */ |
|
179 | + abstract public function execute(); |
|
180 | + |
|
181 | + /** |
|
182 | + * @return IrcNotificationHelper |
|
183 | + */ |
|
184 | + public function getNotificationHelper() |
|
185 | + { |
|
186 | + return $this->notificationHelper; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @param IrcNotificationHelper $notificationHelper |
|
191 | + */ |
|
192 | + public function setNotificationHelper($notificationHelper) |
|
193 | + { |
|
194 | + $this->notificationHelper = $notificationHelper; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @return TorExitProvider |
|
199 | + */ |
|
200 | + public function getTorExitProvider() |
|
201 | + { |
|
202 | + return $this->torExitProvider; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * @param TorExitProvider $torExitProvider |
|
207 | + */ |
|
208 | + public function setTorExitProvider($torExitProvider) |
|
209 | + { |
|
210 | + $this->torExitProvider = $torExitProvider; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Gets the site configuration object |
|
215 | + * |
|
216 | + * @return SiteConfiguration |
|
217 | + */ |
|
218 | + final protected function getSiteConfiguration() |
|
219 | + { |
|
220 | + return $this->siteConfiguration; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Sets the site configuration object for this page |
|
225 | + * |
|
226 | + * @param SiteConfiguration $configuration |
|
227 | + */ |
|
228 | + final public function setSiteConfiguration($configuration) |
|
229 | + { |
|
230 | + $this->siteConfiguration = $configuration; |
|
231 | + } |
|
232 | 232 | } |
233 | 233 | \ No newline at end of file |
@@ -13,97 +13,97 @@ |
||
13 | 13 | |
14 | 14 | abstract class PagedInternalPageBase extends InternalPageBase |
15 | 15 | { |
16 | - /** @var SearchHelperBase */ |
|
17 | - private $searchHelper; |
|
18 | - private $page; |
|
19 | - private $limit; |
|
20 | - |
|
21 | - /** |
|
22 | - * Sets up the pager with the current page, current limit, and total number of records. |
|
23 | - * |
|
24 | - * @param int $count |
|
25 | - * @param array $formParameters |
|
26 | - */ |
|
27 | - protected function setupPageData($count, $formParameters) |
|
28 | - { |
|
29 | - $page = $this->page; |
|
30 | - $limit = $this->limit; |
|
31 | - |
|
32 | - // The number of pages on the pager to show. Must be odd |
|
33 | - $pageLimit = 9; |
|
34 | - |
|
35 | - $pageData = array( |
|
36 | - // Can the user go to the previous page? |
|
37 | - 'canprev' => $page != 1, |
|
38 | - // Can the user go to the next page? |
|
39 | - 'cannext' => ($page * $limit) < $count, |
|
40 | - // Maximum page number |
|
41 | - 'maxpage' => max(1, ceil($count / $limit)), |
|
42 | - // Limit to the number of pages to display |
|
43 | - 'pagelimit' => $pageLimit, |
|
44 | - ); |
|
45 | - |
|
46 | - // number of pages either side of the current to show |
|
47 | - $pageMargin = (($pageLimit - 1) / 2); |
|
48 | - |
|
49 | - // Calculate the number of pages either side to show - this is for situations like: |
|
50 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
51 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
52 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
53 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
54 | - |
|
55 | - if ($pageCount < $pageLimit) { |
|
56 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
57 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
58 | - } |
|
59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - // Put the range of pages into the page data |
|
65 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
66 | - |
|
67 | - $this->assign("pagedata", $pageData); |
|
68 | - |
|
69 | - $this->assign("limit", $limit); |
|
70 | - $this->assign("page", $page); |
|
71 | - |
|
72 | - $this->setupFormParameters($formParameters); |
|
73 | - } |
|
74 | - |
|
75 | - protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
76 | - { |
|
77 | - $this->searchHelper = $searchHelper; |
|
78 | - } |
|
79 | - |
|
80 | - protected function setupLimits() |
|
81 | - { |
|
82 | - $limit = WebRequest::getInt('limit'); |
|
83 | - if ($limit === null) { |
|
84 | - $limit = 100; |
|
85 | - } |
|
86 | - |
|
87 | - $page = WebRequest::getInt('page'); |
|
88 | - if ($page === null) { |
|
89 | - $page = 1; |
|
90 | - } |
|
91 | - |
|
92 | - $offset = ($page - 1) * $limit; |
|
93 | - |
|
94 | - $this->searchHelper->limit($limit, $offset); |
|
95 | - |
|
96 | - $this->page = $page; |
|
97 | - $this->limit = $limit; |
|
98 | - } |
|
99 | - |
|
100 | - private function setupFormParameters($formParameters) |
|
101 | - { |
|
102 | - $formParameters['limit'] = $this->limit; |
|
103 | - $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
104 | - |
|
105 | - foreach ($formParameters as $key => $value) { |
|
106 | - $this->assign($key, $value); |
|
107 | - } |
|
108 | - } |
|
16 | + /** @var SearchHelperBase */ |
|
17 | + private $searchHelper; |
|
18 | + private $page; |
|
19 | + private $limit; |
|
20 | + |
|
21 | + /** |
|
22 | + * Sets up the pager with the current page, current limit, and total number of records. |
|
23 | + * |
|
24 | + * @param int $count |
|
25 | + * @param array $formParameters |
|
26 | + */ |
|
27 | + protected function setupPageData($count, $formParameters) |
|
28 | + { |
|
29 | + $page = $this->page; |
|
30 | + $limit = $this->limit; |
|
31 | + |
|
32 | + // The number of pages on the pager to show. Must be odd |
|
33 | + $pageLimit = 9; |
|
34 | + |
|
35 | + $pageData = array( |
|
36 | + // Can the user go to the previous page? |
|
37 | + 'canprev' => $page != 1, |
|
38 | + // Can the user go to the next page? |
|
39 | + 'cannext' => ($page * $limit) < $count, |
|
40 | + // Maximum page number |
|
41 | + 'maxpage' => max(1, ceil($count / $limit)), |
|
42 | + // Limit to the number of pages to display |
|
43 | + 'pagelimit' => $pageLimit, |
|
44 | + ); |
|
45 | + |
|
46 | + // number of pages either side of the current to show |
|
47 | + $pageMargin = (($pageLimit - 1) / 2); |
|
48 | + |
|
49 | + // Calculate the number of pages either side to show - this is for situations like: |
|
50 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
51 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
52 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
53 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
54 | + |
|
55 | + if ($pageCount < $pageLimit) { |
|
56 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
57 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
58 | + } |
|
59 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + // Put the range of pages into the page data |
|
65 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
66 | + |
|
67 | + $this->assign("pagedata", $pageData); |
|
68 | + |
|
69 | + $this->assign("limit", $limit); |
|
70 | + $this->assign("page", $page); |
|
71 | + |
|
72 | + $this->setupFormParameters($formParameters); |
|
73 | + } |
|
74 | + |
|
75 | + protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
76 | + { |
|
77 | + $this->searchHelper = $searchHelper; |
|
78 | + } |
|
79 | + |
|
80 | + protected function setupLimits() |
|
81 | + { |
|
82 | + $limit = WebRequest::getInt('limit'); |
|
83 | + if ($limit === null) { |
|
84 | + $limit = 100; |
|
85 | + } |
|
86 | + |
|
87 | + $page = WebRequest::getInt('page'); |
|
88 | + if ($page === null) { |
|
89 | + $page = 1; |
|
90 | + } |
|
91 | + |
|
92 | + $offset = ($page - 1) * $limit; |
|
93 | + |
|
94 | + $this->searchHelper->limit($limit, $offset); |
|
95 | + |
|
96 | + $this->page = $page; |
|
97 | + $this->limit = $limit; |
|
98 | + } |
|
99 | + |
|
100 | + private function setupFormParameters($formParameters) |
|
101 | + { |
|
102 | + $formParameters['limit'] = $this->limit; |
|
103 | + $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
104 | + |
|
105 | + foreach ($formParameters as $key => $value) { |
|
106 | + $this->assign($key, $value); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
@@ -55,8 +55,7 @@ |
||
55 | 55 | if ($pageCount < $pageLimit) { |
56 | 56 | if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
57 | 57 | $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
58 | - } |
|
59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
58 | + } elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | 59 | $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
61 | 60 | } |
62 | 61 | } |
@@ -22,137 +22,137 @@ |
||
22 | 22 | |
23 | 23 | interface ITask |
24 | 24 | { |
25 | - /** |
|
26 | - * @return IEmailHelper |
|
27 | - */ |
|
28 | - public function getEmailHelper(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @param IEmailHelper $emailHelper |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function setEmailHelper($emailHelper); |
|
36 | - |
|
37 | - /** |
|
38 | - * @return HttpHelper |
|
39 | - */ |
|
40 | - public function getHttpHelper(); |
|
41 | - |
|
42 | - /** |
|
43 | - * @param HttpHelper $httpHelper |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function setHttpHelper($httpHelper); |
|
48 | - |
|
49 | - /** |
|
50 | - * @return ILocationProvider |
|
51 | - */ |
|
52 | - public function getLocationProvider(); |
|
53 | - |
|
54 | - /** |
|
55 | - * @param ILocationProvider $locationProvider |
|
56 | - * |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function setLocationProvider(ILocationProvider $locationProvider); |
|
60 | - |
|
61 | - /** |
|
62 | - * @return IXffTrustProvider |
|
63 | - */ |
|
64 | - public function getXffTrustProvider(); |
|
65 | - |
|
66 | - /** |
|
67 | - * @param IXffTrustProvider $xffTrustProvider |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
72 | - |
|
73 | - /** |
|
74 | - * @return IRDnsProvider |
|
75 | - */ |
|
76 | - public function getRdnsProvider(); |
|
77 | - |
|
78 | - /** |
|
79 | - * @param IRDnsProvider $rdnsProvider |
|
80 | - * |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function setRdnsProvider($rdnsProvider); |
|
84 | - |
|
85 | - /** |
|
86 | - * @return IAntiSpoofProvider |
|
87 | - */ |
|
88 | - public function getAntiSpoofProvider(); |
|
89 | - |
|
90 | - /** |
|
91 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function setAntiSpoofProvider($antiSpoofProvider); |
|
96 | - |
|
97 | - /** |
|
98 | - * @return PdoDatabase |
|
99 | - */ |
|
100 | - public function getDatabase(); |
|
101 | - |
|
102 | - /** |
|
103 | - * @param PdoDatabase $database |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function setDatabase($database); |
|
108 | - |
|
109 | - /** |
|
110 | - * @return IOAuthProtocolHelper |
|
111 | - */ |
|
112 | - public function getOAuthProtocolHelper(); |
|
113 | - |
|
114 | - /** |
|
115 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
116 | - * |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
120 | - |
|
121 | - /** |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function execute(); |
|
125 | - |
|
126 | - /** |
|
127 | - * Sets the site configuration object for this page |
|
128 | - * |
|
129 | - * @param SiteConfiguration $configuration |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function setSiteConfiguration($configuration); |
|
134 | - |
|
135 | - /** |
|
136 | - * @return IrcNotificationHelper |
|
137 | - */ |
|
138 | - public function getNotificationHelper(); |
|
139 | - |
|
140 | - /** |
|
141 | - * @param IrcNotificationHelper $notificationHelper |
|
142 | - * |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public function setNotificationHelper($notificationHelper); |
|
146 | - |
|
147 | - /** |
|
148 | - * @return TorExitProvider |
|
149 | - */ |
|
150 | - public function getTorExitProvider(); |
|
151 | - |
|
152 | - /** |
|
153 | - * @param TorExitProvider $torExitProvider |
|
154 | - * |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function setTorExitProvider($torExitProvider); |
|
25 | + /** |
|
26 | + * @return IEmailHelper |
|
27 | + */ |
|
28 | + public function getEmailHelper(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @param IEmailHelper $emailHelper |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function setEmailHelper($emailHelper); |
|
36 | + |
|
37 | + /** |
|
38 | + * @return HttpHelper |
|
39 | + */ |
|
40 | + public function getHttpHelper(); |
|
41 | + |
|
42 | + /** |
|
43 | + * @param HttpHelper $httpHelper |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function setHttpHelper($httpHelper); |
|
48 | + |
|
49 | + /** |
|
50 | + * @return ILocationProvider |
|
51 | + */ |
|
52 | + public function getLocationProvider(); |
|
53 | + |
|
54 | + /** |
|
55 | + * @param ILocationProvider $locationProvider |
|
56 | + * |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function setLocationProvider(ILocationProvider $locationProvider); |
|
60 | + |
|
61 | + /** |
|
62 | + * @return IXffTrustProvider |
|
63 | + */ |
|
64 | + public function getXffTrustProvider(); |
|
65 | + |
|
66 | + /** |
|
67 | + * @param IXffTrustProvider $xffTrustProvider |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
72 | + |
|
73 | + /** |
|
74 | + * @return IRDnsProvider |
|
75 | + */ |
|
76 | + public function getRdnsProvider(); |
|
77 | + |
|
78 | + /** |
|
79 | + * @param IRDnsProvider $rdnsProvider |
|
80 | + * |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function setRdnsProvider($rdnsProvider); |
|
84 | + |
|
85 | + /** |
|
86 | + * @return IAntiSpoofProvider |
|
87 | + */ |
|
88 | + public function getAntiSpoofProvider(); |
|
89 | + |
|
90 | + /** |
|
91 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function setAntiSpoofProvider($antiSpoofProvider); |
|
96 | + |
|
97 | + /** |
|
98 | + * @return PdoDatabase |
|
99 | + */ |
|
100 | + public function getDatabase(); |
|
101 | + |
|
102 | + /** |
|
103 | + * @param PdoDatabase $database |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function setDatabase($database); |
|
108 | + |
|
109 | + /** |
|
110 | + * @return IOAuthProtocolHelper |
|
111 | + */ |
|
112 | + public function getOAuthProtocolHelper(); |
|
113 | + |
|
114 | + /** |
|
115 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
116 | + * |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
120 | + |
|
121 | + /** |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function execute(); |
|
125 | + |
|
126 | + /** |
|
127 | + * Sets the site configuration object for this page |
|
128 | + * |
|
129 | + * @param SiteConfiguration $configuration |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function setSiteConfiguration($configuration); |
|
134 | + |
|
135 | + /** |
|
136 | + * @return IrcNotificationHelper |
|
137 | + */ |
|
138 | + public function getNotificationHelper(); |
|
139 | + |
|
140 | + /** |
|
141 | + * @param IrcNotificationHelper $notificationHelper |
|
142 | + * |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public function setNotificationHelper($notificationHelper); |
|
146 | + |
|
147 | + /** |
|
148 | + * @return TorExitProvider |
|
149 | + */ |
|
150 | + public function getTorExitProvider(); |
|
151 | + |
|
152 | + /** |
|
153 | + * @param TorExitProvider $torExitProvider |
|
154 | + * |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function setTorExitProvider($torExitProvider); |
|
158 | 158 | } |
159 | 159 | \ No newline at end of file |
@@ -16,15 +16,15 @@ |
||
16 | 16 | */ |
17 | 17 | class RequestList |
18 | 18 | { |
19 | - public $requests; |
|
20 | - public $showPrivateData; |
|
21 | - public $dataClearEmail; |
|
22 | - public $dataClearIp; |
|
23 | - public $relatedEmailRequests; |
|
24 | - public $relatedIpRequests; |
|
25 | - public $requestTrustedIp; |
|
26 | - public $canBan; |
|
27 | - public $canBreakReservation; |
|
28 | - public $userList; |
|
29 | - public $commonEmail; |
|
19 | + public $requests; |
|
20 | + public $showPrivateData; |
|
21 | + public $dataClearEmail; |
|
22 | + public $dataClearIp; |
|
23 | + public $relatedEmailRequests; |
|
24 | + public $relatedIpRequests; |
|
25 | + public $requestTrustedIp; |
|
26 | + public $canBan; |
|
27 | + public $canBreakReservation; |
|
28 | + public $userList; |
|
29 | + public $commonEmail; |
|
30 | 30 | } |
@@ -23,172 +23,172 @@ |
||
23 | 23 | |
24 | 24 | class RunJobQueueTask extends ConsoleTaskBase |
25 | 25 | { |
26 | - private $taskList = array( |
|
27 | - WelcomeUserTask::class, |
|
28 | - BotCreationTask::class, |
|
29 | - UserCreationTask::class |
|
30 | - ); |
|
31 | - |
|
32 | - public function execute() |
|
33 | - { |
|
34 | - $database = $this->getDatabase(); |
|
35 | - |
|
36 | - // ensure we're running inside a tx here. |
|
37 | - if (!$database->hasActiveTransaction()) { |
|
38 | - $database->beginTransaction(); |
|
39 | - } |
|
40 | - |
|
41 | - $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim'; |
|
42 | - $statement = $database->prepare($sql); |
|
43 | - $statement->execute(array( |
|
44 | - ':status' => JobQueue::STATUS_READY, |
|
45 | - ':lim' => $this->getSiteConfiguration()->getJobQueueBatchSize() |
|
46 | - )); |
|
47 | - |
|
48 | - /** @var JobQueue[] $queuedJobs */ |
|
49 | - $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class); |
|
50 | - |
|
51 | - // mark all the jobs as running, and commit the txn so we're not holding onto long-running transactions. |
|
52 | - // We'll re-lock the row when we get to it. |
|
53 | - foreach ($queuedJobs as $job) { |
|
54 | - $job->setDatabase($database); |
|
55 | - $job->setStatus(JobQueue::STATUS_WAITING); |
|
56 | - $job->setError(null); |
|
57 | - $job->setAcknowledged(null); |
|
58 | - $job->save(); |
|
59 | - } |
|
60 | - |
|
61 | - $database->commit(); |
|
62 | - |
|
63 | - set_error_handler(array(RunJobQueueTask::class, 'errorHandler'), E_ALL); |
|
64 | - |
|
65 | - foreach ($queuedJobs as $job) { |
|
66 | - try { |
|
67 | - // refresh from the database |
|
68 | - /** @var JobQueue $job */ |
|
69 | - $job = JobQueue::getById($job->getId(), $database); |
|
70 | - |
|
71 | - if ($job->getStatus() !== JobQueue::STATUS_WAITING) { |
|
72 | - continue; |
|
73 | - } |
|
74 | - |
|
75 | - $database->beginTransaction(); |
|
76 | - $job->setStatus(JobQueue::STATUS_RUNNING); |
|
77 | - $job->save(); |
|
78 | - $database->commit(); |
|
79 | - |
|
80 | - $database->beginTransaction(); |
|
81 | - |
|
82 | - // re-lock the job |
|
83 | - $job->setStatus(JobQueue::STATUS_RUNNING); |
|
84 | - $job->save(); |
|
85 | - |
|
86 | - // validate we're allowed to run the requested task (whitelist) |
|
87 | - if (!in_array($job->getTask(), $this->taskList)) { |
|
88 | - throw new ApplicationLogicException('Job task not registered'); |
|
89 | - } |
|
90 | - |
|
91 | - // Create a task. |
|
92 | - $taskName = $job->getTask(); |
|
93 | - |
|
94 | - if (!class_exists($taskName)) { |
|
95 | - throw new ApplicationLogicException('Job task does not exist'); |
|
96 | - } |
|
97 | - |
|
98 | - /** @var BackgroundTaskBase $task */ |
|
99 | - $task = new $taskName; |
|
100 | - |
|
101 | - $this->setupTask($task, $job); |
|
102 | - $task->run(); |
|
103 | - } |
|
104 | - catch (Exception $ex) { |
|
105 | - $database->rollBack(); |
|
106 | - try { |
|
107 | - $database->beginTransaction(); |
|
108 | - |
|
109 | - /** @var JobQueue $job */ |
|
110 | - $job = JobQueue::getById($job->getId(), $database); |
|
111 | - $job->setDatabase($database); |
|
112 | - $job->setStatus(JobQueue::STATUS_FAILED); |
|
113 | - $job->setError($ex->getMessage()); |
|
114 | - $job->setAcknowledged(0); |
|
115 | - $job->save(); |
|
116 | - |
|
117 | - Logger::backgroundJobIssue($this->getDatabase(), $job); |
|
118 | - |
|
119 | - $database->commit(); |
|
120 | - } |
|
121 | - catch (Exception $ex) { |
|
122 | - // oops, something went horribly wrong trying to handle this in a nice way; let's just fall back to |
|
123 | - // logging this to disk for a tool root to investigate. |
|
124 | - ExceptionHandler::logExceptionToDisk($ex, $this->getSiteConfiguration()); |
|
125 | - } |
|
126 | - } |
|
127 | - finally { |
|
128 | - $database->commit(); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - $this->stageQueuedTasks($database); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * @param BackgroundTaskBase $task |
|
137 | - * @param JobQueue $job |
|
138 | - */ |
|
139 | - private function setupTask(BackgroundTaskBase $task, JobQueue $job) |
|
140 | - { |
|
141 | - $task->setJob($job); |
|
142 | - $task->setDatabase($this->getDatabase()); |
|
143 | - $task->setHttpHelper($this->getHttpHelper()); |
|
144 | - $task->setOauthProtocolHelper($this->getOAuthProtocolHelper()); |
|
145 | - $task->setEmailHelper($this->getEmailHelper()); |
|
146 | - $task->setSiteConfiguration($this->getSiteConfiguration()); |
|
147 | - $task->setNotificationHelper($this->getNotificationHelper()); |
|
148 | - } |
|
149 | - |
|
150 | - /** @noinspection PhpUnusedParameterInspection */ |
|
151 | - public static function errorHandler($errno, $errstr, $errfile, $errline) |
|
152 | - { |
|
153 | - throw new Exception($errfile . "@" . $errline . ": " . $errstr); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Stages tasks for execution during the *next* jobqueue run. |
|
158 | - * |
|
159 | - * This is to build in some delay between enqueue and execution to allow for accidentally-triggered tasks to be |
|
160 | - * cancelled. |
|
161 | - * |
|
162 | - * @param PdoDatabase $database |
|
163 | - */ |
|
164 | - protected function stageQueuedTasks(PdoDatabase $database): void |
|
165 | - { |
|
166 | - try { |
|
167 | - $database->beginTransaction(); |
|
168 | - |
|
169 | - $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim'; |
|
170 | - $statement = $database->prepare($sql); |
|
171 | - |
|
172 | - // use a larger batch size than the main runner, but still keep it limited in case things go crazy. |
|
173 | - $statement->execute(array( |
|
174 | - ':status' => JobQueue::STATUS_QUEUED, |
|
175 | - ':lim' => $this->getSiteConfiguration()->getJobQueueBatchSize() * 2 |
|
176 | - )); |
|
177 | - |
|
178 | - /** @var JobQueue[] $queuedJobs */ |
|
179 | - $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class); |
|
180 | - |
|
181 | - foreach ($queuedJobs as $job) { |
|
182 | - $job->setDatabase($database); |
|
183 | - $job->setStatus(JobQueue::STATUS_READY); |
|
184 | - $job->save(); |
|
185 | - } |
|
186 | - |
|
187 | - $database->commit(); |
|
188 | - } |
|
189 | - catch (Exception $ex) { |
|
190 | - $database->rollBack(); |
|
191 | - ExceptionHandler::logExceptionToDisk($ex, $this->getSiteConfiguration()); |
|
192 | - } |
|
193 | - } |
|
26 | + private $taskList = array( |
|
27 | + WelcomeUserTask::class, |
|
28 | + BotCreationTask::class, |
|
29 | + UserCreationTask::class |
|
30 | + ); |
|
31 | + |
|
32 | + public function execute() |
|
33 | + { |
|
34 | + $database = $this->getDatabase(); |
|
35 | + |
|
36 | + // ensure we're running inside a tx here. |
|
37 | + if (!$database->hasActiveTransaction()) { |
|
38 | + $database->beginTransaction(); |
|
39 | + } |
|
40 | + |
|
41 | + $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim'; |
|
42 | + $statement = $database->prepare($sql); |
|
43 | + $statement->execute(array( |
|
44 | + ':status' => JobQueue::STATUS_READY, |
|
45 | + ':lim' => $this->getSiteConfiguration()->getJobQueueBatchSize() |
|
46 | + )); |
|
47 | + |
|
48 | + /** @var JobQueue[] $queuedJobs */ |
|
49 | + $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class); |
|
50 | + |
|
51 | + // mark all the jobs as running, and commit the txn so we're not holding onto long-running transactions. |
|
52 | + // We'll re-lock the row when we get to it. |
|
53 | + foreach ($queuedJobs as $job) { |
|
54 | + $job->setDatabase($database); |
|
55 | + $job->setStatus(JobQueue::STATUS_WAITING); |
|
56 | + $job->setError(null); |
|
57 | + $job->setAcknowledged(null); |
|
58 | + $job->save(); |
|
59 | + } |
|
60 | + |
|
61 | + $database->commit(); |
|
62 | + |
|
63 | + set_error_handler(array(RunJobQueueTask::class, 'errorHandler'), E_ALL); |
|
64 | + |
|
65 | + foreach ($queuedJobs as $job) { |
|
66 | + try { |
|
67 | + // refresh from the database |
|
68 | + /** @var JobQueue $job */ |
|
69 | + $job = JobQueue::getById($job->getId(), $database); |
|
70 | + |
|
71 | + if ($job->getStatus() !== JobQueue::STATUS_WAITING) { |
|
72 | + continue; |
|
73 | + } |
|
74 | + |
|
75 | + $database->beginTransaction(); |
|
76 | + $job->setStatus(JobQueue::STATUS_RUNNING); |
|
77 | + $job->save(); |
|
78 | + $database->commit(); |
|
79 | + |
|
80 | + $database->beginTransaction(); |
|
81 | + |
|
82 | + // re-lock the job |
|
83 | + $job->setStatus(JobQueue::STATUS_RUNNING); |
|
84 | + $job->save(); |
|
85 | + |
|
86 | + // validate we're allowed to run the requested task (whitelist) |
|
87 | + if (!in_array($job->getTask(), $this->taskList)) { |
|
88 | + throw new ApplicationLogicException('Job task not registered'); |
|
89 | + } |
|
90 | + |
|
91 | + // Create a task. |
|
92 | + $taskName = $job->getTask(); |
|
93 | + |
|
94 | + if (!class_exists($taskName)) { |
|
95 | + throw new ApplicationLogicException('Job task does not exist'); |
|
96 | + } |
|
97 | + |
|
98 | + /** @var BackgroundTaskBase $task */ |
|
99 | + $task = new $taskName; |
|
100 | + |
|
101 | + $this->setupTask($task, $job); |
|
102 | + $task->run(); |
|
103 | + } |
|
104 | + catch (Exception $ex) { |
|
105 | + $database->rollBack(); |
|
106 | + try { |
|
107 | + $database->beginTransaction(); |
|
108 | + |
|
109 | + /** @var JobQueue $job */ |
|
110 | + $job = JobQueue::getById($job->getId(), $database); |
|
111 | + $job->setDatabase($database); |
|
112 | + $job->setStatus(JobQueue::STATUS_FAILED); |
|
113 | + $job->setError($ex->getMessage()); |
|
114 | + $job->setAcknowledged(0); |
|
115 | + $job->save(); |
|
116 | + |
|
117 | + Logger::backgroundJobIssue($this->getDatabase(), $job); |
|
118 | + |
|
119 | + $database->commit(); |
|
120 | + } |
|
121 | + catch (Exception $ex) { |
|
122 | + // oops, something went horribly wrong trying to handle this in a nice way; let's just fall back to |
|
123 | + // logging this to disk for a tool root to investigate. |
|
124 | + ExceptionHandler::logExceptionToDisk($ex, $this->getSiteConfiguration()); |
|
125 | + } |
|
126 | + } |
|
127 | + finally { |
|
128 | + $database->commit(); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + $this->stageQueuedTasks($database); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * @param BackgroundTaskBase $task |
|
137 | + * @param JobQueue $job |
|
138 | + */ |
|
139 | + private function setupTask(BackgroundTaskBase $task, JobQueue $job) |
|
140 | + { |
|
141 | + $task->setJob($job); |
|
142 | + $task->setDatabase($this->getDatabase()); |
|
143 | + $task->setHttpHelper($this->getHttpHelper()); |
|
144 | + $task->setOauthProtocolHelper($this->getOAuthProtocolHelper()); |
|
145 | + $task->setEmailHelper($this->getEmailHelper()); |
|
146 | + $task->setSiteConfiguration($this->getSiteConfiguration()); |
|
147 | + $task->setNotificationHelper($this->getNotificationHelper()); |
|
148 | + } |
|
149 | + |
|
150 | + /** @noinspection PhpUnusedParameterInspection */ |
|
151 | + public static function errorHandler($errno, $errstr, $errfile, $errline) |
|
152 | + { |
|
153 | + throw new Exception($errfile . "@" . $errline . ": " . $errstr); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Stages tasks for execution during the *next* jobqueue run. |
|
158 | + * |
|
159 | + * This is to build in some delay between enqueue and execution to allow for accidentally-triggered tasks to be |
|
160 | + * cancelled. |
|
161 | + * |
|
162 | + * @param PdoDatabase $database |
|
163 | + */ |
|
164 | + protected function stageQueuedTasks(PdoDatabase $database): void |
|
165 | + { |
|
166 | + try { |
|
167 | + $database->beginTransaction(); |
|
168 | + |
|
169 | + $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim'; |
|
170 | + $statement = $database->prepare($sql); |
|
171 | + |
|
172 | + // use a larger batch size than the main runner, but still keep it limited in case things go crazy. |
|
173 | + $statement->execute(array( |
|
174 | + ':status' => JobQueue::STATUS_QUEUED, |
|
175 | + ':lim' => $this->getSiteConfiguration()->getJobQueueBatchSize() * 2 |
|
176 | + )); |
|
177 | + |
|
178 | + /** @var JobQueue[] $queuedJobs */ |
|
179 | + $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class); |
|
180 | + |
|
181 | + foreach ($queuedJobs as $job) { |
|
182 | + $job->setDatabase($database); |
|
183 | + $job->setStatus(JobQueue::STATUS_READY); |
|
184 | + $job->save(); |
|
185 | + } |
|
186 | + |
|
187 | + $database->commit(); |
|
188 | + } |
|
189 | + catch (Exception $ex) { |
|
190 | + $database->rollBack(); |
|
191 | + ExceptionHandler::logExceptionToDisk($ex, $this->getSiteConfiguration()); |
|
192 | + } |
|
193 | + } |
|
194 | 194 | } |