| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\Consequences; |
| 4 |
|
| 5 |
use MediaWiki\Block\BlockUserFactory; |
| 6 |
use MediaWiki\Block\DatabaseBlockStore; |
| 7 |
use MediaWiki\Config\ServiceOptions; |
| 8 |
use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore; |
| 9 |
use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagger; |
| 10 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Block; |
| 11 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\BlockAutopromote; |
| 12 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Degroup; |
| 13 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Disallow; |
| 14 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\RangeBlock; |
| 15 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Tag; |
| 16 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Throttle; |
| 17 |
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Warn; |
| 18 |
use MediaWiki\Extension\AbuseFilter\FilterUser; |
| 19 |
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder; |
| 20 |
use MediaWiki\Session\Session; |
| 21 |
use MediaWiki\Session\SessionManager; |
| 22 |
use MediaWiki\User\UserEditTracker; |
| 23 |
use MediaWiki\User\UserFactory; |
| 24 |
use MediaWiki\User\UserGroupManager; |
| 25 |
use MediaWiki\User\UserIdentityUtils; |
| 26 |
use MessageLocalizer; |
| 27 |
use Psr\Log\LoggerInterface; |
| 28 |
use Wikimedia\ObjectCache\BagOStuff; |
| 29 |
|
| 30 |
class ConsequencesFactory { |
| 31 |
public const SERVICE_NAME = 'AbuseFilterConsequencesFactory'; |
| 32 |
|
| 33 |
public const CONSTRUCTOR_OPTIONS = [ |
| 34 |
'AbuseFilterCentralDB', |
| 35 |
'AbuseFilterIsCentral', |
| 36 |
'AbuseFilterRangeBlockSize', |
| 37 |
'BlockCIDRLimit', |
| 38 |
]; |
| 39 |
|
| 40 |
|
| 41 |
private $options; |
| 42 |
|
| 43 |
|
| 44 |
private $logger; |
| 45 |
|
| 46 |
|
| 47 |
private $blockUserFactory; |
| 48 |
|
| 49 |
|
| 50 |
private $databaseBlockStore; |
| 51 |
|
| 52 |
|
| 53 |
private $userGroupManager; |
| 54 |
|
| 55 |
|
| 56 |
private $mainStash; |
| 57 |
|
| 58 |
|
| 59 |
private $changeTagger; |
| 60 |
|
| 61 |
|
| 62 |
private $blockAutopromoteStore; |
| 63 |
|
| 64 |
|
| 65 |
private $filterUser; |
| 66 |
|
| 67 |
|
| 68 |
private $messageLocalizer; |
| 69 |
|
| 70 |
|
| 71 |
private $userEditTracker; |
| 72 |
|
| 73 |
|
| 74 |
private $userFactory; |
| 75 |
|
| 76 |
|
| 77 |
private $userIdentityUtils; |
| 78 |
|
| 79 |
|
| 80 |
private $session; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public function __construct( |
| 100 |
ServiceOptions $options, |
| 101 |
LoggerInterface $logger, |
| 102 |
BlockUserFactory $blockUserFactory, |
| 103 |
DatabaseBlockStore $databaseBlockStore, |
| 104 |
UserGroupManager $userGroupManager, |
| 105 |
BagOStuff $mainStash, |
| 106 |
ChangeTagger $changeTagger, |
| 107 |
BlockAutopromoteStore $blockAutopromoteStore, |
| 108 |
FilterUser $filterUser, |
| 109 |
MessageLocalizer $messageLocalizer, |
| 110 |
UserEditTracker $userEditTracker, |
| 111 |
UserFactory $userFactory, |
| 112 |
UserIdentityUtils $userIdentityUtils |
| 113 |
) { |
| 114 |
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 115 |
$this->options = $options; |
| 116 |
$this->logger = $logger; |
| 117 |
$this->blockUserFactory = $blockUserFactory; |
| 118 |
$this->databaseBlockStore = $databaseBlockStore; |
| 119 |
$this->userGroupManager = $userGroupManager; |
| 120 |
$this->mainStash = $mainStash; |
| 121 |
$this->changeTagger = $changeTagger; |
| 122 |
$this->blockAutopromoteStore = $blockAutopromoteStore; |
| 123 |
$this->filterUser = $filterUser; |
| 124 |
$this->messageLocalizer = $messageLocalizer; |
| 125 |
$this->userEditTracker = $userEditTracker; |
| 126 |
$this->userFactory = $userFactory; |
| 127 |
$this->userIdentityUtils = $userIdentityUtils; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public function newBlock( Parameters $params, string $expiry, bool $preventsTalk ): Block { |
| 139 |
return new Block( |
| 140 |
$params, |
| 141 |
$expiry, |
| 142 |
$preventsTalk, |
| 143 |
$this->blockUserFactory, |
| 144 |
$this->databaseBlockStore, |
| 145 |
$this->filterUser, |
| 146 |
$this->messageLocalizer, |
| 147 |
$this->logger |
| 148 |
); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public function newRangeBlock( Parameters $params, string $expiry ): RangeBlock { |
| 157 |
return new RangeBlock( |
| 158 |
$params, |
| 159 |
$expiry, |
| 160 |
$this->blockUserFactory, |
| 161 |
$this->filterUser, |
| 162 |
$this->messageLocalizer, |
| 163 |
$this->logger, |
| 164 |
$this->options->get( 'AbuseFilterRangeBlockSize' ), |
| 165 |
$this->options->get( 'BlockCIDRLimit' ) |
| 166 |
); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
public function newDegroup( Parameters $params, VariableHolder $vars ): Degroup { |
| 175 |
return new Degroup( |
| 176 |
$params, |
| 177 |
$vars, |
| 178 |
$this->userGroupManager, |
| 179 |
$this->userIdentityUtils, |
| 180 |
$this->filterUser, |
| 181 |
$this->messageLocalizer |
| 182 |
); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
public function newBlockAutopromote( Parameters $params, int $duration ): BlockAutopromote { |
| 191 |
return new BlockAutopromote( $params, $duration, $this->blockAutopromoteStore, $this->messageLocalizer, |
| 192 |
$this->userIdentityUtils ); |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public function newThrottle( Parameters $params, array $throttleParams ): Throttle { |
| 202 |
return new Throttle( |
| 203 |
$params, |
| 204 |
$throttleParams, |
| 205 |
$this->mainStash, |
| 206 |
$this->userEditTracker, |
| 207 |
$this->userFactory, |
| 208 |
$this->logger, |
| 209 |
$this->options->get( 'AbuseFilterIsCentral' ), |
| 210 |
$this->options->get( 'AbuseFilterCentralDB' ) |
| 211 |
); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public function newWarn( Parameters $params, string $message ): Warn { |
| 220 |
return new Warn( $params, $message, $this->getSession() ); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
public function newDisallow( Parameters $params, string $message ): Disallow { |
| 229 |
return new Disallow( $params, $message ); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public function newTag( Parameters $params, array $tags ): Tag { |
| 238 |
return new Tag( $params, $tags, $this->changeTagger ); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
public function setSession( Session $session ): void { |
| 246 |
$this->session = $session; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
private function getSession(): Session { |
| 253 |
if ( $this->session === null ) { |
| 254 |
$this->session = SessionManager::getGlobalSession(); |
| 255 |
} |
| 256 |
|
| 257 |
return $this->session; |
| 258 |
} |
| 259 |
} |