@@ -14,50 +14,50 @@ |
||
14 | 14 | |
15 | 15 | class RequestEmailHelper |
16 | 16 | { |
17 | - /** |
|
18 | - * @var IEmailHelper |
|
19 | - */ |
|
20 | - private $emailHelper; |
|
21 | - |
|
22 | - /** |
|
23 | - * RequestEmailHelper constructor. |
|
24 | - * |
|
25 | - * @param IEmailHelper $emailHelper |
|
26 | - */ |
|
27 | - public function __construct(IEmailHelper $emailHelper) |
|
28 | - { |
|
29 | - $this->emailHelper = $emailHelper; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * @param Request $request |
|
34 | - * @param string $mailText |
|
35 | - * @param User $currentUser |
|
36 | - * @param boolean $ccMailingList |
|
37 | - */ |
|
38 | - public function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
39 | - { |
|
40 | - $headers = array( |
|
41 | - 'X-ACC-Request' => $request->getId(), |
|
42 | - 'X-ACC-UserID' => $currentUser->getId(), |
|
43 | - ); |
|
44 | - |
|
45 | - if ($ccMailingList) { |
|
46 | - $headers['Cc'] = '[email protected]'; |
|
47 | - } |
|
48 | - |
|
49 | - $helper = $this->emailHelper; |
|
50 | - |
|
51 | - $emailSig = $currentUser->getEmailSig(); |
|
52 | - if ($emailSig !== '' || $emailSig !== null) { |
|
53 | - $emailSig = "\n\n" . $emailSig; |
|
54 | - } |
|
55 | - |
|
56 | - $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
57 | - $content = $mailText . $emailSig; |
|
58 | - |
|
59 | - $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
60 | - |
|
61 | - $request->setEmailSent(true); |
|
62 | - } |
|
17 | + /** |
|
18 | + * @var IEmailHelper |
|
19 | + */ |
|
20 | + private $emailHelper; |
|
21 | + |
|
22 | + /** |
|
23 | + * RequestEmailHelper constructor. |
|
24 | + * |
|
25 | + * @param IEmailHelper $emailHelper |
|
26 | + */ |
|
27 | + public function __construct(IEmailHelper $emailHelper) |
|
28 | + { |
|
29 | + $this->emailHelper = $emailHelper; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * @param Request $request |
|
34 | + * @param string $mailText |
|
35 | + * @param User $currentUser |
|
36 | + * @param boolean $ccMailingList |
|
37 | + */ |
|
38 | + public function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
39 | + { |
|
40 | + $headers = array( |
|
41 | + 'X-ACC-Request' => $request->getId(), |
|
42 | + 'X-ACC-UserID' => $currentUser->getId(), |
|
43 | + ); |
|
44 | + |
|
45 | + if ($ccMailingList) { |
|
46 | + $headers['Cc'] = '[email protected]'; |
|
47 | + } |
|
48 | + |
|
49 | + $helper = $this->emailHelper; |
|
50 | + |
|
51 | + $emailSig = $currentUser->getEmailSig(); |
|
52 | + if ($emailSig !== '' || $emailSig !== null) { |
|
53 | + $emailSig = "\n\n" . $emailSig; |
|
54 | + } |
|
55 | + |
|
56 | + $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
57 | + $content = $mailText . $emailSig; |
|
58 | + |
|
59 | + $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
60 | + |
|
61 | + $request->setEmailSent(true); |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -239,11 +239,11 @@ |
||
239 | 239 | |
240 | 240 | $emailSig = $currentUser->getEmailSig(); |
241 | 241 | if ($emailSig !== '' || $emailSig !== null) { |
242 | - $emailSig = "\n\n" . $emailSig; |
|
242 | + $emailSig = "\n\n".$emailSig; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
246 | - $content = $mailText . $emailSig; |
|
246 | + $content = $mailText.$emailSig; |
|
247 | 247 | |
248 | 248 | $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
249 | 249 |
@@ -22,233 +22,233 @@ |
||
22 | 22 | |
23 | 23 | class OAuthProtocolHelper implements IOAuthProtocolHelper |
24 | 24 | { |
25 | - private $oauthConsumer; |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - private $oauthEndpoint; |
|
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private $consumerToken; |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $consumerSecret; |
|
38 | - /** |
|
39 | - * @var HttpHelper |
|
40 | - */ |
|
41 | - private $httpHelper; |
|
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - private $mediawikiWebServiceEndpoint; |
|
46 | - |
|
47 | - /** |
|
48 | - * OAuthHelper constructor. |
|
49 | - * |
|
50 | - * @param string $oauthEndpoint |
|
51 | - * @param string $consumerKey |
|
52 | - * @param string $consumerSecret |
|
53 | - * @param HttpHelper $httpHelper |
|
54 | - * @param string $mediawikiWebServiceEndpoint |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - $oauthEndpoint, |
|
58 | - $consumerKey, |
|
59 | - $consumerSecret, |
|
60 | - HttpHelper $httpHelper, |
|
61 | - $mediawikiWebServiceEndpoint |
|
62 | - ) { |
|
63 | - $this->oauthEndpoint = $oauthEndpoint; |
|
64 | - $this->consumerToken = $consumerKey; |
|
65 | - $this->consumerSecret = $consumerSecret; |
|
66 | - $this->httpHelper = $httpHelper; |
|
67 | - |
|
68 | - $this->oauthConsumer = new OAuthConsumer($this->consumerToken, $this->consumerSecret); |
|
69 | - $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @return stdClass |
|
74 | - * |
|
75 | - * @throws Exception |
|
76 | - * @throws CurlException |
|
77 | - */ |
|
78 | - public function getRequestToken() |
|
79 | - { |
|
80 | - $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob'; |
|
81 | - |
|
82 | - $parsedUrl = parse_url($endpoint); |
|
83 | - $urlParameters = array(); |
|
84 | - parse_str($parsedUrl['query'], $urlParameters); |
|
85 | - |
|
86 | - $req_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, null, 'GET', $endpoint, $urlParameters); |
|
87 | - $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
88 | - $req_req->sign_request($hmac_method, $this->oauthConsumer, null); |
|
89 | - |
|
90 | - $targetUrl = (string)$req_req; |
|
91 | - |
|
92 | - $data = $this->httpHelper->get($targetUrl, null); |
|
93 | - |
|
94 | - if ($data === false) { |
|
95 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
96 | - } |
|
97 | - |
|
98 | - $token = json_decode($data); |
|
99 | - |
|
100 | - if (!isset($token)) { |
|
101 | - throw new OAuthException('Unknown error encountered getting request token while decoding json data.'); |
|
102 | - } |
|
103 | - |
|
104 | - if (isset($token->error)) { |
|
105 | - throw new OAuthException('Error encountered while getting request token: ' . $token->error); |
|
106 | - } |
|
107 | - |
|
108 | - return $token; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param string $requestToken |
|
113 | - * |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function getAuthoriseUrl($requestToken) |
|
117 | - { |
|
118 | - return "{$this->oauthEndpoint}/authorize&oauth_token={$requestToken}&oauth_consumer_key={$this->consumerToken}"; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $oauthRequestToken |
|
123 | - * @param string $oauthRequestSecret |
|
124 | - * @param string $oauthVerifier |
|
125 | - * |
|
126 | - * @return stdClass |
|
127 | - * @throws CurlException |
|
128 | - * @throws Exception |
|
129 | - */ |
|
130 | - public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier) |
|
131 | - { |
|
132 | - $endpoint = $this->oauthEndpoint . '/token&format=json'; |
|
133 | - |
|
134 | - $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret); |
|
135 | - |
|
136 | - $parsedUrl = parse_url($endpoint); |
|
137 | - parse_str($parsedUrl['query'], $urlParameters); |
|
138 | - $urlParameters['oauth_verifier'] = trim($oauthVerifier); |
|
139 | - |
|
140 | - $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $requestConsumer, 'GET', $endpoint, |
|
141 | - $urlParameters); |
|
142 | - $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
143 | - $acc_req->sign_request($hmac_method, $this->oauthConsumer, $requestConsumer); |
|
144 | - |
|
145 | - $targetUrl = (string)$acc_req; |
|
146 | - |
|
147 | - $data = $this->httpHelper->get($targetUrl, null); |
|
148 | - |
|
149 | - if ($data === false) { |
|
150 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
151 | - } |
|
152 | - |
|
153 | - $token = json_decode($data); |
|
154 | - |
|
155 | - if (!isset($token)) { |
|
156 | - throw new OAuthException('Unknown error encountered getting access token while decoding json data.'); |
|
157 | - } |
|
158 | - |
|
159 | - if (isset($token->error)) { |
|
160 | - throw new OAuthException('Error encountered while getting access token: ' . $token->error); |
|
161 | - } |
|
162 | - |
|
163 | - return $token; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $oauthAccessToken |
|
168 | - * @param string $oauthAccessSecret |
|
169 | - * |
|
170 | - * @return stdClass |
|
171 | - * @throws CurlException |
|
172 | - * @throws Exception |
|
173 | - */ |
|
174 | - public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret) |
|
175 | - { |
|
176 | - $endpoint = $this->oauthEndpoint . '/identify&format=json'; |
|
177 | - |
|
178 | - $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret); |
|
179 | - |
|
180 | - $parsedUrl = parse_url($endpoint); |
|
181 | - parse_str($parsedUrl['query'], $urlParameters); |
|
182 | - |
|
183 | - $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $oauthToken, 'GET', $endpoint, |
|
184 | - $urlParameters); |
|
185 | - $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
186 | - $acc_req->sign_request($hmac_method, $this->oauthConsumer, $oauthToken); |
|
187 | - |
|
188 | - $targetUrl = (string)$acc_req; |
|
189 | - |
|
190 | - $data = $this->httpHelper->get($targetUrl, null); |
|
191 | - |
|
192 | - if ($data === false) { |
|
193 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
194 | - } |
|
195 | - |
|
196 | - $decodedData = json_decode($data); |
|
197 | - |
|
198 | - if (isset($decodedData->error)) { |
|
199 | - throw new OAuthException($decodedData->error); |
|
200 | - } |
|
201 | - |
|
202 | - $identity = JWT::decode($data, $this->consumerSecret); |
|
203 | - |
|
204 | - return $identity; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @param array $apiParams array of parameters to send to the API |
|
209 | - * @param string $accessToken user's access token |
|
210 | - * @param string $accessSecret user's secret |
|
211 | - * @param string $method HTTP method |
|
212 | - * |
|
213 | - * @return stdClass |
|
214 | - * @throws ApplicationLogicException |
|
215 | - * @throws CurlException |
|
216 | - * @throws Exception |
|
217 | - */ |
|
218 | - public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET') |
|
219 | - { |
|
220 | - $userToken = new OAuthToken($accessToken, $accessSecret); |
|
221 | - |
|
222 | - $apiParams['format'] = 'json'; |
|
223 | - |
|
224 | - $api_req = OAuthRequest::from_consumer_and_token( |
|
225 | - $this->oauthConsumer, // Consumer |
|
226 | - $userToken, // User Access Token |
|
227 | - $method, // HTTP Method |
|
228 | - $this->mediawikiWebServiceEndpoint, // Endpoint url |
|
229 | - $apiParams // Extra signed parameters |
|
230 | - ); |
|
25 | + private $oauthConsumer; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + private $oauthEndpoint; |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private $consumerToken; |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $consumerSecret; |
|
38 | + /** |
|
39 | + * @var HttpHelper |
|
40 | + */ |
|
41 | + private $httpHelper; |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + private $mediawikiWebServiceEndpoint; |
|
46 | + |
|
47 | + /** |
|
48 | + * OAuthHelper constructor. |
|
49 | + * |
|
50 | + * @param string $oauthEndpoint |
|
51 | + * @param string $consumerKey |
|
52 | + * @param string $consumerSecret |
|
53 | + * @param HttpHelper $httpHelper |
|
54 | + * @param string $mediawikiWebServiceEndpoint |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + $oauthEndpoint, |
|
58 | + $consumerKey, |
|
59 | + $consumerSecret, |
|
60 | + HttpHelper $httpHelper, |
|
61 | + $mediawikiWebServiceEndpoint |
|
62 | + ) { |
|
63 | + $this->oauthEndpoint = $oauthEndpoint; |
|
64 | + $this->consumerToken = $consumerKey; |
|
65 | + $this->consumerSecret = $consumerSecret; |
|
66 | + $this->httpHelper = $httpHelper; |
|
67 | + |
|
68 | + $this->oauthConsumer = new OAuthConsumer($this->consumerToken, $this->consumerSecret); |
|
69 | + $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @return stdClass |
|
74 | + * |
|
75 | + * @throws Exception |
|
76 | + * @throws CurlException |
|
77 | + */ |
|
78 | + public function getRequestToken() |
|
79 | + { |
|
80 | + $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob'; |
|
81 | + |
|
82 | + $parsedUrl = parse_url($endpoint); |
|
83 | + $urlParameters = array(); |
|
84 | + parse_str($parsedUrl['query'], $urlParameters); |
|
85 | + |
|
86 | + $req_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, null, 'GET', $endpoint, $urlParameters); |
|
87 | + $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
88 | + $req_req->sign_request($hmac_method, $this->oauthConsumer, null); |
|
89 | + |
|
90 | + $targetUrl = (string)$req_req; |
|
91 | + |
|
92 | + $data = $this->httpHelper->get($targetUrl, null); |
|
93 | + |
|
94 | + if ($data === false) { |
|
95 | + throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
96 | + } |
|
97 | + |
|
98 | + $token = json_decode($data); |
|
99 | + |
|
100 | + if (!isset($token)) { |
|
101 | + throw new OAuthException('Unknown error encountered getting request token while decoding json data.'); |
|
102 | + } |
|
103 | + |
|
104 | + if (isset($token->error)) { |
|
105 | + throw new OAuthException('Error encountered while getting request token: ' . $token->error); |
|
106 | + } |
|
107 | + |
|
108 | + return $token; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param string $requestToken |
|
113 | + * |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function getAuthoriseUrl($requestToken) |
|
117 | + { |
|
118 | + return "{$this->oauthEndpoint}/authorize&oauth_token={$requestToken}&oauth_consumer_key={$this->consumerToken}"; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $oauthRequestToken |
|
123 | + * @param string $oauthRequestSecret |
|
124 | + * @param string $oauthVerifier |
|
125 | + * |
|
126 | + * @return stdClass |
|
127 | + * @throws CurlException |
|
128 | + * @throws Exception |
|
129 | + */ |
|
130 | + public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier) |
|
131 | + { |
|
132 | + $endpoint = $this->oauthEndpoint . '/token&format=json'; |
|
133 | + |
|
134 | + $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret); |
|
135 | + |
|
136 | + $parsedUrl = parse_url($endpoint); |
|
137 | + parse_str($parsedUrl['query'], $urlParameters); |
|
138 | + $urlParameters['oauth_verifier'] = trim($oauthVerifier); |
|
139 | + |
|
140 | + $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $requestConsumer, 'GET', $endpoint, |
|
141 | + $urlParameters); |
|
142 | + $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
143 | + $acc_req->sign_request($hmac_method, $this->oauthConsumer, $requestConsumer); |
|
144 | + |
|
145 | + $targetUrl = (string)$acc_req; |
|
146 | + |
|
147 | + $data = $this->httpHelper->get($targetUrl, null); |
|
148 | + |
|
149 | + if ($data === false) { |
|
150 | + throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
151 | + } |
|
152 | + |
|
153 | + $token = json_decode($data); |
|
154 | + |
|
155 | + if (!isset($token)) { |
|
156 | + throw new OAuthException('Unknown error encountered getting access token while decoding json data.'); |
|
157 | + } |
|
158 | + |
|
159 | + if (isset($token->error)) { |
|
160 | + throw new OAuthException('Error encountered while getting access token: ' . $token->error); |
|
161 | + } |
|
162 | + |
|
163 | + return $token; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $oauthAccessToken |
|
168 | + * @param string $oauthAccessSecret |
|
169 | + * |
|
170 | + * @return stdClass |
|
171 | + * @throws CurlException |
|
172 | + * @throws Exception |
|
173 | + */ |
|
174 | + public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret) |
|
175 | + { |
|
176 | + $endpoint = $this->oauthEndpoint . '/identify&format=json'; |
|
177 | + |
|
178 | + $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret); |
|
179 | + |
|
180 | + $parsedUrl = parse_url($endpoint); |
|
181 | + parse_str($parsedUrl['query'], $urlParameters); |
|
182 | + |
|
183 | + $acc_req = OAuthRequest::from_consumer_and_token($this->oauthConsumer, $oauthToken, 'GET', $endpoint, |
|
184 | + $urlParameters); |
|
185 | + $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
186 | + $acc_req->sign_request($hmac_method, $this->oauthConsumer, $oauthToken); |
|
187 | + |
|
188 | + $targetUrl = (string)$acc_req; |
|
189 | + |
|
190 | + $data = $this->httpHelper->get($targetUrl, null); |
|
191 | + |
|
192 | + if ($data === false) { |
|
193 | + throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
194 | + } |
|
195 | + |
|
196 | + $decodedData = json_decode($data); |
|
197 | + |
|
198 | + if (isset($decodedData->error)) { |
|
199 | + throw new OAuthException($decodedData->error); |
|
200 | + } |
|
201 | + |
|
202 | + $identity = JWT::decode($data, $this->consumerSecret); |
|
203 | + |
|
204 | + return $identity; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param array $apiParams array of parameters to send to the API |
|
209 | + * @param string $accessToken user's access token |
|
210 | + * @param string $accessSecret user's secret |
|
211 | + * @param string $method HTTP method |
|
212 | + * |
|
213 | + * @return stdClass |
|
214 | + * @throws ApplicationLogicException |
|
215 | + * @throws CurlException |
|
216 | + * @throws Exception |
|
217 | + */ |
|
218 | + public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET') |
|
219 | + { |
|
220 | + $userToken = new OAuthToken($accessToken, $accessSecret); |
|
221 | + |
|
222 | + $apiParams['format'] = 'json'; |
|
223 | + |
|
224 | + $api_req = OAuthRequest::from_consumer_and_token( |
|
225 | + $this->oauthConsumer, // Consumer |
|
226 | + $userToken, // User Access Token |
|
227 | + $method, // HTTP Method |
|
228 | + $this->mediawikiWebServiceEndpoint, // Endpoint url |
|
229 | + $apiParams // Extra signed parameters |
|
230 | + ); |
|
231 | 231 | |
232 | - $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
232 | + $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); |
|
233 | 233 | |
234 | - $api_req->sign_request($hmac_method, $this->oauthConsumer, $userToken); |
|
234 | + $api_req->sign_request($hmac_method, $this->oauthConsumer, $userToken); |
|
235 | 235 | |
236 | - $headers = array($api_req->to_header()); |
|
237 | - |
|
238 | - if ($method == 'GET') { |
|
239 | - $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams, $headers); |
|
240 | - } |
|
241 | - elseif ($method == 'POST') { |
|
242 | - $data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams, $headers); |
|
243 | - } |
|
244 | - else { |
|
245 | - throw new ApplicationLogicException('Unsupported HTTP Method'); |
|
246 | - } |
|
247 | - |
|
248 | - if ($data === false) { |
|
249 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
250 | - } |
|
251 | - |
|
252 | - return json_decode($data); |
|
253 | - } |
|
236 | + $headers = array($api_req->to_header()); |
|
237 | + |
|
238 | + if ($method == 'GET') { |
|
239 | + $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, $apiParams, $headers); |
|
240 | + } |
|
241 | + elseif ($method == 'POST') { |
|
242 | + $data = $this->httpHelper->post($this->mediawikiWebServiceEndpoint, $apiParams, $headers); |
|
243 | + } |
|
244 | + else { |
|
245 | + throw new ApplicationLogicException('Unsupported HTTP Method'); |
|
246 | + } |
|
247 | + |
|
248 | + if ($data === false) { |
|
249 | + throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
250 | + } |
|
251 | + |
|
252 | + return json_decode($data); |
|
253 | + } |
|
254 | 254 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function getRequestToken() |
79 | 79 | { |
80 | - $endpoint = $this->oauthEndpoint . '/initiate&format=json&oauth_callback=oob'; |
|
80 | + $endpoint = $this->oauthEndpoint.'/initiate&format=json&oauth_callback=oob'; |
|
81 | 81 | |
82 | 82 | $parsedUrl = parse_url($endpoint); |
83 | 83 | $urlParameters = array(); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $data = $this->httpHelper->get($targetUrl, null); |
93 | 93 | |
94 | 94 | if ($data === false) { |
95 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
95 | + throw new CurlException('Curl error: '.$this->httpHelper->getError()); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $token = json_decode($data); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | if (isset($token->error)) { |
105 | - throw new OAuthException('Error encountered while getting request token: ' . $token->error); |
|
105 | + throw new OAuthException('Error encountered while getting request token: '.$token->error); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $token; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier) |
131 | 131 | { |
132 | - $endpoint = $this->oauthEndpoint . '/token&format=json'; |
|
132 | + $endpoint = $this->oauthEndpoint.'/token&format=json'; |
|
133 | 133 | |
134 | 134 | $requestConsumer = new OAuthConsumer($oauthRequestToken, $oauthRequestSecret); |
135 | 135 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $data = $this->httpHelper->get($targetUrl, null); |
148 | 148 | |
149 | 149 | if ($data === false) { |
150 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
150 | + throw new CurlException('Curl error: '.$this->httpHelper->getError()); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $token = json_decode($data); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | if (isset($token->error)) { |
160 | - throw new OAuthException('Error encountered while getting access token: ' . $token->error); |
|
160 | + throw new OAuthException('Error encountered while getting access token: '.$token->error); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | return $token; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret) |
175 | 175 | { |
176 | - $endpoint = $this->oauthEndpoint . '/identify&format=json'; |
|
176 | + $endpoint = $this->oauthEndpoint.'/identify&format=json'; |
|
177 | 177 | |
178 | 178 | $oauthToken = new OAuthToken($oauthAccessToken, $oauthAccessSecret); |
179 | 179 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $data = $this->httpHelper->get($targetUrl, null); |
191 | 191 | |
192 | 192 | if ($data === false) { |
193 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
193 | + throw new CurlException('Curl error: '.$this->httpHelper->getError()); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | $decodedData = json_decode($data); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | if ($data === false) { |
249 | - throw new CurlException('Curl error: ' . $this->httpHelper->getError()); |
|
249 | + throw new CurlException('Curl error: '.$this->httpHelper->getError()); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return json_decode($data); |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | class RequestStatus |
12 | 12 | { |
13 | - const HOSPITAL = 'Hospital'; |
|
14 | - const JOBQUEUE = 'JobQueue'; |
|
15 | - const CLOSED = 'Closed'; |
|
13 | + const HOSPITAL = 'Hospital'; |
|
14 | + const JOBQUEUE = 'JobQueue'; |
|
15 | + const CLOSED = 'Closed'; |
|
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -16,16 +16,16 @@ |
||
16 | 16 | |
17 | 17 | class BotCreationTask extends CreationTaskBase |
18 | 18 | { |
19 | - /** |
|
20 | - * @return IMediaWikiClient |
|
21 | - */ |
|
22 | - protected function getMediaWikiClient() |
|
23 | - { |
|
24 | - return new BotMediaWikiClient($this->getSiteConfiguration()); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @return IMediaWikiClient |
|
21 | + */ |
|
22 | + protected function getMediaWikiClient() |
|
23 | + { |
|
24 | + return new BotMediaWikiClient($this->getSiteConfiguration()); |
|
25 | + } |
|
26 | 26 | |
27 | - protected function getCreationReason(Request $request, User $user) |
|
28 | - { |
|
29 | - return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
30 | - } |
|
27 | + protected function getCreationReason(Request $request, User $user) |
|
28 | + { |
|
29 | + return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -26,6 +26,6 @@ |
||
26 | 26 | |
27 | 27 | protected function getCreationReason(Request $request, User $user) |
28 | 28 | { |
29 | - return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
29 | + return parent::getCreationReason($request, $user).', on behalf of [[User:'.$user->getOnWikiName().']]'; |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -14,14 +14,14 @@ |
||
14 | 14 | |
15 | 15 | class UserCreationTask extends CreationTaskBase |
16 | 16 | { |
17 | - /** |
|
18 | - * @return IMediaWikiClient |
|
19 | - */ |
|
20 | - protected function getMediaWikiClient() |
|
21 | - { |
|
22 | - $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
23 | - $this->getSiteConfiguration()); |
|
17 | + /** |
|
18 | + * @return IMediaWikiClient |
|
19 | + */ |
|
20 | + protected function getMediaWikiClient() |
|
21 | + { |
|
22 | + $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
23 | + $this->getSiteConfiguration()); |
|
24 | 24 | |
25 | - return $oauth; |
|
26 | - } |
|
25 | + return $oauth; |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -20,73 +20,73 @@ |
||
20 | 20 | |
21 | 21 | class WelcomeUserTask extends BackgroundTaskBase |
22 | 22 | { |
23 | - public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
24 | - { |
|
25 | - $job = new JobQueue(); |
|
26 | - $job->setDatabase($database); |
|
27 | - $job->setTask(WelcomeUserTask::class); |
|
28 | - $job->setRequest($request->getId()); |
|
29 | - $job->setTriggerUserId($triggerUser->getId()); |
|
30 | - $job->save(); |
|
31 | - } |
|
32 | - |
|
33 | - public function execute() |
|
34 | - { |
|
35 | - $database = $this->getDatabase(); |
|
36 | - $request = $this->getRequest(); |
|
37 | - $user = $this->getTriggerUser(); |
|
38 | - |
|
39 | - if ($user->getWelcomeTemplate() === null) { |
|
40 | - $this->markFailed('Welcome template not specified'); |
|
41 | - |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - /** @var WelcomeTemplate $template */ |
|
46 | - $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
47 | - |
|
48 | - if ($template === false) { |
|
49 | - $this->markFailed('Welcome template missing'); |
|
50 | - |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
55 | - $this->getSiteConfiguration()); |
|
56 | - $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
57 | - |
|
58 | - if ($request->getStatus() !== RequestStatus::CLOSED) { |
|
59 | - $this->markFailed('Request is currently open'); |
|
60 | - |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
65 | - $this->markFailed('Account does not exist!'); |
|
66 | - |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $this->performWelcome($template, $request, $mediaWikiHelper); |
|
71 | - $this->markComplete(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Performs the welcome |
|
76 | - * |
|
77 | - * @param WelcomeTemplate $template |
|
78 | - * @param Request $request |
|
79 | - * @param MediaWikiHelper $mediaWikiHelper |
|
80 | - */ |
|
81 | - private function performWelcome( |
|
82 | - WelcomeTemplate $template, |
|
83 | - Request $request, |
|
84 | - MediaWikiHelper $mediaWikiHelper |
|
85 | - ) { |
|
86 | - $templateText = $template->getBotCode(); |
|
87 | - $templateText = str_replace('$signature', '~~~~', $templateText); |
|
88 | - $templateText = str_replace('$username', $request->getName(), $templateText); |
|
89 | - |
|
90 | - $mediaWikiHelper->addTalkPageMessage($request->getName(), 'Welcome!', 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
91 | - } |
|
23 | + public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
24 | + { |
|
25 | + $job = new JobQueue(); |
|
26 | + $job->setDatabase($database); |
|
27 | + $job->setTask(WelcomeUserTask::class); |
|
28 | + $job->setRequest($request->getId()); |
|
29 | + $job->setTriggerUserId($triggerUser->getId()); |
|
30 | + $job->save(); |
|
31 | + } |
|
32 | + |
|
33 | + public function execute() |
|
34 | + { |
|
35 | + $database = $this->getDatabase(); |
|
36 | + $request = $this->getRequest(); |
|
37 | + $user = $this->getTriggerUser(); |
|
38 | + |
|
39 | + if ($user->getWelcomeTemplate() === null) { |
|
40 | + $this->markFailed('Welcome template not specified'); |
|
41 | + |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + /** @var WelcomeTemplate $template */ |
|
46 | + $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
47 | + |
|
48 | + if ($template === false) { |
|
49 | + $this->markFailed('Welcome template missing'); |
|
50 | + |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
55 | + $this->getSiteConfiguration()); |
|
56 | + $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
57 | + |
|
58 | + if ($request->getStatus() !== RequestStatus::CLOSED) { |
|
59 | + $this->markFailed('Request is currently open'); |
|
60 | + |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
65 | + $this->markFailed('Account does not exist!'); |
|
66 | + |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $this->performWelcome($template, $request, $mediaWikiHelper); |
|
71 | + $this->markComplete(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Performs the welcome |
|
76 | + * |
|
77 | + * @param WelcomeTemplate $template |
|
78 | + * @param Request $request |
|
79 | + * @param MediaWikiHelper $mediaWikiHelper |
|
80 | + */ |
|
81 | + private function performWelcome( |
|
82 | + WelcomeTemplate $template, |
|
83 | + Request $request, |
|
84 | + MediaWikiHelper $mediaWikiHelper |
|
85 | + ) { |
|
86 | + $templateText = $template->getBotCode(); |
|
87 | + $templateText = str_replace('$signature', '~~~~', $templateText); |
|
88 | + $templateText = str_replace('$username', $request->getName(), $templateText); |
|
89 | + |
|
90 | + $mediaWikiHelper->addTalkPageMessage($request->getName(), 'Welcome!', 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -61,7 +61,7 @@ |
||
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())) { |
|
65 | 65 | $this->markFailed('Account does not exist!'); |
66 | 66 | |
67 | 67 | return; |
@@ -61,7 +61,7 @@ |
||
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())) { |
|
65 | 65 | $this->markFailed('Account does not exist!'); |
66 | 66 | |
67 | 67 | return; |
@@ -20,123 +20,123 @@ |
||
20 | 20 | |
21 | 21 | abstract class CreationTaskBase extends BackgroundTaskBase |
22 | 22 | { |
23 | - /** @var Request */ |
|
24 | - private $request; |
|
25 | - /** |
|
26 | - * @var MediaWikiHelper |
|
27 | - * Don't use this directly. |
|
28 | - */ |
|
29 | - private $mwHelper = null; |
|
30 | - |
|
31 | - public function execute() |
|
32 | - { |
|
33 | - $this->request = $this->getRequest(); |
|
34 | - $user = $this->getTriggerUser(); |
|
35 | - |
|
36 | - if ($this->request->getStatus() !== RequestStatus::JOBQUEUE) { |
|
37 | - $this->markCancelled('Request is not deferred to the job queue'); |
|
38 | - |
|
39 | - return; |
|
40 | - } |
|
41 | - |
|
42 | - if ($this->request->getEmailSent() != 0) { |
|
43 | - $this->markFailed('Request has already been sent an email'); |
|
44 | - |
|
45 | - return; |
|
46 | - } |
|
47 | - |
|
48 | - if ($this->getEmailTemplate() === null) { |
|
49 | - $this->markFailed('No email template specified'); |
|
50 | - |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - try { |
|
55 | - $this->performCreation($user); |
|
56 | - |
|
57 | - $this->request->setStatus(RequestStatus::CLOSED); |
|
58 | - $this->request->setReserved(null); |
|
59 | - $this->request->save(); |
|
60 | - |
|
61 | - // Log the closure as the user |
|
62 | - Logger::closeRequest($this->getDatabase(), $this->request, $this->getEmailTemplate()->getId(), null, |
|
63 | - $this->getTriggerUser()); |
|
64 | - |
|
65 | - $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
66 | - $requestEmailHelper->sendMail($this->request, $this->getEmailTemplate()->getText(), $this->getTriggerUser(), |
|
67 | - false); |
|
68 | - |
|
69 | - $this->getNotificationHelper()->requestClosed($this->request, $this->getEmailTemplate()->getName()); |
|
70 | - } |
|
71 | - catch (Exception $ex) { |
|
72 | - $this->markFailed($ex->getMessage()); |
|
73 | - |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - $this->markComplete(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return IMediaWikiClient |
|
82 | - */ |
|
83 | - protected abstract function getMediaWikiClient(); |
|
84 | - |
|
85 | - protected function getMediaWikiHelper(){ |
|
86 | - if($this->mwHelper === null) { |
|
87 | - $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
|
88 | - } |
|
89 | - |
|
90 | - return $this->mwHelper; |
|
91 | - } |
|
92 | - |
|
93 | - protected function getCreationReason(Request $request, User $user) |
|
94 | - { |
|
95 | - return 'Requested account at [[WP:ACC]], request #' . $request->getId(); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $name |
|
100 | - * |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - protected function checkAccountExists($name) |
|
104 | - { |
|
105 | - return $this->getMediaWikiHelper()->checkAccountExists($name); |
|
106 | - } |
|
107 | - |
|
108 | - protected function markFailed($reason = null) |
|
109 | - { |
|
110 | - $this->request->setStatus(RequestStatus::HOSPITAL); |
|
111 | - $this->request->save(); |
|
112 | - |
|
113 | - Logger::hospitalised($this->getDatabase(), $this->request); |
|
114 | - |
|
115 | - parent::markFailed($reason); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param $user |
|
120 | - * |
|
121 | - * @throws ApplicationLogicException |
|
122 | - */ |
|
123 | - protected function performCreation($user) |
|
124 | - { |
|
125 | - $mw = $this->getMediaWikiHelper(); |
|
126 | - |
|
127 | - $reason = $this->getCreationReason($this->request, $user); |
|
23 | + /** @var Request */ |
|
24 | + private $request; |
|
25 | + /** |
|
26 | + * @var MediaWikiHelper |
|
27 | + * Don't use this directly. |
|
28 | + */ |
|
29 | + private $mwHelper = null; |
|
30 | + |
|
31 | + public function execute() |
|
32 | + { |
|
33 | + $this->request = $this->getRequest(); |
|
34 | + $user = $this->getTriggerUser(); |
|
35 | + |
|
36 | + if ($this->request->getStatus() !== RequestStatus::JOBQUEUE) { |
|
37 | + $this->markCancelled('Request is not deferred to the job queue'); |
|
38 | + |
|
39 | + return; |
|
40 | + } |
|
41 | + |
|
42 | + if ($this->request->getEmailSent() != 0) { |
|
43 | + $this->markFailed('Request has already been sent an email'); |
|
44 | + |
|
45 | + return; |
|
46 | + } |
|
47 | + |
|
48 | + if ($this->getEmailTemplate() === null) { |
|
49 | + $this->markFailed('No email template specified'); |
|
50 | + |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + try { |
|
55 | + $this->performCreation($user); |
|
56 | + |
|
57 | + $this->request->setStatus(RequestStatus::CLOSED); |
|
58 | + $this->request->setReserved(null); |
|
59 | + $this->request->save(); |
|
60 | + |
|
61 | + // Log the closure as the user |
|
62 | + Logger::closeRequest($this->getDatabase(), $this->request, $this->getEmailTemplate()->getId(), null, |
|
63 | + $this->getTriggerUser()); |
|
64 | + |
|
65 | + $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
66 | + $requestEmailHelper->sendMail($this->request, $this->getEmailTemplate()->getText(), $this->getTriggerUser(), |
|
67 | + false); |
|
68 | + |
|
69 | + $this->getNotificationHelper()->requestClosed($this->request, $this->getEmailTemplate()->getName()); |
|
70 | + } |
|
71 | + catch (Exception $ex) { |
|
72 | + $this->markFailed($ex->getMessage()); |
|
73 | + |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + $this->markComplete(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return IMediaWikiClient |
|
82 | + */ |
|
83 | + protected abstract function getMediaWikiClient(); |
|
84 | + |
|
85 | + protected function getMediaWikiHelper(){ |
|
86 | + if($this->mwHelper === null) { |
|
87 | + $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
|
88 | + } |
|
89 | + |
|
90 | + return $this->mwHelper; |
|
91 | + } |
|
92 | + |
|
93 | + protected function getCreationReason(Request $request, User $user) |
|
94 | + { |
|
95 | + return 'Requested account at [[WP:ACC]], request #' . $request->getId(); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $name |
|
100 | + * |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + protected function checkAccountExists($name) |
|
104 | + { |
|
105 | + return $this->getMediaWikiHelper()->checkAccountExists($name); |
|
106 | + } |
|
107 | + |
|
108 | + protected function markFailed($reason = null) |
|
109 | + { |
|
110 | + $this->request->setStatus(RequestStatus::HOSPITAL); |
|
111 | + $this->request->save(); |
|
112 | + |
|
113 | + Logger::hospitalised($this->getDatabase(), $this->request); |
|
114 | + |
|
115 | + parent::markFailed($reason); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param $user |
|
120 | + * |
|
121 | + * @throws ApplicationLogicException |
|
122 | + */ |
|
123 | + protected function performCreation($user) |
|
124 | + { |
|
125 | + $mw = $this->getMediaWikiHelper(); |
|
126 | + |
|
127 | + $reason = $this->getCreationReason($this->request, $user); |
|
128 | 128 | |
129 | - if ($this->checkAccountExists($this->request->getName())) { |
|
130 | - throw new ApplicationLogicException('Account already exists'); |
|
131 | - } |
|
129 | + if ($this->checkAccountExists($this->request->getName())) { |
|
130 | + throw new ApplicationLogicException('Account already exists'); |
|
131 | + } |
|
132 | 132 | |
133 | - $mw->createAccount($this->request->getName(), $this->request->getEmail(), $reason); |
|
133 | + $mw->createAccount($this->request->getName(), $this->request->getEmail(), $reason); |
|
134 | 134 | |
135 | - if (!$this->checkAccountExists($this->request->getName())) { |
|
136 | - throw new ApplicationLogicException('Account creation appeared to succeed but account does not exist.'); |
|
137 | - } |
|
135 | + if (!$this->checkAccountExists($this->request->getName())) { |
|
136 | + throw new ApplicationLogicException('Account creation appeared to succeed but account does not exist.'); |
|
137 | + } |
|
138 | 138 | |
139 | - $this->request->setStatus(RequestStatus::CLOSED); |
|
140 | - $this->request->save(); |
|
141 | - } |
|
139 | + $this->request->setStatus(RequestStatus::CLOSED); |
|
140 | + $this->request->save(); |
|
141 | + } |
|
142 | 142 | } |
143 | 143 | \ No newline at end of file |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected abstract function getMediaWikiClient(); |
84 | 84 | |
85 | - protected function getMediaWikiHelper(){ |
|
86 | - if($this->mwHelper === null) { |
|
85 | + protected function getMediaWikiHelper() { |
|
86 | + if ($this->mwHelper === null) { |
|
87 | 87 | $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
88 | 88 | } |
89 | 89 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | protected function getCreationReason(Request $request, User $user) |
94 | 94 | { |
95 | - return 'Requested account at [[WP:ACC]], request #' . $request->getId(); |
|
95 | + return 'Requested account at [[WP:ACC]], request #'.$request->getId(); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -82,7 +82,8 @@ |
||
82 | 82 | */ |
83 | 83 | protected abstract function getMediaWikiClient(); |
84 | 84 | |
85 | - protected function getMediaWikiHelper(){ |
|
85 | + protected function getMediaWikiHelper() |
|
86 | + { |
|
86 | 87 | if($this->mwHelper === null) { |
87 | 88 | $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
88 | 89 | } |
@@ -23,265 +23,265 @@ |
||
23 | 23 | |
24 | 24 | abstract class BackgroundTaskBase |
25 | 25 | { |
26 | - /** @var JobQueue */ |
|
27 | - private $job; |
|
28 | - /** @var PdoDatabase */ |
|
29 | - private $database; |
|
30 | - /** @var IOAuthProtocolHelper */ |
|
31 | - private $oauthProtocolHelper; |
|
32 | - /** @var SiteConfiguration */ |
|
33 | - private $siteConfiguration; |
|
34 | - /** @var IEmailHelper */ |
|
35 | - private $emailHelper; |
|
36 | - /** @var HttpHelper */ |
|
37 | - private $httpHelper; |
|
38 | - /** @var IrcNotificationHelper */ |
|
39 | - private $notificationHelper; |
|
40 | - /** @var User */ |
|
41 | - private $triggerUser; |
|
42 | - /** @var Request */ |
|
43 | - private $request; |
|
44 | - /** @var EmailTemplate */ |
|
45 | - private $emailTemplate = null; |
|
46 | - /** @var mixed */ |
|
47 | - private $parameters; |
|
48 | - |
|
49 | - /** |
|
50 | - * @return JobQueue |
|
51 | - */ |
|
52 | - public function getJob() |
|
53 | - { |
|
54 | - return $this->job; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param JobQueue $job |
|
59 | - */ |
|
60 | - public function setJob(JobQueue $job) |
|
61 | - { |
|
62 | - $this->job = $job; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @return PdoDatabase |
|
67 | - */ |
|
68 | - public function getDatabase() |
|
69 | - { |
|
70 | - return $this->database; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param PdoDatabase $database |
|
75 | - */ |
|
76 | - public function setDatabase(PdoDatabase $database) |
|
77 | - { |
|
78 | - $this->database = $database; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return IOAuthProtocolHelper |
|
83 | - */ |
|
84 | - public function getOauthProtocolHelper() |
|
85 | - { |
|
86 | - return $this->oauthProtocolHelper; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
91 | - */ |
|
92 | - public function setOauthProtocolHelper(IOAuthProtocolHelper $oauthProtocolHelper) |
|
93 | - { |
|
94 | - $this->oauthProtocolHelper = $oauthProtocolHelper; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return SiteConfiguration |
|
99 | - */ |
|
100 | - public function getSiteConfiguration() |
|
101 | - { |
|
102 | - return $this->siteConfiguration; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param SiteConfiguration $siteConfiguration |
|
107 | - */ |
|
108 | - public function setSiteConfiguration(SiteConfiguration $siteConfiguration) |
|
109 | - { |
|
110 | - $this->siteConfiguration = $siteConfiguration; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @return HttpHelper |
|
115 | - */ |
|
116 | - public function getHttpHelper() |
|
117 | - { |
|
118 | - return $this->httpHelper; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param HttpHelper $httpHelper |
|
123 | - */ |
|
124 | - public function setHttpHelper(HttpHelper $httpHelper) |
|
125 | - { |
|
126 | - $this->httpHelper = $httpHelper; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return IEmailHelper |
|
131 | - */ |
|
132 | - public function getEmailHelper() |
|
133 | - { |
|
134 | - return $this->emailHelper; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @param IEmailHelper $emailHelper |
|
139 | - */ |
|
140 | - public function setEmailHelper(IEmailHelper $emailHelper) |
|
141 | - { |
|
142 | - $this->emailHelper = $emailHelper; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return IrcNotificationHelper |
|
147 | - */ |
|
148 | - public function getNotificationHelper() |
|
149 | - { |
|
150 | - return $this->notificationHelper; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param IrcNotificationHelper $notificationHelper |
|
155 | - */ |
|
156 | - public function setNotificationHelper($notificationHelper) |
|
157 | - { |
|
158 | - $this->notificationHelper = $notificationHelper; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - protected abstract function execute(); |
|
165 | - |
|
166 | - public function run() |
|
167 | - { |
|
168 | - $this->triggerUser = User::getById($this->job->getTriggerUserId(), $this->getDatabase()); |
|
169 | - |
|
170 | - if ($this->triggerUser === false) { |
|
171 | - throw new ApplicationLogicException('Cannot locate trigger user'); |
|
172 | - } |
|
173 | - |
|
174 | - $this->request = Request::getById($this->job->getRequest(), $this->getDatabase()); |
|
175 | - |
|
176 | - if ($this->request === false) { |
|
177 | - throw new ApplicationLogicException('Cannot locate request'); |
|
178 | - } |
|
179 | - |
|
180 | - if($this->job->getEmailTemplate() !== null){ |
|
181 | - $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
|
182 | - |
|
183 | - if ($this->emailTemplate === false) { |
|
184 | - throw new ApplicationLogicException('Cannot locate email template'); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - $this->parameters = json_decode($this->job->getParameters()); |
|
189 | - |
|
190 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
191 | - throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
192 | - } |
|
193 | - |
|
194 | - // Should we wait for a parent job? |
|
195 | - if($this->job->getParent() !== null) { |
|
196 | - /** @var JobQueue $parentJob */ |
|
197 | - $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
|
198 | - |
|
199 | - if($parentJob === false) { |
|
200 | - $this->markFailed("Parent job could not be found"); |
|
201 | - return; |
|
202 | - } |
|
203 | - |
|
204 | - switch ($parentJob->getStatus()) { |
|
205 | - case JobQueue::STATUS_CANCELLED: |
|
206 | - case JobQueue::STATUS_FAILED: |
|
207 | - $this->markCancelled('Parent job failed/cancelled'); |
|
208 | - return; |
|
209 | - case JobQueue::STATUS_WAITING: |
|
210 | - case JobQueue::STATUS_READY: |
|
211 | - case JobQueue::STATUS_RUNNING: |
|
212 | - case JobQueue::STATUS_HELD: |
|
213 | - // Defer to next execution |
|
214 | - $this->job->setStatus(JobQueue::STATUS_READY); |
|
215 | - $this->job->save(); |
|
216 | - return; |
|
217 | - case JobQueue::STATUS_COMPLETE: |
|
218 | - // do nothing |
|
219 | - break; |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - $this->execute(); |
|
224 | - } |
|
225 | - |
|
226 | - protected function markComplete() |
|
227 | - { |
|
228 | - $this->job->setStatus(JobQueue::STATUS_COMPLETE); |
|
229 | - $this->job->setError(null); |
|
230 | - $this->job->setAcknowledged(null); |
|
231 | - $this->job->save(); |
|
232 | - |
|
233 | - Logger::backgroundJobComplete($this->getDatabase(), $this->getJob()); |
|
234 | - } |
|
235 | - |
|
236 | - protected function markCancelled($reason = null) |
|
237 | - { |
|
238 | - $this->job->setStatus(JobQueue::STATUS_CANCELLED); |
|
239 | - $this->job->setError($reason); |
|
240 | - $this->job->setAcknowledged(null); |
|
241 | - $this->job->save(); |
|
242 | - |
|
243 | - Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
244 | - } |
|
245 | - |
|
246 | - protected function markFailed($reason = null) |
|
247 | - { |
|
248 | - $this->job->setStatus(JobQueue::STATUS_FAILED); |
|
249 | - $this->job->setError($reason); |
|
250 | - $this->job->setAcknowledged(0); |
|
251 | - $this->job->save(); |
|
252 | - |
|
253 | - Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @return User |
|
258 | - */ |
|
259 | - public function getTriggerUser() |
|
260 | - { |
|
261 | - return $this->triggerUser; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @return Request |
|
266 | - */ |
|
267 | - public function getRequest() |
|
268 | - { |
|
269 | - return $this->request; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @return EmailTemplate |
|
274 | - */ |
|
275 | - public function getEmailTemplate() |
|
276 | - { |
|
277 | - return $this->emailTemplate; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @return mixed |
|
282 | - */ |
|
283 | - public function getParameters() |
|
284 | - { |
|
285 | - return $this->parameters; |
|
286 | - } |
|
26 | + /** @var JobQueue */ |
|
27 | + private $job; |
|
28 | + /** @var PdoDatabase */ |
|
29 | + private $database; |
|
30 | + /** @var IOAuthProtocolHelper */ |
|
31 | + private $oauthProtocolHelper; |
|
32 | + /** @var SiteConfiguration */ |
|
33 | + private $siteConfiguration; |
|
34 | + /** @var IEmailHelper */ |
|
35 | + private $emailHelper; |
|
36 | + /** @var HttpHelper */ |
|
37 | + private $httpHelper; |
|
38 | + /** @var IrcNotificationHelper */ |
|
39 | + private $notificationHelper; |
|
40 | + /** @var User */ |
|
41 | + private $triggerUser; |
|
42 | + /** @var Request */ |
|
43 | + private $request; |
|
44 | + /** @var EmailTemplate */ |
|
45 | + private $emailTemplate = null; |
|
46 | + /** @var mixed */ |
|
47 | + private $parameters; |
|
48 | + |
|
49 | + /** |
|
50 | + * @return JobQueue |
|
51 | + */ |
|
52 | + public function getJob() |
|
53 | + { |
|
54 | + return $this->job; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param JobQueue $job |
|
59 | + */ |
|
60 | + public function setJob(JobQueue $job) |
|
61 | + { |
|
62 | + $this->job = $job; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @return PdoDatabase |
|
67 | + */ |
|
68 | + public function getDatabase() |
|
69 | + { |
|
70 | + return $this->database; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param PdoDatabase $database |
|
75 | + */ |
|
76 | + public function setDatabase(PdoDatabase $database) |
|
77 | + { |
|
78 | + $this->database = $database; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return IOAuthProtocolHelper |
|
83 | + */ |
|
84 | + public function getOauthProtocolHelper() |
|
85 | + { |
|
86 | + return $this->oauthProtocolHelper; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
91 | + */ |
|
92 | + public function setOauthProtocolHelper(IOAuthProtocolHelper $oauthProtocolHelper) |
|
93 | + { |
|
94 | + $this->oauthProtocolHelper = $oauthProtocolHelper; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return SiteConfiguration |
|
99 | + */ |
|
100 | + public function getSiteConfiguration() |
|
101 | + { |
|
102 | + return $this->siteConfiguration; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param SiteConfiguration $siteConfiguration |
|
107 | + */ |
|
108 | + public function setSiteConfiguration(SiteConfiguration $siteConfiguration) |
|
109 | + { |
|
110 | + $this->siteConfiguration = $siteConfiguration; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @return HttpHelper |
|
115 | + */ |
|
116 | + public function getHttpHelper() |
|
117 | + { |
|
118 | + return $this->httpHelper; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param HttpHelper $httpHelper |
|
123 | + */ |
|
124 | + public function setHttpHelper(HttpHelper $httpHelper) |
|
125 | + { |
|
126 | + $this->httpHelper = $httpHelper; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return IEmailHelper |
|
131 | + */ |
|
132 | + public function getEmailHelper() |
|
133 | + { |
|
134 | + return $this->emailHelper; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @param IEmailHelper $emailHelper |
|
139 | + */ |
|
140 | + public function setEmailHelper(IEmailHelper $emailHelper) |
|
141 | + { |
|
142 | + $this->emailHelper = $emailHelper; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return IrcNotificationHelper |
|
147 | + */ |
|
148 | + public function getNotificationHelper() |
|
149 | + { |
|
150 | + return $this->notificationHelper; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param IrcNotificationHelper $notificationHelper |
|
155 | + */ |
|
156 | + public function setNotificationHelper($notificationHelper) |
|
157 | + { |
|
158 | + $this->notificationHelper = $notificationHelper; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + protected abstract function execute(); |
|
165 | + |
|
166 | + public function run() |
|
167 | + { |
|
168 | + $this->triggerUser = User::getById($this->job->getTriggerUserId(), $this->getDatabase()); |
|
169 | + |
|
170 | + if ($this->triggerUser === false) { |
|
171 | + throw new ApplicationLogicException('Cannot locate trigger user'); |
|
172 | + } |
|
173 | + |
|
174 | + $this->request = Request::getById($this->job->getRequest(), $this->getDatabase()); |
|
175 | + |
|
176 | + if ($this->request === false) { |
|
177 | + throw new ApplicationLogicException('Cannot locate request'); |
|
178 | + } |
|
179 | + |
|
180 | + if($this->job->getEmailTemplate() !== null){ |
|
181 | + $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
|
182 | + |
|
183 | + if ($this->emailTemplate === false) { |
|
184 | + throw new ApplicationLogicException('Cannot locate email template'); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + $this->parameters = json_decode($this->job->getParameters()); |
|
189 | + |
|
190 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
191 | + throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
192 | + } |
|
193 | + |
|
194 | + // Should we wait for a parent job? |
|
195 | + if($this->job->getParent() !== null) { |
|
196 | + /** @var JobQueue $parentJob */ |
|
197 | + $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
|
198 | + |
|
199 | + if($parentJob === false) { |
|
200 | + $this->markFailed("Parent job could not be found"); |
|
201 | + return; |
|
202 | + } |
|
203 | + |
|
204 | + switch ($parentJob->getStatus()) { |
|
205 | + case JobQueue::STATUS_CANCELLED: |
|
206 | + case JobQueue::STATUS_FAILED: |
|
207 | + $this->markCancelled('Parent job failed/cancelled'); |
|
208 | + return; |
|
209 | + case JobQueue::STATUS_WAITING: |
|
210 | + case JobQueue::STATUS_READY: |
|
211 | + case JobQueue::STATUS_RUNNING: |
|
212 | + case JobQueue::STATUS_HELD: |
|
213 | + // Defer to next execution |
|
214 | + $this->job->setStatus(JobQueue::STATUS_READY); |
|
215 | + $this->job->save(); |
|
216 | + return; |
|
217 | + case JobQueue::STATUS_COMPLETE: |
|
218 | + // do nothing |
|
219 | + break; |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + $this->execute(); |
|
224 | + } |
|
225 | + |
|
226 | + protected function markComplete() |
|
227 | + { |
|
228 | + $this->job->setStatus(JobQueue::STATUS_COMPLETE); |
|
229 | + $this->job->setError(null); |
|
230 | + $this->job->setAcknowledged(null); |
|
231 | + $this->job->save(); |
|
232 | + |
|
233 | + Logger::backgroundJobComplete($this->getDatabase(), $this->getJob()); |
|
234 | + } |
|
235 | + |
|
236 | + protected function markCancelled($reason = null) |
|
237 | + { |
|
238 | + $this->job->setStatus(JobQueue::STATUS_CANCELLED); |
|
239 | + $this->job->setError($reason); |
|
240 | + $this->job->setAcknowledged(null); |
|
241 | + $this->job->save(); |
|
242 | + |
|
243 | + Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
244 | + } |
|
245 | + |
|
246 | + protected function markFailed($reason = null) |
|
247 | + { |
|
248 | + $this->job->setStatus(JobQueue::STATUS_FAILED); |
|
249 | + $this->job->setError($reason); |
|
250 | + $this->job->setAcknowledged(0); |
|
251 | + $this->job->save(); |
|
252 | + |
|
253 | + Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @return User |
|
258 | + */ |
|
259 | + public function getTriggerUser() |
|
260 | + { |
|
261 | + return $this->triggerUser; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @return Request |
|
266 | + */ |
|
267 | + public function getRequest() |
|
268 | + { |
|
269 | + return $this->request; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @return EmailTemplate |
|
274 | + */ |
|
275 | + public function getEmailTemplate() |
|
276 | + { |
|
277 | + return $this->emailTemplate; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @return mixed |
|
282 | + */ |
|
283 | + public function getParameters() |
|
284 | + { |
|
285 | + return $this->parameters; |
|
286 | + } |
|
287 | 287 | } |
288 | 288 | \ No newline at end of file |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | throw new ApplicationLogicException('Cannot locate request'); |
178 | 178 | } |
179 | 179 | |
180 | - if($this->job->getEmailTemplate() !== null){ |
|
180 | + if ($this->job->getEmailTemplate() !== null) { |
|
181 | 181 | $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
182 | 182 | |
183 | 183 | if ($this->emailTemplate === false) { |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | $this->parameters = json_decode($this->job->getParameters()); |
189 | 189 | |
190 | 190 | if (json_last_error() !== JSON_ERROR_NONE) { |
191 | - throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
191 | + throw new ApplicationLogicException('JSON decode: '.json_last_error_msg()); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // Should we wait for a parent job? |
195 | - if($this->job->getParent() !== null) { |
|
195 | + if ($this->job->getParent() !== null) { |
|
196 | 196 | /** @var JobQueue $parentJob */ |
197 | 197 | $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
198 | 198 | |
199 | - if($parentJob === false) { |
|
199 | + if ($parentJob === false) { |
|
200 | 200 | $this->markFailed("Parent job could not be found"); |
201 | 201 | return; |
202 | 202 | } |
@@ -177,7 +177,7 @@ |
||
177 | 177 | throw new ApplicationLogicException('Cannot locate request'); |
178 | 178 | } |
179 | 179 | |
180 | - if($this->job->getEmailTemplate() !== null){ |
|
180 | + if($this->job->getEmailTemplate() !== null) { |
|
181 | 181 | $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
182 | 182 | |
183 | 183 | if ($this->emailTemplate === false) { |
@@ -30,224 +30,224 @@ |
||
30 | 30 | */ |
31 | 31 | class WebStart extends ApplicationBase |
32 | 32 | { |
33 | - /** |
|
34 | - * @var IRequestRouter $requestRouter The request router to use. Note that different entry points have different |
|
35 | - * routers and hence different URL mappings |
|
36 | - */ |
|
37 | - private $requestRouter; |
|
38 | - /** |
|
39 | - * @var bool $isPublic Determines whether to use public interface objects or internal interface objects |
|
40 | - */ |
|
41 | - private $isPublic = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * WebStart constructor. |
|
45 | - * |
|
46 | - * @param SiteConfiguration $configuration The site configuration |
|
47 | - * @param IRequestRouter $router The request router to use |
|
48 | - */ |
|
49 | - public function __construct(SiteConfiguration $configuration, IRequestRouter $router) |
|
50 | - { |
|
51 | - parent::__construct($configuration); |
|
52 | - |
|
53 | - $this->requestRouter = $router; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param ITask $page |
|
58 | - * @param SiteConfiguration $siteConfiguration |
|
59 | - * @param PdoDatabase $database |
|
60 | - * @param PdoDatabase $notificationsDatabase |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - protected function setupHelpers( |
|
65 | - ITask $page, |
|
66 | - SiteConfiguration $siteConfiguration, |
|
67 | - PdoDatabase $database, |
|
68 | - PdoDatabase $notificationsDatabase = null |
|
69 | - ) { |
|
70 | - parent::setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
71 | - |
|
72 | - if ($page instanceof PageBase) { |
|
73 | - $page->setTokenManager(new TokenManager()); |
|
74 | - |
|
75 | - if ($page instanceof InternalPageBase) { |
|
76 | - $page->setTypeAheadHelper(new TypeAheadHelper()); |
|
77 | - |
|
78 | - $identificationVerifier = new IdentificationVerifier($page->getHttpHelper(), $siteConfiguration, |
|
79 | - $database); |
|
80 | - $page->setIdentificationVerifier($identificationVerifier); |
|
81 | - |
|
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 | - catch (ReadableException $ex) { |
|
112 | - ob_end_clean(); |
|
113 | - print $ex->getReadableError(); |
|
114 | - } |
|
115 | - finally { |
|
116 | - $this->cleanupEnvironment(); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Environment setup |
|
122 | - * |
|
123 | - * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
124 | - * and shut down prematurely. |
|
125 | - * |
|
126 | - * @return bool |
|
127 | - * @throws EnvironmentException |
|
128 | - */ |
|
129 | - protected function setupEnvironment() |
|
130 | - { |
|
131 | - // initialise global exception handler |
|
132 | - set_exception_handler(array(ExceptionHandler::class, 'exceptionHandler')); |
|
133 | - set_error_handler(array(ExceptionHandler::class, 'errorHandler'), E_RECOVERABLE_ERROR); |
|
134 | - |
|
135 | - // start output buffering if necessary |
|
136 | - if (ob_get_level() === 0) { |
|
137 | - ob_start(); |
|
138 | - } |
|
139 | - |
|
140 | - // initialise super-global providers |
|
141 | - WebRequest::setGlobalStateProvider(new GlobalStateProvider()); |
|
142 | - |
|
143 | - if (Offline::isOffline()) { |
|
144 | - print Offline::getOfflineMessage($this->isPublic()); |
|
145 | - ob_end_flush(); |
|
146 | - |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - // Call parent setup |
|
151 | - if (!parent::setupEnvironment()) { |
|
152 | - return false; |
|
153 | - } |
|
154 | - |
|
155 | - // Start up sessions |
|
156 | - Session::start(); |
|
157 | - |
|
158 | - // Check the user is allowed to be logged in still. This must be before we call any user-loading functions and |
|
159 | - // get the current user cached. |
|
160 | - // I'm not sure if this function call being here is particularly a good thing, but it's part of starting up a |
|
161 | - // session I suppose. |
|
162 | - $this->checkForceLogout(); |
|
163 | - |
|
164 | - // environment initialised! |
|
165 | - return true; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Main application logic |
|
170 | - */ |
|
171 | - protected function main() |
|
172 | - { |
|
173 | - // Get the right route for the request |
|
174 | - $page = $this->requestRouter->route(); |
|
175 | - |
|
176 | - $siteConfiguration = $this->getConfiguration(); |
|
177 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
178 | - |
|
179 | - if ($siteConfiguration->getIrcNotificationsEnabled()) { |
|
180 | - $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
181 | - } |
|
182 | - else { |
|
183 | - // @todo federated table here? |
|
184 | - $notificationsDatabase = $database; |
|
185 | - } |
|
186 | - |
|
187 | - $this->setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
188 | - |
|
189 | - /* @todo Remove this global statement! It's here for User.php, which does far more than it should. */ |
|
190 | - global $oauthProtocolHelper; |
|
191 | - $oauthProtocolHelper = $page->getOAuthProtocolHelper(); |
|
192 | - |
|
193 | - /* @todo Remove this global statement! It's here for Request.php, which does far more than it should. */ |
|
194 | - global $globalXffTrustProvider; |
|
195 | - $globalXffTrustProvider = $page->getXffTrustProvider(); |
|
196 | - |
|
197 | - // run the route code for the request. |
|
198 | - $page->execute(); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Any cleanup tasks should go here |
|
203 | - * |
|
204 | - * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
205 | - * This should *only* be for cleaning up, no logic should go here. |
|
206 | - */ |
|
207 | - protected function cleanupEnvironment() |
|
208 | - { |
|
209 | - // Clean up anything we splurged after sending the page. |
|
210 | - if (ob_get_level() > 0) { |
|
211 | - for ($i = ob_get_level(); $i > 0; $i--) { |
|
212 | - ob_end_clean(); |
|
213 | - } |
|
214 | - } |
|
215 | - } |
|
216 | - |
|
217 | - private function checkForceLogout() |
|
218 | - { |
|
219 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
220 | - |
|
221 | - $sessionUserId = WebRequest::getSessionUserId(); |
|
222 | - iF ($sessionUserId === null) { |
|
223 | - return; |
|
224 | - } |
|
225 | - |
|
226 | - // Note, User::getCurrent() caches it's result, which we *really* don't want to trigger. |
|
227 | - $currentUser = User::getById($sessionUserId, $database); |
|
228 | - |
|
229 | - if ($currentUser === false) { |
|
230 | - // Umm... this user has a session cookie with a userId set, but no user exists... |
|
231 | - Session::restart(); |
|
232 | - |
|
233 | - $currentUser = User::getCurrent($database); |
|
234 | - } |
|
235 | - |
|
236 | - if ($currentUser->getForceLogout()) { |
|
237 | - Session::restart(); |
|
238 | - |
|
239 | - $currentUser->setForceLogout(false); |
|
240 | - $currentUser->save(); |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - public function isPublic() |
|
245 | - { |
|
246 | - return $this->isPublic; |
|
247 | - } |
|
248 | - |
|
249 | - public function setPublic($isPublic) |
|
250 | - { |
|
251 | - $this->isPublic = $isPublic; |
|
252 | - } |
|
33 | + /** |
|
34 | + * @var IRequestRouter $requestRouter The request router to use. Note that different entry points have different |
|
35 | + * routers and hence different URL mappings |
|
36 | + */ |
|
37 | + private $requestRouter; |
|
38 | + /** |
|
39 | + * @var bool $isPublic Determines whether to use public interface objects or internal interface objects |
|
40 | + */ |
|
41 | + private $isPublic = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * WebStart constructor. |
|
45 | + * |
|
46 | + * @param SiteConfiguration $configuration The site configuration |
|
47 | + * @param IRequestRouter $router The request router to use |
|
48 | + */ |
|
49 | + public function __construct(SiteConfiguration $configuration, IRequestRouter $router) |
|
50 | + { |
|
51 | + parent::__construct($configuration); |
|
52 | + |
|
53 | + $this->requestRouter = $router; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param ITask $page |
|
58 | + * @param SiteConfiguration $siteConfiguration |
|
59 | + * @param PdoDatabase $database |
|
60 | + * @param PdoDatabase $notificationsDatabase |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + protected function setupHelpers( |
|
65 | + ITask $page, |
|
66 | + SiteConfiguration $siteConfiguration, |
|
67 | + PdoDatabase $database, |
|
68 | + PdoDatabase $notificationsDatabase = null |
|
69 | + ) { |
|
70 | + parent::setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
71 | + |
|
72 | + if ($page instanceof PageBase) { |
|
73 | + $page->setTokenManager(new TokenManager()); |
|
74 | + |
|
75 | + if ($page instanceof InternalPageBase) { |
|
76 | + $page->setTypeAheadHelper(new TypeAheadHelper()); |
|
77 | + |
|
78 | + $identificationVerifier = new IdentificationVerifier($page->getHttpHelper(), $siteConfiguration, |
|
79 | + $database); |
|
80 | + $page->setIdentificationVerifier($identificationVerifier); |
|
81 | + |
|
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 | + catch (ReadableException $ex) { |
|
112 | + ob_end_clean(); |
|
113 | + print $ex->getReadableError(); |
|
114 | + } |
|
115 | + finally { |
|
116 | + $this->cleanupEnvironment(); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Environment setup |
|
122 | + * |
|
123 | + * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
124 | + * and shut down prematurely. |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + * @throws EnvironmentException |
|
128 | + */ |
|
129 | + protected function setupEnvironment() |
|
130 | + { |
|
131 | + // initialise global exception handler |
|
132 | + set_exception_handler(array(ExceptionHandler::class, 'exceptionHandler')); |
|
133 | + set_error_handler(array(ExceptionHandler::class, 'errorHandler'), E_RECOVERABLE_ERROR); |
|
134 | + |
|
135 | + // start output buffering if necessary |
|
136 | + if (ob_get_level() === 0) { |
|
137 | + ob_start(); |
|
138 | + } |
|
139 | + |
|
140 | + // initialise super-global providers |
|
141 | + WebRequest::setGlobalStateProvider(new GlobalStateProvider()); |
|
142 | + |
|
143 | + if (Offline::isOffline()) { |
|
144 | + print Offline::getOfflineMessage($this->isPublic()); |
|
145 | + ob_end_flush(); |
|
146 | + |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + // Call parent setup |
|
151 | + if (!parent::setupEnvironment()) { |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + // Start up sessions |
|
156 | + Session::start(); |
|
157 | + |
|
158 | + // Check the user is allowed to be logged in still. This must be before we call any user-loading functions and |
|
159 | + // get the current user cached. |
|
160 | + // I'm not sure if this function call being here is particularly a good thing, but it's part of starting up a |
|
161 | + // session I suppose. |
|
162 | + $this->checkForceLogout(); |
|
163 | + |
|
164 | + // environment initialised! |
|
165 | + return true; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Main application logic |
|
170 | + */ |
|
171 | + protected function main() |
|
172 | + { |
|
173 | + // Get the right route for the request |
|
174 | + $page = $this->requestRouter->route(); |
|
175 | + |
|
176 | + $siteConfiguration = $this->getConfiguration(); |
|
177 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
178 | + |
|
179 | + if ($siteConfiguration->getIrcNotificationsEnabled()) { |
|
180 | + $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
181 | + } |
|
182 | + else { |
|
183 | + // @todo federated table here? |
|
184 | + $notificationsDatabase = $database; |
|
185 | + } |
|
186 | + |
|
187 | + $this->setupHelpers($page, $siteConfiguration, $database, $notificationsDatabase); |
|
188 | + |
|
189 | + /* @todo Remove this global statement! It's here for User.php, which does far more than it should. */ |
|
190 | + global $oauthProtocolHelper; |
|
191 | + $oauthProtocolHelper = $page->getOAuthProtocolHelper(); |
|
192 | + |
|
193 | + /* @todo Remove this global statement! It's here for Request.php, which does far more than it should. */ |
|
194 | + global $globalXffTrustProvider; |
|
195 | + $globalXffTrustProvider = $page->getXffTrustProvider(); |
|
196 | + |
|
197 | + // run the route code for the request. |
|
198 | + $page->execute(); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Any cleanup tasks should go here |
|
203 | + * |
|
204 | + * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
205 | + * This should *only* be for cleaning up, no logic should go here. |
|
206 | + */ |
|
207 | + protected function cleanupEnvironment() |
|
208 | + { |
|
209 | + // Clean up anything we splurged after sending the page. |
|
210 | + if (ob_get_level() > 0) { |
|
211 | + for ($i = ob_get_level(); $i > 0; $i--) { |
|
212 | + ob_end_clean(); |
|
213 | + } |
|
214 | + } |
|
215 | + } |
|
216 | + |
|
217 | + private function checkForceLogout() |
|
218 | + { |
|
219 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
220 | + |
|
221 | + $sessionUserId = WebRequest::getSessionUserId(); |
|
222 | + iF ($sessionUserId === null) { |
|
223 | + return; |
|
224 | + } |
|
225 | + |
|
226 | + // Note, User::getCurrent() caches it's result, which we *really* don't want to trigger. |
|
227 | + $currentUser = User::getById($sessionUserId, $database); |
|
228 | + |
|
229 | + if ($currentUser === false) { |
|
230 | + // Umm... this user has a session cookie with a userId set, but no user exists... |
|
231 | + Session::restart(); |
|
232 | + |
|
233 | + $currentUser = User::getCurrent($database); |
|
234 | + } |
|
235 | + |
|
236 | + if ($currentUser->getForceLogout()) { |
|
237 | + Session::restart(); |
|
238 | + |
|
239 | + $currentUser->setForceLogout(false); |
|
240 | + $currentUser->save(); |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + public function isPublic() |
|
245 | + { |
|
246 | + return $this->isPublic; |
|
247 | + } |
|
248 | + |
|
249 | + public function setPublic($isPublic) |
|
250 | + { |
|
251 | + $this->isPublic = $isPublic; |
|
252 | + } |
|
253 | 253 | } |