@@ -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 $oauthHelper; |
|
| 191 | - $oauthHelper = $page->getOAuthHelper(); |
|
| 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 $oauthHelper; |
|
| 191 | + $oauthHelper = $page->getOAuthHelper(); |
|
| 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 | } |
@@ -83,8 +83,7 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | if ($siteConfiguration->getTitleBlacklistEnabled()) { |
| 85 | 85 | $page->setBlacklistHelper(new FakeBlacklistHelper()); |
| 86 | - } |
|
| 87 | - else { |
|
| 86 | + } else { |
|
| 88 | 87 | $page->setBlacklistHelper(new BlacklistHelper($page->getHttpHelper(), |
| 89 | 88 | $siteConfiguration->getMediawikiWebServiceEndpoint())); |
| 90 | 89 | } |
@@ -178,8 +177,7 @@ discard block |
||
| 178 | 177 | |
| 179 | 178 | if ($siteConfiguration->getIrcNotificationsEnabled()) { |
| 180 | 179 | $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
| 181 | - } |
|
| 182 | - else { |
|
| 180 | + } else { |
|
| 183 | 181 | // @todo federated table here? |
| 184 | 182 | $notificationsDatabase = $database; |
| 185 | 183 | } |
@@ -17,67 +17,67 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class StatusAction extends ApiPageBase implements IApiAction |
| 19 | 19 | { |
| 20 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 21 | - { |
|
| 22 | - $statusElement = $this->document->createElement("status"); |
|
| 23 | - $apiDocument->appendChild($statusElement); |
|
| 20 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 21 | + { |
|
| 22 | + $statusElement = $this->document->createElement("status"); |
|
| 23 | + $apiDocument->appendChild($statusElement); |
|
| 24 | 24 | |
| 25 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 25 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 26 | 26 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
| 27 | 27 | FROM request |
| 28 | 28 | WHERE |
| 29 | 29 | status = :pstatus |
| 30 | 30 | AND emailconfirm = 'Confirmed'; |
| 31 | 31 | SQL |
| 32 | - ); |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 34 | + $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 35 | 35 | |
| 36 | - foreach ($availableRequestStates as $key => $value) { |
|
| 37 | - $query->bindValue(":pstatus", $key); |
|
| 38 | - $query->execute(); |
|
| 39 | - $sus = $query->fetchColumn(); |
|
| 40 | - $statusElement->setAttribute($value['api'], $sus); |
|
| 41 | - $query->closeCursor(); |
|
| 42 | - } |
|
| 36 | + foreach ($availableRequestStates as $key => $value) { |
|
| 37 | + $query->bindValue(":pstatus", $key); |
|
| 38 | + $query->execute(); |
|
| 39 | + $sus = $query->fetchColumn(); |
|
| 40 | + $statusElement->setAttribute($value['api'], $sus); |
|
| 41 | + $query->closeCursor(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 44 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 45 | 45 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
| 46 | 46 | FROM ban |
| 47 | 47 | WHERE |
| 48 | 48 | (duration > UNIX_TIMESTAMP() OR duration = -1) |
| 49 | 49 | AND active = 1; |
| 50 | 50 | SQL |
| 51 | - ); |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - $query->execute(); |
|
| 54 | - $sus = $query->fetchColumn(); |
|
| 55 | - $statusElement->setAttribute("bans", $sus); |
|
| 56 | - $query->closeCursor(); |
|
| 53 | + $query->execute(); |
|
| 54 | + $sus = $query->fetchColumn(); |
|
| 55 | + $statusElement->setAttribute("bans", $sus); |
|
| 56 | + $query->closeCursor(); |
|
| 57 | 57 | |
| 58 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 58 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 59 | 59 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
| 60 | 60 | FROM user WHERE status = :ulevel; |
| 61 | 61 | SQL |
| 62 | - ); |
|
| 63 | - $query->bindValue(":ulevel", "Admin"); |
|
| 64 | - $query->execute(); |
|
| 65 | - $sus = $query->fetchColumn(); |
|
| 66 | - $statusElement->setAttribute("useradmin", $sus); |
|
| 67 | - $query->closeCursor(); |
|
| 62 | + ); |
|
| 63 | + $query->bindValue(":ulevel", "Admin"); |
|
| 64 | + $query->execute(); |
|
| 65 | + $sus = $query->fetchColumn(); |
|
| 66 | + $statusElement->setAttribute("useradmin", $sus); |
|
| 67 | + $query->closeCursor(); |
|
| 68 | 68 | |
| 69 | - $query->bindValue(":ulevel", "User"); |
|
| 70 | - $query->execute(); |
|
| 71 | - $sus = $query->fetchColumn(); |
|
| 72 | - $statusElement->setAttribute("user", $sus); |
|
| 73 | - $query->closeCursor(); |
|
| 69 | + $query->bindValue(":ulevel", "User"); |
|
| 70 | + $query->execute(); |
|
| 71 | + $sus = $query->fetchColumn(); |
|
| 72 | + $statusElement->setAttribute("user", $sus); |
|
| 73 | + $query->closeCursor(); |
|
| 74 | 74 | |
| 75 | - $query->bindValue(":ulevel", "New"); |
|
| 76 | - $query->execute(); |
|
| 77 | - $sus = $query->fetchColumn(); |
|
| 78 | - $statusElement->setAttribute("usernew", $sus); |
|
| 79 | - $query->closeCursor(); |
|
| 75 | + $query->bindValue(":ulevel", "New"); |
|
| 76 | + $query->execute(); |
|
| 77 | + $sus = $query->fetchColumn(); |
|
| 78 | + $statusElement->setAttribute("usernew", $sus); |
|
| 79 | + $query->closeCursor(); |
|
| 80 | 80 | |
| 81 | - return $apiDocument; |
|
| 82 | - } |
|
| 81 | + return $apiDocument; |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class UnknownAction extends HelpAction implements IApiAction |
| 18 | 18 | { |
| 19 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 20 | - { |
|
| 21 | - $errorText = "Unknown API action specified."; |
|
| 22 | - $errorNode = $this->document->createElement("error", $errorText); |
|
| 23 | - $apiDocument->appendChild($errorNode); |
|
| 19 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 20 | + { |
|
| 21 | + $errorText = "Unknown API action specified."; |
|
| 22 | + $errorNode = $this->document->createElement("error", $errorText); |
|
| 23 | + $apiDocument->appendChild($errorNode); |
|
| 24 | 24 | |
| 25 | - $helpElement = $this->getHelpElement(); |
|
| 26 | - $apiDocument->appendChild($helpElement); |
|
| 25 | + $helpElement = $this->getHelpElement(); |
|
| 26 | + $apiDocument->appendChild($helpElement); |
|
| 27 | 27 | |
| 28 | - return $apiDocument; |
|
| 29 | - } |
|
| 28 | + return $apiDocument; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -20,47 +20,47 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class CountAction extends ApiPageBase implements IApiAction |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * The target user |
|
| 25 | - * @var User $user |
|
| 26 | - */ |
|
| 27 | - private $user; |
|
| 23 | + /** |
|
| 24 | + * The target user |
|
| 25 | + * @var User $user |
|
| 26 | + */ |
|
| 27 | + private $user; |
|
| 28 | 28 | |
| 29 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 30 | - { |
|
| 31 | - $username = WebRequest::getString('user'); |
|
| 32 | - if ($username === null) { |
|
| 33 | - throw new ApiException("Please specify a username"); |
|
| 34 | - } |
|
| 29 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 30 | + { |
|
| 31 | + $username = WebRequest::getString('user'); |
|
| 32 | + if ($username === null) { |
|
| 33 | + throw new ApiException("Please specify a username"); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $userElement = $this->document->createElement("user"); |
|
| 37 | - $userElement->setAttribute("name", $username); |
|
| 38 | - $apiDocument->appendChild($userElement); |
|
| 36 | + $userElement = $this->document->createElement("user"); |
|
| 37 | + $userElement->setAttribute("name", $username); |
|
| 38 | + $apiDocument->appendChild($userElement); |
|
| 39 | 39 | |
| 40 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
| 40 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
| 41 | 41 | |
| 42 | - if ($user === false) { |
|
| 43 | - $userElement->setAttribute("missing", "true"); |
|
| 42 | + if ($user === false) { |
|
| 43 | + $userElement->setAttribute("missing", "true"); |
|
| 44 | 44 | |
| 45 | - return $apiDocument; |
|
| 46 | - } |
|
| 45 | + return $apiDocument; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $this->user = $user; |
|
| 48 | + $this->user = $user; |
|
| 49 | 49 | |
| 50 | - $userElement->setAttribute("level", $this->user->getStatus()); |
|
| 51 | - $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
| 50 | + $userElement->setAttribute("level", $this->user->getStatus()); |
|
| 51 | + $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
| 52 | 52 | |
| 53 | - $userElement->setAttribute("today", $this->getToday()); |
|
| 53 | + $userElement->setAttribute("today", $this->getToday()); |
|
| 54 | 54 | |
| 55 | - // Let the IRC bot handle the result of this. |
|
| 56 | - $this->fetchAdminData($userElement); |
|
| 55 | + // Let the IRC bot handle the result of this. |
|
| 56 | + $this->fetchAdminData($userElement); |
|
| 57 | 57 | |
| 58 | - return $apiDocument; |
|
| 59 | - } |
|
| 58 | + return $apiDocument; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - private function getAccountsCreated() |
|
| 62 | - { |
|
| 63 | - $query = <<<QUERY |
|
| 61 | + private function getAccountsCreated() |
|
| 62 | + { |
|
| 63 | + $query = <<<QUERY |
|
| 64 | 64 | SELECT COUNT(*) AS count |
| 65 | 65 | FROM log |
| 66 | 66 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | AND user.username = :username; |
| 72 | 72 | QUERY; |
| 73 | 73 | |
| 74 | - $statement = $this->getDatabase()->prepare($query); |
|
| 75 | - $statement->execute(array(":username" => $this->user->getUsername())); |
|
| 76 | - $result = $statement->fetchColumn(); |
|
| 77 | - $statement->closeCursor(); |
|
| 74 | + $statement = $this->getDatabase()->prepare($query); |
|
| 75 | + $statement->execute(array(":username" => $this->user->getUsername())); |
|
| 76 | + $result = $statement->fetchColumn(); |
|
| 77 | + $statement->closeCursor(); |
|
| 78 | 78 | |
| 79 | - return $result; |
|
| 80 | - } |
|
| 79 | + return $result; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private function getToday() |
|
| 83 | - { |
|
| 84 | - $query = <<<QUERY |
|
| 82 | + private function getToday() |
|
| 83 | + { |
|
| 84 | + $query = <<<QUERY |
|
| 85 | 85 | SELECT |
| 86 | 86 | COUNT(*) AS count |
| 87 | 87 | FROM log |
@@ -93,99 +93,99 @@ discard block |
||
| 93 | 93 | AND user.username = :username; |
| 94 | 94 | QUERY; |
| 95 | 95 | |
| 96 | - $statement = $this->getDatabase()->prepare($query); |
|
| 97 | - $statement->bindValue(":username", $this->user->getUsername()); |
|
| 98 | - $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 99 | - $statement->execute(); |
|
| 100 | - $today = $statement->fetchColumn(); |
|
| 101 | - $statement->closeCursor(); |
|
| 102 | - |
|
| 103 | - return $today; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - private function fetchAdminData(DOMElement $userElement) |
|
| 107 | - { |
|
| 108 | - $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
| 109 | - |
|
| 110 | - $statement = $this->getDatabase()->prepare($query); |
|
| 111 | - $statement->bindValue(":userid", $this->user->getId()); |
|
| 112 | - $statement->bindValue(":action", "Suspended"); |
|
| 113 | - $statement->execute(); |
|
| 114 | - $sus = $statement->fetchColumn(); |
|
| 115 | - $userElement->setAttribute("suspended", $sus); |
|
| 116 | - $statement->closeCursor(); |
|
| 117 | - |
|
| 118 | - $statement->bindValue(":action", "Promoted"); |
|
| 119 | - $statement->execute(); |
|
| 120 | - $pro = $statement->fetchColumn(); |
|
| 121 | - $userElement->setAttribute("promoted", $pro); |
|
| 122 | - $statement->closeCursor(); |
|
| 123 | - |
|
| 124 | - $statement->bindValue(":action", "Approved"); |
|
| 125 | - $statement->execute(); |
|
| 126 | - $app = $statement->fetchColumn(); |
|
| 127 | - $userElement->setAttribute("approved", $app); |
|
| 128 | - $statement->closeCursor(); |
|
| 129 | - |
|
| 130 | - $statement->bindValue(":action", "Demoted"); |
|
| 131 | - $statement->execute(); |
|
| 132 | - $dem = $statement->fetchColumn(); |
|
| 133 | - $userElement->setAttribute("demoted", $dem); |
|
| 134 | - $statement->closeCursor(); |
|
| 135 | - |
|
| 136 | - $statement->bindValue(":action", "Declined"); |
|
| 137 | - $statement->execute(); |
|
| 138 | - $dec = $statement->fetchColumn(); |
|
| 139 | - $userElement->setAttribute("declined", $dec); |
|
| 140 | - $statement->closeCursor(); |
|
| 141 | - |
|
| 142 | - $statement->bindValue(":action", "Renamed"); |
|
| 143 | - $statement->execute(); |
|
| 144 | - $rnc = $statement->fetchColumn(); |
|
| 145 | - $userElement->setAttribute("renamed", $rnc); |
|
| 146 | - $statement->closeCursor(); |
|
| 147 | - |
|
| 148 | - $statement->bindValue(":action", "Edited"); |
|
| 149 | - $statement->execute(); |
|
| 150 | - $mec = $statement->fetchColumn(); |
|
| 151 | - $userElement->setAttribute("edited", $mec); |
|
| 152 | - $statement->closeCursor(); |
|
| 153 | - |
|
| 154 | - $statement->bindValue(":action", "Prefchange"); |
|
| 155 | - $statement->execute(); |
|
| 156 | - $pcc = $statement->fetchColumn(); |
|
| 157 | - $userElement->setAttribute("prefchange", $pcc); |
|
| 158 | - $statement->closeCursor(); |
|
| 159 | - |
|
| 160 | - // Combine all three actions affecting Welcome templates into one count. |
|
| 161 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 96 | + $statement = $this->getDatabase()->prepare($query); |
|
| 97 | + $statement->bindValue(":username", $this->user->getUsername()); |
|
| 98 | + $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 99 | + $statement->execute(); |
|
| 100 | + $today = $statement->fetchColumn(); |
|
| 101 | + $statement->closeCursor(); |
|
| 102 | + |
|
| 103 | + return $today; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + private function fetchAdminData(DOMElement $userElement) |
|
| 107 | + { |
|
| 108 | + $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
| 109 | + |
|
| 110 | + $statement = $this->getDatabase()->prepare($query); |
|
| 111 | + $statement->bindValue(":userid", $this->user->getId()); |
|
| 112 | + $statement->bindValue(":action", "Suspended"); |
|
| 113 | + $statement->execute(); |
|
| 114 | + $sus = $statement->fetchColumn(); |
|
| 115 | + $userElement->setAttribute("suspended", $sus); |
|
| 116 | + $statement->closeCursor(); |
|
| 117 | + |
|
| 118 | + $statement->bindValue(":action", "Promoted"); |
|
| 119 | + $statement->execute(); |
|
| 120 | + $pro = $statement->fetchColumn(); |
|
| 121 | + $userElement->setAttribute("promoted", $pro); |
|
| 122 | + $statement->closeCursor(); |
|
| 123 | + |
|
| 124 | + $statement->bindValue(":action", "Approved"); |
|
| 125 | + $statement->execute(); |
|
| 126 | + $app = $statement->fetchColumn(); |
|
| 127 | + $userElement->setAttribute("approved", $app); |
|
| 128 | + $statement->closeCursor(); |
|
| 129 | + |
|
| 130 | + $statement->bindValue(":action", "Demoted"); |
|
| 131 | + $statement->execute(); |
|
| 132 | + $dem = $statement->fetchColumn(); |
|
| 133 | + $userElement->setAttribute("demoted", $dem); |
|
| 134 | + $statement->closeCursor(); |
|
| 135 | + |
|
| 136 | + $statement->bindValue(":action", "Declined"); |
|
| 137 | + $statement->execute(); |
|
| 138 | + $dec = $statement->fetchColumn(); |
|
| 139 | + $userElement->setAttribute("declined", $dec); |
|
| 140 | + $statement->closeCursor(); |
|
| 141 | + |
|
| 142 | + $statement->bindValue(":action", "Renamed"); |
|
| 143 | + $statement->execute(); |
|
| 144 | + $rnc = $statement->fetchColumn(); |
|
| 145 | + $userElement->setAttribute("renamed", $rnc); |
|
| 146 | + $statement->closeCursor(); |
|
| 147 | + |
|
| 148 | + $statement->bindValue(":action", "Edited"); |
|
| 149 | + $statement->execute(); |
|
| 150 | + $mec = $statement->fetchColumn(); |
|
| 151 | + $userElement->setAttribute("edited", $mec); |
|
| 152 | + $statement->closeCursor(); |
|
| 153 | + |
|
| 154 | + $statement->bindValue(":action", "Prefchange"); |
|
| 155 | + $statement->execute(); |
|
| 156 | + $pcc = $statement->fetchColumn(); |
|
| 157 | + $userElement->setAttribute("prefchange", $pcc); |
|
| 158 | + $statement->closeCursor(); |
|
| 159 | + |
|
| 160 | + // Combine all three actions affecting Welcome templates into one count. |
|
| 161 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 162 | 162 | SELECT |
| 163 | 163 | COUNT(*) AS count |
| 164 | 164 | FROM log |
| 165 | 165 | WHERE log.user = :userid |
| 166 | 166 | AND log.action IN ('CreatedTemplate', 'EditedTemplate', 'DeletedTemplate'); |
| 167 | 167 | SQL |
| 168 | - ); |
|
| 168 | + ); |
|
| 169 | 169 | |
| 170 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 171 | - $combinedquery->execute(); |
|
| 172 | - $dtc = $combinedquery->fetchColumn(); |
|
| 173 | - $userElement->setAttribute("welctempchange", $dtc); |
|
| 174 | - $combinedquery->closeCursor(); |
|
| 170 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 171 | + $combinedquery->execute(); |
|
| 172 | + $dtc = $combinedquery->fetchColumn(); |
|
| 173 | + $userElement->setAttribute("welctempchange", $dtc); |
|
| 174 | + $combinedquery->closeCursor(); |
|
| 175 | 175 | |
| 176 | - // Combine both actions affecting Email templates into one count. |
|
| 177 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 176 | + // Combine both actions affecting Email templates into one count. |
|
| 177 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 178 | 178 | SELECT COUNT(*) AS count |
| 179 | 179 | FROM log |
| 180 | 180 | WHERE log.user = :userid |
| 181 | 181 | AND log.action IN ('CreatedEmail', 'EditedEmail'); |
| 182 | 182 | SQL |
| 183 | - ); |
|
| 184 | - |
|
| 185 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 186 | - $combinedquery->execute(); |
|
| 187 | - $cec = $combinedquery->fetchColumn(); |
|
| 188 | - $userElement->setAttribute("emailtempchange", $cec); |
|
| 189 | - $combinedquery->closeCursor(); |
|
| 190 | - } |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 186 | + $combinedquery->execute(); |
|
| 187 | + $cec = $combinedquery->fetchColumn(); |
|
| 188 | + $userElement->setAttribute("emailtempchange", $cec); |
|
| 189 | + $combinedquery->closeCursor(); |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -18,34 +18,34 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class HelpAction extends ApiPageBase implements IApiAction |
| 20 | 20 | { |
| 21 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 22 | - { |
|
| 23 | - $helpElement = $this->getHelpElement(); |
|
| 24 | - $apiDocument->appendChild($helpElement); |
|
| 25 | - |
|
| 26 | - return $apiDocument; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Gets the help information |
|
| 31 | - * @return DOMElement |
|
| 32 | - */ |
|
| 33 | - protected function getHelpElement() |
|
| 34 | - { |
|
| 35 | - $helpInfo = "Help info goes here!"; |
|
| 36 | - |
|
| 37 | - $help = $this->document->createElement("help"); |
|
| 38 | - $helptext = $this->document->createElement("info", $helpInfo); |
|
| 39 | - $helpactions = $this->document->createElement("actions"); |
|
| 40 | - |
|
| 41 | - foreach (ApiRequestRouter::getActionList() as $action) { |
|
| 42 | - $actionElement = $this->document->createElement("action", $action); |
|
| 43 | - $helpactions->appendChild($actionElement); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $help->appendChild($helptext); |
|
| 47 | - $help->appendChild($helpactions); |
|
| 48 | - |
|
| 49 | - return $help; |
|
| 50 | - } |
|
| 21 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 22 | + { |
|
| 23 | + $helpElement = $this->getHelpElement(); |
|
| 24 | + $apiDocument->appendChild($helpElement); |
|
| 25 | + |
|
| 26 | + return $apiDocument; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Gets the help information |
|
| 31 | + * @return DOMElement |
|
| 32 | + */ |
|
| 33 | + protected function getHelpElement() |
|
| 34 | + { |
|
| 35 | + $helpInfo = "Help info goes here!"; |
|
| 36 | + |
|
| 37 | + $help = $this->document->createElement("help"); |
|
| 38 | + $helptext = $this->document->createElement("info", $helpInfo); |
|
| 39 | + $helpactions = $this->document->createElement("actions"); |
|
| 40 | + |
|
| 41 | + foreach (ApiRequestRouter::getActionList() as $action) { |
|
| 42 | + $actionElement = $this->document->createElement("action", $action); |
|
| 43 | + $helpactions->appendChild($actionElement); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $help->appendChild($helptext); |
|
| 47 | + $help->appendChild($helpactions); |
|
| 48 | + |
|
| 49 | + return $help; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -23,65 +23,65 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MonitorAction extends ApiPageBase implements IApiAction |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @param DOMElement $apiDocument |
|
| 28 | - * |
|
| 29 | - * @return DOMElement |
|
| 30 | - */ |
|
| 31 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 32 | - { |
|
| 33 | - $now = new DateTime(); |
|
| 26 | + /** |
|
| 27 | + * @param DOMElement $apiDocument |
|
| 28 | + * |
|
| 29 | + * @return DOMElement |
|
| 30 | + */ |
|
| 31 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 32 | + { |
|
| 33 | + $now = new DateTime(); |
|
| 34 | 34 | |
| 35 | - $old = $this->getOldest(); |
|
| 36 | - $oldest = new DateTime($old); |
|
| 35 | + $old = $this->getOldest(); |
|
| 36 | + $oldest = new DateTime($old); |
|
| 37 | 37 | |
| 38 | - $new = $this->getNewest(); |
|
| 39 | - $newest = new DateTime($new); |
|
| 38 | + $new = $this->getNewest(); |
|
| 39 | + $newest = new DateTime($new); |
|
| 40 | 40 | |
| 41 | - $monitoringElement = $this->document->createElement("data"); |
|
| 42 | - $monitoringElement->setAttribute("date", $now->format('c')); |
|
| 43 | - $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
| 44 | - $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
| 45 | - $apiDocument->appendChild($monitoringElement); |
|
| 41 | + $monitoringElement = $this->document->createElement("data"); |
|
| 42 | + $monitoringElement->setAttribute("date", $now->format('c')); |
|
| 43 | + $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
| 44 | + $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
| 45 | + $apiDocument->appendChild($monitoringElement); |
|
| 46 | 46 | |
| 47 | - return $apiDocument; |
|
| 48 | - } |
|
| 47 | + return $apiDocument; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return string|null |
|
| 52 | - */ |
|
| 53 | - private function getOldest() |
|
| 54 | - { |
|
| 55 | - $statement = $this->getDatabase() |
|
| 56 | - ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 57 | - $successful = $statement->execute(array( |
|
| 58 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 59 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 60 | - )); |
|
| 50 | + /** |
|
| 51 | + * @return string|null |
|
| 52 | + */ |
|
| 53 | + private function getOldest() |
|
| 54 | + { |
|
| 55 | + $statement = $this->getDatabase() |
|
| 56 | + ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 57 | + $successful = $statement->execute(array( |
|
| 58 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 59 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 60 | + )); |
|
| 61 | 61 | |
| 62 | - if (!$successful) { |
|
| 63 | - return null; |
|
| 64 | - } |
|
| 62 | + if (!$successful) { |
|
| 63 | + return null; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $result = $statement->fetchColumn(); |
|
| 66 | + $result = $statement->fetchColumn(); |
|
| 67 | 67 | |
| 68 | - return $result; |
|
| 69 | - } |
|
| 68 | + return $result; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - private function getNewest() |
|
| 75 | - { |
|
| 76 | - $statement = $this->getDatabase() |
|
| 77 | - ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 78 | - $statement->execute(array( |
|
| 79 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 80 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 81 | - )); |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + private function getNewest() |
|
| 75 | + { |
|
| 76 | + $statement = $this->getDatabase() |
|
| 77 | + ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 78 | + $statement->execute(array( |
|
| 79 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 80 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 81 | + )); |
|
| 82 | 82 | |
| 83 | - $result = $statement->fetchColumn(0); |
|
| 83 | + $result = $statement->fetchColumn(0); |
|
| 84 | 84 | |
| 85 | - return $result; |
|
| 86 | - } |
|
| 85 | + return $result; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -19,55 +19,55 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class StatsAction extends ApiPageBase implements IApiAction |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * The target user |
|
| 24 | - * @var User $user |
|
| 25 | - */ |
|
| 26 | - private $user; |
|
| 22 | + /** |
|
| 23 | + * The target user |
|
| 24 | + * @var User $user |
|
| 25 | + */ |
|
| 26 | + private $user; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Summary of execute |
|
| 30 | - * |
|
| 31 | - * @param \DOMElement $apiDocument |
|
| 32 | - * |
|
| 33 | - * @return \DOMElement |
|
| 34 | - * @throws ApiException |
|
| 35 | - * @throws \Exception |
|
| 36 | - */ |
|
| 37 | - public function executeApiAction(\DOMElement $apiDocument) |
|
| 38 | - { |
|
| 39 | - $username = WebRequest::getString('user'); |
|
| 40 | - $wikiusername = WebRequest::getString('wikiuser'); |
|
| 28 | + /** |
|
| 29 | + * Summary of execute |
|
| 30 | + * |
|
| 31 | + * @param \DOMElement $apiDocument |
|
| 32 | + * |
|
| 33 | + * @return \DOMElement |
|
| 34 | + * @throws ApiException |
|
| 35 | + * @throws \Exception |
|
| 36 | + */ |
|
| 37 | + public function executeApiAction(\DOMElement $apiDocument) |
|
| 38 | + { |
|
| 39 | + $username = WebRequest::getString('user'); |
|
| 40 | + $wikiusername = WebRequest::getString('wikiuser'); |
|
| 41 | 41 | |
| 42 | - if ($username === null && $wikiusername === null) { |
|
| 43 | - throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
| 44 | - } |
|
| 42 | + if ($username === null && $wikiusername === null) { |
|
| 43 | + throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $userElement = $this->document->createElement("user"); |
|
| 47 | - $apiDocument->appendChild($userElement); |
|
| 46 | + $userElement = $this->document->createElement("user"); |
|
| 47 | + $apiDocument->appendChild($userElement); |
|
| 48 | 48 | |
| 49 | - if ($username !== null) { |
|
| 50 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
| 51 | - } |
|
| 52 | - else { |
|
| 53 | - $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
| 54 | - } |
|
| 49 | + if ($username !== null) { |
|
| 50 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
| 51 | + } |
|
| 52 | + else { |
|
| 53 | + $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if ($user === false) { |
|
| 57 | - $userElement->setAttribute("missing", "true"); |
|
| 56 | + if ($user === false) { |
|
| 57 | + $userElement->setAttribute("missing", "true"); |
|
| 58 | 58 | |
| 59 | - return $apiDocument; |
|
| 60 | - } |
|
| 59 | + return $apiDocument; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $this->user = $user; |
|
| 62 | + $this->user = $user; |
|
| 63 | 63 | |
| 64 | - $userElement->setAttribute("username", $this->user->getUsername()); |
|
| 65 | - $userElement->setAttribute("status", $this->user->getStatus()); |
|
| 66 | - $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
| 67 | - $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
| 68 | - $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
| 69 | - $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false"); |
|
| 64 | + $userElement->setAttribute("username", $this->user->getUsername()); |
|
| 65 | + $userElement->setAttribute("status", $this->user->getStatus()); |
|
| 66 | + $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
| 67 | + $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
| 68 | + $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
| 69 | + $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false"); |
|
| 70 | 70 | |
| 71 | - return $apiDocument; |
|
| 72 | - } |
|
| 71 | + return $apiDocument; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | if ($username !== null) { |
| 50 | 50 | $user = User::getByUsername($username, $this->getDatabase()); |
| 51 | - } |
|
| 52 | - else { |
|
| 51 | + } else { |
|
| 53 | 52 | $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -17,17 +17,17 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IApiAction extends IRoutedTask |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Method that runs API action |
|
| 22 | - * |
|
| 23 | - * @param DOMElement $apiDocument |
|
| 24 | - * |
|
| 25 | - * @return DOMElement The modified API document |
|
| 26 | - */ |
|
| 27 | - public function executeApiAction(DOMElement $apiDocument); |
|
| 20 | + /** |
|
| 21 | + * Method that runs API action |
|
| 22 | + * |
|
| 23 | + * @param DOMElement $apiDocument |
|
| 24 | + * |
|
| 25 | + * @return DOMElement The modified API document |
|
| 26 | + */ |
|
| 27 | + public function executeApiAction(DOMElement $apiDocument); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return string the XML, or false if an error occurred. |
|
| 31 | - */ |
|
| 32 | - public function runApiPage(); |
|
| 29 | + /** |
|
| 30 | + * @return string the XML, or false if an error occurred. |
|
| 31 | + */ |
|
| 32 | + public function runApiPage(); |
|
| 33 | 33 | } |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ApiException extends Exception |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param string $message |
|
| 20 | - */ |
|
| 21 | - public function __construct($message) |
|
| 22 | - { |
|
| 23 | - $this->message = $message; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $message |
|
| 20 | + */ |
|
| 21 | + public function __construct($message) |
|
| 22 | + { |
|
| 23 | + $this->message = $message; |
|
| 24 | + } |
|
| 25 | 25 | } |