@@ -17,254 +17,254 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class RequestQueue extends DataObject |
| 19 | 19 | { |
| 20 | - const DEFAULT_DEFAULT = 'default'; |
|
| 21 | - const DEFAULT_ANTISPOOF = 'antispoof'; |
|
| 22 | - const DEFAULT_TITLEBLACKLIST = 'titleblacklist'; |
|
| 23 | - |
|
| 24 | - /** @var int */ |
|
| 25 | - private $enabled = 0; |
|
| 26 | - /** @var int */ |
|
| 27 | - private $isdefault = 0; |
|
| 28 | - /** @var int */ |
|
| 29 | - private $defaultantispoof = 0; |
|
| 30 | - /** @var int */ |
|
| 31 | - private $defaulttitleblacklist = 0; |
|
| 32 | - /** @var int */ |
|
| 33 | - private $domain; |
|
| 34 | - /** @var string */ |
|
| 35 | - private $apiname; |
|
| 36 | - /** @var string */ |
|
| 37 | - private $displayname; |
|
| 38 | - /** @var string */ |
|
| 39 | - private $header; |
|
| 40 | - /** @var string|null */ |
|
| 41 | - private $help; |
|
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - * @deprecated Removal due as part of #607 |
|
| 45 | - */ |
|
| 46 | - private $logname; |
|
| 47 | - /** |
|
| 48 | - * @param PdoDatabase $database |
|
| 49 | - * |
|
| 50 | - * @return RequestQueue[] |
|
| 51 | - */ |
|
| 52 | - public static function getAllQueues(PdoDatabase $database) |
|
| 53 | - { |
|
| 54 | - $statement = $database->prepare(<<<SQL |
|
| 20 | + const DEFAULT_DEFAULT = 'default'; |
|
| 21 | + const DEFAULT_ANTISPOOF = 'antispoof'; |
|
| 22 | + const DEFAULT_TITLEBLACKLIST = 'titleblacklist'; |
|
| 23 | + |
|
| 24 | + /** @var int */ |
|
| 25 | + private $enabled = 0; |
|
| 26 | + /** @var int */ |
|
| 27 | + private $isdefault = 0; |
|
| 28 | + /** @var int */ |
|
| 29 | + private $defaultantispoof = 0; |
|
| 30 | + /** @var int */ |
|
| 31 | + private $defaulttitleblacklist = 0; |
|
| 32 | + /** @var int */ |
|
| 33 | + private $domain; |
|
| 34 | + /** @var string */ |
|
| 35 | + private $apiname; |
|
| 36 | + /** @var string */ |
|
| 37 | + private $displayname; |
|
| 38 | + /** @var string */ |
|
| 39 | + private $header; |
|
| 40 | + /** @var string|null */ |
|
| 41 | + private $help; |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + * @deprecated Removal due as part of #607 |
|
| 45 | + */ |
|
| 46 | + private $logname; |
|
| 47 | + /** |
|
| 48 | + * @param PdoDatabase $database |
|
| 49 | + * |
|
| 50 | + * @return RequestQueue[] |
|
| 51 | + */ |
|
| 52 | + public static function getAllQueues(PdoDatabase $database) |
|
| 53 | + { |
|
| 54 | + $statement = $database->prepare(<<<SQL |
|
| 55 | 55 | SELECT * FROM requestqueue; |
| 56 | 56 | SQL |
| 57 | - ); |
|
| 58 | - $statement->execute(); |
|
| 59 | - |
|
| 60 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 61 | - |
|
| 62 | - /** @var RequestQueue $t */ |
|
| 63 | - foreach ($resultObject as $t) { |
|
| 64 | - $t->setDatabase($database); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $resultObject; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param PdoDatabase $database |
|
| 72 | - * |
|
| 73 | - * @return RequestQueue[] |
|
| 74 | - */ |
|
| 75 | - public static function getEnabledQueues(PdoDatabase $database) |
|
| 76 | - { |
|
| 77 | - $statement = $database->prepare(<<<SQL |
|
| 57 | + ); |
|
| 58 | + $statement->execute(); |
|
| 59 | + |
|
| 60 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 61 | + |
|
| 62 | + /** @var RequestQueue $t */ |
|
| 63 | + foreach ($resultObject as $t) { |
|
| 64 | + $t->setDatabase($database); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $resultObject; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param PdoDatabase $database |
|
| 72 | + * |
|
| 73 | + * @return RequestQueue[] |
|
| 74 | + */ |
|
| 75 | + public static function getEnabledQueues(PdoDatabase $database) |
|
| 76 | + { |
|
| 77 | + $statement = $database->prepare(<<<SQL |
|
| 78 | 78 | SELECT * FROM requestqueue WHERE enabled = 1; |
| 79 | 79 | SQL |
| 80 | - ); |
|
| 81 | - $statement->execute(); |
|
| 82 | - |
|
| 83 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 84 | - |
|
| 85 | - /** @var RequestQueue $t */ |
|
| 86 | - foreach ($resultObject as $t) { |
|
| 87 | - $t->setDatabase($database); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $resultObject; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param PdoDatabase $database |
|
| 95 | - * @param string $apiName |
|
| 96 | - * @param int $domain |
|
| 97 | - * |
|
| 98 | - * @return false|RequestQueue |
|
| 99 | - */ |
|
| 100 | - public static function getByApiName(PdoDatabase $database, string $apiName, int $domain) |
|
| 101 | - { |
|
| 102 | - $statement = $database->prepare(<<<SQL |
|
| 80 | + ); |
|
| 81 | + $statement->execute(); |
|
| 82 | + |
|
| 83 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 84 | + |
|
| 85 | + /** @var RequestQueue $t */ |
|
| 86 | + foreach ($resultObject as $t) { |
|
| 87 | + $t->setDatabase($database); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $resultObject; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param PdoDatabase $database |
|
| 95 | + * @param string $apiName |
|
| 96 | + * @param int $domain |
|
| 97 | + * |
|
| 98 | + * @return false|RequestQueue |
|
| 99 | + */ |
|
| 100 | + public static function getByApiName(PdoDatabase $database, string $apiName, int $domain) |
|
| 101 | + { |
|
| 102 | + $statement = $database->prepare(<<<SQL |
|
| 103 | 103 | SELECT * FROM requestqueue WHERE apiname = :apiName AND domain = :domain; |
| 104 | 104 | SQL |
| 105 | - ); |
|
| 106 | - |
|
| 107 | - $statement->execute([ |
|
| 108 | - ':apiName' => $apiName, |
|
| 109 | - ':domain' => $domain, |
|
| 110 | - ]); |
|
| 111 | - |
|
| 112 | - /** @var RequestQueue|false $result */ |
|
| 113 | - $result = $statement->fetchObject(get_called_class()); |
|
| 114 | - |
|
| 115 | - if ($result !== false) { |
|
| 116 | - $result->setDatabase($database); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $result; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @param PdoDatabase $database |
|
| 124 | - * @param string $displayName |
|
| 125 | - * @param int $domain |
|
| 126 | - * |
|
| 127 | - * @return false|RequestQueue |
|
| 128 | - */ |
|
| 129 | - public static function getByDisplayName(PdoDatabase $database, string $displayName, int $domain) |
|
| 130 | - { |
|
| 131 | - $statement = $database->prepare(<<<SQL |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + $statement->execute([ |
|
| 108 | + ':apiName' => $apiName, |
|
| 109 | + ':domain' => $domain, |
|
| 110 | + ]); |
|
| 111 | + |
|
| 112 | + /** @var RequestQueue|false $result */ |
|
| 113 | + $result = $statement->fetchObject(get_called_class()); |
|
| 114 | + |
|
| 115 | + if ($result !== false) { |
|
| 116 | + $result->setDatabase($database); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $result; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @param PdoDatabase $database |
|
| 124 | + * @param string $displayName |
|
| 125 | + * @param int $domain |
|
| 126 | + * |
|
| 127 | + * @return false|RequestQueue |
|
| 128 | + */ |
|
| 129 | + public static function getByDisplayName(PdoDatabase $database, string $displayName, int $domain) |
|
| 130 | + { |
|
| 131 | + $statement = $database->prepare(<<<SQL |
|
| 132 | 132 | SELECT * FROM requestqueue WHERE displayname = :displayName AND domain = :domain; |
| 133 | 133 | SQL |
| 134 | - ); |
|
| 135 | - |
|
| 136 | - $statement->execute([ |
|
| 137 | - ':displayName' => $displayName, |
|
| 138 | - ':domain' => $domain, |
|
| 139 | - ]); |
|
| 140 | - |
|
| 141 | - /** @var RequestQueue|false $result */ |
|
| 142 | - $result = $statement->fetchObject(get_called_class()); |
|
| 143 | - |
|
| 144 | - if ($result !== false) { |
|
| 145 | - $result->setDatabase($database); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $result; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param PdoDatabase $database |
|
| 153 | - * @param string $header |
|
| 154 | - * @param int $domain |
|
| 155 | - * |
|
| 156 | - * @return false|RequestQueue |
|
| 157 | - */ |
|
| 158 | - public static function getByHeader(PdoDatabase $database, string $header, int $domain) |
|
| 159 | - { |
|
| 160 | - $statement = $database->prepare(<<<SQL |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + $statement->execute([ |
|
| 137 | + ':displayName' => $displayName, |
|
| 138 | + ':domain' => $domain, |
|
| 139 | + ]); |
|
| 140 | + |
|
| 141 | + /** @var RequestQueue|false $result */ |
|
| 142 | + $result = $statement->fetchObject(get_called_class()); |
|
| 143 | + |
|
| 144 | + if ($result !== false) { |
|
| 145 | + $result->setDatabase($database); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $result; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param PdoDatabase $database |
|
| 153 | + * @param string $header |
|
| 154 | + * @param int $domain |
|
| 155 | + * |
|
| 156 | + * @return false|RequestQueue |
|
| 157 | + */ |
|
| 158 | + public static function getByHeader(PdoDatabase $database, string $header, int $domain) |
|
| 159 | + { |
|
| 160 | + $statement = $database->prepare(<<<SQL |
|
| 161 | 161 | SELECT * FROM requestqueue WHERE header = :header AND domain = :domain; |
| 162 | 162 | SQL |
| 163 | - ); |
|
| 164 | - |
|
| 165 | - $statement->execute([ |
|
| 166 | - ':header' => $header, |
|
| 167 | - ':domain' => $domain, |
|
| 168 | - ]); |
|
| 169 | - |
|
| 170 | - /** @var RequestQueue|false $result */ |
|
| 171 | - $result = $statement->fetchObject(get_called_class()); |
|
| 172 | - |
|
| 173 | - if ($result !== false) { |
|
| 174 | - $result->setDatabase($database); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $result; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param PdoDatabase $database |
|
| 182 | - * @param int $domain |
|
| 183 | - * |
|
| 184 | - * @param string $defaultType The type of default queue to get. |
|
| 185 | - * |
|
| 186 | - * @return false|RequestQueue |
|
| 187 | - * @throws ApplicationLogicException |
|
| 188 | - */ |
|
| 189 | - public static function getDefaultQueue(PdoDatabase $database, int $domain, string $defaultType = 'default') |
|
| 190 | - { |
|
| 191 | - switch ($defaultType) { |
|
| 192 | - case self::DEFAULT_DEFAULT: |
|
| 193 | - $sql = 'SELECT * FROM requestqueue WHERE isdefault = 1 AND domain = :domain;'; |
|
| 194 | - break; |
|
| 195 | - case self::DEFAULT_ANTISPOOF: |
|
| 196 | - $sql = 'SELECT * FROM requestqueue WHERE defaultantispoof = 1 AND domain = :domain;'; |
|
| 197 | - break; |
|
| 198 | - case self::DEFAULT_TITLEBLACKLIST: |
|
| 199 | - $sql = 'SELECT * FROM requestqueue WHERE defaulttitleblacklist = 1 AND domain = :domain;'; |
|
| 200 | - break; |
|
| 201 | - default: |
|
| 202 | - throw new ApplicationLogicException('Unknown request for default queue'); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $statement = $database->prepare($sql); |
|
| 206 | - |
|
| 207 | - $statement->execute([':domain' => $domain]); |
|
| 208 | - |
|
| 209 | - /** @var RequestQueue|false $result */ |
|
| 210 | - $result = $statement->fetchObject(get_called_class()); |
|
| 211 | - |
|
| 212 | - if ($result !== false) { |
|
| 213 | - $result->setDatabase($database); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return $result; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - public function save() |
|
| 220 | - { |
|
| 221 | - // find and squish existing defaults |
|
| 222 | - if ($this->isDefault()) { |
|
| 223 | - $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET isdefault = 0 WHERE isdefault = 1 AND domain = :domain;'); |
|
| 224 | - $squishStatement->execute([':domain' => $this->domain]); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if ($this->isDefaultAntispoof()) { |
|
| 228 | - $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaultantispoof = 0 WHERE defaultantispoof = 1 AND domain = :domain;'); |
|
| 229 | - $squishStatement->execute([':domain' => $this->domain]); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if ($this->isDefaultTitleBlacklist()) { |
|
| 233 | - $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaulttitleblacklist = 0 WHERE defaulttitleblacklist = 1 AND domain = :domain;'); |
|
| 234 | - $squishStatement->execute([':domain' => $this->domain]); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if ($this->isNew()) { |
|
| 238 | - // insert |
|
| 239 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + $statement->execute([ |
|
| 166 | + ':header' => $header, |
|
| 167 | + ':domain' => $domain, |
|
| 168 | + ]); |
|
| 169 | + |
|
| 170 | + /** @var RequestQueue|false $result */ |
|
| 171 | + $result = $statement->fetchObject(get_called_class()); |
|
| 172 | + |
|
| 173 | + if ($result !== false) { |
|
| 174 | + $result->setDatabase($database); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $result; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param PdoDatabase $database |
|
| 182 | + * @param int $domain |
|
| 183 | + * |
|
| 184 | + * @param string $defaultType The type of default queue to get. |
|
| 185 | + * |
|
| 186 | + * @return false|RequestQueue |
|
| 187 | + * @throws ApplicationLogicException |
|
| 188 | + */ |
|
| 189 | + public static function getDefaultQueue(PdoDatabase $database, int $domain, string $defaultType = 'default') |
|
| 190 | + { |
|
| 191 | + switch ($defaultType) { |
|
| 192 | + case self::DEFAULT_DEFAULT: |
|
| 193 | + $sql = 'SELECT * FROM requestqueue WHERE isdefault = 1 AND domain = :domain;'; |
|
| 194 | + break; |
|
| 195 | + case self::DEFAULT_ANTISPOOF: |
|
| 196 | + $sql = 'SELECT * FROM requestqueue WHERE defaultantispoof = 1 AND domain = :domain;'; |
|
| 197 | + break; |
|
| 198 | + case self::DEFAULT_TITLEBLACKLIST: |
|
| 199 | + $sql = 'SELECT * FROM requestqueue WHERE defaulttitleblacklist = 1 AND domain = :domain;'; |
|
| 200 | + break; |
|
| 201 | + default: |
|
| 202 | + throw new ApplicationLogicException('Unknown request for default queue'); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $statement = $database->prepare($sql); |
|
| 206 | + |
|
| 207 | + $statement->execute([':domain' => $domain]); |
|
| 208 | + |
|
| 209 | + /** @var RequestQueue|false $result */ |
|
| 210 | + $result = $statement->fetchObject(get_called_class()); |
|
| 211 | + |
|
| 212 | + if ($result !== false) { |
|
| 213 | + $result->setDatabase($database); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return $result; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public function save() |
|
| 220 | + { |
|
| 221 | + // find and squish existing defaults |
|
| 222 | + if ($this->isDefault()) { |
|
| 223 | + $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET isdefault = 0 WHERE isdefault = 1 AND domain = :domain;'); |
|
| 224 | + $squishStatement->execute([':domain' => $this->domain]); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if ($this->isDefaultAntispoof()) { |
|
| 228 | + $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaultantispoof = 0 WHERE defaultantispoof = 1 AND domain = :domain;'); |
|
| 229 | + $squishStatement->execute([':domain' => $this->domain]); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if ($this->isDefaultTitleBlacklist()) { |
|
| 233 | + $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaulttitleblacklist = 0 WHERE defaulttitleblacklist = 1 AND domain = :domain;'); |
|
| 234 | + $squishStatement->execute([':domain' => $this->domain]); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if ($this->isNew()) { |
|
| 238 | + // insert |
|
| 239 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 240 | 240 | INSERT INTO requestqueue ( |
| 241 | 241 | enabled, isdefault, defaultantispoof, defaulttitleblacklist, domain, apiname, displayname, header, help, logname |
| 242 | 242 | ) VALUES ( |
| 243 | 243 | :enabled, :isdefault, :defaultantispoof, :defaulttitleblacklist, :domain, :apiname, :displayname, :header, :help, :logname |
| 244 | 244 | ); |
| 245 | 245 | SQL |
| 246 | - ); |
|
| 247 | - |
|
| 248 | - $statement->bindValue(":enabled", $this->enabled); |
|
| 249 | - $statement->bindValue(":isdefault", $this->isdefault); |
|
| 250 | - $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
| 251 | - $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
| 252 | - $statement->bindValue(":domain", $this->domain); |
|
| 253 | - $statement->bindValue(":apiname", $this->apiname); |
|
| 254 | - $statement->bindValue(":displayname", $this->displayname); |
|
| 255 | - $statement->bindValue(":header", $this->header); |
|
| 256 | - $statement->bindValue(":help", $this->help); |
|
| 257 | - $statement->bindValue(":logname", $this->logname); |
|
| 258 | - |
|
| 259 | - if ($statement->execute()) { |
|
| 260 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 261 | - } |
|
| 262 | - else { |
|
| 263 | - throw new Exception($statement->errorInfo()); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - else { |
|
| 267 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + $statement->bindValue(":enabled", $this->enabled); |
|
| 249 | + $statement->bindValue(":isdefault", $this->isdefault); |
|
| 250 | + $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
| 251 | + $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
| 252 | + $statement->bindValue(":domain", $this->domain); |
|
| 253 | + $statement->bindValue(":apiname", $this->apiname); |
|
| 254 | + $statement->bindValue(":displayname", $this->displayname); |
|
| 255 | + $statement->bindValue(":header", $this->header); |
|
| 256 | + $statement->bindValue(":help", $this->help); |
|
| 257 | + $statement->bindValue(":logname", $this->logname); |
|
| 258 | + |
|
| 259 | + if ($statement->execute()) { |
|
| 260 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 261 | + } |
|
| 262 | + else { |
|
| 263 | + throw new Exception($statement->errorInfo()); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + else { |
|
| 267 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 268 | 268 | UPDATE requestqueue SET |
| 269 | 269 | enabled = :enabled, |
| 270 | 270 | isdefault = :isdefault, |
@@ -280,194 +280,194 @@ discard block |
||
| 280 | 280 | updateversion = updateversion + 1 |
| 281 | 281 | WHERE id = :id AND updateversion = :updateversion; |
| 282 | 282 | SQL |
| 283 | - ); |
|
| 284 | - |
|
| 285 | - $statement->bindValue(":enabled", $this->enabled); |
|
| 286 | - $statement->bindValue(":isdefault", $this->isdefault); |
|
| 287 | - $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
| 288 | - $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
| 289 | - $statement->bindValue(":domain", $this->domain); |
|
| 290 | - $statement->bindValue(":apiname", $this->apiname); |
|
| 291 | - $statement->bindValue(":displayname", $this->displayname); |
|
| 292 | - $statement->bindValue(":header", $this->header); |
|
| 293 | - $statement->bindValue(":help", $this->help); |
|
| 294 | - $statement->bindValue(":logname", $this->logname); |
|
| 295 | - |
|
| 296 | - $statement->bindValue(':id', $this->id); |
|
| 297 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 298 | - |
|
| 299 | - if (!$statement->execute()) { |
|
| 300 | - throw new Exception($statement->errorInfo()); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - if ($statement->rowCount() !== 1) { |
|
| 304 | - throw new OptimisticLockFailedException(); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $this->updateversion++; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @return bool |
|
| 313 | - */ |
|
| 314 | - public function isEnabled(): bool |
|
| 315 | - { |
|
| 316 | - return $this->enabled == 1; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @param bool $enabled |
|
| 321 | - */ |
|
| 322 | - public function setEnabled(bool $enabled): void |
|
| 323 | - { |
|
| 324 | - $this->enabled = $enabled ? 1 : 0; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function isDefault(): bool |
|
| 331 | - { |
|
| 332 | - return $this->isdefault == 1; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param bool $isDefault |
|
| 337 | - */ |
|
| 338 | - public function setDefault(bool $isDefault): void |
|
| 339 | - { |
|
| 340 | - $this->isdefault = $isDefault ? 1 : 0; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @return bool |
|
| 345 | - */ |
|
| 346 | - public function isDefaultAntispoof(): bool |
|
| 347 | - { |
|
| 348 | - return $this->defaultantispoof == 1; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @param bool $isDefault |
|
| 353 | - */ |
|
| 354 | - public function setDefaultAntispoof(bool $isDefault): void |
|
| 355 | - { |
|
| 356 | - $this->defaultantispoof = $isDefault ? 1 : 0; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * @return bool |
|
| 361 | - */ |
|
| 362 | - public function isDefaultTitleBlacklist(): bool |
|
| 363 | - { |
|
| 364 | - return $this->defaulttitleblacklist == 1; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @param bool $isDefault |
|
| 369 | - */ |
|
| 370 | - public function setDefaultTitleBlacklist(bool $isDefault): void |
|
| 371 | - { |
|
| 372 | - $this->defaulttitleblacklist = $isDefault ? 1 : 0; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @return int |
|
| 377 | - */ |
|
| 378 | - public function getDomain(): int |
|
| 379 | - { |
|
| 380 | - return $this->domain; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @param int $domain |
|
| 385 | - */ |
|
| 386 | - public function setDomain(int $domain): void |
|
| 387 | - { |
|
| 388 | - $this->domain = $domain; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - public function getApiName(): string |
|
| 395 | - { |
|
| 396 | - return $this->apiname; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * @param string $apiName |
|
| 401 | - */ |
|
| 402 | - public function setApiName(string $apiName): void |
|
| 403 | - { |
|
| 404 | - $this->apiname = $apiName; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public function getDisplayName(): string |
|
| 411 | - { |
|
| 412 | - return $this->displayname; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param string $displayName |
|
| 417 | - */ |
|
| 418 | - public function setDisplayName(string $displayName): void |
|
| 419 | - { |
|
| 420 | - $this->displayname = $displayName; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @return string |
|
| 425 | - */ |
|
| 426 | - public function getHeader(): string |
|
| 427 | - { |
|
| 428 | - return $this->header; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * @param string $header |
|
| 433 | - */ |
|
| 434 | - public function setHeader(string $header): void |
|
| 435 | - { |
|
| 436 | - $this->header = $header; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @return string|null |
|
| 441 | - */ |
|
| 442 | - public function getHelp(): ?string |
|
| 443 | - { |
|
| 444 | - return $this->help; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * @param string|null $help |
|
| 449 | - */ |
|
| 450 | - public function setHelp(?string $help): void |
|
| 451 | - { |
|
| 452 | - $this->help = $help; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @return string |
|
| 457 | - * @deprecated |
|
| 458 | - */ |
|
| 459 | - public function getLogName(): string |
|
| 460 | - { |
|
| 461 | - return $this->logname; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * @param string $logName |
|
| 466 | - * |
|
| 467 | - * @deprecated |
|
| 468 | - */ |
|
| 469 | - public function setLogName(string $logName): void |
|
| 470 | - { |
|
| 471 | - $this->logname = $logName; |
|
| 472 | - } |
|
| 283 | + ); |
|
| 284 | + |
|
| 285 | + $statement->bindValue(":enabled", $this->enabled); |
|
| 286 | + $statement->bindValue(":isdefault", $this->isdefault); |
|
| 287 | + $statement->bindValue(":defaultantispoof", $this->defaultantispoof); |
|
| 288 | + $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist); |
|
| 289 | + $statement->bindValue(":domain", $this->domain); |
|
| 290 | + $statement->bindValue(":apiname", $this->apiname); |
|
| 291 | + $statement->bindValue(":displayname", $this->displayname); |
|
| 292 | + $statement->bindValue(":header", $this->header); |
|
| 293 | + $statement->bindValue(":help", $this->help); |
|
| 294 | + $statement->bindValue(":logname", $this->logname); |
|
| 295 | + |
|
| 296 | + $statement->bindValue(':id', $this->id); |
|
| 297 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 298 | + |
|
| 299 | + if (!$statement->execute()) { |
|
| 300 | + throw new Exception($statement->errorInfo()); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + if ($statement->rowCount() !== 1) { |
|
| 304 | + throw new OptimisticLockFailedException(); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $this->updateversion++; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @return bool |
|
| 313 | + */ |
|
| 314 | + public function isEnabled(): bool |
|
| 315 | + { |
|
| 316 | + return $this->enabled == 1; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @param bool $enabled |
|
| 321 | + */ |
|
| 322 | + public function setEnabled(bool $enabled): void |
|
| 323 | + { |
|
| 324 | + $this->enabled = $enabled ? 1 : 0; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function isDefault(): bool |
|
| 331 | + { |
|
| 332 | + return $this->isdefault == 1; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param bool $isDefault |
|
| 337 | + */ |
|
| 338 | + public function setDefault(bool $isDefault): void |
|
| 339 | + { |
|
| 340 | + $this->isdefault = $isDefault ? 1 : 0; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @return bool |
|
| 345 | + */ |
|
| 346 | + public function isDefaultAntispoof(): bool |
|
| 347 | + { |
|
| 348 | + return $this->defaultantispoof == 1; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @param bool $isDefault |
|
| 353 | + */ |
|
| 354 | + public function setDefaultAntispoof(bool $isDefault): void |
|
| 355 | + { |
|
| 356 | + $this->defaultantispoof = $isDefault ? 1 : 0; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * @return bool |
|
| 361 | + */ |
|
| 362 | + public function isDefaultTitleBlacklist(): bool |
|
| 363 | + { |
|
| 364 | + return $this->defaulttitleblacklist == 1; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @param bool $isDefault |
|
| 369 | + */ |
|
| 370 | + public function setDefaultTitleBlacklist(bool $isDefault): void |
|
| 371 | + { |
|
| 372 | + $this->defaulttitleblacklist = $isDefault ? 1 : 0; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @return int |
|
| 377 | + */ |
|
| 378 | + public function getDomain(): int |
|
| 379 | + { |
|
| 380 | + return $this->domain; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @param int $domain |
|
| 385 | + */ |
|
| 386 | + public function setDomain(int $domain): void |
|
| 387 | + { |
|
| 388 | + $this->domain = $domain; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + public function getApiName(): string |
|
| 395 | + { |
|
| 396 | + return $this->apiname; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * @param string $apiName |
|
| 401 | + */ |
|
| 402 | + public function setApiName(string $apiName): void |
|
| 403 | + { |
|
| 404 | + $this->apiname = $apiName; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public function getDisplayName(): string |
|
| 411 | + { |
|
| 412 | + return $this->displayname; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param string $displayName |
|
| 417 | + */ |
|
| 418 | + public function setDisplayName(string $displayName): void |
|
| 419 | + { |
|
| 420 | + $this->displayname = $displayName; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @return string |
|
| 425 | + */ |
|
| 426 | + public function getHeader(): string |
|
| 427 | + { |
|
| 428 | + return $this->header; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * @param string $header |
|
| 433 | + */ |
|
| 434 | + public function setHeader(string $header): void |
|
| 435 | + { |
|
| 436 | + $this->header = $header; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @return string|null |
|
| 441 | + */ |
|
| 442 | + public function getHelp(): ?string |
|
| 443 | + { |
|
| 444 | + return $this->help; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @param string|null $help |
|
| 449 | + */ |
|
| 450 | + public function setHelp(?string $help): void |
|
| 451 | + { |
|
| 452 | + $this->help = $help; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @return string |
|
| 457 | + * @deprecated |
|
| 458 | + */ |
|
| 459 | + public function getLogName(): string |
|
| 460 | + { |
|
| 461 | + return $this->logname; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * @param string $logName |
|
| 466 | + * |
|
| 467 | + * @deprecated |
|
| 468 | + */ |
|
| 469 | + public function setLogName(string $logName): void |
|
| 470 | + { |
|
| 471 | + $this->logname = $logName; |
|
| 472 | + } |
|
| 473 | 473 | } |
| 474 | 474 | \ No newline at end of file |
@@ -258,12 +258,10 @@ |
||
| 258 | 258 | |
| 259 | 259 | if ($statement->execute()) { |
| 260 | 260 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 261 | - } |
|
| 262 | - else { |
|
| 261 | + } else { |
|
| 263 | 262 | throw new Exception($statement->errorInfo()); |
| 264 | 263 | } |
| 265 | - } |
|
| 266 | - else { |
|
| 264 | + } else { |
|
| 267 | 265 | $statement = $this->dbObject->prepare(<<<SQL |
| 268 | 266 | UPDATE requestqueue SET |
| 269 | 267 | enabled = :enabled, |
@@ -17,92 +17,92 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class Domain extends DataObject |
| 19 | 19 | { |
| 20 | - /** @var string */ |
|
| 21 | - private $shortname; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $longname; |
|
| 24 | - /** @var string */ |
|
| 25 | - private $wikiarticlepath; |
|
| 26 | - /** @var string */ |
|
| 27 | - private $wikiapipath; |
|
| 28 | - /** @var int */ |
|
| 29 | - private $enabled = 0; |
|
| 30 | - /** @var int|null */ |
|
| 31 | - private $defaultclose; |
|
| 32 | - /** @var string */ |
|
| 33 | - private $defaultlanguage = 'en'; |
|
| 34 | - /** @var string */ |
|
| 35 | - private $emailreplyaddress; |
|
| 36 | - /** @var string|null */ |
|
| 37 | - private $notificationtarget; |
|
| 38 | - /** @var string */ |
|
| 39 | - private $localdocumentation; |
|
| 40 | - |
|
| 41 | - /** @var Domain Cache variable of the current domain */ |
|
| 42 | - private static $currentDomain; |
|
| 43 | - |
|
| 44 | - public static function getCurrent(PdoDatabase $database) |
|
| 45 | - { |
|
| 46 | - if (self::$currentDomain === null) { |
|
| 47 | - $sessionDomain = WebRequest::getSessionDomain(); |
|
| 48 | - |
|
| 49 | - if ($sessionDomain !== null) { |
|
| 50 | - /** @var Domain $domain */ |
|
| 51 | - $domain = self::getById($sessionDomain, $database); |
|
| 52 | - |
|
| 53 | - if ($domain === false) { |
|
| 54 | - self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
| 55 | - } |
|
| 56 | - else { |
|
| 57 | - self::$currentDomain = $domain; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - else { |
|
| 61 | - self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return self::$currentDomain; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public static function getByShortName(string $shortName, PdoDatabase $database) |
|
| 69 | - { |
|
| 70 | - $statement = $database->prepare(<<<SQL |
|
| 20 | + /** @var string */ |
|
| 21 | + private $shortname; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $longname; |
|
| 24 | + /** @var string */ |
|
| 25 | + private $wikiarticlepath; |
|
| 26 | + /** @var string */ |
|
| 27 | + private $wikiapipath; |
|
| 28 | + /** @var int */ |
|
| 29 | + private $enabled = 0; |
|
| 30 | + /** @var int|null */ |
|
| 31 | + private $defaultclose; |
|
| 32 | + /** @var string */ |
|
| 33 | + private $defaultlanguage = 'en'; |
|
| 34 | + /** @var string */ |
|
| 35 | + private $emailreplyaddress; |
|
| 36 | + /** @var string|null */ |
|
| 37 | + private $notificationtarget; |
|
| 38 | + /** @var string */ |
|
| 39 | + private $localdocumentation; |
|
| 40 | + |
|
| 41 | + /** @var Domain Cache variable of the current domain */ |
|
| 42 | + private static $currentDomain; |
|
| 43 | + |
|
| 44 | + public static function getCurrent(PdoDatabase $database) |
|
| 45 | + { |
|
| 46 | + if (self::$currentDomain === null) { |
|
| 47 | + $sessionDomain = WebRequest::getSessionDomain(); |
|
| 48 | + |
|
| 49 | + if ($sessionDomain !== null) { |
|
| 50 | + /** @var Domain $domain */ |
|
| 51 | + $domain = self::getById($sessionDomain, $database); |
|
| 52 | + |
|
| 53 | + if ($domain === false) { |
|
| 54 | + self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
| 55 | + } |
|
| 56 | + else { |
|
| 57 | + self::$currentDomain = $domain; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + else { |
|
| 61 | + self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return self::$currentDomain; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public static function getByShortName(string $shortName, PdoDatabase $database) |
|
| 69 | + { |
|
| 70 | + $statement = $database->prepare(<<<SQL |
|
| 71 | 71 | SELECT * FROM domain WHERE shortname = :name; |
| 72 | 72 | SQL |
| 73 | - ); |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - $statement->execute([ |
|
| 76 | - ':name' => $shortName, |
|
| 77 | - ]); |
|
| 75 | + $statement->execute([ |
|
| 76 | + ':name' => $shortName, |
|
| 77 | + ]); |
|
| 78 | 78 | |
| 79 | - /** @var RequestForm|false $result */ |
|
| 80 | - $result = $statement->fetchObject(get_called_class()); |
|
| 79 | + /** @var RequestForm|false $result */ |
|
| 80 | + $result = $statement->fetchObject(get_called_class()); |
|
| 81 | 81 | |
| 82 | - if ($result !== false) { |
|
| 83 | - $result->setDatabase($database); |
|
| 84 | - } |
|
| 82 | + if ($result !== false) { |
|
| 83 | + $result->setDatabase($database); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $result; |
|
| 87 | - } |
|
| 86 | + return $result; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public static function getAll(PdoDatabase $database) { |
|
| 90 | - $statement = $database->prepare("SELECT * FROM domain;"); |
|
| 91 | - $statement->execute(); |
|
| 89 | + public static function getAll(PdoDatabase $database) { |
|
| 90 | + $statement = $database->prepare("SELECT * FROM domain;"); |
|
| 91 | + $statement->execute(); |
|
| 92 | 92 | |
| 93 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 93 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 94 | 94 | |
| 95 | - /** @var Domain $t */ |
|
| 96 | - foreach ($resultObject as $t) { |
|
| 97 | - $t->setDatabase($database); |
|
| 98 | - } |
|
| 95 | + /** @var Domain $t */ |
|
| 96 | + foreach ($resultObject as $t) { |
|
| 97 | + $t->setDatabase($database); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return $resultObject; |
|
| 101 | - } |
|
| 100 | + return $resultObject; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - public static function getDomainByUser(PdoDatabase $database, User $user, ?bool $enabled = null) |
|
| 104 | - { |
|
| 105 | - $statement = $database->prepare(<<<'SQL' |
|
| 103 | + public static function getDomainByUser(PdoDatabase $database, User $user, ?bool $enabled = null) |
|
| 104 | + { |
|
| 105 | + $statement = $database->prepare(<<<'SQL' |
|
| 106 | 106 | SELECT d.* |
| 107 | 107 | FROM domain d |
| 108 | 108 | INNER JOIN userdomain ud on d.id = ud.domain |
@@ -110,27 +110,27 @@ discard block |
||
| 110 | 110 | AND (:filterEnabled = 0 OR d.enabled = :enabled) |
| 111 | 111 | SQL |
| 112 | 112 | ); |
| 113 | - $statement->execute([ |
|
| 114 | - ':user' => $user->getId(), |
|
| 115 | - ':filterEnabled' => ($enabled === null) ? 0 : 1, |
|
| 116 | - ':enabled' => ($enabled) ? 1 : 0 |
|
| 117 | - ]); |
|
| 118 | - |
|
| 119 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 120 | - |
|
| 121 | - /** @var Domain $t */ |
|
| 122 | - foreach ($resultObject as $t) { |
|
| 123 | - $t->setDatabase($database); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $resultObject; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function save() |
|
| 130 | - { |
|
| 131 | - if ($this->isNew()) { |
|
| 132 | - // insert |
|
| 133 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 113 | + $statement->execute([ |
|
| 114 | + ':user' => $user->getId(), |
|
| 115 | + ':filterEnabled' => ($enabled === null) ? 0 : 1, |
|
| 116 | + ':enabled' => ($enabled) ? 1 : 0 |
|
| 117 | + ]); |
|
| 118 | + |
|
| 119 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
| 120 | + |
|
| 121 | + /** @var Domain $t */ |
|
| 122 | + foreach ($resultObject as $t) { |
|
| 123 | + $t->setDatabase($database); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $resultObject; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function save() |
|
| 130 | + { |
|
| 131 | + if ($this->isNew()) { |
|
| 132 | + // insert |
|
| 133 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 134 | 134 | INSERT INTO domain ( |
| 135 | 135 | shortname, longname, wikiarticlepath, wikiapipath, enabled, defaultclose, defaultlanguage, |
| 136 | 136 | emailreplyaddress, notificationtarget, localdocumentation |
@@ -139,29 +139,29 @@ discard block |
||
| 139 | 139 | :emailreplyaddress, :notificationtarget, :localdocumentation |
| 140 | 140 | ); |
| 141 | 141 | SQL |
| 142 | - ); |
|
| 143 | - |
|
| 144 | - $statement->bindValue(":shortname", $this->shortname); |
|
| 145 | - $statement->bindValue(":longname", $this->longname); |
|
| 146 | - $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
| 147 | - $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
| 148 | - $statement->bindValue(":enabled", $this->enabled); |
|
| 149 | - $statement->bindValue(":defaultclose", $this->defaultclose); |
|
| 150 | - $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
| 151 | - $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
| 152 | - $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
| 153 | - $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - if ($statement->execute()) { |
|
| 157 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 158 | - } |
|
| 159 | - else { |
|
| 160 | - throw new Exception($statement->errorInfo()); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - else { |
|
| 164 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + $statement->bindValue(":shortname", $this->shortname); |
|
| 145 | + $statement->bindValue(":longname", $this->longname); |
|
| 146 | + $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
| 147 | + $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
| 148 | + $statement->bindValue(":enabled", $this->enabled); |
|
| 149 | + $statement->bindValue(":defaultclose", $this->defaultclose); |
|
| 150 | + $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
| 151 | + $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
| 152 | + $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
| 153 | + $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + if ($statement->execute()) { |
|
| 157 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 158 | + } |
|
| 159 | + else { |
|
| 160 | + throw new Exception($statement->errorInfo()); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + else { |
|
| 164 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 165 | 165 | UPDATE domain SET |
| 166 | 166 | longname = :longname, |
| 167 | 167 | wikiarticlepath = :wikiarticlepath, |
@@ -176,190 +176,190 @@ discard block |
||
| 176 | 176 | updateversion = updateversion + 1 |
| 177 | 177 | WHERE id = :id AND updateversion = :updateversion; |
| 178 | 178 | SQL |
| 179 | - ); |
|
| 180 | - |
|
| 181 | - $statement->bindValue(":longname", $this->longname); |
|
| 182 | - $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
| 183 | - $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
| 184 | - $statement->bindValue(":enabled", $this->enabled); |
|
| 185 | - $statement->bindValue(":defaultclose", $this->defaultclose); |
|
| 186 | - $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
| 187 | - $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
| 188 | - $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
| 189 | - $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
| 190 | - |
|
| 191 | - $statement->bindValue(':id', $this->id); |
|
| 192 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 193 | - |
|
| 194 | - if (!$statement->execute()) { |
|
| 195 | - throw new Exception($statement->errorInfo()); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($statement->rowCount() !== 1) { |
|
| 199 | - throw new OptimisticLockFailedException(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $this->updateversion++; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public function getShortName(): string |
|
| 210 | - { |
|
| 211 | - return $this->shortname; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param string $shortName |
|
| 216 | - */ |
|
| 217 | - public function setShortName(string $shortName): void |
|
| 218 | - { |
|
| 219 | - $this->shortname = $shortName; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public function getLongName(): string |
|
| 226 | - { |
|
| 227 | - return $this->longname; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @param string $longName |
|
| 232 | - */ |
|
| 233 | - public function setLongName(string $longName): void |
|
| 234 | - { |
|
| 235 | - $this->longname = $longName; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public function getWikiArticlePath(): string |
|
| 242 | - { |
|
| 243 | - return $this->wikiarticlepath; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param string $wikiArticlePath |
|
| 248 | - */ |
|
| 249 | - public function setWikiArticlePath(string $wikiArticlePath): void |
|
| 250 | - { |
|
| 251 | - $this->wikiarticlepath = $wikiArticlePath; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function getWikiApiPath(): string |
|
| 258 | - { |
|
| 259 | - return $this->wikiapipath; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param string $wikiApiPath |
|
| 264 | - */ |
|
| 265 | - public function setWikiApiPath(string $wikiApiPath): void |
|
| 266 | - { |
|
| 267 | - $this->wikiapipath = $wikiApiPath; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @return bool |
|
| 272 | - */ |
|
| 273 | - public function isEnabled(): bool |
|
| 274 | - { |
|
| 275 | - return $this->enabled == 1; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @param bool $enabled |
|
| 280 | - */ |
|
| 281 | - public function setEnabled(bool $enabled): void |
|
| 282 | - { |
|
| 283 | - $this->enabled = $enabled ? 1 : 0; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @return int |
|
| 288 | - */ |
|
| 289 | - public function getDefaultClose(): ?int |
|
| 290 | - { |
|
| 291 | - return $this->defaultclose; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param int $defaultClose |
|
| 296 | - */ |
|
| 297 | - public function setDefaultClose(?int $defaultClose): void |
|
| 298 | - { |
|
| 299 | - $this->defaultclose = $defaultClose; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - public function getDefaultLanguage(): string |
|
| 306 | - { |
|
| 307 | - return $this->defaultlanguage; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param string $defaultLanguage |
|
| 312 | - */ |
|
| 313 | - public function setDefaultLanguage(string $defaultLanguage): void |
|
| 314 | - { |
|
| 315 | - $this->defaultlanguage = $defaultLanguage; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @return string |
|
| 320 | - */ |
|
| 321 | - public function getEmailReplyAddress(): string |
|
| 322 | - { |
|
| 323 | - return $this->emailreplyaddress; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param string $emailReplyAddress |
|
| 328 | - */ |
|
| 329 | - public function setEmailReplyAddress(string $emailReplyAddress): void |
|
| 330 | - { |
|
| 331 | - $this->emailreplyaddress = $emailReplyAddress; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * @return string|null |
|
| 336 | - */ |
|
| 337 | - public function getNotificationTarget(): ?string |
|
| 338 | - { |
|
| 339 | - return $this->notificationtarget; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @param string|null $notificationTarget |
|
| 344 | - */ |
|
| 345 | - public function setNotificationTarget(?string $notificationTarget): void |
|
| 346 | - { |
|
| 347 | - $this->notificationtarget = $notificationTarget; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - public function getLocalDocumentation(): string |
|
| 354 | - { |
|
| 355 | - return $this->localdocumentation; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @param string $localDocumentation |
|
| 360 | - */ |
|
| 361 | - public function setLocalDocumentation(string $localDocumentation): void |
|
| 362 | - { |
|
| 363 | - $this->localdocumentation = $localDocumentation; |
|
| 364 | - } |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + $statement->bindValue(":longname", $this->longname); |
|
| 182 | + $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
|
| 183 | + $statement->bindValue(":wikiapipath", $this->wikiapipath); |
|
| 184 | + $statement->bindValue(":enabled", $this->enabled); |
|
| 185 | + $statement->bindValue(":defaultclose", $this->defaultclose); |
|
| 186 | + $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
|
| 187 | + $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
|
| 188 | + $statement->bindValue(":notificationtarget", $this->notificationtarget); |
|
| 189 | + $statement->bindValue(":localdocumentation", $this->localdocumentation); |
|
| 190 | + |
|
| 191 | + $statement->bindValue(':id', $this->id); |
|
| 192 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 193 | + |
|
| 194 | + if (!$statement->execute()) { |
|
| 195 | + throw new Exception($statement->errorInfo()); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($statement->rowCount() !== 1) { |
|
| 199 | + throw new OptimisticLockFailedException(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $this->updateversion++; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public function getShortName(): string |
|
| 210 | + { |
|
| 211 | + return $this->shortname; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param string $shortName |
|
| 216 | + */ |
|
| 217 | + public function setShortName(string $shortName): void |
|
| 218 | + { |
|
| 219 | + $this->shortname = $shortName; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public function getLongName(): string |
|
| 226 | + { |
|
| 227 | + return $this->longname; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @param string $longName |
|
| 232 | + */ |
|
| 233 | + public function setLongName(string $longName): void |
|
| 234 | + { |
|
| 235 | + $this->longname = $longName; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public function getWikiArticlePath(): string |
|
| 242 | + { |
|
| 243 | + return $this->wikiarticlepath; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param string $wikiArticlePath |
|
| 248 | + */ |
|
| 249 | + public function setWikiArticlePath(string $wikiArticlePath): void |
|
| 250 | + { |
|
| 251 | + $this->wikiarticlepath = $wikiArticlePath; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function getWikiApiPath(): string |
|
| 258 | + { |
|
| 259 | + return $this->wikiapipath; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param string $wikiApiPath |
|
| 264 | + */ |
|
| 265 | + public function setWikiApiPath(string $wikiApiPath): void |
|
| 266 | + { |
|
| 267 | + $this->wikiapipath = $wikiApiPath; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @return bool |
|
| 272 | + */ |
|
| 273 | + public function isEnabled(): bool |
|
| 274 | + { |
|
| 275 | + return $this->enabled == 1; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @param bool $enabled |
|
| 280 | + */ |
|
| 281 | + public function setEnabled(bool $enabled): void |
|
| 282 | + { |
|
| 283 | + $this->enabled = $enabled ? 1 : 0; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @return int |
|
| 288 | + */ |
|
| 289 | + public function getDefaultClose(): ?int |
|
| 290 | + { |
|
| 291 | + return $this->defaultclose; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param int $defaultClose |
|
| 296 | + */ |
|
| 297 | + public function setDefaultClose(?int $defaultClose): void |
|
| 298 | + { |
|
| 299 | + $this->defaultclose = $defaultClose; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | + public function getDefaultLanguage(): string |
|
| 306 | + { |
|
| 307 | + return $this->defaultlanguage; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param string $defaultLanguage |
|
| 312 | + */ |
|
| 313 | + public function setDefaultLanguage(string $defaultLanguage): void |
|
| 314 | + { |
|
| 315 | + $this->defaultlanguage = $defaultLanguage; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @return string |
|
| 320 | + */ |
|
| 321 | + public function getEmailReplyAddress(): string |
|
| 322 | + { |
|
| 323 | + return $this->emailreplyaddress; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param string $emailReplyAddress |
|
| 328 | + */ |
|
| 329 | + public function setEmailReplyAddress(string $emailReplyAddress): void |
|
| 330 | + { |
|
| 331 | + $this->emailreplyaddress = $emailReplyAddress; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * @return string|null |
|
| 336 | + */ |
|
| 337 | + public function getNotificationTarget(): ?string |
|
| 338 | + { |
|
| 339 | + return $this->notificationtarget; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @param string|null $notificationTarget |
|
| 344 | + */ |
|
| 345 | + public function setNotificationTarget(?string $notificationTarget): void |
|
| 346 | + { |
|
| 347 | + $this->notificationtarget = $notificationTarget; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + public function getLocalDocumentation(): string |
|
| 354 | + { |
|
| 355 | + return $this->localdocumentation; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @param string $localDocumentation |
|
| 360 | + */ |
|
| 361 | + public function setLocalDocumentation(string $localDocumentation): void |
|
| 362 | + { |
|
| 363 | + $this->localdocumentation = $localDocumentation; |
|
| 364 | + } |
|
| 365 | 365 | } |
| 366 | 366 | \ No newline at end of file |
@@ -52,12 +52,10 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | if ($domain === false) { |
| 54 | 54 | self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
| 55 | - } |
|
| 56 | - else { |
|
| 55 | + } else { |
|
| 57 | 56 | self::$currentDomain = $domain; |
| 58 | 57 | } |
| 59 | - } |
|
| 60 | - else { |
|
| 58 | + } else { |
|
| 61 | 59 | self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain(); |
| 62 | 60 | } |
| 63 | 61 | } |
@@ -86,7 +84,8 @@ discard block |
||
| 86 | 84 | return $result; |
| 87 | 85 | } |
| 88 | 86 | |
| 89 | - public static function getAll(PdoDatabase $database) { |
|
| 87 | + public static function getAll(PdoDatabase $database) |
|
| 88 | + { |
|
| 90 | 89 | $statement = $database->prepare("SELECT * FROM domain;"); |
| 91 | 90 | $statement->execute(); |
| 92 | 91 | |
@@ -155,12 +154,10 @@ discard block |
||
| 155 | 154 | |
| 156 | 155 | if ($statement->execute()) { |
| 157 | 156 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 158 | - } |
|
| 159 | - else { |
|
| 157 | + } else { |
|
| 160 | 158 | throw new Exception($statement->errorInfo()); |
| 161 | 159 | } |
| 162 | - } |
|
| 163 | - else { |
|
| 160 | + } else { |
|
| 164 | 161 | $statement = $this->dbObject->prepare(<<<SQL |
| 165 | 162 | UPDATE domain SET |
| 166 | 163 | longname = :longname, |
@@ -264,8 +264,7 @@ |
||
| 264 | 264 | // Are we changing script? |
| 265 | 265 | if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
| 266 | 266 | $targetScriptName = $currentScriptName; |
| 267 | - } |
|
| 268 | - else { |
|
| 267 | + } else { |
|
| 269 | 268 | $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
| 270 | 269 | } |
| 271 | 270 | |
@@ -24,378 +24,378 @@ |
||
| 24 | 24 | |
| 25 | 25 | abstract class PageBase extends TaskBase implements IRoutedTask |
| 26 | 26 | { |
| 27 | - use TemplateOutput; |
|
| 28 | - /** @var string Smarty template to display */ |
|
| 29 | - protected $template = "base.tpl"; |
|
| 30 | - /** @var string HTML title. Currently unused. */ |
|
| 31 | - protected $htmlTitle; |
|
| 32 | - /** @var bool Determines if the page is a redirect or not */ |
|
| 33 | - protected $isRedirecting = false; |
|
| 34 | - /** @var array Queue of headers to be sent on successful completion */ |
|
| 35 | - protected $headerQueue = array(); |
|
| 36 | - /** @var string The name of the route to use, as determined by the request router. */ |
|
| 37 | - private $routeName = null; |
|
| 38 | - /** @var TokenManager */ |
|
| 39 | - protected $tokenManager; |
|
| 40 | - /** @var ContentSecurityPolicyManager */ |
|
| 41 | - private $cspManager; |
|
| 42 | - /** @var string[] Extra JS files to include */ |
|
| 43 | - private $extraJs = array(); |
|
| 44 | - /** @var bool Don't show (and hence clear) session alerts when this page is displayed */ |
|
| 45 | - private $hideAlerts = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
| 49 | - * |
|
| 50 | - * @param string $routeName The name of the route |
|
| 51 | - * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
| 52 | - * |
|
| 53 | - * @throws Exception |
|
| 54 | - * @category Security-Critical |
|
| 55 | - */ |
|
| 56 | - final public function setRoute($routeName, $skipCallableTest = false) |
|
| 57 | - { |
|
| 58 | - // Test the new route is callable before adopting it. |
|
| 59 | - if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
| 60 | - throw new Exception("Proposed route '$routeName' is not callable."); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Adopt the new route |
|
| 64 | - $this->routeName = $routeName; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Gets the name of the route that has been passed from the request router. |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - final public function getRouteName() |
|
| 72 | - { |
|
| 73 | - return $this->routeName; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Performs generic page setup actions |
|
| 78 | - */ |
|
| 79 | - final protected function setupPage() |
|
| 80 | - { |
|
| 81 | - $this->setUpSmarty(); |
|
| 82 | - |
|
| 83 | - $database = $this->getDatabase(); |
|
| 84 | - $currentUser = User::getCurrent($database); |
|
| 85 | - $this->assign('currentUser', $currentUser); |
|
| 86 | - $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN)); |
|
| 87 | - $this->assign('currentDomain', Domain::getCurrent($database)); |
|
| 88 | - $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Runs the page logic as routed by the RequestRouter |
|
| 93 | - * |
|
| 94 | - * Only should be called after a security barrier! That means only from execute(). |
|
| 95 | - */ |
|
| 96 | - final protected function runPage() |
|
| 97 | - { |
|
| 98 | - $database = $this->getDatabase(); |
|
| 99 | - |
|
| 100 | - // initialise a database transaction |
|
| 101 | - if (!$database->beginTransaction()) { |
|
| 102 | - throw new Exception('Failed to start transaction on primary database.'); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - try { |
|
| 106 | - // run the page code |
|
| 107 | - $this->{$this->getRouteName()}(); |
|
| 108 | - |
|
| 109 | - $database->commit(); |
|
| 110 | - } |
|
| 111 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
| 112 | - catch (ApplicationLogicException $ex) { |
|
| 113 | - // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
| 114 | - // standard templating system for this. |
|
| 115 | - |
|
| 116 | - // Firstly, let's undo anything that happened to the database. |
|
| 117 | - $database->rollBack(); |
|
| 118 | - |
|
| 119 | - // Reset smarty |
|
| 120 | - $this->setupPage(); |
|
| 121 | - |
|
| 122 | - $this->skipAlerts(); |
|
| 123 | - |
|
| 124 | - // Set the template |
|
| 125 | - $this->setTemplate('exception/application-logic.tpl'); |
|
| 126 | - $this->assign('message', $ex->getMessage()); |
|
| 127 | - |
|
| 128 | - // Force this back to false |
|
| 129 | - $this->isRedirecting = false; |
|
| 130 | - $this->headerQueue = array(); |
|
| 131 | - } |
|
| 132 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
| 133 | - catch (OptimisticLockFailedException $ex) { |
|
| 134 | - // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
| 135 | - // standard templating system for this. |
|
| 136 | - |
|
| 137 | - // Firstly, let's undo anything that happened to the database. |
|
| 138 | - $database->rollBack(); |
|
| 139 | - |
|
| 140 | - // Reset smarty |
|
| 141 | - $this->setupPage(); |
|
| 142 | - |
|
| 143 | - // Set the template |
|
| 144 | - $this->skipAlerts(); |
|
| 145 | - $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
| 146 | - $this->assign('message', $ex->getMessage()); |
|
| 147 | - |
|
| 148 | - $this->assign('debugTrace', false); |
|
| 149 | - |
|
| 150 | - if ($this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
| 151 | - ob_start(); |
|
| 152 | - var_dump(ExceptionHandler::getExceptionData($ex)); |
|
| 153 | - $textErrorData = ob_get_contents(); |
|
| 154 | - ob_end_clean(); |
|
| 155 | - |
|
| 156 | - $this->assign('exceptionData', $textErrorData); |
|
| 157 | - $this->assign('debugTrace', true); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // Force this back to false |
|
| 161 | - $this->isRedirecting = false; |
|
| 162 | - $this->headerQueue = array(); |
|
| 163 | - } |
|
| 164 | - finally { |
|
| 165 | - // Catch any hanging on transactions |
|
| 166 | - if ($database->hasActiveTransaction()) { |
|
| 167 | - $database->rollBack(); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // run any finalisation code needed before we send the output to the browser. |
|
| 172 | - $this->finalisePage(); |
|
| 173 | - |
|
| 174 | - // Send the headers |
|
| 175 | - $this->sendResponseHeaders(); |
|
| 176 | - |
|
| 177 | - // Check we have a template to use! |
|
| 178 | - if ($this->template !== null) { |
|
| 179 | - $content = $this->fetchTemplate($this->template); |
|
| 180 | - ob_clean(); |
|
| 181 | - print($content); |
|
| 182 | - ob_flush(); |
|
| 183 | - |
|
| 184 | - return; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Performs final tasks needed before rendering the page. |
|
| 190 | - */ |
|
| 191 | - protected function finalisePage() |
|
| 192 | - { |
|
| 193 | - if ($this->isRedirecting) { |
|
| 194 | - $this->template = null; |
|
| 195 | - |
|
| 196 | - return; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $this->assign('extraJs', $this->extraJs); |
|
| 200 | - |
|
| 201 | - if (!$this->hideAlerts) { |
|
| 202 | - // If we're actually displaying content, we want to add the session alerts here! |
|
| 203 | - $this->assign('alerts', SessionAlert::getAlerts()); |
|
| 204 | - SessionAlert::clearAlerts(); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $this->assign('htmlTitle', $this->htmlTitle); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @return TokenManager |
|
| 212 | - */ |
|
| 213 | - public function getTokenManager() |
|
| 214 | - { |
|
| 215 | - return $this->tokenManager; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @param TokenManager $tokenManager |
|
| 220 | - */ |
|
| 221 | - public function setTokenManager($tokenManager) |
|
| 222 | - { |
|
| 223 | - $this->tokenManager = $tokenManager; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return ContentSecurityPolicyManager |
|
| 228 | - */ |
|
| 229 | - public function getCspManager(): ContentSecurityPolicyManager |
|
| 230 | - { |
|
| 231 | - return $this->cspManager; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @param ContentSecurityPolicyManager $cspManager |
|
| 236 | - */ |
|
| 237 | - public function setCspManager(ContentSecurityPolicyManager $cspManager): void |
|
| 238 | - { |
|
| 239 | - $this->cspManager = $cspManager; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Skip the display of session alerts in this page |
|
| 244 | - */ |
|
| 245 | - public function skipAlerts(): void |
|
| 246 | - { |
|
| 247 | - $this->hideAlerts = true; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Sends the redirect headers to perform a GET at the destination page. |
|
| 252 | - * |
|
| 253 | - * Also nullifies the set template so Smarty does not render it. |
|
| 254 | - * |
|
| 255 | - * @param string $page The page to redirect requests to (as used in the UR) |
|
| 256 | - * @param null|string $action The action to use on the page. |
|
| 257 | - * @param null|array $parameters |
|
| 258 | - * @param null|string $script The script (relative to index.php) to redirect to |
|
| 259 | - */ |
|
| 260 | - final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
| 261 | - { |
|
| 262 | - $currentScriptName = WebRequest::scriptName(); |
|
| 263 | - |
|
| 264 | - // Are we changing script? |
|
| 265 | - if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
| 266 | - $targetScriptName = $currentScriptName; |
|
| 267 | - } |
|
| 268 | - else { |
|
| 269 | - $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $pathInfo = array($targetScriptName); |
|
| 273 | - |
|
| 274 | - $pathInfo[1] = $page; |
|
| 275 | - |
|
| 276 | - if ($action !== null) { |
|
| 277 | - $pathInfo[2] = $action; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $url = implode('/', $pathInfo); |
|
| 281 | - |
|
| 282 | - if (is_array($parameters) && count($parameters) > 0) { |
|
| 283 | - $url .= '?' . http_build_query($parameters); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $this->redirectUrl($url); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Sends the redirect headers to perform a GET at the new address. |
|
| 291 | - * |
|
| 292 | - * Also nullifies the set template so Smarty does not render it. |
|
| 293 | - * |
|
| 294 | - * @param string $path URL to redirect to |
|
| 295 | - */ |
|
| 296 | - final protected function redirectUrl($path) |
|
| 297 | - { |
|
| 298 | - // 303 See Other = re-request at new address with a GET. |
|
| 299 | - $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
| 300 | - $this->headerQueue[] = "Location: $path"; |
|
| 301 | - |
|
| 302 | - $this->setTemplate(null); |
|
| 303 | - $this->isRedirecting = true; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Sets the name of the template this page should display. |
|
| 308 | - * |
|
| 309 | - * @param string $name |
|
| 310 | - * |
|
| 311 | - * @throws Exception |
|
| 312 | - */ |
|
| 313 | - final protected function setTemplate($name) |
|
| 314 | - { |
|
| 315 | - if ($this->isRedirecting) { |
|
| 316 | - throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $this->template = $name; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Adds an extra JS file to to the page |
|
| 324 | - * |
|
| 325 | - * @param string $path The path (relative to the application root) of the file |
|
| 326 | - */ |
|
| 327 | - final protected function addJs($path) |
|
| 328 | - { |
|
| 329 | - if (in_array($path, $this->extraJs)) { |
|
| 330 | - // nothing to do |
|
| 331 | - return; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $this->extraJs[] = $path; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Main function for this page, when no specific actions are called. |
|
| 339 | - * @return void |
|
| 340 | - */ |
|
| 341 | - abstract protected function main(); |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Takes a smarty template string and sets the HTML title to that value |
|
| 345 | - * |
|
| 346 | - * @param string $title |
|
| 347 | - * |
|
| 348 | - * @throws Smarty\Exception |
|
| 349 | - */ |
|
| 350 | - final protected function setHtmlTitle($title) |
|
| 351 | - { |
|
| 352 | - $this->htmlTitle = $this->smarty->fetch('string:' . $title); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - public function execute() |
|
| 356 | - { |
|
| 357 | - if ($this->getRouteName() === null) { |
|
| 358 | - throw new Exception('Request is unrouted.'); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if ($this->getSiteConfiguration() === null) { |
|
| 362 | - throw new Exception('Page has no configuration!'); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - $this->setupPage(); |
|
| 366 | - |
|
| 367 | - $this->runPage(); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - public function assignCSRFToken() |
|
| 371 | - { |
|
| 372 | - $token = $this->tokenManager->getNewToken(); |
|
| 373 | - $this->assign('csrfTokenData', $token->getTokenData()); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - public function validateCSRFToken() |
|
| 377 | - { |
|
| 378 | - if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
| 379 | - throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - protected function sendResponseHeaders() |
|
| 384 | - { |
|
| 385 | - if (headers_sent()) { |
|
| 386 | - throw new ApplicationLogicException('Headers have already been sent! This is likely a bug in the application.'); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - // send the CSP headers now |
|
| 390 | - header($this->getCspManager()->getHeader()); |
|
| 391 | - |
|
| 392 | - foreach ($this->headerQueue as $item) { |
|
| 393 | - if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
| 394 | - // Oops. We're not allowed to do this. |
|
| 395 | - throw new Exception('Unable to split header'); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - header($item); |
|
| 399 | - } |
|
| 400 | - } |
|
| 27 | + use TemplateOutput; |
|
| 28 | + /** @var string Smarty template to display */ |
|
| 29 | + protected $template = "base.tpl"; |
|
| 30 | + /** @var string HTML title. Currently unused. */ |
|
| 31 | + protected $htmlTitle; |
|
| 32 | + /** @var bool Determines if the page is a redirect or not */ |
|
| 33 | + protected $isRedirecting = false; |
|
| 34 | + /** @var array Queue of headers to be sent on successful completion */ |
|
| 35 | + protected $headerQueue = array(); |
|
| 36 | + /** @var string The name of the route to use, as determined by the request router. */ |
|
| 37 | + private $routeName = null; |
|
| 38 | + /** @var TokenManager */ |
|
| 39 | + protected $tokenManager; |
|
| 40 | + /** @var ContentSecurityPolicyManager */ |
|
| 41 | + private $cspManager; |
|
| 42 | + /** @var string[] Extra JS files to include */ |
|
| 43 | + private $extraJs = array(); |
|
| 44 | + /** @var bool Don't show (and hence clear) session alerts when this page is displayed */ |
|
| 45 | + private $hideAlerts = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Sets the route the request will take. Only should be called from the request router or barrier test. |
|
| 49 | + * |
|
| 50 | + * @param string $routeName The name of the route |
|
| 51 | + * @param bool $skipCallableTest Don't use this unless you know what you're doing, and what the implications are. |
|
| 52 | + * |
|
| 53 | + * @throws Exception |
|
| 54 | + * @category Security-Critical |
|
| 55 | + */ |
|
| 56 | + final public function setRoute($routeName, $skipCallableTest = false) |
|
| 57 | + { |
|
| 58 | + // Test the new route is callable before adopting it. |
|
| 59 | + if (!$skipCallableTest && !is_callable(array($this, $routeName))) { |
|
| 60 | + throw new Exception("Proposed route '$routeName' is not callable."); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Adopt the new route |
|
| 64 | + $this->routeName = $routeName; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Gets the name of the route that has been passed from the request router. |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + final public function getRouteName() |
|
| 72 | + { |
|
| 73 | + return $this->routeName; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Performs generic page setup actions |
|
| 78 | + */ |
|
| 79 | + final protected function setupPage() |
|
| 80 | + { |
|
| 81 | + $this->setUpSmarty(); |
|
| 82 | + |
|
| 83 | + $database = $this->getDatabase(); |
|
| 84 | + $currentUser = User::getCurrent($database); |
|
| 85 | + $this->assign('currentUser', $currentUser); |
|
| 86 | + $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN)); |
|
| 87 | + $this->assign('currentDomain', Domain::getCurrent($database)); |
|
| 88 | + $this->assign('loggedIn', (!$currentUser->isCommunityUser())); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Runs the page logic as routed by the RequestRouter |
|
| 93 | + * |
|
| 94 | + * Only should be called after a security barrier! That means only from execute(). |
|
| 95 | + */ |
|
| 96 | + final protected function runPage() |
|
| 97 | + { |
|
| 98 | + $database = $this->getDatabase(); |
|
| 99 | + |
|
| 100 | + // initialise a database transaction |
|
| 101 | + if (!$database->beginTransaction()) { |
|
| 102 | + throw new Exception('Failed to start transaction on primary database.'); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + try { |
|
| 106 | + // run the page code |
|
| 107 | + $this->{$this->getRouteName()}(); |
|
| 108 | + |
|
| 109 | + $database->commit(); |
|
| 110 | + } |
|
| 111 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
| 112 | + catch (ApplicationLogicException $ex) { |
|
| 113 | + // it's an application logic exception, so nothing went seriously wrong with the site. We can use the |
|
| 114 | + // standard templating system for this. |
|
| 115 | + |
|
| 116 | + // Firstly, let's undo anything that happened to the database. |
|
| 117 | + $database->rollBack(); |
|
| 118 | + |
|
| 119 | + // Reset smarty |
|
| 120 | + $this->setupPage(); |
|
| 121 | + |
|
| 122 | + $this->skipAlerts(); |
|
| 123 | + |
|
| 124 | + // Set the template |
|
| 125 | + $this->setTemplate('exception/application-logic.tpl'); |
|
| 126 | + $this->assign('message', $ex->getMessage()); |
|
| 127 | + |
|
| 128 | + // Force this back to false |
|
| 129 | + $this->isRedirecting = false; |
|
| 130 | + $this->headerQueue = array(); |
|
| 131 | + } |
|
| 132 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
| 133 | + catch (OptimisticLockFailedException $ex) { |
|
| 134 | + // it's an optimistic lock failure exception, so nothing went seriously wrong with the site. We can use the |
|
| 135 | + // standard templating system for this. |
|
| 136 | + |
|
| 137 | + // Firstly, let's undo anything that happened to the database. |
|
| 138 | + $database->rollBack(); |
|
| 139 | + |
|
| 140 | + // Reset smarty |
|
| 141 | + $this->setupPage(); |
|
| 142 | + |
|
| 143 | + // Set the template |
|
| 144 | + $this->skipAlerts(); |
|
| 145 | + $this->setTemplate('exception/optimistic-lock-failure.tpl'); |
|
| 146 | + $this->assign('message', $ex->getMessage()); |
|
| 147 | + |
|
| 148 | + $this->assign('debugTrace', false); |
|
| 149 | + |
|
| 150 | + if ($this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
| 151 | + ob_start(); |
|
| 152 | + var_dump(ExceptionHandler::getExceptionData($ex)); |
|
| 153 | + $textErrorData = ob_get_contents(); |
|
| 154 | + ob_end_clean(); |
|
| 155 | + |
|
| 156 | + $this->assign('exceptionData', $textErrorData); |
|
| 157 | + $this->assign('debugTrace', true); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // Force this back to false |
|
| 161 | + $this->isRedirecting = false; |
|
| 162 | + $this->headerQueue = array(); |
|
| 163 | + } |
|
| 164 | + finally { |
|
| 165 | + // Catch any hanging on transactions |
|
| 166 | + if ($database->hasActiveTransaction()) { |
|
| 167 | + $database->rollBack(); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // run any finalisation code needed before we send the output to the browser. |
|
| 172 | + $this->finalisePage(); |
|
| 173 | + |
|
| 174 | + // Send the headers |
|
| 175 | + $this->sendResponseHeaders(); |
|
| 176 | + |
|
| 177 | + // Check we have a template to use! |
|
| 178 | + if ($this->template !== null) { |
|
| 179 | + $content = $this->fetchTemplate($this->template); |
|
| 180 | + ob_clean(); |
|
| 181 | + print($content); |
|
| 182 | + ob_flush(); |
|
| 183 | + |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Performs final tasks needed before rendering the page. |
|
| 190 | + */ |
|
| 191 | + protected function finalisePage() |
|
| 192 | + { |
|
| 193 | + if ($this->isRedirecting) { |
|
| 194 | + $this->template = null; |
|
| 195 | + |
|
| 196 | + return; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $this->assign('extraJs', $this->extraJs); |
|
| 200 | + |
|
| 201 | + if (!$this->hideAlerts) { |
|
| 202 | + // If we're actually displaying content, we want to add the session alerts here! |
|
| 203 | + $this->assign('alerts', SessionAlert::getAlerts()); |
|
| 204 | + SessionAlert::clearAlerts(); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $this->assign('htmlTitle', $this->htmlTitle); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @return TokenManager |
|
| 212 | + */ |
|
| 213 | + public function getTokenManager() |
|
| 214 | + { |
|
| 215 | + return $this->tokenManager; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @param TokenManager $tokenManager |
|
| 220 | + */ |
|
| 221 | + public function setTokenManager($tokenManager) |
|
| 222 | + { |
|
| 223 | + $this->tokenManager = $tokenManager; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return ContentSecurityPolicyManager |
|
| 228 | + */ |
|
| 229 | + public function getCspManager(): ContentSecurityPolicyManager |
|
| 230 | + { |
|
| 231 | + return $this->cspManager; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @param ContentSecurityPolicyManager $cspManager |
|
| 236 | + */ |
|
| 237 | + public function setCspManager(ContentSecurityPolicyManager $cspManager): void |
|
| 238 | + { |
|
| 239 | + $this->cspManager = $cspManager; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Skip the display of session alerts in this page |
|
| 244 | + */ |
|
| 245 | + public function skipAlerts(): void |
|
| 246 | + { |
|
| 247 | + $this->hideAlerts = true; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Sends the redirect headers to perform a GET at the destination page. |
|
| 252 | + * |
|
| 253 | + * Also nullifies the set template so Smarty does not render it. |
|
| 254 | + * |
|
| 255 | + * @param string $page The page to redirect requests to (as used in the UR) |
|
| 256 | + * @param null|string $action The action to use on the page. |
|
| 257 | + * @param null|array $parameters |
|
| 258 | + * @param null|string $script The script (relative to index.php) to redirect to |
|
| 259 | + */ |
|
| 260 | + final protected function redirect($page = '', $action = null, $parameters = null, $script = null) |
|
| 261 | + { |
|
| 262 | + $currentScriptName = WebRequest::scriptName(); |
|
| 263 | + |
|
| 264 | + // Are we changing script? |
|
| 265 | + if ($script === null || substr($currentScriptName, -1 * count($script)) === $script) { |
|
| 266 | + $targetScriptName = $currentScriptName; |
|
| 267 | + } |
|
| 268 | + else { |
|
| 269 | + $targetScriptName = $this->getSiteConfiguration()->getBaseUrl() . '/' . $script; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $pathInfo = array($targetScriptName); |
|
| 273 | + |
|
| 274 | + $pathInfo[1] = $page; |
|
| 275 | + |
|
| 276 | + if ($action !== null) { |
|
| 277 | + $pathInfo[2] = $action; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $url = implode('/', $pathInfo); |
|
| 281 | + |
|
| 282 | + if (is_array($parameters) && count($parameters) > 0) { |
|
| 283 | + $url .= '?' . http_build_query($parameters); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $this->redirectUrl($url); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Sends the redirect headers to perform a GET at the new address. |
|
| 291 | + * |
|
| 292 | + * Also nullifies the set template so Smarty does not render it. |
|
| 293 | + * |
|
| 294 | + * @param string $path URL to redirect to |
|
| 295 | + */ |
|
| 296 | + final protected function redirectUrl($path) |
|
| 297 | + { |
|
| 298 | + // 303 See Other = re-request at new address with a GET. |
|
| 299 | + $this->headerQueue[] = 'HTTP/1.1 303 See Other'; |
|
| 300 | + $this->headerQueue[] = "Location: $path"; |
|
| 301 | + |
|
| 302 | + $this->setTemplate(null); |
|
| 303 | + $this->isRedirecting = true; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Sets the name of the template this page should display. |
|
| 308 | + * |
|
| 309 | + * @param string $name |
|
| 310 | + * |
|
| 311 | + * @throws Exception |
|
| 312 | + */ |
|
| 313 | + final protected function setTemplate($name) |
|
| 314 | + { |
|
| 315 | + if ($this->isRedirecting) { |
|
| 316 | + throw new Exception('This page has been set as a redirect, no template can be displayed!'); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $this->template = $name; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Adds an extra JS file to to the page |
|
| 324 | + * |
|
| 325 | + * @param string $path The path (relative to the application root) of the file |
|
| 326 | + */ |
|
| 327 | + final protected function addJs($path) |
|
| 328 | + { |
|
| 329 | + if (in_array($path, $this->extraJs)) { |
|
| 330 | + // nothing to do |
|
| 331 | + return; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $this->extraJs[] = $path; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Main function for this page, when no specific actions are called. |
|
| 339 | + * @return void |
|
| 340 | + */ |
|
| 341 | + abstract protected function main(); |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Takes a smarty template string and sets the HTML title to that value |
|
| 345 | + * |
|
| 346 | + * @param string $title |
|
| 347 | + * |
|
| 348 | + * @throws Smarty\Exception |
|
| 349 | + */ |
|
| 350 | + final protected function setHtmlTitle($title) |
|
| 351 | + { |
|
| 352 | + $this->htmlTitle = $this->smarty->fetch('string:' . $title); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + public function execute() |
|
| 356 | + { |
|
| 357 | + if ($this->getRouteName() === null) { |
|
| 358 | + throw new Exception('Request is unrouted.'); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if ($this->getSiteConfiguration() === null) { |
|
| 362 | + throw new Exception('Page has no configuration!'); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + $this->setupPage(); |
|
| 366 | + |
|
| 367 | + $this->runPage(); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + public function assignCSRFToken() |
|
| 371 | + { |
|
| 372 | + $token = $this->tokenManager->getNewToken(); |
|
| 373 | + $this->assign('csrfTokenData', $token->getTokenData()); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + public function validateCSRFToken() |
|
| 377 | + { |
|
| 378 | + if (!$this->tokenManager->validateToken(WebRequest::postString('csrfTokenData'))) { |
|
| 379 | + throw new ApplicationLogicException('Form token is not valid, please reload and try again'); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + protected function sendResponseHeaders() |
|
| 384 | + { |
|
| 385 | + if (headers_sent()) { |
|
| 386 | + throw new ApplicationLogicException('Headers have already been sent! This is likely a bug in the application.'); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + // send the CSP headers now |
|
| 390 | + header($this->getCspManager()->getHeader()); |
|
| 391 | + |
|
| 392 | + foreach ($this->headerQueue as $item) { |
|
| 393 | + if (mb_strpos($item, "\r") !== false || mb_strpos($item, "\n") !== false) { |
|
| 394 | + // Oops. We're not allowed to do this. |
|
| 395 | + throw new Exception('Unable to split header'); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + header($item); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | 401 | } |
@@ -14,69 +14,69 @@ |
||
| 14 | 14 | |
| 15 | 15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Main function for this page, when no specific actions are called. |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - * @throws ApiException |
|
| 22 | - */ |
|
| 23 | - final protected function main() |
|
| 24 | - { |
|
| 25 | - if (headers_sent()) { |
|
| 26 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * Main function for this page, when no specific actions are called. |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + * @throws ApiException |
|
| 22 | + */ |
|
| 23 | + final protected function main() |
|
| 24 | + { |
|
| 25 | + if (headers_sent()) { |
|
| 26 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // javascript access control |
|
| 30 | - $httpOrigin = WebRequest::origin(); |
|
| 29 | + // javascript access control |
|
| 30 | + $httpOrigin = WebRequest::origin(); |
|
| 31 | 31 | |
| 32 | - if ($httpOrigin !== null) { |
|
| 33 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
| 32 | + if ($httpOrigin !== null) { |
|
| 33 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
| 34 | 34 | |
| 35 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
| 36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
| 37 | - } |
|
| 38 | - } |
|
| 35 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
| 36 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $responseData = $this->runApiPage(); |
|
| 40 | + $responseData = $this->runApiPage(); |
|
| 41 | 41 | |
| 42 | - ob_end_clean(); |
|
| 43 | - print($responseData); |
|
| 44 | - ob_start(); |
|
| 45 | - } |
|
| 42 | + ob_end_clean(); |
|
| 43 | + print($responseData); |
|
| 44 | + ob_start(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Method that runs API action |
|
| 49 | - * |
|
| 50 | - * @return object|array The modified API document |
|
| 51 | - */ |
|
| 52 | - public abstract function executeApiAction(); |
|
| 47 | + /** |
|
| 48 | + * Method that runs API action |
|
| 49 | + * |
|
| 50 | + * @return object|array The modified API document |
|
| 51 | + */ |
|
| 52 | + public abstract function executeApiAction(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - final public function runApiPage() |
|
| 58 | - { |
|
| 59 | - try { |
|
| 60 | - $apiDocument = $this->executeApiAction(); |
|
| 61 | - } |
|
| 62 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
| 63 | - catch (ApiException $ex) { |
|
| 64 | - $apiDocument = [ |
|
| 65 | - 'error' => $ex->getMessage(), |
|
| 66 | - ]; |
|
| 67 | - } |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + final public function runApiPage() |
|
| 58 | + { |
|
| 59 | + try { |
|
| 60 | + $apiDocument = $this->executeApiAction(); |
|
| 61 | + } |
|
| 62 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
| 63 | + catch (ApiException $ex) { |
|
| 64 | + $apiDocument = [ |
|
| 65 | + 'error' => $ex->getMessage(), |
|
| 66 | + ]; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
| 69 | + $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
| 70 | 70 | |
| 71 | - $targetVar = WebRequest::getString('targetVariable'); |
|
| 72 | - if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
| 73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
| 74 | - header("Content-Type: text/javascript"); |
|
| 75 | - } |
|
| 76 | - else { |
|
| 77 | - header("Content-Type: application/json"); |
|
| 78 | - } |
|
| 71 | + $targetVar = WebRequest::getString('targetVariable'); |
|
| 72 | + if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
| 73 | + $data = $targetVar . ' = ' . $data . ';'; |
|
| 74 | + header("Content-Type: text/javascript"); |
|
| 75 | + } |
|
| 76 | + else { |
|
| 77 | + header("Content-Type: application/json"); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return $data; |
|
| 81 | - } |
|
| 80 | + return $data; |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -72,8 +72,7 @@ |
||
| 72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
| 73 | 73 | $data = $targetVar . ' = ' . $data . ';'; |
| 74 | 74 | header("Content-Type: text/javascript"); |
| 75 | - } |
|
| 76 | - else { |
|
| 75 | + } else { |
|
| 77 | 76 | header("Content-Type: application/json"); |
| 78 | 77 | } |
| 79 | 78 | |
@@ -22,211 +22,211 @@ |
||
| 22 | 22 | |
| 23 | 23 | abstract class TaskBase implements ITask |
| 24 | 24 | { |
| 25 | - /** @var SiteConfiguration */ |
|
| 26 | - private $siteConfiguration; |
|
| 27 | - /** @var IEmailHelper */ |
|
| 28 | - private $emailHelper; |
|
| 29 | - /** @var HttpHelper */ |
|
| 30 | - private $httpHelper; |
|
| 31 | - /** @var ILocationProvider */ |
|
| 32 | - private $locationProvider; |
|
| 33 | - /** @var IXffTrustProvider */ |
|
| 34 | - private $xffTrustProvider; |
|
| 35 | - /** @var IRDnsProvider */ |
|
| 36 | - private $rdnsProvider; |
|
| 37 | - /** @var IAntiSpoofProvider */ |
|
| 38 | - private $antiSpoofProvider; |
|
| 39 | - /** @var IOAuthProtocolHelper */ |
|
| 40 | - private $oauthHelper; |
|
| 41 | - /** @var PdoDatabase */ |
|
| 42 | - private $database; |
|
| 43 | - /** @var IrcNotificationHelper */ |
|
| 44 | - private $notificationHelper; |
|
| 45 | - /** @var TorExitProvider */ |
|
| 46 | - private $torExitProvider; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return IEmailHelper |
|
| 50 | - */ |
|
| 51 | - final public function getEmailHelper() |
|
| 52 | - { |
|
| 53 | - return $this->emailHelper; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param IEmailHelper $emailHelper |
|
| 58 | - */ |
|
| 59 | - final public function setEmailHelper($emailHelper) |
|
| 60 | - { |
|
| 61 | - $this->emailHelper = $emailHelper; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return HttpHelper |
|
| 66 | - */ |
|
| 67 | - final public function getHttpHelper() |
|
| 68 | - { |
|
| 69 | - return $this->httpHelper; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param HttpHelper $httpHelper |
|
| 74 | - */ |
|
| 75 | - final public function setHttpHelper($httpHelper) |
|
| 76 | - { |
|
| 77 | - $this->httpHelper = $httpHelper; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return ILocationProvider |
|
| 82 | - */ |
|
| 83 | - final public function getLocationProvider() |
|
| 84 | - { |
|
| 85 | - return $this->locationProvider; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param ILocationProvider $locationProvider |
|
| 90 | - */ |
|
| 91 | - final public function setLocationProvider(ILocationProvider $locationProvider) |
|
| 92 | - { |
|
| 93 | - $this->locationProvider = $locationProvider; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return IXffTrustProvider |
|
| 98 | - */ |
|
| 99 | - final public function getXffTrustProvider() |
|
| 100 | - { |
|
| 101 | - return $this->xffTrustProvider; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param IXffTrustProvider $xffTrustProvider |
|
| 106 | - */ |
|
| 107 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
| 108 | - { |
|
| 109 | - $this->xffTrustProvider = $xffTrustProvider; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return IRDnsProvider |
|
| 114 | - */ |
|
| 115 | - final public function getRdnsProvider() |
|
| 116 | - { |
|
| 117 | - return $this->rdnsProvider; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param IRDnsProvider $rdnsProvider |
|
| 122 | - */ |
|
| 123 | - public function setRdnsProvider($rdnsProvider) |
|
| 124 | - { |
|
| 125 | - $this->rdnsProvider = $rdnsProvider; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return IAntiSpoofProvider |
|
| 130 | - */ |
|
| 131 | - public function getAntiSpoofProvider() |
|
| 132 | - { |
|
| 133 | - return $this->antiSpoofProvider; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 138 | - */ |
|
| 139 | - public function setAntiSpoofProvider($antiSpoofProvider) |
|
| 140 | - { |
|
| 141 | - $this->antiSpoofProvider = $antiSpoofProvider; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return PdoDatabase |
|
| 146 | - */ |
|
| 147 | - final public function getDatabase() |
|
| 148 | - { |
|
| 149 | - return $this->database; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param PdoDatabase $database |
|
| 154 | - */ |
|
| 155 | - final public function setDatabase($database) |
|
| 156 | - { |
|
| 157 | - $this->database = $database; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @return IOAuthProtocolHelper |
|
| 162 | - */ |
|
| 163 | - public function getOAuthProtocolHelper() |
|
| 164 | - { |
|
| 165 | - return $this->oauthHelper; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 170 | - */ |
|
| 171 | - public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
| 172 | - { |
|
| 173 | - $this->oauthHelper = $oauthProtocolHelper; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @return void |
|
| 178 | - */ |
|
| 179 | - abstract public function execute(); |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @return IrcNotificationHelper |
|
| 183 | - */ |
|
| 184 | - public function getNotificationHelper() |
|
| 185 | - { |
|
| 186 | - return $this->notificationHelper; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @param IrcNotificationHelper $notificationHelper |
|
| 191 | - */ |
|
| 192 | - public function setNotificationHelper($notificationHelper) |
|
| 193 | - { |
|
| 194 | - $this->notificationHelper = $notificationHelper; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @return TorExitProvider |
|
| 199 | - */ |
|
| 200 | - public function getTorExitProvider() |
|
| 201 | - { |
|
| 202 | - return $this->torExitProvider; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param TorExitProvider $torExitProvider |
|
| 207 | - */ |
|
| 208 | - public function setTorExitProvider($torExitProvider) |
|
| 209 | - { |
|
| 210 | - $this->torExitProvider = $torExitProvider; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Gets the site configuration object |
|
| 215 | - * |
|
| 216 | - * @return SiteConfiguration |
|
| 217 | - */ |
|
| 218 | - final protected function getSiteConfiguration() |
|
| 219 | - { |
|
| 220 | - return $this->siteConfiguration; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Sets the site configuration object for this page |
|
| 225 | - * |
|
| 226 | - * @param SiteConfiguration $configuration |
|
| 227 | - */ |
|
| 228 | - final public function setSiteConfiguration($configuration) |
|
| 229 | - { |
|
| 230 | - $this->siteConfiguration = $configuration; |
|
| 231 | - } |
|
| 25 | + /** @var SiteConfiguration */ |
|
| 26 | + private $siteConfiguration; |
|
| 27 | + /** @var IEmailHelper */ |
|
| 28 | + private $emailHelper; |
|
| 29 | + /** @var HttpHelper */ |
|
| 30 | + private $httpHelper; |
|
| 31 | + /** @var ILocationProvider */ |
|
| 32 | + private $locationProvider; |
|
| 33 | + /** @var IXffTrustProvider */ |
|
| 34 | + private $xffTrustProvider; |
|
| 35 | + /** @var IRDnsProvider */ |
|
| 36 | + private $rdnsProvider; |
|
| 37 | + /** @var IAntiSpoofProvider */ |
|
| 38 | + private $antiSpoofProvider; |
|
| 39 | + /** @var IOAuthProtocolHelper */ |
|
| 40 | + private $oauthHelper; |
|
| 41 | + /** @var PdoDatabase */ |
|
| 42 | + private $database; |
|
| 43 | + /** @var IrcNotificationHelper */ |
|
| 44 | + private $notificationHelper; |
|
| 45 | + /** @var TorExitProvider */ |
|
| 46 | + private $torExitProvider; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return IEmailHelper |
|
| 50 | + */ |
|
| 51 | + final public function getEmailHelper() |
|
| 52 | + { |
|
| 53 | + return $this->emailHelper; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param IEmailHelper $emailHelper |
|
| 58 | + */ |
|
| 59 | + final public function setEmailHelper($emailHelper) |
|
| 60 | + { |
|
| 61 | + $this->emailHelper = $emailHelper; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return HttpHelper |
|
| 66 | + */ |
|
| 67 | + final public function getHttpHelper() |
|
| 68 | + { |
|
| 69 | + return $this->httpHelper; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param HttpHelper $httpHelper |
|
| 74 | + */ |
|
| 75 | + final public function setHttpHelper($httpHelper) |
|
| 76 | + { |
|
| 77 | + $this->httpHelper = $httpHelper; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return ILocationProvider |
|
| 82 | + */ |
|
| 83 | + final public function getLocationProvider() |
|
| 84 | + { |
|
| 85 | + return $this->locationProvider; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param ILocationProvider $locationProvider |
|
| 90 | + */ |
|
| 91 | + final public function setLocationProvider(ILocationProvider $locationProvider) |
|
| 92 | + { |
|
| 93 | + $this->locationProvider = $locationProvider; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return IXffTrustProvider |
|
| 98 | + */ |
|
| 99 | + final public function getXffTrustProvider() |
|
| 100 | + { |
|
| 101 | + return $this->xffTrustProvider; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param IXffTrustProvider $xffTrustProvider |
|
| 106 | + */ |
|
| 107 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
| 108 | + { |
|
| 109 | + $this->xffTrustProvider = $xffTrustProvider; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return IRDnsProvider |
|
| 114 | + */ |
|
| 115 | + final public function getRdnsProvider() |
|
| 116 | + { |
|
| 117 | + return $this->rdnsProvider; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param IRDnsProvider $rdnsProvider |
|
| 122 | + */ |
|
| 123 | + public function setRdnsProvider($rdnsProvider) |
|
| 124 | + { |
|
| 125 | + $this->rdnsProvider = $rdnsProvider; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return IAntiSpoofProvider |
|
| 130 | + */ |
|
| 131 | + public function getAntiSpoofProvider() |
|
| 132 | + { |
|
| 133 | + return $this->antiSpoofProvider; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 138 | + */ |
|
| 139 | + public function setAntiSpoofProvider($antiSpoofProvider) |
|
| 140 | + { |
|
| 141 | + $this->antiSpoofProvider = $antiSpoofProvider; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return PdoDatabase |
|
| 146 | + */ |
|
| 147 | + final public function getDatabase() |
|
| 148 | + { |
|
| 149 | + return $this->database; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param PdoDatabase $database |
|
| 154 | + */ |
|
| 155 | + final public function setDatabase($database) |
|
| 156 | + { |
|
| 157 | + $this->database = $database; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @return IOAuthProtocolHelper |
|
| 162 | + */ |
|
| 163 | + public function getOAuthProtocolHelper() |
|
| 164 | + { |
|
| 165 | + return $this->oauthHelper; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 170 | + */ |
|
| 171 | + public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
| 172 | + { |
|
| 173 | + $this->oauthHelper = $oauthProtocolHelper; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @return void |
|
| 178 | + */ |
|
| 179 | + abstract public function execute(); |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @return IrcNotificationHelper |
|
| 183 | + */ |
|
| 184 | + public function getNotificationHelper() |
|
| 185 | + { |
|
| 186 | + return $this->notificationHelper; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @param IrcNotificationHelper $notificationHelper |
|
| 191 | + */ |
|
| 192 | + public function setNotificationHelper($notificationHelper) |
|
| 193 | + { |
|
| 194 | + $this->notificationHelper = $notificationHelper; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @return TorExitProvider |
|
| 199 | + */ |
|
| 200 | + public function getTorExitProvider() |
|
| 201 | + { |
|
| 202 | + return $this->torExitProvider; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param TorExitProvider $torExitProvider |
|
| 207 | + */ |
|
| 208 | + public function setTorExitProvider($torExitProvider) |
|
| 209 | + { |
|
| 210 | + $this->torExitProvider = $torExitProvider; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Gets the site configuration object |
|
| 215 | + * |
|
| 216 | + * @return SiteConfiguration |
|
| 217 | + */ |
|
| 218 | + final protected function getSiteConfiguration() |
|
| 219 | + { |
|
| 220 | + return $this->siteConfiguration; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Sets the site configuration object for this page |
|
| 225 | + * |
|
| 226 | + * @param SiteConfiguration $configuration |
|
| 227 | + */ |
|
| 228 | + final public function setSiteConfiguration($configuration) |
|
| 229 | + { |
|
| 230 | + $this->siteConfiguration = $configuration; |
|
| 231 | + } |
|
| 232 | 232 | } |
| 233 | 233 | \ No newline at end of file |
@@ -13,97 +13,97 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class PagedInternalPageBase extends InternalPageBase |
| 15 | 15 | { |
| 16 | - /** @var SearchHelperBase */ |
|
| 17 | - private $searchHelper; |
|
| 18 | - private $page; |
|
| 19 | - private $limit; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Sets up the pager with the current page, current limit, and total number of records. |
|
| 23 | - * |
|
| 24 | - * @param int $count |
|
| 25 | - * @param array $formParameters |
|
| 26 | - */ |
|
| 27 | - protected function setupPageData($count, $formParameters) |
|
| 28 | - { |
|
| 29 | - $page = $this->page; |
|
| 30 | - $limit = $this->limit; |
|
| 31 | - |
|
| 32 | - // The number of pages on the pager to show. Must be odd |
|
| 33 | - $pageLimit = 9; |
|
| 34 | - |
|
| 35 | - $pageData = array( |
|
| 36 | - // Can the user go to the previous page? |
|
| 37 | - 'canprev' => $page != 1, |
|
| 38 | - // Can the user go to the next page? |
|
| 39 | - 'cannext' => ($page * $limit) < $count, |
|
| 40 | - // Maximum page number |
|
| 41 | - 'maxpage' => max(1, ceil($count / $limit)), |
|
| 42 | - // Limit to the number of pages to display |
|
| 43 | - 'pagelimit' => $pageLimit, |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - // number of pages either side of the current to show |
|
| 47 | - $pageMargin = (($pageLimit - 1) / 2); |
|
| 48 | - |
|
| 49 | - // Calculate the number of pages either side to show - this is for situations like: |
|
| 50 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
| 51 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
| 52 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
| 53 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
| 54 | - |
|
| 55 | - if ($pageCount < $pageLimit) { |
|
| 56 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
| 57 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
| 58 | - } |
|
| 59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 60 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Put the range of pages into the page data |
|
| 65 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
| 66 | - |
|
| 67 | - $this->assign("pagedata", $pageData); |
|
| 68 | - |
|
| 69 | - $this->assign("limit", $limit); |
|
| 70 | - $this->assign("page", $page); |
|
| 71 | - |
|
| 72 | - $this->setupFormParameters($formParameters); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
| 76 | - { |
|
| 77 | - $this->searchHelper = $searchHelper; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - protected function setupLimits() |
|
| 81 | - { |
|
| 82 | - $limit = WebRequest::getInt('limit'); |
|
| 83 | - if ($limit === null) { |
|
| 84 | - $limit = 100; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $page = WebRequest::getInt('page'); |
|
| 88 | - if ($page === null) { |
|
| 89 | - $page = 1; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $offset = ($page - 1) * $limit; |
|
| 93 | - |
|
| 94 | - $this->searchHelper->limit($limit, $offset); |
|
| 95 | - |
|
| 96 | - $this->page = $page; |
|
| 97 | - $this->limit = $limit; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - private function setupFormParameters($formParameters) |
|
| 101 | - { |
|
| 102 | - $formParameters['limit'] = $this->limit; |
|
| 103 | - $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
| 104 | - |
|
| 105 | - foreach ($formParameters as $key => $value) { |
|
| 106 | - $this->assign($key, $value); |
|
| 107 | - } |
|
| 108 | - } |
|
| 16 | + /** @var SearchHelperBase */ |
|
| 17 | + private $searchHelper; |
|
| 18 | + private $page; |
|
| 19 | + private $limit; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Sets up the pager with the current page, current limit, and total number of records. |
|
| 23 | + * |
|
| 24 | + * @param int $count |
|
| 25 | + * @param array $formParameters |
|
| 26 | + */ |
|
| 27 | + protected function setupPageData($count, $formParameters) |
|
| 28 | + { |
|
| 29 | + $page = $this->page; |
|
| 30 | + $limit = $this->limit; |
|
| 31 | + |
|
| 32 | + // The number of pages on the pager to show. Must be odd |
|
| 33 | + $pageLimit = 9; |
|
| 34 | + |
|
| 35 | + $pageData = array( |
|
| 36 | + // Can the user go to the previous page? |
|
| 37 | + 'canprev' => $page != 1, |
|
| 38 | + // Can the user go to the next page? |
|
| 39 | + 'cannext' => ($page * $limit) < $count, |
|
| 40 | + // Maximum page number |
|
| 41 | + 'maxpage' => max(1, ceil($count / $limit)), |
|
| 42 | + // Limit to the number of pages to display |
|
| 43 | + 'pagelimit' => $pageLimit, |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + // number of pages either side of the current to show |
|
| 47 | + $pageMargin = (($pageLimit - 1) / 2); |
|
| 48 | + |
|
| 49 | + // Calculate the number of pages either side to show - this is for situations like: |
|
| 50 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
| 51 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
| 52 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
| 53 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
| 54 | + |
|
| 55 | + if ($pageCount < $pageLimit) { |
|
| 56 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
| 57 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
| 58 | + } |
|
| 59 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 60 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Put the range of pages into the page data |
|
| 65 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
| 66 | + |
|
| 67 | + $this->assign("pagedata", $pageData); |
|
| 68 | + |
|
| 69 | + $this->assign("limit", $limit); |
|
| 70 | + $this->assign("page", $page); |
|
| 71 | + |
|
| 72 | + $this->setupFormParameters($formParameters); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
| 76 | + { |
|
| 77 | + $this->searchHelper = $searchHelper; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + protected function setupLimits() |
|
| 81 | + { |
|
| 82 | + $limit = WebRequest::getInt('limit'); |
|
| 83 | + if ($limit === null) { |
|
| 84 | + $limit = 100; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $page = WebRequest::getInt('page'); |
|
| 88 | + if ($page === null) { |
|
| 89 | + $page = 1; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $offset = ($page - 1) * $limit; |
|
| 93 | + |
|
| 94 | + $this->searchHelper->limit($limit, $offset); |
|
| 95 | + |
|
| 96 | + $this->page = $page; |
|
| 97 | + $this->limit = $limit; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + private function setupFormParameters($formParameters) |
|
| 101 | + { |
|
| 102 | + $formParameters['limit'] = $this->limit; |
|
| 103 | + $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
| 104 | + |
|
| 105 | + foreach ($formParameters as $key => $value) { |
|
| 106 | + $this->assign($key, $value); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -55,8 +55,7 @@ |
||
| 55 | 55 | if ($pageCount < $pageLimit) { |
| 56 | 56 | if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
| 57 | 57 | $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
| 58 | - } |
|
| 59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 58 | + } elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 60 | 59 | $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
| 61 | 60 | } |
| 62 | 61 | } |
@@ -23,245 +23,245 @@ |
||
| 23 | 23 | |
| 24 | 24 | abstract class InternalPageBase extends PageBase |
| 25 | 25 | { |
| 26 | - use NavigationMenuAccessControl; |
|
| 27 | - |
|
| 28 | - /** @var ITypeAheadHelper */ |
|
| 29 | - private $typeAheadHelper; |
|
| 30 | - /** @var SecurityManager */ |
|
| 31 | - private $securityManager; |
|
| 32 | - /** @var IBlacklistHelper */ |
|
| 33 | - private $blacklistHelper; |
|
| 34 | - /** @var DomainAccessManager */ |
|
| 35 | - private $domainAccessManager; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @return ITypeAheadHelper |
|
| 39 | - */ |
|
| 40 | - public function getTypeAheadHelper() |
|
| 41 | - { |
|
| 42 | - return $this->typeAheadHelper; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param ITypeAheadHelper $typeAheadHelper |
|
| 47 | - */ |
|
| 48 | - public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
| 49 | - { |
|
| 50 | - $this->typeAheadHelper = $typeAheadHelper; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Runs the page code |
|
| 55 | - * |
|
| 56 | - * @throws Exception |
|
| 57 | - * @category Security-Critical |
|
| 58 | - */ |
|
| 59 | - final public function execute() |
|
| 60 | - { |
|
| 61 | - if ($this->getRouteName() === null) { |
|
| 62 | - throw new Exception("Request is unrouted."); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if ($this->getSiteConfiguration() === null) { |
|
| 66 | - throw new Exception("Page has no configuration!"); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $this->setupPage(); |
|
| 70 | - |
|
| 71 | - $this->touchUserLastActive(); |
|
| 72 | - |
|
| 73 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 74 | - |
|
| 75 | - // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
| 76 | - if (!$this->isProtectedPage()) { |
|
| 77 | - // This page is /not/ a protected page, as such we can just run it. |
|
| 78 | - $this->runPage(); |
|
| 79 | - |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Security barrier. |
|
| 84 | - // |
|
| 85 | - // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
| 86 | - // away for us |
|
| 87 | - $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
| 88 | - if ($securityResult === SecurityManager::ALLOWED) { |
|
| 89 | - // We're allowed to run the page, so let's run it. |
|
| 90 | - $this->runPage(); |
|
| 91 | - } |
|
| 92 | - else { |
|
| 93 | - $this->handleAccessDenied($securityResult); |
|
| 94 | - |
|
| 95 | - // Send the headers |
|
| 96 | - $this->sendResponseHeaders(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Performs final tasks needed before rendering the page. |
|
| 102 | - */ |
|
| 103 | - final public function finalisePage() |
|
| 104 | - { |
|
| 105 | - parent::finalisePage(); |
|
| 106 | - |
|
| 107 | - $database = $this->getDatabase(); |
|
| 108 | - $currentUser = User::getCurrent($database); |
|
| 109 | - |
|
| 110 | - // Load in the badges for the navbar |
|
| 111 | - $this->setUpNavBarBadges($currentUser, $database); |
|
| 112 | - |
|
| 113 | - if ($this->barrierTest('viewSiteNotice', User::getCurrent($database), 'GlobalInfo')) { |
|
| 114 | - $siteNotice = SiteNotice::get($this->getDatabase()); |
|
| 115 | - $siteNoticeHash = sha1($siteNotice); |
|
| 116 | - |
|
| 117 | - if (WebRequest::testSiteNoticeCookieValue($siteNoticeHash)) { |
|
| 118 | - $this->assign('siteNoticeState', 'd-none'); |
|
| 119 | - } |
|
| 120 | - else { |
|
| 121 | - $this->assign('siteNoticeState', 'd-block'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $this->assign('siteNoticeText', $siteNotice); |
|
| 125 | - $this->assign('siteNoticeVersion', $siteNoticeHash); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ($this->barrierTest('viewOnlineUsers', User::getCurrent($database), 'GlobalInfo')) { |
|
| 129 | - $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
| 130 | - $statement = $database->query($sql); |
|
| 131 | - $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
| 132 | - $this->assign('onlineusers', $activeUsers); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $this->setupNavMenuAccess($currentUser); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Configures whether the page respects roles or not. You probably want this to return true. |
|
| 140 | - * |
|
| 141 | - * Set to false for public pages. You probably want this to return true. |
|
| 142 | - * |
|
| 143 | - * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
| 144 | - * on this page, so you probably want this to return true. |
|
| 145 | - * |
|
| 146 | - * @return bool |
|
| 147 | - * @category Security-Critical |
|
| 148 | - */ |
|
| 149 | - protected function isProtectedPage() |
|
| 150 | - { |
|
| 151 | - return true; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - protected function handleAccessDenied($denyReason) |
|
| 155 | - { |
|
| 156 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 157 | - |
|
| 158 | - // Not allowed to access this resource. |
|
| 159 | - // Firstly, let's check if we're even logged in. |
|
| 160 | - if ($currentUser->isCommunityUser()) { |
|
| 161 | - // Not logged in, redirect to login page |
|
| 162 | - WebRequest::setPostLoginRedirect(); |
|
| 163 | - $this->redirect("login"); |
|
| 164 | - |
|
| 165 | - return; |
|
| 166 | - } |
|
| 167 | - else { |
|
| 168 | - // Decide whether this was a rights failure, or an identification failure. |
|
| 169 | - |
|
| 170 | - if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
|
| 171 | - // Not identified |
|
| 172 | - throw new NotIdentifiedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 173 | - } |
|
| 174 | - elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
| 175 | - // Nope, plain old access denied |
|
| 176 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 177 | - } |
|
| 178 | - else { |
|
| 179 | - throw new Exception('Unknown response from security manager.'); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Tests the security barrier for a specified action. |
|
| 186 | - * |
|
| 187 | - * Don't use within templates |
|
| 188 | - * |
|
| 189 | - * @param string $action |
|
| 190 | - * |
|
| 191 | - * @param User $user |
|
| 192 | - * @param null|string $pageName |
|
| 193 | - * |
|
| 194 | - * @return bool |
|
| 195 | - * @category Security-Critical |
|
| 196 | - */ |
|
| 197 | - final public function barrierTest($action, User $user, $pageName = null) |
|
| 198 | - { |
|
| 199 | - $page = get_called_class(); |
|
| 200 | - if ($pageName !== null) { |
|
| 201 | - $page = $pageName; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
| 205 | - |
|
| 206 | - return $securityResult === SecurityManager::ALLOWED; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Updates the lastactive timestamp |
|
| 211 | - */ |
|
| 212 | - private function touchUserLastActive() |
|
| 213 | - { |
|
| 214 | - if (WebRequest::getSessionUserId() !== null) { |
|
| 215 | - $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
| 216 | - $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @return SecurityManager |
|
| 222 | - */ |
|
| 223 | - public function getSecurityManager() |
|
| 224 | - { |
|
| 225 | - return $this->securityManager; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @param SecurityManager $securityManager |
|
| 230 | - */ |
|
| 231 | - public function setSecurityManager(SecurityManager $securityManager) |
|
| 232 | - { |
|
| 233 | - $this->securityManager = $securityManager; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @return IBlacklistHelper |
|
| 238 | - */ |
|
| 239 | - public function getBlacklistHelper() |
|
| 240 | - { |
|
| 241 | - return $this->blacklistHelper; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param IBlacklistHelper $blacklistHelper |
|
| 246 | - */ |
|
| 247 | - public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
| 248 | - { |
|
| 249 | - $this->blacklistHelper = $blacklistHelper; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @return DomainAccessManager |
|
| 254 | - */ |
|
| 255 | - public function getDomainAccessManager(): DomainAccessManager |
|
| 256 | - { |
|
| 257 | - return $this->domainAccessManager; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @param DomainAccessManager $domainAccessManager |
|
| 262 | - */ |
|
| 263 | - public function setDomainAccessManager(DomainAccessManager $domainAccessManager): void |
|
| 264 | - { |
|
| 265 | - $this->domainAccessManager = $domainAccessManager; |
|
| 266 | - } |
|
| 26 | + use NavigationMenuAccessControl; |
|
| 27 | + |
|
| 28 | + /** @var ITypeAheadHelper */ |
|
| 29 | + private $typeAheadHelper; |
|
| 30 | + /** @var SecurityManager */ |
|
| 31 | + private $securityManager; |
|
| 32 | + /** @var IBlacklistHelper */ |
|
| 33 | + private $blacklistHelper; |
|
| 34 | + /** @var DomainAccessManager */ |
|
| 35 | + private $domainAccessManager; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @return ITypeAheadHelper |
|
| 39 | + */ |
|
| 40 | + public function getTypeAheadHelper() |
|
| 41 | + { |
|
| 42 | + return $this->typeAheadHelper; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param ITypeAheadHelper $typeAheadHelper |
|
| 47 | + */ |
|
| 48 | + public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
| 49 | + { |
|
| 50 | + $this->typeAheadHelper = $typeAheadHelper; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Runs the page code |
|
| 55 | + * |
|
| 56 | + * @throws Exception |
|
| 57 | + * @category Security-Critical |
|
| 58 | + */ |
|
| 59 | + final public function execute() |
|
| 60 | + { |
|
| 61 | + if ($this->getRouteName() === null) { |
|
| 62 | + throw new Exception("Request is unrouted."); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if ($this->getSiteConfiguration() === null) { |
|
| 66 | + throw new Exception("Page has no configuration!"); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $this->setupPage(); |
|
| 70 | + |
|
| 71 | + $this->touchUserLastActive(); |
|
| 72 | + |
|
| 73 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 74 | + |
|
| 75 | + // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
| 76 | + if (!$this->isProtectedPage()) { |
|
| 77 | + // This page is /not/ a protected page, as such we can just run it. |
|
| 78 | + $this->runPage(); |
|
| 79 | + |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Security barrier. |
|
| 84 | + // |
|
| 85 | + // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
| 86 | + // away for us |
|
| 87 | + $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
| 88 | + if ($securityResult === SecurityManager::ALLOWED) { |
|
| 89 | + // We're allowed to run the page, so let's run it. |
|
| 90 | + $this->runPage(); |
|
| 91 | + } |
|
| 92 | + else { |
|
| 93 | + $this->handleAccessDenied($securityResult); |
|
| 94 | + |
|
| 95 | + // Send the headers |
|
| 96 | + $this->sendResponseHeaders(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Performs final tasks needed before rendering the page. |
|
| 102 | + */ |
|
| 103 | + final public function finalisePage() |
|
| 104 | + { |
|
| 105 | + parent::finalisePage(); |
|
| 106 | + |
|
| 107 | + $database = $this->getDatabase(); |
|
| 108 | + $currentUser = User::getCurrent($database); |
|
| 109 | + |
|
| 110 | + // Load in the badges for the navbar |
|
| 111 | + $this->setUpNavBarBadges($currentUser, $database); |
|
| 112 | + |
|
| 113 | + if ($this->barrierTest('viewSiteNotice', User::getCurrent($database), 'GlobalInfo')) { |
|
| 114 | + $siteNotice = SiteNotice::get($this->getDatabase()); |
|
| 115 | + $siteNoticeHash = sha1($siteNotice); |
|
| 116 | + |
|
| 117 | + if (WebRequest::testSiteNoticeCookieValue($siteNoticeHash)) { |
|
| 118 | + $this->assign('siteNoticeState', 'd-none'); |
|
| 119 | + } |
|
| 120 | + else { |
|
| 121 | + $this->assign('siteNoticeState', 'd-block'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $this->assign('siteNoticeText', $siteNotice); |
|
| 125 | + $this->assign('siteNoticeVersion', $siteNoticeHash); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ($this->barrierTest('viewOnlineUsers', User::getCurrent($database), 'GlobalInfo')) { |
|
| 129 | + $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
| 130 | + $statement = $database->query($sql); |
|
| 131 | + $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
| 132 | + $this->assign('onlineusers', $activeUsers); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $this->setupNavMenuAccess($currentUser); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Configures whether the page respects roles or not. You probably want this to return true. |
|
| 140 | + * |
|
| 141 | + * Set to false for public pages. You probably want this to return true. |
|
| 142 | + * |
|
| 143 | + * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
| 144 | + * on this page, so you probably want this to return true. |
|
| 145 | + * |
|
| 146 | + * @return bool |
|
| 147 | + * @category Security-Critical |
|
| 148 | + */ |
|
| 149 | + protected function isProtectedPage() |
|
| 150 | + { |
|
| 151 | + return true; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + protected function handleAccessDenied($denyReason) |
|
| 155 | + { |
|
| 156 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 157 | + |
|
| 158 | + // Not allowed to access this resource. |
|
| 159 | + // Firstly, let's check if we're even logged in. |
|
| 160 | + if ($currentUser->isCommunityUser()) { |
|
| 161 | + // Not logged in, redirect to login page |
|
| 162 | + WebRequest::setPostLoginRedirect(); |
|
| 163 | + $this->redirect("login"); |
|
| 164 | + |
|
| 165 | + return; |
|
| 166 | + } |
|
| 167 | + else { |
|
| 168 | + // Decide whether this was a rights failure, or an identification failure. |
|
| 169 | + |
|
| 170 | + if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
|
| 171 | + // Not identified |
|
| 172 | + throw new NotIdentifiedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 173 | + } |
|
| 174 | + elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
| 175 | + // Nope, plain old access denied |
|
| 176 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | + throw new Exception('Unknown response from security manager.'); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Tests the security barrier for a specified action. |
|
| 186 | + * |
|
| 187 | + * Don't use within templates |
|
| 188 | + * |
|
| 189 | + * @param string $action |
|
| 190 | + * |
|
| 191 | + * @param User $user |
|
| 192 | + * @param null|string $pageName |
|
| 193 | + * |
|
| 194 | + * @return bool |
|
| 195 | + * @category Security-Critical |
|
| 196 | + */ |
|
| 197 | + final public function barrierTest($action, User $user, $pageName = null) |
|
| 198 | + { |
|
| 199 | + $page = get_called_class(); |
|
| 200 | + if ($pageName !== null) { |
|
| 201 | + $page = $pageName; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
| 205 | + |
|
| 206 | + return $securityResult === SecurityManager::ALLOWED; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Updates the lastactive timestamp |
|
| 211 | + */ |
|
| 212 | + private function touchUserLastActive() |
|
| 213 | + { |
|
| 214 | + if (WebRequest::getSessionUserId() !== null) { |
|
| 215 | + $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
| 216 | + $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @return SecurityManager |
|
| 222 | + */ |
|
| 223 | + public function getSecurityManager() |
|
| 224 | + { |
|
| 225 | + return $this->securityManager; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @param SecurityManager $securityManager |
|
| 230 | + */ |
|
| 231 | + public function setSecurityManager(SecurityManager $securityManager) |
|
| 232 | + { |
|
| 233 | + $this->securityManager = $securityManager; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @return IBlacklistHelper |
|
| 238 | + */ |
|
| 239 | + public function getBlacklistHelper() |
|
| 240 | + { |
|
| 241 | + return $this->blacklistHelper; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param IBlacklistHelper $blacklistHelper |
|
| 246 | + */ |
|
| 247 | + public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
| 248 | + { |
|
| 249 | + $this->blacklistHelper = $blacklistHelper; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @return DomainAccessManager |
|
| 254 | + */ |
|
| 255 | + public function getDomainAccessManager(): DomainAccessManager |
|
| 256 | + { |
|
| 257 | + return $this->domainAccessManager; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @param DomainAccessManager $domainAccessManager |
|
| 262 | + */ |
|
| 263 | + public function setDomainAccessManager(DomainAccessManager $domainAccessManager): void |
|
| 264 | + { |
|
| 265 | + $this->domainAccessManager = $domainAccessManager; |
|
| 266 | + } |
|
| 267 | 267 | } |
@@ -88,8 +88,7 @@ discard block |
||
| 88 | 88 | if ($securityResult === SecurityManager::ALLOWED) { |
| 89 | 89 | // We're allowed to run the page, so let's run it. |
| 90 | 90 | $this->runPage(); |
| 91 | - } |
|
| 92 | - else { |
|
| 91 | + } else { |
|
| 93 | 92 | $this->handleAccessDenied($securityResult); |
| 94 | 93 | |
| 95 | 94 | // Send the headers |
@@ -116,8 +115,7 @@ discard block |
||
| 116 | 115 | |
| 117 | 116 | if (WebRequest::testSiteNoticeCookieValue($siteNoticeHash)) { |
| 118 | 117 | $this->assign('siteNoticeState', 'd-none'); |
| 119 | - } |
|
| 120 | - else { |
|
| 118 | + } else { |
|
| 121 | 119 | $this->assign('siteNoticeState', 'd-block'); |
| 122 | 120 | } |
| 123 | 121 | |
@@ -163,19 +161,16 @@ discard block |
||
| 163 | 161 | $this->redirect("login"); |
| 164 | 162 | |
| 165 | 163 | return; |
| 166 | - } |
|
| 167 | - else { |
|
| 164 | + } else { |
|
| 168 | 165 | // Decide whether this was a rights failure, or an identification failure. |
| 169 | 166 | |
| 170 | 167 | if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) { |
| 171 | 168 | // Not identified |
| 172 | 169 | throw new NotIdentifiedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
| 173 | - } |
|
| 174 | - elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
| 170 | + } elseif ($denyReason === SecurityManager::ERROR_DENIED) { |
|
| 175 | 171 | // Nope, plain old access denied |
| 176 | 172 | throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
| 177 | - } |
|
| 178 | - else { |
|
| 173 | + } else { |
|
| 179 | 174 | throw new Exception('Unknown response from security manager.'); |
| 180 | 175 | } |
| 181 | 176 | } |
@@ -22,137 +22,137 @@ |
||
| 22 | 22 | |
| 23 | 23 | interface ITask |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @return IEmailHelper |
|
| 27 | - */ |
|
| 28 | - public function getEmailHelper(); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param IEmailHelper $emailHelper |
|
| 32 | - * |
|
| 33 | - * @return void |
|
| 34 | - */ |
|
| 35 | - public function setEmailHelper($emailHelper); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @return HttpHelper |
|
| 39 | - */ |
|
| 40 | - public function getHttpHelper(); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param HttpHelper $httpHelper |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function setHttpHelper($httpHelper); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @return ILocationProvider |
|
| 51 | - */ |
|
| 52 | - public function getLocationProvider(); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param ILocationProvider $locationProvider |
|
| 56 | - * |
|
| 57 | - * @return void |
|
| 58 | - */ |
|
| 59 | - public function setLocationProvider(ILocationProvider $locationProvider); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @return IXffTrustProvider |
|
| 63 | - */ |
|
| 64 | - public function getXffTrustProvider(); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param IXffTrustProvider $xffTrustProvider |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @return IRDnsProvider |
|
| 75 | - */ |
|
| 76 | - public function getRdnsProvider(); |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param IRDnsProvider $rdnsProvider |
|
| 80 | - * |
|
| 81 | - * @return void |
|
| 82 | - */ |
|
| 83 | - public function setRdnsProvider($rdnsProvider); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return IAntiSpoofProvider |
|
| 87 | - */ |
|
| 88 | - public function getAntiSpoofProvider(); |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 92 | - * |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function setAntiSpoofProvider($antiSpoofProvider); |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return PdoDatabase |
|
| 99 | - */ |
|
| 100 | - public function getDatabase(); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param PdoDatabase $database |
|
| 104 | - * |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public function setDatabase($database); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return IOAuthProtocolHelper |
|
| 111 | - */ |
|
| 112 | - public function getOAuthProtocolHelper(); |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 116 | - * |
|
| 117 | - * @return void |
|
| 118 | - */ |
|
| 119 | - public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public function execute(); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Sets the site configuration object for this page |
|
| 128 | - * |
|
| 129 | - * @param SiteConfiguration $configuration |
|
| 130 | - * |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - public function setSiteConfiguration($configuration); |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return IrcNotificationHelper |
|
| 137 | - */ |
|
| 138 | - public function getNotificationHelper(); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param IrcNotificationHelper $notificationHelper |
|
| 142 | - * |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public function setNotificationHelper($notificationHelper); |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return TorExitProvider |
|
| 149 | - */ |
|
| 150 | - public function getTorExitProvider(); |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param TorExitProvider $torExitProvider |
|
| 154 | - * |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - public function setTorExitProvider($torExitProvider); |
|
| 25 | + /** |
|
| 26 | + * @return IEmailHelper |
|
| 27 | + */ |
|
| 28 | + public function getEmailHelper(); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param IEmailHelper $emailHelper |
|
| 32 | + * |
|
| 33 | + * @return void |
|
| 34 | + */ |
|
| 35 | + public function setEmailHelper($emailHelper); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @return HttpHelper |
|
| 39 | + */ |
|
| 40 | + public function getHttpHelper(); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param HttpHelper $httpHelper |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function setHttpHelper($httpHelper); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @return ILocationProvider |
|
| 51 | + */ |
|
| 52 | + public function getLocationProvider(); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param ILocationProvider $locationProvider |
|
| 56 | + * |
|
| 57 | + * @return void |
|
| 58 | + */ |
|
| 59 | + public function setLocationProvider(ILocationProvider $locationProvider); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @return IXffTrustProvider |
|
| 63 | + */ |
|
| 64 | + public function getXffTrustProvider(); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param IXffTrustProvider $xffTrustProvider |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @return IRDnsProvider |
|
| 75 | + */ |
|
| 76 | + public function getRdnsProvider(); |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param IRDnsProvider $rdnsProvider |
|
| 80 | + * |
|
| 81 | + * @return void |
|
| 82 | + */ |
|
| 83 | + public function setRdnsProvider($rdnsProvider); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return IAntiSpoofProvider |
|
| 87 | + */ |
|
| 88 | + public function getAntiSpoofProvider(); |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
| 92 | + * |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function setAntiSpoofProvider($antiSpoofProvider); |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return PdoDatabase |
|
| 99 | + */ |
|
| 100 | + public function getDatabase(); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param PdoDatabase $database |
|
| 104 | + * |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public function setDatabase($database); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return IOAuthProtocolHelper |
|
| 111 | + */ |
|
| 112 | + public function getOAuthProtocolHelper(); |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 116 | + * |
|
| 117 | + * @return void |
|
| 118 | + */ |
|
| 119 | + public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public function execute(); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Sets the site configuration object for this page |
|
| 128 | + * |
|
| 129 | + * @param SiteConfiguration $configuration |
|
| 130 | + * |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + public function setSiteConfiguration($configuration); |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return IrcNotificationHelper |
|
| 137 | + */ |
|
| 138 | + public function getNotificationHelper(); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param IrcNotificationHelper $notificationHelper |
|
| 142 | + * |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public function setNotificationHelper($notificationHelper); |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return TorExitProvider |
|
| 149 | + */ |
|
| 150 | + public function getTorExitProvider(); |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param TorExitProvider $torExitProvider |
|
| 154 | + * |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + public function setTorExitProvider($torExitProvider); |
|
| 158 | 158 | } |
| 159 | 159 | \ No newline at end of file |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RequestList |
| 18 | 18 | { |
| 19 | - public $requests; |
|
| 20 | - public $showPrivateData; |
|
| 21 | - public $dataClearEmail; |
|
| 22 | - public $dataClearIp; |
|
| 23 | - public $relatedEmailRequests; |
|
| 24 | - public $relatedIpRequests; |
|
| 25 | - public $requestTrustedIp; |
|
| 26 | - public $canBan; |
|
| 27 | - public $canBreakReservation; |
|
| 28 | - public $userList; |
|
| 29 | - public $commonEmail; |
|
| 19 | + public $requests; |
|
| 20 | + public $showPrivateData; |
|
| 21 | + public $dataClearEmail; |
|
| 22 | + public $dataClearIp; |
|
| 23 | + public $relatedEmailRequests; |
|
| 24 | + public $relatedIpRequests; |
|
| 25 | + public $requestTrustedIp; |
|
| 26 | + public $canBan; |
|
| 27 | + public $canBreakReservation; |
|
| 28 | + public $userList; |
|
| 29 | + public $commonEmail; |
|
| 30 | 30 | } |