@@ -16,18 +16,18 @@ |
||
16 | 16 | |
17 | 17 | class JsUsersAction extends JsonApiPageBase implements IJsonApiAction |
18 | 18 | { |
19 | - public function executeApiAction() |
|
20 | - { |
|
21 | - $this->getDatabase(); |
|
19 | + public function executeApiAction() |
|
20 | + { |
|
21 | + $this->getDatabase(); |
|
22 | 22 | |
23 | - $userSearchHelper = UserSearchHelper::get($this->getDatabase()); |
|
23 | + $userSearchHelper = UserSearchHelper::get($this->getDatabase()); |
|
24 | 24 | |
25 | - if (WebRequest::getString('all') === null) { |
|
26 | - $userSearchHelper->byStatus(User::STATUS_ACTIVE); |
|
25 | + if (WebRequest::getString('all') === null) { |
|
26 | + $userSearchHelper->byStatus(User::STATUS_ACTIVE); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - $dataset = $userSearchHelper->fetchColumn('username'); |
|
31 | - return $dataset; |
|
32 | - } |
|
30 | + $dataset = $userSearchHelper->fetchColumn('username'); |
|
31 | + return $dataset; |
|
32 | + } |
|
33 | 33 | } |
@@ -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 | } |
@@ -17,67 +17,67 @@ |
||
17 | 17 | */ |
18 | 18 | class StatusAction extends XmlApiPageBase implements IXmlApiAction |
19 | 19 | { |
20 | - public function executeApiAction(DOMElement $apiDocument) |
|
21 | - { |
|
22 | - $statusElement = $this->document->createElement("status"); |
|
23 | - $apiDocument->appendChild($statusElement); |
|
20 | + public function executeApiAction(DOMElement $apiDocument) |
|
21 | + { |
|
22 | + $statusElement = $this->document->createElement("status"); |
|
23 | + $apiDocument->appendChild($statusElement); |
|
24 | 24 | |
25 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
25 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
26 | 26 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
27 | 27 | FROM request |
28 | 28 | WHERE |
29 | 29 | status = :pstatus |
30 | 30 | AND emailconfirm = 'Confirmed'; |
31 | 31 | SQL |
32 | - ); |
|
32 | + ); |
|
33 | 33 | |
34 | - $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
34 | + $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
35 | 35 | |
36 | - foreach ($availableRequestStates as $key => $value) { |
|
37 | - $query->bindValue(":pstatus", $key); |
|
38 | - $query->execute(); |
|
39 | - $sus = $query->fetchColumn(); |
|
40 | - $statusElement->setAttribute($value['api'], $sus); |
|
41 | - $query->closeCursor(); |
|
42 | - } |
|
36 | + foreach ($availableRequestStates as $key => $value) { |
|
37 | + $query->bindValue(":pstatus", $key); |
|
38 | + $query->execute(); |
|
39 | + $sus = $query->fetchColumn(); |
|
40 | + $statusElement->setAttribute($value['api'], $sus); |
|
41 | + $query->closeCursor(); |
|
42 | + } |
|
43 | 43 | |
44 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
44 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
45 | 45 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
46 | 46 | FROM ban |
47 | 47 | WHERE |
48 | 48 | (duration > UNIX_TIMESTAMP() OR duration = -1) |
49 | 49 | AND active = 1; |
50 | 50 | SQL |
51 | - ); |
|
51 | + ); |
|
52 | 52 | |
53 | - $query->execute(); |
|
54 | - $sus = $query->fetchColumn(); |
|
55 | - $statusElement->setAttribute("bans", $sus); |
|
56 | - $query->closeCursor(); |
|
53 | + $query->execute(); |
|
54 | + $sus = $query->fetchColumn(); |
|
55 | + $statusElement->setAttribute("bans", $sus); |
|
56 | + $query->closeCursor(); |
|
57 | 57 | |
58 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
58 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
59 | 59 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
60 | 60 | FROM user WHERE status = :ulevel; |
61 | 61 | SQL |
62 | - ); |
|
63 | - $query->bindValue(":ulevel", "Admin"); |
|
64 | - $query->execute(); |
|
65 | - $sus = $query->fetchColumn(); |
|
66 | - $statusElement->setAttribute("useradmin", $sus); |
|
67 | - $query->closeCursor(); |
|
62 | + ); |
|
63 | + $query->bindValue(":ulevel", "Admin"); |
|
64 | + $query->execute(); |
|
65 | + $sus = $query->fetchColumn(); |
|
66 | + $statusElement->setAttribute("useradmin", $sus); |
|
67 | + $query->closeCursor(); |
|
68 | 68 | |
69 | - $query->bindValue(":ulevel", "User"); |
|
70 | - $query->execute(); |
|
71 | - $sus = $query->fetchColumn(); |
|
72 | - $statusElement->setAttribute("user", $sus); |
|
73 | - $query->closeCursor(); |
|
69 | + $query->bindValue(":ulevel", "User"); |
|
70 | + $query->execute(); |
|
71 | + $sus = $query->fetchColumn(); |
|
72 | + $statusElement->setAttribute("user", $sus); |
|
73 | + $query->closeCursor(); |
|
74 | 74 | |
75 | - $query->bindValue(":ulevel", "New"); |
|
76 | - $query->execute(); |
|
77 | - $sus = $query->fetchColumn(); |
|
78 | - $statusElement->setAttribute("usernew", $sus); |
|
79 | - $query->closeCursor(); |
|
75 | + $query->bindValue(":ulevel", "New"); |
|
76 | + $query->execute(); |
|
77 | + $sus = $query->fetchColumn(); |
|
78 | + $statusElement->setAttribute("usernew", $sus); |
|
79 | + $query->closeCursor(); |
|
80 | 80 | |
81 | - return $apiDocument; |
|
82 | - } |
|
81 | + return $apiDocument; |
|
82 | + } |
|
83 | 83 | } |
@@ -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 | } |
@@ -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 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | { |
23 | 23 | $dataList = ''; |
24 | 24 | foreach ($generator() as $dataItem) { |
25 | - $dataList .= '"' . htmlentities($dataItem) . '", '; |
|
25 | + $dataList .= '"'.htmlentities($dataItem).'", '; |
|
26 | 26 | } |
27 | - $dataList = "[" . rtrim($dataList, ", ") . "]"; |
|
27 | + $dataList = "[".rtrim($dataList, ", ")."]"; |
|
28 | 28 | |
29 | 29 | $script = <<<JS |
30 | 30 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | foreach ($this->definedClasses as $class => $js) { |
57 | - $jsBlocks = $js . "\r\n\r\n"; |
|
57 | + $jsBlocks = $js."\r\n\r\n"; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $data = <<<HTML |
@@ -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,76 +17,76 @@ |
||
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 | - catch (ApiException $ex) { |
|
83 | - $exception = $this->document->createElement("error"); |
|
84 | - $exception->setAttribute("message", $ex->getMessage()); |
|
85 | - $apiDocument->appendChild($exception); |
|
86 | - } |
|
87 | - |
|
88 | - $this->document->appendChild($apiDocument); |
|
89 | - |
|
90 | - return $this->document->saveXML(); |
|
91 | - } |
|
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 | + catch (ApiException $ex) { |
|
83 | + $exception = $this->document->createElement("error"); |
|
84 | + $exception->setAttribute("message", $ex->getMessage()); |
|
85 | + $apiDocument->appendChild($exception); |
|
86 | + } |
|
87 | + |
|
88 | + $this->document->appendChild($apiDocument); |
|
89 | + |
|
90 | + return $this->document->saveXML(); |
|
91 | + } |
|
92 | 92 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
70 | 70 | |
71 | 71 | if (in_array($httpOrigin, $CORSallowed)) { |
72 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
72 | + header("Access-Control-Allow-Origin: ".$httpOrigin); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 |
@@ -18,34 +18,34 @@ |
||
18 | 18 | */ |
19 | 19 | class HelpAction extends XmlApiPageBase implements IXmlApiAction |
20 | 20 | { |
21 | - public function executeApiAction(DOMElement $apiDocument) |
|
22 | - { |
|
23 | - $helpElement = $this->getHelpElement(); |
|
24 | - $apiDocument->appendChild($helpElement); |
|
25 | - |
|
26 | - return $apiDocument; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Gets the help information |
|
31 | - * @return DOMElement |
|
32 | - */ |
|
33 | - protected function getHelpElement() |
|
34 | - { |
|
21 | + public function executeApiAction(DOMElement $apiDocument) |
|
22 | + { |
|
23 | + $helpElement = $this->getHelpElement(); |
|
24 | + $apiDocument->appendChild($helpElement); |
|
25 | + |
|
26 | + return $apiDocument; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Gets the help information |
|
31 | + * @return DOMElement |
|
32 | + */ |
|
33 | + protected function getHelpElement() |
|
34 | + { |
|
35 | 35 | $helpInfo = "API help can be found at https://github.com/enwikipedia-acc/waca/wiki/API"; |
36 | 36 | |
37 | - $help = $this->document->createElement("help"); |
|
38 | - $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | - $helpactions = $this->document->createElement("actions"); |
|
37 | + $help = $this->document->createElement("help"); |
|
38 | + $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | + $helpactions = $this->document->createElement("actions"); |
|
40 | 40 | |
41 | - foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | - $actionElement = $this->document->createElement("action", $action); |
|
43 | - $helpactions->appendChild($actionElement); |
|
44 | - } |
|
41 | + foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | + $actionElement = $this->document->createElement("action", $action); |
|
43 | + $helpactions->appendChild($actionElement); |
|
44 | + } |
|
45 | 45 | |
46 | - $help->appendChild($helptext); |
|
47 | - $help->appendChild($helpactions); |
|
46 | + $help->appendChild($helptext); |
|
47 | + $help->appendChild($helpactions); |
|
48 | 48 | |
49 | - return $help; |
|
50 | - } |
|
49 | + return $help; |
|
50 | + } |
|
51 | 51 | } |
@@ -22,58 +22,58 @@ |
||
22 | 22 | */ |
23 | 23 | class StatsAction extends XmlApiPageBase implements IXmlApiAction |
24 | 24 | { |
25 | - /** |
|
26 | - * The target user |
|
27 | - * @var User $user |
|
28 | - */ |
|
29 | - private $user; |
|
25 | + /** |
|
26 | + * The target user |
|
27 | + * @var User $user |
|
28 | + */ |
|
29 | + private $user; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Summary of execute |
|
33 | - * |
|
34 | - * @param DOMElement $apiDocument |
|
35 | - * |
|
36 | - * @return DOMElement |
|
37 | - * @throws ApiException |
|
38 | - * @throws Exception |
|
39 | - */ |
|
40 | - public function executeApiAction(DOMElement $apiDocument) |
|
41 | - { |
|
42 | - $username = WebRequest::getString('user'); |
|
43 | - $wikiusername = WebRequest::getString('wikiuser'); |
|
31 | + /** |
|
32 | + * Summary of execute |
|
33 | + * |
|
34 | + * @param DOMElement $apiDocument |
|
35 | + * |
|
36 | + * @return DOMElement |
|
37 | + * @throws ApiException |
|
38 | + * @throws Exception |
|
39 | + */ |
|
40 | + public function executeApiAction(DOMElement $apiDocument) |
|
41 | + { |
|
42 | + $username = WebRequest::getString('user'); |
|
43 | + $wikiusername = WebRequest::getString('wikiuser'); |
|
44 | 44 | |
45 | - if ($username === null && $wikiusername === null) { |
|
46 | - throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
47 | - } |
|
45 | + if ($username === null && $wikiusername === null) { |
|
46 | + throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
47 | + } |
|
48 | 48 | |
49 | - $userElement = $this->document->createElement("user"); |
|
50 | - $apiDocument->appendChild($userElement); |
|
49 | + $userElement = $this->document->createElement("user"); |
|
50 | + $apiDocument->appendChild($userElement); |
|
51 | 51 | |
52 | - if ($username !== null) { |
|
53 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
54 | - } |
|
55 | - else { |
|
56 | - $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
57 | - } |
|
52 | + if ($username !== null) { |
|
53 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
54 | + } |
|
55 | + else { |
|
56 | + $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
57 | + } |
|
58 | 58 | |
59 | - if ($user === false) { |
|
60 | - $userElement->setAttribute("missing", "true"); |
|
59 | + if ($user === false) { |
|
60 | + $userElement->setAttribute("missing", "true"); |
|
61 | 61 | |
62 | - return $apiDocument; |
|
63 | - } |
|
62 | + return $apiDocument; |
|
63 | + } |
|
64 | 64 | |
65 | - $this->user = $user; |
|
65 | + $this->user = $user; |
|
66 | 66 | |
67 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
68 | - $this->getSiteConfiguration()); |
|
67 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
68 | + $this->getSiteConfiguration()); |
|
69 | 69 | |
70 | - $userElement->setAttribute("username", $this->user->getUsername()); |
|
71 | - $userElement->setAttribute("status", $this->user->getStatus()); |
|
72 | - $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
73 | - $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
74 | - $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
75 | - $userElement->setAttribute("oauth", $oauth->isFullyLinked() ? "true" : "false"); |
|
70 | + $userElement->setAttribute("username", $this->user->getUsername()); |
|
71 | + $userElement->setAttribute("status", $this->user->getStatus()); |
|
72 | + $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
73 | + $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
74 | + $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
75 | + $userElement->setAttribute("oauth", $oauth->isFullyLinked() ? "true" : "false"); |
|
76 | 76 | |
77 | - return $apiDocument; |
|
78 | - } |
|
77 | + return $apiDocument; |
|
78 | + } |
|
79 | 79 | } |