@@ -17,76 +17,76 @@ |
||
17 | 17 | |
18 | 18 | abstract class XmlApiPageBase extends ApiPageBase implements IXmlApiAction |
19 | 19 | { |
20 | - /** |
|
21 | - * API result document |
|
22 | - * @var DOMDocument |
|
23 | - */ |
|
24 | - protected $document; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->document = new DOMDocument('1.0'); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Main function for this page, when no specific actions are called. |
|
33 | - * |
|
34 | - * @throws ApiException |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - final protected function main() |
|
38 | - { |
|
39 | - if (headers_sent()) { |
|
40 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
41 | - } |
|
42 | - |
|
43 | - header("Content-Type: text/xml"); |
|
44 | - |
|
45 | - // javascript access control |
|
46 | - $httpOrigin = WebRequest::origin(); |
|
47 | - |
|
48 | - if ($httpOrigin !== null) { |
|
49 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
50 | - |
|
51 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
52 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - $responseData = $this->runApiPage(); |
|
57 | - |
|
58 | - ob_end_clean(); |
|
59 | - print($responseData); |
|
60 | - ob_start(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Method that runs API action |
|
65 | - * |
|
66 | - * @param DOMElement $apiDocument |
|
67 | - * |
|
68 | - * @return DOMElement |
|
69 | - */ |
|
70 | - abstract public function executeApiAction(DOMElement $apiDocument); |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - final public function runApiPage() |
|
76 | - { |
|
77 | - $apiDocument = $this->document->createElement("api"); |
|
78 | - |
|
79 | - try { |
|
80 | - $apiDocument = $this->executeApiAction($apiDocument); |
|
81 | - } |
|
82 | - catch (ApiException $ex) { |
|
83 | - $exception = $this->document->createElement("error"); |
|
84 | - $exception->setAttribute("message", $ex->getMessage()); |
|
85 | - $apiDocument->appendChild($exception); |
|
86 | - } |
|
87 | - |
|
88 | - $this->document->appendChild($apiDocument); |
|
89 | - |
|
90 | - return $this->document->saveXML(); |
|
91 | - } |
|
20 | + /** |
|
21 | + * API result document |
|
22 | + * @var DOMDocument |
|
23 | + */ |
|
24 | + protected $document; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->document = new DOMDocument('1.0'); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Main function for this page, when no specific actions are called. |
|
33 | + * |
|
34 | + * @throws ApiException |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + final protected function main() |
|
38 | + { |
|
39 | + if (headers_sent()) { |
|
40 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
41 | + } |
|
42 | + |
|
43 | + header("Content-Type: text/xml"); |
|
44 | + |
|
45 | + // javascript access control |
|
46 | + $httpOrigin = WebRequest::origin(); |
|
47 | + |
|
48 | + if ($httpOrigin !== null) { |
|
49 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
50 | + |
|
51 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
52 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + $responseData = $this->runApiPage(); |
|
57 | + |
|
58 | + ob_end_clean(); |
|
59 | + print($responseData); |
|
60 | + ob_start(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Method that runs API action |
|
65 | + * |
|
66 | + * @param DOMElement $apiDocument |
|
67 | + * |
|
68 | + * @return DOMElement |
|
69 | + */ |
|
70 | + abstract public function executeApiAction(DOMElement $apiDocument); |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + final public function runApiPage() |
|
76 | + { |
|
77 | + $apiDocument = $this->document->createElement("api"); |
|
78 | + |
|
79 | + try { |
|
80 | + $apiDocument = $this->executeApiAction($apiDocument); |
|
81 | + } |
|
82 | + catch (ApiException $ex) { |
|
83 | + $exception = $this->document->createElement("error"); |
|
84 | + $exception->setAttribute("message", $ex->getMessage()); |
|
85 | + $apiDocument->appendChild($exception); |
|
86 | + } |
|
87 | + |
|
88 | + $this->document->appendChild($apiDocument); |
|
89 | + |
|
90 | + return $this->document->saveXML(); |
|
91 | + } |
|
92 | 92 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
70 | 70 | |
71 | 71 | if (in_array($httpOrigin, $CORSallowed)) { |
72 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
72 | + header("Access-Control-Allow-Origin: ".$httpOrigin); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 |
@@ -18,34 +18,34 @@ |
||
18 | 18 | */ |
19 | 19 | class HelpAction extends XmlApiPageBase implements IXmlApiAction |
20 | 20 | { |
21 | - public function executeApiAction(DOMElement $apiDocument) |
|
22 | - { |
|
23 | - $helpElement = $this->getHelpElement(); |
|
24 | - $apiDocument->appendChild($helpElement); |
|
25 | - |
|
26 | - return $apiDocument; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Gets the help information |
|
31 | - * @return DOMElement |
|
32 | - */ |
|
33 | - protected function getHelpElement() |
|
34 | - { |
|
21 | + public function executeApiAction(DOMElement $apiDocument) |
|
22 | + { |
|
23 | + $helpElement = $this->getHelpElement(); |
|
24 | + $apiDocument->appendChild($helpElement); |
|
25 | + |
|
26 | + return $apiDocument; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Gets the help information |
|
31 | + * @return DOMElement |
|
32 | + */ |
|
33 | + protected function getHelpElement() |
|
34 | + { |
|
35 | 35 | $helpInfo = "API help can be found at https://github.com/enwikipedia-acc/waca/wiki/API"; |
36 | 36 | |
37 | - $help = $this->document->createElement("help"); |
|
38 | - $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | - $helpactions = $this->document->createElement("actions"); |
|
37 | + $help = $this->document->createElement("help"); |
|
38 | + $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | + $helpactions = $this->document->createElement("actions"); |
|
40 | 40 | |
41 | - foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | - $actionElement = $this->document->createElement("action", $action); |
|
43 | - $helpactions->appendChild($actionElement); |
|
44 | - } |
|
41 | + foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | + $actionElement = $this->document->createElement("action", $action); |
|
43 | + $helpactions->appendChild($actionElement); |
|
44 | + } |
|
45 | 45 | |
46 | - $help->appendChild($helptext); |
|
47 | - $help->appendChild($helpactions); |
|
46 | + $help->appendChild($helptext); |
|
47 | + $help->appendChild($helpactions); |
|
48 | 48 | |
49 | - return $help; |
|
50 | - } |
|
49 | + return $help; |
|
50 | + } |
|
51 | 51 | } |
@@ -22,58 +22,58 @@ |
||
22 | 22 | */ |
23 | 23 | class StatsAction extends XmlApiPageBase implements IXmlApiAction |
24 | 24 | { |
25 | - /** |
|
26 | - * The target user |
|
27 | - * @var User $user |
|
28 | - */ |
|
29 | - private $user; |
|
25 | + /** |
|
26 | + * The target user |
|
27 | + * @var User $user |
|
28 | + */ |
|
29 | + private $user; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Summary of execute |
|
33 | - * |
|
34 | - * @param DOMElement $apiDocument |
|
35 | - * |
|
36 | - * @return DOMElement |
|
37 | - * @throws ApiException |
|
38 | - * @throws Exception |
|
39 | - */ |
|
40 | - public function executeApiAction(DOMElement $apiDocument) |
|
41 | - { |
|
42 | - $username = WebRequest::getString('user'); |
|
43 | - $wikiusername = WebRequest::getString('wikiuser'); |
|
31 | + /** |
|
32 | + * Summary of execute |
|
33 | + * |
|
34 | + * @param DOMElement $apiDocument |
|
35 | + * |
|
36 | + * @return DOMElement |
|
37 | + * @throws ApiException |
|
38 | + * @throws Exception |
|
39 | + */ |
|
40 | + public function executeApiAction(DOMElement $apiDocument) |
|
41 | + { |
|
42 | + $username = WebRequest::getString('user'); |
|
43 | + $wikiusername = WebRequest::getString('wikiuser'); |
|
44 | 44 | |
45 | - if ($username === null && $wikiusername === null) { |
|
46 | - throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
47 | - } |
|
45 | + if ($username === null && $wikiusername === null) { |
|
46 | + throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
47 | + } |
|
48 | 48 | |
49 | - $userElement = $this->document->createElement("user"); |
|
50 | - $apiDocument->appendChild($userElement); |
|
49 | + $userElement = $this->document->createElement("user"); |
|
50 | + $apiDocument->appendChild($userElement); |
|
51 | 51 | |
52 | - if ($username !== null) { |
|
53 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
54 | - } |
|
55 | - else { |
|
56 | - $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
57 | - } |
|
52 | + if ($username !== null) { |
|
53 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
54 | + } |
|
55 | + else { |
|
56 | + $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
57 | + } |
|
58 | 58 | |
59 | - if ($user === false) { |
|
60 | - $userElement->setAttribute("missing", "true"); |
|
59 | + if ($user === false) { |
|
60 | + $userElement->setAttribute("missing", "true"); |
|
61 | 61 | |
62 | - return $apiDocument; |
|
63 | - } |
|
62 | + return $apiDocument; |
|
63 | + } |
|
64 | 64 | |
65 | - $this->user = $user; |
|
65 | + $this->user = $user; |
|
66 | 66 | |
67 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
68 | - $this->getSiteConfiguration()); |
|
67 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
68 | + $this->getSiteConfiguration()); |
|
69 | 69 | |
70 | - $userElement->setAttribute("username", $this->user->getUsername()); |
|
71 | - $userElement->setAttribute("status", $this->user->getStatus()); |
|
72 | - $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
73 | - $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
74 | - $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
75 | - $userElement->setAttribute("oauth", $oauth->isFullyLinked() ? "true" : "false"); |
|
70 | + $userElement->setAttribute("username", $this->user->getUsername()); |
|
71 | + $userElement->setAttribute("status", $this->user->getStatus()); |
|
72 | + $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
73 | + $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
74 | + $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
75 | + $userElement->setAttribute("oauth", $oauth->isFullyLinked() ? "true" : "false"); |
|
76 | 76 | |
77 | - return $apiDocument; |
|
78 | - } |
|
77 | + return $apiDocument; |
|
78 | + } |
|
79 | 79 | } |
@@ -16,51 +16,51 @@ discard block |
||
16 | 16 | |
17 | 17 | class OAuthIdentity extends DataObject |
18 | 18 | { |
19 | - #region Fields |
|
20 | - /** @var int */ |
|
21 | - private $user; |
|
22 | - /** @var string */ |
|
23 | - private $iss; |
|
24 | - /** @var int */ |
|
25 | - private $sub; |
|
26 | - /** @var string */ |
|
27 | - private $aud; |
|
28 | - /** @var int */ |
|
29 | - private $exp; |
|
30 | - /** @var int */ |
|
31 | - private $iat; |
|
32 | - /** @var string */ |
|
33 | - private $username; |
|
34 | - /** @var int */ |
|
35 | - private $editcount; |
|
36 | - /** @var int */ |
|
37 | - private $confirmed_email; |
|
38 | - /** @var int */ |
|
39 | - private $blocked; |
|
40 | - /** @var string */ |
|
41 | - private $registered; |
|
42 | - /** @var int */ |
|
43 | - private $checkuser; |
|
44 | - /** @var int */ |
|
45 | - private $grantbasic; |
|
46 | - /** @var int */ |
|
47 | - private $grantcreateaccount; |
|
48 | - /** @var int */ |
|
49 | - private $granthighvolume; |
|
50 | - /** @var int */ |
|
51 | - private $grantcreateeditmovepage; |
|
52 | - #endregion |
|
53 | - |
|
54 | - /** |
|
55 | - * Saves a data object to the database, either updating or inserting a record. |
|
56 | - * @return void |
|
57 | - * @throws Exception |
|
58 | - * @throws OptimisticLockFailedException |
|
59 | - */ |
|
60 | - public function save() |
|
61 | - { |
|
62 | - if ($this->isNew()) { |
|
63 | - $statement = $this->dbObject->prepare(<<<SQL |
|
19 | + #region Fields |
|
20 | + /** @var int */ |
|
21 | + private $user; |
|
22 | + /** @var string */ |
|
23 | + private $iss; |
|
24 | + /** @var int */ |
|
25 | + private $sub; |
|
26 | + /** @var string */ |
|
27 | + private $aud; |
|
28 | + /** @var int */ |
|
29 | + private $exp; |
|
30 | + /** @var int */ |
|
31 | + private $iat; |
|
32 | + /** @var string */ |
|
33 | + private $username; |
|
34 | + /** @var int */ |
|
35 | + private $editcount; |
|
36 | + /** @var int */ |
|
37 | + private $confirmed_email; |
|
38 | + /** @var int */ |
|
39 | + private $blocked; |
|
40 | + /** @var string */ |
|
41 | + private $registered; |
|
42 | + /** @var int */ |
|
43 | + private $checkuser; |
|
44 | + /** @var int */ |
|
45 | + private $grantbasic; |
|
46 | + /** @var int */ |
|
47 | + private $grantcreateaccount; |
|
48 | + /** @var int */ |
|
49 | + private $granthighvolume; |
|
50 | + /** @var int */ |
|
51 | + private $grantcreateeditmovepage; |
|
52 | + #endregion |
|
53 | + |
|
54 | + /** |
|
55 | + * Saves a data object to the database, either updating or inserting a record. |
|
56 | + * @return void |
|
57 | + * @throws Exception |
|
58 | + * @throws OptimisticLockFailedException |
|
59 | + */ |
|
60 | + public function save() |
|
61 | + { |
|
62 | + if ($this->isNew()) { |
|
63 | + $statement = $this->dbObject->prepare(<<<SQL |
|
64 | 64 | INSERT INTO oauthidentity ( |
65 | 65 | user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, |
66 | 66 | grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage |
@@ -69,34 +69,34 @@ discard block |
||
69 | 69 | :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage |
70 | 70 | ) |
71 | 71 | SQL |
72 | - ); |
|
73 | - |
|
74 | - $statement->bindValue(':user', $this->user); |
|
75 | - $statement->bindValue(':iss', $this->iss); |
|
76 | - $statement->bindValue(':sub', $this->sub); |
|
77 | - $statement->bindValue(':aud', $this->aud); |
|
78 | - $statement->bindValue(':exp', $this->exp); |
|
79 | - $statement->bindValue(':iat', $this->iat); |
|
80 | - $statement->bindValue(':username', $this->username); |
|
81 | - $statement->bindValue(':editcount', $this->editcount); |
|
82 | - $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
83 | - $statement->bindValue(':blocked', $this->blocked); |
|
84 | - $statement->bindValue(':registered', $this->registered); |
|
85 | - $statement->bindValue(':checkuser', $this->checkuser); |
|
86 | - $statement->bindValue(':grantbasic', $this->grantbasic); |
|
87 | - $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
88 | - $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
89 | - $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
90 | - |
|
91 | - if ($statement->execute()) { |
|
92 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
93 | - } |
|
94 | - else { |
|
95 | - throw new Exception($statement->errorInfo()); |
|
96 | - } |
|
97 | - } |
|
98 | - else { |
|
99 | - $statement = $this->dbObject->prepare(<<<SQL |
|
72 | + ); |
|
73 | + |
|
74 | + $statement->bindValue(':user', $this->user); |
|
75 | + $statement->bindValue(':iss', $this->iss); |
|
76 | + $statement->bindValue(':sub', $this->sub); |
|
77 | + $statement->bindValue(':aud', $this->aud); |
|
78 | + $statement->bindValue(':exp', $this->exp); |
|
79 | + $statement->bindValue(':iat', $this->iat); |
|
80 | + $statement->bindValue(':username', $this->username); |
|
81 | + $statement->bindValue(':editcount', $this->editcount); |
|
82 | + $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
83 | + $statement->bindValue(':blocked', $this->blocked); |
|
84 | + $statement->bindValue(':registered', $this->registered); |
|
85 | + $statement->bindValue(':checkuser', $this->checkuser); |
|
86 | + $statement->bindValue(':grantbasic', $this->grantbasic); |
|
87 | + $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
88 | + $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
89 | + $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
90 | + |
|
91 | + if ($statement->execute()) { |
|
92 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
93 | + } |
|
94 | + else { |
|
95 | + throw new Exception($statement->errorInfo()); |
|
96 | + } |
|
97 | + } |
|
98 | + else { |
|
99 | + $statement = $this->dbObject->prepare(<<<SQL |
|
100 | 100 | UPDATE oauthidentity SET |
101 | 101 | iss = :iss |
102 | 102 | , sub = :sub |
@@ -116,211 +116,211 @@ discard block |
||
116 | 116 | , updateversion = updateversion + 1 |
117 | 117 | WHERE id = :id AND updateversion = :updateversion |
118 | 118 | SQL |
119 | - ); |
|
120 | - |
|
121 | - $statement->bindValue(':iss', $this->iss); |
|
122 | - $statement->bindValue(':sub', $this->sub); |
|
123 | - $statement->bindValue(':aud', $this->aud); |
|
124 | - $statement->bindValue(':exp', $this->exp); |
|
125 | - $statement->bindValue(':iat', $this->iat); |
|
126 | - $statement->bindValue(':username', $this->username); |
|
127 | - $statement->bindValue(':editcount', $this->editcount); |
|
128 | - $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
129 | - $statement->bindValue(':blocked', $this->blocked); |
|
130 | - $statement->bindValue(':registered', $this->registered); |
|
131 | - $statement->bindValue(':checkuser', $this->checkuser); |
|
132 | - $statement->bindValue(':grantbasic', $this->grantbasic); |
|
133 | - $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
134 | - $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
135 | - $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
136 | - |
|
137 | - $statement->bindValue(':id', $this->id); |
|
138 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
139 | - |
|
140 | - if (!$statement->execute()) { |
|
141 | - throw new Exception($statement->errorInfo()); |
|
142 | - } |
|
143 | - |
|
144 | - if ($statement->rowCount() !== 1) { |
|
145 | - throw new OptimisticLockFailedException(); |
|
146 | - } |
|
147 | - |
|
148 | - $this->updateversion++; |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - #region Properties |
|
153 | - |
|
154 | - /** |
|
155 | - * @return int |
|
156 | - */ |
|
157 | - public function getUserId() |
|
158 | - { |
|
159 | - return $this->user; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @param int $user |
|
164 | - */ |
|
165 | - public function setUserId($user) |
|
166 | - { |
|
167 | - $this->user = $user; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function getIssuer() |
|
174 | - { |
|
175 | - return $this->iss; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return int |
|
180 | - */ |
|
181 | - public function getSubject() |
|
182 | - { |
|
183 | - return $this->sub; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function getAudience() |
|
190 | - { |
|
191 | - return $this->aud; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @return int |
|
196 | - */ |
|
197 | - public function getExpirationTime() |
|
198 | - { |
|
199 | - return $this->exp; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return int |
|
204 | - */ |
|
205 | - public function getIssuedAtTime() |
|
206 | - { |
|
207 | - return $this->iat; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function getUsername() |
|
214 | - { |
|
215 | - return $this->username; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @return int |
|
220 | - */ |
|
221 | - public function getEditCount() |
|
222 | - { |
|
223 | - return $this->editcount; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return bool |
|
228 | - */ |
|
229 | - public function getConfirmedEmail() |
|
230 | - { |
|
231 | - return $this->confirmed_email == 1; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @return bool |
|
236 | - */ |
|
237 | - public function getBlocked() |
|
238 | - { |
|
239 | - return $this->blocked == 1; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - public function getRegistered() |
|
246 | - { |
|
247 | - return $this->registered; |
|
248 | - } |
|
249 | - |
|
250 | - public function getRegistrationDate() |
|
251 | - { |
|
252 | - return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r'); |
|
253 | - } |
|
254 | - |
|
255 | - public function getAccountAge() |
|
256 | - { |
|
257 | - $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered); |
|
258 | - $interval = $regDate->diff(new DateTimeImmutable(), true); |
|
259 | - |
|
260 | - return $interval->days; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @return bool |
|
265 | - */ |
|
266 | - public function getCheckuser() |
|
267 | - { |
|
268 | - return $this->checkuser == 1; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * @return bool |
|
273 | - */ |
|
274 | - public function getGrantBasic() |
|
275 | - { |
|
276 | - return $this->grantbasic == 1; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @return bool |
|
281 | - */ |
|
282 | - public function getGrantCreateAccount() |
|
283 | - { |
|
284 | - return $this->grantcreateaccount == 1; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @return bool |
|
289 | - */ |
|
290 | - public function getGrantHighVolume() |
|
291 | - { |
|
292 | - return $this->granthighvolume == 1; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * @return bool |
|
297 | - */ |
|
298 | - public function getGrantCreateEditMovePage() |
|
299 | - { |
|
300 | - return $this->grantcreateeditmovepage == 1; |
|
301 | - } |
|
302 | - |
|
303 | - #endregion Properties |
|
304 | - |
|
305 | - /** |
|
306 | - * Populates the fields of this instance from a provided JSON Web Token |
|
307 | - * |
|
308 | - * @param stdClass $jwt |
|
309 | - */ |
|
310 | - public function populate($jwt) |
|
311 | - { |
|
312 | - $this->iss = $jwt->iss; |
|
313 | - $this->sub = $jwt->sub; |
|
314 | - $this->aud = $jwt->aud; |
|
315 | - $this->exp = $jwt->exp; |
|
316 | - $this->iat = $jwt->iat; |
|
317 | - $this->username = $jwt->username; |
|
318 | - $this->editcount = $jwt->editcount; |
|
319 | - $this->confirmed_email = $jwt->confirmed_email ? 1 : 0; |
|
320 | - $this->blocked = $jwt->blocked ? 1 : 0; |
|
321 | - $this->registered = $jwt->registered; |
|
322 | - |
|
323 | - /* |
|
119 | + ); |
|
120 | + |
|
121 | + $statement->bindValue(':iss', $this->iss); |
|
122 | + $statement->bindValue(':sub', $this->sub); |
|
123 | + $statement->bindValue(':aud', $this->aud); |
|
124 | + $statement->bindValue(':exp', $this->exp); |
|
125 | + $statement->bindValue(':iat', $this->iat); |
|
126 | + $statement->bindValue(':username', $this->username); |
|
127 | + $statement->bindValue(':editcount', $this->editcount); |
|
128 | + $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
129 | + $statement->bindValue(':blocked', $this->blocked); |
|
130 | + $statement->bindValue(':registered', $this->registered); |
|
131 | + $statement->bindValue(':checkuser', $this->checkuser); |
|
132 | + $statement->bindValue(':grantbasic', $this->grantbasic); |
|
133 | + $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
134 | + $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
135 | + $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
136 | + |
|
137 | + $statement->bindValue(':id', $this->id); |
|
138 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
139 | + |
|
140 | + if (!$statement->execute()) { |
|
141 | + throw new Exception($statement->errorInfo()); |
|
142 | + } |
|
143 | + |
|
144 | + if ($statement->rowCount() !== 1) { |
|
145 | + throw new OptimisticLockFailedException(); |
|
146 | + } |
|
147 | + |
|
148 | + $this->updateversion++; |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + #region Properties |
|
153 | + |
|
154 | + /** |
|
155 | + * @return int |
|
156 | + */ |
|
157 | + public function getUserId() |
|
158 | + { |
|
159 | + return $this->user; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @param int $user |
|
164 | + */ |
|
165 | + public function setUserId($user) |
|
166 | + { |
|
167 | + $this->user = $user; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function getIssuer() |
|
174 | + { |
|
175 | + return $this->iss; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return int |
|
180 | + */ |
|
181 | + public function getSubject() |
|
182 | + { |
|
183 | + return $this->sub; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function getAudience() |
|
190 | + { |
|
191 | + return $this->aud; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @return int |
|
196 | + */ |
|
197 | + public function getExpirationTime() |
|
198 | + { |
|
199 | + return $this->exp; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return int |
|
204 | + */ |
|
205 | + public function getIssuedAtTime() |
|
206 | + { |
|
207 | + return $this->iat; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function getUsername() |
|
214 | + { |
|
215 | + return $this->username; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @return int |
|
220 | + */ |
|
221 | + public function getEditCount() |
|
222 | + { |
|
223 | + return $this->editcount; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return bool |
|
228 | + */ |
|
229 | + public function getConfirmedEmail() |
|
230 | + { |
|
231 | + return $this->confirmed_email == 1; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @return bool |
|
236 | + */ |
|
237 | + public function getBlocked() |
|
238 | + { |
|
239 | + return $this->blocked == 1; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + public function getRegistered() |
|
246 | + { |
|
247 | + return $this->registered; |
|
248 | + } |
|
249 | + |
|
250 | + public function getRegistrationDate() |
|
251 | + { |
|
252 | + return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r'); |
|
253 | + } |
|
254 | + |
|
255 | + public function getAccountAge() |
|
256 | + { |
|
257 | + $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered); |
|
258 | + $interval = $regDate->diff(new DateTimeImmutable(), true); |
|
259 | + |
|
260 | + return $interval->days; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @return bool |
|
265 | + */ |
|
266 | + public function getCheckuser() |
|
267 | + { |
|
268 | + return $this->checkuser == 1; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * @return bool |
|
273 | + */ |
|
274 | + public function getGrantBasic() |
|
275 | + { |
|
276 | + return $this->grantbasic == 1; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @return bool |
|
281 | + */ |
|
282 | + public function getGrantCreateAccount() |
|
283 | + { |
|
284 | + return $this->grantcreateaccount == 1; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @return bool |
|
289 | + */ |
|
290 | + public function getGrantHighVolume() |
|
291 | + { |
|
292 | + return $this->granthighvolume == 1; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * @return bool |
|
297 | + */ |
|
298 | + public function getGrantCreateEditMovePage() |
|
299 | + { |
|
300 | + return $this->grantcreateeditmovepage == 1; |
|
301 | + } |
|
302 | + |
|
303 | + #endregion Properties |
|
304 | + |
|
305 | + /** |
|
306 | + * Populates the fields of this instance from a provided JSON Web Token |
|
307 | + * |
|
308 | + * @param stdClass $jwt |
|
309 | + */ |
|
310 | + public function populate($jwt) |
|
311 | + { |
|
312 | + $this->iss = $jwt->iss; |
|
313 | + $this->sub = $jwt->sub; |
|
314 | + $this->aud = $jwt->aud; |
|
315 | + $this->exp = $jwt->exp; |
|
316 | + $this->iat = $jwt->iat; |
|
317 | + $this->username = $jwt->username; |
|
318 | + $this->editcount = $jwt->editcount; |
|
319 | + $this->confirmed_email = $jwt->confirmed_email ? 1 : 0; |
|
320 | + $this->blocked = $jwt->blocked ? 1 : 0; |
|
321 | + $this->registered = $jwt->registered; |
|
322 | + |
|
323 | + /* |
|
324 | 324 | * Rights we need: |
325 | 325 | * Account creation |
326 | 326 | * createaccount => createaccount |
@@ -342,11 +342,11 @@ discard block |
||
342 | 342 | * Any antispoof conflicts will still have to be resolved manually using the normal creation form. |
343 | 343 | */ |
344 | 344 | |
345 | - $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0; |
|
346 | - $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0; |
|
347 | - $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0; |
|
348 | - $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0; |
|
345 | + $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0; |
|
346 | + $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0; |
|
347 | + $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0; |
|
348 | + $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0; |
|
349 | 349 | |
350 | - $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0; |
|
351 | - } |
|
350 | + $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0; |
|
351 | + } |
|
352 | 352 | } |
@@ -26,241 +26,241 @@ |
||
26 | 26 | |
27 | 27 | class PageJobQueue extends PagedInternalPageBase |
28 | 28 | { |
29 | - /** |
|
30 | - * Main function for this page, when no specific actions are called. |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - protected function main() |
|
34 | - { |
|
35 | - $this->setHtmlTitle('Job Queue Management'); |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + protected function main() |
|
34 | + { |
|
35 | + $this->setHtmlTitle('Job Queue Management'); |
|
36 | 36 | |
37 | - $this->prepareMaps(); |
|
37 | + $this->prepareMaps(); |
|
38 | 38 | |
39 | - $database = $this->getDatabase(); |
|
39 | + $database = $this->getDatabase(); |
|
40 | 40 | |
41 | - /** @var JobQueue[] $jobList */ |
|
42 | - $jobList = JobQueueSearchHelper::get($database) |
|
43 | - ->statusIn(array('ready', 'waiting', 'running', 'failed')) |
|
44 | - ->notAcknowledged() |
|
45 | - ->fetch(); |
|
41 | + /** @var JobQueue[] $jobList */ |
|
42 | + $jobList = JobQueueSearchHelper::get($database) |
|
43 | + ->statusIn(array('ready', 'waiting', 'running', 'failed')) |
|
44 | + ->notAcknowledged() |
|
45 | + ->fetch(); |
|
46 | 46 | |
47 | - $userIds = array(); |
|
48 | - $requestIds = array(); |
|
47 | + $userIds = array(); |
|
48 | + $requestIds = array(); |
|
49 | 49 | |
50 | - foreach ($jobList as $job) { |
|
51 | - $userIds[] = $job->getTriggerUserId(); |
|
52 | - $requestIds[] = $job->getRequest(); |
|
50 | + foreach ($jobList as $job) { |
|
51 | + $userIds[] = $job->getTriggerUserId(); |
|
52 | + $requestIds[] = $job->getRequest(); |
|
53 | 53 | |
54 | - $job->setDatabase($database); |
|
55 | - } |
|
54 | + $job->setDatabase($database); |
|
55 | + } |
|
56 | 56 | |
57 | - $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database))); |
|
57 | + $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database))); |
|
58 | 58 | |
59 | - $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
60 | - $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name')); |
|
59 | + $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
60 | + $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name')); |
|
61 | 61 | |
62 | - $this->assign('joblist', $jobList); |
|
63 | - $this->setTemplate('jobqueue/main.tpl'); |
|
64 | - } |
|
62 | + $this->assign('joblist', $jobList); |
|
63 | + $this->setTemplate('jobqueue/main.tpl'); |
|
64 | + } |
|
65 | 65 | |
66 | - protected function all() |
|
67 | - { |
|
68 | - $this->setHtmlTitle('All Jobs'); |
|
66 | + protected function all() |
|
67 | + { |
|
68 | + $this->setHtmlTitle('All Jobs'); |
|
69 | 69 | |
70 | - $this->prepareMaps(); |
|
70 | + $this->prepareMaps(); |
|
71 | 71 | |
72 | - $database = $this->getDatabase(); |
|
72 | + $database = $this->getDatabase(); |
|
73 | 73 | |
74 | - $searchHelper = JobQueueSearchHelper::get($database); |
|
75 | - $this->setSearchHelper($searchHelper); |
|
76 | - $this->setupLimits(); |
|
74 | + $searchHelper = JobQueueSearchHelper::get($database); |
|
75 | + $this->setSearchHelper($searchHelper); |
|
76 | + $this->setupLimits(); |
|
77 | 77 | |
78 | - $filterUser = WebRequest::getString('filterUser'); |
|
79 | - $filterTask = WebRequest::getString('filterTask'); |
|
80 | - $filterStatus = WebRequest::getString('filterStatus'); |
|
81 | - $filterRequest = WebRequest::getString('filterRequest'); |
|
78 | + $filterUser = WebRequest::getString('filterUser'); |
|
79 | + $filterTask = WebRequest::getString('filterTask'); |
|
80 | + $filterStatus = WebRequest::getString('filterStatus'); |
|
81 | + $filterRequest = WebRequest::getString('filterRequest'); |
|
82 | 82 | |
83 | - if ($filterUser !== null) { |
|
84 | - $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
85 | - } |
|
83 | + if ($filterUser !== null) { |
|
84 | + $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
85 | + } |
|
86 | 86 | |
87 | - if ($filterTask !== null) { |
|
88 | - $searchHelper->byTask($filterTask); |
|
89 | - } |
|
87 | + if ($filterTask !== null) { |
|
88 | + $searchHelper->byTask($filterTask); |
|
89 | + } |
|
90 | 90 | |
91 | - if ($filterStatus !== null) { |
|
92 | - $searchHelper->byStatus($filterStatus); |
|
93 | - } |
|
91 | + if ($filterStatus !== null) { |
|
92 | + $searchHelper->byStatus($filterStatus); |
|
93 | + } |
|
94 | 94 | |
95 | - if ($filterRequest !== null) { |
|
96 | - $searchHelper->byRequest($filterRequest); |
|
97 | - } |
|
95 | + if ($filterRequest !== null) { |
|
96 | + $searchHelper->byRequest($filterRequest); |
|
97 | + } |
|
98 | 98 | |
99 | - /** @var JobQueue[] $jobList */ |
|
100 | - $jobList = $searchHelper->getRecordCount($count)->fetch(); |
|
99 | + /** @var JobQueue[] $jobList */ |
|
100 | + $jobList = $searchHelper->getRecordCount($count)->fetch(); |
|
101 | 101 | |
102 | - $this->setupPageData($count, array( |
|
103 | - 'filterUser' => $filterUser, |
|
104 | - 'filterTask' => $filterTask, |
|
105 | - 'filterStatus' => $filterStatus, |
|
106 | - 'filterRequest' => $filterRequest, |
|
107 | - )); |
|
102 | + $this->setupPageData($count, array( |
|
103 | + 'filterUser' => $filterUser, |
|
104 | + 'filterTask' => $filterTask, |
|
105 | + 'filterStatus' => $filterStatus, |
|
106 | + 'filterRequest' => $filterRequest, |
|
107 | + )); |
|
108 | 108 | |
109 | - $userIds = array(); |
|
110 | - $requestIds = array(); |
|
109 | + $userIds = array(); |
|
110 | + $requestIds = array(); |
|
111 | 111 | |
112 | - foreach ($jobList as $job) { |
|
113 | - $userIds[] = $job->getTriggerUserId(); |
|
114 | - $requestIds[] = $job->getRequest(); |
|
112 | + foreach ($jobList as $job) { |
|
113 | + $userIds[] = $job->getTriggerUserId(); |
|
114 | + $requestIds[] = $job->getRequest(); |
|
115 | 115 | |
116 | - $job->setDatabase($database); |
|
117 | - } |
|
116 | + $job->setDatabase($database); |
|
117 | + } |
|
118 | 118 | |
119 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
120 | - return UserSearchHelper::get($database)->fetchColumn('username'); |
|
121 | - }); |
|
119 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
120 | + return UserSearchHelper::get($database)->fetchColumn('username'); |
|
121 | + }); |
|
122 | 122 | |
123 | - $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
124 | - $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name')); |
|
123 | + $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
124 | + $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name')); |
|
125 | 125 | |
126 | - $this->assign('joblist', $jobList); |
|
126 | + $this->assign('joblist', $jobList); |
|
127 | 127 | |
128 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
128 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
129 | 129 | |
130 | - $this->setTemplate('jobqueue/all.tpl'); |
|
131 | - } |
|
130 | + $this->setTemplate('jobqueue/all.tpl'); |
|
131 | + } |
|
132 | 132 | |
133 | - protected function view() |
|
134 | - { |
|
135 | - $jobId = WebRequest::getInt('id'); |
|
136 | - $database = $this->getDatabase(); |
|
133 | + protected function view() |
|
134 | + { |
|
135 | + $jobId = WebRequest::getInt('id'); |
|
136 | + $database = $this->getDatabase(); |
|
137 | 137 | |
138 | - if ($jobId === null) { |
|
139 | - throw new ApplicationLogicException('No job specified'); |
|
140 | - } |
|
138 | + if ($jobId === null) { |
|
139 | + throw new ApplicationLogicException('No job specified'); |
|
140 | + } |
|
141 | 141 | |
142 | - /** @var JobQueue $job */ |
|
143 | - $job = JobQueue::getById($jobId, $database); |
|
142 | + /** @var JobQueue $job */ |
|
143 | + $job = JobQueue::getById($jobId, $database); |
|
144 | 144 | |
145 | - if ($job === false) { |
|
146 | - throw new ApplicationLogicException('Could not find requested job'); |
|
147 | - } |
|
145 | + if ($job === false) { |
|
146 | + throw new ApplicationLogicException('Could not find requested job'); |
|
147 | + } |
|
148 | 148 | |
149 | - $this->prepareMaps(); |
|
149 | + $this->prepareMaps(); |
|
150 | 150 | |
151 | - $this->assign('user', User::getById($job->getTriggerUserId(), $database)); |
|
152 | - $this->assign('request', Request::getById($job->getRequest(), $database)); |
|
153 | - $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database)); |
|
154 | - $this->assign('parent', JobQueue::getById($job->getParent(), $database)); |
|
151 | + $this->assign('user', User::getById($job->getTriggerUserId(), $database)); |
|
152 | + $this->assign('request', Request::getById($job->getRequest(), $database)); |
|
153 | + $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database)); |
|
154 | + $this->assign('parent', JobQueue::getById($job->getParent(), $database)); |
|
155 | 155 | |
156 | - /** @var Log[] $logs */ |
|
157 | - $logs = LogSearchHelper::get($database)->byObjectType('JobQueue') |
|
158 | - ->byObjectId($job->getId())->getRecordCount($logCount)->fetch(); |
|
159 | - if ($logCount === 0) { |
|
160 | - $this->assign('log', array()); |
|
161 | - } |
|
162 | - else { |
|
163 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
156 | + /** @var Log[] $logs */ |
|
157 | + $logs = LogSearchHelper::get($database)->byObjectType('JobQueue') |
|
158 | + ->byObjectId($job->getId())->getRecordCount($logCount)->fetch(); |
|
159 | + if ($logCount === 0) { |
|
160 | + $this->assign('log', array()); |
|
161 | + } |
|
162 | + else { |
|
163 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
164 | 164 | |
165 | - $this->assign("log", $logData); |
|
166 | - $this->assign("users", $users); |
|
167 | - } |
|
165 | + $this->assign("log", $logData); |
|
166 | + $this->assign("users", $users); |
|
167 | + } |
|
168 | 168 | |
169 | - $this->assignCSRFToken(); |
|
169 | + $this->assignCSRFToken(); |
|
170 | 170 | |
171 | - $this->assign('job', $job); |
|
171 | + $this->assign('job', $job); |
|
172 | 172 | |
173 | - $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database))); |
|
174 | - $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database))); |
|
173 | + $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database))); |
|
174 | + $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database))); |
|
175 | 175 | |
176 | - $this->setHtmlTitle('Job #{$job->getId()|escape}'); |
|
177 | - $this->setTemplate('jobqueue/view.tpl'); |
|
178 | - } |
|
176 | + $this->setHtmlTitle('Job #{$job->getId()|escape}'); |
|
177 | + $this->setTemplate('jobqueue/view.tpl'); |
|
178 | + } |
|
179 | 179 | |
180 | - protected function acknowledge() |
|
181 | - { |
|
182 | - if (!WebRequest::wasPosted()) { |
|
183 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
184 | - } |
|
180 | + protected function acknowledge() |
|
181 | + { |
|
182 | + if (!WebRequest::wasPosted()) { |
|
183 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
184 | + } |
|
185 | 185 | |
186 | - $this->validateCSRFToken(); |
|
186 | + $this->validateCSRFToken(); |
|
187 | 187 | |
188 | - $jobId = WebRequest::postInt('job'); |
|
189 | - $database = $this->getDatabase(); |
|
188 | + $jobId = WebRequest::postInt('job'); |
|
189 | + $database = $this->getDatabase(); |
|
190 | 190 | |
191 | - if ($jobId === null) { |
|
192 | - throw new ApplicationLogicException('No job specified'); |
|
193 | - } |
|
191 | + if ($jobId === null) { |
|
192 | + throw new ApplicationLogicException('No job specified'); |
|
193 | + } |
|
194 | 194 | |
195 | - /** @var JobQueue $job */ |
|
196 | - $job = JobQueue::getById($jobId, $database); |
|
195 | + /** @var JobQueue $job */ |
|
196 | + $job = JobQueue::getById($jobId, $database); |
|
197 | 197 | |
198 | - if ($job === false) { |
|
199 | - throw new ApplicationLogicException('Could not find requested job'); |
|
200 | - } |
|
198 | + if ($job === false) { |
|
199 | + throw new ApplicationLogicException('Could not find requested job'); |
|
200 | + } |
|
201 | 201 | |
202 | - $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
203 | - $job->setAcknowledged(true); |
|
204 | - $job->save(); |
|
202 | + $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
203 | + $job->setAcknowledged(true); |
|
204 | + $job->save(); |
|
205 | 205 | |
206 | - Logger::backgroundJobAcknowledged($database, $job); |
|
206 | + Logger::backgroundJobAcknowledged($database, $job); |
|
207 | 207 | |
208 | - $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
209 | - } |
|
208 | + $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
209 | + } |
|
210 | 210 | |
211 | - protected function requeue() |
|
212 | - { |
|
213 | - if (!WebRequest::wasPosted()) { |
|
214 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
215 | - } |
|
211 | + protected function requeue() |
|
212 | + { |
|
213 | + if (!WebRequest::wasPosted()) { |
|
214 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
215 | + } |
|
216 | 216 | |
217 | - $this->validateCSRFToken(); |
|
217 | + $this->validateCSRFToken(); |
|
218 | 218 | |
219 | - $jobId = WebRequest::postInt('job'); |
|
220 | - $database = $this->getDatabase(); |
|
219 | + $jobId = WebRequest::postInt('job'); |
|
220 | + $database = $this->getDatabase(); |
|
221 | 221 | |
222 | - if ($jobId === null) { |
|
223 | - throw new ApplicationLogicException('No job specified'); |
|
224 | - } |
|
222 | + if ($jobId === null) { |
|
223 | + throw new ApplicationLogicException('No job specified'); |
|
224 | + } |
|
225 | 225 | |
226 | - /** @var JobQueue $job */ |
|
227 | - $job = JobQueue::getById($jobId, $database); |
|
226 | + /** @var JobQueue $job */ |
|
227 | + $job = JobQueue::getById($jobId, $database); |
|
228 | 228 | |
229 | - if ($job === false) { |
|
230 | - throw new ApplicationLogicException('Could not find requested job'); |
|
231 | - } |
|
229 | + if ($job === false) { |
|
230 | + throw new ApplicationLogicException('Could not find requested job'); |
|
231 | + } |
|
232 | 232 | |
233 | - $job->setStatus(JobQueue::STATUS_READY); |
|
234 | - $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
235 | - $job->setAcknowledged(null); |
|
236 | - $job->setError(null); |
|
237 | - $job->save(); |
|
238 | - |
|
239 | - /** @var Request $request */ |
|
240 | - $request = Request::getById($job->getRequest(), $database); |
|
241 | - $request->setStatus(RequestStatus::JOBQUEUE); |
|
242 | - $request->save(); |
|
233 | + $job->setStatus(JobQueue::STATUS_READY); |
|
234 | + $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
235 | + $job->setAcknowledged(null); |
|
236 | + $job->setError(null); |
|
237 | + $job->save(); |
|
238 | + |
|
239 | + /** @var Request $request */ |
|
240 | + $request = Request::getById($job->getRequest(), $database); |
|
241 | + $request->setStatus(RequestStatus::JOBQUEUE); |
|
242 | + $request->save(); |
|
243 | 243 | |
244 | - Logger::enqueuedJobQueue($database, $request); |
|
245 | - Logger::backgroundJobRequeued($database, $job); |
|
246 | - |
|
247 | - $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
248 | - } |
|
249 | - |
|
250 | - protected function prepareMaps() |
|
251 | - { |
|
252 | - $taskNameMap = JobQueue::getTaskDescriptions(); |
|
253 | - |
|
254 | - $statusDecriptionMap = array( |
|
255 | - JobQueue::STATUS_CANCELLED => 'The job was cancelled', |
|
256 | - JobQueue::STATUS_COMPLETE => 'The job completed successfully', |
|
257 | - JobQueue::STATUS_FAILED => 'The job encountered an error', |
|
258 | - JobQueue::STATUS_READY => 'The job is ready to be picked up by the next job runner execution', |
|
259 | - JobQueue::STATUS_RUNNING => 'The job is being run right now by the job runner', |
|
260 | - JobQueue::STATUS_WAITING => 'The job has been picked up by a job runner', |
|
261 | - JobQueue::STATUS_HELD => 'The job has manually held from processing', |
|
262 | - ); |
|
263 | - $this->assign('taskNameMap', $taskNameMap); |
|
264 | - $this->assign('statusDescriptionMap', $statusDecriptionMap); |
|
265 | - } |
|
244 | + Logger::enqueuedJobQueue($database, $request); |
|
245 | + Logger::backgroundJobRequeued($database, $job); |
|
246 | + |
|
247 | + $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
248 | + } |
|
249 | + |
|
250 | + protected function prepareMaps() |
|
251 | + { |
|
252 | + $taskNameMap = JobQueue::getTaskDescriptions(); |
|
253 | + |
|
254 | + $statusDecriptionMap = array( |
|
255 | + JobQueue::STATUS_CANCELLED => 'The job was cancelled', |
|
256 | + JobQueue::STATUS_COMPLETE => 'The job completed successfully', |
|
257 | + JobQueue::STATUS_FAILED => 'The job encountered an error', |
|
258 | + JobQueue::STATUS_READY => 'The job is ready to be picked up by the next job runner execution', |
|
259 | + JobQueue::STATUS_RUNNING => 'The job is being run right now by the job runner', |
|
260 | + JobQueue::STATUS_WAITING => 'The job has been picked up by a job runner', |
|
261 | + JobQueue::STATUS_HELD => 'The job has manually held from processing', |
|
262 | + ); |
|
263 | + $this->assign('taskNameMap', $taskNameMap); |
|
264 | + $this->assign('statusDescriptionMap', $statusDecriptionMap); |
|
265 | + } |
|
266 | 266 | } |
@@ -16,167 +16,167 @@ |
||
16 | 16 | */ |
17 | 17 | class CommunityUser extends User |
18 | 18 | { |
19 | - public function getId() |
|
20 | - { |
|
21 | - return -1; |
|
22 | - } |
|
23 | - |
|
24 | - public function save() |
|
25 | - { |
|
26 | - // Do nothing |
|
27 | - } |
|
28 | - |
|
29 | - #region properties |
|
30 | - |
|
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getUsername() |
|
35 | - { |
|
36 | - global $communityUsername; |
|
37 | - |
|
38 | - return $communityUsername; |
|
39 | - } |
|
40 | - |
|
41 | - public function setUsername($username) |
|
42 | - { |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getEmail() |
|
49 | - { |
|
50 | - global $cDataClearEmail; |
|
51 | - |
|
52 | - return $cDataClearEmail; |
|
53 | - } |
|
54 | - |
|
55 | - public function setEmail($email) |
|
56 | - { |
|
57 | - } |
|
58 | - |
|
59 | - public function getStatus() |
|
60 | - { |
|
61 | - return "Community"; |
|
62 | - } |
|
63 | - |
|
64 | - public function getOnWikiName() |
|
65 | - { |
|
66 | - return "127.0.0.1"; |
|
67 | - } |
|
68 | - |
|
69 | - public function setOnWikiName($onWikiName) |
|
70 | - { |
|
71 | - } |
|
72 | - |
|
73 | - public function getWelcomeSig() |
|
74 | - { |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - public function setWelcomeSig($welcomeSig) |
|
79 | - { |
|
80 | - } |
|
81 | - |
|
82 | - public function getLastActive() |
|
83 | - { |
|
84 | - $now = new DateTime(); |
|
85 | - |
|
86 | - return $now->format("Y-m-d H:i:s"); |
|
87 | - } |
|
88 | - |
|
89 | - public function getForceLogout() |
|
90 | - { |
|
91 | - return true; |
|
92 | - } |
|
93 | - |
|
94 | - public function setForceLogout($forceLogout) |
|
95 | - { |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $status |
|
100 | - */ |
|
101 | - public function setStatus($status) |
|
102 | - { |
|
103 | - } |
|
104 | - |
|
105 | - public function getWelcomeTemplate() |
|
106 | - { |
|
107 | - return 0; |
|
108 | - } |
|
109 | - |
|
110 | - public function setWelcomeTemplate($welcomeTemplate) |
|
111 | - { |
|
112 | - } |
|
113 | - |
|
114 | - public function getAbortPref() |
|
115 | - { |
|
116 | - return 0; |
|
117 | - } |
|
118 | - |
|
119 | - public function setAbortPref($abortPreference) |
|
120 | - { |
|
121 | - } |
|
122 | - |
|
123 | - public function getConfirmationDiff() |
|
124 | - { |
|
125 | - return null; |
|
126 | - } |
|
127 | - |
|
128 | - public function setConfirmationDiff($confirmationDiff) |
|
129 | - { |
|
130 | - } |
|
131 | - |
|
132 | - public function getEmailSig() |
|
133 | - { |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - public function setEmailSig($emailSignature) |
|
138 | - { |
|
139 | - } |
|
140 | - |
|
141 | - public function setUseAlternateSkin($useAlternate) |
|
142 | - { |
|
143 | - } |
|
144 | - |
|
145 | - #endregion |
|
146 | - |
|
147 | - #region user access checks |
|
148 | - |
|
149 | - public function isIdentified(IdentificationVerifier $iv) |
|
150 | - { |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - public function isSuspended() |
|
155 | - { |
|
156 | - return false; |
|
157 | - } |
|
158 | - |
|
159 | - public function isNewUser() |
|
160 | - { |
|
161 | - return false; |
|
162 | - } |
|
163 | - |
|
164 | - public function isDeclined() |
|
165 | - { |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - public function isCommunityUser() |
|
170 | - { |
|
171 | - return true; |
|
172 | - } |
|
173 | - |
|
174 | - #endregion |
|
175 | - |
|
176 | - public function getApprovalDate() |
|
177 | - { |
|
178 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00"); |
|
179 | - |
|
180 | - return $data; |
|
181 | - } |
|
19 | + public function getId() |
|
20 | + { |
|
21 | + return -1; |
|
22 | + } |
|
23 | + |
|
24 | + public function save() |
|
25 | + { |
|
26 | + // Do nothing |
|
27 | + } |
|
28 | + |
|
29 | + #region properties |
|
30 | + |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getUsername() |
|
35 | + { |
|
36 | + global $communityUsername; |
|
37 | + |
|
38 | + return $communityUsername; |
|
39 | + } |
|
40 | + |
|
41 | + public function setUsername($username) |
|
42 | + { |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getEmail() |
|
49 | + { |
|
50 | + global $cDataClearEmail; |
|
51 | + |
|
52 | + return $cDataClearEmail; |
|
53 | + } |
|
54 | + |
|
55 | + public function setEmail($email) |
|
56 | + { |
|
57 | + } |
|
58 | + |
|
59 | + public function getStatus() |
|
60 | + { |
|
61 | + return "Community"; |
|
62 | + } |
|
63 | + |
|
64 | + public function getOnWikiName() |
|
65 | + { |
|
66 | + return "127.0.0.1"; |
|
67 | + } |
|
68 | + |
|
69 | + public function setOnWikiName($onWikiName) |
|
70 | + { |
|
71 | + } |
|
72 | + |
|
73 | + public function getWelcomeSig() |
|
74 | + { |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + public function setWelcomeSig($welcomeSig) |
|
79 | + { |
|
80 | + } |
|
81 | + |
|
82 | + public function getLastActive() |
|
83 | + { |
|
84 | + $now = new DateTime(); |
|
85 | + |
|
86 | + return $now->format("Y-m-d H:i:s"); |
|
87 | + } |
|
88 | + |
|
89 | + public function getForceLogout() |
|
90 | + { |
|
91 | + return true; |
|
92 | + } |
|
93 | + |
|
94 | + public function setForceLogout($forceLogout) |
|
95 | + { |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $status |
|
100 | + */ |
|
101 | + public function setStatus($status) |
|
102 | + { |
|
103 | + } |
|
104 | + |
|
105 | + public function getWelcomeTemplate() |
|
106 | + { |
|
107 | + return 0; |
|
108 | + } |
|
109 | + |
|
110 | + public function setWelcomeTemplate($welcomeTemplate) |
|
111 | + { |
|
112 | + } |
|
113 | + |
|
114 | + public function getAbortPref() |
|
115 | + { |
|
116 | + return 0; |
|
117 | + } |
|
118 | + |
|
119 | + public function setAbortPref($abortPreference) |
|
120 | + { |
|
121 | + } |
|
122 | + |
|
123 | + public function getConfirmationDiff() |
|
124 | + { |
|
125 | + return null; |
|
126 | + } |
|
127 | + |
|
128 | + public function setConfirmationDiff($confirmationDiff) |
|
129 | + { |
|
130 | + } |
|
131 | + |
|
132 | + public function getEmailSig() |
|
133 | + { |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + public function setEmailSig($emailSignature) |
|
138 | + { |
|
139 | + } |
|
140 | + |
|
141 | + public function setUseAlternateSkin($useAlternate) |
|
142 | + { |
|
143 | + } |
|
144 | + |
|
145 | + #endregion |
|
146 | + |
|
147 | + #region user access checks |
|
148 | + |
|
149 | + public function isIdentified(IdentificationVerifier $iv) |
|
150 | + { |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + public function isSuspended() |
|
155 | + { |
|
156 | + return false; |
|
157 | + } |
|
158 | + |
|
159 | + public function isNewUser() |
|
160 | + { |
|
161 | + return false; |
|
162 | + } |
|
163 | + |
|
164 | + public function isDeclined() |
|
165 | + { |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + public function isCommunityUser() |
|
170 | + { |
|
171 | + return true; |
|
172 | + } |
|
173 | + |
|
174 | + #endregion |
|
175 | + |
|
176 | + public function getApprovalDate() |
|
177 | + { |
|
178 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00"); |
|
179 | + |
|
180 | + return $data; |
|
181 | + } |
|
182 | 182 | } |
@@ -15,26 +15,26 @@ |
||
15 | 15 | |
16 | 16 | class RegenerateStylesheetsTask extends ConsoleTaskBase |
17 | 17 | { |
18 | - const RESOURCES_GENERATED = 'resources/generated'; |
|
18 | + const RESOURCES_GENERATED = 'resources/generated'; |
|
19 | 19 | |
20 | - public function execute() |
|
21 | - { |
|
22 | - $scss = new Compiler(); |
|
23 | - $scss->setImportPaths('resources/scss'); |
|
20 | + public function execute() |
|
21 | + { |
|
22 | + $scss = new Compiler(); |
|
23 | + $scss->setImportPaths('resources/scss'); |
|
24 | 24 | |
25 | - if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
26 | - $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
27 | - $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
28 | - } |
|
25 | + if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
26 | + $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
27 | + $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
28 | + } |
|
29 | 29 | |
30 | - if (!is_dir(self::RESOURCES_GENERATED)) { |
|
31 | - mkdir(self::RESOURCES_GENERATED); |
|
32 | - } |
|
30 | + if (!is_dir(self::RESOURCES_GENERATED)) { |
|
31 | + mkdir(self::RESOURCES_GENERATED); |
|
32 | + } |
|
33 | 33 | |
34 | - foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
|
35 | - file_put_contents( |
|
36 | - self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
37 | - $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
38 | - } |
|
39 | - } |
|
34 | + foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
|
35 | + file_put_contents( |
|
36 | + self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
37 | + $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | } |
@@ -33,8 +33,8 @@ |
||
33 | 33 | |
34 | 34 | foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
35 | 35 | file_put_contents( |
36 | - self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
37 | - $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
36 | + self::RESOURCES_GENERATED.'/'.$file.'.css', |
|
37 | + $scss->compile('/*! Do not edit this auto-generated file! */ @import "'.$file.'";')); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | } |
@@ -62,15 +62,15 @@ |
||
62 | 62 | |
63 | 63 | $usedToken = null; |
64 | 64 | foreach ($scratchTokens as $scratchToken) { |
65 | - if (password_verify($data, $scratchToken)){ |
|
65 | + if (password_verify($data, $scratchToken)) { |
|
66 | 66 | $usedToken = $scratchToken; |
67 | 67 | SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
68 | - WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
|
68 | + WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl()."/internal.php/multiFactor"); |
|
69 | 69 | break; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - if($usedToken === null) { |
|
73 | + if ($usedToken === null) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 |
@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | $usedToken = null; |
64 | 64 | foreach ($scratchTokens as $scratchToken) { |
65 | - if (password_verify($data, $scratchToken)){ |
|
65 | + if (password_verify($data, $scratchToken)) { |
|
66 | 66 | $usedToken = $scratchToken; |
67 | 67 | SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
68 | 68 | WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
@@ -20,136 +20,136 @@ |
||
20 | 20 | |
21 | 21 | class ScratchTokenCredentialProvider extends CredentialProviderBase |
22 | 22 | { |
23 | - /** @var EncryptionHelper */ |
|
24 | - private $encryptionHelper; |
|
25 | - /** @var array the tokens generated in the last generation round. */ |
|
26 | - private $generatedTokens; |
|
27 | - |
|
28 | - /** |
|
29 | - * ScratchTokenCredentialProvider constructor. |
|
30 | - * |
|
31 | - * @param PdoDatabase $database |
|
32 | - * @param SiteConfiguration $configuration |
|
33 | - */ |
|
34 | - public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
35 | - { |
|
36 | - parent::__construct($database, $configuration, 'scratch'); |
|
37 | - $this->encryptionHelper = new EncryptionHelper($configuration); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Validates a user-provided credential |
|
42 | - * |
|
43 | - * @param User $user The user to test the authentication against |
|
44 | - * @param string $data The raw credential data to be validated |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - * @throws ApplicationLogicException|OptimisticLockFailedException |
|
48 | - */ |
|
49 | - public function authenticate(User $user, $data) |
|
50 | - { |
|
51 | - if (is_array($data)) { |
|
52 | - return false; |
|
53 | - } |
|
54 | - |
|
55 | - $storedData = $this->getCredentialData($user->getId()); |
|
56 | - |
|
57 | - if ($storedData === null) { |
|
58 | - throw new ApplicationLogicException('Credential data not found'); |
|
59 | - } |
|
60 | - |
|
61 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
62 | - |
|
63 | - $usedToken = null; |
|
64 | - foreach ($scratchTokens as $scratchToken) { |
|
65 | - if (password_verify($data, $scratchToken)){ |
|
66 | - $usedToken = $scratchToken; |
|
67 | - SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
|
68 | - WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
|
69 | - break; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if($usedToken === null) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - |
|
77 | - $scratchTokens = array_diff($scratchTokens, [$usedToken]); |
|
78 | - |
|
79 | - $storedData->setData($this->encryptionHelper->encryptData(serialize($scratchTokens))); |
|
80 | - $storedData->save(); |
|
81 | - |
|
82 | - return true; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param User $user The user the credential belongs to |
|
87 | - * @param int $factor The factor this credential provides |
|
88 | - * @param string $data Unused. |
|
89 | - * |
|
90 | - * @throws OptimisticLockFailedException |
|
91 | - */ |
|
92 | - public function setCredential(User $user, $factor, $data) |
|
93 | - { |
|
94 | - $plaintextScratch = array(); |
|
95 | - $storedScratch = array(); |
|
96 | - for ($i = 0; $i < 5; $i++) { |
|
97 | - $token = Base32::encodeUpper(openssl_random_pseudo_bytes(10)); |
|
98 | - $plaintextScratch[] = $token; |
|
99 | - |
|
100 | - $storedScratch[] = password_hash( |
|
101 | - $token, |
|
102 | - PasswordCredentialProvider::PASSWORD_ALGO, |
|
103 | - array('cost' => PasswordCredentialProvider::PASSWORD_COST) |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - $storedData = $this->getCredentialData($user->getId(), null); |
|
108 | - |
|
109 | - if ($storedData !== null) { |
|
110 | - $storedData->delete(); |
|
111 | - } |
|
112 | - |
|
113 | - $storedData = $this->createNewCredential($user); |
|
114 | - |
|
115 | - $storedData->setData($this->encryptionHelper->encryptData(serialize($storedScratch))); |
|
116 | - $storedData->setFactor($factor); |
|
117 | - $storedData->setVersion(1); |
|
118 | - $storedData->setPriority(9); |
|
119 | - |
|
120 | - $storedData->save(); |
|
121 | - $this->generatedTokens = $plaintextScratch; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Gets the count of remaining valid tokens |
|
126 | - * |
|
127 | - * @param int $userId |
|
128 | - * |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function getRemaining($userId) |
|
132 | - { |
|
133 | - $storedData = $this->getCredentialData($userId); |
|
134 | - |
|
135 | - if ($storedData === null) { |
|
136 | - return 0; |
|
137 | - } |
|
138 | - |
|
139 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
140 | - |
|
141 | - return count($scratchTokens); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - public function getTokens() |
|
148 | - { |
|
149 | - if ($this->generatedTokens != null) { |
|
150 | - return $this->generatedTokens; |
|
151 | - } |
|
152 | - |
|
153 | - return array(); |
|
154 | - } |
|
23 | + /** @var EncryptionHelper */ |
|
24 | + private $encryptionHelper; |
|
25 | + /** @var array the tokens generated in the last generation round. */ |
|
26 | + private $generatedTokens; |
|
27 | + |
|
28 | + /** |
|
29 | + * ScratchTokenCredentialProvider constructor. |
|
30 | + * |
|
31 | + * @param PdoDatabase $database |
|
32 | + * @param SiteConfiguration $configuration |
|
33 | + */ |
|
34 | + public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
35 | + { |
|
36 | + parent::__construct($database, $configuration, 'scratch'); |
|
37 | + $this->encryptionHelper = new EncryptionHelper($configuration); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Validates a user-provided credential |
|
42 | + * |
|
43 | + * @param User $user The user to test the authentication against |
|
44 | + * @param string $data The raw credential data to be validated |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + * @throws ApplicationLogicException|OptimisticLockFailedException |
|
48 | + */ |
|
49 | + public function authenticate(User $user, $data) |
|
50 | + { |
|
51 | + if (is_array($data)) { |
|
52 | + return false; |
|
53 | + } |
|
54 | + |
|
55 | + $storedData = $this->getCredentialData($user->getId()); |
|
56 | + |
|
57 | + if ($storedData === null) { |
|
58 | + throw new ApplicationLogicException('Credential data not found'); |
|
59 | + } |
|
60 | + |
|
61 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
62 | + |
|
63 | + $usedToken = null; |
|
64 | + foreach ($scratchTokens as $scratchToken) { |
|
65 | + if (password_verify($data, $scratchToken)){ |
|
66 | + $usedToken = $scratchToken; |
|
67 | + SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
|
68 | + WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
|
69 | + break; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if($usedToken === null) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + |
|
77 | + $scratchTokens = array_diff($scratchTokens, [$usedToken]); |
|
78 | + |
|
79 | + $storedData->setData($this->encryptionHelper->encryptData(serialize($scratchTokens))); |
|
80 | + $storedData->save(); |
|
81 | + |
|
82 | + return true; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param User $user The user the credential belongs to |
|
87 | + * @param int $factor The factor this credential provides |
|
88 | + * @param string $data Unused. |
|
89 | + * |
|
90 | + * @throws OptimisticLockFailedException |
|
91 | + */ |
|
92 | + public function setCredential(User $user, $factor, $data) |
|
93 | + { |
|
94 | + $plaintextScratch = array(); |
|
95 | + $storedScratch = array(); |
|
96 | + for ($i = 0; $i < 5; $i++) { |
|
97 | + $token = Base32::encodeUpper(openssl_random_pseudo_bytes(10)); |
|
98 | + $plaintextScratch[] = $token; |
|
99 | + |
|
100 | + $storedScratch[] = password_hash( |
|
101 | + $token, |
|
102 | + PasswordCredentialProvider::PASSWORD_ALGO, |
|
103 | + array('cost' => PasswordCredentialProvider::PASSWORD_COST) |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + $storedData = $this->getCredentialData($user->getId(), null); |
|
108 | + |
|
109 | + if ($storedData !== null) { |
|
110 | + $storedData->delete(); |
|
111 | + } |
|
112 | + |
|
113 | + $storedData = $this->createNewCredential($user); |
|
114 | + |
|
115 | + $storedData->setData($this->encryptionHelper->encryptData(serialize($storedScratch))); |
|
116 | + $storedData->setFactor($factor); |
|
117 | + $storedData->setVersion(1); |
|
118 | + $storedData->setPriority(9); |
|
119 | + |
|
120 | + $storedData->save(); |
|
121 | + $this->generatedTokens = $plaintextScratch; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Gets the count of remaining valid tokens |
|
126 | + * |
|
127 | + * @param int $userId |
|
128 | + * |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function getRemaining($userId) |
|
132 | + { |
|
133 | + $storedData = $this->getCredentialData($userId); |
|
134 | + |
|
135 | + if ($storedData === null) { |
|
136 | + return 0; |
|
137 | + } |
|
138 | + |
|
139 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
140 | + |
|
141 | + return count($scratchTokens); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + public function getTokens() |
|
148 | + { |
|
149 | + if ($this->generatedTokens != null) { |
|
150 | + return $this->generatedTokens; |
|
151 | + } |
|
152 | + |
|
153 | + return array(); |
|
154 | + } |
|
155 | 155 | } |
@@ -22,567 +22,567 @@ |
||
22 | 22 | */ |
23 | 23 | class WebRequest |
24 | 24 | { |
25 | - /** |
|
26 | - * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | - */ |
|
28 | - private static $globalStateProvider; |
|
29 | - |
|
30 | - /** |
|
31 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function wasPosted() |
|
35 | - { |
|
36 | - return self::method() === 'POST'; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the HTTP Method used |
|
41 | - * @return string|null |
|
42 | - */ |
|
43 | - public static function method() |
|
44 | - { |
|
45 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | - |
|
47 | - if (isset($server['REQUEST_METHOD'])) { |
|
48 | - return $server['REQUEST_METHOD']; |
|
49 | - } |
|
50 | - |
|
51 | - return null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public static function isHttps() |
|
59 | - { |
|
60 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | - |
|
62 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | - // Client <=> Proxy is encrypted |
|
65 | - return true; |
|
66 | - } |
|
67 | - else { |
|
68 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | - return false; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($server['HTTPS'])) { |
|
74 | - if ($server['HTTPS'] === 'off') { |
|
75 | - // ISAPI on IIS breaks the spec. :( |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - if ($server['HTTPS'] !== '') { |
|
80 | - // Set to a non-empty value |
|
81 | - return true; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return false; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the path info |
|
90 | - * |
|
91 | - * @return array Array of path info segments |
|
92 | - */ |
|
93 | - public static function pathInfo() |
|
94 | - { |
|
95 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | - if (!isset($server['PATH_INFO'])) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $exploded = explode('/', $server['PATH_INFO']); |
|
101 | - |
|
102 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | - // with a / |
|
104 | - return array_values(array_filter($exploded)); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Gets the remote address of the web request |
|
109 | - * @return null|string |
|
110 | - */ |
|
111 | - public static function remoteAddress() |
|
112 | - { |
|
113 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | - |
|
115 | - if (isset($server['REMOTE_ADDR'])) { |
|
116 | - return $server['REMOTE_ADDR']; |
|
117 | - } |
|
118 | - |
|
119 | - return null; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets the remote address of the web request |
|
124 | - * @return null|string |
|
125 | - */ |
|
126 | - public static function httpHost() |
|
127 | - { |
|
128 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | - |
|
130 | - if (isset($server['HTTP_HOST'])) { |
|
131 | - return $server['HTTP_HOST']; |
|
132 | - } |
|
133 | - |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Gets the XFF header contents for the web request |
|
139 | - * @return null|string |
|
140 | - */ |
|
141 | - public static function forwardedAddress() |
|
142 | - { |
|
143 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
144 | - |
|
145 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
146 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
147 | - } |
|
148 | - |
|
149 | - return null; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets the global state provider. |
|
154 | - * |
|
155 | - * Almost guaranteed this is not the method you want in production code. |
|
156 | - * |
|
157 | - * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
158 | - */ |
|
159 | - public static function setGlobalStateProvider($globalState) |
|
160 | - { |
|
161 | - self::$globalStateProvider = $globalState; |
|
162 | - } |
|
163 | - |
|
164 | - #region POST variables |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $key |
|
168 | - * |
|
169 | - * @return null|string |
|
170 | - */ |
|
171 | - public static function postString($key) |
|
172 | - { |
|
173 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
174 | - if (!array_key_exists($key, $post)) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - |
|
178 | - if ($post[$key] === "") { |
|
179 | - return null; |
|
180 | - } |
|
181 | - |
|
182 | - return (string)$post[$key]; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $key |
|
187 | - * |
|
188 | - * @return null|string |
|
189 | - */ |
|
190 | - public static function postEmail($key) |
|
191 | - { |
|
192 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
193 | - if (!array_key_exists($key, $post)) { |
|
194 | - return null; |
|
195 | - } |
|
196 | - |
|
197 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
198 | - |
|
199 | - if ($filteredValue === false) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - |
|
203 | - return (string)$filteredValue; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string $key |
|
208 | - * |
|
209 | - * @return int|null |
|
210 | - */ |
|
211 | - public static function postInt($key) |
|
212 | - { |
|
213 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
214 | - if (!array_key_exists($key, $post)) { |
|
215 | - return null; |
|
216 | - } |
|
217 | - |
|
218 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
219 | - |
|
220 | - if ($filteredValue === null) { |
|
221 | - return null; |
|
222 | - } |
|
223 | - |
|
224 | - return (int)$filteredValue; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $key |
|
229 | - * |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public static function postBoolean($key) |
|
233 | - { |
|
234 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
235 | - if (!array_key_exists($key, $get)) { |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - // presence of parameter only |
|
240 | - if ($get[$key] === "") { |
|
241 | - return true; |
|
242 | - } |
|
243 | - |
|
244 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - return true; |
|
249 | - } |
|
250 | - |
|
251 | - #endregion |
|
252 | - |
|
253 | - #region GET variables |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $key |
|
257 | - * |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public static function getBoolean($key) |
|
261 | - { |
|
262 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
263 | - if (!array_key_exists($key, $get)) { |
|
264 | - return false; |
|
265 | - } |
|
266 | - |
|
267 | - // presence of parameter only |
|
268 | - if ($get[$key] === "") { |
|
269 | - return true; |
|
270 | - } |
|
271 | - |
|
272 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - return true; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @param string $key |
|
281 | - * |
|
282 | - * @return int|null |
|
283 | - */ |
|
284 | - public static function getInt($key) |
|
285 | - { |
|
286 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
287 | - if (!array_key_exists($key, $get)) { |
|
288 | - return null; |
|
289 | - } |
|
290 | - |
|
291 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
292 | - |
|
293 | - if ($filteredValue === null) { |
|
294 | - return null; |
|
295 | - } |
|
296 | - |
|
297 | - return (int)$filteredValue; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @param string $key |
|
302 | - * |
|
303 | - * @return null|string |
|
304 | - */ |
|
305 | - public static function getString($key) |
|
306 | - { |
|
307 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
308 | - if (!array_key_exists($key, $get)) { |
|
309 | - return null; |
|
310 | - } |
|
311 | - |
|
312 | - if ($get[$key] === "") { |
|
313 | - return null; |
|
314 | - } |
|
315 | - |
|
316 | - return (string)$get[$key]; |
|
317 | - } |
|
318 | - |
|
319 | - #endregion |
|
320 | - |
|
321 | - /** |
|
322 | - * Sets the logged-in user to the specified user. |
|
323 | - * |
|
324 | - * @param User $user |
|
325 | - */ |
|
326 | - public static function setLoggedInUser(User $user) |
|
327 | - { |
|
328 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
329 | - |
|
330 | - $session['userID'] = $user->getId(); |
|
331 | - unset($session['partialLogin']); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sets the post-login redirect |
|
336 | - * |
|
337 | - * @param string|null $uri The URI to redirect to |
|
338 | - */ |
|
339 | - public static function setPostLoginRedirect($uri = null) |
|
340 | - { |
|
341 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
342 | - |
|
343 | - if ($uri === null) { |
|
344 | - $uri = self::requestUri(); |
|
345 | - } |
|
346 | - |
|
347 | - $session['returnTo'] = $uri; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * @return string|null |
|
352 | - */ |
|
353 | - public static function requestUri() |
|
354 | - { |
|
355 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
356 | - |
|
357 | - if (isset($server['REQUEST_URI'])) { |
|
358 | - return $server['REQUEST_URI']; |
|
359 | - } |
|
360 | - |
|
361 | - return null; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Clears the post-login redirect |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public static function clearPostLoginRedirect() |
|
369 | - { |
|
370 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
371 | - if (array_key_exists('returnTo', $session)) { |
|
372 | - $path = $session['returnTo']; |
|
373 | - unset($session['returnTo']); |
|
374 | - |
|
375 | - return $path; |
|
376 | - } |
|
377 | - |
|
378 | - return null; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * @return string|null |
|
383 | - */ |
|
384 | - public static function serverName() |
|
385 | - { |
|
386 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
387 | - |
|
388 | - if (isset($server['SERVER_NAME'])) { |
|
389 | - return $server['SERVER_NAME']; |
|
390 | - } |
|
391 | - |
|
392 | - return null; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * You probably only want to deal with this through SessionAlert. |
|
397 | - * @return void |
|
398 | - */ |
|
399 | - public static function clearSessionAlertData() |
|
400 | - { |
|
401 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
402 | - if (array_key_exists('alerts', $session)) { |
|
403 | - unset($session['alerts']); |
|
404 | - } |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * You probably only want to deal with this through SessionAlert. |
|
409 | - * |
|
410 | - * @return string[] |
|
411 | - */ |
|
412 | - public static function getSessionAlertData() |
|
413 | - { |
|
414 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
415 | - if (array_key_exists('alerts', $session)) { |
|
416 | - return $session['alerts']; |
|
417 | - } |
|
418 | - |
|
419 | - return array(); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * You probably only want to deal with this through SessionAlert. |
|
424 | - * |
|
425 | - * @param string[] $data |
|
426 | - */ |
|
427 | - public static function setSessionAlertData($data) |
|
428 | - { |
|
429 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
430 | - $session['alerts'] = $data; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * You probably only want to deal with this through TokenManager. |
|
435 | - * |
|
436 | - * @return string[] |
|
437 | - */ |
|
438 | - public static function getSessionTokenData() |
|
439 | - { |
|
440 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
441 | - if (array_key_exists('tokens', $session)) { |
|
442 | - return $session['tokens']; |
|
443 | - } |
|
444 | - |
|
445 | - return array(); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * You probably only want to deal with this through TokenManager. |
|
450 | - * |
|
451 | - * @param string[] $data |
|
452 | - */ |
|
453 | - public static function setSessionTokenData($data) |
|
454 | - { |
|
455 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
456 | - $session['tokens'] = $data; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * @param string $key |
|
461 | - * |
|
462 | - * @return mixed |
|
463 | - */ |
|
464 | - public static function getSessionContext($key) |
|
465 | - { |
|
466 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
467 | - |
|
468 | - if (!isset($session['context'])) { |
|
469 | - $session['context'] = array(); |
|
470 | - } |
|
471 | - |
|
472 | - if (!isset($session['context'][$key])) { |
|
473 | - return null; |
|
474 | - } |
|
475 | - |
|
476 | - return $session['context'][$key]; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @param string $key |
|
481 | - * @param mixed $data |
|
482 | - */ |
|
483 | - public static function setSessionContext($key, $data) |
|
484 | - { |
|
485 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
486 | - |
|
487 | - if (!isset($session['context'])) { |
|
488 | - $session['context'] = array(); |
|
489 | - } |
|
490 | - |
|
491 | - $session['context'][$key] = $data; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @return int|null |
|
496 | - */ |
|
497 | - public static function getSessionUserId() |
|
498 | - { |
|
499 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
500 | - |
|
501 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * @param User $user |
|
506 | - */ |
|
507 | - public static function setOAuthPartialLogin(User $user) |
|
508 | - { |
|
509 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
510 | - $session['oauthPartialLogin'] = $user->getId(); |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * @return int|null |
|
515 | - */ |
|
516 | - public static function getOAuthPartialLogin() |
|
517 | - { |
|
518 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
519 | - |
|
520 | - return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
521 | - } |
|
522 | - |
|
523 | - public static function setAuthPartialLogin($userId, $stage) |
|
524 | - { |
|
525 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
526 | - $session['authPartialLoginId'] = $userId; |
|
527 | - $session['authPartialLoginStage'] = $stage; |
|
528 | - } |
|
529 | - |
|
530 | - public static function getAuthPartialLogin() |
|
531 | - { |
|
532 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
533 | - |
|
534 | - $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
535 | - $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
536 | - |
|
537 | - return array($userId, $stage); |
|
538 | - } |
|
539 | - |
|
540 | - public static function clearAuthPartialLogin() |
|
541 | - { |
|
542 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
543 | - unset($session['authPartialLoginId']); |
|
544 | - unset($session['authPartialLoginStage']); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * @return null|string |
|
549 | - */ |
|
550 | - public static function userAgent() |
|
551 | - { |
|
552 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
553 | - |
|
554 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
555 | - return $server['HTTP_USER_AGENT']; |
|
556 | - } |
|
557 | - |
|
558 | - return null; |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * @return null|string |
|
563 | - */ |
|
564 | - public static function scriptName() |
|
565 | - { |
|
566 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
567 | - |
|
568 | - if (isset($server['SCRIPT_NAME'])) { |
|
569 | - return $server['SCRIPT_NAME']; |
|
570 | - } |
|
571 | - |
|
572 | - return null; |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * @return null|string |
|
577 | - */ |
|
578 | - public static function origin() |
|
579 | - { |
|
580 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
581 | - |
|
582 | - if (isset($server['HTTP_ORIGIN'])) { |
|
583 | - return $server['HTTP_ORIGIN']; |
|
584 | - } |
|
585 | - |
|
586 | - return null; |
|
587 | - } |
|
25 | + /** |
|
26 | + * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | + */ |
|
28 | + private static $globalStateProvider; |
|
29 | + |
|
30 | + /** |
|
31 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function wasPosted() |
|
35 | + { |
|
36 | + return self::method() === 'POST'; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the HTTP Method used |
|
41 | + * @return string|null |
|
42 | + */ |
|
43 | + public static function method() |
|
44 | + { |
|
45 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | + |
|
47 | + if (isset($server['REQUEST_METHOD'])) { |
|
48 | + return $server['REQUEST_METHOD']; |
|
49 | + } |
|
50 | + |
|
51 | + return null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public static function isHttps() |
|
59 | + { |
|
60 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | + |
|
62 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | + // Client <=> Proxy is encrypted |
|
65 | + return true; |
|
66 | + } |
|
67 | + else { |
|
68 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | + return false; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($server['HTTPS'])) { |
|
74 | + if ($server['HTTPS'] === 'off') { |
|
75 | + // ISAPI on IIS breaks the spec. :( |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + if ($server['HTTPS'] !== '') { |
|
80 | + // Set to a non-empty value |
|
81 | + return true; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return false; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the path info |
|
90 | + * |
|
91 | + * @return array Array of path info segments |
|
92 | + */ |
|
93 | + public static function pathInfo() |
|
94 | + { |
|
95 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | + if (!isset($server['PATH_INFO'])) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $exploded = explode('/', $server['PATH_INFO']); |
|
101 | + |
|
102 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | + // with a / |
|
104 | + return array_values(array_filter($exploded)); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Gets the remote address of the web request |
|
109 | + * @return null|string |
|
110 | + */ |
|
111 | + public static function remoteAddress() |
|
112 | + { |
|
113 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | + |
|
115 | + if (isset($server['REMOTE_ADDR'])) { |
|
116 | + return $server['REMOTE_ADDR']; |
|
117 | + } |
|
118 | + |
|
119 | + return null; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets the remote address of the web request |
|
124 | + * @return null|string |
|
125 | + */ |
|
126 | + public static function httpHost() |
|
127 | + { |
|
128 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | + |
|
130 | + if (isset($server['HTTP_HOST'])) { |
|
131 | + return $server['HTTP_HOST']; |
|
132 | + } |
|
133 | + |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Gets the XFF header contents for the web request |
|
139 | + * @return null|string |
|
140 | + */ |
|
141 | + public static function forwardedAddress() |
|
142 | + { |
|
143 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
144 | + |
|
145 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
146 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
147 | + } |
|
148 | + |
|
149 | + return null; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets the global state provider. |
|
154 | + * |
|
155 | + * Almost guaranteed this is not the method you want in production code. |
|
156 | + * |
|
157 | + * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
158 | + */ |
|
159 | + public static function setGlobalStateProvider($globalState) |
|
160 | + { |
|
161 | + self::$globalStateProvider = $globalState; |
|
162 | + } |
|
163 | + |
|
164 | + #region POST variables |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $key |
|
168 | + * |
|
169 | + * @return null|string |
|
170 | + */ |
|
171 | + public static function postString($key) |
|
172 | + { |
|
173 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
174 | + if (!array_key_exists($key, $post)) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + |
|
178 | + if ($post[$key] === "") { |
|
179 | + return null; |
|
180 | + } |
|
181 | + |
|
182 | + return (string)$post[$key]; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $key |
|
187 | + * |
|
188 | + * @return null|string |
|
189 | + */ |
|
190 | + public static function postEmail($key) |
|
191 | + { |
|
192 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
193 | + if (!array_key_exists($key, $post)) { |
|
194 | + return null; |
|
195 | + } |
|
196 | + |
|
197 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
198 | + |
|
199 | + if ($filteredValue === false) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + |
|
203 | + return (string)$filteredValue; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string $key |
|
208 | + * |
|
209 | + * @return int|null |
|
210 | + */ |
|
211 | + public static function postInt($key) |
|
212 | + { |
|
213 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
214 | + if (!array_key_exists($key, $post)) { |
|
215 | + return null; |
|
216 | + } |
|
217 | + |
|
218 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
219 | + |
|
220 | + if ($filteredValue === null) { |
|
221 | + return null; |
|
222 | + } |
|
223 | + |
|
224 | + return (int)$filteredValue; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $key |
|
229 | + * |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public static function postBoolean($key) |
|
233 | + { |
|
234 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
235 | + if (!array_key_exists($key, $get)) { |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + // presence of parameter only |
|
240 | + if ($get[$key] === "") { |
|
241 | + return true; |
|
242 | + } |
|
243 | + |
|
244 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + return true; |
|
249 | + } |
|
250 | + |
|
251 | + #endregion |
|
252 | + |
|
253 | + #region GET variables |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $key |
|
257 | + * |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public static function getBoolean($key) |
|
261 | + { |
|
262 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
263 | + if (!array_key_exists($key, $get)) { |
|
264 | + return false; |
|
265 | + } |
|
266 | + |
|
267 | + // presence of parameter only |
|
268 | + if ($get[$key] === "") { |
|
269 | + return true; |
|
270 | + } |
|
271 | + |
|
272 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + return true; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @param string $key |
|
281 | + * |
|
282 | + * @return int|null |
|
283 | + */ |
|
284 | + public static function getInt($key) |
|
285 | + { |
|
286 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
287 | + if (!array_key_exists($key, $get)) { |
|
288 | + return null; |
|
289 | + } |
|
290 | + |
|
291 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
292 | + |
|
293 | + if ($filteredValue === null) { |
|
294 | + return null; |
|
295 | + } |
|
296 | + |
|
297 | + return (int)$filteredValue; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @param string $key |
|
302 | + * |
|
303 | + * @return null|string |
|
304 | + */ |
|
305 | + public static function getString($key) |
|
306 | + { |
|
307 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
308 | + if (!array_key_exists($key, $get)) { |
|
309 | + return null; |
|
310 | + } |
|
311 | + |
|
312 | + if ($get[$key] === "") { |
|
313 | + return null; |
|
314 | + } |
|
315 | + |
|
316 | + return (string)$get[$key]; |
|
317 | + } |
|
318 | + |
|
319 | + #endregion |
|
320 | + |
|
321 | + /** |
|
322 | + * Sets the logged-in user to the specified user. |
|
323 | + * |
|
324 | + * @param User $user |
|
325 | + */ |
|
326 | + public static function setLoggedInUser(User $user) |
|
327 | + { |
|
328 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
329 | + |
|
330 | + $session['userID'] = $user->getId(); |
|
331 | + unset($session['partialLogin']); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sets the post-login redirect |
|
336 | + * |
|
337 | + * @param string|null $uri The URI to redirect to |
|
338 | + */ |
|
339 | + public static function setPostLoginRedirect($uri = null) |
|
340 | + { |
|
341 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
342 | + |
|
343 | + if ($uri === null) { |
|
344 | + $uri = self::requestUri(); |
|
345 | + } |
|
346 | + |
|
347 | + $session['returnTo'] = $uri; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * @return string|null |
|
352 | + */ |
|
353 | + public static function requestUri() |
|
354 | + { |
|
355 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
356 | + |
|
357 | + if (isset($server['REQUEST_URI'])) { |
|
358 | + return $server['REQUEST_URI']; |
|
359 | + } |
|
360 | + |
|
361 | + return null; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Clears the post-login redirect |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public static function clearPostLoginRedirect() |
|
369 | + { |
|
370 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
371 | + if (array_key_exists('returnTo', $session)) { |
|
372 | + $path = $session['returnTo']; |
|
373 | + unset($session['returnTo']); |
|
374 | + |
|
375 | + return $path; |
|
376 | + } |
|
377 | + |
|
378 | + return null; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * @return string|null |
|
383 | + */ |
|
384 | + public static function serverName() |
|
385 | + { |
|
386 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
387 | + |
|
388 | + if (isset($server['SERVER_NAME'])) { |
|
389 | + return $server['SERVER_NAME']; |
|
390 | + } |
|
391 | + |
|
392 | + return null; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * You probably only want to deal with this through SessionAlert. |
|
397 | + * @return void |
|
398 | + */ |
|
399 | + public static function clearSessionAlertData() |
|
400 | + { |
|
401 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
402 | + if (array_key_exists('alerts', $session)) { |
|
403 | + unset($session['alerts']); |
|
404 | + } |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * You probably only want to deal with this through SessionAlert. |
|
409 | + * |
|
410 | + * @return string[] |
|
411 | + */ |
|
412 | + public static function getSessionAlertData() |
|
413 | + { |
|
414 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
415 | + if (array_key_exists('alerts', $session)) { |
|
416 | + return $session['alerts']; |
|
417 | + } |
|
418 | + |
|
419 | + return array(); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * You probably only want to deal with this through SessionAlert. |
|
424 | + * |
|
425 | + * @param string[] $data |
|
426 | + */ |
|
427 | + public static function setSessionAlertData($data) |
|
428 | + { |
|
429 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
430 | + $session['alerts'] = $data; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * You probably only want to deal with this through TokenManager. |
|
435 | + * |
|
436 | + * @return string[] |
|
437 | + */ |
|
438 | + public static function getSessionTokenData() |
|
439 | + { |
|
440 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
441 | + if (array_key_exists('tokens', $session)) { |
|
442 | + return $session['tokens']; |
|
443 | + } |
|
444 | + |
|
445 | + return array(); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * You probably only want to deal with this through TokenManager. |
|
450 | + * |
|
451 | + * @param string[] $data |
|
452 | + */ |
|
453 | + public static function setSessionTokenData($data) |
|
454 | + { |
|
455 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
456 | + $session['tokens'] = $data; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * @param string $key |
|
461 | + * |
|
462 | + * @return mixed |
|
463 | + */ |
|
464 | + public static function getSessionContext($key) |
|
465 | + { |
|
466 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
467 | + |
|
468 | + if (!isset($session['context'])) { |
|
469 | + $session['context'] = array(); |
|
470 | + } |
|
471 | + |
|
472 | + if (!isset($session['context'][$key])) { |
|
473 | + return null; |
|
474 | + } |
|
475 | + |
|
476 | + return $session['context'][$key]; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @param string $key |
|
481 | + * @param mixed $data |
|
482 | + */ |
|
483 | + public static function setSessionContext($key, $data) |
|
484 | + { |
|
485 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
486 | + |
|
487 | + if (!isset($session['context'])) { |
|
488 | + $session['context'] = array(); |
|
489 | + } |
|
490 | + |
|
491 | + $session['context'][$key] = $data; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @return int|null |
|
496 | + */ |
|
497 | + public static function getSessionUserId() |
|
498 | + { |
|
499 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
500 | + |
|
501 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * @param User $user |
|
506 | + */ |
|
507 | + public static function setOAuthPartialLogin(User $user) |
|
508 | + { |
|
509 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
510 | + $session['oauthPartialLogin'] = $user->getId(); |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * @return int|null |
|
515 | + */ |
|
516 | + public static function getOAuthPartialLogin() |
|
517 | + { |
|
518 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
519 | + |
|
520 | + return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
521 | + } |
|
522 | + |
|
523 | + public static function setAuthPartialLogin($userId, $stage) |
|
524 | + { |
|
525 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
526 | + $session['authPartialLoginId'] = $userId; |
|
527 | + $session['authPartialLoginStage'] = $stage; |
|
528 | + } |
|
529 | + |
|
530 | + public static function getAuthPartialLogin() |
|
531 | + { |
|
532 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
533 | + |
|
534 | + $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
535 | + $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
536 | + |
|
537 | + return array($userId, $stage); |
|
538 | + } |
|
539 | + |
|
540 | + public static function clearAuthPartialLogin() |
|
541 | + { |
|
542 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
543 | + unset($session['authPartialLoginId']); |
|
544 | + unset($session['authPartialLoginStage']); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * @return null|string |
|
549 | + */ |
|
550 | + public static function userAgent() |
|
551 | + { |
|
552 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
553 | + |
|
554 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
555 | + return $server['HTTP_USER_AGENT']; |
|
556 | + } |
|
557 | + |
|
558 | + return null; |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * @return null|string |
|
563 | + */ |
|
564 | + public static function scriptName() |
|
565 | + { |
|
566 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
567 | + |
|
568 | + if (isset($server['SCRIPT_NAME'])) { |
|
569 | + return $server['SCRIPT_NAME']; |
|
570 | + } |
|
571 | + |
|
572 | + return null; |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * @return null|string |
|
577 | + */ |
|
578 | + public static function origin() |
|
579 | + { |
|
580 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
581 | + |
|
582 | + if (isset($server['HTTP_ORIGIN'])) { |
|
583 | + return $server['HTTP_ORIGIN']; |
|
584 | + } |
|
585 | + |
|
586 | + return null; |
|
587 | + } |
|
588 | 588 | } |