@@ -13,91 +13,91 @@ |
||
13 | 13 | |
14 | 14 | class TokenManager |
15 | 15 | { |
16 | - /** |
|
17 | - * Validates a CSRF token |
|
18 | - * |
|
19 | - * @param string $data The token data string itself |
|
20 | - * @param string|null $context Token context for extra validation |
|
21 | - * |
|
22 | - * @return bool |
|
23 | - */ |
|
24 | - public function validateToken($data, $context = null) |
|
25 | - { |
|
26 | - if (!is_string($data) || strlen($data) === 0) { |
|
27 | - // Nothing to validate |
|
28 | - return false; |
|
29 | - } |
|
30 | - |
|
31 | - $tokens = WebRequest::getSessionTokenData(); |
|
32 | - |
|
33 | - // if the token doesn't exist, then it's not valid |
|
34 | - if (!array_key_exists($data, $tokens)) { |
|
35 | - return false; |
|
36 | - } |
|
37 | - |
|
38 | - /** @var Token $token */ |
|
39 | - $token = unserialize($tokens[$data]); |
|
40 | - |
|
41 | - if ($token->getTokenData() !== $data) { |
|
42 | - return false; |
|
43 | - } |
|
44 | - |
|
45 | - if ($token->getContext() !== $context) { |
|
46 | - return false; |
|
47 | - } |
|
48 | - |
|
49 | - if ($token->isUsed()) { |
|
50 | - return false; |
|
51 | - } |
|
52 | - |
|
53 | - // mark the token as used, and save it back to the session |
|
54 | - $token->markAsUsed(); |
|
55 | - $this->storeToken($token); |
|
56 | - |
|
57 | - return true; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string|null $context An optional context for extra validation |
|
62 | - * |
|
63 | - * @return Token |
|
64 | - */ |
|
65 | - public function getNewToken($context = null) |
|
66 | - { |
|
67 | - $token = new Token($this->generateTokenData(), $context); |
|
68 | - $this->storeToken($token); |
|
69 | - |
|
70 | - return $token; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Stores a token in the session data |
|
75 | - * |
|
76 | - * @param Token $token |
|
77 | - */ |
|
78 | - private function storeToken(Token $token) |
|
79 | - { |
|
80 | - $tokens = WebRequest::getSessionTokenData(); |
|
81 | - $tokens[$token->getTokenData()] = serialize($token); |
|
82 | - WebRequest::setSessionTokenData($tokens); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Generates a security token |
|
87 | - * |
|
88 | - * @return string |
|
89 | - * @throws Exception |
|
90 | - * |
|
91 | - * @category Security-Critical |
|
92 | - */ |
|
93 | - private function generateTokenData() |
|
94 | - { |
|
95 | - $genBytes = openssl_random_pseudo_bytes(33); |
|
96 | - |
|
97 | - if ($genBytes !== false) { |
|
98 | - return base64_encode($genBytes); |
|
99 | - } |
|
100 | - |
|
101 | - throw new Exception('Unable to generate secure token.'); |
|
102 | - } |
|
16 | + /** |
|
17 | + * Validates a CSRF token |
|
18 | + * |
|
19 | + * @param string $data The token data string itself |
|
20 | + * @param string|null $context Token context for extra validation |
|
21 | + * |
|
22 | + * @return bool |
|
23 | + */ |
|
24 | + public function validateToken($data, $context = null) |
|
25 | + { |
|
26 | + if (!is_string($data) || strlen($data) === 0) { |
|
27 | + // Nothing to validate |
|
28 | + return false; |
|
29 | + } |
|
30 | + |
|
31 | + $tokens = WebRequest::getSessionTokenData(); |
|
32 | + |
|
33 | + // if the token doesn't exist, then it's not valid |
|
34 | + if (!array_key_exists($data, $tokens)) { |
|
35 | + return false; |
|
36 | + } |
|
37 | + |
|
38 | + /** @var Token $token */ |
|
39 | + $token = unserialize($tokens[$data]); |
|
40 | + |
|
41 | + if ($token->getTokenData() !== $data) { |
|
42 | + return false; |
|
43 | + } |
|
44 | + |
|
45 | + if ($token->getContext() !== $context) { |
|
46 | + return false; |
|
47 | + } |
|
48 | + |
|
49 | + if ($token->isUsed()) { |
|
50 | + return false; |
|
51 | + } |
|
52 | + |
|
53 | + // mark the token as used, and save it back to the session |
|
54 | + $token->markAsUsed(); |
|
55 | + $this->storeToken($token); |
|
56 | + |
|
57 | + return true; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string|null $context An optional context for extra validation |
|
62 | + * |
|
63 | + * @return Token |
|
64 | + */ |
|
65 | + public function getNewToken($context = null) |
|
66 | + { |
|
67 | + $token = new Token($this->generateTokenData(), $context); |
|
68 | + $this->storeToken($token); |
|
69 | + |
|
70 | + return $token; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Stores a token in the session data |
|
75 | + * |
|
76 | + * @param Token $token |
|
77 | + */ |
|
78 | + private function storeToken(Token $token) |
|
79 | + { |
|
80 | + $tokens = WebRequest::getSessionTokenData(); |
|
81 | + $tokens[$token->getTokenData()] = serialize($token); |
|
82 | + WebRequest::setSessionTokenData($tokens); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Generates a security token |
|
87 | + * |
|
88 | + * @return string |
|
89 | + * @throws Exception |
|
90 | + * |
|
91 | + * @category Security-Critical |
|
92 | + */ |
|
93 | + private function generateTokenData() |
|
94 | + { |
|
95 | + $genBytes = openssl_random_pseudo_bytes(33); |
|
96 | + |
|
97 | + if ($genBytes !== false) { |
|
98 | + return base64_encode($genBytes); |
|
99 | + } |
|
100 | + |
|
101 | + throw new Exception('Unable to generate secure token.'); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | \ No newline at end of file |
@@ -83,8 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | if ($siteConfiguration->getTitleBlacklistEnabled()) { |
85 | 85 | $page->setBlacklistHelper(new FakeBlacklistHelper()); |
86 | - } |
|
87 | - else { |
|
86 | + } else { |
|
88 | 87 | $page->setBlacklistHelper(new BlacklistHelper($page->getHttpHelper(), |
89 | 88 | $siteConfiguration->getMediawikiWebServiceEndpoint())); |
90 | 89 | } |
@@ -178,8 +177,7 @@ discard block |
||
178 | 177 | |
179 | 178 | if ($siteConfiguration->getIrcNotificationsEnabled()) { |
180 | 179 | $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
181 | - } |
|
182 | - else { |
|
180 | + } else { |
|
183 | 181 | // @todo federated table here? |
184 | 182 | $notificationsDatabase = $database; |
185 | 183 | } |
@@ -31,216 +31,216 @@ |
||
31 | 31 | */ |
32 | 32 | class WebStart extends ApplicationBase |
33 | 33 | { |
34 | - /** |
|
35 | - * @var IRequestRouter $requestRouter The request router to use. Note that different entry points have different |
|
36 | - * routers and hence different URL mappings |
|
37 | - */ |
|
38 | - private $requestRouter; |
|
39 | - /** |
|
40 | - * @var bool $isPublic Determines whether to use public interface objects or internal interface objects |
|
41 | - */ |
|
42 | - private $isPublic = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * WebStart constructor. |
|
46 | - * |
|
47 | - * @param SiteConfiguration $configuration The site configuration |
|
48 | - * @param IRequestRouter $router The request router to use |
|
49 | - */ |
|
50 | - public function __construct(SiteConfiguration $configuration, IRequestRouter $router) |
|
51 | - { |
|
52 | - parent::__construct($configuration); |
|
53 | - |
|
54 | - $this->requestRouter = $router; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param ITask $page |
|
59 | - * @param SiteConfiguration $siteConfiguration |
|
60 | - * @param PdoDatabase $database |
|
61 | - * @param PdoDatabase $notificationsDatabase |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - protected function setupHelpers( |
|
66 | - ITask $page, |
|
67 | - SiteConfiguration $siteConfiguration, |
|
68 | - PdoDatabase $database, |
|
69 | - PdoDatabase $notificationsDatabase = null |
|
70 | - ) { |
|
71 | - parent::setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
72 | - |
|
73 | - if ($page instanceof PageBase) { |
|
74 | - $page->setTokenManager(new TokenManager()); |
|
75 | - $page->setCspManager(new ContentSecurityPolicyManager($siteConfiguration)); |
|
76 | - |
|
77 | - if ($page instanceof InternalPageBase) { |
|
78 | - $page->setTypeAheadHelper(new TypeAheadHelper()); |
|
79 | - |
|
80 | - $identificationVerifier = new IdentificationVerifier($page->getHttpHelper(), $siteConfiguration, |
|
81 | - $database); |
|
82 | - $page->setSecurityManager(new SecurityManager($identificationVerifier, new RoleConfiguration())); |
|
83 | - |
|
84 | - if ($siteConfiguration->getTitleBlacklistEnabled()) { |
|
85 | - $page->setBlacklistHelper(new FakeBlacklistHelper()); |
|
86 | - } |
|
87 | - else { |
|
88 | - $page->setBlacklistHelper(new BlacklistHelper($page->getHttpHelper(), |
|
89 | - $siteConfiguration->getMediawikiWebServiceEndpoint())); |
|
90 | - } |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Application entry point. |
|
97 | - * |
|
98 | - * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
99 | - */ |
|
100 | - public function run() |
|
101 | - { |
|
102 | - try { |
|
103 | - if ($this->setupEnvironment()) { |
|
104 | - $this->main(); |
|
105 | - } |
|
106 | - } |
|
107 | - catch (EnvironmentException $ex) { |
|
108 | - ob_end_clean(); |
|
109 | - print Offline::getOfflineMessage($this->isPublic(), $ex->getMessage()); |
|
110 | - } |
|
111 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
112 | - catch (ReadableException $ex) { |
|
113 | - ob_end_clean(); |
|
114 | - print $ex->getReadableError(); |
|
115 | - } |
|
116 | - finally { |
|
117 | - $this->cleanupEnvironment(); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Environment setup |
|
123 | - * |
|
124 | - * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
125 | - * and shut down prematurely. |
|
126 | - * |
|
127 | - * @return bool |
|
128 | - * @throws EnvironmentException |
|
129 | - */ |
|
130 | - protected function setupEnvironment() |
|
131 | - { |
|
132 | - // initialise global exception handler |
|
133 | - set_exception_handler(array(ExceptionHandler::class, 'exceptionHandler')); |
|
134 | - set_error_handler(array(ExceptionHandler::class, 'errorHandler'), E_RECOVERABLE_ERROR); |
|
135 | - |
|
136 | - // start output buffering if necessary |
|
137 | - if (ob_get_level() === 0) { |
|
138 | - ob_start(); |
|
139 | - } |
|
140 | - |
|
141 | - // initialise super-global providers |
|
142 | - WebRequest::setGlobalStateProvider(new GlobalStateProvider()); |
|
143 | - |
|
144 | - if (Offline::isOffline()) { |
|
145 | - print Offline::getOfflineMessage($this->isPublic()); |
|
146 | - ob_end_flush(); |
|
147 | - |
|
148 | - return false; |
|
149 | - } |
|
150 | - |
|
151 | - // Call parent setup |
|
152 | - if (!parent::setupEnvironment()) { |
|
153 | - return false; |
|
154 | - } |
|
155 | - |
|
156 | - // Start up sessions |
|
157 | - Session::start(); |
|
158 | - |
|
159 | - // Check the user is allowed to be logged in still. This must be before we call any user-loading functions and |
|
160 | - // get the current user cached. |
|
161 | - // I'm not sure if this function call being here is particularly a good thing, but it's part of starting up a |
|
162 | - // session I suppose. |
|
163 | - $this->checkForceLogout(); |
|
164 | - |
|
165 | - // environment initialised! |
|
166 | - return true; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Main application logic |
|
171 | - */ |
|
172 | - protected function main() |
|
173 | - { |
|
174 | - // Get the right route for the request |
|
175 | - $page = $this->requestRouter->route(); |
|
176 | - |
|
177 | - $siteConfiguration = $this->getConfiguration(); |
|
178 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
179 | - |
|
180 | - if ($siteConfiguration->getIrcNotificationsEnabled()) { |
|
181 | - $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
182 | - } |
|
183 | - else { |
|
184 | - // @todo federated table here? |
|
185 | - $notificationsDatabase = $database; |
|
186 | - } |
|
187 | - |
|
188 | - $this->setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
189 | - |
|
190 | - // run the route code for the request. |
|
191 | - $page->execute(); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Any cleanup tasks should go here |
|
196 | - * |
|
197 | - * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
198 | - * This should *only* be for cleaning up, no logic should go here. |
|
199 | - */ |
|
200 | - protected function cleanupEnvironment() |
|
201 | - { |
|
202 | - // Clean up anything we splurged after sending the page. |
|
203 | - if (ob_get_level() > 0) { |
|
204 | - for ($i = ob_get_level(); $i > 0; $i--) { |
|
205 | - ob_end_clean(); |
|
206 | - } |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - private function checkForceLogout() |
|
211 | - { |
|
212 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
213 | - |
|
214 | - $sessionUserId = WebRequest::getSessionUserId(); |
|
215 | - iF ($sessionUserId === null) { |
|
216 | - return; |
|
217 | - } |
|
218 | - |
|
219 | - // Note, User::getCurrent() caches it's result, which we *really* don't want to trigger. |
|
220 | - $currentUser = User::getById($sessionUserId, $database); |
|
221 | - |
|
222 | - if ($currentUser === false) { |
|
223 | - // Umm... this user has a session cookie with a userId set, but no user exists... |
|
224 | - Session::restart(); |
|
225 | - |
|
226 | - $currentUser = User::getCurrent($database); |
|
227 | - } |
|
228 | - |
|
229 | - if ($currentUser->getForceLogout()) { |
|
230 | - Session::restart(); |
|
231 | - |
|
232 | - $currentUser->setForceLogout(false); |
|
233 | - $currentUser->save(); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - public function isPublic() |
|
238 | - { |
|
239 | - return $this->isPublic; |
|
240 | - } |
|
241 | - |
|
242 | - public function setPublic($isPublic) |
|
243 | - { |
|
244 | - $this->isPublic = $isPublic; |
|
245 | - } |
|
34 | + /** |
|
35 | + * @var IRequestRouter $requestRouter The request router to use. Note that different entry points have different |
|
36 | + * routers and hence different URL mappings |
|
37 | + */ |
|
38 | + private $requestRouter; |
|
39 | + /** |
|
40 | + * @var bool $isPublic Determines whether to use public interface objects or internal interface objects |
|
41 | + */ |
|
42 | + private $isPublic = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * WebStart constructor. |
|
46 | + * |
|
47 | + * @param SiteConfiguration $configuration The site configuration |
|
48 | + * @param IRequestRouter $router The request router to use |
|
49 | + */ |
|
50 | + public function __construct(SiteConfiguration $configuration, IRequestRouter $router) |
|
51 | + { |
|
52 | + parent::__construct($configuration); |
|
53 | + |
|
54 | + $this->requestRouter = $router; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param ITask $page |
|
59 | + * @param SiteConfiguration $siteConfiguration |
|
60 | + * @param PdoDatabase $database |
|
61 | + * @param PdoDatabase $notificationsDatabase |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + protected function setupHelpers( |
|
66 | + ITask $page, |
|
67 | + SiteConfiguration $siteConfiguration, |
|
68 | + PdoDatabase $database, |
|
69 | + PdoDatabase $notificationsDatabase = null |
|
70 | + ) { |
|
71 | + parent::setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
72 | + |
|
73 | + if ($page instanceof PageBase) { |
|
74 | + $page->setTokenManager(new TokenManager()); |
|
75 | + $page->setCspManager(new ContentSecurityPolicyManager($siteConfiguration)); |
|
76 | + |
|
77 | + if ($page instanceof InternalPageBase) { |
|
78 | + $page->setTypeAheadHelper(new TypeAheadHelper()); |
|
79 | + |
|
80 | + $identificationVerifier = new IdentificationVerifier($page->getHttpHelper(), $siteConfiguration, |
|
81 | + $database); |
|
82 | + $page->setSecurityManager(new SecurityManager($identificationVerifier, new RoleConfiguration())); |
|
83 | + |
|
84 | + if ($siteConfiguration->getTitleBlacklistEnabled()) { |
|
85 | + $page->setBlacklistHelper(new FakeBlacklistHelper()); |
|
86 | + } |
|
87 | + else { |
|
88 | + $page->setBlacklistHelper(new BlacklistHelper($page->getHttpHelper(), |
|
89 | + $siteConfiguration->getMediawikiWebServiceEndpoint())); |
|
90 | + } |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Application entry point. |
|
97 | + * |
|
98 | + * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
99 | + */ |
|
100 | + public function run() |
|
101 | + { |
|
102 | + try { |
|
103 | + if ($this->setupEnvironment()) { |
|
104 | + $this->main(); |
|
105 | + } |
|
106 | + } |
|
107 | + catch (EnvironmentException $ex) { |
|
108 | + ob_end_clean(); |
|
109 | + print Offline::getOfflineMessage($this->isPublic(), $ex->getMessage()); |
|
110 | + } |
|
111 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
112 | + catch (ReadableException $ex) { |
|
113 | + ob_end_clean(); |
|
114 | + print $ex->getReadableError(); |
|
115 | + } |
|
116 | + finally { |
|
117 | + $this->cleanupEnvironment(); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Environment setup |
|
123 | + * |
|
124 | + * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
125 | + * and shut down prematurely. |
|
126 | + * |
|
127 | + * @return bool |
|
128 | + * @throws EnvironmentException |
|
129 | + */ |
|
130 | + protected function setupEnvironment() |
|
131 | + { |
|
132 | + // initialise global exception handler |
|
133 | + set_exception_handler(array(ExceptionHandler::class, 'exceptionHandler')); |
|
134 | + set_error_handler(array(ExceptionHandler::class, 'errorHandler'), E_RECOVERABLE_ERROR); |
|
135 | + |
|
136 | + // start output buffering if necessary |
|
137 | + if (ob_get_level() === 0) { |
|
138 | + ob_start(); |
|
139 | + } |
|
140 | + |
|
141 | + // initialise super-global providers |
|
142 | + WebRequest::setGlobalStateProvider(new GlobalStateProvider()); |
|
143 | + |
|
144 | + if (Offline::isOffline()) { |
|
145 | + print Offline::getOfflineMessage($this->isPublic()); |
|
146 | + ob_end_flush(); |
|
147 | + |
|
148 | + return false; |
|
149 | + } |
|
150 | + |
|
151 | + // Call parent setup |
|
152 | + if (!parent::setupEnvironment()) { |
|
153 | + return false; |
|
154 | + } |
|
155 | + |
|
156 | + // Start up sessions |
|
157 | + Session::start(); |
|
158 | + |
|
159 | + // Check the user is allowed to be logged in still. This must be before we call any user-loading functions and |
|
160 | + // get the current user cached. |
|
161 | + // I'm not sure if this function call being here is particularly a good thing, but it's part of starting up a |
|
162 | + // session I suppose. |
|
163 | + $this->checkForceLogout(); |
|
164 | + |
|
165 | + // environment initialised! |
|
166 | + return true; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Main application logic |
|
171 | + */ |
|
172 | + protected function main() |
|
173 | + { |
|
174 | + // Get the right route for the request |
|
175 | + $page = $this->requestRouter->route(); |
|
176 | + |
|
177 | + $siteConfiguration = $this->getConfiguration(); |
|
178 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
179 | + |
|
180 | + if ($siteConfiguration->getIrcNotificationsEnabled()) { |
|
181 | + $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
182 | + } |
|
183 | + else { |
|
184 | + // @todo federated table here? |
|
185 | + $notificationsDatabase = $database; |
|
186 | + } |
|
187 | + |
|
188 | + $this->setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
189 | + |
|
190 | + // run the route code for the request. |
|
191 | + $page->execute(); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Any cleanup tasks should go here |
|
196 | + * |
|
197 | + * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
198 | + * This should *only* be for cleaning up, no logic should go here. |
|
199 | + */ |
|
200 | + protected function cleanupEnvironment() |
|
201 | + { |
|
202 | + // Clean up anything we splurged after sending the page. |
|
203 | + if (ob_get_level() > 0) { |
|
204 | + for ($i = ob_get_level(); $i > 0; $i--) { |
|
205 | + ob_end_clean(); |
|
206 | + } |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + private function checkForceLogout() |
|
211 | + { |
|
212 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
213 | + |
|
214 | + $sessionUserId = WebRequest::getSessionUserId(); |
|
215 | + iF ($sessionUserId === null) { |
|
216 | + return; |
|
217 | + } |
|
218 | + |
|
219 | + // Note, User::getCurrent() caches it's result, which we *really* don't want to trigger. |
|
220 | + $currentUser = User::getById($sessionUserId, $database); |
|
221 | + |
|
222 | + if ($currentUser === false) { |
|
223 | + // Umm... this user has a session cookie with a userId set, but no user exists... |
|
224 | + Session::restart(); |
|
225 | + |
|
226 | + $currentUser = User::getCurrent($database); |
|
227 | + } |
|
228 | + |
|
229 | + if ($currentUser->getForceLogout()) { |
|
230 | + Session::restart(); |
|
231 | + |
|
232 | + $currentUser->setForceLogout(false); |
|
233 | + $currentUser->save(); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + public function isPublic() |
|
238 | + { |
|
239 | + return $this->isPublic; |
|
240 | + } |
|
241 | + |
|
242 | + public function setPublic($isPublic) |
|
243 | + { |
|
244 | + $this->isPublic = $isPublic; |
|
245 | + } |
|
246 | 246 | } |
@@ -48,8 +48,7 @@ |
||
48 | 48 | |
49 | 49 | if ($username !== null) { |
50 | 50 | $user = User::getByUsername($username, $this->getDatabase()); |
51 | - } |
|
52 | - else { |
|
51 | + } else { |
|
53 | 52 | $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
54 | 53 | } |
55 | 54 |
@@ -22,50 +22,50 @@ |
||
22 | 22 | */ |
23 | 23 | class StatsAction extends XmlApiPageBase implements IXmlApiAction |
24 | 24 | { |
25 | - /** |
|
26 | - * Summary of execute |
|
27 | - * |
|
28 | - * @param DOMElement $apiDocument |
|
29 | - * |
|
30 | - * @return DOMElement |
|
31 | - * @throws ApiException |
|
32 | - * @throws Exception |
|
33 | - */ |
|
34 | - public function executeApiAction(DOMElement $apiDocument) |
|
35 | - { |
|
36 | - $username = WebRequest::getString('user'); |
|
37 | - $wikiusername = WebRequest::getString('wikiuser'); |
|
25 | + /** |
|
26 | + * Summary of execute |
|
27 | + * |
|
28 | + * @param DOMElement $apiDocument |
|
29 | + * |
|
30 | + * @return DOMElement |
|
31 | + * @throws ApiException |
|
32 | + * @throws Exception |
|
33 | + */ |
|
34 | + public function executeApiAction(DOMElement $apiDocument) |
|
35 | + { |
|
36 | + $username = WebRequest::getString('user'); |
|
37 | + $wikiusername = WebRequest::getString('wikiuser'); |
|
38 | 38 | |
39 | - if ($username === null && $wikiusername === null) { |
|
40 | - throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
41 | - } |
|
39 | + if ($username === null && $wikiusername === null) { |
|
40 | + throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
41 | + } |
|
42 | 42 | |
43 | - $userElement = $this->document->createElement("user"); |
|
44 | - $apiDocument->appendChild($userElement); |
|
43 | + $userElement = $this->document->createElement("user"); |
|
44 | + $apiDocument->appendChild($userElement); |
|
45 | 45 | |
46 | - if ($username !== null) { |
|
47 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
48 | - } |
|
49 | - else { |
|
50 | - $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
51 | - } |
|
46 | + if ($username !== null) { |
|
47 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
48 | + } |
|
49 | + else { |
|
50 | + $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
51 | + } |
|
52 | 52 | |
53 | - if ($user === false) { |
|
54 | - $userElement->setAttribute("missing", "true"); |
|
53 | + if ($user === false) { |
|
54 | + $userElement->setAttribute("missing", "true"); |
|
55 | 55 | |
56 | - return $apiDocument; |
|
57 | - } |
|
56 | + return $apiDocument; |
|
57 | + } |
|
58 | 58 | |
59 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
60 | - $this->getSiteConfiguration()); |
|
59 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
60 | + $this->getSiteConfiguration()); |
|
61 | 61 | |
62 | - $userElement->setAttribute("username", $user->getUsername()); |
|
63 | - $userElement->setAttribute("status", $user->getStatus()); |
|
64 | - $userElement->setAttribute("lastactive", $user->getLastActive()); |
|
65 | - $userElement->setAttribute("welcome_template", $user->getWelcomeTemplate()); |
|
66 | - $userElement->setAttribute("onwikiname", $user->getOnWikiName()); |
|
67 | - $userElement->setAttribute("oauth", $oauth->isFullyLinked() ? "true" : "false"); |
|
62 | + $userElement->setAttribute("username", $user->getUsername()); |
|
63 | + $userElement->setAttribute("status", $user->getStatus()); |
|
64 | + $userElement->setAttribute("lastactive", $user->getLastActive()); |
|
65 | + $userElement->setAttribute("welcome_template", $user->getWelcomeTemplate()); |
|
66 | + $userElement->setAttribute("onwikiname", $user->getOnWikiName()); |
|
67 | + $userElement->setAttribute("oauth", $oauth->isFullyLinked() ? "true" : "false"); |
|
68 | 68 | |
69 | - return $apiDocument; |
|
70 | - } |
|
69 | + return $apiDocument; |
|
70 | + } |
|
71 | 71 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | class ApiException extends Exception |
17 | 17 | { |
18 | - /** |
|
19 | - * @param string $message |
|
20 | - */ |
|
21 | - public function __construct($message) |
|
22 | - { |
|
23 | - $this->message = $message; |
|
24 | - } |
|
18 | + /** |
|
19 | + * @param string $message |
|
20 | + */ |
|
21 | + public function __construct($message) |
|
22 | + { |
|
23 | + $this->message = $message; |
|
24 | + } |
|
25 | 25 | } |
@@ -57,8 +57,7 @@ |
||
57 | 57 | |
58 | 58 | if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
59 | 59 | $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
60 | - } |
|
61 | - else { |
|
60 | + } else { |
|
62 | 61 | // pass through null |
63 | 62 | $notificationsDatabase = null; |
64 | 63 | } |
@@ -15,74 +15,74 @@ |
||
15 | 15 | |
16 | 16 | class ConsoleStart extends ApplicationBase |
17 | 17 | { |
18 | - /** |
|
19 | - * @var ConsoleTaskBase |
|
20 | - */ |
|
21 | - private $consoleTask; |
|
18 | + /** |
|
19 | + * @var ConsoleTaskBase |
|
20 | + */ |
|
21 | + private $consoleTask; |
|
22 | 22 | |
23 | - /** |
|
24 | - * ConsoleStart constructor. |
|
25 | - * |
|
26 | - * @param SiteConfiguration $configuration |
|
27 | - * @param ConsoleTaskBase $consoleTask |
|
28 | - */ |
|
29 | - public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | - { |
|
31 | - parent::__construct($configuration); |
|
32 | - $this->consoleTask = $consoleTask; |
|
33 | - } |
|
23 | + /** |
|
24 | + * ConsoleStart constructor. |
|
25 | + * |
|
26 | + * @param SiteConfiguration $configuration |
|
27 | + * @param ConsoleTaskBase $consoleTask |
|
28 | + */ |
|
29 | + public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | + { |
|
31 | + parent::__construct($configuration); |
|
32 | + $this->consoleTask = $consoleTask; |
|
33 | + } |
|
34 | 34 | |
35 | - protected function setupEnvironment() |
|
36 | - { |
|
37 | - // initialise super-global providers |
|
38 | - WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
35 | + protected function setupEnvironment() |
|
36 | + { |
|
37 | + // initialise super-global providers |
|
38 | + WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
39 | 39 | |
40 | - if (WebRequest::method() !== null) { |
|
41 | - throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | - } |
|
40 | + if (WebRequest::method() !== null) { |
|
41 | + throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | + } |
|
43 | 43 | |
44 | - return parent::setupEnvironment(); |
|
45 | - } |
|
44 | + return parent::setupEnvironment(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function cleanupEnvironment() |
|
48 | - { |
|
49 | - } |
|
47 | + protected function cleanupEnvironment() |
|
48 | + { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Main application logic |
|
53 | - */ |
|
54 | - protected function main() |
|
55 | - { |
|
56 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
51 | + /** |
|
52 | + * Main application logic |
|
53 | + */ |
|
54 | + protected function main() |
|
55 | + { |
|
56 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
57 | 57 | |
58 | - if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
|
59 | - $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
60 | - } |
|
61 | - else { |
|
62 | - // pass through null |
|
63 | - $notificationsDatabase = null; |
|
64 | - } |
|
58 | + if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
|
59 | + $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
60 | + } |
|
61 | + else { |
|
62 | + // pass through null |
|
63 | + $notificationsDatabase = null; |
|
64 | + } |
|
65 | 65 | |
66 | - $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase); |
|
66 | + $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase); |
|
67 | 67 | |
68 | - // initialise a database transaction |
|
69 | - if (!$database->beginTransaction()) { |
|
70 | - throw new Exception('Failed to start transaction on primary database.'); |
|
71 | - } |
|
68 | + // initialise a database transaction |
|
69 | + if (!$database->beginTransaction()) { |
|
70 | + throw new Exception('Failed to start transaction on primary database.'); |
|
71 | + } |
|
72 | 72 | |
73 | - try { |
|
74 | - // run the task |
|
75 | - $this->consoleTask->execute(); |
|
73 | + try { |
|
74 | + // run the task |
|
75 | + $this->consoleTask->execute(); |
|
76 | 76 | |
77 | - if ($database->hasActiveTransaction()) { |
|
78 | - $database->commit(); |
|
79 | - } |
|
80 | - } |
|
81 | - finally { |
|
82 | - // Catch any hanging on transactions |
|
83 | - if ($database->hasActiveTransaction()) { |
|
84 | - $database->rollBack(); |
|
85 | - } |
|
86 | - } |
|
87 | - } |
|
77 | + if ($database->hasActiveTransaction()) { |
|
78 | + $database->commit(); |
|
79 | + } |
|
80 | + } |
|
81 | + finally { |
|
82 | + // Catch any hanging on transactions |
|
83 | + if ($database->hasActiveTransaction()) { |
|
84 | + $database->rollBack(); |
|
85 | + } |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | \ No newline at end of file |
@@ -78,8 +78,7 @@ |
||
78 | 78 | { |
79 | 79 | if (ord($string) < 128) { |
80 | 80 | return ucfirst($string); |
81 | - } |
|
82 | - else { |
|
81 | + } else { |
|
83 | 82 | return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
84 | 83 | } |
85 | 84 | } |
@@ -10,20 +10,20 @@ |
||
10 | 10 | |
11 | 11 | class StringFunctions |
12 | 12 | { |
13 | - /** |
|
14 | - * Make a string's first character uppercase |
|
15 | - * |
|
16 | - * @param string $string |
|
17 | - * |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function upperCaseFirst($string) |
|
21 | - { |
|
22 | - if (ord($string) < 128) { |
|
23 | - return ucfirst($string); |
|
24 | - } |
|
25 | - else { |
|
26 | - return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
27 | - } |
|
28 | - } |
|
13 | + /** |
|
14 | + * Make a string's first character uppercase |
|
15 | + * |
|
16 | + * @param string $string |
|
17 | + * |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function upperCaseFirst($string) |
|
21 | + { |
|
22 | + if (ord($string) < 128) { |
|
23 | + return ucfirst($string); |
|
24 | + } |
|
25 | + else { |
|
26 | + return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | } |
@@ -63,8 +63,7 @@ |
||
63 | 63 | if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
64 | 64 | // Client <=> Proxy is encrypted |
65 | 65 | return true; |
66 | - } |
|
67 | - else { |
|
66 | + } else { |
|
68 | 67 | // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
69 | 68 | return false; |
70 | 69 | } |
@@ -24,578 +24,578 @@ |
||
24 | 24 | */ |
25 | 25 | class WebRequest |
26 | 26 | { |
27 | - /** |
|
28 | - * @var IGlobalStateProvider Provides access to the global state. |
|
29 | - */ |
|
30 | - private static $globalStateProvider; |
|
31 | - |
|
32 | - /** |
|
33 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public static function wasPosted() |
|
37 | - { |
|
38 | - return self::method() === 'POST'; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Gets the HTTP Method used |
|
43 | - * @return string|null |
|
44 | - */ |
|
45 | - public static function method() |
|
46 | - { |
|
47 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
48 | - |
|
49 | - if (isset($server['REQUEST_METHOD'])) { |
|
50 | - return $server['REQUEST_METHOD']; |
|
51 | - } |
|
52 | - |
|
53 | - return null; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public static function isHttps() |
|
61 | - { |
|
62 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
63 | - |
|
64 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
65 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
66 | - // Client <=> Proxy is encrypted |
|
67 | - return true; |
|
68 | - } |
|
69 | - else { |
|
70 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
71 | - return false; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - if (isset($server['HTTPS'])) { |
|
76 | - if ($server['HTTPS'] === 'off') { |
|
77 | - // ISAPI on IIS breaks the spec. :( |
|
78 | - return false; |
|
79 | - } |
|
80 | - |
|
81 | - if ($server['HTTPS'] !== '') { |
|
82 | - // Set to a non-empty value |
|
83 | - return true; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - return false; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Gets the path info |
|
92 | - * |
|
93 | - * @return array Array of path info segments |
|
94 | - */ |
|
95 | - public static function pathInfo() |
|
96 | - { |
|
97 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
98 | - if (!isset($server['PATH_INFO'])) { |
|
99 | - return array(); |
|
100 | - } |
|
101 | - |
|
102 | - $exploded = explode('/', $server['PATH_INFO']); |
|
103 | - |
|
104 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
105 | - // with a / |
|
106 | - return array_values(array_filter($exploded)); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Gets the remote address of the web request |
|
111 | - * @return null|string |
|
112 | - */ |
|
113 | - public static function remoteAddress() |
|
114 | - { |
|
115 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
116 | - |
|
117 | - if (isset($server['REMOTE_ADDR'])) { |
|
118 | - return $server['REMOTE_ADDR']; |
|
119 | - } |
|
120 | - |
|
121 | - return null; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Gets the remote address of the web request |
|
126 | - * @return null|string |
|
127 | - */ |
|
128 | - public static function httpHost() |
|
129 | - { |
|
130 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
131 | - |
|
132 | - if (isset($server['HTTP_HOST'])) { |
|
133 | - return $server['HTTP_HOST']; |
|
134 | - } |
|
135 | - |
|
136 | - return null; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Gets the XFF header contents for the web request |
|
141 | - * @return null|string |
|
142 | - */ |
|
143 | - public static function forwardedAddress() |
|
144 | - { |
|
145 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
146 | - |
|
147 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
148 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
149 | - } |
|
150 | - |
|
151 | - return null; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Sets the global state provider. |
|
156 | - * |
|
157 | - * Almost guaranteed this is not the method you want in production code. |
|
158 | - * |
|
159 | - * @param IGlobalStateProvider $globalState |
|
160 | - */ |
|
161 | - public static function setGlobalStateProvider($globalState) |
|
162 | - { |
|
163 | - self::$globalStateProvider = $globalState; |
|
164 | - } |
|
165 | - |
|
166 | - #region POST variables |
|
167 | - |
|
168 | - /** |
|
169 | - * @param string $key |
|
170 | - * |
|
171 | - * @return null|string |
|
172 | - */ |
|
173 | - public static function postString($key) |
|
174 | - { |
|
175 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
176 | - if (!array_key_exists($key, $post)) { |
|
177 | - return null; |
|
178 | - } |
|
179 | - |
|
180 | - if ($post[$key] === "") { |
|
181 | - return null; |
|
182 | - } |
|
183 | - |
|
184 | - return (string)$post[$key]; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param string $key |
|
189 | - * |
|
190 | - * @return null|string |
|
191 | - */ |
|
192 | - public static function postEmail($key) |
|
193 | - { |
|
194 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
195 | - if (!array_key_exists($key, $post)) { |
|
196 | - return null; |
|
197 | - } |
|
198 | - |
|
199 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
200 | - |
|
201 | - if ($filteredValue === false) { |
|
202 | - return null; |
|
203 | - } |
|
204 | - |
|
205 | - return (string)$filteredValue; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param string $key |
|
210 | - * |
|
211 | - * @return int|null |
|
212 | - */ |
|
213 | - public static function postInt($key) |
|
214 | - { |
|
215 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
216 | - if (!array_key_exists($key, $post)) { |
|
217 | - return null; |
|
218 | - } |
|
219 | - |
|
220 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
221 | - |
|
222 | - if ($filteredValue === null) { |
|
223 | - return null; |
|
224 | - } |
|
225 | - |
|
226 | - return (int)$filteredValue; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string $key |
|
231 | - * |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public static function postBoolean($key) |
|
235 | - { |
|
236 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
237 | - if (!array_key_exists($key, $get)) { |
|
238 | - return false; |
|
239 | - } |
|
240 | - |
|
241 | - // presence of parameter only |
|
242 | - if ($get[$key] === "") { |
|
243 | - return true; |
|
244 | - } |
|
245 | - |
|
246 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
247 | - return false; |
|
248 | - } |
|
249 | - |
|
250 | - return true; |
|
251 | - } |
|
252 | - |
|
253 | - #endregion |
|
254 | - |
|
255 | - #region GET variables |
|
256 | - |
|
257 | - /** |
|
258 | - * @param string $key |
|
259 | - * |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public static function getBoolean($key) |
|
263 | - { |
|
264 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
265 | - if (!array_key_exists($key, $get)) { |
|
266 | - return false; |
|
267 | - } |
|
268 | - |
|
269 | - // presence of parameter only |
|
270 | - if ($get[$key] === "") { |
|
271 | - return true; |
|
272 | - } |
|
273 | - |
|
274 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
275 | - return false; |
|
276 | - } |
|
277 | - |
|
278 | - return true; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * @param string $key |
|
283 | - * |
|
284 | - * @return int|null |
|
285 | - */ |
|
286 | - public static function getInt($key) |
|
287 | - { |
|
288 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
289 | - if (!array_key_exists($key, $get)) { |
|
290 | - return null; |
|
291 | - } |
|
292 | - |
|
293 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
294 | - |
|
295 | - if ($filteredValue === null) { |
|
296 | - return null; |
|
297 | - } |
|
298 | - |
|
299 | - return (int)$filteredValue; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param string $key |
|
304 | - * |
|
305 | - * @return null|string |
|
306 | - */ |
|
307 | - public static function getString($key) |
|
308 | - { |
|
309 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
310 | - if (!array_key_exists($key, $get)) { |
|
311 | - return null; |
|
312 | - } |
|
313 | - |
|
314 | - if ($get[$key] === "") { |
|
315 | - return null; |
|
316 | - } |
|
317 | - |
|
318 | - return (string)$get[$key]; |
|
319 | - } |
|
320 | - |
|
321 | - #endregion |
|
322 | - |
|
323 | - /** |
|
324 | - * Sets the logged-in user to the specified user. |
|
325 | - * |
|
326 | - * @param User $user |
|
327 | - */ |
|
328 | - public static function setLoggedInUser(User $user) |
|
329 | - { |
|
330 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
331 | - |
|
332 | - $session['userID'] = $user->getId(); |
|
333 | - unset($session['partialLogin']); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Sets the post-login redirect |
|
338 | - * |
|
339 | - * @param string|null $uri The URI to redirect to |
|
340 | - */ |
|
341 | - public static function setPostLoginRedirect($uri = null) |
|
342 | - { |
|
343 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
344 | - |
|
345 | - if ($uri === null) { |
|
346 | - $uri = self::requestUri(); |
|
347 | - } |
|
348 | - |
|
349 | - $session['returnTo'] = $uri; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * @return string|null |
|
354 | - */ |
|
355 | - public static function requestUri() |
|
356 | - { |
|
357 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
358 | - |
|
359 | - if (isset($server['REQUEST_URI'])) { |
|
360 | - return $server['REQUEST_URI']; |
|
361 | - } |
|
362 | - |
|
363 | - return null; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Clears the post-login redirect |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - public static function clearPostLoginRedirect() |
|
371 | - { |
|
372 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
373 | - if (array_key_exists('returnTo', $session)) { |
|
374 | - $path = $session['returnTo']; |
|
375 | - unset($session['returnTo']); |
|
376 | - |
|
377 | - return $path; |
|
378 | - } |
|
379 | - |
|
380 | - return null; |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * @return string|null |
|
385 | - */ |
|
386 | - public static function serverName() |
|
387 | - { |
|
388 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
389 | - |
|
390 | - if (isset($server['SERVER_NAME'])) { |
|
391 | - return $server['SERVER_NAME']; |
|
392 | - } |
|
393 | - |
|
394 | - return null; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * You probably only want to deal with this through SessionAlert. |
|
399 | - * @return void |
|
400 | - */ |
|
401 | - public static function clearSessionAlertData() |
|
402 | - { |
|
403 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
404 | - if (array_key_exists('alerts', $session)) { |
|
405 | - unset($session['alerts']); |
|
406 | - } |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * You probably only want to deal with this through SessionAlert. |
|
411 | - * |
|
412 | - * @return string[] |
|
413 | - */ |
|
414 | - public static function getSessionAlertData() |
|
415 | - { |
|
416 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
417 | - if (array_key_exists('alerts', $session)) { |
|
418 | - return $session['alerts']; |
|
419 | - } |
|
420 | - |
|
421 | - return array(); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * You probably only want to deal with this through SessionAlert. |
|
426 | - * |
|
427 | - * @param string[] $data |
|
428 | - */ |
|
429 | - public static function setSessionAlertData($data) |
|
430 | - { |
|
431 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
432 | - $session['alerts'] = $data; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * You probably only want to deal with this through TokenManager. |
|
437 | - * |
|
438 | - * @return string[] |
|
439 | - */ |
|
440 | - public static function getSessionTokenData() |
|
441 | - { |
|
442 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
443 | - if (array_key_exists('tokens', $session)) { |
|
444 | - return $session['tokens']; |
|
445 | - } |
|
446 | - |
|
447 | - return array(); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * You probably only want to deal with this through TokenManager. |
|
452 | - * |
|
453 | - * @param string[] $data |
|
454 | - */ |
|
455 | - public static function setSessionTokenData($data) |
|
456 | - { |
|
457 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
458 | - $session['tokens'] = $data; |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * @param string $key |
|
463 | - * |
|
464 | - * @return mixed |
|
465 | - */ |
|
466 | - public static function getSessionContext($key) |
|
467 | - { |
|
468 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
469 | - |
|
470 | - if (!isset($session['context'])) { |
|
471 | - $session['context'] = array(); |
|
472 | - } |
|
473 | - |
|
474 | - if (!isset($session['context'][$key])) { |
|
475 | - return null; |
|
476 | - } |
|
477 | - |
|
478 | - return $session['context'][$key]; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * @param string $key |
|
483 | - * @param mixed $data |
|
484 | - */ |
|
485 | - public static function setSessionContext($key, $data) |
|
486 | - { |
|
487 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
488 | - |
|
489 | - if (!isset($session['context'])) { |
|
490 | - $session['context'] = array(); |
|
491 | - } |
|
492 | - |
|
493 | - $session['context'][$key] = $data; |
|
494 | - } |
|
495 | - |
|
496 | - /** |
|
497 | - * @return int|null |
|
498 | - */ |
|
499 | - public static function getSessionUserId() |
|
500 | - { |
|
501 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
502 | - |
|
503 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * @param User $user |
|
508 | - */ |
|
509 | - public static function setOAuthPartialLogin(User $user) |
|
510 | - { |
|
511 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
512 | - $session['oauthPartialLogin'] = $user->getId(); |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * @return int|null |
|
517 | - */ |
|
518 | - public static function getOAuthPartialLogin() |
|
519 | - { |
|
520 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
521 | - |
|
522 | - return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
523 | - } |
|
524 | - |
|
525 | - public static function setAuthPartialLogin($userId, $stage) |
|
526 | - { |
|
527 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
528 | - $session['authPartialLoginId'] = $userId; |
|
529 | - $session['authPartialLoginStage'] = $stage; |
|
530 | - } |
|
531 | - |
|
532 | - public static function getAuthPartialLogin() |
|
533 | - { |
|
534 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
535 | - |
|
536 | - $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
537 | - $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
538 | - |
|
539 | - return array($userId, $stage); |
|
540 | - } |
|
541 | - |
|
542 | - public static function clearAuthPartialLogin() |
|
543 | - { |
|
544 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
545 | - unset($session['authPartialLoginId']); |
|
546 | - unset($session['authPartialLoginStage']); |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * @return null|string |
|
551 | - */ |
|
552 | - public static function userAgent() |
|
553 | - { |
|
554 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
555 | - |
|
556 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
557 | - return $server['HTTP_USER_AGENT']; |
|
558 | - } |
|
559 | - |
|
560 | - return null; |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * @return null|string |
|
565 | - */ |
|
566 | - public static function scriptName() |
|
567 | - { |
|
568 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
569 | - |
|
570 | - if (isset($server['SCRIPT_NAME'])) { |
|
571 | - return $server['SCRIPT_NAME']; |
|
572 | - } |
|
573 | - |
|
574 | - return null; |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * @return null|string |
|
579 | - */ |
|
580 | - public static function origin() |
|
581 | - { |
|
582 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
583 | - |
|
584 | - if (isset($server['HTTP_ORIGIN'])) { |
|
585 | - return $server['HTTP_ORIGIN']; |
|
586 | - } |
|
587 | - |
|
588 | - return null; |
|
589 | - } |
|
590 | - |
|
591 | - public static function testSiteNoticeCookieValue($expectedHash) |
|
592 | - { |
|
593 | - $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
|
594 | - |
|
595 | - if(isset($cookie['sitenotice'])) { |
|
596 | - return $cookie['sitenotice'] === $expectedHash; |
|
597 | - } |
|
598 | - |
|
599 | - return false; |
|
600 | - } |
|
27 | + /** |
|
28 | + * @var IGlobalStateProvider Provides access to the global state. |
|
29 | + */ |
|
30 | + private static $globalStateProvider; |
|
31 | + |
|
32 | + /** |
|
33 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public static function wasPosted() |
|
37 | + { |
|
38 | + return self::method() === 'POST'; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Gets the HTTP Method used |
|
43 | + * @return string|null |
|
44 | + */ |
|
45 | + public static function method() |
|
46 | + { |
|
47 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
48 | + |
|
49 | + if (isset($server['REQUEST_METHOD'])) { |
|
50 | + return $server['REQUEST_METHOD']; |
|
51 | + } |
|
52 | + |
|
53 | + return null; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public static function isHttps() |
|
61 | + { |
|
62 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
63 | + |
|
64 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
65 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
66 | + // Client <=> Proxy is encrypted |
|
67 | + return true; |
|
68 | + } |
|
69 | + else { |
|
70 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
71 | + return false; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + if (isset($server['HTTPS'])) { |
|
76 | + if ($server['HTTPS'] === 'off') { |
|
77 | + // ISAPI on IIS breaks the spec. :( |
|
78 | + return false; |
|
79 | + } |
|
80 | + |
|
81 | + if ($server['HTTPS'] !== '') { |
|
82 | + // Set to a non-empty value |
|
83 | + return true; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + return false; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Gets the path info |
|
92 | + * |
|
93 | + * @return array Array of path info segments |
|
94 | + */ |
|
95 | + public static function pathInfo() |
|
96 | + { |
|
97 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
98 | + if (!isset($server['PATH_INFO'])) { |
|
99 | + return array(); |
|
100 | + } |
|
101 | + |
|
102 | + $exploded = explode('/', $server['PATH_INFO']); |
|
103 | + |
|
104 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
105 | + // with a / |
|
106 | + return array_values(array_filter($exploded)); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Gets the remote address of the web request |
|
111 | + * @return null|string |
|
112 | + */ |
|
113 | + public static function remoteAddress() |
|
114 | + { |
|
115 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
116 | + |
|
117 | + if (isset($server['REMOTE_ADDR'])) { |
|
118 | + return $server['REMOTE_ADDR']; |
|
119 | + } |
|
120 | + |
|
121 | + return null; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Gets the remote address of the web request |
|
126 | + * @return null|string |
|
127 | + */ |
|
128 | + public static function httpHost() |
|
129 | + { |
|
130 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
131 | + |
|
132 | + if (isset($server['HTTP_HOST'])) { |
|
133 | + return $server['HTTP_HOST']; |
|
134 | + } |
|
135 | + |
|
136 | + return null; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Gets the XFF header contents for the web request |
|
141 | + * @return null|string |
|
142 | + */ |
|
143 | + public static function forwardedAddress() |
|
144 | + { |
|
145 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
146 | + |
|
147 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
148 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
149 | + } |
|
150 | + |
|
151 | + return null; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Sets the global state provider. |
|
156 | + * |
|
157 | + * Almost guaranteed this is not the method you want in production code. |
|
158 | + * |
|
159 | + * @param IGlobalStateProvider $globalState |
|
160 | + */ |
|
161 | + public static function setGlobalStateProvider($globalState) |
|
162 | + { |
|
163 | + self::$globalStateProvider = $globalState; |
|
164 | + } |
|
165 | + |
|
166 | + #region POST variables |
|
167 | + |
|
168 | + /** |
|
169 | + * @param string $key |
|
170 | + * |
|
171 | + * @return null|string |
|
172 | + */ |
|
173 | + public static function postString($key) |
|
174 | + { |
|
175 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
176 | + if (!array_key_exists($key, $post)) { |
|
177 | + return null; |
|
178 | + } |
|
179 | + |
|
180 | + if ($post[$key] === "") { |
|
181 | + return null; |
|
182 | + } |
|
183 | + |
|
184 | + return (string)$post[$key]; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param string $key |
|
189 | + * |
|
190 | + * @return null|string |
|
191 | + */ |
|
192 | + public static function postEmail($key) |
|
193 | + { |
|
194 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
195 | + if (!array_key_exists($key, $post)) { |
|
196 | + return null; |
|
197 | + } |
|
198 | + |
|
199 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
200 | + |
|
201 | + if ($filteredValue === false) { |
|
202 | + return null; |
|
203 | + } |
|
204 | + |
|
205 | + return (string)$filteredValue; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param string $key |
|
210 | + * |
|
211 | + * @return int|null |
|
212 | + */ |
|
213 | + public static function postInt($key) |
|
214 | + { |
|
215 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
216 | + if (!array_key_exists($key, $post)) { |
|
217 | + return null; |
|
218 | + } |
|
219 | + |
|
220 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
221 | + |
|
222 | + if ($filteredValue === null) { |
|
223 | + return null; |
|
224 | + } |
|
225 | + |
|
226 | + return (int)$filteredValue; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string $key |
|
231 | + * |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public static function postBoolean($key) |
|
235 | + { |
|
236 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
237 | + if (!array_key_exists($key, $get)) { |
|
238 | + return false; |
|
239 | + } |
|
240 | + |
|
241 | + // presence of parameter only |
|
242 | + if ($get[$key] === "") { |
|
243 | + return true; |
|
244 | + } |
|
245 | + |
|
246 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
247 | + return false; |
|
248 | + } |
|
249 | + |
|
250 | + return true; |
|
251 | + } |
|
252 | + |
|
253 | + #endregion |
|
254 | + |
|
255 | + #region GET variables |
|
256 | + |
|
257 | + /** |
|
258 | + * @param string $key |
|
259 | + * |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public static function getBoolean($key) |
|
263 | + { |
|
264 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
265 | + if (!array_key_exists($key, $get)) { |
|
266 | + return false; |
|
267 | + } |
|
268 | + |
|
269 | + // presence of parameter only |
|
270 | + if ($get[$key] === "") { |
|
271 | + return true; |
|
272 | + } |
|
273 | + |
|
274 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
275 | + return false; |
|
276 | + } |
|
277 | + |
|
278 | + return true; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * @param string $key |
|
283 | + * |
|
284 | + * @return int|null |
|
285 | + */ |
|
286 | + public static function getInt($key) |
|
287 | + { |
|
288 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
289 | + if (!array_key_exists($key, $get)) { |
|
290 | + return null; |
|
291 | + } |
|
292 | + |
|
293 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
294 | + |
|
295 | + if ($filteredValue === null) { |
|
296 | + return null; |
|
297 | + } |
|
298 | + |
|
299 | + return (int)$filteredValue; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param string $key |
|
304 | + * |
|
305 | + * @return null|string |
|
306 | + */ |
|
307 | + public static function getString($key) |
|
308 | + { |
|
309 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
310 | + if (!array_key_exists($key, $get)) { |
|
311 | + return null; |
|
312 | + } |
|
313 | + |
|
314 | + if ($get[$key] === "") { |
|
315 | + return null; |
|
316 | + } |
|
317 | + |
|
318 | + return (string)$get[$key]; |
|
319 | + } |
|
320 | + |
|
321 | + #endregion |
|
322 | + |
|
323 | + /** |
|
324 | + * Sets the logged-in user to the specified user. |
|
325 | + * |
|
326 | + * @param User $user |
|
327 | + */ |
|
328 | + public static function setLoggedInUser(User $user) |
|
329 | + { |
|
330 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
331 | + |
|
332 | + $session['userID'] = $user->getId(); |
|
333 | + unset($session['partialLogin']); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Sets the post-login redirect |
|
338 | + * |
|
339 | + * @param string|null $uri The URI to redirect to |
|
340 | + */ |
|
341 | + public static function setPostLoginRedirect($uri = null) |
|
342 | + { |
|
343 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
344 | + |
|
345 | + if ($uri === null) { |
|
346 | + $uri = self::requestUri(); |
|
347 | + } |
|
348 | + |
|
349 | + $session['returnTo'] = $uri; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * @return string|null |
|
354 | + */ |
|
355 | + public static function requestUri() |
|
356 | + { |
|
357 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
358 | + |
|
359 | + if (isset($server['REQUEST_URI'])) { |
|
360 | + return $server['REQUEST_URI']; |
|
361 | + } |
|
362 | + |
|
363 | + return null; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Clears the post-login redirect |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + public static function clearPostLoginRedirect() |
|
371 | + { |
|
372 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
373 | + if (array_key_exists('returnTo', $session)) { |
|
374 | + $path = $session['returnTo']; |
|
375 | + unset($session['returnTo']); |
|
376 | + |
|
377 | + return $path; |
|
378 | + } |
|
379 | + |
|
380 | + return null; |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * @return string|null |
|
385 | + */ |
|
386 | + public static function serverName() |
|
387 | + { |
|
388 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
389 | + |
|
390 | + if (isset($server['SERVER_NAME'])) { |
|
391 | + return $server['SERVER_NAME']; |
|
392 | + } |
|
393 | + |
|
394 | + return null; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * You probably only want to deal with this through SessionAlert. |
|
399 | + * @return void |
|
400 | + */ |
|
401 | + public static function clearSessionAlertData() |
|
402 | + { |
|
403 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
404 | + if (array_key_exists('alerts', $session)) { |
|
405 | + unset($session['alerts']); |
|
406 | + } |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * You probably only want to deal with this through SessionAlert. |
|
411 | + * |
|
412 | + * @return string[] |
|
413 | + */ |
|
414 | + public static function getSessionAlertData() |
|
415 | + { |
|
416 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
417 | + if (array_key_exists('alerts', $session)) { |
|
418 | + return $session['alerts']; |
|
419 | + } |
|
420 | + |
|
421 | + return array(); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * You probably only want to deal with this through SessionAlert. |
|
426 | + * |
|
427 | + * @param string[] $data |
|
428 | + */ |
|
429 | + public static function setSessionAlertData($data) |
|
430 | + { |
|
431 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
432 | + $session['alerts'] = $data; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * You probably only want to deal with this through TokenManager. |
|
437 | + * |
|
438 | + * @return string[] |
|
439 | + */ |
|
440 | + public static function getSessionTokenData() |
|
441 | + { |
|
442 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
443 | + if (array_key_exists('tokens', $session)) { |
|
444 | + return $session['tokens']; |
|
445 | + } |
|
446 | + |
|
447 | + return array(); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * You probably only want to deal with this through TokenManager. |
|
452 | + * |
|
453 | + * @param string[] $data |
|
454 | + */ |
|
455 | + public static function setSessionTokenData($data) |
|
456 | + { |
|
457 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
458 | + $session['tokens'] = $data; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * @param string $key |
|
463 | + * |
|
464 | + * @return mixed |
|
465 | + */ |
|
466 | + public static function getSessionContext($key) |
|
467 | + { |
|
468 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
469 | + |
|
470 | + if (!isset($session['context'])) { |
|
471 | + $session['context'] = array(); |
|
472 | + } |
|
473 | + |
|
474 | + if (!isset($session['context'][$key])) { |
|
475 | + return null; |
|
476 | + } |
|
477 | + |
|
478 | + return $session['context'][$key]; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * @param string $key |
|
483 | + * @param mixed $data |
|
484 | + */ |
|
485 | + public static function setSessionContext($key, $data) |
|
486 | + { |
|
487 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
488 | + |
|
489 | + if (!isset($session['context'])) { |
|
490 | + $session['context'] = array(); |
|
491 | + } |
|
492 | + |
|
493 | + $session['context'][$key] = $data; |
|
494 | + } |
|
495 | + |
|
496 | + /** |
|
497 | + * @return int|null |
|
498 | + */ |
|
499 | + public static function getSessionUserId() |
|
500 | + { |
|
501 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
502 | + |
|
503 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * @param User $user |
|
508 | + */ |
|
509 | + public static function setOAuthPartialLogin(User $user) |
|
510 | + { |
|
511 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
512 | + $session['oauthPartialLogin'] = $user->getId(); |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * @return int|null |
|
517 | + */ |
|
518 | + public static function getOAuthPartialLogin() |
|
519 | + { |
|
520 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
521 | + |
|
522 | + return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
523 | + } |
|
524 | + |
|
525 | + public static function setAuthPartialLogin($userId, $stage) |
|
526 | + { |
|
527 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
528 | + $session['authPartialLoginId'] = $userId; |
|
529 | + $session['authPartialLoginStage'] = $stage; |
|
530 | + } |
|
531 | + |
|
532 | + public static function getAuthPartialLogin() |
|
533 | + { |
|
534 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
535 | + |
|
536 | + $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
537 | + $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
538 | + |
|
539 | + return array($userId, $stage); |
|
540 | + } |
|
541 | + |
|
542 | + public static function clearAuthPartialLogin() |
|
543 | + { |
|
544 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
545 | + unset($session['authPartialLoginId']); |
|
546 | + unset($session['authPartialLoginStage']); |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * @return null|string |
|
551 | + */ |
|
552 | + public static function userAgent() |
|
553 | + { |
|
554 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
555 | + |
|
556 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
557 | + return $server['HTTP_USER_AGENT']; |
|
558 | + } |
|
559 | + |
|
560 | + return null; |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * @return null|string |
|
565 | + */ |
|
566 | + public static function scriptName() |
|
567 | + { |
|
568 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
569 | + |
|
570 | + if (isset($server['SCRIPT_NAME'])) { |
|
571 | + return $server['SCRIPT_NAME']; |
|
572 | + } |
|
573 | + |
|
574 | + return null; |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * @return null|string |
|
579 | + */ |
|
580 | + public static function origin() |
|
581 | + { |
|
582 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
583 | + |
|
584 | + if (isset($server['HTTP_ORIGIN'])) { |
|
585 | + return $server['HTTP_ORIGIN']; |
|
586 | + } |
|
587 | + |
|
588 | + return null; |
|
589 | + } |
|
590 | + |
|
591 | + public static function testSiteNoticeCookieValue($expectedHash) |
|
592 | + { |
|
593 | + $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
|
594 | + |
|
595 | + if(isset($cookie['sitenotice'])) { |
|
596 | + return $cookie['sitenotice'] === $expectedHash; |
|
597 | + } |
|
598 | + |
|
599 | + return false; |
|
600 | + } |
|
601 | 601 | } |
@@ -592,7 +592,7 @@ |
||
592 | 592 | { |
593 | 593 | $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
594 | 594 | |
595 | - if(isset($cookie['sitenotice'])) { |
|
595 | + if (isset($cookie['sitenotice'])) { |
|
596 | 596 | return $cookie['sitenotice'] === $expectedHash; |
597 | 597 | } |
598 | 598 |
@@ -15,8 +15,8 @@ |
||
15 | 15 | */ |
16 | 16 | class FakeLocationProvider implements ILocationProvider |
17 | 17 | { |
18 | - public function getIpLocation($address) |
|
19 | - { |
|
20 | - return null; |
|
21 | - } |
|
18 | + public function getIpLocation($address) |
|
19 | + { |
|
20 | + return null; |
|
21 | + } |
|
22 | 22 | } |
@@ -13,10 +13,10 @@ |
||
13 | 13 | */ |
14 | 14 | interface ILocationProvider |
15 | 15 | { |
16 | - /** |
|
17 | - * @param string $address IP address |
|
18 | - * |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function getIpLocation($address); |
|
16 | + /** |
|
17 | + * @param string $address IP address |
|
18 | + * |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function getIpLocation($address); |
|
22 | 22 | } |