@@ -23,65 +23,65 @@ |
||
23 | 23 | */ |
24 | 24 | class MonitorAction extends XmlApiPageBase implements IXmlApiAction |
25 | 25 | { |
26 | - /** |
|
27 | - * @param DOMElement $apiDocument |
|
28 | - * |
|
29 | - * @return DOMElement |
|
30 | - */ |
|
31 | - public function executeApiAction(DOMElement $apiDocument) |
|
32 | - { |
|
33 | - $now = new DateTime(); |
|
26 | + /** |
|
27 | + * @param DOMElement $apiDocument |
|
28 | + * |
|
29 | + * @return DOMElement |
|
30 | + */ |
|
31 | + public function executeApiAction(DOMElement $apiDocument) |
|
32 | + { |
|
33 | + $now = new DateTime(); |
|
34 | 34 | |
35 | - $old = $this->getOldest(); |
|
36 | - $oldest = new DateTime($old); |
|
35 | + $old = $this->getOldest(); |
|
36 | + $oldest = new DateTime($old); |
|
37 | 37 | |
38 | - $new = $this->getNewest(); |
|
39 | - $newest = new DateTime($new); |
|
38 | + $new = $this->getNewest(); |
|
39 | + $newest = new DateTime($new); |
|
40 | 40 | |
41 | - $monitoringElement = $this->document->createElement("data"); |
|
42 | - $monitoringElement->setAttribute("date", $now->format('c')); |
|
43 | - $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
44 | - $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
45 | - $apiDocument->appendChild($monitoringElement); |
|
41 | + $monitoringElement = $this->document->createElement("data"); |
|
42 | + $monitoringElement->setAttribute("date", $now->format('c')); |
|
43 | + $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
44 | + $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
45 | + $apiDocument->appendChild($monitoringElement); |
|
46 | 46 | |
47 | - return $apiDocument; |
|
48 | - } |
|
47 | + return $apiDocument; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string|null |
|
52 | - */ |
|
53 | - private function getOldest() |
|
54 | - { |
|
55 | - $statement = $this->getDatabase() |
|
56 | - ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
57 | - $successful = $statement->execute(array( |
|
58 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
59 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
60 | - )); |
|
50 | + /** |
|
51 | + * @return string|null |
|
52 | + */ |
|
53 | + private function getOldest() |
|
54 | + { |
|
55 | + $statement = $this->getDatabase() |
|
56 | + ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
57 | + $successful = $statement->execute(array( |
|
58 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
59 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
60 | + )); |
|
61 | 61 | |
62 | - if (!$successful) { |
|
63 | - return null; |
|
64 | - } |
|
62 | + if (!$successful) { |
|
63 | + return null; |
|
64 | + } |
|
65 | 65 | |
66 | - $result = $statement->fetchColumn(); |
|
66 | + $result = $statement->fetchColumn(); |
|
67 | 67 | |
68 | - return $result; |
|
69 | - } |
|
68 | + return $result; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - private function getNewest() |
|
75 | - { |
|
76 | - $statement = $this->getDatabase() |
|
77 | - ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
78 | - $statement->execute(array( |
|
79 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
80 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
81 | - )); |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + private function getNewest() |
|
75 | + { |
|
76 | + $statement = $this->getDatabase() |
|
77 | + ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
78 | + $statement->execute(array( |
|
79 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
80 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
81 | + )); |
|
82 | 82 | |
83 | - $result = $statement->fetchColumn(0); |
|
83 | + $result = $statement->fetchColumn(0); |
|
84 | 84 | |
85 | - return $result; |
|
86 | - } |
|
85 | + return $result; |
|
86 | + } |
|
87 | 87 | } |
@@ -15,8 +15,8 @@ |
||
15 | 15 | */ |
16 | 16 | interface IApiAction extends IRoutedTask |
17 | 17 | { |
18 | - /** |
|
19 | - * @return string the XML, or false if an error occurred. |
|
20 | - */ |
|
21 | - public function runApiPage(); |
|
18 | + /** |
|
19 | + * @return string the XML, or false if an error occurred. |
|
20 | + */ |
|
21 | + public function runApiPage(); |
|
22 | 22 | } |
@@ -13,37 +13,37 @@ |
||
13 | 13 | */ |
14 | 14 | class AutoLoader |
15 | 15 | { |
16 | - public static function load($class) |
|
17 | - { |
|
18 | - // handle namespaces sensibly |
|
19 | - if (strpos($class, "Waca") !== false) { |
|
20 | - // strip off the initial namespace |
|
21 | - $class = str_replace("Waca\\", "", $class); |
|
16 | + public static function load($class) |
|
17 | + { |
|
18 | + // handle namespaces sensibly |
|
19 | + if (strpos($class, "Waca") !== false) { |
|
20 | + // strip off the initial namespace |
|
21 | + $class = str_replace("Waca\\", "", $class); |
|
22 | 22 | |
23 | - // swap backslashes for forward slashes to map to directory names |
|
24 | - $class = str_replace("\\", "/", $class); |
|
25 | - } |
|
23 | + // swap backslashes for forward slashes to map to directory names |
|
24 | + $class = str_replace("\\", "/", $class); |
|
25 | + } |
|
26 | 26 | |
27 | - $paths = array( |
|
28 | - __DIR__ . '/' . $class . ".php", |
|
29 | - __DIR__ . '/DataObjects/' . $class . ".php", |
|
30 | - __DIR__ . '/Providers/' . $class . ".php", |
|
31 | - __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
32 | - __DIR__ . '/Validation/' . $class . ".php", |
|
33 | - __DIR__ . '/Helpers/' . $class . ".php", |
|
34 | - __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
35 | - __DIR__ . '/' . $class . ".php", |
|
36 | - ); |
|
27 | + $paths = array( |
|
28 | + __DIR__ . '/' . $class . ".php", |
|
29 | + __DIR__ . '/DataObjects/' . $class . ".php", |
|
30 | + __DIR__ . '/Providers/' . $class . ".php", |
|
31 | + __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
32 | + __DIR__ . '/Validation/' . $class . ".php", |
|
33 | + __DIR__ . '/Helpers/' . $class . ".php", |
|
34 | + __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
35 | + __DIR__ . '/' . $class . ".php", |
|
36 | + ); |
|
37 | 37 | |
38 | - foreach ($paths as $file) { |
|
39 | - if (file_exists($file)) { |
|
40 | - /** @noinspection PhpIncludeInspection */ |
|
41 | - require_once($file); |
|
42 | - } |
|
38 | + foreach ($paths as $file) { |
|
39 | + if (file_exists($file)) { |
|
40 | + /** @noinspection PhpIncludeInspection */ |
|
41 | + require_once($file); |
|
42 | + } |
|
43 | 43 | |
44 | - if (class_exists($class)) { |
|
45 | - return; |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
44 | + if (class_exists($class)) { |
|
45 | + return; |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -38,7 +38,8 @@ |
||
38 | 38 | $requestList->requests = $requests; |
39 | 39 | |
40 | 40 | $userIds = array_map( |
41 | - function(Request $entry) { |
|
41 | + function(Request $entry) |
|
42 | + { |
|
42 | 43 | return $entry->getReserved(); |
43 | 44 | }, |
44 | 45 | $requests |
@@ -19,77 +19,77 @@ |
||
19 | 19 | |
20 | 20 | trait RequestListData |
21 | 21 | { |
22 | - // function imports from InternalPageBase etc. |
|
23 | - protected abstract function getDatabase(); |
|
24 | - |
|
25 | - protected abstract function getXffTrustProvider(); |
|
26 | - |
|
27 | - /** @return SiteConfiguration */ |
|
28 | - protected abstract function getSiteConfiguration(); |
|
29 | - |
|
30 | - protected abstract function barrierTest($action, User $user, $pageName = null); |
|
31 | - |
|
32 | - /** |
|
33 | - * @param Request[] $requests |
|
34 | - * |
|
35 | - * @return RequestList |
|
36 | - */ |
|
37 | - protected function prepareRequestData(array $requests) : RequestList |
|
38 | - { |
|
39 | - $requestList = new RequestList(); |
|
40 | - $requestList->requests = $requests; |
|
41 | - |
|
42 | - $userIds = array_map( |
|
43 | - function(Request $entry) { |
|
44 | - return $entry->getReserved(); |
|
45 | - }, |
|
46 | - $requests |
|
47 | - ); |
|
48 | - |
|
49 | - $requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
50 | - |
|
51 | - $requestList->requestTrustedIp = []; |
|
52 | - $requestList->relatedIpRequests = []; |
|
53 | - $requestList->relatedEmailRequests = []; |
|
54 | - |
|
55 | - foreach ($requests as $request) { |
|
56 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
57 | - $request->getIp(), |
|
58 | - $request->getForwardedIp() |
|
59 | - ); |
|
60 | - |
|
61 | - // TODO: Do we really want to return results from other domains? |
|
62 | - RequestSearchHelper::get($this->getDatabase(), null) |
|
63 | - ->byIp($trustedIp) |
|
64 | - ->withConfirmedEmail() |
|
65 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
66 | - ->excludingRequest($request->getId()) |
|
67 | - ->getRecordCount($ipCount); |
|
68 | - |
|
69 | - RequestSearchHelper::get($this->getDatabase(), null) |
|
70 | - ->byEmailAddress($request->getEmail()) |
|
71 | - ->withConfirmedEmail() |
|
72 | - ->excludingPurgedData($this->getSiteConfiguration()) |
|
73 | - ->excludingRequest($request->getId()) |
|
74 | - ->getRecordCount($emailCount); |
|
75 | - |
|
76 | - $requestList->requestTrustedIp[$request->getId()] = $trustedIp; |
|
77 | - $requestList->relatedEmailRequests[$request->getId()] = $emailCount; |
|
78 | - $requestList->relatedIpRequests[$request->getId()] = $ipCount; |
|
79 | - |
|
80 | - $emailDomain = explode("@", $request->getEmail())[1]; |
|
81 | - $requestList->commonEmail[$request->getId()] = in_array(strtolower($emailDomain), $this->getSiteConfiguration()->getCommonEmailDomains()) |
|
82 | - || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail(); |
|
83 | - } |
|
84 | - |
|
85 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
86 | - |
|
87 | - $requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class); |
|
88 | - $requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class); |
|
89 | - $requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData'); |
|
90 | - $requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail(); |
|
91 | - $requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp(); |
|
92 | - |
|
93 | - return $requestList; |
|
94 | - } |
|
22 | + // function imports from InternalPageBase etc. |
|
23 | + protected abstract function getDatabase(); |
|
24 | + |
|
25 | + protected abstract function getXffTrustProvider(); |
|
26 | + |
|
27 | + /** @return SiteConfiguration */ |
|
28 | + protected abstract function getSiteConfiguration(); |
|
29 | + |
|
30 | + protected abstract function barrierTest($action, User $user, $pageName = null); |
|
31 | + |
|
32 | + /** |
|
33 | + * @param Request[] $requests |
|
34 | + * |
|
35 | + * @return RequestList |
|
36 | + */ |
|
37 | + protected function prepareRequestData(array $requests) : RequestList |
|
38 | + { |
|
39 | + $requestList = new RequestList(); |
|
40 | + $requestList->requests = $requests; |
|
41 | + |
|
42 | + $userIds = array_map( |
|
43 | + function(Request $entry) { |
|
44 | + return $entry->getReserved(); |
|
45 | + }, |
|
46 | + $requests |
|
47 | + ); |
|
48 | + |
|
49 | + $requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
50 | + |
|
51 | + $requestList->requestTrustedIp = []; |
|
52 | + $requestList->relatedIpRequests = []; |
|
53 | + $requestList->relatedEmailRequests = []; |
|
54 | + |
|
55 | + foreach ($requests as $request) { |
|
56 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
57 | + $request->getIp(), |
|
58 | + $request->getForwardedIp() |
|
59 | + ); |
|
60 | + |
|
61 | + // TODO: Do we really want to return results from other domains? |
|
62 | + RequestSearchHelper::get($this->getDatabase(), null) |
|
63 | + ->byIp($trustedIp) |
|
64 | + ->withConfirmedEmail() |
|
65 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
66 | + ->excludingRequest($request->getId()) |
|
67 | + ->getRecordCount($ipCount); |
|
68 | + |
|
69 | + RequestSearchHelper::get($this->getDatabase(), null) |
|
70 | + ->byEmailAddress($request->getEmail()) |
|
71 | + ->withConfirmedEmail() |
|
72 | + ->excludingPurgedData($this->getSiteConfiguration()) |
|
73 | + ->excludingRequest($request->getId()) |
|
74 | + ->getRecordCount($emailCount); |
|
75 | + |
|
76 | + $requestList->requestTrustedIp[$request->getId()] = $trustedIp; |
|
77 | + $requestList->relatedEmailRequests[$request->getId()] = $emailCount; |
|
78 | + $requestList->relatedIpRequests[$request->getId()] = $ipCount; |
|
79 | + |
|
80 | + $emailDomain = explode("@", $request->getEmail())[1]; |
|
81 | + $requestList->commonEmail[$request->getId()] = in_array(strtolower($emailDomain), $this->getSiteConfiguration()->getCommonEmailDomains()) |
|
82 | + || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail(); |
|
83 | + } |
|
84 | + |
|
85 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
86 | + |
|
87 | + $requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class); |
|
88 | + $requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class); |
|
89 | + $requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData'); |
|
90 | + $requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail(); |
|
91 | + $requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp(); |
|
92 | + |
|
93 | + return $requestList; |
|
94 | + } |
|
95 | 95 | } |
@@ -12,21 +12,21 @@ discard block |
||
12 | 12 | |
13 | 13 | class TypeAheadHelper implements ITypeAheadHelper |
14 | 14 | { |
15 | - private $definedClasses = array(); |
|
15 | + private $definedClasses = array(); |
|
16 | 16 | |
17 | - /** |
|
18 | - * @param string $class CSS class to apply this typeahead to. |
|
19 | - * @param callable $generator Generator function taking no arguments to return an array of strings. |
|
20 | - */ |
|
21 | - public function defineTypeAheadSource($class, callable $generator) |
|
22 | - { |
|
23 | - $dataList = ''; |
|
24 | - foreach ($generator() as $dataItem) { |
|
25 | - $dataList .= '"' . htmlentities($dataItem) . '", '; |
|
26 | - } |
|
27 | - $dataList = "[" . rtrim($dataList, ", ") . "]"; |
|
17 | + /** |
|
18 | + * @param string $class CSS class to apply this typeahead to. |
|
19 | + * @param callable $generator Generator function taking no arguments to return an array of strings. |
|
20 | + */ |
|
21 | + public function defineTypeAheadSource($class, callable $generator) |
|
22 | + { |
|
23 | + $dataList = ''; |
|
24 | + foreach ($generator() as $dataItem) { |
|
25 | + $dataList .= '"' . htmlentities($dataItem) . '", '; |
|
26 | + } |
|
27 | + $dataList = "[" . rtrim($dataList, ", ") . "]"; |
|
28 | 28 | |
29 | - $script = <<<JS |
|
29 | + $script = <<<JS |
|
30 | 30 | |
31 | 31 | $('.{$class}').typeahead({ |
32 | 32 | hint: true, |
@@ -39,32 +39,32 @@ discard block |
||
39 | 39 | }) |
40 | 40 | ; |
41 | 41 | JS; |
42 | - $this->definedClasses[$class] = $script; |
|
43 | - } |
|
42 | + $this->definedClasses[$class] = $script; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return string HTML fragment containing a JS block for typeaheads. |
|
47 | - */ |
|
48 | - public function getTypeAheadScriptBlock() |
|
49 | - { |
|
50 | - $jsBlocks = ''; |
|
45 | + /** |
|
46 | + * @return string HTML fragment containing a JS block for typeaheads. |
|
47 | + */ |
|
48 | + public function getTypeAheadScriptBlock() |
|
49 | + { |
|
50 | + $jsBlocks = ''; |
|
51 | 51 | |
52 | - if (count($this->definedClasses) === 0) { |
|
53 | - return ''; |
|
54 | - } |
|
52 | + if (count($this->definedClasses) === 0) { |
|
53 | + return ''; |
|
54 | + } |
|
55 | 55 | |
56 | - foreach ($this->definedClasses as $class => $js) { |
|
57 | - $jsBlocks = $js . "\r\n\r\n"; |
|
58 | - } |
|
56 | + foreach ($this->definedClasses as $class => $js) { |
|
57 | + $jsBlocks = $js . "\r\n\r\n"; |
|
58 | + } |
|
59 | 59 | |
60 | - $data = <<<HTML |
|
60 | + $data = <<<HTML |
|
61 | 61 | <script type="text/javascript"> |
62 | 62 | {$jsBlocks} |
63 | 63 | </script> |
64 | 64 | HTML; |
65 | 65 | |
66 | - $this->definedClasses = array(); |
|
66 | + $this->definedClasses = array(); |
|
67 | 67 | |
68 | - return $data; |
|
69 | - } |
|
68 | + return $data; |
|
69 | + } |
|
70 | 70 | } |
@@ -15,73 +15,73 @@ discard block |
||
15 | 15 | |
16 | 16 | class UserSearchHelper extends SearchHelperBase |
17 | 17 | { |
18 | - /** |
|
19 | - * UserSearchHelper constructor. |
|
20 | - * |
|
21 | - * @param PdoDatabase $database |
|
22 | - */ |
|
23 | - public function __construct(PdoDatabase $database) |
|
24 | - { |
|
25 | - parent::__construct($database, 'user', User::class); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Initiates a search for requests |
|
30 | - * |
|
31 | - * @param PdoDatabase $database |
|
32 | - * |
|
33 | - * @return UserSearchHelper |
|
34 | - */ |
|
35 | - public static function get(PdoDatabase $database) |
|
36 | - { |
|
37 | - $helper = new UserSearchHelper($database); |
|
38 | - |
|
39 | - return $helper; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $status |
|
44 | - * |
|
45 | - * @return $this |
|
46 | - */ |
|
47 | - public function byStatus($status) |
|
48 | - { |
|
49 | - $this->whereClause .= ' AND status = ?'; |
|
50 | - $this->parameterList[] = $status; |
|
51 | - |
|
52 | - return $this; |
|
53 | - } |
|
54 | - |
|
55 | - public function statusIn($statuses) |
|
56 | - { |
|
57 | - $this->inClause('status', $statuses); |
|
58 | - |
|
59 | - return $this; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param string $role |
|
64 | - * |
|
65 | - * @return $this |
|
66 | - */ |
|
67 | - public function byRole($role) |
|
68 | - { |
|
69 | - $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
70 | - $this->whereClause .= ' AND r.role = ?'; |
|
71 | - $this->parameterList[] = $role; |
|
72 | - |
|
73 | - return $this; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param DateTime $instant |
|
78 | - * |
|
79 | - * @return $this |
|
80 | - */ |
|
81 | - public function lastActiveBefore(DateTime $instant) |
|
82 | - { |
|
83 | - $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?'; |
|
84 | - $this->joinClause .= <<<'SQLFRAG' |
|
18 | + /** |
|
19 | + * UserSearchHelper constructor. |
|
20 | + * |
|
21 | + * @param PdoDatabase $database |
|
22 | + */ |
|
23 | + public function __construct(PdoDatabase $database) |
|
24 | + { |
|
25 | + parent::__construct($database, 'user', User::class); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Initiates a search for requests |
|
30 | + * |
|
31 | + * @param PdoDatabase $database |
|
32 | + * |
|
33 | + * @return UserSearchHelper |
|
34 | + */ |
|
35 | + public static function get(PdoDatabase $database) |
|
36 | + { |
|
37 | + $helper = new UserSearchHelper($database); |
|
38 | + |
|
39 | + return $helper; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $status |
|
44 | + * |
|
45 | + * @return $this |
|
46 | + */ |
|
47 | + public function byStatus($status) |
|
48 | + { |
|
49 | + $this->whereClause .= ' AND status = ?'; |
|
50 | + $this->parameterList[] = $status; |
|
51 | + |
|
52 | + return $this; |
|
53 | + } |
|
54 | + |
|
55 | + public function statusIn($statuses) |
|
56 | + { |
|
57 | + $this->inClause('status', $statuses); |
|
58 | + |
|
59 | + return $this; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param string $role |
|
64 | + * |
|
65 | + * @return $this |
|
66 | + */ |
|
67 | + public function byRole($role) |
|
68 | + { |
|
69 | + $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
70 | + $this->whereClause .= ' AND r.role = ?'; |
|
71 | + $this->parameterList[] = $role; |
|
72 | + |
|
73 | + return $this; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param DateTime $instant |
|
78 | + * |
|
79 | + * @return $this |
|
80 | + */ |
|
81 | + public function lastActiveBefore(DateTime $instant) |
|
82 | + { |
|
83 | + $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?'; |
|
84 | + $this->joinClause .= <<<'SQLFRAG' |
|
85 | 85 | LEFT JOIN ( |
86 | 86 | SELECT objectid, MAX(timestamp) timestamp |
87 | 87 | FROM log |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | GROUP BY objectid |
90 | 90 | ) approvaldate ON approvaldate.objectid = origin.id |
91 | 91 | SQLFRAG; |
92 | - $formattedDate = $instant->format("Y-m-d H:i:s"); |
|
93 | - $this->parameterList[] = $formattedDate; |
|
94 | - $this->parameterList[] = $formattedDate; |
|
92 | + $formattedDate = $instant->format("Y-m-d H:i:s"); |
|
93 | + $this->parameterList[] = $formattedDate; |
|
94 | + $this->parameterList[] = $formattedDate; |
|
95 | 95 | |
96 | - return $this; |
|
97 | - } |
|
96 | + return $this; |
|
97 | + } |
|
98 | 98 | |
99 | - public function getRoleMap(&$roleMap) |
|
100 | - { |
|
101 | - $query = <<<SQL |
|
99 | + public function getRoleMap(&$roleMap) |
|
100 | + { |
|
101 | + $query = <<<SQL |
|
102 | 102 | SELECT /* UserSearchHelper/roleMap */ |
103 | 103 | r.user user |
104 | 104 | , group_concat(r.role SEPARATOR ', ') roles |
@@ -107,22 +107,22 @@ discard block |
||
107 | 107 | GROUP BY r.user |
108 | 108 | SQL; |
109 | 109 | |
110 | - $statement = $this->database->prepare($query); |
|
111 | - $statement->execute($this->parameterList); |
|
110 | + $statement = $this->database->prepare($query); |
|
111 | + $statement->execute($this->parameterList); |
|
112 | 112 | |
113 | - $roleMap = array(); |
|
114 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
115 | - $roleMap[$row['user']] = $row['roles']; |
|
116 | - } |
|
113 | + $roleMap = array(); |
|
114 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
115 | + $roleMap[$row['user']] = $row['roles']; |
|
116 | + } |
|
117 | 117 | |
118 | - return $this; |
|
119 | - } |
|
118 | + return $this; |
|
119 | + } |
|
120 | 120 | |
121 | - public function withReservedRequest() |
|
122 | - { |
|
123 | - $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id'; |
|
124 | - $this->groupByClause = ' GROUP BY origin.id, origin.username'; |
|
121 | + public function withReservedRequest() |
|
122 | + { |
|
123 | + $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id'; |
|
124 | + $this->groupByClause = ' GROUP BY origin.id, origin.username'; |
|
125 | 125 | |
126 | - return $this->fetchMap('username'); |
|
127 | - } |
|
126 | + return $this->fetchMap('username'); |
|
127 | + } |
|
128 | 128 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | interface IMediaWikiClient |
12 | 12 | { |
13 | - function doApiCall($params, $method); |
|
13 | + function doApiCall($params, $method); |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -12,24 +12,24 @@ |
||
12 | 12 | |
13 | 13 | abstract class ApiPageBase extends TaskBase implements IRoutedTask, IApiAction |
14 | 14 | { |
15 | - final public function execute() |
|
16 | - { |
|
17 | - $this->main(); |
|
18 | - } |
|
15 | + final public function execute() |
|
16 | + { |
|
17 | + $this->main(); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param string $routeName |
|
22 | - */ |
|
23 | - public function setRoute($routeName) |
|
24 | - { |
|
25 | - // no-op |
|
26 | - } |
|
20 | + /** |
|
21 | + * @param string $routeName |
|
22 | + */ |
|
23 | + public function setRoute($routeName) |
|
24 | + { |
|
25 | + // no-op |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function getRouteName() |
|
32 | - { |
|
33 | - return 'main'; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function getRouteName() |
|
32 | + { |
|
33 | + return 'main'; |
|
34 | + } |
|
35 | 35 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | |
18 | 18 | abstract class XmlApiPageBase extends ApiPageBase implements IXmlApiAction |
19 | 19 | { |
20 | - /** |
|
21 | - * API result document |
|
22 | - * @var DOMDocument |
|
23 | - */ |
|
24 | - protected $document; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->document = new DOMDocument('1.0'); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Main function for this page, when no specific actions are called. |
|
33 | - * |
|
34 | - * @throws ApiException |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - final protected function main() |
|
38 | - { |
|
39 | - if (headers_sent()) { |
|
40 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
41 | - } |
|
42 | - |
|
43 | - header("Content-Type: text/xml"); |
|
44 | - |
|
45 | - // javascript access control |
|
46 | - $httpOrigin = WebRequest::origin(); |
|
47 | - |
|
48 | - if ($httpOrigin !== null) { |
|
49 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
50 | - |
|
51 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
52 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - $responseData = $this->runApiPage(); |
|
57 | - |
|
58 | - ob_end_clean(); |
|
59 | - print($responseData); |
|
60 | - ob_start(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Method that runs API action |
|
65 | - * |
|
66 | - * @param DOMElement $apiDocument |
|
67 | - * |
|
68 | - * @return DOMElement |
|
69 | - */ |
|
70 | - abstract public function executeApiAction(DOMElement $apiDocument); |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - final public function runApiPage() |
|
76 | - { |
|
77 | - $apiDocument = $this->document->createElement("api"); |
|
78 | - |
|
79 | - try { |
|
80 | - $apiDocument = $this->executeApiAction($apiDocument); |
|
81 | - } |
|
82 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
83 | - catch (ApiException $ex) { |
|
84 | - $exception = $this->document->createElement("error"); |
|
85 | - $exception->setAttribute("message", $ex->getMessage()); |
|
86 | - $apiDocument->appendChild($exception); |
|
87 | - } |
|
88 | - |
|
89 | - $this->document->appendChild($apiDocument); |
|
90 | - |
|
91 | - return $this->document->saveXML(); |
|
92 | - } |
|
20 | + /** |
|
21 | + * API result document |
|
22 | + * @var DOMDocument |
|
23 | + */ |
|
24 | + protected $document; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->document = new DOMDocument('1.0'); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Main function for this page, when no specific actions are called. |
|
33 | + * |
|
34 | + * @throws ApiException |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + final protected function main() |
|
38 | + { |
|
39 | + if (headers_sent()) { |
|
40 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
41 | + } |
|
42 | + |
|
43 | + header("Content-Type: text/xml"); |
|
44 | + |
|
45 | + // javascript access control |
|
46 | + $httpOrigin = WebRequest::origin(); |
|
47 | + |
|
48 | + if ($httpOrigin !== null) { |
|
49 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
50 | + |
|
51 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
52 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + $responseData = $this->runApiPage(); |
|
57 | + |
|
58 | + ob_end_clean(); |
|
59 | + print($responseData); |
|
60 | + ob_start(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Method that runs API action |
|
65 | + * |
|
66 | + * @param DOMElement $apiDocument |
|
67 | + * |
|
68 | + * @return DOMElement |
|
69 | + */ |
|
70 | + abstract public function executeApiAction(DOMElement $apiDocument); |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + final public function runApiPage() |
|
76 | + { |
|
77 | + $apiDocument = $this->document->createElement("api"); |
|
78 | + |
|
79 | + try { |
|
80 | + $apiDocument = $this->executeApiAction($apiDocument); |
|
81 | + } |
|
82 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
83 | + catch (ApiException $ex) { |
|
84 | + $exception = $this->document->createElement("error"); |
|
85 | + $exception->setAttribute("message", $ex->getMessage()); |
|
86 | + $apiDocument->appendChild($exception); |
|
87 | + } |
|
88 | + |
|
89 | + $this->document->appendChild($apiDocument); |
|
90 | + |
|
91 | + return $this->document->saveXML(); |
|
92 | + } |
|
93 | 93 | } |