@@ -16,16 +16,16 @@ |
||
16 | 16 | */ |
17 | 17 | function smarty_modifier_date($input) |
18 | 18 | { |
19 | - if (gettype($input) === 'object' |
|
20 | - && (get_class($input) === DateTime::class || get_class($input) === DateTimeImmutable::class) |
|
21 | - ) { |
|
22 | - /** @var $date DateTime|DateTimeImmutable */ |
|
23 | - $date = $input; |
|
24 | - $dateString = $date->format('Y-m-d H:i:s'); |
|
19 | + if (gettype($input) === 'object' |
|
20 | + && (get_class($input) === DateTime::class || get_class($input) === DateTimeImmutable::class) |
|
21 | + ) { |
|
22 | + /** @var $date DateTime|DateTimeImmutable */ |
|
23 | + $date = $input; |
|
24 | + $dateString = $date->format('Y-m-d H:i:s'); |
|
25 | 25 | |
26 | - return $dateString; |
|
27 | - } |
|
28 | - else { |
|
29 | - return $input; |
|
30 | - } |
|
26 | + return $dateString; |
|
27 | + } |
|
28 | + else { |
|
29 | + return $input; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -17,87 +17,87 @@ |
||
17 | 17 | |
18 | 18 | class PageExpandedRequestList extends InternalPageBase |
19 | 19 | { |
20 | - /** |
|
21 | - * Sets up the security for this page. If certain actions have different permissions, this should be reflected in |
|
22 | - * the return value from this function. |
|
23 | - * |
|
24 | - * If this page even supports actions, you will need to check the route |
|
25 | - * |
|
26 | - * @return SecurityConfiguration |
|
27 | - * @category Security-Critical |
|
28 | - */ |
|
29 | - protected function getSecurityConfiguration() |
|
30 | - { |
|
31 | - return $this->getSecurityManager()->configure()->asInternalPage(); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Main function for this page, when no specific actions are called. |
|
36 | - * @return void |
|
37 | - * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
38 | - */ |
|
39 | - protected function main() |
|
40 | - { |
|
41 | - $config = $this->getSiteConfiguration(); |
|
42 | - |
|
43 | - $requestedStatus = WebRequest::getString('status'); |
|
44 | - $requestStates = $config->getRequestStates(); |
|
45 | - |
|
46 | - if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
47 | - |
|
48 | - $this->assignCSRFToken(); |
|
49 | - |
|
50 | - $database = $this->getDatabase(); |
|
51 | - |
|
52 | - if ($config->getEmailConfirmationEnabled()) { |
|
53 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
54 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
55 | - } |
|
56 | - else { |
|
57 | - $query = "SELECT * FROM request WHERE status = :type;"; |
|
58 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
59 | - } |
|
60 | - |
|
61 | - $statement = $database->prepare($query); |
|
62 | - |
|
63 | - $totalRequestsStatement = $database->prepare($totalQuery); |
|
64 | - |
|
65 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
66 | - |
|
67 | - $type = $requestedStatus; |
|
68 | - |
|
69 | - $statement->bindValue(":type", $type); |
|
70 | - $statement->execute(); |
|
71 | - |
|
72 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
73 | - |
|
74 | - /** @var Request $req */ |
|
75 | - foreach ($requests as $req) { |
|
76 | - $req->setDatabase($database); |
|
77 | - } |
|
78 | - |
|
79 | - $this->assign('requests', $requests); |
|
80 | - $this->assign('header', $type); |
|
81 | - |
|
82 | - $totalRequestsStatement->bindValue(':type', $type); |
|
83 | - $totalRequestsStatement->execute(); |
|
84 | - $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
85 | - $totalRequestsStatement->closeCursor(); |
|
86 | - $this->assign('totalRequests', $totalRequests); |
|
87 | - |
|
88 | - $userIds = array_map( |
|
89 | - function(Request $entry) { |
|
90 | - return $entry->getReserved(); |
|
91 | - }, |
|
92 | - $requests |
|
93 | - ); |
|
94 | - |
|
95 | - $userList = User::getUsernames($userIds, $this->getDatabase()); |
|
96 | - $this->assign('userlist', $userList); |
|
97 | - |
|
98 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
99 | - |
|
100 | - $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
101 | - } |
|
102 | - } |
|
20 | + /** |
|
21 | + * Sets up the security for this page. If certain actions have different permissions, this should be reflected in |
|
22 | + * the return value from this function. |
|
23 | + * |
|
24 | + * If this page even supports actions, you will need to check the route |
|
25 | + * |
|
26 | + * @return SecurityConfiguration |
|
27 | + * @category Security-Critical |
|
28 | + */ |
|
29 | + protected function getSecurityConfiguration() |
|
30 | + { |
|
31 | + return $this->getSecurityManager()->configure()->asInternalPage(); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Main function for this page, when no specific actions are called. |
|
36 | + * @return void |
|
37 | + * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
38 | + */ |
|
39 | + protected function main() |
|
40 | + { |
|
41 | + $config = $this->getSiteConfiguration(); |
|
42 | + |
|
43 | + $requestedStatus = WebRequest::getString('status'); |
|
44 | + $requestStates = $config->getRequestStates(); |
|
45 | + |
|
46 | + if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
47 | + |
|
48 | + $this->assignCSRFToken(); |
|
49 | + |
|
50 | + $database = $this->getDatabase(); |
|
51 | + |
|
52 | + if ($config->getEmailConfirmationEnabled()) { |
|
53 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
54 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
55 | + } |
|
56 | + else { |
|
57 | + $query = "SELECT * FROM request WHERE status = :type;"; |
|
58 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
59 | + } |
|
60 | + |
|
61 | + $statement = $database->prepare($query); |
|
62 | + |
|
63 | + $totalRequestsStatement = $database->prepare($totalQuery); |
|
64 | + |
|
65 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
66 | + |
|
67 | + $type = $requestedStatus; |
|
68 | + |
|
69 | + $statement->bindValue(":type", $type); |
|
70 | + $statement->execute(); |
|
71 | + |
|
72 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
73 | + |
|
74 | + /** @var Request $req */ |
|
75 | + foreach ($requests as $req) { |
|
76 | + $req->setDatabase($database); |
|
77 | + } |
|
78 | + |
|
79 | + $this->assign('requests', $requests); |
|
80 | + $this->assign('header', $type); |
|
81 | + |
|
82 | + $totalRequestsStatement->bindValue(':type', $type); |
|
83 | + $totalRequestsStatement->execute(); |
|
84 | + $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
85 | + $totalRequestsStatement->closeCursor(); |
|
86 | + $this->assign('totalRequests', $totalRequests); |
|
87 | + |
|
88 | + $userIds = array_map( |
|
89 | + function(Request $entry) { |
|
90 | + return $entry->getReserved(); |
|
91 | + }, |
|
92 | + $requests |
|
93 | + ); |
|
94 | + |
|
95 | + $userList = User::getUsernames($userIds, $this->getDatabase()); |
|
96 | + $this->assign('userlist', $userList); |
|
97 | + |
|
98 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
99 | + |
|
100 | + $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | } |
@@ -13,87 +13,87 @@ |
||
13 | 13 | |
14 | 14 | class LogSearchHelper extends SearchHelperBase |
15 | 15 | { |
16 | - /** |
|
17 | - * LogSearchHelper constructor. |
|
18 | - * |
|
19 | - * @param PdoDatabase $database |
|
20 | - */ |
|
21 | - protected function __construct(PdoDatabase $database) |
|
22 | - { |
|
23 | - parent::__construct($database, 'log', Log::class, 'timestamp DESC'); |
|
24 | - } |
|
16 | + /** |
|
17 | + * LogSearchHelper constructor. |
|
18 | + * |
|
19 | + * @param PdoDatabase $database |
|
20 | + */ |
|
21 | + protected function __construct(PdoDatabase $database) |
|
22 | + { |
|
23 | + parent::__construct($database, 'log', Log::class, 'timestamp DESC'); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Initiates a search for requests |
|
28 | - * |
|
29 | - * @param PdoDatabase $database |
|
30 | - * |
|
31 | - * @return LogSearchHelper |
|
32 | - */ |
|
33 | - public static function get(PdoDatabase $database) |
|
34 | - { |
|
35 | - $helper = new LogSearchHelper($database); |
|
26 | + /** |
|
27 | + * Initiates a search for requests |
|
28 | + * |
|
29 | + * @param PdoDatabase $database |
|
30 | + * |
|
31 | + * @return LogSearchHelper |
|
32 | + */ |
|
33 | + public static function get(PdoDatabase $database) |
|
34 | + { |
|
35 | + $helper = new LogSearchHelper($database); |
|
36 | 36 | |
37 | - return $helper; |
|
38 | - } |
|
37 | + return $helper; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Filters the results by user |
|
42 | - * |
|
43 | - * @param int $userId |
|
44 | - * |
|
45 | - * @return $this |
|
46 | - */ |
|
47 | - public function byUser($userId) |
|
48 | - { |
|
49 | - $this->whereClause .= ' AND user = ?'; |
|
50 | - $this->parameterList[] = $userId; |
|
40 | + /** |
|
41 | + * Filters the results by user |
|
42 | + * |
|
43 | + * @param int $userId |
|
44 | + * |
|
45 | + * @return $this |
|
46 | + */ |
|
47 | + public function byUser($userId) |
|
48 | + { |
|
49 | + $this->whereClause .= ' AND user = ?'; |
|
50 | + $this->parameterList[] = $userId; |
|
51 | 51 | |
52 | - return $this; |
|
53 | - } |
|
52 | + return $this; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Filters the results by log action |
|
57 | - * |
|
58 | - * @param string $action |
|
59 | - * |
|
60 | - * @return $this |
|
61 | - */ |
|
62 | - public function byAction($action) |
|
63 | - { |
|
64 | - $this->whereClause .= ' AND action = ?'; |
|
65 | - $this->parameterList[] = $action; |
|
55 | + /** |
|
56 | + * Filters the results by log action |
|
57 | + * |
|
58 | + * @param string $action |
|
59 | + * |
|
60 | + * @return $this |
|
61 | + */ |
|
62 | + public function byAction($action) |
|
63 | + { |
|
64 | + $this->whereClause .= ' AND action = ?'; |
|
65 | + $this->parameterList[] = $action; |
|
66 | 66 | |
67 | - return $this; |
|
68 | - } |
|
67 | + return $this; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Filters the results by object type |
|
72 | - * |
|
73 | - * @param string $objectType |
|
74 | - * |
|
75 | - * @return $this |
|
76 | - */ |
|
77 | - public function byObjectType($objectType) |
|
78 | - { |
|
79 | - $this->whereClause .= ' AND objecttype = ?'; |
|
80 | - $this->parameterList[] = $objectType; |
|
70 | + /** |
|
71 | + * Filters the results by object type |
|
72 | + * |
|
73 | + * @param string $objectType |
|
74 | + * |
|
75 | + * @return $this |
|
76 | + */ |
|
77 | + public function byObjectType($objectType) |
|
78 | + { |
|
79 | + $this->whereClause .= ' AND objecttype = ?'; |
|
80 | + $this->parameterList[] = $objectType; |
|
81 | 81 | |
82 | - return $this; |
|
83 | - } |
|
82 | + return $this; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Filters the results by object type |
|
87 | - * |
|
88 | - * @param integer $objectId |
|
89 | - * |
|
90 | - * @return $this |
|
91 | - */ |
|
92 | - public function byObjectId($objectId) |
|
93 | - { |
|
94 | - $this->whereClause .= ' AND objectid = ?'; |
|
95 | - $this->parameterList[] = $objectId; |
|
85 | + /** |
|
86 | + * Filters the results by object type |
|
87 | + * |
|
88 | + * @param integer $objectId |
|
89 | + * |
|
90 | + * @return $this |
|
91 | + */ |
|
92 | + public function byObjectId($objectId) |
|
93 | + { |
|
94 | + $this->whereClause .= ' AND objectid = ?'; |
|
95 | + $this->parameterList[] = $objectId; |
|
96 | 96 | |
97 | - return $this; |
|
98 | - } |
|
97 | + return $this; |
|
98 | + } |
|
99 | 99 | } |
100 | 100 | \ No newline at end of file |
@@ -15,182 +15,182 @@ |
||
15 | 15 | |
16 | 16 | abstract class SearchHelperBase |
17 | 17 | { |
18 | - /** @var PdoDatabase */ |
|
19 | - protected $database; |
|
20 | - /** @var array */ |
|
21 | - protected $parameterList = array(); |
|
22 | - /** @var null|int */ |
|
23 | - private $limit = null; |
|
24 | - /** @var null|int */ |
|
25 | - private $offset = null; |
|
26 | - private $orderBy = null; |
|
27 | - /** |
|
28 | - * @var string The where clause. |
|
29 | - * |
|
30 | - * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note |
|
31 | - * that we use positional parameters instead of named parameters because we don't know many times different options |
|
32 | - * will be called (looking at excluding() here, but there's the option for others). |
|
33 | - */ |
|
34 | - protected $whereClause = ' WHERE 1 = 1'; |
|
35 | - /** @var string */ |
|
36 | - protected $table; |
|
37 | - protected $joinClause = ''; |
|
38 | - private $targetClass; |
|
39 | - |
|
40 | - /** |
|
41 | - * SearchHelperBase constructor. |
|
42 | - * |
|
43 | - * @param PdoDatabase $database |
|
44 | - * @param string $table |
|
45 | - * @param $targetClass |
|
46 | - * @param null|string $order Order by clause, excluding ORDER BY. |
|
47 | - */ |
|
48 | - protected function __construct(PdoDatabase $database, $table, $targetClass, $order = null) |
|
49 | - { |
|
50 | - $this->database = $database; |
|
51 | - $this->table = $table; |
|
52 | - $this->orderBy = $order; |
|
53 | - $this->targetClass = $targetClass; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Finalises the database query, and executes it, returning a set of objects. |
|
58 | - * |
|
59 | - * @return DataObject[] |
|
60 | - */ |
|
61 | - public function fetch() |
|
62 | - { |
|
63 | - $statement = $this->getData(); |
|
64 | - |
|
65 | - /** @var DataObject[] $returnedObjects */ |
|
66 | - $returnedObjects = $statement->fetchAll(PDO::FETCH_CLASS, $this->targetClass); |
|
67 | - foreach ($returnedObjects as $req) { |
|
68 | - $req->setDatabase($this->database); |
|
69 | - } |
|
70 | - |
|
71 | - return $returnedObjects; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Finalises the database query, and executes it, returning only the requested column. |
|
76 | - * |
|
77 | - * @param string $column The required column |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public function fetchColumn($column){ |
|
81 | - $statement = $this->getData($column); |
|
82 | - |
|
83 | - return $statement->fetchAll(PDO::FETCH_COLUMN); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param int $count Returns the record count of the result set |
|
88 | - * |
|
89 | - * @return $this |
|
90 | - */ |
|
91 | - public function getRecordCount(&$count) |
|
92 | - { |
|
93 | - $query = 'SELECT /* SearchHelper */ COUNT(*) FROM ' . $this->table . ' origin '; |
|
94 | - $query .= $this->joinClause . $this->whereClause; |
|
95 | - |
|
96 | - $statement = $this->database->prepare($query); |
|
97 | - $statement->execute($this->parameterList); |
|
98 | - |
|
99 | - $count = $statement->fetchColumn(0); |
|
100 | - $statement->closeCursor(); |
|
101 | - |
|
102 | - return $this; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Limits the results |
|
107 | - * |
|
108 | - * @param integer $limit |
|
109 | - * @param integer|null $offset |
|
110 | - * |
|
111 | - * @return $this |
|
112 | - * |
|
113 | - */ |
|
114 | - public function limit($limit, $offset = null) |
|
115 | - { |
|
116 | - $this->limit = $limit; |
|
117 | - $this->offset = $offset; |
|
118 | - |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - private function applyLimit() |
|
123 | - { |
|
124 | - $clause = ''; |
|
125 | - if ($this->limit !== null) { |
|
126 | - $clause = ' LIMIT ?'; |
|
127 | - $this->parameterList[] = $this->limit; |
|
128 | - |
|
129 | - if ($this->offset !== null) { |
|
130 | - $clause .= ' OFFSET ?'; |
|
131 | - $this->parameterList[] = $this->offset; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - return $clause; |
|
136 | - } |
|
137 | - |
|
138 | - private function applyOrder() |
|
139 | - { |
|
140 | - if ($this->orderBy !== null) { |
|
141 | - return ' ORDER BY ' . $this->orderBy; |
|
142 | - } |
|
143 | - |
|
144 | - return ''; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param $column |
|
149 | - * |
|
150 | - * @return PDOStatement |
|
151 | - */ |
|
152 | - private function getData($column = '*') |
|
153 | - { |
|
154 | - $query = $this->buildQuery($column); |
|
155 | - $query .= $this->applyOrder(); |
|
156 | - $query .= $this->applyLimit(); |
|
157 | - |
|
158 | - $statement = $this->database->prepare($query); |
|
159 | - $statement->execute($this->parameterList); |
|
160 | - |
|
161 | - return $statement; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param $column |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - protected function buildQuery($column) |
|
170 | - { |
|
171 | - $query = 'SELECT /* SearchHelper */ origin.' . $column . ' FROM ' . $this->table . ' origin '; |
|
172 | - $query .= $this->joinClause . $this->whereClause; |
|
173 | - |
|
174 | - return $query; |
|
175 | - } |
|
176 | - |
|
177 | - public function inIds($idList) { |
|
178 | - $this->inClause('id', $idList); |
|
179 | - return $this; |
|
180 | - } |
|
181 | - |
|
182 | - protected function inClause($column, $values) { |
|
183 | - if (count($values) === 0) { |
|
184 | - return; |
|
185 | - } |
|
186 | - |
|
187 | - // Urgh. OK. You can't use IN() with parameters directly, so let's munge something together. |
|
188 | - $valueCount = count($values); |
|
189 | - |
|
190 | - // Firstly, let's create a string of question marks, which will do as positional parameters. |
|
191 | - $inSection = str_repeat('?,', $valueCount - 1) . '?'; |
|
192 | - |
|
193 | - $this->whereClause .= " AND {$column} IN ({$inSection})"; |
|
194 | - $this->parameterList = array_merge($this->parameterList, $values); |
|
195 | - } |
|
18 | + /** @var PdoDatabase */ |
|
19 | + protected $database; |
|
20 | + /** @var array */ |
|
21 | + protected $parameterList = array(); |
|
22 | + /** @var null|int */ |
|
23 | + private $limit = null; |
|
24 | + /** @var null|int */ |
|
25 | + private $offset = null; |
|
26 | + private $orderBy = null; |
|
27 | + /** |
|
28 | + * @var string The where clause. |
|
29 | + * |
|
30 | + * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note |
|
31 | + * that we use positional parameters instead of named parameters because we don't know many times different options |
|
32 | + * will be called (looking at excluding() here, but there's the option for others). |
|
33 | + */ |
|
34 | + protected $whereClause = ' WHERE 1 = 1'; |
|
35 | + /** @var string */ |
|
36 | + protected $table; |
|
37 | + protected $joinClause = ''; |
|
38 | + private $targetClass; |
|
39 | + |
|
40 | + /** |
|
41 | + * SearchHelperBase constructor. |
|
42 | + * |
|
43 | + * @param PdoDatabase $database |
|
44 | + * @param string $table |
|
45 | + * @param $targetClass |
|
46 | + * @param null|string $order Order by clause, excluding ORDER BY. |
|
47 | + */ |
|
48 | + protected function __construct(PdoDatabase $database, $table, $targetClass, $order = null) |
|
49 | + { |
|
50 | + $this->database = $database; |
|
51 | + $this->table = $table; |
|
52 | + $this->orderBy = $order; |
|
53 | + $this->targetClass = $targetClass; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Finalises the database query, and executes it, returning a set of objects. |
|
58 | + * |
|
59 | + * @return DataObject[] |
|
60 | + */ |
|
61 | + public function fetch() |
|
62 | + { |
|
63 | + $statement = $this->getData(); |
|
64 | + |
|
65 | + /** @var DataObject[] $returnedObjects */ |
|
66 | + $returnedObjects = $statement->fetchAll(PDO::FETCH_CLASS, $this->targetClass); |
|
67 | + foreach ($returnedObjects as $req) { |
|
68 | + $req->setDatabase($this->database); |
|
69 | + } |
|
70 | + |
|
71 | + return $returnedObjects; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Finalises the database query, and executes it, returning only the requested column. |
|
76 | + * |
|
77 | + * @param string $column The required column |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public function fetchColumn($column){ |
|
81 | + $statement = $this->getData($column); |
|
82 | + |
|
83 | + return $statement->fetchAll(PDO::FETCH_COLUMN); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param int $count Returns the record count of the result set |
|
88 | + * |
|
89 | + * @return $this |
|
90 | + */ |
|
91 | + public function getRecordCount(&$count) |
|
92 | + { |
|
93 | + $query = 'SELECT /* SearchHelper */ COUNT(*) FROM ' . $this->table . ' origin '; |
|
94 | + $query .= $this->joinClause . $this->whereClause; |
|
95 | + |
|
96 | + $statement = $this->database->prepare($query); |
|
97 | + $statement->execute($this->parameterList); |
|
98 | + |
|
99 | + $count = $statement->fetchColumn(0); |
|
100 | + $statement->closeCursor(); |
|
101 | + |
|
102 | + return $this; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Limits the results |
|
107 | + * |
|
108 | + * @param integer $limit |
|
109 | + * @param integer|null $offset |
|
110 | + * |
|
111 | + * @return $this |
|
112 | + * |
|
113 | + */ |
|
114 | + public function limit($limit, $offset = null) |
|
115 | + { |
|
116 | + $this->limit = $limit; |
|
117 | + $this->offset = $offset; |
|
118 | + |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + private function applyLimit() |
|
123 | + { |
|
124 | + $clause = ''; |
|
125 | + if ($this->limit !== null) { |
|
126 | + $clause = ' LIMIT ?'; |
|
127 | + $this->parameterList[] = $this->limit; |
|
128 | + |
|
129 | + if ($this->offset !== null) { |
|
130 | + $clause .= ' OFFSET ?'; |
|
131 | + $this->parameterList[] = $this->offset; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + return $clause; |
|
136 | + } |
|
137 | + |
|
138 | + private function applyOrder() |
|
139 | + { |
|
140 | + if ($this->orderBy !== null) { |
|
141 | + return ' ORDER BY ' . $this->orderBy; |
|
142 | + } |
|
143 | + |
|
144 | + return ''; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param $column |
|
149 | + * |
|
150 | + * @return PDOStatement |
|
151 | + */ |
|
152 | + private function getData($column = '*') |
|
153 | + { |
|
154 | + $query = $this->buildQuery($column); |
|
155 | + $query .= $this->applyOrder(); |
|
156 | + $query .= $this->applyLimit(); |
|
157 | + |
|
158 | + $statement = $this->database->prepare($query); |
|
159 | + $statement->execute($this->parameterList); |
|
160 | + |
|
161 | + return $statement; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param $column |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + protected function buildQuery($column) |
|
170 | + { |
|
171 | + $query = 'SELECT /* SearchHelper */ origin.' . $column . ' FROM ' . $this->table . ' origin '; |
|
172 | + $query .= $this->joinClause . $this->whereClause; |
|
173 | + |
|
174 | + return $query; |
|
175 | + } |
|
176 | + |
|
177 | + public function inIds($idList) { |
|
178 | + $this->inClause('id', $idList); |
|
179 | + return $this; |
|
180 | + } |
|
181 | + |
|
182 | + protected function inClause($column, $values) { |
|
183 | + if (count($values) === 0) { |
|
184 | + return; |
|
185 | + } |
|
186 | + |
|
187 | + // Urgh. OK. You can't use IN() with parameters directly, so let's munge something together. |
|
188 | + $valueCount = count($values); |
|
189 | + |
|
190 | + // Firstly, let's create a string of question marks, which will do as positional parameters. |
|
191 | + $inSection = str_repeat('?,', $valueCount - 1) . '?'; |
|
192 | + |
|
193 | + $this->whereClause .= " AND {$column} IN ({$inSection})"; |
|
194 | + $this->parameterList = array_merge($this->parameterList, $values); |
|
195 | + } |
|
196 | 196 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param string $column The required column |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - public function fetchColumn($column){ |
|
80 | + public function fetchColumn($column) { |
|
81 | 81 | $statement = $this->getData($column); |
82 | 82 | |
83 | 83 | return $statement->fetchAll(PDO::FETCH_COLUMN); |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function getRecordCount(&$count) |
92 | 92 | { |
93 | - $query = 'SELECT /* SearchHelper */ COUNT(*) FROM ' . $this->table . ' origin '; |
|
94 | - $query .= $this->joinClause . $this->whereClause; |
|
93 | + $query = 'SELECT /* SearchHelper */ COUNT(*) FROM '.$this->table.' origin '; |
|
94 | + $query .= $this->joinClause.$this->whereClause; |
|
95 | 95 | |
96 | 96 | $statement = $this->database->prepare($query); |
97 | 97 | $statement->execute($this->parameterList); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | private function applyOrder() |
139 | 139 | { |
140 | 140 | if ($this->orderBy !== null) { |
141 | - return ' ORDER BY ' . $this->orderBy; |
|
141 | + return ' ORDER BY '.$this->orderBy; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return ''; |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function buildQuery($column) |
170 | 170 | { |
171 | - $query = 'SELECT /* SearchHelper */ origin.' . $column . ' FROM ' . $this->table . ' origin '; |
|
172 | - $query .= $this->joinClause . $this->whereClause; |
|
171 | + $query = 'SELECT /* SearchHelper */ origin.'.$column.' FROM '.$this->table.' origin '; |
|
172 | + $query .= $this->joinClause.$this->whereClause; |
|
173 | 173 | |
174 | 174 | return $query; |
175 | 175 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $valueCount = count($values); |
189 | 189 | |
190 | 190 | // Firstly, let's create a string of question marks, which will do as positional parameters. |
191 | - $inSection = str_repeat('?,', $valueCount - 1) . '?'; |
|
191 | + $inSection = str_repeat('?,', $valueCount - 1).'?'; |
|
192 | 192 | |
193 | 193 | $this->whereClause .= " AND {$column} IN ({$inSection})"; |
194 | 194 | $this->parameterList = array_merge($this->parameterList, $values); |
@@ -77,7 +77,8 @@ discard block |
||
77 | 77 | * @param string $column The required column |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - public function fetchColumn($column){ |
|
80 | + public function fetchColumn($column) |
|
81 | + { |
|
81 | 82 | $statement = $this->getData($column); |
82 | 83 | |
83 | 84 | return $statement->fetchAll(PDO::FETCH_COLUMN); |
@@ -174,12 +175,14 @@ discard block |
||
174 | 175 | return $query; |
175 | 176 | } |
176 | 177 | |
177 | - public function inIds($idList) { |
|
178 | + public function inIds($idList) |
|
179 | + { |
|
178 | 180 | $this->inClause('id', $idList); |
179 | 181 | return $this; |
180 | 182 | } |
181 | 183 | |
182 | - protected function inClause($column, $values) { |
|
184 | + protected function inClause($column, $values) |
|
185 | + { |
|
183 | 186 | if (count($values) === 0) { |
184 | 187 | return; |
185 | 188 | } |
@@ -20,341 +20,341 @@ |
||
20 | 20 | |
21 | 21 | abstract class PageBase extends TaskBase implements IRoutedTask |
22 | 22 | { |
23 | - use TemplateOutput; |
|
24 | - /** @var string Smarty template to display */ |
|
25 | - protected $template = "base.tpl"; |
|
26 | - /** @var string HTML title. Currently unused. */ |
|
27 | - protected $htmlTitle; |
|
28 | - /** @var bool Determines if the page is a redirect or not */ |
|
29 | - protected $isRedirecting = false; |
|
30 | - /** @var array Queue of headers to be sent on successful completion */ |
|
31 | - protected $headerQueue = array(); |
|
32 | - /** @var string The name of the route to use, as determined by the request router. */ |
|
33 | - private $routeName = null; |
|
34 | - /** @var TokenManager */ |
|
35 | - protected $tokenManager; |
|
36 | - /** @var string[] Extra CSS files to include */ |
|
37 | - private $extraCss = array(); |
|
38 | - /** @var string[] Extra JS files to include */ |
|
39 | - private $extraJs = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
43 | - * |
|
44 | - * @param string $routeName The name of the route |
|
45 | - * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
46 | - * |
|
47 | - * @throws Exception |
|
48 | - * @category Security-Critical |
|
49 | - */ |
|
50 | - final public function setRoute($routeName, $skipCallableTest = false) |
|
51 | - { |
|
52 | - // Test the new route is callable before adopting it. |
|
53 | - if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
54 | - throw new Exception("Proposed route '$routeName' is not callable."); |
|
55 | - } |
|
56 | - |
|
57 | - // Adopt the new route |
|
58 | - $this->routeName = $routeName; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Gets the name of the route that has been passed from the request router. |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - final public function getRouteName() |
|
66 | - { |
|
67 | - return $this->routeName; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Performs generic page setup actions |
|
72 | - */ |
|
73 | - final protected function setupPage() |
|
74 | - { |
|
75 | - $this->setUpSmarty(); |
|
76 | - |
|
77 | - $siteNoticeText = SiteNotice::get($this->getDatabase()); |
|
78 | - |
|
79 | - $this->assign('siteNoticeText', $siteNoticeText); |
|
80 | - |
|
81 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
82 | - $this->assign('currentUser', $currentUser); |
|
83 | - $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Runs the page logic as routed by the RequestRouter |
|
88 | - * |
|
89 | - * Only should be called after a security barrier! That means only from execute(). |
|
90 | - */ |
|
91 | - final protected function runPage() |
|
92 | - { |
|
93 | - $database = $this->getDatabase(); |
|
94 | - |
|
95 | - // initialise a database transaction |
|
96 | - if (!$database->beginTransaction()) { |
|
97 | - throw new Exception('Failed to start transaction on primary database.'); |
|
98 | - } |
|
99 | - |
|
100 | - try { |
|
101 | - // run the page code |
|
102 | - $this->{$this->getRouteName()}(); |
|
103 | - |
|
104 | - $database->commit(); |
|
105 | - } |
|
106 | - catch (ApplicationLogicException $ex) { |
|
107 | - // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
108 | - // standard templating system for this. |
|
109 | - |
|
110 | - // Firstly, let's undo anything that happened to the database. |
|
111 | - $database->rollBack(); |
|
112 | - |
|
113 | - // Reset smarty |
|
114 | - $this->setUpSmarty(); |
|
115 | - |
|
116 | - // Set the template |
|
117 | - $this->setTemplate('exception/application-logic.tpl'); |
|
118 | - $this->assign('message', $ex->getMessage()); |
|
119 | - |
|
120 | - // Force this back to false |
|
121 | - $this->isRedirecting = false; |
|
122 | - $this->headerQueue = array(); |
|
123 | - } |
|
124 | - catch (OptimisticLockFailedException $ex) { |
|
125 | - // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
126 | - // standard templating system for this. |
|
127 | - |
|
128 | - // Firstly, let's undo anything that happened to the database. |
|
129 | - $database->rollBack(); |
|
130 | - |
|
131 | - // Reset smarty |
|
132 | - $this->setUpSmarty(); |
|
133 | - |
|
134 | - // Set the template |
|
135 | - $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
136 | - $this->assign('message', $ex->getMessage()); |
|
137 | - |
|
138 | - // Force this back to false |
|
139 | - $this->isRedirecting = false; |
|
140 | - $this->headerQueue = array(); |
|
141 | - } |
|
142 | - finally { |
|
143 | - // Catch any hanging on transactions |
|
144 | - if ($database->hasActiveTransaction()) { |
|
145 | - $database->rollBack(); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - // run any finalisation code needed before we send the output to the browser. |
|
150 | - $this->finalisePage(); |
|
151 | - |
|
152 | - // Send the headers |
|
153 | - $this->sendResponseHeaders(); |
|
154 | - |
|
155 | - // Check we have a template to use! |
|
156 | - if ($this->template !== null) { |
|
157 | - $content = $this->fetchTemplate($this->template); |
|
158 | - ob_clean(); |
|
159 | - print($content); |
|
160 | - ob_flush(); |
|
161 | - |
|
162 | - return; |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Performs final tasks needed before rendering the page. |
|
168 | - */ |
|
169 | - protected function finalisePage() |
|
170 | - { |
|
171 | - if ($this->isRedirecting) { |
|
172 | - $this->template = null; |
|
173 | - |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - $this->assign('extraCss', $this->extraCss); |
|
178 | - $this->assign('extraJs', $this->extraJs); |
|
179 | - |
|
180 | - // If we're actually displaying content, we want to add the session alerts here! |
|
181 | - $this->assign('alerts', SessionAlert::getAlerts()); |
|
182 | - SessionAlert::clearAlerts(); |
|
183 | - |
|
184 | - $this->assign('htmlTitle', $this->htmlTitle); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @return TokenManager |
|
189 | - */ |
|
190 | - public function getTokenManager() |
|
191 | - { |
|
192 | - return $this->tokenManager; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param TokenManager $tokenManager |
|
197 | - */ |
|
198 | - public function setTokenManager($tokenManager) |
|
199 | - { |
|
200 | - $this->tokenManager = $tokenManager; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Sends the redirect headers to perform a GET at the destination page. |
|
205 | - * |
|
206 | - * Also nullifies the set template so Smarty does not render it. |
|
207 | - * |
|
208 | - * @param string $page The page to redirect requests to (as used in the UR) |
|
209 | - * @param null|string $action The action to use on the page. |
|
210 | - * @param null|array $parameters |
|
211 | - * @param null|string $script The script (relative to index.php) to redirect to |
|
212 | - */ |
|
213 | - final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
214 | - { |
|
215 | - $currentScriptName = WebRequest::scriptName(); |
|
216 | - |
|
217 | - // Are we changing script? |
|
218 | - if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
219 | - $targetScriptName = $currentScriptName; |
|
220 | - } |
|
221 | - else { |
|
222 | - $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
223 | - } |
|
224 | - |
|
225 | - $pathInfo = array($targetScriptName); |
|
226 | - |
|
227 | - $pathInfo[1] = $page; |
|
228 | - |
|
229 | - if ($action !== null) { |
|
230 | - $pathInfo[2] = $action; |
|
231 | - } |
|
232 | - |
|
233 | - $url = implode('/', $pathInfo); |
|
234 | - |
|
235 | - if (is_array($parameters) && count($parameters) > 0) { |
|
236 | - $url .= '?' . http_build_query($parameters); |
|
237 | - } |
|
238 | - |
|
239 | - $this->redirectUrl($url); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Sends the redirect headers to perform a GET at the new address. |
|
244 | - * |
|
245 | - * Also nullifies the set template so Smarty does not render it. |
|
246 | - * |
|
247 | - * @param string $path URL to redirect to |
|
248 | - */ |
|
249 | - final protected function redirectUrl($path) |
|
250 | - { |
|
251 | - // 303 See Other = re-request at new address with a GET. |
|
252 | - $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
253 | - $this->headerQueue[] = "Location: $path"; |
|
254 | - |
|
255 | - $this->setTemplate(null); |
|
256 | - $this->isRedirecting = true; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Sets the name of the template this page should display. |
|
261 | - * |
|
262 | - * @param string $name |
|
263 | - * |
|
264 | - * @throws Exception |
|
265 | - */ |
|
266 | - final protected function setTemplate($name) |
|
267 | - { |
|
268 | - if ($this->isRedirecting) { |
|
269 | - throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
270 | - } |
|
271 | - |
|
272 | - $this->template = $name; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Adds an extra CSS file to to the page |
|
277 | - * |
|
278 | - * @param string $path The path (relative to the application root) of the file |
|
279 | - */ |
|
280 | - final protected function addCss($path) { |
|
281 | - if(in_array($path, $this->extraCss)){ |
|
282 | - // nothing to do |
|
283 | - return; |
|
284 | - } |
|
285 | - |
|
286 | - $this->extraCss[] = $path; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Adds an extra JS file to to the page |
|
291 | - * |
|
292 | - * @param string $path The path (relative to the application root) of the file |
|
293 | - */ |
|
294 | - final protected function addJs($path){ |
|
295 | - if(in_array($path, $this->extraJs)){ |
|
296 | - // nothing to do |
|
297 | - return; |
|
298 | - } |
|
299 | - |
|
300 | - $this->extraJs[] = $path; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Main function for this page, when no specific actions are called. |
|
305 | - * @return void |
|
306 | - */ |
|
307 | - abstract protected function main(); |
|
308 | - |
|
309 | - /** |
|
310 | - * @param string $title |
|
311 | - */ |
|
312 | - final protected function setHtmlTitle($title) |
|
313 | - { |
|
314 | - $this->htmlTitle = $title; |
|
315 | - } |
|
316 | - |
|
317 | - public function execute() |
|
318 | - { |
|
319 | - if ($this->getRouteName() === null) { |
|
320 | - throw new Exception('Request is unrouted.'); |
|
321 | - } |
|
322 | - |
|
323 | - if ($this->getSiteConfiguration() === null) { |
|
324 | - throw new Exception('Page has no configuration!'); |
|
325 | - } |
|
326 | - |
|
327 | - $this->setupPage(); |
|
328 | - |
|
329 | - $this->runPage(); |
|
330 | - } |
|
331 | - |
|
332 | - public function assignCSRFToken() |
|
333 | - { |
|
334 | - $token = $this->tokenManager->getNewToken(); |
|
335 | - $this->assign('csrfTokenData', $token->getTokenData()); |
|
336 | - } |
|
337 | - |
|
338 | - public function validateCSRFToken() |
|
339 | - { |
|
340 | - if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
341 | - throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - protected function sendResponseHeaders() |
|
346 | - { |
|
347 | - if (headers_sent()) { |
|
348 | - throw new ApplicationLogicException ('Headers have already been sent! This is likely a bug in the application.'); |
|
349 | - } |
|
350 | - |
|
351 | - foreach ($this->headerQueue as $item) { |
|
352 | - if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
353 | - // Oops. We're not allowed to do this. |
|
354 | - throw new Exception('Unable to split header'); |
|
355 | - } |
|
356 | - |
|
357 | - header($item); |
|
358 | - } |
|
359 | - } |
|
23 | + use TemplateOutput; |
|
24 | + /** @var string Smarty template to display */ |
|
25 | + protected $template = "base.tpl"; |
|
26 | + /** @var string HTML title. Currently unused. */ |
|
27 | + protected $htmlTitle; |
|
28 | + /** @var bool Determines if the page is a redirect or not */ |
|
29 | + protected $isRedirecting = false; |
|
30 | + /** @var array Queue of headers to be sent on successful completion */ |
|
31 | + protected $headerQueue = array(); |
|
32 | + /** @var string The name of the route to use, as determined by the request router. */ |
|
33 | + private $routeName = null; |
|
34 | + /** @var TokenManager */ |
|
35 | + protected $tokenManager; |
|
36 | + /** @var string[] Extra CSS files to include */ |
|
37 | + private $extraCss = array(); |
|
38 | + /** @var string[] Extra JS files to include */ |
|
39 | + private $extraJs = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
43 | + * |
|
44 | + * @param string $routeName The name of the route |
|
45 | + * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
46 | + * |
|
47 | + * @throws Exception |
|
48 | + * @category Security-Critical |
|
49 | + */ |
|
50 | + final public function setRoute($routeName, $skipCallableTest = false) |
|
51 | + { |
|
52 | + // Test the new route is callable before adopting it. |
|
53 | + if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
54 | + throw new Exception("Proposed route '$routeName' is not callable."); |
|
55 | + } |
|
56 | + |
|
57 | + // Adopt the new route |
|
58 | + $this->routeName = $routeName; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Gets the name of the route that has been passed from the request router. |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + final public function getRouteName() |
|
66 | + { |
|
67 | + return $this->routeName; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Performs generic page setup actions |
|
72 | + */ |
|
73 | + final protected function setupPage() |
|
74 | + { |
|
75 | + $this->setUpSmarty(); |
|
76 | + |
|
77 | + $siteNoticeText = SiteNotice::get($this->getDatabase()); |
|
78 | + |
|
79 | + $this->assign('siteNoticeText', $siteNoticeText); |
|
80 | + |
|
81 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
82 | + $this->assign('currentUser', $currentUser); |
|
83 | + $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Runs the page logic as routed by the RequestRouter |
|
88 | + * |
|
89 | + * Only should be called after a security barrier! That means only from execute(). |
|
90 | + */ |
|
91 | + final protected function runPage() |
|
92 | + { |
|
93 | + $database = $this->getDatabase(); |
|
94 | + |
|
95 | + // initialise a database transaction |
|
96 | + if (!$database->beginTransaction()) { |
|
97 | + throw new Exception('Failed to start transaction on primary database.'); |
|
98 | + } |
|
99 | + |
|
100 | + try { |
|
101 | + // run the page code |
|
102 | + $this->{$this->getRouteName()}(); |
|
103 | + |
|
104 | + $database->commit(); |
|
105 | + } |
|
106 | + catch (ApplicationLogicException $ex) { |
|
107 | + // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
108 | + // standard templating system for this. |
|
109 | + |
|
110 | + // Firstly, let's undo anything that happened to the database. |
|
111 | + $database->rollBack(); |
|
112 | + |
|
113 | + // Reset smarty |
|
114 | + $this->setUpSmarty(); |
|
115 | + |
|
116 | + // Set the template |
|
117 | + $this->setTemplate('exception/application-logic.tpl'); |
|
118 | + $this->assign('message', $ex->getMessage()); |
|
119 | + |
|
120 | + // Force this back to false |
|
121 | + $this->isRedirecting = false; |
|
122 | + $this->headerQueue = array(); |
|
123 | + } |
|
124 | + catch (OptimisticLockFailedException $ex) { |
|
125 | + // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
126 | + // standard templating system for this. |
|
127 | + |
|
128 | + // Firstly, let's undo anything that happened to the database. |
|
129 | + $database->rollBack(); |
|
130 | + |
|
131 | + // Reset smarty |
|
132 | + $this->setUpSmarty(); |
|
133 | + |
|
134 | + // Set the template |
|
135 | + $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
136 | + $this->assign('message', $ex->getMessage()); |
|
137 | + |
|
138 | + // Force this back to false |
|
139 | + $this->isRedirecting = false; |
|
140 | + $this->headerQueue = array(); |
|
141 | + } |
|
142 | + finally { |
|
143 | + // Catch any hanging on transactions |
|
144 | + if ($database->hasActiveTransaction()) { |
|
145 | + $database->rollBack(); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + // run any finalisation code needed before we send the output to the browser. |
|
150 | + $this->finalisePage(); |
|
151 | + |
|
152 | + // Send the headers |
|
153 | + $this->sendResponseHeaders(); |
|
154 | + |
|
155 | + // Check we have a template to use! |
|
156 | + if ($this->template !== null) { |
|
157 | + $content = $this->fetchTemplate($this->template); |
|
158 | + ob_clean(); |
|
159 | + print($content); |
|
160 | + ob_flush(); |
|
161 | + |
|
162 | + return; |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Performs final tasks needed before rendering the page. |
|
168 | + */ |
|
169 | + protected function finalisePage() |
|
170 | + { |
|
171 | + if ($this->isRedirecting) { |
|
172 | + $this->template = null; |
|
173 | + |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + $this->assign('extraCss', $this->extraCss); |
|
178 | + $this->assign('extraJs', $this->extraJs); |
|
179 | + |
|
180 | + // If we're actually displaying content, we want to add the session alerts here! |
|
181 | + $this->assign('alerts', SessionAlert::getAlerts()); |
|
182 | + SessionAlert::clearAlerts(); |
|
183 | + |
|
184 | + $this->assign('htmlTitle', $this->htmlTitle); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @return TokenManager |
|
189 | + */ |
|
190 | + public function getTokenManager() |
|
191 | + { |
|
192 | + return $this->tokenManager; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param TokenManager $tokenManager |
|
197 | + */ |
|
198 | + public function setTokenManager($tokenManager) |
|
199 | + { |
|
200 | + $this->tokenManager = $tokenManager; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Sends the redirect headers to perform a GET at the destination page. |
|
205 | + * |
|
206 | + * Also nullifies the set template so Smarty does not render it. |
|
207 | + * |
|
208 | + * @param string $page The page to redirect requests to (as used in the UR) |
|
209 | + * @param null|string $action The action to use on the page. |
|
210 | + * @param null|array $parameters |
|
211 | + * @param null|string $script The script (relative to index.php) to redirect to |
|
212 | + */ |
|
213 | + final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
214 | + { |
|
215 | + $currentScriptName = WebRequest::scriptName(); |
|
216 | + |
|
217 | + // Are we changing script? |
|
218 | + if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
219 | + $targetScriptName = $currentScriptName; |
|
220 | + } |
|
221 | + else { |
|
222 | + $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
223 | + } |
|
224 | + |
|
225 | + $pathInfo = array($targetScriptName); |
|
226 | + |
|
227 | + $pathInfo[1] = $page; |
|
228 | + |
|
229 | + if ($action !== null) { |
|
230 | + $pathInfo[2] = $action; |
|
231 | + } |
|
232 | + |
|
233 | + $url = implode('/', $pathInfo); |
|
234 | + |
|
235 | + if (is_array($parameters) && count($parameters) > 0) { |
|
236 | + $url .= '?' . http_build_query($parameters); |
|
237 | + } |
|
238 | + |
|
239 | + $this->redirectUrl($url); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Sends the redirect headers to perform a GET at the new address. |
|
244 | + * |
|
245 | + * Also nullifies the set template so Smarty does not render it. |
|
246 | + * |
|
247 | + * @param string $path URL to redirect to |
|
248 | + */ |
|
249 | + final protected function redirectUrl($path) |
|
250 | + { |
|
251 | + // 303 See Other = re-request at new address with a GET. |
|
252 | + $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
253 | + $this->headerQueue[] = "Location: $path"; |
|
254 | + |
|
255 | + $this->setTemplate(null); |
|
256 | + $this->isRedirecting = true; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Sets the name of the template this page should display. |
|
261 | + * |
|
262 | + * @param string $name |
|
263 | + * |
|
264 | + * @throws Exception |
|
265 | + */ |
|
266 | + final protected function setTemplate($name) |
|
267 | + { |
|
268 | + if ($this->isRedirecting) { |
|
269 | + throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
270 | + } |
|
271 | + |
|
272 | + $this->template = $name; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Adds an extra CSS file to to the page |
|
277 | + * |
|
278 | + * @param string $path The path (relative to the application root) of the file |
|
279 | + */ |
|
280 | + final protected function addCss($path) { |
|
281 | + if(in_array($path, $this->extraCss)){ |
|
282 | + // nothing to do |
|
283 | + return; |
|
284 | + } |
|
285 | + |
|
286 | + $this->extraCss[] = $path; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Adds an extra JS file to to the page |
|
291 | + * |
|
292 | + * @param string $path The path (relative to the application root) of the file |
|
293 | + */ |
|
294 | + final protected function addJs($path){ |
|
295 | + if(in_array($path, $this->extraJs)){ |
|
296 | + // nothing to do |
|
297 | + return; |
|
298 | + } |
|
299 | + |
|
300 | + $this->extraJs[] = $path; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Main function for this page, when no specific actions are called. |
|
305 | + * @return void |
|
306 | + */ |
|
307 | + abstract protected function main(); |
|
308 | + |
|
309 | + /** |
|
310 | + * @param string $title |
|
311 | + */ |
|
312 | + final protected function setHtmlTitle($title) |
|
313 | + { |
|
314 | + $this->htmlTitle = $title; |
|
315 | + } |
|
316 | + |
|
317 | + public function execute() |
|
318 | + { |
|
319 | + if ($this->getRouteName() === null) { |
|
320 | + throw new Exception('Request is unrouted.'); |
|
321 | + } |
|
322 | + |
|
323 | + if ($this->getSiteConfiguration() === null) { |
|
324 | + throw new Exception('Page has no configuration!'); |
|
325 | + } |
|
326 | + |
|
327 | + $this->setupPage(); |
|
328 | + |
|
329 | + $this->runPage(); |
|
330 | + } |
|
331 | + |
|
332 | + public function assignCSRFToken() |
|
333 | + { |
|
334 | + $token = $this->tokenManager->getNewToken(); |
|
335 | + $this->assign('csrfTokenData', $token->getTokenData()); |
|
336 | + } |
|
337 | + |
|
338 | + public function validateCSRFToken() |
|
339 | + { |
|
340 | + if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
341 | + throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + protected function sendResponseHeaders() |
|
346 | + { |
|
347 | + if (headers_sent()) { |
|
348 | + throw new ApplicationLogicException ('Headers have already been sent! This is likely a bug in the application.'); |
|
349 | + } |
|
350 | + |
|
351 | + foreach ($this->headerQueue as $item) { |
|
352 | + if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
353 | + // Oops. We're not allowed to do this. |
|
354 | + throw new Exception('Unable to split header'); |
|
355 | + } |
|
356 | + |
|
357 | + header($item); |
|
358 | + } |
|
359 | + } |
|
360 | 360 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $targetScriptName = $currentScriptName; |
220 | 220 | } |
221 | 221 | else { |
222 | - $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
222 | + $targetScriptName = $this->getSiteConfiguration()->getBaseUrl().'/'.$script; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | $pathInfo = array($targetScriptName); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $url = implode('/', $pathInfo); |
234 | 234 | |
235 | 235 | if (is_array($parameters) && count($parameters) > 0) { |
236 | - $url .= '?' . http_build_query($parameters); |
|
236 | + $url .= '?'.http_build_query($parameters); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->redirectUrl($url); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param string $path The path (relative to the application root) of the file |
279 | 279 | */ |
280 | 280 | final protected function addCss($path) { |
281 | - if(in_array($path, $this->extraCss)){ |
|
281 | + if (in_array($path, $this->extraCss)) { |
|
282 | 282 | // nothing to do |
283 | 283 | return; |
284 | 284 | } |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @param string $path The path (relative to the application root) of the file |
293 | 293 | */ |
294 | - final protected function addJs($path){ |
|
295 | - if(in_array($path, $this->extraJs)){ |
|
294 | + final protected function addJs($path) { |
|
295 | + if (in_array($path, $this->extraJs)) { |
|
296 | 296 | // nothing to do |
297 | 297 | return; |
298 | 298 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | protected function sendResponseHeaders() |
346 | 346 | { |
347 | 347 | if (headers_sent()) { |
348 | - throw new ApplicationLogicException ('Headers have already been sent! This is likely a bug in the application.'); |
|
348 | + throw new ApplicationLogicException('Headers have already been sent! This is likely a bug in the application.'); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | foreach ($this->headerQueue as $item) { |
@@ -277,8 +277,9 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @param string $path The path (relative to the application root) of the file |
279 | 279 | */ |
280 | - final protected function addCss($path) { |
|
281 | - if(in_array($path, $this->extraCss)){ |
|
280 | + final protected function addCss($path) |
|
281 | + { |
|
282 | + if(in_array($path, $this->extraCss)) { |
|
282 | 283 | // nothing to do |
283 | 284 | return; |
284 | 285 | } |
@@ -291,8 +292,9 @@ discard block |
||
291 | 292 | * |
292 | 293 | * @param string $path The path (relative to the application root) of the file |
293 | 294 | */ |
294 | - final protected function addJs($path){ |
|
295 | - if(in_array($path, $this->extraJs)){ |
|
295 | + final protected function addJs($path) |
|
296 | + { |
|
297 | + if(in_array($path, $this->extraJs)) { |
|
296 | 298 | // nothing to do |
297 | 299 | return; |
298 | 300 | } |
@@ -26,131 +26,131 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class IdentificationVerifier |
28 | 28 | { |
29 | - /** |
|
30 | - * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia |
|
31 | - * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard. Note that URL encoding |
|
32 | - * of these values is *not* necessary; this is done automatically. |
|
33 | - * |
|
34 | - * @var string[] |
|
35 | - * @category Security-Critical |
|
36 | - */ |
|
37 | - private static $apiQueryParameters = array( |
|
38 | - 'action' => 'query', |
|
39 | - 'format' => 'json', |
|
40 | - 'prop' => 'links', |
|
41 | - 'titles' => 'Access to nonpublic information policy/Noticeboard', |
|
42 | - // Username of the user to be checked, with User: prefix, goes here! Set in isIdentifiedOnWiki() |
|
43 | - 'pltitles' => '', |
|
44 | - ); |
|
45 | - /** @var HttpHelper */ |
|
46 | - private $httpHelper; |
|
47 | - /** @var SiteConfiguration */ |
|
48 | - private $siteConfiguration; |
|
49 | - /** @var PdoDatabase */ |
|
50 | - private $dbObject; |
|
51 | - |
|
52 | - /** |
|
53 | - * IdentificationVerifier constructor. |
|
54 | - * |
|
55 | - * @param HttpHelper $httpHelper |
|
56 | - * @param SiteConfiguration $siteConfiguration |
|
57 | - * @param PdoDatabase $dbObject |
|
58 | - */ |
|
59 | - public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
60 | - { |
|
61 | - $this->httpHelper = $httpHelper; |
|
62 | - $this->siteConfiguration = $siteConfiguration; |
|
63 | - $this->dbObject = $dbObject; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Checks if the given user is identified to the Wikimedia Foundation. |
|
68 | - * |
|
69 | - * @param string $onWikiName The Wikipedia username of the user |
|
70 | - * |
|
71 | - * @return bool |
|
72 | - * @category Security-Critical |
|
73 | - */ |
|
74 | - public function isUserIdentified($onWikiName) |
|
75 | - { |
|
76 | - if ($this->checkIdentificationCache($onWikiName)) { |
|
77 | - return true; |
|
78 | - } |
|
79 | - else { |
|
80 | - if ($this->isIdentifiedOnWiki($onWikiName)) { |
|
81 | - $this->cacheIdentificationStatus($onWikiName); |
|
82 | - |
|
83 | - return true; |
|
84 | - } |
|
85 | - else { |
|
86 | - return false; |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Checks if the given user has a valid entry in the idcache table. |
|
93 | - * |
|
94 | - * @param string $onWikiName The Wikipedia username of the user |
|
95 | - * |
|
96 | - * @return bool |
|
97 | - * @category Security-Critical |
|
98 | - */ |
|
99 | - private function checkIdentificationCache($onWikiName) |
|
100 | - { |
|
101 | - $interval = $this->siteConfiguration->getIdentificationCacheExpiry(); |
|
102 | - |
|
103 | - $query = <<<SQL |
|
29 | + /** |
|
30 | + * This field is an array of parameters, in key => value format, that should be appended to the Meta Wikimedia |
|
31 | + * Web Service Endpoint URL to query if a user is listed on the Identification Noticeboard. Note that URL encoding |
|
32 | + * of these values is *not* necessary; this is done automatically. |
|
33 | + * |
|
34 | + * @var string[] |
|
35 | + * @category Security-Critical |
|
36 | + */ |
|
37 | + private static $apiQueryParameters = array( |
|
38 | + 'action' => 'query', |
|
39 | + 'format' => 'json', |
|
40 | + 'prop' => 'links', |
|
41 | + 'titles' => 'Access to nonpublic information policy/Noticeboard', |
|
42 | + // Username of the user to be checked, with User: prefix, goes here! Set in isIdentifiedOnWiki() |
|
43 | + 'pltitles' => '', |
|
44 | + ); |
|
45 | + /** @var HttpHelper */ |
|
46 | + private $httpHelper; |
|
47 | + /** @var SiteConfiguration */ |
|
48 | + private $siteConfiguration; |
|
49 | + /** @var PdoDatabase */ |
|
50 | + private $dbObject; |
|
51 | + |
|
52 | + /** |
|
53 | + * IdentificationVerifier constructor. |
|
54 | + * |
|
55 | + * @param HttpHelper $httpHelper |
|
56 | + * @param SiteConfiguration $siteConfiguration |
|
57 | + * @param PdoDatabase $dbObject |
|
58 | + */ |
|
59 | + public function __construct(HttpHelper $httpHelper, SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
60 | + { |
|
61 | + $this->httpHelper = $httpHelper; |
|
62 | + $this->siteConfiguration = $siteConfiguration; |
|
63 | + $this->dbObject = $dbObject; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Checks if the given user is identified to the Wikimedia Foundation. |
|
68 | + * |
|
69 | + * @param string $onWikiName The Wikipedia username of the user |
|
70 | + * |
|
71 | + * @return bool |
|
72 | + * @category Security-Critical |
|
73 | + */ |
|
74 | + public function isUserIdentified($onWikiName) |
|
75 | + { |
|
76 | + if ($this->checkIdentificationCache($onWikiName)) { |
|
77 | + return true; |
|
78 | + } |
|
79 | + else { |
|
80 | + if ($this->isIdentifiedOnWiki($onWikiName)) { |
|
81 | + $this->cacheIdentificationStatus($onWikiName); |
|
82 | + |
|
83 | + return true; |
|
84 | + } |
|
85 | + else { |
|
86 | + return false; |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Checks if the given user has a valid entry in the idcache table. |
|
93 | + * |
|
94 | + * @param string $onWikiName The Wikipedia username of the user |
|
95 | + * |
|
96 | + * @return bool |
|
97 | + * @category Security-Critical |
|
98 | + */ |
|
99 | + private function checkIdentificationCache($onWikiName) |
|
100 | + { |
|
101 | + $interval = $this->siteConfiguration->getIdentificationCacheExpiry(); |
|
102 | + |
|
103 | + $query = <<<SQL |
|
104 | 104 | SELECT COUNT(`id`) |
105 | 105 | FROM `idcache` |
106 | 106 | WHERE `onwikiusername` = :onwikiname |
107 | 107 | AND DATE_ADD(`checktime`, INTERVAL {$interval}) >= NOW(); |
108 | 108 | SQL; |
109 | - $stmt = $this->dbObject->prepare($query); |
|
110 | - $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
111 | - $stmt->execute(); |
|
112 | - |
|
113 | - // Guaranteed by the query to only return a single row with a single column |
|
114 | - $results = $stmt->fetch(PDO::FETCH_NUM); |
|
115 | - |
|
116 | - // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a |
|
117 | - // unique key - but meh. |
|
118 | - return $results[0] != 0; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the |
|
123 | - * idcache table. Meant to be called periodically by a maintenance script. |
|
124 | - * |
|
125 | - * @param SiteConfiguration $siteConfiguration |
|
126 | - * @param PdoDatabase $dbObject |
|
127 | - * |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
131 | - { |
|
132 | - $interval = $siteConfiguration->getIdentificationCacheExpiry(); |
|
133 | - |
|
134 | - $query = <<<SQL |
|
109 | + $stmt = $this->dbObject->prepare($query); |
|
110 | + $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
111 | + $stmt->execute(); |
|
112 | + |
|
113 | + // Guaranteed by the query to only return a single row with a single column |
|
114 | + $results = $stmt->fetch(PDO::FETCH_NUM); |
|
115 | + |
|
116 | + // I don't expect this to ever be a value other than 0 or 1 since the `onwikiusername` column is declared as a |
|
117 | + // unique key - but meh. |
|
118 | + return $results[0] != 0; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Does pretty much exactly what it says on the label - this method will clear all expired idcache entries from the |
|
123 | + * idcache table. Meant to be called periodically by a maintenance script. |
|
124 | + * |
|
125 | + * @param SiteConfiguration $siteConfiguration |
|
126 | + * @param PdoDatabase $dbObject |
|
127 | + * |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public static function clearExpiredCacheEntries(SiteConfiguration $siteConfiguration, PdoDatabase $dbObject) |
|
131 | + { |
|
132 | + $interval = $siteConfiguration->getIdentificationCacheExpiry(); |
|
133 | + |
|
134 | + $query = <<<SQL |
|
135 | 135 | DELETE FROM `idcache` |
136 | 136 | WHERE DATE_ADD(`checktime`, INTERVAL {$interval}) < NOW(); |
137 | 137 | SQL; |
138 | - $dbObject->prepare($query)->execute(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified. This |
|
143 | - * is so we don't have to hit the API every single time we check. The cache entry is valid for as long as specified |
|
144 | - * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()). |
|
145 | - * |
|
146 | - * @param string $onWikiName The Wikipedia username of the user |
|
147 | - * |
|
148 | - * @return void |
|
149 | - * @category Security-Critical |
|
150 | - */ |
|
151 | - private function cacheIdentificationStatus($onWikiName) |
|
152 | - { |
|
153 | - $query = <<<SQL |
|
138 | + $dbObject->prepare($query)->execute(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * This method will add an entry to the idcache that the given Wikipedia user has been verified as identified. This |
|
143 | + * is so we don't have to hit the API every single time we check. The cache entry is valid for as long as specified |
|
144 | + * in the ACC configuration (validity enforced by checkIdentificationCache() and clearExpiredCacheEntries()). |
|
145 | + * |
|
146 | + * @param string $onWikiName The Wikipedia username of the user |
|
147 | + * |
|
148 | + * @return void |
|
149 | + * @category Security-Critical |
|
150 | + */ |
|
151 | + private function cacheIdentificationStatus($onWikiName) |
|
152 | + { |
|
153 | + $query = <<<SQL |
|
154 | 154 | INSERT INTO `idcache` |
155 | 155 | (`onwikiusername`) |
156 | 156 | VALUES |
@@ -159,44 +159,44 @@ discard block |
||
159 | 159 | `onwikiusername` = VALUES(`onwikiusername`), |
160 | 160 | `checktime` = CURRENT_TIMESTAMP; |
161 | 161 | SQL; |
162 | - $stmt = $this->dbObject->prepare($query); |
|
163 | - $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
164 | - $stmt->execute(); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard. |
|
169 | - * |
|
170 | - * @param string $onWikiName The Wikipedia username of the user |
|
171 | - * |
|
172 | - * @return bool |
|
173 | - * @throws EnvironmentException |
|
174 | - * @category Security-Critical |
|
175 | - */ |
|
176 | - private function isIdentifiedOnWiki($onWikiName) |
|
177 | - { |
|
178 | - $strings = new StringFunctions(); |
|
179 | - |
|
180 | - // First character of Wikipedia usernames is always capitalized. |
|
181 | - $onWikiName = $strings->ucfirst($onWikiName); |
|
182 | - |
|
183 | - $parameters = self::$apiQueryParameters; |
|
184 | - $parameters['pltitles'] = "User:" . $onWikiName; |
|
185 | - |
|
186 | - try { |
|
187 | - $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
|
188 | - $response = $this->httpHelper->get($endpoint, $parameters); |
|
189 | - $response = json_decode($response, true); |
|
190 | - } catch (CurlException $ex) { |
|
191 | - // failed getting identification status, so throw a nicer error. |
|
192 | - $m = 'Could not contact metawiki API to determine user\' identification status. ' |
|
193 | - . 'This is probably a transient error, so please try again.'; |
|
194 | - |
|
195 | - throw new EnvironmentException($m, 0, $ex); |
|
196 | - } |
|
197 | - |
|
198 | - $page = @array_pop($response['query']['pages']); |
|
199 | - |
|
200 | - return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
201 | - } |
|
162 | + $stmt = $this->dbObject->prepare($query); |
|
163 | + $stmt->bindValue(':onwikiname', $onWikiName, PDO::PARAM_STR); |
|
164 | + $stmt->execute(); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Queries the Wikimedia API to determine if the specified user is listed on the identification noticeboard. |
|
169 | + * |
|
170 | + * @param string $onWikiName The Wikipedia username of the user |
|
171 | + * |
|
172 | + * @return bool |
|
173 | + * @throws EnvironmentException |
|
174 | + * @category Security-Critical |
|
175 | + */ |
|
176 | + private function isIdentifiedOnWiki($onWikiName) |
|
177 | + { |
|
178 | + $strings = new StringFunctions(); |
|
179 | + |
|
180 | + // First character of Wikipedia usernames is always capitalized. |
|
181 | + $onWikiName = $strings->ucfirst($onWikiName); |
|
182 | + |
|
183 | + $parameters = self::$apiQueryParameters; |
|
184 | + $parameters['pltitles'] = "User:" . $onWikiName; |
|
185 | + |
|
186 | + try { |
|
187 | + $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
|
188 | + $response = $this->httpHelper->get($endpoint, $parameters); |
|
189 | + $response = json_decode($response, true); |
|
190 | + } catch (CurlException $ex) { |
|
191 | + // failed getting identification status, so throw a nicer error. |
|
192 | + $m = 'Could not contact metawiki API to determine user\' identification status. ' |
|
193 | + . 'This is probably a transient error, so please try again.'; |
|
194 | + |
|
195 | + throw new EnvironmentException($m, 0, $ex); |
|
196 | + } |
|
197 | + |
|
198 | + $page = @array_pop($response['query']['pages']); |
|
199 | + |
|
200 | + return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
201 | + } |
|
202 | 202 | } |
@@ -187,7 +187,8 @@ |
||
187 | 187 | $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
188 | 188 | $response = $this->httpHelper->get($endpoint, $parameters); |
189 | 189 | $response = json_decode($response, true); |
190 | - } catch (CurlException $ex) { |
|
190 | + } |
|
191 | + catch (CurlException $ex) { |
|
191 | 192 | // failed getting identification status, so throw a nicer error. |
192 | 193 | $m = 'Could not contact metawiki API to determine user\' identification status. ' |
193 | 194 | . 'This is probably a transient error, so please try again.'; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $onWikiName = $strings->ucfirst($onWikiName); |
182 | 182 | |
183 | 183 | $parameters = self::$apiQueryParameters; |
184 | - $parameters['pltitles'] = "User:" . $onWikiName; |
|
184 | + $parameters['pltitles'] = "User:".$onWikiName; |
|
185 | 185 | |
186 | 186 | try { |
187 | 187 | $endpoint = $this->siteConfiguration->getMetaWikimediaWebServiceEndpoint(); |
@@ -197,6 +197,6 @@ discard block |
||
197 | 197 | |
198 | 198 | $page = @array_pop($response['query']['pages']); |
199 | 199 | |
200 | - return @$page['links'][0]['title'] === "User:" . $onWikiName; |
|
200 | + return @$page['links'][0]['title'] === "User:".$onWikiName; |
|
201 | 201 | } |
202 | 202 | } |
@@ -13,25 +13,25 @@ |
||
13 | 13 | |
14 | 14 | class ClearOldDataTask extends ConsoleTaskBase |
15 | 15 | { |
16 | - public function execute() |
|
17 | - { |
|
18 | - $dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval(); |
|
16 | + public function execute() |
|
17 | + { |
|
18 | + $dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval(); |
|
19 | 19 | |
20 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
20 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
21 | 21 | UPDATE request |
22 | 22 | SET ip = :ip, forwardedip = null, email = :mail, useragent = '' |
23 | 23 | WHERE date < DATE_SUB(curdate(), INTERVAL {$dataClearInterval}) |
24 | 24 | AND status = 'Closed'; |
25 | 25 | SQL |
26 | - ); |
|
26 | + ); |
|
27 | 27 | |
28 | - $success = $query->execute(array( |
|
29 | - ":ip" => $this->getSiteConfiguration()->getDataClearIp(), |
|
30 | - ":mail" => $this->getSiteConfiguration()->getDataClearEmail(), |
|
31 | - )); |
|
28 | + $success = $query->execute(array( |
|
29 | + ":ip" => $this->getSiteConfiguration()->getDataClearIp(), |
|
30 | + ":mail" => $this->getSiteConfiguration()->getDataClearEmail(), |
|
31 | + )); |
|
32 | 32 | |
33 | - if (!$success) { |
|
34 | - throw new Exception("Error in transaction: Could not clear data."); |
|
35 | - } |
|
36 | - } |
|
33 | + if (!$success) { |
|
34 | + throw new Exception("Error in transaction: Could not clear data."); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | \ No newline at end of file |