@@ -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 | } |
@@ -19,55 +19,55 @@ |
||
19 | 19 | */ |
20 | 20 | class StatsAction extends XmlApiPageBase implements IXmlApiAction |
21 | 21 | { |
22 | - /** |
|
23 | - * The target user |
|
24 | - * @var User $user |
|
25 | - */ |
|
26 | - private $user; |
|
22 | + /** |
|
23 | + * The target user |
|
24 | + * @var User $user |
|
25 | + */ |
|
26 | + private $user; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Summary of execute |
|
30 | - * |
|
31 | - * @param \DOMElement $apiDocument |
|
32 | - * |
|
33 | - * @return \DOMElement |
|
34 | - * @throws ApiException |
|
35 | - * @throws \Exception |
|
36 | - */ |
|
37 | - public function executeApiAction(\DOMElement $apiDocument) |
|
38 | - { |
|
39 | - $username = WebRequest::getString('user'); |
|
40 | - $wikiusername = WebRequest::getString('wikiuser'); |
|
28 | + /** |
|
29 | + * Summary of execute |
|
30 | + * |
|
31 | + * @param \DOMElement $apiDocument |
|
32 | + * |
|
33 | + * @return \DOMElement |
|
34 | + * @throws ApiException |
|
35 | + * @throws \Exception |
|
36 | + */ |
|
37 | + public function executeApiAction(\DOMElement $apiDocument) |
|
38 | + { |
|
39 | + $username = WebRequest::getString('user'); |
|
40 | + $wikiusername = WebRequest::getString('wikiuser'); |
|
41 | 41 | |
42 | - if ($username === null && $wikiusername === null) { |
|
43 | - throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
44 | - } |
|
42 | + if ($username === null && $wikiusername === null) { |
|
43 | + throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
44 | + } |
|
45 | 45 | |
46 | - $userElement = $this->document->createElement("user"); |
|
47 | - $apiDocument->appendChild($userElement); |
|
46 | + $userElement = $this->document->createElement("user"); |
|
47 | + $apiDocument->appendChild($userElement); |
|
48 | 48 | |
49 | - if ($username !== null) { |
|
50 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
51 | - } |
|
52 | - else { |
|
53 | - $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
54 | - } |
|
49 | + if ($username !== null) { |
|
50 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
51 | + } |
|
52 | + else { |
|
53 | + $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
54 | + } |
|
55 | 55 | |
56 | - if ($user === false) { |
|
57 | - $userElement->setAttribute("missing", "true"); |
|
56 | + if ($user === false) { |
|
57 | + $userElement->setAttribute("missing", "true"); |
|
58 | 58 | |
59 | - return $apiDocument; |
|
60 | - } |
|
59 | + return $apiDocument; |
|
60 | + } |
|
61 | 61 | |
62 | - $this->user = $user; |
|
62 | + $this->user = $user; |
|
63 | 63 | |
64 | - $userElement->setAttribute("username", $this->user->getUsername()); |
|
65 | - $userElement->setAttribute("status", $this->user->getStatus()); |
|
66 | - $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
67 | - $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
68 | - $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
69 | - $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false"); |
|
64 | + $userElement->setAttribute("username", $this->user->getUsername()); |
|
65 | + $userElement->setAttribute("status", $this->user->getStatus()); |
|
66 | + $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
67 | + $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
68 | + $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
69 | + $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false"); |
|
70 | 70 | |
71 | - return $apiDocument; |
|
72 | - } |
|
71 | + return $apiDocument; |
|
72 | + } |
|
73 | 73 | } |
@@ -20,47 +20,47 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class CountAction extends XmlApiPageBase implements IXmlApiAction |
22 | 22 | { |
23 | - /** |
|
24 | - * The target user |
|
25 | - * @var User $user |
|
26 | - */ |
|
27 | - private $user; |
|
23 | + /** |
|
24 | + * The target user |
|
25 | + * @var User $user |
|
26 | + */ |
|
27 | + private $user; |
|
28 | 28 | |
29 | - public function executeApiAction(DOMElement $apiDocument) |
|
30 | - { |
|
31 | - $username = WebRequest::getString('user'); |
|
32 | - if ($username === null) { |
|
33 | - throw new ApiException("Please specify a username"); |
|
34 | - } |
|
29 | + public function executeApiAction(DOMElement $apiDocument) |
|
30 | + { |
|
31 | + $username = WebRequest::getString('user'); |
|
32 | + if ($username === null) { |
|
33 | + throw new ApiException("Please specify a username"); |
|
34 | + } |
|
35 | 35 | |
36 | - $userElement = $this->document->createElement("user"); |
|
37 | - $userElement->setAttribute("name", $username); |
|
38 | - $apiDocument->appendChild($userElement); |
|
36 | + $userElement = $this->document->createElement("user"); |
|
37 | + $userElement->setAttribute("name", $username); |
|
38 | + $apiDocument->appendChild($userElement); |
|
39 | 39 | |
40 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
40 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
41 | 41 | |
42 | - if ($user === false) { |
|
43 | - $userElement->setAttribute("missing", "true"); |
|
42 | + if ($user === false) { |
|
43 | + $userElement->setAttribute("missing", "true"); |
|
44 | 44 | |
45 | - return $apiDocument; |
|
46 | - } |
|
45 | + return $apiDocument; |
|
46 | + } |
|
47 | 47 | |
48 | - $this->user = $user; |
|
48 | + $this->user = $user; |
|
49 | 49 | |
50 | - $userElement->setAttribute("level", $this->user->getStatus()); |
|
51 | - $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
50 | + $userElement->setAttribute("level", $this->user->getStatus()); |
|
51 | + $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
52 | 52 | |
53 | - $userElement->setAttribute("today", $this->getToday()); |
|
53 | + $userElement->setAttribute("today", $this->getToday()); |
|
54 | 54 | |
55 | - // Let the IRC bot handle the result of this. |
|
56 | - $this->fetchAdminData($userElement); |
|
55 | + // Let the IRC bot handle the result of this. |
|
56 | + $this->fetchAdminData($userElement); |
|
57 | 57 | |
58 | - return $apiDocument; |
|
59 | - } |
|
58 | + return $apiDocument; |
|
59 | + } |
|
60 | 60 | |
61 | - private function getAccountsCreated() |
|
62 | - { |
|
63 | - $query = <<<QUERY |
|
61 | + private function getAccountsCreated() |
|
62 | + { |
|
63 | + $query = <<<QUERY |
|
64 | 64 | SELECT COUNT(*) AS count |
65 | 65 | FROM log |
66 | 66 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | AND user.username = :username; |
72 | 72 | QUERY; |
73 | 73 | |
74 | - $statement = $this->getDatabase()->prepare($query); |
|
75 | - $statement->execute(array(":username" => $this->user->getUsername())); |
|
76 | - $result = $statement->fetchColumn(); |
|
77 | - $statement->closeCursor(); |
|
74 | + $statement = $this->getDatabase()->prepare($query); |
|
75 | + $statement->execute(array(":username" => $this->user->getUsername())); |
|
76 | + $result = $statement->fetchColumn(); |
|
77 | + $statement->closeCursor(); |
|
78 | 78 | |
79 | - return $result; |
|
80 | - } |
|
79 | + return $result; |
|
80 | + } |
|
81 | 81 | |
82 | - private function getToday() |
|
83 | - { |
|
84 | - $query = <<<QUERY |
|
82 | + private function getToday() |
|
83 | + { |
|
84 | + $query = <<<QUERY |
|
85 | 85 | SELECT |
86 | 86 | COUNT(*) AS count |
87 | 87 | FROM log |
@@ -93,99 +93,99 @@ discard block |
||
93 | 93 | AND user.username = :username; |
94 | 94 | QUERY; |
95 | 95 | |
96 | - $statement = $this->getDatabase()->prepare($query); |
|
97 | - $statement->bindValue(":username", $this->user->getUsername()); |
|
98 | - $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
99 | - $statement->execute(); |
|
100 | - $today = $statement->fetchColumn(); |
|
101 | - $statement->closeCursor(); |
|
102 | - |
|
103 | - return $today; |
|
104 | - } |
|
105 | - |
|
106 | - private function fetchAdminData(DOMElement $userElement) |
|
107 | - { |
|
108 | - $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
109 | - |
|
110 | - $statement = $this->getDatabase()->prepare($query); |
|
111 | - $statement->bindValue(":userid", $this->user->getId()); |
|
112 | - $statement->bindValue(":action", "Suspended"); |
|
113 | - $statement->execute(); |
|
114 | - $sus = $statement->fetchColumn(); |
|
115 | - $userElement->setAttribute("suspended", $sus); |
|
116 | - $statement->closeCursor(); |
|
117 | - |
|
118 | - $statement->bindValue(":action", "Promoted"); |
|
119 | - $statement->execute(); |
|
120 | - $pro = $statement->fetchColumn(); |
|
121 | - $userElement->setAttribute("promoted", $pro); |
|
122 | - $statement->closeCursor(); |
|
123 | - |
|
124 | - $statement->bindValue(":action", "Approved"); |
|
125 | - $statement->execute(); |
|
126 | - $app = $statement->fetchColumn(); |
|
127 | - $userElement->setAttribute("approved", $app); |
|
128 | - $statement->closeCursor(); |
|
129 | - |
|
130 | - $statement->bindValue(":action", "Demoted"); |
|
131 | - $statement->execute(); |
|
132 | - $dem = $statement->fetchColumn(); |
|
133 | - $userElement->setAttribute("demoted", $dem); |
|
134 | - $statement->closeCursor(); |
|
135 | - |
|
136 | - $statement->bindValue(":action", "Declined"); |
|
137 | - $statement->execute(); |
|
138 | - $dec = $statement->fetchColumn(); |
|
139 | - $userElement->setAttribute("declined", $dec); |
|
140 | - $statement->closeCursor(); |
|
141 | - |
|
142 | - $statement->bindValue(":action", "Renamed"); |
|
143 | - $statement->execute(); |
|
144 | - $rnc = $statement->fetchColumn(); |
|
145 | - $userElement->setAttribute("renamed", $rnc); |
|
146 | - $statement->closeCursor(); |
|
147 | - |
|
148 | - $statement->bindValue(":action", "Edited"); |
|
149 | - $statement->execute(); |
|
150 | - $mec = $statement->fetchColumn(); |
|
151 | - $userElement->setAttribute("edited", $mec); |
|
152 | - $statement->closeCursor(); |
|
153 | - |
|
154 | - $statement->bindValue(":action", "Prefchange"); |
|
155 | - $statement->execute(); |
|
156 | - $pcc = $statement->fetchColumn(); |
|
157 | - $userElement->setAttribute("prefchange", $pcc); |
|
158 | - $statement->closeCursor(); |
|
159 | - |
|
160 | - // Combine all three actions affecting Welcome templates into one count. |
|
161 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
96 | + $statement = $this->getDatabase()->prepare($query); |
|
97 | + $statement->bindValue(":username", $this->user->getUsername()); |
|
98 | + $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
99 | + $statement->execute(); |
|
100 | + $today = $statement->fetchColumn(); |
|
101 | + $statement->closeCursor(); |
|
102 | + |
|
103 | + return $today; |
|
104 | + } |
|
105 | + |
|
106 | + private function fetchAdminData(DOMElement $userElement) |
|
107 | + { |
|
108 | + $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
109 | + |
|
110 | + $statement = $this->getDatabase()->prepare($query); |
|
111 | + $statement->bindValue(":userid", $this->user->getId()); |
|
112 | + $statement->bindValue(":action", "Suspended"); |
|
113 | + $statement->execute(); |
|
114 | + $sus = $statement->fetchColumn(); |
|
115 | + $userElement->setAttribute("suspended", $sus); |
|
116 | + $statement->closeCursor(); |
|
117 | + |
|
118 | + $statement->bindValue(":action", "Promoted"); |
|
119 | + $statement->execute(); |
|
120 | + $pro = $statement->fetchColumn(); |
|
121 | + $userElement->setAttribute("promoted", $pro); |
|
122 | + $statement->closeCursor(); |
|
123 | + |
|
124 | + $statement->bindValue(":action", "Approved"); |
|
125 | + $statement->execute(); |
|
126 | + $app = $statement->fetchColumn(); |
|
127 | + $userElement->setAttribute("approved", $app); |
|
128 | + $statement->closeCursor(); |
|
129 | + |
|
130 | + $statement->bindValue(":action", "Demoted"); |
|
131 | + $statement->execute(); |
|
132 | + $dem = $statement->fetchColumn(); |
|
133 | + $userElement->setAttribute("demoted", $dem); |
|
134 | + $statement->closeCursor(); |
|
135 | + |
|
136 | + $statement->bindValue(":action", "Declined"); |
|
137 | + $statement->execute(); |
|
138 | + $dec = $statement->fetchColumn(); |
|
139 | + $userElement->setAttribute("declined", $dec); |
|
140 | + $statement->closeCursor(); |
|
141 | + |
|
142 | + $statement->bindValue(":action", "Renamed"); |
|
143 | + $statement->execute(); |
|
144 | + $rnc = $statement->fetchColumn(); |
|
145 | + $userElement->setAttribute("renamed", $rnc); |
|
146 | + $statement->closeCursor(); |
|
147 | + |
|
148 | + $statement->bindValue(":action", "Edited"); |
|
149 | + $statement->execute(); |
|
150 | + $mec = $statement->fetchColumn(); |
|
151 | + $userElement->setAttribute("edited", $mec); |
|
152 | + $statement->closeCursor(); |
|
153 | + |
|
154 | + $statement->bindValue(":action", "Prefchange"); |
|
155 | + $statement->execute(); |
|
156 | + $pcc = $statement->fetchColumn(); |
|
157 | + $userElement->setAttribute("prefchange", $pcc); |
|
158 | + $statement->closeCursor(); |
|
159 | + |
|
160 | + // Combine all three actions affecting Welcome templates into one count. |
|
161 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
162 | 162 | SELECT |
163 | 163 | COUNT(*) AS count |
164 | 164 | FROM log |
165 | 165 | WHERE log.user = :userid |
166 | 166 | AND log.action IN ('CreatedTemplate', 'EditedTemplate', 'DeletedTemplate'); |
167 | 167 | SQL |
168 | - ); |
|
168 | + ); |
|
169 | 169 | |
170 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
171 | - $combinedquery->execute(); |
|
172 | - $dtc = $combinedquery->fetchColumn(); |
|
173 | - $userElement->setAttribute("welctempchange", $dtc); |
|
174 | - $combinedquery->closeCursor(); |
|
170 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
171 | + $combinedquery->execute(); |
|
172 | + $dtc = $combinedquery->fetchColumn(); |
|
173 | + $userElement->setAttribute("welctempchange", $dtc); |
|
174 | + $combinedquery->closeCursor(); |
|
175 | 175 | |
176 | - // Combine both actions affecting Email templates into one count. |
|
177 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
176 | + // Combine both actions affecting Email templates into one count. |
|
177 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
178 | 178 | SELECT COUNT(*) AS count |
179 | 179 | FROM log |
180 | 180 | WHERE log.user = :userid |
181 | 181 | AND log.action IN ('CreatedEmail', 'EditedEmail'); |
182 | 182 | SQL |
183 | - ); |
|
184 | - |
|
185 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
186 | - $combinedquery->execute(); |
|
187 | - $cec = $combinedquery->fetchColumn(); |
|
188 | - $userElement->setAttribute("emailtempchange", $cec); |
|
189 | - $combinedquery->closeCursor(); |
|
190 | - } |
|
183 | + ); |
|
184 | + |
|
185 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
186 | + $combinedquery->execute(); |
|
187 | + $cec = $combinedquery->fetchColumn(); |
|
188 | + $userElement->setAttribute("emailtempchange", $cec); |
|
189 | + $combinedquery->closeCursor(); |
|
190 | + } |
|
191 | 191 | } |
@@ -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 | } |
@@ -15,74 +15,74 @@ |
||
15 | 15 | |
16 | 16 | trait TemplateOutput |
17 | 17 | { |
18 | - /** @var Smarty */ |
|
19 | - private $smarty; |
|
18 | + /** @var Smarty */ |
|
19 | + private $smarty; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return SiteConfiguration |
|
23 | - */ |
|
24 | - protected abstract function getSiteConfiguration(); |
|
21 | + /** |
|
22 | + * @return SiteConfiguration |
|
23 | + */ |
|
24 | + protected abstract function getSiteConfiguration(); |
|
25 | 25 | |
26 | - /** |
|
27 | - * Assigns a Smarty variable |
|
28 | - * |
|
29 | - * @param array|string $name the template variable name(s) |
|
30 | - * @param mixed $value the value to assign |
|
31 | - */ |
|
32 | - final protected function assign($name, $value) |
|
33 | - { |
|
34 | - $this->smarty->assign($name, $value); |
|
35 | - } |
|
26 | + /** |
|
27 | + * Assigns a Smarty variable |
|
28 | + * |
|
29 | + * @param array|string $name the template variable name(s) |
|
30 | + * @param mixed $value the value to assign |
|
31 | + */ |
|
32 | + final protected function assign($name, $value) |
|
33 | + { |
|
34 | + $this->smarty->assign($name, $value); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Sets up the variables used by the main Smarty base template. |
|
39 | - * |
|
40 | - * This list is getting kinda long. |
|
41 | - */ |
|
42 | - final protected function setUpSmarty() |
|
43 | - { |
|
44 | - $this->smarty = new Smarty(); |
|
45 | - $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins'); |
|
37 | + /** |
|
38 | + * Sets up the variables used by the main Smarty base template. |
|
39 | + * |
|
40 | + * This list is getting kinda long. |
|
41 | + */ |
|
42 | + final protected function setUpSmarty() |
|
43 | + { |
|
44 | + $this->smarty = new Smarty(); |
|
45 | + $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins'); |
|
46 | 46 | |
47 | - $this->assign('currentUser', User::getCommunity()); |
|
48 | - $this->assign('loggedIn', false); |
|
49 | - $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl()); |
|
50 | - $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath()); |
|
47 | + $this->assign('currentUser', User::getCommunity()); |
|
48 | + $this->assign('loggedIn', false); |
|
49 | + $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl()); |
|
50 | + $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath()); |
|
51 | 51 | |
52 | - $this->assign('siteNoticeText', ''); |
|
53 | - $this->assign('toolversion', Environment::getToolVersion()); |
|
52 | + $this->assign('siteNoticeText', ''); |
|
53 | + $this->assign('toolversion', Environment::getToolVersion()); |
|
54 | 54 | |
55 | - // default these |
|
56 | - $this->assign('onlineusers', array()); |
|
57 | - $this->assign('typeAheadBlock', ''); |
|
58 | - $this->assign('extraJs', array()); |
|
59 | - $this->assign('extraCss', array()); |
|
55 | + // default these |
|
56 | + $this->assign('onlineusers', array()); |
|
57 | + $this->assign('typeAheadBlock', ''); |
|
58 | + $this->assign('extraJs', array()); |
|
59 | + $this->assign('extraCss', array()); |
|
60 | 60 | |
61 | - // nav menu access control |
|
62 | - $this->assign('nav__canRequests', false); |
|
63 | - $this->assign('nav__canLogs', false); |
|
64 | - $this->assign('nav__canUsers', false); |
|
65 | - $this->assign('nav__canSearch', false); |
|
66 | - $this->assign('nav__canStats', false); |
|
67 | - $this->assign('nav__canBan', false); |
|
68 | - $this->assign('nav__canEmailMgmt', false); |
|
69 | - $this->assign('nav__canWelcomeMgmt', false); |
|
70 | - $this->assign('nav__canSiteNoticeMgmt', false); |
|
71 | - $this->assign('nav__canUserMgmt', false); |
|
72 | - $this->assign('nav__canViewRequest', false); |
|
61 | + // nav menu access control |
|
62 | + $this->assign('nav__canRequests', false); |
|
63 | + $this->assign('nav__canLogs', false); |
|
64 | + $this->assign('nav__canUsers', false); |
|
65 | + $this->assign('nav__canSearch', false); |
|
66 | + $this->assign('nav__canStats', false); |
|
67 | + $this->assign('nav__canBan', false); |
|
68 | + $this->assign('nav__canEmailMgmt', false); |
|
69 | + $this->assign('nav__canWelcomeMgmt', false); |
|
70 | + $this->assign('nav__canSiteNoticeMgmt', false); |
|
71 | + $this->assign('nav__canUserMgmt', false); |
|
72 | + $this->assign('nav__canViewRequest', false); |
|
73 | 73 | |
74 | - $this->assign('page', $this); |
|
75 | - } |
|
74 | + $this->assign('page', $this); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Fetches a rendered Smarty template |
|
79 | - * |
|
80 | - * @param $template string Template file path, relative to /templates/ |
|
81 | - * |
|
82 | - * @return string Templated HTML |
|
83 | - */ |
|
84 | - final protected function fetchTemplate($template) |
|
85 | - { |
|
86 | - return $this->smarty->fetch($template); |
|
87 | - } |
|
77 | + /** |
|
78 | + * Fetches a rendered Smarty template |
|
79 | + * |
|
80 | + * @param $template string Template file path, relative to /templates/ |
|
81 | + * |
|
82 | + * @return string Templated HTML |
|
83 | + */ |
|
84 | + final protected function fetchTemplate($template) |
|
85 | + { |
|
86 | + return $this->smarty->fetch($template); |
|
87 | + } |
|
88 | 88 | } |
@@ -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 |
@@ -22,223 +22,223 @@ |
||
22 | 22 | |
23 | 23 | abstract class InternalPageBase extends PageBase |
24 | 24 | { |
25 | - use NavigationMenuAccessControl; |
|
26 | - |
|
27 | - /** @var IdentificationVerifier */ |
|
28 | - private $identificationVerifier; |
|
29 | - /** @var ITypeAheadHelper */ |
|
30 | - private $typeAheadHelper; |
|
31 | - /** @var SecurityManager */ |
|
32 | - private $securityManager; |
|
33 | - /** @var IBlacklistHelper */ |
|
34 | - private $blacklistHelper; |
|
35 | - |
|
36 | - /** |
|
37 | - * @return ITypeAheadHelper |
|
38 | - */ |
|
39 | - public function getTypeAheadHelper() |
|
40 | - { |
|
41 | - return $this->typeAheadHelper; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Sets up the internal IdentificationVerifier instance. Intended to be called from WebStart::setupHelpers(). |
|
46 | - * |
|
47 | - * @param IdentificationVerifier $identificationVerifier |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier) |
|
52 | - { |
|
53 | - $this->identificationVerifier = $identificationVerifier; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param ITypeAheadHelper $typeAheadHelper |
|
58 | - */ |
|
59 | - public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
60 | - { |
|
61 | - $this->typeAheadHelper = $typeAheadHelper; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Runs the page code |
|
66 | - * |
|
67 | - * @throws Exception |
|
68 | - * @category Security-Critical |
|
69 | - */ |
|
70 | - final public function execute() |
|
71 | - { |
|
72 | - if ($this->getRouteName() === null) { |
|
73 | - throw new Exception("Request is unrouted."); |
|
74 | - } |
|
75 | - |
|
76 | - if ($this->getSiteConfiguration() === null) { |
|
77 | - throw new Exception("Page has no configuration!"); |
|
78 | - } |
|
79 | - |
|
80 | - $this->setupPage(); |
|
81 | - |
|
82 | - $this->touchUserLastActive(); |
|
83 | - |
|
84 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
85 | - |
|
86 | - // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
87 | - if (!$this->isProtectedPage()) { |
|
88 | - // This page is /not/ a protected page, as such we can just run it. |
|
89 | - $this->runPage(); |
|
90 | - |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - // Security barrier. |
|
95 | - // |
|
96 | - // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
97 | - // away for us |
|
98 | - $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
99 | - if ($securityResult === SecurityManager::ALLOWED) { |
|
100 | - // We're allowed to run the page, so let's run it. |
|
101 | - $this->runPage(); |
|
102 | - } |
|
103 | - else { |
|
104 | - $this->handleAccessDenied($securityResult); |
|
105 | - |
|
106 | - // Send the headers |
|
107 | - $this->sendResponseHeaders(); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Performs final tasks needed before rendering the page. |
|
113 | - */ |
|
114 | - final public function finalisePage() |
|
115 | - { |
|
116 | - parent::finalisePage(); |
|
117 | - |
|
118 | - $database = $this->getDatabase(); |
|
119 | - |
|
120 | - $currentUser = User::getCurrent($database); |
|
121 | - if (!$currentUser->isCommunityUser()) { |
|
122 | - $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
123 | - $statement = $database->query($sql); |
|
124 | - $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
125 | - $this->assign('onlineusers', $activeUsers); |
|
126 | - } |
|
127 | - |
|
128 | - $this->setupNavMenuAccess($currentUser); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Configures whether the page respects roles or not. You probably want this to return true. |
|
133 | - * |
|
134 | - * Set to false for public pages. You probably want this to return true. |
|
135 | - * |
|
136 | - * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
137 | - * on this page, so you probably want this to return true. |
|
138 | - * |
|
139 | - * @return bool |
|
140 | - * @category Security-Critical |
|
141 | - */ |
|
142 | - protected function isProtectedPage() |
|
143 | - { |
|
144 | - return true; |
|
145 | - } |
|
146 | - |
|
147 | - protected function handleAccessDenied($denyReason) |
|
148 | - { |
|
149 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
150 | - |
|
151 | - // Not allowed to access this resource. |
|
152 | - // Firstly, let's check if we're even logged in. |
|
153 | - if ($currentUser->isCommunityUser()) { |
|
154 | - // Not logged in, redirect to login page |
|
155 | - WebRequest::setPostLoginRedirect(); |
|
156 | - $this->redirect("login"); |
|
157 | - |
|
158 | - return; |
|
159 | - } |
|
160 | - else { |
|
161 | - // Decide whether this was a rights failure, or an identification failure. |
|
162 | - |
|
163 | - if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
|
164 | - // Not identified |
|
165 | - throw new NotIdentifiedException($this->getSecurityManager()); |
|
166 | - } |
|
167 | - elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
168 | - // Nope, plain old access denied |
|
169 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
170 | - } |
|
171 | - else { |
|
172 | - throw new Exception('Unknown response from security manager.'); |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Tests the security barrier for a specified action. |
|
179 | - * |
|
180 | - * Don't use within templates |
|
181 | - * |
|
182 | - * @param string $action |
|
183 | - * |
|
184 | - * @param User $user |
|
185 | - * @param null|string $pageName |
|
186 | - * |
|
187 | - * @return bool |
|
188 | - * @category Security-Critical |
|
189 | - */ |
|
190 | - final public function barrierTest($action, User $user, $pageName = null) |
|
191 | - { |
|
192 | - $page = get_called_class(); |
|
193 | - if ($pageName !== null) { |
|
194 | - $page = $pageName; |
|
195 | - } |
|
196 | - |
|
197 | - $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
198 | - |
|
199 | - return $securityResult === SecurityManager::ALLOWED; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Updates the lastactive timestamp |
|
204 | - */ |
|
205 | - private function touchUserLastActive() |
|
206 | - { |
|
207 | - if (WebRequest::getSessionUserId() !== null) { |
|
208 | - $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
209 | - $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return SecurityManager |
|
215 | - */ |
|
216 | - public function getSecurityManager() |
|
217 | - { |
|
218 | - return $this->securityManager; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @param SecurityManager $securityManager |
|
223 | - */ |
|
224 | - public function setSecurityManager(SecurityManager $securityManager) |
|
225 | - { |
|
226 | - $this->securityManager = $securityManager; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @return IBlacklistHelper |
|
231 | - */ |
|
232 | - public function getBlacklistHelper() |
|
233 | - { |
|
234 | - return $this->blacklistHelper; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param IBlacklistHelper $blacklistHelper |
|
239 | - */ |
|
240 | - public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
241 | - { |
|
242 | - $this->blacklistHelper = $blacklistHelper; |
|
243 | - } |
|
25 | + use NavigationMenuAccessControl; |
|
26 | + |
|
27 | + /** @var IdentificationVerifier */ |
|
28 | + private $identificationVerifier; |
|
29 | + /** @var ITypeAheadHelper */ |
|
30 | + private $typeAheadHelper; |
|
31 | + /** @var SecurityManager */ |
|
32 | + private $securityManager; |
|
33 | + /** @var IBlacklistHelper */ |
|
34 | + private $blacklistHelper; |
|
35 | + |
|
36 | + /** |
|
37 | + * @return ITypeAheadHelper |
|
38 | + */ |
|
39 | + public function getTypeAheadHelper() |
|
40 | + { |
|
41 | + return $this->typeAheadHelper; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Sets up the internal IdentificationVerifier instance. Intended to be called from WebStart::setupHelpers(). |
|
46 | + * |
|
47 | + * @param IdentificationVerifier $identificationVerifier |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier) |
|
52 | + { |
|
53 | + $this->identificationVerifier = $identificationVerifier; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param ITypeAheadHelper $typeAheadHelper |
|
58 | + */ |
|
59 | + public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
60 | + { |
|
61 | + $this->typeAheadHelper = $typeAheadHelper; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Runs the page code |
|
66 | + * |
|
67 | + * @throws Exception |
|
68 | + * @category Security-Critical |
|
69 | + */ |
|
70 | + final public function execute() |
|
71 | + { |
|
72 | + if ($this->getRouteName() === null) { |
|
73 | + throw new Exception("Request is unrouted."); |
|
74 | + } |
|
75 | + |
|
76 | + if ($this->getSiteConfiguration() === null) { |
|
77 | + throw new Exception("Page has no configuration!"); |
|
78 | + } |
|
79 | + |
|
80 | + $this->setupPage(); |
|
81 | + |
|
82 | + $this->touchUserLastActive(); |
|
83 | + |
|
84 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
85 | + |
|
86 | + // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
87 | + if (!$this->isProtectedPage()) { |
|
88 | + // This page is /not/ a protected page, as such we can just run it. |
|
89 | + $this->runPage(); |
|
90 | + |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + // Security barrier. |
|
95 | + // |
|
96 | + // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
97 | + // away for us |
|
98 | + $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
99 | + if ($securityResult === SecurityManager::ALLOWED) { |
|
100 | + // We're allowed to run the page, so let's run it. |
|
101 | + $this->runPage(); |
|
102 | + } |
|
103 | + else { |
|
104 | + $this->handleAccessDenied($securityResult); |
|
105 | + |
|
106 | + // Send the headers |
|
107 | + $this->sendResponseHeaders(); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Performs final tasks needed before rendering the page. |
|
113 | + */ |
|
114 | + final public function finalisePage() |
|
115 | + { |
|
116 | + parent::finalisePage(); |
|
117 | + |
|
118 | + $database = $this->getDatabase(); |
|
119 | + |
|
120 | + $currentUser = User::getCurrent($database); |
|
121 | + if (!$currentUser->isCommunityUser()) { |
|
122 | + $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
123 | + $statement = $database->query($sql); |
|
124 | + $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
125 | + $this->assign('onlineusers', $activeUsers); |
|
126 | + } |
|
127 | + |
|
128 | + $this->setupNavMenuAccess($currentUser); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Configures whether the page respects roles or not. You probably want this to return true. |
|
133 | + * |
|
134 | + * Set to false for public pages. You probably want this to return true. |
|
135 | + * |
|
136 | + * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
137 | + * on this page, so you probably want this to return true. |
|
138 | + * |
|
139 | + * @return bool |
|
140 | + * @category Security-Critical |
|
141 | + */ |
|
142 | + protected function isProtectedPage() |
|
143 | + { |
|
144 | + return true; |
|
145 | + } |
|
146 | + |
|
147 | + protected function handleAccessDenied($denyReason) |
|
148 | + { |
|
149 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
150 | + |
|
151 | + // Not allowed to access this resource. |
|
152 | + // Firstly, let's check if we're even logged in. |
|
153 | + if ($currentUser->isCommunityUser()) { |
|
154 | + // Not logged in, redirect to login page |
|
155 | + WebRequest::setPostLoginRedirect(); |
|
156 | + $this->redirect("login"); |
|
157 | + |
|
158 | + return; |
|
159 | + } |
|
160 | + else { |
|
161 | + // Decide whether this was a rights failure, or an identification failure. |
|
162 | + |
|
163 | + if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
|
164 | + // Not identified |
|
165 | + throw new NotIdentifiedException($this->getSecurityManager()); |
|
166 | + } |
|
167 | + elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
168 | + // Nope, plain old access denied |
|
169 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
170 | + } |
|
171 | + else { |
|
172 | + throw new Exception('Unknown response from security manager.'); |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Tests the security barrier for a specified action. |
|
179 | + * |
|
180 | + * Don't use within templates |
|
181 | + * |
|
182 | + * @param string $action |
|
183 | + * |
|
184 | + * @param User $user |
|
185 | + * @param null|string $pageName |
|
186 | + * |
|
187 | + * @return bool |
|
188 | + * @category Security-Critical |
|
189 | + */ |
|
190 | + final public function barrierTest($action, User $user, $pageName = null) |
|
191 | + { |
|
192 | + $page = get_called_class(); |
|
193 | + if ($pageName !== null) { |
|
194 | + $page = $pageName; |
|
195 | + } |
|
196 | + |
|
197 | + $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
198 | + |
|
199 | + return $securityResult === SecurityManager::ALLOWED; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Updates the lastactive timestamp |
|
204 | + */ |
|
205 | + private function touchUserLastActive() |
|
206 | + { |
|
207 | + if (WebRequest::getSessionUserId() !== null) { |
|
208 | + $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
209 | + $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return SecurityManager |
|
215 | + */ |
|
216 | + public function getSecurityManager() |
|
217 | + { |
|
218 | + return $this->securityManager; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @param SecurityManager $securityManager |
|
223 | + */ |
|
224 | + public function setSecurityManager(SecurityManager $securityManager) |
|
225 | + { |
|
226 | + $this->securityManager = $securityManager; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @return IBlacklistHelper |
|
231 | + */ |
|
232 | + public function getBlacklistHelper() |
|
233 | + { |
|
234 | + return $this->blacklistHelper; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param IBlacklistHelper $blacklistHelper |
|
239 | + */ |
|
240 | + public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
241 | + { |
|
242 | + $this->blacklistHelper = $blacklistHelper; |
|
243 | + } |
|
244 | 244 | } |
@@ -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 | } |