28use InvalidArgumentException;
36use Psr\Log\LoggerInterface;
38use Wikimedia\Assert\Assert;
113 $this->hookRunner =
new HookRunner( $hookContainer );
125 if ( $this->readOnlyMode->isReadOnly() ) {
129 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
144 $dbw->
delete(
'ipblocks', [
'ipb_id' => $ids ], $fname );
160 $storeDomain = $this->loadBalancer->resolveDomainID( $expectedWiki );
161 if ( $dbDomain !== $storeDomain ) {
162 throw new InvalidArgumentException(
163 "DB connection domain '$dbDomain' does not match '$storeDomain'"
167 if ( $expectedWiki !== UserIdentity::LOCAL ) {
168 throw new InvalidArgumentException(
169 "Must provide a database connection for wiki '$expectedWiki'."
191 throw new MWException(
'Cannot insert a block without a blocker set' );
196 $this->logger->debug(
'Inserting block; timestamp ' . $block->
getTimestamp() );
201 $dbw = $database ?: $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
204 $dbw->
insert(
'ipblocks', $row, __METHOD__, [
'IGNORE' ] );
223 'ipb_address' => $row[
'ipb_address'],
224 'ipb_user' => $row[
'ipb_user'],
230 $dbw->
delete(
'ipblocks', [
'ipb_id' => $ids ], __METHOD__ );
231 $this->blockRestrictionStore->deleteByBlockId( $ids );
232 $dbw->
insert(
'ipblocks', $row, __METHOD__, [
'IGNORE' ] );
244 if ( $this->options->get(
'BlockDisablesLogin' ) ) {
246 if ( $targetUserIdentity ) {
247 $targetUser = $this->userFactory->newFromUserIdentity( $targetUserIdentity );
249 $targetUser->setToken();
250 $targetUser->saveSettings();
254 return [
'id' => $block->
getId(),
'autoIds' => $autoBlockIds ];
269 $this->logger->debug(
'Updating block; timestamp ' . $block->
getTimestamp() );
273 $block->
getBlocker()->getWikiId() === UserIdentity::LOCAL,
274 '$block->getBlocker()',
275 'must belong to the local wiki.'
278 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
285 [
'ipb_id' => $block->
getId() ],
291 if ( $restrictions !==
null ) {
293 if ( empty( $restrictions ) ) {
294 $success = $this->blockRestrictionStore->deleteByBlockId( $block->
getId() );
296 $success = $this->blockRestrictionStore->update( $restrictions );
307 [
'ipb_parent_block_id' => $block->
getId() ],
312 if ( $restrictions !==
null ) {
313 $this->blockRestrictionStore->updateByParentBlockId(
320 $this->blockRestrictionStore->deleteByParentBlockId( $block->
getId() );
323 [
'ipb_parent_block_id' => $block->
getId() ],
332 return [
'id' => $block->
getId(),
'autoIds' => $autoBlockIds ];
346 if ( $this->readOnlyMode->isReadOnly() ) {
350 $blockId = $block->
getId();
354 __METHOD__ .
" requires that a block id be set\n"
357 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
359 $this->blockRestrictionStore->deleteByParentBlockId( $blockId );
362 [
'ipb_parent_block_id' => $blockId ],
366 $this->blockRestrictionStore->deleteByBlockId( $blockId );
369 [
'ipb_id' => $blockId ],
388 $expiry = $dbw->encodeExpiry( $block->getExpiry() );
396 throw new \RuntimeException( __METHOD__ .
': this block does not have a blocker' );
399 $blockerActor = $this->actorStoreFactory
401 ->acquireActorId( $block->
getBlocker(), $dbw );
405 'ipb_user' => $userId,
406 'ipb_by_actor' => $blockerActor,
412 'ipb_expiry' => $expiry,
421 $commentArray = $this->commentStore->insert(
427 $combinedArray = $blockArray + $commentArray;
428 return $combinedArray;
438 if ( !$block->getBlocker() ) {
439 throw new \RuntimeException( __METHOD__ .
': this block does not have a blocker' );
441 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
442 $blockerActor = $this->actorStoreFactory
443 ->getActorNormalization()
444 ->acquireActorId( $block->
getBlocker(), $dbw );
446 'ipb_by_actor' => $blockerActor,
453 $commentArray = $this->commentStore->
insert(
459 $combinedArray = $blockArray + $commentArray;
460 return $combinedArray;
474 $this->logger->debug(
475 'Doing retroactive autoblocks for ' . $block->
getTargetName()
478 $hookAutoBlocked = [];
479 $continue = $this->hookRunner->onPerformRetroactiveAutoblock(
485 $coreAutoBlocked = $this->performRetroactiveAutoblock( $block );
486 $autoBlockIds = array_merge( $hookAutoBlocked, $coreAutoBlocked );
488 $autoBlockIds = $hookAutoBlocked;
491 return $autoBlockIds;
502 if ( !$this->options->get(
'PutIPinRC' ) ) {
508 if (
$type !== AbstractBlock::TYPE_USER ) {
516 $actor = $targetUser ? $this->actorStoreFactory->getActorNormalization()->findActorId(
522 $this->logger->debug(
'No actor found to retroactively autoblock' );
526 $rcIp =
$dbr->selectField(
529 [
'rc_actor' => $actor ],
531 [
'ORDER BY' =>
'rc_timestamp DESC' ]
535 $this->logger->debug(
'No IP found to retroactively autoblock' );
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Deferrable Update for closure/callback updates that should use auto-commit mode.
Class for managing the deferral of updates within the scope of a PHP script invocation.
A service class for fetching the wiki's current read-only mode.