wiki.techinc.nl/includes/user/ActorMigration.php
Thalia 6909b2016e Always allow local IP actors to be created when importing
Why:

* Following T345578, the ActorStore throws an error on
  attempting to create an actor whose name is their IP address
  if temporary accounts are enabled.
* For the specific case of importing old revisions, we need to
  be able to create new actors whose name is their IP address,
  while still generally disallowing it.

What:

* Add $allowCreateIpActors flag to ActorStore, and check for
  it during actor name validation.
* Set the flag from ActorStoreFactory::getActorStore depending
  on whether temporary users are enabled.
* Add ActorStoreFactory::getActorStoreForImport, which sets
  flag to true.
* Add RevisionStoreFactory::getRevisionStoreForImport, which
  uses getActorStoreForImport. Use this from classes handling
  imports, so that IP actors can always be created.
* Add $forImport flag on ActorMigration, since RevisionStore
  uses an actor store obtained via ActorMigration.

Bug: T354207
Change-Id: I0715bd0d23089fd8156e579913e6e823089809be
2024-01-29 19:35:14 +00:00

103 lines
2.7 KiB
PHP

<?php
namespace MediaWiki\User;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\IReadableDatabase;
/**
* This is not intended to be a long-term part of MediaWiki; it will be
* deprecated and removed once actor migration is complete.
*
* @since 1.31
* @since 1.34 Use with 'ar_user', 'img_user', 'oi_user', 'fa_user',
* 'rc_user', 'log_user', and 'ipb_by' is deprecated. Callers should
* reference the corresponding actor fields directly.
* @deprecated since 1.39
*/
class ActorMigration extends ActorMigrationBase {
/**
* Constant for extensions to feature-test whether $wgActorTableSchemaMigrationStage
* (in MW <1.34) expects MIGRATION_* or SCHEMA_COMPAT_*
*/
public const MIGRATION_STAGE_SCHEMA_COMPAT = 1;
/**
* Field information
* @see ActorMigrationBase::getFieldInfo()
*/
public const FIELD_INFOS = [
// Deprecated since 1.39
'rev_user' => [],
];
/**
* Static constructor
* @return self
*/
public static function newMigration() {
return MediaWikiServices::getInstance()->getActorMigration();
}
/**
* Static constructor
* @return self
*/
public static function newMigrationForImport() {
$migration = new self(
MediaWikiServices::getInstance()->getActorStoreFactory()
);
$migration->setForImport( true );
return $migration;
}
/**
* @internal
*
* @param ActorStoreFactory $actorStoreFactory
*/
public function __construct( ActorStoreFactory $actorStoreFactory ) {
parent::__construct(
self::FIELD_INFOS,
SCHEMA_COMPAT_NEW,
$actorStoreFactory
);
}
/**
* @inheritDoc
* @deprecated since 1.39 Use `{table} JOIN actor ON {table_prefix}_actor = actor_id`
* E.g. for key=rev_user, use `revision JOIN actor ON rev_actor = actor_id`
*/
public function getJoin( $key ) {
return parent::getJoin( $key );
}
/**
* @inheritDoc
* @deprecated since 1.39 Use `{table_prefix}_actor IN ({list of actor IDs})`.
* E.g. for key=rev_user, use `rev_actor IN ({list of actor IDs})`.
* Use `MediaWikiServices::getInstance()->getActorNormalization()
* ->findActorId( $user, $db )` to get the actor ID for a given user.
*/
public function getWhere( IReadableDatabase $db, $key, $users, $useId = true ) {
return parent::getWhere( $db, $key, $users, $useId );
}
/**
* @inheritDoc
* @deprecated since 1.39 Use `[ '{table_prefix}_actor' => MediaWikiServices::getInstance()
* ->getActorNormalization()->acquireActorId( $user, $dbw ) ]`
* E.g. for key=log_user, use `[ 'log_actor' => ... ]`
*/
public function getInsertValues( IDatabase $dbw, $key, UserIdentity $user ) {
return parent::getInsertValues( $dbw, $key, $user );
}
}
/**
* @deprecated since 1.40
*/
class_alias( ActorMigration::class, 'ActorMigration' );