@@ -25,155 +25,155 @@ |
||
25 | 25 | |
26 | 26 | abstract class ApplicationBase |
27 | 27 | { |
28 | - private $configuration; |
|
29 | - |
|
30 | - public function __construct(SiteConfiguration $configuration) |
|
31 | - { |
|
32 | - $this->configuration = $configuration; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Application entry point. |
|
37 | - * |
|
38 | - * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
39 | - */ |
|
40 | - public function run() |
|
41 | - { |
|
42 | - try { |
|
43 | - if ($this->setupEnvironment()) { |
|
44 | - $this->main(); |
|
45 | - } |
|
46 | - } |
|
47 | - catch (Exception $ex) { |
|
48 | - print $ex->getMessage(); |
|
49 | - } |
|
50 | - finally { |
|
51 | - $this->cleanupEnvironment(); |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Environment setup |
|
57 | - * |
|
58 | - * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
59 | - * and shut down prematurely. |
|
60 | - * |
|
61 | - * @return bool |
|
62 | - * @throws EnvironmentException |
|
63 | - */ |
|
64 | - protected function setupEnvironment() |
|
65 | - { |
|
66 | - $this->setupDatabase(); |
|
67 | - |
|
68 | - return true; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return PdoDatabase |
|
73 | - * @throws EnvironmentException |
|
74 | - * @throws Exception |
|
75 | - */ |
|
76 | - protected function setupDatabase() |
|
77 | - { |
|
78 | - // check the schema version |
|
79 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
80 | - |
|
81 | - /** @var int $actualVersion */ |
|
82 | - $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
83 | - if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
84 | - throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
85 | - } |
|
86 | - |
|
87 | - return $database; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return SiteConfiguration |
|
92 | - */ |
|
93 | - public function getConfiguration() |
|
94 | - { |
|
95 | - return $this->configuration; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Main application logic |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - abstract protected function main(); |
|
103 | - |
|
104 | - /** |
|
105 | - * Any cleanup tasks should go here |
|
106 | - * |
|
107 | - * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
108 | - * This should *only* be for cleaning up, no logic should go here. |
|
109 | - * |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - abstract protected function cleanupEnvironment(); |
|
113 | - |
|
114 | - /** |
|
115 | - * @param ITask $page |
|
116 | - * @param SiteConfiguration $siteConfiguration |
|
117 | - * @param PdoDatabase $database |
|
118 | - * @param PdoDatabase $notificationsDatabase |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - protected function setupHelpers( |
|
123 | - ITask $page, |
|
124 | - SiteConfiguration $siteConfiguration, |
|
125 | - PdoDatabase $database, |
|
126 | - PdoDatabase $notificationsDatabase = null |
|
127 | - ) { |
|
128 | - $page->setSiteConfiguration($siteConfiguration); |
|
129 | - |
|
130 | - // setup the global database object |
|
131 | - $page->setDatabase($database); |
|
132 | - |
|
133 | - // set up helpers and inject them into the page. |
|
134 | - $httpHelper = new HttpHelper( |
|
135 | - $siteConfiguration->getUserAgent(), |
|
136 | - $siteConfiguration->getCurlDisableVerifyPeer() |
|
137 | - ); |
|
138 | - |
|
139 | - $page->setEmailHelper(new EmailHelper()); |
|
140 | - $page->setHttpHelper($httpHelper); |
|
141 | - $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
142 | - |
|
143 | - if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
144 | - $page->setLocationProvider(new FakeLocationProvider()); |
|
145 | - } |
|
146 | - else { |
|
147 | - $page->setLocationProvider( |
|
148 | - new IpLocationProvider( |
|
149 | - $database, |
|
150 | - $siteConfiguration->getLocationProviderApiKey(), |
|
151 | - $httpHelper |
|
152 | - )); |
|
153 | - } |
|
154 | - |
|
155 | - $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
156 | - |
|
157 | - $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
158 | - |
|
159 | - $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
160 | - $database, |
|
161 | - $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
162 | - $httpHelper)); |
|
163 | - |
|
164 | - $page->setOAuthHelper(new OAuthHelper( |
|
165 | - $siteConfiguration->getOAuthBaseUrl(), |
|
166 | - $siteConfiguration->getOAuthConsumerToken(), |
|
167 | - $siteConfiguration->getOAuthConsumerSecret(), |
|
168 | - $httpHelper, |
|
169 | - $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
170 | - )); |
|
171 | - |
|
172 | - $page->setNotificationHelper(new IrcNotificationHelper( |
|
173 | - $siteConfiguration, |
|
174 | - $database, |
|
175 | - $notificationsDatabase)); |
|
176 | - |
|
177 | - $page->setTorExitProvider(new TorExitProvider($database)); |
|
178 | - } |
|
28 | + private $configuration; |
|
29 | + |
|
30 | + public function __construct(SiteConfiguration $configuration) |
|
31 | + { |
|
32 | + $this->configuration = $configuration; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Application entry point. |
|
37 | + * |
|
38 | + * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
39 | + */ |
|
40 | + public function run() |
|
41 | + { |
|
42 | + try { |
|
43 | + if ($this->setupEnvironment()) { |
|
44 | + $this->main(); |
|
45 | + } |
|
46 | + } |
|
47 | + catch (Exception $ex) { |
|
48 | + print $ex->getMessage(); |
|
49 | + } |
|
50 | + finally { |
|
51 | + $this->cleanupEnvironment(); |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Environment setup |
|
57 | + * |
|
58 | + * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
59 | + * and shut down prematurely. |
|
60 | + * |
|
61 | + * @return bool |
|
62 | + * @throws EnvironmentException |
|
63 | + */ |
|
64 | + protected function setupEnvironment() |
|
65 | + { |
|
66 | + $this->setupDatabase(); |
|
67 | + |
|
68 | + return true; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return PdoDatabase |
|
73 | + * @throws EnvironmentException |
|
74 | + * @throws Exception |
|
75 | + */ |
|
76 | + protected function setupDatabase() |
|
77 | + { |
|
78 | + // check the schema version |
|
79 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
80 | + |
|
81 | + /** @var int $actualVersion */ |
|
82 | + $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
83 | + if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
84 | + throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
85 | + } |
|
86 | + |
|
87 | + return $database; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return SiteConfiguration |
|
92 | + */ |
|
93 | + public function getConfiguration() |
|
94 | + { |
|
95 | + return $this->configuration; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Main application logic |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + abstract protected function main(); |
|
103 | + |
|
104 | + /** |
|
105 | + * Any cleanup tasks should go here |
|
106 | + * |
|
107 | + * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
108 | + * This should *only* be for cleaning up, no logic should go here. |
|
109 | + * |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + abstract protected function cleanupEnvironment(); |
|
113 | + |
|
114 | + /** |
|
115 | + * @param ITask $page |
|
116 | + * @param SiteConfiguration $siteConfiguration |
|
117 | + * @param PdoDatabase $database |
|
118 | + * @param PdoDatabase $notificationsDatabase |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + protected function setupHelpers( |
|
123 | + ITask $page, |
|
124 | + SiteConfiguration $siteConfiguration, |
|
125 | + PdoDatabase $database, |
|
126 | + PdoDatabase $notificationsDatabase = null |
|
127 | + ) { |
|
128 | + $page->setSiteConfiguration($siteConfiguration); |
|
129 | + |
|
130 | + // setup the global database object |
|
131 | + $page->setDatabase($database); |
|
132 | + |
|
133 | + // set up helpers and inject them into the page. |
|
134 | + $httpHelper = new HttpHelper( |
|
135 | + $siteConfiguration->getUserAgent(), |
|
136 | + $siteConfiguration->getCurlDisableVerifyPeer() |
|
137 | + ); |
|
138 | + |
|
139 | + $page->setEmailHelper(new EmailHelper()); |
|
140 | + $page->setHttpHelper($httpHelper); |
|
141 | + $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
142 | + |
|
143 | + if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
144 | + $page->setLocationProvider(new FakeLocationProvider()); |
|
145 | + } |
|
146 | + else { |
|
147 | + $page->setLocationProvider( |
|
148 | + new IpLocationProvider( |
|
149 | + $database, |
|
150 | + $siteConfiguration->getLocationProviderApiKey(), |
|
151 | + $httpHelper |
|
152 | + )); |
|
153 | + } |
|
154 | + |
|
155 | + $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
156 | + |
|
157 | + $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
158 | + |
|
159 | + $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
160 | + $database, |
|
161 | + $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
162 | + $httpHelper)); |
|
163 | + |
|
164 | + $page->setOAuthHelper(new OAuthHelper( |
|
165 | + $siteConfiguration->getOAuthBaseUrl(), |
|
166 | + $siteConfiguration->getOAuthConsumerToken(), |
|
167 | + $siteConfiguration->getOAuthConsumerSecret(), |
|
168 | + $httpHelper, |
|
169 | + $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
170 | + )); |
|
171 | + |
|
172 | + $page->setNotificationHelper(new IrcNotificationHelper( |
|
173 | + $siteConfiguration, |
|
174 | + $database, |
|
175 | + $notificationsDatabase)); |
|
176 | + |
|
177 | + $page->setTorExitProvider(new TorExitProvider($database)); |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | \ No newline at end of file |
@@ -142,8 +142,7 @@ |
||
142 | 142 | |
143 | 143 | if ($siteConfiguration->getLocationProviderApiKey() === null) { |
144 | 144 | $page->setLocationProvider(new FakeLocationProvider()); |
145 | - } |
|
146 | - else { |
|
145 | + } else { |
|
147 | 146 | $page->setLocationProvider( |
148 | 147 | new IpLocationProvider( |
149 | 148 | $database, |
@@ -21,141 +21,141 @@ |
||
21 | 21 | */ |
22 | 22 | class SessionAlert |
23 | 23 | { |
24 | - private $message; |
|
25 | - private $title; |
|
26 | - private $type; |
|
27 | - private $closable; |
|
28 | - private $block; |
|
29 | - |
|
30 | - /** |
|
31 | - * @param string $message |
|
32 | - * @param string $title |
|
33 | - * @param string $type |
|
34 | - * @param bool $closable |
|
35 | - * @param bool $block |
|
36 | - */ |
|
37 | - public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
38 | - { |
|
39 | - $this->message = $message; |
|
40 | - $this->title = $title; |
|
41 | - $this->type = $type; |
|
42 | - $this->closable = $closable; |
|
43 | - $this->block = $block; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Shows a quick one-liner message |
|
48 | - * |
|
49 | - * @param string $message |
|
50 | - * @param string $type |
|
51 | - */ |
|
52 | - public static function quick($message, $type = "alert-info") |
|
53 | - { |
|
54 | - self::append(new SessionAlert($message, "", $type, true, false)); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param SessionAlert $alert |
|
59 | - */ |
|
60 | - public static function append(SessionAlert $alert) |
|
61 | - { |
|
62 | - $data = WebRequest::getSessionAlertData(); |
|
63 | - $data[] = serialize($alert); |
|
64 | - WebRequest::setSessionAlertData($data); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Shows a quick one-liner success message |
|
69 | - * |
|
70 | - * @param string $message |
|
71 | - */ |
|
72 | - public static function success($message) |
|
73 | - { |
|
74 | - self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Shows a quick one-liner warning message |
|
79 | - * |
|
80 | - * @param string $message |
|
81 | - * @param string $title |
|
82 | - */ |
|
83 | - public static function warning($message, $title = "Warning!") |
|
84 | - { |
|
85 | - self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Shows a quick one-liner error message |
|
90 | - * |
|
91 | - * @param string $message |
|
92 | - * @param string $title |
|
93 | - */ |
|
94 | - public static function error($message, $title = "Error!") |
|
95 | - { |
|
96 | - self::append(new SessionAlert($message, $title, "alert-error", true, true)); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Retrieves the alerts which have been saved to the session |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public static function getAlerts() |
|
104 | - { |
|
105 | - $alertData = array(); |
|
106 | - |
|
107 | - foreach (WebRequest::getSessionAlertData() as $a) { |
|
108 | - $alertData[] = unserialize($a); |
|
109 | - } |
|
110 | - |
|
111 | - return $alertData; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Clears the alerts from the session |
|
116 | - */ |
|
117 | - public static function clearAlerts() |
|
118 | - { |
|
119 | - WebRequest::clearSessionAlertData(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return boolean |
|
124 | - */ |
|
125 | - public function isBlock() |
|
126 | - { |
|
127 | - return $this->block; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return boolean |
|
132 | - */ |
|
133 | - public function isClosable() |
|
134 | - { |
|
135 | - return $this->closable; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function getType() |
|
142 | - { |
|
143 | - return $this->type; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function getTitle() |
|
150 | - { |
|
151 | - return $this->title; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function getMessage() |
|
158 | - { |
|
159 | - return $this->message; |
|
160 | - } |
|
24 | + private $message; |
|
25 | + private $title; |
|
26 | + private $type; |
|
27 | + private $closable; |
|
28 | + private $block; |
|
29 | + |
|
30 | + /** |
|
31 | + * @param string $message |
|
32 | + * @param string $title |
|
33 | + * @param string $type |
|
34 | + * @param bool $closable |
|
35 | + * @param bool $block |
|
36 | + */ |
|
37 | + public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
38 | + { |
|
39 | + $this->message = $message; |
|
40 | + $this->title = $title; |
|
41 | + $this->type = $type; |
|
42 | + $this->closable = $closable; |
|
43 | + $this->block = $block; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Shows a quick one-liner message |
|
48 | + * |
|
49 | + * @param string $message |
|
50 | + * @param string $type |
|
51 | + */ |
|
52 | + public static function quick($message, $type = "alert-info") |
|
53 | + { |
|
54 | + self::append(new SessionAlert($message, "", $type, true, false)); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param SessionAlert $alert |
|
59 | + */ |
|
60 | + public static function append(SessionAlert $alert) |
|
61 | + { |
|
62 | + $data = WebRequest::getSessionAlertData(); |
|
63 | + $data[] = serialize($alert); |
|
64 | + WebRequest::setSessionAlertData($data); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Shows a quick one-liner success message |
|
69 | + * |
|
70 | + * @param string $message |
|
71 | + */ |
|
72 | + public static function success($message) |
|
73 | + { |
|
74 | + self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Shows a quick one-liner warning message |
|
79 | + * |
|
80 | + * @param string $message |
|
81 | + * @param string $title |
|
82 | + */ |
|
83 | + public static function warning($message, $title = "Warning!") |
|
84 | + { |
|
85 | + self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Shows a quick one-liner error message |
|
90 | + * |
|
91 | + * @param string $message |
|
92 | + * @param string $title |
|
93 | + */ |
|
94 | + public static function error($message, $title = "Error!") |
|
95 | + { |
|
96 | + self::append(new SessionAlert($message, $title, "alert-error", true, true)); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Retrieves the alerts which have been saved to the session |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public static function getAlerts() |
|
104 | + { |
|
105 | + $alertData = array(); |
|
106 | + |
|
107 | + foreach (WebRequest::getSessionAlertData() as $a) { |
|
108 | + $alertData[] = unserialize($a); |
|
109 | + } |
|
110 | + |
|
111 | + return $alertData; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Clears the alerts from the session |
|
116 | + */ |
|
117 | + public static function clearAlerts() |
|
118 | + { |
|
119 | + WebRequest::clearSessionAlertData(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return boolean |
|
124 | + */ |
|
125 | + public function isBlock() |
|
126 | + { |
|
127 | + return $this->block; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return boolean |
|
132 | + */ |
|
133 | + public function isClosable() |
|
134 | + { |
|
135 | + return $this->closable; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getType() |
|
142 | + { |
|
143 | + return $this->type; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function getTitle() |
|
150 | + { |
|
151 | + return $this->title; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function getMessage() |
|
158 | + { |
|
159 | + return $this->message; |
|
160 | + } |
|
161 | 161 | } |
@@ -13,36 +13,36 @@ |
||
13 | 13 | */ |
14 | 14 | class AutoLoader |
15 | 15 | { |
16 | - public static function load($class) |
|
17 | - { |
|
18 | - // handle namespaces sensibly |
|
19 | - if (strpos($class, "Waca") !== false) { |
|
20 | - // strip off the initial namespace |
|
21 | - $class = str_replace("Waca\\", "", $class); |
|
16 | + public static function load($class) |
|
17 | + { |
|
18 | + // handle namespaces sensibly |
|
19 | + if (strpos($class, "Waca") !== false) { |
|
20 | + // strip off the initial namespace |
|
21 | + $class = str_replace("Waca\\", "", $class); |
|
22 | 22 | |
23 | - // swap backslashes for forward slashes to map to directory names |
|
24 | - $class = str_replace("\\", "/", $class); |
|
25 | - } |
|
23 | + // swap backslashes for forward slashes to map to directory names |
|
24 | + $class = str_replace("\\", "/", $class); |
|
25 | + } |
|
26 | 26 | |
27 | - $paths = array( |
|
28 | - __DIR__ . '/' . $class . ".php", |
|
29 | - __DIR__ . '/DataObjects/' . $class . ".php", |
|
30 | - __DIR__ . '/Providers/' . $class . ".php", |
|
31 | - __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
32 | - __DIR__ . '/Validation/' . $class . ".php", |
|
33 | - __DIR__ . '/Helpers/' . $class . ".php", |
|
34 | - __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
35 | - __DIR__ . '/' . $class . ".php", |
|
36 | - ); |
|
27 | + $paths = array( |
|
28 | + __DIR__ . '/' . $class . ".php", |
|
29 | + __DIR__ . '/DataObjects/' . $class . ".php", |
|
30 | + __DIR__ . '/Providers/' . $class . ".php", |
|
31 | + __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
32 | + __DIR__ . '/Validation/' . $class . ".php", |
|
33 | + __DIR__ . '/Helpers/' . $class . ".php", |
|
34 | + __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
35 | + __DIR__ . '/' . $class . ".php", |
|
36 | + ); |
|
37 | 37 | |
38 | - foreach ($paths as $file) { |
|
39 | - if (file_exists($file)) { |
|
40 | - require_once($file); |
|
41 | - } |
|
38 | + foreach ($paths as $file) { |
|
39 | + if (file_exists($file)) { |
|
40 | + require_once($file); |
|
41 | + } |
|
42 | 42 | |
43 | - if (class_exists($class)) { |
|
44 | - return; |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
43 | + if (class_exists($class)) { |
|
44 | + return; |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | 48 | } |
@@ -16,97 +16,97 @@ |
||
16 | 16 | |
17 | 17 | abstract class ApiPageBase extends TaskBase implements IRoutedTask, IApiAction |
18 | 18 | { |
19 | - /** |
|
20 | - * API result document |
|
21 | - * @var DOMDocument |
|
22 | - */ |
|
23 | - protected $document; |
|
24 | - |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->document = new DOMDocument('1.0'); |
|
28 | - } |
|
29 | - |
|
30 | - final public function execute() |
|
31 | - { |
|
32 | - $this->main(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $routeName |
|
37 | - */ |
|
38 | - public function setRoute($routeName) |
|
39 | - { |
|
40 | - // no-op |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function getRouteName() |
|
47 | - { |
|
48 | - return 'main'; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Main function for this page, when no specific actions are called. |
|
53 | - * |
|
54 | - * @throws ApiException |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - final protected function main() |
|
58 | - { |
|
59 | - if (headers_sent()) { |
|
60 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
61 | - } |
|
62 | - |
|
63 | - header("Content-Type: text/xml"); |
|
64 | - |
|
65 | - // javascript access control |
|
66 | - $httpOrigin = WebRequest::origin(); |
|
67 | - |
|
68 | - if ($httpOrigin !== null) { |
|
69 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
70 | - |
|
71 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
72 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - $responseData = $this->runApiPage(); |
|
77 | - |
|
78 | - ob_end_clean(); |
|
79 | - print($responseData); |
|
80 | - ob_start(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Method that runs API action |
|
85 | - * |
|
86 | - * @param DOMElement $apiDocument |
|
87 | - * |
|
88 | - * @return DOMElement |
|
89 | - */ |
|
90 | - abstract public function executeApiAction(DOMElement $apiDocument); |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - final public function runApiPage() |
|
96 | - { |
|
97 | - $apiDocument = $this->document->createElement("api"); |
|
98 | - |
|
99 | - try { |
|
100 | - $apiDocument = $this->executeApiAction($apiDocument); |
|
101 | - } |
|
102 | - catch (ApiException $ex) { |
|
103 | - $exception = $this->document->createElement("error"); |
|
104 | - $exception->setAttribute("message", $ex->getMessage()); |
|
105 | - $apiDocument->appendChild($exception); |
|
106 | - } |
|
107 | - |
|
108 | - $this->document->appendChild($apiDocument); |
|
109 | - |
|
110 | - return $this->document->saveXML(); |
|
111 | - } |
|
19 | + /** |
|
20 | + * API result document |
|
21 | + * @var DOMDocument |
|
22 | + */ |
|
23 | + protected $document; |
|
24 | + |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->document = new DOMDocument('1.0'); |
|
28 | + } |
|
29 | + |
|
30 | + final public function execute() |
|
31 | + { |
|
32 | + $this->main(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $routeName |
|
37 | + */ |
|
38 | + public function setRoute($routeName) |
|
39 | + { |
|
40 | + // no-op |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function getRouteName() |
|
47 | + { |
|
48 | + return 'main'; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Main function for this page, when no specific actions are called. |
|
53 | + * |
|
54 | + * @throws ApiException |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + final protected function main() |
|
58 | + { |
|
59 | + if (headers_sent()) { |
|
60 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
61 | + } |
|
62 | + |
|
63 | + header("Content-Type: text/xml"); |
|
64 | + |
|
65 | + // javascript access control |
|
66 | + $httpOrigin = WebRequest::origin(); |
|
67 | + |
|
68 | + if ($httpOrigin !== null) { |
|
69 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
70 | + |
|
71 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
72 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + $responseData = $this->runApiPage(); |
|
77 | + |
|
78 | + ob_end_clean(); |
|
79 | + print($responseData); |
|
80 | + ob_start(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Method that runs API action |
|
85 | + * |
|
86 | + * @param DOMElement $apiDocument |
|
87 | + * |
|
88 | + * @return DOMElement |
|
89 | + */ |
|
90 | + abstract public function executeApiAction(DOMElement $apiDocument); |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + final public function runApiPage() |
|
96 | + { |
|
97 | + $apiDocument = $this->document->createElement("api"); |
|
98 | + |
|
99 | + try { |
|
100 | + $apiDocument = $this->executeApiAction($apiDocument); |
|
101 | + } |
|
102 | + catch (ApiException $ex) { |
|
103 | + $exception = $this->document->createElement("error"); |
|
104 | + $exception->setAttribute("message", $ex->getMessage()); |
|
105 | + $apiDocument->appendChild($exception); |
|
106 | + } |
|
107 | + |
|
108 | + $this->document->appendChild($apiDocument); |
|
109 | + |
|
110 | + return $this->document->saveXML(); |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -10,21 +10,21 @@ |
||
10 | 10 | |
11 | 11 | abstract class PublicInterfacePageBase extends PageBase |
12 | 12 | { |
13 | - /** |
|
14 | - * PublicInterfaceInternalPageBase constructor. |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - $this->template = 'publicbase.tpl'; |
|
19 | - } |
|
13 | + /** |
|
14 | + * PublicInterfaceInternalPageBase constructor. |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + $this->template = 'publicbase.tpl'; |
|
19 | + } |
|
20 | 20 | |
21 | - final public function execute() |
|
22 | - { |
|
23 | - parent::execute(); |
|
24 | - } |
|
21 | + final public function execute() |
|
22 | + { |
|
23 | + parent::execute(); |
|
24 | + } |
|
25 | 25 | |
26 | - final public function finalisePage() |
|
27 | - { |
|
28 | - parent::finalisePage(); |
|
29 | - } |
|
26 | + final public function finalisePage() |
|
27 | + { |
|
28 | + parent::finalisePage(); |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -23,149 +23,149 @@ |
||
23 | 23 | |
24 | 24 | interface ITask |
25 | 25 | { |
26 | - /** |
|
27 | - * @return IEmailHelper |
|
28 | - */ |
|
29 | - public function getEmailHelper(); |
|
30 | - |
|
31 | - /** |
|
32 | - * @param IEmailHelper $emailHelper |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setEmailHelper($emailHelper); |
|
37 | - |
|
38 | - /** |
|
39 | - * @return HttpHelper |
|
40 | - */ |
|
41 | - public function getHttpHelper(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @param HttpHelper $httpHelper |
|
45 | - * |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function setHttpHelper($httpHelper); |
|
49 | - |
|
50 | - /** |
|
51 | - * @return WikiTextHelper |
|
52 | - */ |
|
53 | - public function getWikiTextHelper(); |
|
54 | - |
|
55 | - /** |
|
56 | - * @param WikiTextHelper $wikiTextHelper |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function setWikiTextHelper($wikiTextHelper); |
|
61 | - |
|
62 | - /** |
|
63 | - * @return ILocationProvider |
|
64 | - */ |
|
65 | - public function getLocationProvider(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @param ILocationProvider $locationProvider |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function setLocationProvider(ILocationProvider $locationProvider); |
|
73 | - |
|
74 | - /** |
|
75 | - * @return IXffTrustProvider |
|
76 | - */ |
|
77 | - public function getXffTrustProvider(); |
|
78 | - |
|
79 | - /** |
|
80 | - * @param IXffTrustProvider $xffTrustProvider |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
85 | - |
|
86 | - /** |
|
87 | - * @return IRDnsProvider |
|
88 | - */ |
|
89 | - public function getRdnsProvider(); |
|
90 | - |
|
91 | - /** |
|
92 | - * @param IRDnsProvider $rdnsProvider |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function setRdnsProvider($rdnsProvider); |
|
97 | - |
|
98 | - /** |
|
99 | - * @return IAntiSpoofProvider |
|
100 | - */ |
|
101 | - public function getAntiSpoofProvider(); |
|
102 | - |
|
103 | - /** |
|
104 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function setAntiSpoofProvider($antiSpoofProvider); |
|
109 | - |
|
110 | - /** |
|
111 | - * @return PdoDatabase |
|
112 | - */ |
|
113 | - public function getDatabase(); |
|
114 | - |
|
115 | - /** |
|
116 | - * @param PdoDatabase $database |
|
117 | - * |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function setDatabase($database); |
|
121 | - |
|
122 | - /** |
|
123 | - * @return IOAuthHelper |
|
124 | - */ |
|
125 | - public function getOAuthHelper(); |
|
126 | - |
|
127 | - /** |
|
128 | - * @param IOAuthHelper $oauthHelper |
|
129 | - * |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function setOAuthHelper($oauthHelper); |
|
133 | - |
|
134 | - /** |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - public function execute(); |
|
138 | - |
|
139 | - /** |
|
140 | - * Sets the site configuration object for this page |
|
141 | - * |
|
142 | - * @param SiteConfiguration $configuration |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function setSiteConfiguration($configuration); |
|
147 | - |
|
148 | - /** |
|
149 | - * @return IrcNotificationHelper |
|
150 | - */ |
|
151 | - public function getNotificationHelper(); |
|
152 | - |
|
153 | - /** |
|
154 | - * @param IrcNotificationHelper $notificationHelper |
|
155 | - * |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function setNotificationHelper($notificationHelper); |
|
159 | - |
|
160 | - /** |
|
161 | - * @return TorExitProvider |
|
162 | - */ |
|
163 | - public function getTorExitProvider(); |
|
164 | - |
|
165 | - /** |
|
166 | - * @param TorExitProvider $torExitProvider |
|
167 | - * |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function setTorExitProvider($torExitProvider); |
|
26 | + /** |
|
27 | + * @return IEmailHelper |
|
28 | + */ |
|
29 | + public function getEmailHelper(); |
|
30 | + |
|
31 | + /** |
|
32 | + * @param IEmailHelper $emailHelper |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setEmailHelper($emailHelper); |
|
37 | + |
|
38 | + /** |
|
39 | + * @return HttpHelper |
|
40 | + */ |
|
41 | + public function getHttpHelper(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @param HttpHelper $httpHelper |
|
45 | + * |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function setHttpHelper($httpHelper); |
|
49 | + |
|
50 | + /** |
|
51 | + * @return WikiTextHelper |
|
52 | + */ |
|
53 | + public function getWikiTextHelper(); |
|
54 | + |
|
55 | + /** |
|
56 | + * @param WikiTextHelper $wikiTextHelper |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function setWikiTextHelper($wikiTextHelper); |
|
61 | + |
|
62 | + /** |
|
63 | + * @return ILocationProvider |
|
64 | + */ |
|
65 | + public function getLocationProvider(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @param ILocationProvider $locationProvider |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function setLocationProvider(ILocationProvider $locationProvider); |
|
73 | + |
|
74 | + /** |
|
75 | + * @return IXffTrustProvider |
|
76 | + */ |
|
77 | + public function getXffTrustProvider(); |
|
78 | + |
|
79 | + /** |
|
80 | + * @param IXffTrustProvider $xffTrustProvider |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
85 | + |
|
86 | + /** |
|
87 | + * @return IRDnsProvider |
|
88 | + */ |
|
89 | + public function getRdnsProvider(); |
|
90 | + |
|
91 | + /** |
|
92 | + * @param IRDnsProvider $rdnsProvider |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function setRdnsProvider($rdnsProvider); |
|
97 | + |
|
98 | + /** |
|
99 | + * @return IAntiSpoofProvider |
|
100 | + */ |
|
101 | + public function getAntiSpoofProvider(); |
|
102 | + |
|
103 | + /** |
|
104 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function setAntiSpoofProvider($antiSpoofProvider); |
|
109 | + |
|
110 | + /** |
|
111 | + * @return PdoDatabase |
|
112 | + */ |
|
113 | + public function getDatabase(); |
|
114 | + |
|
115 | + /** |
|
116 | + * @param PdoDatabase $database |
|
117 | + * |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function setDatabase($database); |
|
121 | + |
|
122 | + /** |
|
123 | + * @return IOAuthHelper |
|
124 | + */ |
|
125 | + public function getOAuthHelper(); |
|
126 | + |
|
127 | + /** |
|
128 | + * @param IOAuthHelper $oauthHelper |
|
129 | + * |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function setOAuthHelper($oauthHelper); |
|
133 | + |
|
134 | + /** |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + public function execute(); |
|
138 | + |
|
139 | + /** |
|
140 | + * Sets the site configuration object for this page |
|
141 | + * |
|
142 | + * @param SiteConfiguration $configuration |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function setSiteConfiguration($configuration); |
|
147 | + |
|
148 | + /** |
|
149 | + * @return IrcNotificationHelper |
|
150 | + */ |
|
151 | + public function getNotificationHelper(); |
|
152 | + |
|
153 | + /** |
|
154 | + * @param IrcNotificationHelper $notificationHelper |
|
155 | + * |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function setNotificationHelper($notificationHelper); |
|
159 | + |
|
160 | + /** |
|
161 | + * @return TorExitProvider |
|
162 | + */ |
|
163 | + public function getTorExitProvider(); |
|
164 | + |
|
165 | + /** |
|
166 | + * @param TorExitProvider $torExitProvider |
|
167 | + * |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function setTorExitProvider($torExitProvider); |
|
171 | 171 | } |
172 | 172 | \ No newline at end of file |
@@ -23,229 +23,229 @@ |
||
23 | 23 | |
24 | 24 | abstract class TaskBase implements ITask |
25 | 25 | { |
26 | - /** @var SiteConfiguration */ |
|
27 | - private $siteConfiguration; |
|
28 | - /** @var IEmailHelper */ |
|
29 | - private $emailHelper; |
|
30 | - /** @var HttpHelper */ |
|
31 | - private $httpHelper; |
|
32 | - /** @var WikiTextHelper */ |
|
33 | - private $wikiTextHelper; |
|
34 | - /** @var ILocationProvider */ |
|
35 | - private $locationProvider; |
|
36 | - /** @var IXffTrustProvider */ |
|
37 | - private $xffTrustProvider; |
|
38 | - /** @var IRDnsProvider */ |
|
39 | - private $rdnsProvider; |
|
40 | - /** @var IAntiSpoofProvider */ |
|
41 | - private $antiSpoofProvider; |
|
42 | - /** @var IOAuthHelper */ |
|
43 | - private $oauthHelper; |
|
44 | - /** @var PdoDatabase */ |
|
45 | - private $database; |
|
46 | - /** @var IrcNotificationHelper */ |
|
47 | - private $notificationHelper; |
|
48 | - /** @var TorExitProvider */ |
|
49 | - private $torExitProvider; |
|
50 | - |
|
51 | - /** |
|
52 | - * @return IEmailHelper |
|
53 | - */ |
|
54 | - final public function getEmailHelper() |
|
55 | - { |
|
56 | - return $this->emailHelper; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IEmailHelper $emailHelper |
|
61 | - */ |
|
62 | - final public function setEmailHelper($emailHelper) |
|
63 | - { |
|
64 | - $this->emailHelper = $emailHelper; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @return HttpHelper |
|
69 | - */ |
|
70 | - final public function getHttpHelper() |
|
71 | - { |
|
72 | - return $this->httpHelper; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param HttpHelper $httpHelper |
|
77 | - */ |
|
78 | - final public function setHttpHelper($httpHelper) |
|
79 | - { |
|
80 | - $this->httpHelper = $httpHelper; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return WikiTextHelper |
|
85 | - */ |
|
86 | - final public function getWikiTextHelper() |
|
87 | - { |
|
88 | - return $this->wikiTextHelper; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param WikiTextHelper $wikiTextHelper |
|
93 | - */ |
|
94 | - final public function setWikiTextHelper($wikiTextHelper) |
|
95 | - { |
|
96 | - $this->wikiTextHelper = $wikiTextHelper; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return ILocationProvider |
|
101 | - */ |
|
102 | - final public function getLocationProvider() |
|
103 | - { |
|
104 | - return $this->locationProvider; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param ILocationProvider $locationProvider |
|
109 | - */ |
|
110 | - final public function setLocationProvider(ILocationProvider $locationProvider) |
|
111 | - { |
|
112 | - $this->locationProvider = $locationProvider; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @return IXffTrustProvider |
|
117 | - */ |
|
118 | - final public function getXffTrustProvider() |
|
119 | - { |
|
120 | - return $this->xffTrustProvider; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param IXffTrustProvider $xffTrustProvider |
|
125 | - */ |
|
126 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
127 | - { |
|
128 | - $this->xffTrustProvider = $xffTrustProvider; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return IRDnsProvider |
|
133 | - */ |
|
134 | - final public function getRdnsProvider() |
|
135 | - { |
|
136 | - return $this->rdnsProvider; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param IRDnsProvider $rdnsProvider |
|
141 | - */ |
|
142 | - public function setRdnsProvider($rdnsProvider) |
|
143 | - { |
|
144 | - $this->rdnsProvider = $rdnsProvider; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return IAntiSpoofProvider |
|
149 | - */ |
|
150 | - public function getAntiSpoofProvider() |
|
151 | - { |
|
152 | - return $this->antiSpoofProvider; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
157 | - */ |
|
158 | - public function setAntiSpoofProvider($antiSpoofProvider) |
|
159 | - { |
|
160 | - $this->antiSpoofProvider = $antiSpoofProvider; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return PdoDatabase |
|
165 | - */ |
|
166 | - final public function getDatabase() |
|
167 | - { |
|
168 | - return $this->database; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param PdoDatabase $database |
|
173 | - */ |
|
174 | - final public function setDatabase($database) |
|
175 | - { |
|
176 | - $this->database = $database; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return IOAuthHelper |
|
181 | - */ |
|
182 | - public function getOAuthHelper() |
|
183 | - { |
|
184 | - return $this->oauthHelper; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param IOAuthHelper $oauthHelper |
|
189 | - */ |
|
190 | - public function setOAuthHelper($oauthHelper) |
|
191 | - { |
|
192 | - $this->oauthHelper = $oauthHelper; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @return void |
|
197 | - */ |
|
198 | - abstract public function execute(); |
|
199 | - |
|
200 | - /** |
|
201 | - * @return IrcNotificationHelper |
|
202 | - */ |
|
203 | - public function getNotificationHelper() |
|
204 | - { |
|
205 | - return $this->notificationHelper; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param IrcNotificationHelper $notificationHelper |
|
210 | - */ |
|
211 | - public function setNotificationHelper($notificationHelper) |
|
212 | - { |
|
213 | - $this->notificationHelper = $notificationHelper; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @return TorExitProvider |
|
218 | - */ |
|
219 | - public function getTorExitProvider() |
|
220 | - { |
|
221 | - return $this->torExitProvider; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param TorExitProvider $torExitProvider |
|
226 | - */ |
|
227 | - public function setTorExitProvider($torExitProvider) |
|
228 | - { |
|
229 | - $this->torExitProvider = $torExitProvider; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Gets the site configuration object |
|
234 | - * |
|
235 | - * @return SiteConfiguration |
|
236 | - */ |
|
237 | - final protected function getSiteConfiguration() |
|
238 | - { |
|
239 | - return $this->siteConfiguration; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets the site configuration object for this page |
|
244 | - * |
|
245 | - * @param SiteConfiguration $configuration |
|
246 | - */ |
|
247 | - final public function setSiteConfiguration($configuration) |
|
248 | - { |
|
249 | - $this->siteConfiguration = $configuration; |
|
250 | - } |
|
26 | + /** @var SiteConfiguration */ |
|
27 | + private $siteConfiguration; |
|
28 | + /** @var IEmailHelper */ |
|
29 | + private $emailHelper; |
|
30 | + /** @var HttpHelper */ |
|
31 | + private $httpHelper; |
|
32 | + /** @var WikiTextHelper */ |
|
33 | + private $wikiTextHelper; |
|
34 | + /** @var ILocationProvider */ |
|
35 | + private $locationProvider; |
|
36 | + /** @var IXffTrustProvider */ |
|
37 | + private $xffTrustProvider; |
|
38 | + /** @var IRDnsProvider */ |
|
39 | + private $rdnsProvider; |
|
40 | + /** @var IAntiSpoofProvider */ |
|
41 | + private $antiSpoofProvider; |
|
42 | + /** @var IOAuthHelper */ |
|
43 | + private $oauthHelper; |
|
44 | + /** @var PdoDatabase */ |
|
45 | + private $database; |
|
46 | + /** @var IrcNotificationHelper */ |
|
47 | + private $notificationHelper; |
|
48 | + /** @var TorExitProvider */ |
|
49 | + private $torExitProvider; |
|
50 | + |
|
51 | + /** |
|
52 | + * @return IEmailHelper |
|
53 | + */ |
|
54 | + final public function getEmailHelper() |
|
55 | + { |
|
56 | + return $this->emailHelper; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IEmailHelper $emailHelper |
|
61 | + */ |
|
62 | + final public function setEmailHelper($emailHelper) |
|
63 | + { |
|
64 | + $this->emailHelper = $emailHelper; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @return HttpHelper |
|
69 | + */ |
|
70 | + final public function getHttpHelper() |
|
71 | + { |
|
72 | + return $this->httpHelper; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param HttpHelper $httpHelper |
|
77 | + */ |
|
78 | + final public function setHttpHelper($httpHelper) |
|
79 | + { |
|
80 | + $this->httpHelper = $httpHelper; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return WikiTextHelper |
|
85 | + */ |
|
86 | + final public function getWikiTextHelper() |
|
87 | + { |
|
88 | + return $this->wikiTextHelper; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param WikiTextHelper $wikiTextHelper |
|
93 | + */ |
|
94 | + final public function setWikiTextHelper($wikiTextHelper) |
|
95 | + { |
|
96 | + $this->wikiTextHelper = $wikiTextHelper; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return ILocationProvider |
|
101 | + */ |
|
102 | + final public function getLocationProvider() |
|
103 | + { |
|
104 | + return $this->locationProvider; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param ILocationProvider $locationProvider |
|
109 | + */ |
|
110 | + final public function setLocationProvider(ILocationProvider $locationProvider) |
|
111 | + { |
|
112 | + $this->locationProvider = $locationProvider; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @return IXffTrustProvider |
|
117 | + */ |
|
118 | + final public function getXffTrustProvider() |
|
119 | + { |
|
120 | + return $this->xffTrustProvider; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param IXffTrustProvider $xffTrustProvider |
|
125 | + */ |
|
126 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
127 | + { |
|
128 | + $this->xffTrustProvider = $xffTrustProvider; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return IRDnsProvider |
|
133 | + */ |
|
134 | + final public function getRdnsProvider() |
|
135 | + { |
|
136 | + return $this->rdnsProvider; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param IRDnsProvider $rdnsProvider |
|
141 | + */ |
|
142 | + public function setRdnsProvider($rdnsProvider) |
|
143 | + { |
|
144 | + $this->rdnsProvider = $rdnsProvider; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return IAntiSpoofProvider |
|
149 | + */ |
|
150 | + public function getAntiSpoofProvider() |
|
151 | + { |
|
152 | + return $this->antiSpoofProvider; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
157 | + */ |
|
158 | + public function setAntiSpoofProvider($antiSpoofProvider) |
|
159 | + { |
|
160 | + $this->antiSpoofProvider = $antiSpoofProvider; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return PdoDatabase |
|
165 | + */ |
|
166 | + final public function getDatabase() |
|
167 | + { |
|
168 | + return $this->database; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param PdoDatabase $database |
|
173 | + */ |
|
174 | + final public function setDatabase($database) |
|
175 | + { |
|
176 | + $this->database = $database; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return IOAuthHelper |
|
181 | + */ |
|
182 | + public function getOAuthHelper() |
|
183 | + { |
|
184 | + return $this->oauthHelper; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param IOAuthHelper $oauthHelper |
|
189 | + */ |
|
190 | + public function setOAuthHelper($oauthHelper) |
|
191 | + { |
|
192 | + $this->oauthHelper = $oauthHelper; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @return void |
|
197 | + */ |
|
198 | + abstract public function execute(); |
|
199 | + |
|
200 | + /** |
|
201 | + * @return IrcNotificationHelper |
|
202 | + */ |
|
203 | + public function getNotificationHelper() |
|
204 | + { |
|
205 | + return $this->notificationHelper; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param IrcNotificationHelper $notificationHelper |
|
210 | + */ |
|
211 | + public function setNotificationHelper($notificationHelper) |
|
212 | + { |
|
213 | + $this->notificationHelper = $notificationHelper; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @return TorExitProvider |
|
218 | + */ |
|
219 | + public function getTorExitProvider() |
|
220 | + { |
|
221 | + return $this->torExitProvider; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param TorExitProvider $torExitProvider |
|
226 | + */ |
|
227 | + public function setTorExitProvider($torExitProvider) |
|
228 | + { |
|
229 | + $this->torExitProvider = $torExitProvider; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Gets the site configuration object |
|
234 | + * |
|
235 | + * @return SiteConfiguration |
|
236 | + */ |
|
237 | + final protected function getSiteConfiguration() |
|
238 | + { |
|
239 | + return $this->siteConfiguration; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets the site configuration object for this page |
|
244 | + * |
|
245 | + * @param SiteConfiguration $configuration |
|
246 | + */ |
|
247 | + final public function setSiteConfiguration($configuration) |
|
248 | + { |
|
249 | + $this->siteConfiguration = $configuration; |
|
250 | + } |
|
251 | 251 | } |
252 | 252 | \ No newline at end of file |
@@ -12,21 +12,21 @@ |
||
12 | 12 | |
13 | 13 | interface IRoutedTask extends ITask |
14 | 14 | { |
15 | - /** |
|
16 | - * Sets the route the request will take. Only should be called from the request router. |
|
17 | - * |
|
18 | - * @param $routeName string |
|
19 | - * |
|
20 | - * @return void |
|
21 | - * |
|
22 | - * @throws Exception |
|
23 | - * @category Security-Critical |
|
24 | - */ |
|
25 | - public function setRoute($routeName); |
|
15 | + /** |
|
16 | + * Sets the route the request will take. Only should be called from the request router. |
|
17 | + * |
|
18 | + * @param $routeName string |
|
19 | + * |
|
20 | + * @return void |
|
21 | + * |
|
22 | + * @throws Exception |
|
23 | + * @category Security-Critical |
|
24 | + */ |
|
25 | + public function setRoute($routeName); |
|
26 | 26 | |
27 | - /** |
|
28 | - * Gets the name of the route that has been passed from the request router. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function getRouteName(); |
|
27 | + /** |
|
28 | + * Gets the name of the route that has been passed from the request router. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function getRouteName(); |
|
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -22,225 +22,225 @@ |
||
22 | 22 | |
23 | 23 | abstract class InternalPageBase extends PageBase |
24 | 24 | { |
25 | - use NavigationMenuAccessControl; |
|
26 | - |
|
27 | - /** @var IdentificationVerifier */ |
|
28 | - private $identificationVerifier; |
|
29 | - /** @var ITypeAheadHelper */ |
|
30 | - private $typeAheadHelper; |
|
31 | - /** @var SecurityManager */ |
|
32 | - private $securityManager; |
|
33 | - /** @var IBlacklistHelper */ |
|
34 | - private $blacklistHelper; |
|
35 | - |
|
36 | - /** |
|
37 | - * @return ITypeAheadHelper |
|
38 | - */ |
|
39 | - public function getTypeAheadHelper() |
|
40 | - { |
|
41 | - return $this->typeAheadHelper; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Sets up the internal IdentificationVerifier instance. Intended to be called from WebStart::setupHelpers(). |
|
46 | - * |
|
47 | - * @param IdentificationVerifier $identificationVerifier |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier) |
|
52 | - { |
|
53 | - $this->identificationVerifier = $identificationVerifier; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param ITypeAheadHelper $typeAheadHelper |
|
58 | - */ |
|
59 | - public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
60 | - { |
|
61 | - $this->typeAheadHelper = $typeAheadHelper; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Runs the page code |
|
66 | - * |
|
67 | - * @throws Exception |
|
68 | - * @category Security-Critical |
|
69 | - */ |
|
70 | - final public function execute() |
|
71 | - { |
|
72 | - if ($this->getRouteName() === null) { |
|
73 | - throw new Exception("Request is unrouted."); |
|
74 | - } |
|
75 | - |
|
76 | - if ($this->getSiteConfiguration() === null) { |
|
77 | - throw new Exception("Page has no configuration!"); |
|
78 | - } |
|
79 | - |
|
80 | - $this->setupPage(); |
|
81 | - |
|
82 | - $this->touchUserLastActive(); |
|
83 | - |
|
84 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
85 | - |
|
86 | - // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
87 | - if (!$this->isProtectedPage()) { |
|
88 | - // This page is /not/ a protected page, as such we can just run it. |
|
89 | - $this->runPage(); |
|
90 | - |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - // Security barrier. |
|
95 | - // |
|
96 | - // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
97 | - // away for us |
|
98 | - $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
99 | - if ($securityResult === SecurityManager::ALLOWED) { |
|
100 | - // We're allowed to run the page, so let's run it. |
|
101 | - $this->runPage(); |
|
102 | - } |
|
103 | - else { |
|
104 | - $this->handleAccessDenied($securityResult); |
|
105 | - |
|
106 | - // Send the headers |
|
107 | - $this->sendResponseHeaders(); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Performs final tasks needed before rendering the page. |
|
113 | - */ |
|
114 | - final public function finalisePage() |
|
115 | - { |
|
116 | - parent::finalisePage(); |
|
117 | - |
|
118 | - $this->assign('typeAheadBlock', $this->getTypeAheadHelper()->getTypeAheadScriptBlock()); |
|
119 | - |
|
120 | - $database = $this->getDatabase(); |
|
121 | - |
|
122 | - $currentUser = User::getCurrent($database); |
|
123 | - if (!$currentUser->isCommunityUser()) { |
|
124 | - $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
125 | - $statement = $database->query($sql); |
|
126 | - $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
127 | - $this->assign('onlineusers', $activeUsers); |
|
128 | - } |
|
129 | - |
|
130 | - $this->setupNavMenuAccess($currentUser); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Configures whether the page respects roles or not. You probably want this to return true. |
|
135 | - * |
|
136 | - * Set to false for public pages. You probably want this to return true. |
|
137 | - * |
|
138 | - * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
139 | - * on this page, so you probably want this to return true. |
|
140 | - * |
|
141 | - * @return bool |
|
142 | - * @category Security-Critical |
|
143 | - */ |
|
144 | - protected function isProtectedPage() |
|
145 | - { |
|
146 | - return true; |
|
147 | - } |
|
148 | - |
|
149 | - protected function handleAccessDenied($denyReason) |
|
150 | - { |
|
151 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
152 | - |
|
153 | - // Not allowed to access this resource. |
|
154 | - // Firstly, let's check if we're even logged in. |
|
155 | - if ($currentUser->isCommunityUser()) { |
|
156 | - // Not logged in, redirect to login page |
|
157 | - WebRequest::setPostLoginRedirect(); |
|
158 | - $this->redirect("login"); |
|
159 | - |
|
160 | - return; |
|
161 | - } |
|
162 | - else { |
|
163 | - // Decide whether this was a rights failure, or an identification failure. |
|
164 | - |
|
165 | - if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
|
166 | - // Not identified |
|
167 | - throw new NotIdentifiedException($this->getSecurityManager()); |
|
168 | - } |
|
169 | - elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
170 | - // Nope, plain old access denied |
|
171 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
172 | - } |
|
173 | - else { |
|
174 | - throw new Exception('Unknown response from security manager.'); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Tests the security barrier for a specified action. |
|
181 | - * |
|
182 | - * Don't use within templates |
|
183 | - * |
|
184 | - * @param string $action |
|
185 | - * |
|
186 | - * @param User $user |
|
187 | - * @param null|string $pageName |
|
188 | - * |
|
189 | - * @return bool |
|
190 | - * @category Security-Critical |
|
191 | - */ |
|
192 | - final public function barrierTest($action, User $user, $pageName = null) |
|
193 | - { |
|
194 | - $page = get_called_class(); |
|
195 | - if ($pageName !== null) { |
|
196 | - $page = $pageName; |
|
197 | - } |
|
198 | - |
|
199 | - $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
200 | - |
|
201 | - return $securityResult === SecurityManager::ALLOWED; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Updates the lastactive timestamp |
|
206 | - */ |
|
207 | - private function touchUserLastActive() |
|
208 | - { |
|
209 | - if (WebRequest::getSessionUserId() !== null) { |
|
210 | - $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
211 | - $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return SecurityManager |
|
217 | - */ |
|
218 | - public function getSecurityManager() |
|
219 | - { |
|
220 | - return $this->securityManager; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param SecurityManager $securityManager |
|
225 | - */ |
|
226 | - public function setSecurityManager(SecurityManager $securityManager) |
|
227 | - { |
|
228 | - $this->securityManager = $securityManager; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * @return IBlacklistHelper |
|
233 | - */ |
|
234 | - public function getBlacklistHelper() |
|
235 | - { |
|
236 | - return $this->blacklistHelper; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * @param IBlacklistHelper $blacklistHelper |
|
241 | - */ |
|
242 | - public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
243 | - { |
|
244 | - $this->blacklistHelper = $blacklistHelper; |
|
245 | - } |
|
25 | + use NavigationMenuAccessControl; |
|
26 | + |
|
27 | + /** @var IdentificationVerifier */ |
|
28 | + private $identificationVerifier; |
|
29 | + /** @var ITypeAheadHelper */ |
|
30 | + private $typeAheadHelper; |
|
31 | + /** @var SecurityManager */ |
|
32 | + private $securityManager; |
|
33 | + /** @var IBlacklistHelper */ |
|
34 | + private $blacklistHelper; |
|
35 | + |
|
36 | + /** |
|
37 | + * @return ITypeAheadHelper |
|
38 | + */ |
|
39 | + public function getTypeAheadHelper() |
|
40 | + { |
|
41 | + return $this->typeAheadHelper; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Sets up the internal IdentificationVerifier instance. Intended to be called from WebStart::setupHelpers(). |
|
46 | + * |
|
47 | + * @param IdentificationVerifier $identificationVerifier |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier) |
|
52 | + { |
|
53 | + $this->identificationVerifier = $identificationVerifier; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param ITypeAheadHelper $typeAheadHelper |
|
58 | + */ |
|
59 | + public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
60 | + { |
|
61 | + $this->typeAheadHelper = $typeAheadHelper; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Runs the page code |
|
66 | + * |
|
67 | + * @throws Exception |
|
68 | + * @category Security-Critical |
|
69 | + */ |
|
70 | + final public function execute() |
|
71 | + { |
|
72 | + if ($this->getRouteName() === null) { |
|
73 | + throw new Exception("Request is unrouted."); |
|
74 | + } |
|
75 | + |
|
76 | + if ($this->getSiteConfiguration() === null) { |
|
77 | + throw new Exception("Page has no configuration!"); |
|
78 | + } |
|
79 | + |
|
80 | + $this->setupPage(); |
|
81 | + |
|
82 | + $this->touchUserLastActive(); |
|
83 | + |
|
84 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
85 | + |
|
86 | + // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
87 | + if (!$this->isProtectedPage()) { |
|
88 | + // This page is /not/ a protected page, as such we can just run it. |
|
89 | + $this->runPage(); |
|
90 | + |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + // Security barrier. |
|
95 | + // |
|
96 | + // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
97 | + // away for us |
|
98 | + $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
99 | + if ($securityResult === SecurityManager::ALLOWED) { |
|
100 | + // We're allowed to run the page, so let's run it. |
|
101 | + $this->runPage(); |
|
102 | + } |
|
103 | + else { |
|
104 | + $this->handleAccessDenied($securityResult); |
|
105 | + |
|
106 | + // Send the headers |
|
107 | + $this->sendResponseHeaders(); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Performs final tasks needed before rendering the page. |
|
113 | + */ |
|
114 | + final public function finalisePage() |
|
115 | + { |
|
116 | + parent::finalisePage(); |
|
117 | + |
|
118 | + $this->assign('typeAheadBlock', $this->getTypeAheadHelper()->getTypeAheadScriptBlock()); |
|
119 | + |
|
120 | + $database = $this->getDatabase(); |
|
121 | + |
|
122 | + $currentUser = User::getCurrent($database); |
|
123 | + if (!$currentUser->isCommunityUser()) { |
|
124 | + $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
125 | + $statement = $database->query($sql); |
|
126 | + $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
127 | + $this->assign('onlineusers', $activeUsers); |
|
128 | + } |
|
129 | + |
|
130 | + $this->setupNavMenuAccess($currentUser); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Configures whether the page respects roles or not. You probably want this to return true. |
|
135 | + * |
|
136 | + * Set to false for public pages. You probably want this to return true. |
|
137 | + * |
|
138 | + * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
139 | + * on this page, so you probably want this to return true. |
|
140 | + * |
|
141 | + * @return bool |
|
142 | + * @category Security-Critical |
|
143 | + */ |
|
144 | + protected function isProtectedPage() |
|
145 | + { |
|
146 | + return true; |
|
147 | + } |
|
148 | + |
|
149 | + protected function handleAccessDenied($denyReason) |
|
150 | + { |
|
151 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
152 | + |
|
153 | + // Not allowed to access this resource. |
|
154 | + // Firstly, let's check if we're even logged in. |
|
155 | + if ($currentUser->isCommunityUser()) { |
|
156 | + // Not logged in, redirect to login page |
|
157 | + WebRequest::setPostLoginRedirect(); |
|
158 | + $this->redirect("login"); |
|
159 | + |
|
160 | + return; |
|
161 | + } |
|
162 | + else { |
|
163 | + // Decide whether this was a rights failure, or an identification failure. |
|
164 | + |
|
165 | + if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
|
166 | + // Not identified |
|
167 | + throw new NotIdentifiedException($this->getSecurityManager()); |
|
168 | + } |
|
169 | + elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
170 | + // Nope, plain old access denied |
|
171 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
172 | + } |
|
173 | + else { |
|
174 | + throw new Exception('Unknown response from security manager.'); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Tests the security barrier for a specified action. |
|
181 | + * |
|
182 | + * Don't use within templates |
|
183 | + * |
|
184 | + * @param string $action |
|
185 | + * |
|
186 | + * @param User $user |
|
187 | + * @param null|string $pageName |
|
188 | + * |
|
189 | + * @return bool |
|
190 | + * @category Security-Critical |
|
191 | + */ |
|
192 | + final public function barrierTest($action, User $user, $pageName = null) |
|
193 | + { |
|
194 | + $page = get_called_class(); |
|
195 | + if ($pageName !== null) { |
|
196 | + $page = $pageName; |
|
197 | + } |
|
198 | + |
|
199 | + $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
200 | + |
|
201 | + return $securityResult === SecurityManager::ALLOWED; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Updates the lastactive timestamp |
|
206 | + */ |
|
207 | + private function touchUserLastActive() |
|
208 | + { |
|
209 | + if (WebRequest::getSessionUserId() !== null) { |
|
210 | + $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
211 | + $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return SecurityManager |
|
217 | + */ |
|
218 | + public function getSecurityManager() |
|
219 | + { |
|
220 | + return $this->securityManager; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param SecurityManager $securityManager |
|
225 | + */ |
|
226 | + public function setSecurityManager(SecurityManager $securityManager) |
|
227 | + { |
|
228 | + $this->securityManager = $securityManager; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * @return IBlacklistHelper |
|
233 | + */ |
|
234 | + public function getBlacklistHelper() |
|
235 | + { |
|
236 | + return $this->blacklistHelper; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * @param IBlacklistHelper $blacklistHelper |
|
241 | + */ |
|
242 | + public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
243 | + { |
|
244 | + $this->blacklistHelper = $blacklistHelper; |
|
245 | + } |
|
246 | 246 | } |
@@ -99,8 +99,7 @@ discard block |
||
99 | 99 | if ($securityResult === SecurityManager::ALLOWED) { |
100 | 100 | // We're allowed to run the page, so let's run it. |
101 | 101 | $this->runPage(); |
102 | - } |
|
103 | - else { |
|
102 | + } else { |
|
104 | 103 | $this->handleAccessDenied($securityResult); |
105 | 104 | |
106 | 105 | // Send the headers |
@@ -158,19 +157,16 @@ discard block |
||
158 | 157 | $this->redirect("login"); |
159 | 158 | |
160 | 159 | return; |
161 | - } |
|
162 | - else { |
|
160 | + } else { |
|
163 | 161 | // Decide whether this was a rights failure, or an identification failure. |
164 | 162 | |
165 | 163 | if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
166 | 164 | // Not identified |
167 | 165 | throw new NotIdentifiedException($this->getSecurityManager()); |
168 | - } |
|
169 | - elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
166 | + } elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
170 | 167 | // Nope, plain old access denied |
171 | 168 | throw new AccessDeniedException($this->getSecurityManager()); |
172 | - } |
|
173 | - else { |
|
169 | + } else { |
|
174 | 170 | throw new Exception('Unknown response from security manager.'); |
175 | 171 | } |
176 | 172 | } |