@@ -64,12 +64,10 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | if ($user === false) { |
| 66 | 66 | self::$currentUser = new CommunityUser(); |
| 67 | - } |
|
| 68 | - else { |
|
| 67 | + } else { |
|
| 69 | 68 | self::$currentUser = $user; |
| 70 | 69 | } |
| 71 | - } |
|
| 72 | - else { |
|
| 70 | + } else { |
|
| 73 | 71 | $anonymousCoward = new CommunityUser(); |
| 74 | 72 | |
| 75 | 73 | self::$currentUser = $anonymousCoward; |
@@ -203,12 +201,10 @@ discard block |
||
| 203 | 201 | |
| 204 | 202 | if ($statement->execute()) { |
| 205 | 203 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 206 | - } |
|
| 207 | - else { |
|
| 204 | + } else { |
|
| 208 | 205 | throw new Exception($statement->errorInfo()); |
| 209 | 206 | } |
| 210 | - } |
|
| 211 | - else { |
|
| 207 | + } else { |
|
| 212 | 208 | // update |
| 213 | 209 | $statement = $this->dbObject->prepare(<<<SQL |
| 214 | 210 | UPDATE `user` SET |
@@ -533,12 +529,10 @@ discard block |
||
| 533 | 529 | if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
| 534 | 530 | // User forced to unidentified in the database. |
| 535 | 531 | return false; |
| 536 | - } |
|
| 537 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 532 | + } elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 538 | 533 | // User forced to identified in the database. |
| 539 | 534 | return true; |
| 540 | - } |
|
| 541 | - else { |
|
| 535 | + } else { |
|
| 542 | 536 | // User not forced to any particular identified status; consult IdentificationVerifier |
| 543 | 537 | return $iv->isUserIdentified($this->getOnWikiName()); |
| 544 | 538 | } |
@@ -549,7 +543,8 @@ discard block |
||
| 549 | 543 | * |
| 550 | 544 | * @return bool|null |
| 551 | 545 | */ |
| 552 | - public function getForceIdentified() { |
|
| 546 | + public function getForceIdentified() |
|
| 547 | + { |
|
| 553 | 548 | return $this->forceidentified; |
| 554 | 549 | } |
| 555 | 550 | |
@@ -21,160 +21,160 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class User extends DataObject |
| 23 | 23 | { |
| 24 | - const STATUS_ACTIVE = 'Active'; |
|
| 25 | - const STATUS_SUSPENDED = 'Suspended'; |
|
| 26 | - const STATUS_DECLINED = 'Declined'; |
|
| 27 | - const STATUS_NEW = 'New'; |
|
| 28 | - const CREATION_MANUAL = 0; |
|
| 29 | - const CREATION_OAUTH = 1; |
|
| 30 | - const CREATION_BOT = 2; |
|
| 31 | - private $username; |
|
| 32 | - private $email; |
|
| 33 | - private $status = self::STATUS_NEW; |
|
| 34 | - private $onwikiname; |
|
| 35 | - private $welcome_sig = ""; |
|
| 36 | - private $lastactive = "0000-00-00 00:00:00"; |
|
| 37 | - private $forcelogout = 0; |
|
| 38 | - private $forceidentified = null; |
|
| 39 | - private $welcome_template = 0; |
|
| 40 | - private $abortpref = 0; |
|
| 41 | - private $confirmationdiff = 0; |
|
| 42 | - private $emailsig = ""; |
|
| 43 | - private $creationmode = 0; |
|
| 44 | - private $skin = "auto"; |
|
| 45 | - /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 46 | - private static $currentUser; |
|
| 47 | - #region Object load methods |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Gets the currently logged in user |
|
| 51 | - * |
|
| 52 | - * @param PdoDatabase $database |
|
| 53 | - * |
|
| 54 | - * @return User|CommunityUser |
|
| 55 | - */ |
|
| 56 | - public static function getCurrent(PdoDatabase $database) |
|
| 57 | - { |
|
| 58 | - if (self::$currentUser === null) { |
|
| 59 | - $sessionId = WebRequest::getSessionUserId(); |
|
| 60 | - |
|
| 61 | - if ($sessionId !== null) { |
|
| 62 | - /** @var User $user */ |
|
| 63 | - $user = self::getById($sessionId, $database); |
|
| 64 | - |
|
| 65 | - if ($user === false) { |
|
| 66 | - self::$currentUser = new CommunityUser(); |
|
| 67 | - } |
|
| 68 | - else { |
|
| 69 | - self::$currentUser = $user; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - else { |
|
| 73 | - $anonymousCoward = new CommunityUser(); |
|
| 74 | - |
|
| 75 | - self::$currentUser = $anonymousCoward; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return self::$currentUser; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Gets a user by their user ID |
|
| 84 | - * |
|
| 85 | - * Pass -1 to get the community user. |
|
| 86 | - * |
|
| 87 | - * @param int|null $id |
|
| 88 | - * @param PdoDatabase $database |
|
| 89 | - * |
|
| 90 | - * @return User|false |
|
| 91 | - */ |
|
| 92 | - public static function getById($id, PdoDatabase $database) |
|
| 93 | - { |
|
| 94 | - if ($id === null || $id == -1) { |
|
| 95 | - return new CommunityUser(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** @var User|false $user */ |
|
| 99 | - $user = parent::getById($id, $database); |
|
| 100 | - |
|
| 101 | - return $user; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return CommunityUser |
|
| 106 | - */ |
|
| 107 | - public static function getCommunity() |
|
| 108 | - { |
|
| 109 | - return new CommunityUser(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Gets a user by their username |
|
| 114 | - * |
|
| 115 | - * @param string $username |
|
| 116 | - * @param PdoDatabase $database |
|
| 117 | - * |
|
| 118 | - * @return CommunityUser|User|false |
|
| 119 | - */ |
|
| 120 | - public static function getByUsername($username, PdoDatabase $database) |
|
| 121 | - { |
|
| 122 | - global $communityUsername; |
|
| 123 | - if ($username == $communityUsername) { |
|
| 124 | - return new CommunityUser(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 128 | - $statement->bindValue(":id", $username); |
|
| 129 | - |
|
| 130 | - $statement->execute(); |
|
| 131 | - |
|
| 132 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 133 | - |
|
| 134 | - if ($resultObject != false) { |
|
| 135 | - $resultObject->setDatabase($database); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $resultObject; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Gets a user by their on-wiki username. |
|
| 143 | - * |
|
| 144 | - * @param string $username |
|
| 145 | - * @param PdoDatabase $database |
|
| 146 | - * |
|
| 147 | - * @return User|false |
|
| 148 | - */ |
|
| 149 | - public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 150 | - { |
|
| 151 | - $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 152 | - $statement->bindValue(":id", $username); |
|
| 153 | - $statement->execute(); |
|
| 154 | - |
|
| 155 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 156 | - |
|
| 157 | - if ($resultObject != false) { |
|
| 158 | - $resultObject->setDatabase($database); |
|
| 159 | - |
|
| 160 | - return $resultObject; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - #endregion |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Saves the current object |
|
| 170 | - * |
|
| 171 | - * @throws Exception |
|
| 172 | - */ |
|
| 173 | - public function save() |
|
| 174 | - { |
|
| 175 | - if ($this->isNew()) { |
|
| 176 | - // insert |
|
| 177 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 24 | + const STATUS_ACTIVE = 'Active'; |
|
| 25 | + const STATUS_SUSPENDED = 'Suspended'; |
|
| 26 | + const STATUS_DECLINED = 'Declined'; |
|
| 27 | + const STATUS_NEW = 'New'; |
|
| 28 | + const CREATION_MANUAL = 0; |
|
| 29 | + const CREATION_OAUTH = 1; |
|
| 30 | + const CREATION_BOT = 2; |
|
| 31 | + private $username; |
|
| 32 | + private $email; |
|
| 33 | + private $status = self::STATUS_NEW; |
|
| 34 | + private $onwikiname; |
|
| 35 | + private $welcome_sig = ""; |
|
| 36 | + private $lastactive = "0000-00-00 00:00:00"; |
|
| 37 | + private $forcelogout = 0; |
|
| 38 | + private $forceidentified = null; |
|
| 39 | + private $welcome_template = 0; |
|
| 40 | + private $abortpref = 0; |
|
| 41 | + private $confirmationdiff = 0; |
|
| 42 | + private $emailsig = ""; |
|
| 43 | + private $creationmode = 0; |
|
| 44 | + private $skin = "auto"; |
|
| 45 | + /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
| 46 | + private static $currentUser; |
|
| 47 | + #region Object load methods |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Gets the currently logged in user |
|
| 51 | + * |
|
| 52 | + * @param PdoDatabase $database |
|
| 53 | + * |
|
| 54 | + * @return User|CommunityUser |
|
| 55 | + */ |
|
| 56 | + public static function getCurrent(PdoDatabase $database) |
|
| 57 | + { |
|
| 58 | + if (self::$currentUser === null) { |
|
| 59 | + $sessionId = WebRequest::getSessionUserId(); |
|
| 60 | + |
|
| 61 | + if ($sessionId !== null) { |
|
| 62 | + /** @var User $user */ |
|
| 63 | + $user = self::getById($sessionId, $database); |
|
| 64 | + |
|
| 65 | + if ($user === false) { |
|
| 66 | + self::$currentUser = new CommunityUser(); |
|
| 67 | + } |
|
| 68 | + else { |
|
| 69 | + self::$currentUser = $user; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + else { |
|
| 73 | + $anonymousCoward = new CommunityUser(); |
|
| 74 | + |
|
| 75 | + self::$currentUser = $anonymousCoward; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return self::$currentUser; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Gets a user by their user ID |
|
| 84 | + * |
|
| 85 | + * Pass -1 to get the community user. |
|
| 86 | + * |
|
| 87 | + * @param int|null $id |
|
| 88 | + * @param PdoDatabase $database |
|
| 89 | + * |
|
| 90 | + * @return User|false |
|
| 91 | + */ |
|
| 92 | + public static function getById($id, PdoDatabase $database) |
|
| 93 | + { |
|
| 94 | + if ($id === null || $id == -1) { |
|
| 95 | + return new CommunityUser(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** @var User|false $user */ |
|
| 99 | + $user = parent::getById($id, $database); |
|
| 100 | + |
|
| 101 | + return $user; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return CommunityUser |
|
| 106 | + */ |
|
| 107 | + public static function getCommunity() |
|
| 108 | + { |
|
| 109 | + return new CommunityUser(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Gets a user by their username |
|
| 114 | + * |
|
| 115 | + * @param string $username |
|
| 116 | + * @param PdoDatabase $database |
|
| 117 | + * |
|
| 118 | + * @return CommunityUser|User|false |
|
| 119 | + */ |
|
| 120 | + public static function getByUsername($username, PdoDatabase $database) |
|
| 121 | + { |
|
| 122 | + global $communityUsername; |
|
| 123 | + if ($username == $communityUsername) { |
|
| 124 | + return new CommunityUser(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
| 128 | + $statement->bindValue(":id", $username); |
|
| 129 | + |
|
| 130 | + $statement->execute(); |
|
| 131 | + |
|
| 132 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 133 | + |
|
| 134 | + if ($resultObject != false) { |
|
| 135 | + $resultObject->setDatabase($database); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $resultObject; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Gets a user by their on-wiki username. |
|
| 143 | + * |
|
| 144 | + * @param string $username |
|
| 145 | + * @param PdoDatabase $database |
|
| 146 | + * |
|
| 147 | + * @return User|false |
|
| 148 | + */ |
|
| 149 | + public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
| 150 | + { |
|
| 151 | + $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
| 152 | + $statement->bindValue(":id", $username); |
|
| 153 | + $statement->execute(); |
|
| 154 | + |
|
| 155 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 156 | + |
|
| 157 | + if ($resultObject != false) { |
|
| 158 | + $resultObject->setDatabase($database); |
|
| 159 | + |
|
| 160 | + return $resultObject; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + #endregion |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Saves the current object |
|
| 170 | + * |
|
| 171 | + * @throws Exception |
|
| 172 | + */ |
|
| 173 | + public function save() |
|
| 174 | + { |
|
| 175 | + if ($this->isNew()) { |
|
| 176 | + // insert |
|
| 177 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 178 | 178 | INSERT INTO `user` ( |
| 179 | 179 | username, email, status, onwikiname, welcome_sig, |
| 180 | 180 | lastactive, forcelogout, forceidentified, |
@@ -185,32 +185,32 @@ discard block |
||
| 185 | 185 | :welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode, :skin |
| 186 | 186 | ); |
| 187 | 187 | SQL |
| 188 | - ); |
|
| 189 | - $statement->bindValue(":username", $this->username); |
|
| 190 | - $statement->bindValue(":email", $this->email); |
|
| 191 | - $statement->bindValue(":status", $this->status); |
|
| 192 | - $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 193 | - $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 194 | - $statement->bindValue(":lastactive", $this->lastactive); |
|
| 195 | - $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 196 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 197 | - $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 198 | - $statement->bindValue(":abortpref", $this->abortpref); |
|
| 199 | - $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 200 | - $statement->bindValue(":emailsig", $this->emailsig); |
|
| 201 | - $statement->bindValue(":creationmode", $this->creationmode); |
|
| 202 | - $statement->bindValue(":skin", $this->skin); |
|
| 203 | - |
|
| 204 | - if ($statement->execute()) { |
|
| 205 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 206 | - } |
|
| 207 | - else { |
|
| 208 | - throw new Exception($statement->errorInfo()); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - // update |
|
| 213 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 188 | + ); |
|
| 189 | + $statement->bindValue(":username", $this->username); |
|
| 190 | + $statement->bindValue(":email", $this->email); |
|
| 191 | + $statement->bindValue(":status", $this->status); |
|
| 192 | + $statement->bindValue(":onwikiname", $this->onwikiname); |
|
| 193 | + $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
| 194 | + $statement->bindValue(":lastactive", $this->lastactive); |
|
| 195 | + $statement->bindValue(":forcelogout", $this->forcelogout); |
|
| 196 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 197 | + $statement->bindValue(":welcome_template", $this->welcome_template); |
|
| 198 | + $statement->bindValue(":abortpref", $this->abortpref); |
|
| 199 | + $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
| 200 | + $statement->bindValue(":emailsig", $this->emailsig); |
|
| 201 | + $statement->bindValue(":creationmode", $this->creationmode); |
|
| 202 | + $statement->bindValue(":skin", $this->skin); |
|
| 203 | + |
|
| 204 | + if ($statement->execute()) { |
|
| 205 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 206 | + } |
|
| 207 | + else { |
|
| 208 | + throw new Exception($statement->errorInfo()); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + // update |
|
| 213 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 214 | 214 | UPDATE `user` SET |
| 215 | 215 | username = :username, email = :email, |
| 216 | 216 | status = :status, |
@@ -223,379 +223,379 @@ discard block |
||
| 223 | 223 | updateversion = updateversion + 1 |
| 224 | 224 | WHERE id = :id AND updateversion = :updateversion; |
| 225 | 225 | SQL |
| 226 | - ); |
|
| 227 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 228 | - |
|
| 229 | - $statement->bindValue(':id', $this->id); |
|
| 230 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 231 | - |
|
| 232 | - $statement->bindValue(':username', $this->username); |
|
| 233 | - $statement->bindValue(':email', $this->email); |
|
| 234 | - $statement->bindValue(':status', $this->status); |
|
| 235 | - $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 236 | - $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 237 | - $statement->bindValue(':lastactive', $this->lastactive); |
|
| 238 | - $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 239 | - $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 240 | - $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 241 | - $statement->bindValue(':abortpref', $this->abortpref); |
|
| 242 | - $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 243 | - $statement->bindValue(':emailsig', $this->emailsig); |
|
| 244 | - $statement->bindValue(':creationmode', $this->creationmode); |
|
| 245 | - $statement->bindValue(':skin', $this->skin); |
|
| 246 | - |
|
| 247 | - if (!$statement->execute()) { |
|
| 248 | - throw new Exception($statement->errorInfo()); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - if ($statement->rowCount() !== 1) { |
|
| 252 | - throw new OptimisticLockFailedException(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $this->updateversion++; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - #region properties |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Gets the tool username |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function getUsername() |
|
| 266 | - { |
|
| 267 | - return $this->username; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Sets the tool username |
|
| 272 | - * |
|
| 273 | - * @param string $username |
|
| 274 | - */ |
|
| 275 | - public function setUsername($username) |
|
| 276 | - { |
|
| 277 | - $this->username = $username; |
|
| 278 | - |
|
| 279 | - // If this isn't a brand new user, then it's a rename, force the logout |
|
| 280 | - if (!$this->isNew()) { |
|
| 281 | - $this->forcelogout = 1; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Gets the user's email address |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public function getEmail() |
|
| 290 | - { |
|
| 291 | - return $this->email; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Sets the user's email address |
|
| 296 | - * |
|
| 297 | - * @param string $email |
|
| 298 | - */ |
|
| 299 | - public function setEmail($email) |
|
| 300 | - { |
|
| 301 | - $this->email = $email; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function getStatus() |
|
| 309 | - { |
|
| 310 | - return $this->status; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @param string $status |
|
| 315 | - */ |
|
| 316 | - public function setStatus($status) |
|
| 317 | - { |
|
| 318 | - $this->status = $status; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Gets the user's on-wiki name |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function getOnWikiName() |
|
| 326 | - { |
|
| 327 | - return $this->onwikiname; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets the user's on-wiki name |
|
| 332 | - * |
|
| 333 | - * This can have interesting side-effects with OAuth. |
|
| 334 | - * |
|
| 335 | - * @param string $onWikiName |
|
| 336 | - */ |
|
| 337 | - public function setOnWikiName($onWikiName) |
|
| 338 | - { |
|
| 339 | - $this->onwikiname = $onWikiName; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Gets the welcome signature |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function getWelcomeSig() |
|
| 347 | - { |
|
| 348 | - return $this->welcome_sig; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Sets the welcome signature |
|
| 353 | - * |
|
| 354 | - * @param string $welcomeSig |
|
| 355 | - */ |
|
| 356 | - public function setWelcomeSig($welcomeSig) |
|
| 357 | - { |
|
| 358 | - $this->welcome_sig = $welcomeSig; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Gets the last activity date for the user |
|
| 363 | - * |
|
| 364 | - * @return string |
|
| 365 | - * @todo This should probably return an instance of DateTime |
|
| 366 | - */ |
|
| 367 | - public function getLastActive() |
|
| 368 | - { |
|
| 369 | - return $this->lastactive; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Gets the user's forced logout status |
|
| 374 | - * |
|
| 375 | - * @return bool |
|
| 376 | - */ |
|
| 377 | - public function getForceLogout() |
|
| 378 | - { |
|
| 379 | - return $this->forcelogout == 1; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Sets the user's forced logout status |
|
| 384 | - * |
|
| 385 | - * @param bool $forceLogout |
|
| 386 | - */ |
|
| 387 | - public function setForceLogout($forceLogout) |
|
| 388 | - { |
|
| 389 | - $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns the ID of the welcome template used. |
|
| 394 | - * @return int |
|
| 395 | - */ |
|
| 396 | - public function getWelcomeTemplate() |
|
| 397 | - { |
|
| 398 | - return $this->welcome_template; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Sets the ID of the welcome template used. |
|
| 403 | - * |
|
| 404 | - * @param int $welcomeTemplate |
|
| 405 | - */ |
|
| 406 | - public function setWelcomeTemplate($welcomeTemplate) |
|
| 407 | - { |
|
| 408 | - $this->welcome_template = $welcomeTemplate; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Gets the user's abort preference |
|
| 413 | - * @todo this is badly named too! Also a bool that's actually an int. |
|
| 414 | - * @return int |
|
| 415 | - */ |
|
| 416 | - public function getAbortPref() |
|
| 417 | - { |
|
| 418 | - return $this->abortpref; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Sets the user's abort preference |
|
| 423 | - * @todo rename, retype, and re-comment. |
|
| 424 | - * |
|
| 425 | - * @param int $abortPreference |
|
| 426 | - */ |
|
| 427 | - public function setAbortPref($abortPreference) |
|
| 428 | - { |
|
| 429 | - $this->abortpref = $abortPreference; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 434 | - * @return int the diff ID |
|
| 435 | - */ |
|
| 436 | - public function getConfirmationDiff() |
|
| 437 | - { |
|
| 438 | - return $this->confirmationdiff; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Sets the user's confirmation diff. |
|
| 443 | - * |
|
| 444 | - * @param int $confirmationDiff |
|
| 445 | - */ |
|
| 446 | - public function setConfirmationDiff($confirmationDiff) |
|
| 447 | - { |
|
| 448 | - $this->confirmationdiff = $confirmationDiff; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Gets the users' email signature used on outbound mail. |
|
| 453 | - * @todo rename me! |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - public function getEmailSig() |
|
| 457 | - { |
|
| 458 | - return $this->emailsig; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Sets the user's email signature for outbound mail. |
|
| 463 | - * |
|
| 464 | - * @param string $emailSignature |
|
| 465 | - */ |
|
| 466 | - public function setEmailSig($emailSignature) |
|
| 467 | - { |
|
| 468 | - $this->emailsig = $emailSignature; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return int |
|
| 473 | - */ |
|
| 474 | - public function getCreationMode() |
|
| 475 | - { |
|
| 476 | - return $this->creationmode; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @param $creationMode int |
|
| 481 | - */ |
|
| 482 | - public function setCreationMode($creationMode) |
|
| 483 | - { |
|
| 484 | - $this->creationmode = $creationMode; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @return string |
|
| 489 | - */ |
|
| 490 | - public function getSkin() |
|
| 491 | - { |
|
| 492 | - return $this->skin; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @param $skin string |
|
| 497 | - */ |
|
| 498 | - public function setSkin($skin) |
|
| 499 | - { |
|
| 500 | - $this->skin = $skin; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - #endregion |
|
| 504 | - |
|
| 505 | - #region user access checks |
|
| 506 | - |
|
| 507 | - public function isActive() |
|
| 508 | - { |
|
| 509 | - return $this->status == self::STATUS_ACTIVE; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Tests if the user is identified |
|
| 514 | - * |
|
| 515 | - * @param IdentificationVerifier $iv |
|
| 516 | - * |
|
| 517 | - * @return bool |
|
| 518 | - * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 519 | - * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 520 | - * to play it safe for now. |
|
| 521 | - * @category Security-Critical |
|
| 522 | - */ |
|
| 523 | - public function isIdentified(IdentificationVerifier $iv) |
|
| 524 | - { |
|
| 525 | - if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 526 | - // User forced to unidentified in the database. |
|
| 527 | - return false; |
|
| 528 | - } |
|
| 529 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 530 | - // User forced to identified in the database. |
|
| 531 | - return true; |
|
| 532 | - } |
|
| 533 | - else { |
|
| 534 | - // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 535 | - return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * DO NOT USE FOR TESTING IDENTIFICATION STATUS. |
|
| 541 | - * |
|
| 542 | - * @return bool|null |
|
| 543 | - */ |
|
| 544 | - public function getForceIdentified() { |
|
| 545 | - return $this->forceidentified; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Tests if the user is suspended |
|
| 550 | - * @return bool |
|
| 551 | - * @category Security-Critical |
|
| 552 | - */ |
|
| 553 | - public function isSuspended() |
|
| 554 | - { |
|
| 555 | - return $this->status == self::STATUS_SUSPENDED; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Tests if the user is new |
|
| 560 | - * @return bool |
|
| 561 | - * @category Security-Critical |
|
| 562 | - */ |
|
| 563 | - public function isNewUser() |
|
| 564 | - { |
|
| 565 | - return $this->status == self::STATUS_NEW; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Tests if the user has been declined access to the tool |
|
| 570 | - * @return bool |
|
| 571 | - * @category Security-Critical |
|
| 572 | - */ |
|
| 573 | - public function isDeclined() |
|
| 574 | - { |
|
| 575 | - return $this->status == self::STATUS_DECLINED; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Tests if the user is the community user |
|
| 580 | - * |
|
| 581 | - * @todo decide if this means logged out. I think it usually does. |
|
| 582 | - * @return bool |
|
| 583 | - * @category Security-Critical |
|
| 584 | - */ |
|
| 585 | - public function isCommunityUser() |
|
| 586 | - { |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - #endregion |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Gets the approval date of the user |
|
| 594 | - * @return DateTime|false |
|
| 595 | - */ |
|
| 596 | - public function getApprovalDate() |
|
| 597 | - { |
|
| 598 | - $query = $this->dbObject->prepare(<<<SQL |
|
| 226 | + ); |
|
| 227 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
| 228 | + |
|
| 229 | + $statement->bindValue(':id', $this->id); |
|
| 230 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 231 | + |
|
| 232 | + $statement->bindValue(':username', $this->username); |
|
| 233 | + $statement->bindValue(':email', $this->email); |
|
| 234 | + $statement->bindValue(':status', $this->status); |
|
| 235 | + $statement->bindValue(':onwikiname', $this->onwikiname); |
|
| 236 | + $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
| 237 | + $statement->bindValue(':lastactive', $this->lastactive); |
|
| 238 | + $statement->bindValue(':forcelogout', $this->forcelogout); |
|
| 239 | + $statement->bindValue(':forceidentified', $this->forceidentified); |
|
| 240 | + $statement->bindValue(':welcome_template', $this->welcome_template); |
|
| 241 | + $statement->bindValue(':abortpref', $this->abortpref); |
|
| 242 | + $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
| 243 | + $statement->bindValue(':emailsig', $this->emailsig); |
|
| 244 | + $statement->bindValue(':creationmode', $this->creationmode); |
|
| 245 | + $statement->bindValue(':skin', $this->skin); |
|
| 246 | + |
|
| 247 | + if (!$statement->execute()) { |
|
| 248 | + throw new Exception($statement->errorInfo()); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + if ($statement->rowCount() !== 1) { |
|
| 252 | + throw new OptimisticLockFailedException(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $this->updateversion++; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + #region properties |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Gets the tool username |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function getUsername() |
|
| 266 | + { |
|
| 267 | + return $this->username; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Sets the tool username |
|
| 272 | + * |
|
| 273 | + * @param string $username |
|
| 274 | + */ |
|
| 275 | + public function setUsername($username) |
|
| 276 | + { |
|
| 277 | + $this->username = $username; |
|
| 278 | + |
|
| 279 | + // If this isn't a brand new user, then it's a rename, force the logout |
|
| 280 | + if (!$this->isNew()) { |
|
| 281 | + $this->forcelogout = 1; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Gets the user's email address |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public function getEmail() |
|
| 290 | + { |
|
| 291 | + return $this->email; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Sets the user's email address |
|
| 296 | + * |
|
| 297 | + * @param string $email |
|
| 298 | + */ |
|
| 299 | + public function setEmail($email) |
|
| 300 | + { |
|
| 301 | + $this->email = $email; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function getStatus() |
|
| 309 | + { |
|
| 310 | + return $this->status; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @param string $status |
|
| 315 | + */ |
|
| 316 | + public function setStatus($status) |
|
| 317 | + { |
|
| 318 | + $this->status = $status; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Gets the user's on-wiki name |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function getOnWikiName() |
|
| 326 | + { |
|
| 327 | + return $this->onwikiname; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets the user's on-wiki name |
|
| 332 | + * |
|
| 333 | + * This can have interesting side-effects with OAuth. |
|
| 334 | + * |
|
| 335 | + * @param string $onWikiName |
|
| 336 | + */ |
|
| 337 | + public function setOnWikiName($onWikiName) |
|
| 338 | + { |
|
| 339 | + $this->onwikiname = $onWikiName; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Gets the welcome signature |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function getWelcomeSig() |
|
| 347 | + { |
|
| 348 | + return $this->welcome_sig; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Sets the welcome signature |
|
| 353 | + * |
|
| 354 | + * @param string $welcomeSig |
|
| 355 | + */ |
|
| 356 | + public function setWelcomeSig($welcomeSig) |
|
| 357 | + { |
|
| 358 | + $this->welcome_sig = $welcomeSig; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Gets the last activity date for the user |
|
| 363 | + * |
|
| 364 | + * @return string |
|
| 365 | + * @todo This should probably return an instance of DateTime |
|
| 366 | + */ |
|
| 367 | + public function getLastActive() |
|
| 368 | + { |
|
| 369 | + return $this->lastactive; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Gets the user's forced logout status |
|
| 374 | + * |
|
| 375 | + * @return bool |
|
| 376 | + */ |
|
| 377 | + public function getForceLogout() |
|
| 378 | + { |
|
| 379 | + return $this->forcelogout == 1; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Sets the user's forced logout status |
|
| 384 | + * |
|
| 385 | + * @param bool $forceLogout |
|
| 386 | + */ |
|
| 387 | + public function setForceLogout($forceLogout) |
|
| 388 | + { |
|
| 389 | + $this->forcelogout = $forceLogout ? 1 : 0; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns the ID of the welcome template used. |
|
| 394 | + * @return int |
|
| 395 | + */ |
|
| 396 | + public function getWelcomeTemplate() |
|
| 397 | + { |
|
| 398 | + return $this->welcome_template; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Sets the ID of the welcome template used. |
|
| 403 | + * |
|
| 404 | + * @param int $welcomeTemplate |
|
| 405 | + */ |
|
| 406 | + public function setWelcomeTemplate($welcomeTemplate) |
|
| 407 | + { |
|
| 408 | + $this->welcome_template = $welcomeTemplate; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Gets the user's abort preference |
|
| 413 | + * @todo this is badly named too! Also a bool that's actually an int. |
|
| 414 | + * @return int |
|
| 415 | + */ |
|
| 416 | + public function getAbortPref() |
|
| 417 | + { |
|
| 418 | + return $this->abortpref; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Sets the user's abort preference |
|
| 423 | + * @todo rename, retype, and re-comment. |
|
| 424 | + * |
|
| 425 | + * @param int $abortPreference |
|
| 426 | + */ |
|
| 427 | + public function setAbortPref($abortPreference) |
|
| 428 | + { |
|
| 429 | + $this->abortpref = $abortPreference; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
| 434 | + * @return int the diff ID |
|
| 435 | + */ |
|
| 436 | + public function getConfirmationDiff() |
|
| 437 | + { |
|
| 438 | + return $this->confirmationdiff; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Sets the user's confirmation diff. |
|
| 443 | + * |
|
| 444 | + * @param int $confirmationDiff |
|
| 445 | + */ |
|
| 446 | + public function setConfirmationDiff($confirmationDiff) |
|
| 447 | + { |
|
| 448 | + $this->confirmationdiff = $confirmationDiff; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Gets the users' email signature used on outbound mail. |
|
| 453 | + * @todo rename me! |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + public function getEmailSig() |
|
| 457 | + { |
|
| 458 | + return $this->emailsig; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Sets the user's email signature for outbound mail. |
|
| 463 | + * |
|
| 464 | + * @param string $emailSignature |
|
| 465 | + */ |
|
| 466 | + public function setEmailSig($emailSignature) |
|
| 467 | + { |
|
| 468 | + $this->emailsig = $emailSignature; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return int |
|
| 473 | + */ |
|
| 474 | + public function getCreationMode() |
|
| 475 | + { |
|
| 476 | + return $this->creationmode; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @param $creationMode int |
|
| 481 | + */ |
|
| 482 | + public function setCreationMode($creationMode) |
|
| 483 | + { |
|
| 484 | + $this->creationmode = $creationMode; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @return string |
|
| 489 | + */ |
|
| 490 | + public function getSkin() |
|
| 491 | + { |
|
| 492 | + return $this->skin; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param $skin string |
|
| 497 | + */ |
|
| 498 | + public function setSkin($skin) |
|
| 499 | + { |
|
| 500 | + $this->skin = $skin; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + #endregion |
|
| 504 | + |
|
| 505 | + #region user access checks |
|
| 506 | + |
|
| 507 | + public function isActive() |
|
| 508 | + { |
|
| 509 | + return $this->status == self::STATUS_ACTIVE; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Tests if the user is identified |
|
| 514 | + * |
|
| 515 | + * @param IdentificationVerifier $iv |
|
| 516 | + * |
|
| 517 | + * @return bool |
|
| 518 | + * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
| 519 | + * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
| 520 | + * to play it safe for now. |
|
| 521 | + * @category Security-Critical |
|
| 522 | + */ |
|
| 523 | + public function isIdentified(IdentificationVerifier $iv) |
|
| 524 | + { |
|
| 525 | + if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
| 526 | + // User forced to unidentified in the database. |
|
| 527 | + return false; |
|
| 528 | + } |
|
| 529 | + elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
| 530 | + // User forced to identified in the database. |
|
| 531 | + return true; |
|
| 532 | + } |
|
| 533 | + else { |
|
| 534 | + // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 535 | + return $iv->isUserIdentified($this->getOnWikiName()); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * DO NOT USE FOR TESTING IDENTIFICATION STATUS. |
|
| 541 | + * |
|
| 542 | + * @return bool|null |
|
| 543 | + */ |
|
| 544 | + public function getForceIdentified() { |
|
| 545 | + return $this->forceidentified; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Tests if the user is suspended |
|
| 550 | + * @return bool |
|
| 551 | + * @category Security-Critical |
|
| 552 | + */ |
|
| 553 | + public function isSuspended() |
|
| 554 | + { |
|
| 555 | + return $this->status == self::STATUS_SUSPENDED; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Tests if the user is new |
|
| 560 | + * @return bool |
|
| 561 | + * @category Security-Critical |
|
| 562 | + */ |
|
| 563 | + public function isNewUser() |
|
| 564 | + { |
|
| 565 | + return $this->status == self::STATUS_NEW; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Tests if the user has been declined access to the tool |
|
| 570 | + * @return bool |
|
| 571 | + * @category Security-Critical |
|
| 572 | + */ |
|
| 573 | + public function isDeclined() |
|
| 574 | + { |
|
| 575 | + return $this->status == self::STATUS_DECLINED; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Tests if the user is the community user |
|
| 580 | + * |
|
| 581 | + * @todo decide if this means logged out. I think it usually does. |
|
| 582 | + * @return bool |
|
| 583 | + * @category Security-Critical |
|
| 584 | + */ |
|
| 585 | + public function isCommunityUser() |
|
| 586 | + { |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + #endregion |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Gets the approval date of the user |
|
| 594 | + * @return DateTime|false |
|
| 595 | + */ |
|
| 596 | + public function getApprovalDate() |
|
| 597 | + { |
|
| 598 | + $query = $this->dbObject->prepare(<<<SQL |
|
| 599 | 599 | SELECT timestamp |
| 600 | 600 | FROM log |
| 601 | 601 | WHERE objectid = :userid |
@@ -604,12 +604,12 @@ discard block |
||
| 604 | 604 | ORDER BY id DESC |
| 605 | 605 | LIMIT 1; |
| 606 | 606 | SQL |
| 607 | - ); |
|
| 608 | - $query->execute(array(":userid" => $this->id)); |
|
| 607 | + ); |
|
| 608 | + $query->execute(array(":userid" => $this->id)); |
|
| 609 | 609 | |
| 610 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 611 | - $query->closeCursor(); |
|
| 610 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
| 611 | + $query->closeCursor(); |
|
| 612 | 612 | |
| 613 | - return $data; |
|
| 614 | - } |
|
| 613 | + return $data; |
|
| 614 | + } |
|
| 615 | 615 | } |
@@ -46,8 +46,7 @@ |
||
| 46 | 46 | SessionAlert::success("Preferences updated!"); |
| 47 | 47 | |
| 48 | 48 | $this->redirect(''); |
| 49 | - } |
|
| 50 | - else { |
|
| 49 | + } else { |
|
| 51 | 50 | $this->assignCSRFToken(); |
| 52 | 51 | $this->setTemplate('preferences/prefs.tpl'); |
| 53 | 52 | $this->assign("enforceOAuth", $enforceOAuth); |
@@ -16,98 +16,98 @@ |
||
| 16 | 16 | |
| 17 | 17 | class PagePreferences extends InternalPageBase |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Main function for this page, when no specific actions are called. |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - protected function main() |
|
| 24 | - { |
|
| 25 | - $this->setHtmlTitle('Preferences'); |
|
| 26 | - |
|
| 27 | - $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
| 28 | - $database = $this->getDatabase(); |
|
| 29 | - $user = User::getCurrent($database); |
|
| 30 | - |
|
| 31 | - // Dual mode |
|
| 32 | - if (WebRequest::wasPosted()) { |
|
| 33 | - $this->validateCSRFToken(); |
|
| 34 | - $user->setWelcomeSig(WebRequest::postString('sig')); |
|
| 35 | - $user->setEmailSig(WebRequest::postString('emailsig')); |
|
| 36 | - $user->setAbortPref(WebRequest::postBoolean('abortpref') ? 1 : 0); |
|
| 37 | - $this->setCreationMode($user); |
|
| 38 | - |
|
| 39 | - $newSkin = WebRequest::postString('skintype'); |
|
| 40 | - if ($newSkin === 'main' || $newSkin === 'alt' || $newSkin === 'auto') { |
|
| 41 | - $user->setSkin($newSkin); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $email = WebRequest::postEmail('email'); |
|
| 45 | - if ($email !== null) { |
|
| 46 | - $user->setEmail($email); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $user->save(); |
|
| 50 | - SessionAlert::success("Preferences updated!"); |
|
| 51 | - |
|
| 52 | - $this->redirect(''); |
|
| 53 | - } |
|
| 54 | - else { |
|
| 55 | - $this->assignCSRFToken(); |
|
| 56 | - $this->setTemplate('preferences/prefs.tpl'); |
|
| 57 | - $this->assign("enforceOAuth", $enforceOAuth); |
|
| 58 | - |
|
| 59 | - $this->assign('canManualCreate', |
|
| 60 | - $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 61 | - $this->assign('canOauthCreate', |
|
| 62 | - $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 63 | - $this->assign('canBotCreate', |
|
| 64 | - $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
|
| 65 | - |
|
| 66 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 67 | - $this->getSiteConfiguration()); |
|
| 68 | - $this->assign('oauth', $oauth); |
|
| 69 | - |
|
| 70 | - $identity = null; |
|
| 71 | - if ($oauth->isFullyLinked()) { |
|
| 72 | - $identity = $oauth->getIdentity(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->assign('identity', $identity); |
|
| 76 | - $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - protected function refreshOAuth() |
|
| 81 | - { |
|
| 82 | - if (!WebRequest::wasPosted()) { |
|
| 83 | - $this->redirect('preferences'); |
|
| 84 | - |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $database = $this->getDatabase(); |
|
| 89 | - $oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(), |
|
| 90 | - $this->getSiteConfiguration()); |
|
| 91 | - if ($oauth->isFullyLinked()) { |
|
| 92 | - $oauth->refreshIdentity(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $this->redirect('preferences'); |
|
| 96 | - |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param User $user |
|
| 102 | - */ |
|
| 103 | - protected function setCreationMode(User $user) |
|
| 104 | - { |
|
| 105 | - // if the user is selecting a creation mode that they are not allowed, do nothing. |
|
| 106 | - // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
|
| 107 | - // or that they have kept from when they previously had certain access. |
|
| 108 | - $creationMode = WebRequest::postInt('creationmode'); |
|
| 109 | - if ($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
|
| 110 | - $user->setCreationMode($creationMode); |
|
| 111 | - } |
|
| 112 | - } |
|
| 19 | + /** |
|
| 20 | + * Main function for this page, when no specific actions are called. |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + protected function main() |
|
| 24 | + { |
|
| 25 | + $this->setHtmlTitle('Preferences'); |
|
| 26 | + |
|
| 27 | + $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
| 28 | + $database = $this->getDatabase(); |
|
| 29 | + $user = User::getCurrent($database); |
|
| 30 | + |
|
| 31 | + // Dual mode |
|
| 32 | + if (WebRequest::wasPosted()) { |
|
| 33 | + $this->validateCSRFToken(); |
|
| 34 | + $user->setWelcomeSig(WebRequest::postString('sig')); |
|
| 35 | + $user->setEmailSig(WebRequest::postString('emailsig')); |
|
| 36 | + $user->setAbortPref(WebRequest::postBoolean('abortpref') ? 1 : 0); |
|
| 37 | + $this->setCreationMode($user); |
|
| 38 | + |
|
| 39 | + $newSkin = WebRequest::postString('skintype'); |
|
| 40 | + if ($newSkin === 'main' || $newSkin === 'alt' || $newSkin === 'auto') { |
|
| 41 | + $user->setSkin($newSkin); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $email = WebRequest::postEmail('email'); |
|
| 45 | + if ($email !== null) { |
|
| 46 | + $user->setEmail($email); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $user->save(); |
|
| 50 | + SessionAlert::success("Preferences updated!"); |
|
| 51 | + |
|
| 52 | + $this->redirect(''); |
|
| 53 | + } |
|
| 54 | + else { |
|
| 55 | + $this->assignCSRFToken(); |
|
| 56 | + $this->setTemplate('preferences/prefs.tpl'); |
|
| 57 | + $this->assign("enforceOAuth", $enforceOAuth); |
|
| 58 | + |
|
| 59 | + $this->assign('canManualCreate', |
|
| 60 | + $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 61 | + $this->assign('canOauthCreate', |
|
| 62 | + $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 63 | + $this->assign('canBotCreate', |
|
| 64 | + $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
|
| 65 | + |
|
| 66 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 67 | + $this->getSiteConfiguration()); |
|
| 68 | + $this->assign('oauth', $oauth); |
|
| 69 | + |
|
| 70 | + $identity = null; |
|
| 71 | + if ($oauth->isFullyLinked()) { |
|
| 72 | + $identity = $oauth->getIdentity(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->assign('identity', $identity); |
|
| 76 | + $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + protected function refreshOAuth() |
|
| 81 | + { |
|
| 82 | + if (!WebRequest::wasPosted()) { |
|
| 83 | + $this->redirect('preferences'); |
|
| 84 | + |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $database = $this->getDatabase(); |
|
| 89 | + $oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(), |
|
| 90 | + $this->getSiteConfiguration()); |
|
| 91 | + if ($oauth->isFullyLinked()) { |
|
| 92 | + $oauth->refreshIdentity(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $this->redirect('preferences'); |
|
| 96 | + |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param User $user |
|
| 102 | + */ |
|
| 103 | + protected function setCreationMode(User $user) |
|
| 104 | + { |
|
| 105 | + // if the user is selecting a creation mode that they are not allowed, do nothing. |
|
| 106 | + // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
|
| 107 | + // or that they have kept from when they previously had certain access. |
|
| 108 | + $creationMode = WebRequest::postInt('creationmode'); |
|
| 109 | + if ($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
|
| 110 | + $user->setCreationMode($creationMode); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -99,8 +99,7 @@ discard block |
||
| 99 | 99 | $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
| 100 | 100 | $this->setupCheckUserData($request); |
| 101 | 101 | } |
| 102 | - } |
|
| 103 | - else { |
|
| 102 | + } else { |
|
| 104 | 103 | $this->setTemplate('view-request/main.tpl'); |
| 105 | 104 | } |
| 106 | 105 | } |
@@ -114,8 +113,7 @@ discard block |
||
| 114 | 113 | if ($request->getStatus() === 'Closed') { |
| 115 | 114 | if ($request->getWasCreated()) { |
| 116 | 115 | $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
| 117 | - } |
|
| 118 | - else { |
|
| 116 | + } else { |
|
| 119 | 117 | $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
| 120 | 118 | } |
| 121 | 119 | } |
@@ -25,279 +25,279 @@ |
||
| 25 | 25 | |
| 26 | 26 | class PageViewRequest extends InternalPageBase |
| 27 | 27 | { |
| 28 | - use RequestData; |
|
| 29 | - const STATUS_SYMBOL_OPEN = 'Ο'; |
|
| 30 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 31 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Main function for this page, when no specific actions are called. |
|
| 35 | - * @throws ApplicationLogicException |
|
| 36 | - */ |
|
| 37 | - protected function main() |
|
| 38 | - { |
|
| 39 | - // set up csrf protection |
|
| 40 | - $this->assignCSRFToken(); |
|
| 41 | - |
|
| 42 | - // get some useful objects |
|
| 43 | - $database = $this->getDatabase(); |
|
| 44 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 45 | - $config = $this->getSiteConfiguration(); |
|
| 46 | - $currentUser = User::getCurrent($database); |
|
| 47 | - |
|
| 48 | - // Test we should be able to look at this request |
|
| 49 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 50 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 51 | - // Not allowed to look at this yet. |
|
| 52 | - throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $this->setupBasicData($request, $config); |
|
| 57 | - |
|
| 58 | - $this->setupUsernameData($request); |
|
| 59 | - |
|
| 60 | - $this->setupTitle($request); |
|
| 61 | - |
|
| 62 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 63 | - $this->setupGeneralData($database); |
|
| 64 | - |
|
| 65 | - $this->assign('requestDataCleared', false); |
|
| 66 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 67 | - $this->assign('requestDataCleared', true); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 71 | - |
|
| 72 | - $this->setupCreationTypes($currentUser); |
|
| 73 | - |
|
| 74 | - $this->setupLogData($request, $database); |
|
| 75 | - |
|
| 76 | - $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 77 | - |
|
| 78 | - $this->assign('showRevealLink', false); |
|
| 79 | - if ($request->getReserved() === $currentUser->getId() || |
|
| 80 | - $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 81 | - ) { |
|
| 82 | - $this->assign('showRevealLink', true); |
|
| 83 | - $this->assign('revealHash', $request->getRevealHash()); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->assign('canSeeRelatedRequests', false); |
|
| 87 | - if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) { |
|
| 88 | - $this->setupRelatedRequests($request, $config, $database); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($allowedPrivateData) { |
|
| 92 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 93 | - $this->setupPrivateData($request); |
|
| 94 | - |
|
| 95 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 96 | - $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 97 | - |
|
| 98 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 99 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 100 | - $this->setupCheckUserData($request); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - else { |
|
| 104 | - $this->setTemplate('view-request/main.tpl'); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param Request $request |
|
| 110 | - */ |
|
| 111 | - protected function setupTitle(Request $request) |
|
| 112 | - { |
|
| 113 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 114 | - if ($request->getStatus() === 'Closed') { |
|
| 115 | - if ($request->getWasCreated()) { |
|
| 116 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 117 | - } |
|
| 118 | - else { |
|
| 119 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Sets up data unrelated to the request, such as the email template information |
|
| 128 | - * |
|
| 129 | - * @param PdoDatabase $database |
|
| 130 | - */ |
|
| 131 | - protected function setupGeneralData(PdoDatabase $database) |
|
| 132 | - { |
|
| 133 | - $config = $this->getSiteConfiguration(); |
|
| 134 | - |
|
| 135 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 136 | - |
|
| 137 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 138 | - |
|
| 139 | - $this->assign('requestStates', $config->getRequestStates()); |
|
| 140 | - |
|
| 141 | - /** @var EmailTemplate $createdTemplate */ |
|
| 142 | - $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 143 | - |
|
| 144 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 145 | - $this->assign('createdId', $createdTemplate->getId()); |
|
| 146 | - $this->assign('createdName', $createdTemplate->getName()); |
|
| 147 | - |
|
| 148 | - $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 149 | - $this->assign("createReasons", $createReasons); |
|
| 150 | - $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 151 | - $this->assign("declineReasons", $declineReasons); |
|
| 152 | - |
|
| 153 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 154 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
| 155 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 156 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 157 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 158 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - private function setupLogData(Request $request, PdoDatabase $database) |
|
| 162 | - { |
|
| 163 | - $currentUser = User::getCurrent($database); |
|
| 164 | - |
|
| 165 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 166 | - $requestLogs = array(); |
|
| 167 | - |
|
| 168 | - /** @var User[] $nameCache */ |
|
| 169 | - $nameCache = array(); |
|
| 170 | - |
|
| 171 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 172 | - |
|
| 173 | - /** @var Log|Comment $entry */ |
|
| 174 | - foreach ($logs as $entry) { |
|
| 175 | - // both log and comment have a 'user' field |
|
| 176 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 177 | - $entryUser = User::getById($entry->getUser(), $database); |
|
| 178 | - $nameCache[$entry->getUser()] = $entryUser; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if ($entry instanceof Comment) { |
|
| 182 | - $requestLogs[] = array( |
|
| 183 | - 'type' => 'comment', |
|
| 184 | - 'security' => $entry->getVisibility(), |
|
| 185 | - 'user' => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(), |
|
| 186 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 187 | - 'entry' => null, |
|
| 188 | - 'time' => $entry->getTime(), |
|
| 189 | - 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 190 | - 'id' => $entry->getId(), |
|
| 191 | - 'comment' => $entry->getComment(), |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($entry instanceof Log) { |
|
| 196 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 197 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 198 | - |
|
| 199 | - $entryComment = $entry->getComment(); |
|
| 200 | - |
|
| 201 | - if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') { |
|
| 202 | - $data = unserialize($entry->getComment()); |
|
| 203 | - /** @var JobQueue $job */ |
|
| 204 | - $job = JobQueue::getById($data['job'], $database); |
|
| 205 | - $requestLogs[] = array( |
|
| 206 | - 'type' => 'joblog', |
|
| 207 | - 'security' => 'user', |
|
| 208 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 209 | - 'user' => $entryUser->getUsername(), |
|
| 210 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 211 | - 'time' => $entry->getTimestamp(), |
|
| 212 | - 'canedit' => false, |
|
| 213 | - 'id' => $entry->getId(), |
|
| 214 | - 'jobId' => $job->getId(), |
|
| 215 | - 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 216 | - ); |
|
| 217 | - } else { |
|
| 218 | - $requestLogs[] = array( |
|
| 219 | - 'type' => 'log', |
|
| 220 | - 'security' => 'user', |
|
| 221 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 222 | - 'user' => $entryUser->getUsername(), |
|
| 223 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 224 | - 'time' => $entry->getTimestamp(), |
|
| 225 | - 'canedit' => false, |
|
| 226 | - 'id' => $entry->getId(), |
|
| 227 | - 'comment' => $entryComment, |
|
| 228 | - ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 234 | - |
|
| 235 | - $this->assign("requestLogs", $requestLogs); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param Request $request |
|
| 240 | - */ |
|
| 241 | - protected function setupUsernameData(Request $request) |
|
| 242 | - { |
|
| 243 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 244 | - |
|
| 245 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 246 | - $this->assign('requestBlacklist', $blacklistData); |
|
| 247 | - |
|
| 248 | - try { |
|
| 249 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 250 | - } |
|
| 251 | - catch (Exception $ex) { |
|
| 252 | - $spoofs = $ex->getMessage(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $this->assign("spoofs", $spoofs); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - private function setupCreationTypes(User $user) |
|
| 259 | - { |
|
| 260 | - $this->assign('allowWelcomeSkip', false); |
|
| 261 | - $this->assign('forceWelcomeSkip', false); |
|
| 262 | - |
|
| 263 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 264 | - |
|
| 265 | - if ($user->getWelcomeTemplate() != 0) { |
|
| 266 | - $this->assign('allowWelcomeSkip', true); |
|
| 267 | - |
|
| 268 | - if (!$oauth->canWelcome()) { |
|
| 269 | - $this->assign('forceWelcomeSkip', true); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // test credentials |
|
| 274 | - $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 275 | - $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 276 | - $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
|
| 277 | - |
|
| 278 | - $this->assign('canManualCreate', $canManualCreate); |
|
| 279 | - $this->assign('canOauthCreate', $canOauthCreate); |
|
| 280 | - $this->assign('canBotCreate', $canBotCreate); |
|
| 281 | - |
|
| 282 | - // show/hide the type radio buttons |
|
| 283 | - $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 284 | - |
|
| 285 | - if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
|
| 286 | - // user is not allowed to use their default. Force a choice. |
|
| 287 | - $creationHasChoice = true; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - $this->assign('creationHasChoice', $creationHasChoice); |
|
| 291 | - |
|
| 292 | - // determine problems in creation types |
|
| 293 | - $this->assign('botProblem', false); |
|
| 294 | - if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 295 | - $this->assign('botProblem', true); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $this->assign('oauthProblem', false); |
|
| 299 | - if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 300 | - $this->assign('oauthProblem', true); |
|
| 301 | - } |
|
| 302 | - } |
|
| 28 | + use RequestData; |
|
| 29 | + const STATUS_SYMBOL_OPEN = 'Ο'; |
|
| 30 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 31 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Main function for this page, when no specific actions are called. |
|
| 35 | + * @throws ApplicationLogicException |
|
| 36 | + */ |
|
| 37 | + protected function main() |
|
| 38 | + { |
|
| 39 | + // set up csrf protection |
|
| 40 | + $this->assignCSRFToken(); |
|
| 41 | + |
|
| 42 | + // get some useful objects |
|
| 43 | + $database = $this->getDatabase(); |
|
| 44 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 45 | + $config = $this->getSiteConfiguration(); |
|
| 46 | + $currentUser = User::getCurrent($database); |
|
| 47 | + |
|
| 48 | + // Test we should be able to look at this request |
|
| 49 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 50 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 51 | + // Not allowed to look at this yet. |
|
| 52 | + throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $this->setupBasicData($request, $config); |
|
| 57 | + |
|
| 58 | + $this->setupUsernameData($request); |
|
| 59 | + |
|
| 60 | + $this->setupTitle($request); |
|
| 61 | + |
|
| 62 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 63 | + $this->setupGeneralData($database); |
|
| 64 | + |
|
| 65 | + $this->assign('requestDataCleared', false); |
|
| 66 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 67 | + $this->assign('requestDataCleared', true); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 71 | + |
|
| 72 | + $this->setupCreationTypes($currentUser); |
|
| 73 | + |
|
| 74 | + $this->setupLogData($request, $database); |
|
| 75 | + |
|
| 76 | + $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 77 | + |
|
| 78 | + $this->assign('showRevealLink', false); |
|
| 79 | + if ($request->getReserved() === $currentUser->getId() || |
|
| 80 | + $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 81 | + ) { |
|
| 82 | + $this->assign('showRevealLink', true); |
|
| 83 | + $this->assign('revealHash', $request->getRevealHash()); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->assign('canSeeRelatedRequests', false); |
|
| 87 | + if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) { |
|
| 88 | + $this->setupRelatedRequests($request, $config, $database); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($allowedPrivateData) { |
|
| 92 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 93 | + $this->setupPrivateData($request); |
|
| 94 | + |
|
| 95 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 96 | + $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 97 | + |
|
| 98 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 99 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 100 | + $this->setupCheckUserData($request); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + else { |
|
| 104 | + $this->setTemplate('view-request/main.tpl'); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param Request $request |
|
| 110 | + */ |
|
| 111 | + protected function setupTitle(Request $request) |
|
| 112 | + { |
|
| 113 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 114 | + if ($request->getStatus() === 'Closed') { |
|
| 115 | + if ($request->getWasCreated()) { |
|
| 116 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 117 | + } |
|
| 118 | + else { |
|
| 119 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Sets up data unrelated to the request, such as the email template information |
|
| 128 | + * |
|
| 129 | + * @param PdoDatabase $database |
|
| 130 | + */ |
|
| 131 | + protected function setupGeneralData(PdoDatabase $database) |
|
| 132 | + { |
|
| 133 | + $config = $this->getSiteConfiguration(); |
|
| 134 | + |
|
| 135 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 136 | + |
|
| 137 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 138 | + |
|
| 139 | + $this->assign('requestStates', $config->getRequestStates()); |
|
| 140 | + |
|
| 141 | + /** @var EmailTemplate $createdTemplate */ |
|
| 142 | + $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 143 | + |
|
| 144 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 145 | + $this->assign('createdId', $createdTemplate->getId()); |
|
| 146 | + $this->assign('createdName', $createdTemplate->getName()); |
|
| 147 | + |
|
| 148 | + $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 149 | + $this->assign("createReasons", $createReasons); |
|
| 150 | + $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 151 | + $this->assign("declineReasons", $declineReasons); |
|
| 152 | + |
|
| 153 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 154 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
| 155 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 156 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 157 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 158 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + private function setupLogData(Request $request, PdoDatabase $database) |
|
| 162 | + { |
|
| 163 | + $currentUser = User::getCurrent($database); |
|
| 164 | + |
|
| 165 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 166 | + $requestLogs = array(); |
|
| 167 | + |
|
| 168 | + /** @var User[] $nameCache */ |
|
| 169 | + $nameCache = array(); |
|
| 170 | + |
|
| 171 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 172 | + |
|
| 173 | + /** @var Log|Comment $entry */ |
|
| 174 | + foreach ($logs as $entry) { |
|
| 175 | + // both log and comment have a 'user' field |
|
| 176 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 177 | + $entryUser = User::getById($entry->getUser(), $database); |
|
| 178 | + $nameCache[$entry->getUser()] = $entryUser; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if ($entry instanceof Comment) { |
|
| 182 | + $requestLogs[] = array( |
|
| 183 | + 'type' => 'comment', |
|
| 184 | + 'security' => $entry->getVisibility(), |
|
| 185 | + 'user' => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(), |
|
| 186 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 187 | + 'entry' => null, |
|
| 188 | + 'time' => $entry->getTime(), |
|
| 189 | + 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 190 | + 'id' => $entry->getId(), |
|
| 191 | + 'comment' => $entry->getComment(), |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($entry instanceof Log) { |
|
| 196 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 197 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 198 | + |
|
| 199 | + $entryComment = $entry->getComment(); |
|
| 200 | + |
|
| 201 | + if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') { |
|
| 202 | + $data = unserialize($entry->getComment()); |
|
| 203 | + /** @var JobQueue $job */ |
|
| 204 | + $job = JobQueue::getById($data['job'], $database); |
|
| 205 | + $requestLogs[] = array( |
|
| 206 | + 'type' => 'joblog', |
|
| 207 | + 'security' => 'user', |
|
| 208 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 209 | + 'user' => $entryUser->getUsername(), |
|
| 210 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 211 | + 'time' => $entry->getTimestamp(), |
|
| 212 | + 'canedit' => false, |
|
| 213 | + 'id' => $entry->getId(), |
|
| 214 | + 'jobId' => $job->getId(), |
|
| 215 | + 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 216 | + ); |
|
| 217 | + } else { |
|
| 218 | + $requestLogs[] = array( |
|
| 219 | + 'type' => 'log', |
|
| 220 | + 'security' => 'user', |
|
| 221 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 222 | + 'user' => $entryUser->getUsername(), |
|
| 223 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 224 | + 'time' => $entry->getTimestamp(), |
|
| 225 | + 'canedit' => false, |
|
| 226 | + 'id' => $entry->getId(), |
|
| 227 | + 'comment' => $entryComment, |
|
| 228 | + ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 234 | + |
|
| 235 | + $this->assign("requestLogs", $requestLogs); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param Request $request |
|
| 240 | + */ |
|
| 241 | + protected function setupUsernameData(Request $request) |
|
| 242 | + { |
|
| 243 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 244 | + |
|
| 245 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 246 | + $this->assign('requestBlacklist', $blacklistData); |
|
| 247 | + |
|
| 248 | + try { |
|
| 249 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 250 | + } |
|
| 251 | + catch (Exception $ex) { |
|
| 252 | + $spoofs = $ex->getMessage(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $this->assign("spoofs", $spoofs); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + private function setupCreationTypes(User $user) |
|
| 259 | + { |
|
| 260 | + $this->assign('allowWelcomeSkip', false); |
|
| 261 | + $this->assign('forceWelcomeSkip', false); |
|
| 262 | + |
|
| 263 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 264 | + |
|
| 265 | + if ($user->getWelcomeTemplate() != 0) { |
|
| 266 | + $this->assign('allowWelcomeSkip', true); |
|
| 267 | + |
|
| 268 | + if (!$oauth->canWelcome()) { |
|
| 269 | + $this->assign('forceWelcomeSkip', true); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // test credentials |
|
| 274 | + $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 275 | + $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 276 | + $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
|
| 277 | + |
|
| 278 | + $this->assign('canManualCreate', $canManualCreate); |
|
| 279 | + $this->assign('canOauthCreate', $canOauthCreate); |
|
| 280 | + $this->assign('canBotCreate', $canBotCreate); |
|
| 281 | + |
|
| 282 | + // show/hide the type radio buttons |
|
| 283 | + $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 284 | + |
|
| 285 | + if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
|
| 286 | + // user is not allowed to use their default. Force a choice. |
|
| 287 | + $creationHasChoice = true; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + $this->assign('creationHasChoice', $creationHasChoice); |
|
| 291 | + |
|
| 292 | + // determine problems in creation types |
|
| 293 | + $this->assign('botProblem', false); |
|
| 294 | + if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 295 | + $this->assign('botProblem', true); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $this->assign('oauthProblem', false); |
|
| 299 | + if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 300 | + $this->assign('oauthProblem', true); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | 303 | } |
@@ -13,26 +13,26 @@ |
||
| 13 | 13 | |
| 14 | 14 | class RegenerateStylesheetsTask extends ConsoleTaskBase |
| 15 | 15 | { |
| 16 | - const RESOURCES_GENERATED = 'resources/generated'; |
|
| 16 | + const RESOURCES_GENERATED = 'resources/generated'; |
|
| 17 | 17 | |
| 18 | - public function execute() |
|
| 19 | - { |
|
| 20 | - $scss = new Compiler(); |
|
| 21 | - $scss->setImportPaths('resources/scss'); |
|
| 18 | + public function execute() |
|
| 19 | + { |
|
| 20 | + $scss = new Compiler(); |
|
| 21 | + $scss->setImportPaths('resources/scss'); |
|
| 22 | 22 | |
| 23 | - if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
| 24 | - $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
| 25 | - $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
| 26 | - } |
|
| 23 | + if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
| 24 | + $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
| 25 | + $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - if (!is_dir(self::RESOURCES_GENERATED)) { |
|
| 29 | - mkdir(self::RESOURCES_GENERATED); |
|
| 30 | - } |
|
| 28 | + if (!is_dir(self::RESOURCES_GENERATED)) { |
|
| 29 | + mkdir(self::RESOURCES_GENERATED); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - foreach (['bootstrap-main', 'bootstrap-alt', 'bootstrap-auto'] as $file) { |
|
| 33 | - file_put_contents( |
|
| 34 | - self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
| 35 | - $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
| 36 | - } |
|
| 37 | - } |
|
| 32 | + foreach (['bootstrap-main', 'bootstrap-alt', 'bootstrap-auto'] as $file) { |
|
| 33 | + file_put_contents( |
|
| 34 | + self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
| 35 | + $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | } |