@@ -10,12 +10,12 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface IBlacklistHelper |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist |
|
| 15 | - * |
|
| 16 | - * @param string $username |
|
| 17 | - * |
|
| 18 | - * @return bool |
|
| 19 | - */ |
|
| 20 | - public function isBlacklisted($username); |
|
| 13 | + /** |
|
| 14 | + * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist |
|
| 15 | + * |
|
| 16 | + * @param string $username |
|
| 17 | + * |
|
| 18 | + * @return bool |
|
| 19 | + */ |
|
| 20 | + public function isBlacklisted($username); |
|
| 21 | 21 | } |
| 22 | 22 | \ No newline at end of file |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface ITypeAheadHelper |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param string $class CSS class to apply this typeahead to. |
|
| 15 | - * @param callable $generator Generator function taking no arguments to return an array of strings. |
|
| 16 | - * |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - public function defineTypeAheadSource($class, callable $generator); |
|
| 13 | + /** |
|
| 14 | + * @param string $class CSS class to apply this typeahead to. |
|
| 15 | + * @param callable $generator Generator function taking no arguments to return an array of strings. |
|
| 16 | + * |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + public function defineTypeAheadSource($class, callable $generator); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @return string HTML fragment containing a JS block for typeaheads. |
|
| 23 | - */ |
|
| 24 | - public function getTypeAheadScriptBlock(); |
|
| 21 | + /** |
|
| 22 | + * @return string HTML fragment containing a JS block for typeaheads. |
|
| 23 | + */ |
|
| 24 | + public function getTypeAheadScriptBlock(); |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -22,73 +22,73 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Notification extends DataObject |
| 24 | 24 | { |
| 25 | - private $date; |
|
| 26 | - private $type; |
|
| 27 | - private $text; |
|
| 25 | + private $date; |
|
| 26 | + private $type; |
|
| 27 | + private $text; |
|
| 28 | 28 | |
| 29 | - public function delete() |
|
| 30 | - { |
|
| 31 | - throw new Exception("You shouldn't be doing this..."); |
|
| 32 | - } |
|
| 29 | + public function delete() |
|
| 30 | + { |
|
| 31 | + throw new Exception("You shouldn't be doing this..."); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function save() |
|
| 35 | - { |
|
| 36 | - if ($this->isNew()) { |
|
| 37 | - // insert |
|
| 38 | - $statement = $this->dbObject->prepare("INSERT INTO notification ( type, text ) VALUES ( :type, :text );"); |
|
| 39 | - $statement->bindValue(":type", $this->type); |
|
| 40 | - $statement->bindValue(":text", $this->text); |
|
| 34 | + public function save() |
|
| 35 | + { |
|
| 36 | + if ($this->isNew()) { |
|
| 37 | + // insert |
|
| 38 | + $statement = $this->dbObject->prepare("INSERT INTO notification ( type, text ) VALUES ( :type, :text );"); |
|
| 39 | + $statement->bindValue(":type", $this->type); |
|
| 40 | + $statement->bindValue(":text", $this->text); |
|
| 41 | 41 | |
| 42 | - if ($statement->execute()) { |
|
| 43 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 44 | - } |
|
| 45 | - else { |
|
| 46 | - throw new Exception($statement->errorInfo()); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - else { |
|
| 50 | - throw new Exception("You shouldn't be doing this..."); |
|
| 51 | - } |
|
| 52 | - } |
|
| 42 | + if ($statement->execute()) { |
|
| 43 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 44 | + } |
|
| 45 | + else { |
|
| 46 | + throw new Exception($statement->errorInfo()); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + else { |
|
| 50 | + throw new Exception("You shouldn't be doing this..."); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function getDate() |
|
| 55 | - { |
|
| 56 | - return new DateTimeImmutable($this->date); |
|
| 57 | - } |
|
| 54 | + public function getDate() |
|
| 55 | + { |
|
| 56 | + return new DateTimeImmutable($this->date); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return int |
|
| 61 | - */ |
|
| 62 | - public function getType() |
|
| 63 | - { |
|
| 64 | - return $this->type; |
|
| 65 | - } |
|
| 59 | + /** |
|
| 60 | + * @return int |
|
| 61 | + */ |
|
| 62 | + public function getType() |
|
| 63 | + { |
|
| 64 | + return $this->type; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function getText() |
|
| 71 | - { |
|
| 72 | - return $this->text; |
|
| 73 | - } |
|
| 67 | + /** |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function getText() |
|
| 71 | + { |
|
| 72 | + return $this->text; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Summary of setType |
|
| 77 | - * |
|
| 78 | - * @param int $type |
|
| 79 | - */ |
|
| 80 | - public function setType($type) |
|
| 81 | - { |
|
| 82 | - $this->type = $type; |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * Summary of setType |
|
| 77 | + * |
|
| 78 | + * @param int $type |
|
| 79 | + */ |
|
| 80 | + public function setType($type) |
|
| 81 | + { |
|
| 82 | + $this->type = $type; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Summary of setText |
|
| 87 | - * |
|
| 88 | - * @param string $text |
|
| 89 | - */ |
|
| 90 | - public function setText($text) |
|
| 91 | - { |
|
| 92 | - $this->text = $text; |
|
| 93 | - } |
|
| 85 | + /** |
|
| 86 | + * Summary of setText |
|
| 87 | + * |
|
| 88 | + * @param string $text |
|
| 89 | + */ |
|
| 90 | + public function setText($text) |
|
| 91 | + { |
|
| 92 | + $this->text = $text; |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -18,101 +18,101 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class AntiSpoofCache extends DataObject |
| 20 | 20 | { |
| 21 | - /** @var string */ |
|
| 22 | - protected $username; |
|
| 23 | - /** @var string */ |
|
| 24 | - protected $data; |
|
| 25 | - /** @var string */ |
|
| 26 | - protected $timestamp; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @param string $username |
|
| 30 | - * @param PdoDatabase $database |
|
| 31 | - * |
|
| 32 | - * @return AntiSpoofCache|false |
|
| 33 | - */ |
|
| 34 | - public static function getByUsername($username, PdoDatabase $database) |
|
| 35 | - { |
|
| 36 | - $statement = $database->prepare(<<<SQL |
|
| 21 | + /** @var string */ |
|
| 22 | + protected $username; |
|
| 23 | + /** @var string */ |
|
| 24 | + protected $data; |
|
| 25 | + /** @var string */ |
|
| 26 | + protected $timestamp; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @param string $username |
|
| 30 | + * @param PdoDatabase $database |
|
| 31 | + * |
|
| 32 | + * @return AntiSpoofCache|false |
|
| 33 | + */ |
|
| 34 | + public static function getByUsername($username, PdoDatabase $database) |
|
| 35 | + { |
|
| 36 | + $statement = $database->prepare(<<<SQL |
|
| 37 | 37 | SELECT * |
| 38 | 38 | FROM antispoofcache |
| 39 | 39 | WHERE username = :id AND timestamp > date_sub(now(), INTERVAL 3 HOUR) |
| 40 | 40 | LIMIT 1 |
| 41 | 41 | SQL |
| 42 | - ); |
|
| 43 | - $statement->bindValue(":id", $username); |
|
| 44 | - |
|
| 45 | - $statement->execute(); |
|
| 46 | - |
|
| 47 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 48 | - |
|
| 49 | - if ($resultObject != false) { |
|
| 50 | - $resultObject->setDatabase($database); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $resultObject; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function getUsername() |
|
| 60 | - { |
|
| 61 | - return $this->username; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param string $username |
|
| 66 | - */ |
|
| 67 | - public function setUsername($username) |
|
| 68 | - { |
|
| 69 | - $this->username = $username; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public function getData() |
|
| 76 | - { |
|
| 77 | - return $this->data; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param string $data |
|
| 82 | - */ |
|
| 83 | - public function setData($data) |
|
| 84 | - { |
|
| 85 | - $this->data = $data; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return DateTimeImmutable |
|
| 90 | - */ |
|
| 91 | - public function getTimestamp() |
|
| 92 | - { |
|
| 93 | - return new DateTimeImmutable($this->timestamp); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @throws Exception |
|
| 98 | - */ |
|
| 99 | - public function save() |
|
| 100 | - { |
|
| 101 | - if ($this->isNew()) { |
|
| 102 | - // insert |
|
| 103 | - // clear old data first |
|
| 104 | - $this->dbObject->exec("DELETE FROM antispoofcache WHERE timestamp < date_sub(now(), INTERVAL 3 HOUR);"); |
|
| 105 | - |
|
| 106 | - $statement = $this->dbObject->prepare("INSERT INTO antispoofcache (username, data) VALUES (:username, :data);"); |
|
| 107 | - $statement->bindValue(":username", $this->username); |
|
| 108 | - $statement->bindValue(":data", $this->data); |
|
| 109 | - |
|
| 110 | - if ($statement->execute()) { |
|
| 111 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 112 | - } |
|
| 113 | - else { |
|
| 114 | - throw new Exception($statement->errorInfo()); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 42 | + ); |
|
| 43 | + $statement->bindValue(":id", $username); |
|
| 44 | + |
|
| 45 | + $statement->execute(); |
|
| 46 | + |
|
| 47 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 48 | + |
|
| 49 | + if ($resultObject != false) { |
|
| 50 | + $resultObject->setDatabase($database); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $resultObject; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function getUsername() |
|
| 60 | + { |
|
| 61 | + return $this->username; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param string $username |
|
| 66 | + */ |
|
| 67 | + public function setUsername($username) |
|
| 68 | + { |
|
| 69 | + $this->username = $username; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public function getData() |
|
| 76 | + { |
|
| 77 | + return $this->data; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param string $data |
|
| 82 | + */ |
|
| 83 | + public function setData($data) |
|
| 84 | + { |
|
| 85 | + $this->data = $data; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return DateTimeImmutable |
|
| 90 | + */ |
|
| 91 | + public function getTimestamp() |
|
| 92 | + { |
|
| 93 | + return new DateTimeImmutable($this->timestamp); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @throws Exception |
|
| 98 | + */ |
|
| 99 | + public function save() |
|
| 100 | + { |
|
| 101 | + if ($this->isNew()) { |
|
| 102 | + // insert |
|
| 103 | + // clear old data first |
|
| 104 | + $this->dbObject->exec("DELETE FROM antispoofcache WHERE timestamp < date_sub(now(), INTERVAL 3 HOUR);"); |
|
| 105 | + |
|
| 106 | + $statement = $this->dbObject->prepare("INSERT INTO antispoofcache (username, data) VALUES (:username, :data);"); |
|
| 107 | + $statement->bindValue(":username", $this->username); |
|
| 108 | + $statement->bindValue(":data", $this->data); |
|
| 109 | + |
|
| 110 | + if ($statement->execute()) { |
|
| 111 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 112 | + } |
|
| 113 | + else { |
|
| 114 | + throw new Exception($statement->errorInfo()); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -17,151 +17,151 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Log extends DataObject |
| 19 | 19 | { |
| 20 | - /** @var int */ |
|
| 21 | - private $objectid; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $objecttype; |
|
| 24 | - /** @var int */ |
|
| 25 | - private $user; |
|
| 26 | - /** @var string */ |
|
| 27 | - private $action; |
|
| 28 | - private $timestamp; |
|
| 29 | - /** @var string|null */ |
|
| 30 | - private $comment; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @throws Exception |
|
| 34 | - */ |
|
| 35 | - public function save() |
|
| 36 | - { |
|
| 37 | - if ($this->isNew()) { |
|
| 38 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 20 | + /** @var int */ |
|
| 21 | + private $objectid; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $objecttype; |
|
| 24 | + /** @var int */ |
|
| 25 | + private $user; |
|
| 26 | + /** @var string */ |
|
| 27 | + private $action; |
|
| 28 | + private $timestamp; |
|
| 29 | + /** @var string|null */ |
|
| 30 | + private $comment; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @throws Exception |
|
| 34 | + */ |
|
| 35 | + public function save() |
|
| 36 | + { |
|
| 37 | + if ($this->isNew()) { |
|
| 38 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 39 | 39 | INSERT INTO log (objectid, objecttype, user, action, timestamp, comment) |
| 40 | 40 | VALUES (:id, :type, :user, :action, CURRENT_TIMESTAMP(), :comment); |
| 41 | 41 | SQL |
| 42 | - ); |
|
| 43 | - |
|
| 44 | - $statement->bindValue(":id", $this->objectid); |
|
| 45 | - $statement->bindValue(":type", $this->objecttype); |
|
| 46 | - $statement->bindValue(":user", $this->user); |
|
| 47 | - $statement->bindValue(":action", $this->action); |
|
| 48 | - $statement->bindValue(":comment", $this->comment); |
|
| 49 | - |
|
| 50 | - if ($statement->execute()) { |
|
| 51 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 52 | - } |
|
| 53 | - else { |
|
| 54 | - throw new Exception($statement->errorInfo()); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - throw new Exception("Updating logs is not available"); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @throws Exception |
|
| 64 | - */ |
|
| 65 | - public function delete() |
|
| 66 | - { |
|
| 67 | - throw new Exception("Deleting logs is not available."); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return int |
|
| 72 | - */ |
|
| 73 | - public function getObjectId() |
|
| 74 | - { |
|
| 75 | - return $this->objectid; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Summary of setObjectId |
|
| 80 | - * |
|
| 81 | - * @param int $objectId |
|
| 82 | - */ |
|
| 83 | - public function setObjectId($objectId) |
|
| 84 | - { |
|
| 85 | - $this->objectid = $objectId; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function getObjectType() |
|
| 92 | - { |
|
| 93 | - return $this->objecttype; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Summary of setObjectType |
|
| 98 | - * |
|
| 99 | - * @param string $objectType |
|
| 100 | - */ |
|
| 101 | - public function setObjectType($objectType) |
|
| 102 | - { |
|
| 103 | - $this->objecttype = $objectType; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return int |
|
| 108 | - */ |
|
| 109 | - public function getUser() |
|
| 110 | - { |
|
| 111 | - return $this->user; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Summary of setUser |
|
| 116 | - * |
|
| 117 | - * @param User $user |
|
| 118 | - */ |
|
| 119 | - public function setUser(User $user) |
|
| 120 | - { |
|
| 121 | - $this->user = $user->getId(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function getAction() |
|
| 128 | - { |
|
| 129 | - return $this->action; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Summary of setAction |
|
| 134 | - * |
|
| 135 | - * @param string $action |
|
| 136 | - */ |
|
| 137 | - public function setAction($action) |
|
| 138 | - { |
|
| 139 | - $this->action = $action; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return DateTimeImmutable |
|
| 144 | - */ |
|
| 145 | - public function getTimestamp() |
|
| 146 | - { |
|
| 147 | - return new DateTimeImmutable($this->timestamp); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return string|null |
|
| 152 | - */ |
|
| 153 | - public function getComment() |
|
| 154 | - { |
|
| 155 | - return $this->comment; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Summary of setComment |
|
| 160 | - * |
|
| 161 | - * @param string $comment |
|
| 162 | - */ |
|
| 163 | - public function setComment($comment) |
|
| 164 | - { |
|
| 165 | - $this->comment = $comment; |
|
| 166 | - } |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $statement->bindValue(":id", $this->objectid); |
|
| 45 | + $statement->bindValue(":type", $this->objecttype); |
|
| 46 | + $statement->bindValue(":user", $this->user); |
|
| 47 | + $statement->bindValue(":action", $this->action); |
|
| 48 | + $statement->bindValue(":comment", $this->comment); |
|
| 49 | + |
|
| 50 | + if ($statement->execute()) { |
|
| 51 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 52 | + } |
|
| 53 | + else { |
|
| 54 | + throw new Exception($statement->errorInfo()); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + throw new Exception("Updating logs is not available"); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @throws Exception |
|
| 64 | + */ |
|
| 65 | + public function delete() |
|
| 66 | + { |
|
| 67 | + throw new Exception("Deleting logs is not available."); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return int |
|
| 72 | + */ |
|
| 73 | + public function getObjectId() |
|
| 74 | + { |
|
| 75 | + return $this->objectid; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Summary of setObjectId |
|
| 80 | + * |
|
| 81 | + * @param int $objectId |
|
| 82 | + */ |
|
| 83 | + public function setObjectId($objectId) |
|
| 84 | + { |
|
| 85 | + $this->objectid = $objectId; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function getObjectType() |
|
| 92 | + { |
|
| 93 | + return $this->objecttype; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Summary of setObjectType |
|
| 98 | + * |
|
| 99 | + * @param string $objectType |
|
| 100 | + */ |
|
| 101 | + public function setObjectType($objectType) |
|
| 102 | + { |
|
| 103 | + $this->objecttype = $objectType; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return int |
|
| 108 | + */ |
|
| 109 | + public function getUser() |
|
| 110 | + { |
|
| 111 | + return $this->user; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Summary of setUser |
|
| 116 | + * |
|
| 117 | + * @param User $user |
|
| 118 | + */ |
|
| 119 | + public function setUser(User $user) |
|
| 120 | + { |
|
| 121 | + $this->user = $user->getId(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function getAction() |
|
| 128 | + { |
|
| 129 | + return $this->action; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Summary of setAction |
|
| 134 | + * |
|
| 135 | + * @param string $action |
|
| 136 | + */ |
|
| 137 | + public function setAction($action) |
|
| 138 | + { |
|
| 139 | + $this->action = $action; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return DateTimeImmutable |
|
| 144 | + */ |
|
| 145 | + public function getTimestamp() |
|
| 146 | + { |
|
| 147 | + return new DateTimeImmutable($this->timestamp); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return string|null |
|
| 152 | + */ |
|
| 153 | + public function getComment() |
|
| 154 | + { |
|
| 155 | + return $this->comment; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Summary of setComment |
|
| 160 | + * |
|
| 161 | + * @param string $comment |
|
| 162 | + */ |
|
| 163 | + public function setComment($comment) |
|
| 164 | + { |
|
| 165 | + $this->comment = $comment; |
|
| 166 | + } |
|
| 167 | 167 | } |
@@ -17,25 +17,25 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Session |
| 19 | 19 | { |
| 20 | - public static function start() |
|
| 21 | - { |
|
| 22 | - ini_set('session.cookie_httponly', 1); |
|
| 20 | + public static function start() |
|
| 21 | + { |
|
| 22 | + ini_set('session.cookie_httponly', 1); |
|
| 23 | 23 | |
| 24 | - if (WebRequest::isHttps()) { |
|
| 25 | - ini_set('session.cookie_secure', 1); |
|
| 26 | - } |
|
| 24 | + if (WebRequest::isHttps()) { |
|
| 25 | + ini_set('session.cookie_secure', 1); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - session_start(); |
|
| 29 | - } |
|
| 28 | + session_start(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public static function destroy() |
|
| 32 | - { |
|
| 33 | - session_destroy(); |
|
| 34 | - } |
|
| 31 | + public static function destroy() |
|
| 32 | + { |
|
| 33 | + session_destroy(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public static function restart() |
|
| 37 | - { |
|
| 38 | - self::destroy(); |
|
| 39 | - self::start(); |
|
| 40 | - } |
|
| 36 | + public static function restart() |
|
| 37 | + { |
|
| 38 | + self::destroy(); |
|
| 39 | + self::start(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ApiException extends Exception |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param string $message |
|
| 20 | - */ |
|
| 21 | - public function __construct($message) |
|
| 22 | - { |
|
| 23 | - $this->message = $message; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $message |
|
| 20 | + */ |
|
| 21 | + public function __construct($message) |
|
| 22 | + { |
|
| 23 | + $this->message = $message; |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -22,77 +22,77 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class CachedApiAntispoofProvider implements IAntiSpoofProvider |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var PdoDatabase |
|
| 27 | - */ |
|
| 28 | - private $database; |
|
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - private $mediawikiWebServiceEndpoint; |
|
| 33 | - /** |
|
| 34 | - * @var HttpHelper |
|
| 35 | - */ |
|
| 36 | - private $httpHelper; |
|
| 25 | + /** |
|
| 26 | + * @var PdoDatabase |
|
| 27 | + */ |
|
| 28 | + private $database; |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + private $mediawikiWebServiceEndpoint; |
|
| 33 | + /** |
|
| 34 | + * @var HttpHelper |
|
| 35 | + */ |
|
| 36 | + private $httpHelper; |
|
| 37 | 37 | |
| 38 | - public function __construct(PdoDatabase $database, $mediawikiWebServiceEndpoint, HttpHelper $httpHelper) |
|
| 39 | - { |
|
| 40 | - $this->database = $database; |
|
| 41 | - $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint; |
|
| 42 | - $this->httpHelper = $httpHelper; |
|
| 43 | - } |
|
| 38 | + public function __construct(PdoDatabase $database, $mediawikiWebServiceEndpoint, HttpHelper $httpHelper) |
|
| 39 | + { |
|
| 40 | + $this->database = $database; |
|
| 41 | + $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint; |
|
| 42 | + $this->httpHelper = $httpHelper; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function getSpoofs($username) |
|
| 46 | - { |
|
| 47 | - /** @var AntiSpoofCache $cacheResult */ |
|
| 48 | - $cacheResult = AntiSpoofCache::getByUsername($username, $this->database); |
|
| 49 | - if ($cacheResult == false) { |
|
| 50 | - // get the data from the API |
|
| 51 | - $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, array( |
|
| 52 | - 'action' => 'antispoof', |
|
| 53 | - 'format' => 'php', |
|
| 54 | - 'username' => $username, |
|
| 55 | - )); |
|
| 45 | + public function getSpoofs($username) |
|
| 46 | + { |
|
| 47 | + /** @var AntiSpoofCache $cacheResult */ |
|
| 48 | + $cacheResult = AntiSpoofCache::getByUsername($username, $this->database); |
|
| 49 | + if ($cacheResult == false) { |
|
| 50 | + // get the data from the API |
|
| 51 | + $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, array( |
|
| 52 | + 'action' => 'antispoof', |
|
| 53 | + 'format' => 'php', |
|
| 54 | + 'username' => $username, |
|
| 55 | + )); |
|
| 56 | 56 | |
| 57 | - $cacheEntry = new AntiSpoofCache(); |
|
| 58 | - $cacheEntry->setDatabase($this->database); |
|
| 59 | - $cacheEntry->setUsername($username); |
|
| 60 | - $cacheEntry->setData($data); |
|
| 61 | - $cacheEntry->save(); |
|
| 57 | + $cacheEntry = new AntiSpoofCache(); |
|
| 58 | + $cacheEntry->setDatabase($this->database); |
|
| 59 | + $cacheEntry->setUsername($username); |
|
| 60 | + $cacheEntry->setData($data); |
|
| 61 | + $cacheEntry->save(); |
|
| 62 | 62 | |
| 63 | - $cacheResult = $cacheEntry; |
|
| 64 | - } |
|
| 65 | - else { |
|
| 66 | - $data = $cacheResult->getData(); |
|
| 67 | - } |
|
| 63 | + $cacheResult = $cacheEntry; |
|
| 64 | + } |
|
| 65 | + else { |
|
| 66 | + $data = $cacheResult->getData(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $result = unserialize($data); |
|
| 69 | + $result = unserialize($data); |
|
| 70 | 70 | |
| 71 | - if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) { |
|
| 72 | - $cacheResult->delete(); |
|
| 71 | + if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) { |
|
| 72 | + $cacheResult->delete(); |
|
| 73 | 73 | |
| 74 | - if (isset($result['error']['info'])) { |
|
| 75 | - throw new Exception("Unrecognised API response to query: " . $result['error']['info']); |
|
| 76 | - } |
|
| 74 | + if (isset($result['error']['info'])) { |
|
| 75 | + throw new Exception("Unrecognised API response to query: " . $result['error']['info']); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - throw new Exception("Unrecognised API response to query."); |
|
| 79 | - } |
|
| 78 | + throw new Exception("Unrecognised API response to query."); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - if ($result['antispoof']['result'] == "pass") { |
|
| 82 | - // All good here! |
|
| 83 | - return array(); |
|
| 84 | - } |
|
| 81 | + if ($result['antispoof']['result'] == "pass") { |
|
| 82 | + // All good here! |
|
| 83 | + return array(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if ($result['antispoof']['result'] == "conflict") { |
|
| 87 | - // we've got conflicts, let's do something with them. |
|
| 88 | - return $result['antispoof']['users']; |
|
| 89 | - } |
|
| 86 | + if ($result['antispoof']['result'] == "conflict") { |
|
| 87 | + // we've got conflicts, let's do something with them. |
|
| 88 | + return $result['antispoof']['users']; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - if ($result['antispoof']['result'] == "error") { |
|
| 92 | - // we've got conflicts, let's do something with them. |
|
| 93 | - throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']); |
|
| 94 | - } |
|
| 91 | + if ($result['antispoof']['result'] == "error") { |
|
| 92 | + // we've got conflicts, let's do something with them. |
|
| 93 | + throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - throw new Exception("Unrecognised API response to query."); |
|
| 97 | - } |
|
| 96 | + throw new Exception("Unrecognised API response to query."); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -22,156 +22,156 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class XffTrustProvider implements IXffTrustProvider |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Array of IP addresses which are TRUSTED proxies |
|
| 27 | - * @var string[] |
|
| 28 | - */ |
|
| 29 | - private $trustedCache = array(); |
|
| 30 | - /** |
|
| 31 | - * Array of IP addresses which are UNTRUSTED proxies |
|
| 32 | - * @var string[] |
|
| 33 | - */ |
|
| 34 | - private $untrustedCache = array(); |
|
| 35 | - /** @var PDOStatement */ |
|
| 36 | - private $trustedQuery; |
|
| 37 | - /** |
|
| 38 | - * @var PdoDatabase |
|
| 39 | - */ |
|
| 40 | - private $database; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Creates a new instance of the trust provider |
|
| 44 | - * |
|
| 45 | - * @param string[] $squidIpList List of IP addresses to pre-approve |
|
| 46 | - * @param PdoDatabase $database |
|
| 47 | - */ |
|
| 48 | - public function __construct($squidIpList, PdoDatabase $database) |
|
| 49 | - { |
|
| 50 | - $this->trustedCache = $squidIpList; |
|
| 51 | - $this->database = $database; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Returns a value if the IP address is a trusted proxy |
|
| 56 | - * |
|
| 57 | - * @param string $ip |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function isTrusted($ip) |
|
| 62 | - { |
|
| 63 | - if (in_array($ip, $this->trustedCache)) { |
|
| 64 | - return true; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if (in_array($ip, $this->untrustedCache)) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if ($this->trustedQuery === null) { |
|
| 72 | - $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;"; |
|
| 73 | - $this->trustedQuery = $this->database->prepare($query); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $this->trustedQuery->execute(array(":ip" => $ip)); |
|
| 77 | - $result = $this->trustedQuery->fetchColumn(); |
|
| 78 | - $this->trustedQuery->closeCursor(); |
|
| 79 | - |
|
| 80 | - if ($result == 0) { |
|
| 81 | - $this->untrustedCache[] = $ip; |
|
| 82 | - |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($result >= 1) { |
|
| 87 | - $this->trustedCache[] = $ip; |
|
| 88 | - |
|
| 89 | - return true; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // something weird has happened if we've got here. |
|
| 93 | - // default to untrusted. |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets the last trusted IP in the proxy chain. |
|
| 99 | - * |
|
| 100 | - * @param string $ip The IP address from REMOTE_ADDR |
|
| 101 | - * @param string $proxyIp The contents of the XFF header. |
|
| 102 | - * |
|
| 103 | - * @return string Trusted source IP address |
|
| 104 | - */ |
|
| 105 | - public function getTrustedClientIp($ip, $proxyIp) |
|
| 106 | - { |
|
| 107 | - $clientIpAddress = $ip; |
|
| 108 | - if ($proxyIp) { |
|
| 109 | - $ipList = explode(",", $proxyIp); |
|
| 110 | - $ipList[] = $clientIpAddress; |
|
| 111 | - $ipList = array_reverse($ipList); |
|
| 112 | - |
|
| 113 | - foreach ($ipList as $ipNumber => $ipAddress) { |
|
| 114 | - if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) { |
|
| 115 | - continue; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $clientIpAddress = $ipAddress; |
|
| 119 | - break; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $clientIpAddress; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them. |
|
| 128 | - * |
|
| 129 | - * @param array $haystack |
|
| 130 | - * @param string $ip |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function ipInRange($haystack, $ip) |
|
| 135 | - { |
|
| 136 | - $needle = ip2long($ip); |
|
| 137 | - |
|
| 138 | - foreach ($haystack as $low => $high) { |
|
| 139 | - if (ip2long($low) <= $needle && ip2long($high) >= $needle) { |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Explodes a CIDR range into an array of addresses |
|
| 149 | - * |
|
| 150 | - * @param string $range A CIDR-format range |
|
| 151 | - * |
|
| 152 | - * @return array An array containing every IP address in the range |
|
| 153 | - */ |
|
| 154 | - public function explodeCidr($range) |
|
| 155 | - { |
|
| 156 | - $cidrData = explode('/', $range); |
|
| 157 | - |
|
| 158 | - if (!isset($cidrData[1])) { |
|
| 159 | - return array($range); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $blow = ( |
|
| 163 | - str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) & |
|
| 164 | - str_pad(str_pad("", $cidrData[1], "1"), 32, "0") |
|
| 165 | - ); |
|
| 166 | - $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1")); |
|
| 167 | - |
|
| 168 | - $list = array(); |
|
| 169 | - |
|
| 170 | - $bindecBHigh = bindec($bhigh); |
|
| 171 | - for ($x = bindec($blow); $x <= $bindecBHigh; $x++) { |
|
| 172 | - $list[] = long2ip($x); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $list; |
|
| 176 | - } |
|
| 25 | + /** |
|
| 26 | + * Array of IP addresses which are TRUSTED proxies |
|
| 27 | + * @var string[] |
|
| 28 | + */ |
|
| 29 | + private $trustedCache = array(); |
|
| 30 | + /** |
|
| 31 | + * Array of IP addresses which are UNTRUSTED proxies |
|
| 32 | + * @var string[] |
|
| 33 | + */ |
|
| 34 | + private $untrustedCache = array(); |
|
| 35 | + /** @var PDOStatement */ |
|
| 36 | + private $trustedQuery; |
|
| 37 | + /** |
|
| 38 | + * @var PdoDatabase |
|
| 39 | + */ |
|
| 40 | + private $database; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Creates a new instance of the trust provider |
|
| 44 | + * |
|
| 45 | + * @param string[] $squidIpList List of IP addresses to pre-approve |
|
| 46 | + * @param PdoDatabase $database |
|
| 47 | + */ |
|
| 48 | + public function __construct($squidIpList, PdoDatabase $database) |
|
| 49 | + { |
|
| 50 | + $this->trustedCache = $squidIpList; |
|
| 51 | + $this->database = $database; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Returns a value if the IP address is a trusted proxy |
|
| 56 | + * |
|
| 57 | + * @param string $ip |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function isTrusted($ip) |
|
| 62 | + { |
|
| 63 | + if (in_array($ip, $this->trustedCache)) { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if (in_array($ip, $this->untrustedCache)) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if ($this->trustedQuery === null) { |
|
| 72 | + $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;"; |
|
| 73 | + $this->trustedQuery = $this->database->prepare($query); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $this->trustedQuery->execute(array(":ip" => $ip)); |
|
| 77 | + $result = $this->trustedQuery->fetchColumn(); |
|
| 78 | + $this->trustedQuery->closeCursor(); |
|
| 79 | + |
|
| 80 | + if ($result == 0) { |
|
| 81 | + $this->untrustedCache[] = $ip; |
|
| 82 | + |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($result >= 1) { |
|
| 87 | + $this->trustedCache[] = $ip; |
|
| 88 | + |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // something weird has happened if we've got here. |
|
| 93 | + // default to untrusted. |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets the last trusted IP in the proxy chain. |
|
| 99 | + * |
|
| 100 | + * @param string $ip The IP address from REMOTE_ADDR |
|
| 101 | + * @param string $proxyIp The contents of the XFF header. |
|
| 102 | + * |
|
| 103 | + * @return string Trusted source IP address |
|
| 104 | + */ |
|
| 105 | + public function getTrustedClientIp($ip, $proxyIp) |
|
| 106 | + { |
|
| 107 | + $clientIpAddress = $ip; |
|
| 108 | + if ($proxyIp) { |
|
| 109 | + $ipList = explode(",", $proxyIp); |
|
| 110 | + $ipList[] = $clientIpAddress; |
|
| 111 | + $ipList = array_reverse($ipList); |
|
| 112 | + |
|
| 113 | + foreach ($ipList as $ipNumber => $ipAddress) { |
|
| 114 | + if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $clientIpAddress = $ipAddress; |
|
| 119 | + break; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $clientIpAddress; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them. |
|
| 128 | + * |
|
| 129 | + * @param array $haystack |
|
| 130 | + * @param string $ip |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function ipInRange($haystack, $ip) |
|
| 135 | + { |
|
| 136 | + $needle = ip2long($ip); |
|
| 137 | + |
|
| 138 | + foreach ($haystack as $low => $high) { |
|
| 139 | + if (ip2long($low) <= $needle && ip2long($high) >= $needle) { |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Explodes a CIDR range into an array of addresses |
|
| 149 | + * |
|
| 150 | + * @param string $range A CIDR-format range |
|
| 151 | + * |
|
| 152 | + * @return array An array containing every IP address in the range |
|
| 153 | + */ |
|
| 154 | + public function explodeCidr($range) |
|
| 155 | + { |
|
| 156 | + $cidrData = explode('/', $range); |
|
| 157 | + |
|
| 158 | + if (!isset($cidrData[1])) { |
|
| 159 | + return array($range); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $blow = ( |
|
| 163 | + str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) & |
|
| 164 | + str_pad(str_pad("", $cidrData[1], "1"), 32, "0") |
|
| 165 | + ); |
|
| 166 | + $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1")); |
|
| 167 | + |
|
| 168 | + $list = array(); |
|
| 169 | + |
|
| 170 | + $bindecBHigh = bindec($bhigh); |
|
| 171 | + for ($x = bindec($blow); $x <= $bindecBHigh; $x++) { |
|
| 172 | + $list[] = long2ip($x); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $list; |
|
| 176 | + } |
|
| 177 | 177 | } |