Skip to content

Commit eb815e2

Browse files
xtexxtstarling
authored andcommitted
RenameUser: Introduce RenameUserJob to run rename job
RenameUserJob is moved to Job/RenameUserTableJob because there are two kinds of jobs now. The newly added RenameUserDerivedJob is used for performing user-renames across a wiki family using virtual domains or shared tables. Most code are moved from SpecialRenameUser and maintenance/renameUser. The new service, RenameUserFactory is added for constructing RenameUser easier. When a global rename happen, the central wiki will enqueue RenameUserDerivedJobs for other wikis in the same family. The derived jobs will check if the central wiki has the same user table as local, and perform updates to local tables. A new user-right 'renameuser-global' is also added because wiki families may want global users to be renamed only by a limit set of users or on a certain global wiki. Bug: T104830 Change-Id: Ic4120cbd9a4850dfe22d009daa171199fe7c5e39
1 parent fbbe3b2 commit eb815e2

23 files changed

+847
-337
lines changed

RELEASE-NOTES-1.44

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ For notes on 1.43.x and older releases, see HISTORY.
9797

9898
* (T267477) Users with rename userright can now rename themselves through
9999
[[Special:RenameUser]].
100+
* (T104830) [[Special:RenameUser]] can now be used in wiki families using
101+
shared tables.
102+
A renameuser-global right is added and required when renaming global users.
103+
No groups have this right by default.
100104
* …
101105

102106
=== New developer features in 1.44 ===
@@ -268,6 +272,8 @@ because of Phabricator reports.
268272
added. This will be hard deprecated in the next MediaWiki release. More
269273
information is available at T333211. To avoid future breakage, see the
270274
guidance in T385346.
275+
* RenameuserSQL::rename has been deprecated and should be replaced with
276+
RenameuserSQL::renameUser, which returns a Status instead of boolean.
271277
* LocalFile::getQueryInfo() and OldLocalFile::getQueryInfo(), deprecated
272278
since 1.41, are now emitting warnings.
273279
* The 'PermissionErrorAudit' hook has been deprecated and replaced by

autoload.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,10 @@
22002200
'MediaWiki\\RenameUser\\Hook\\RenameUserPreRenameHook' => __DIR__ . '/includes/RenameUser/Hook/RenameUserPreRenameHook.php',
22012201
'MediaWiki\\RenameUser\\Hook\\RenameUserSQLHook' => __DIR__ . '/includes/RenameUser/Hook/RenameUserSQLHook.php',
22022202
'MediaWiki\\RenameUser\\Hook\\RenameUserWarningHook' => __DIR__ . '/includes/RenameUser/Hook/RenameUserWarningHook.php',
2203-
'MediaWiki\\RenameUser\\RenameUserJob' => __DIR__ . '/includes/RenameUser/RenameUserJob.php',
2203+
'MediaWiki\\RenameUser\\Job\\RenameUserDerivedJob' => __DIR__ . '/includes/RenameUser/Job/RenameUserDerivedJob.php',
2204+
'MediaWiki\\RenameUser\\Job\\RenameUserTableJob' => __DIR__ . '/includes/RenameUser/Job/RenameUserTableJob.php',
2205+
'MediaWiki\\RenameUser\\RenameUser' => __DIR__ . '/includes/RenameUser/RenameUser.php',
2206+
'MediaWiki\\RenameUser\\RenameUserFactory' => __DIR__ . '/includes/RenameUser/RenameUserFactory.php',
22042207
'MediaWiki\\RenameUser\\RenameuserSQL' => __DIR__ . '/includes/RenameUser/RenameuserSQL.php',
22052208
'MediaWiki\\Request\\ContentSecurityPolicy' => __DIR__ . '/includes/Request/ContentSecurityPolicy.php',
22062209
'MediaWiki\\Request\\DerivativeRequest' => __DIR__ . '/includes/Request/DerivativeRequest.php',
@@ -3080,7 +3083,7 @@
30803083
'RenameDbPrefix' => __DIR__ . '/maintenance/renameDbPrefix.php',
30813084
'RenameRestrictions' => __DIR__ . '/maintenance/renameRestrictions.php',
30823085
'RenameUser' => __DIR__ . '/maintenance/renameUser.php',
3083-
'RenameUserJob' => __DIR__ . '/includes/RenameUser/RenameUserJob.php',
3086+
'RenameUserJob' => __DIR__ . '/includes/RenameUser/Job/RenameUserTableJob.php',
30843087
'RenameUsersMatchingPattern' => __DIR__ . '/maintenance/renameUsersMatchingPattern.php',
30853088
'RenameuserLogFormatter' => __DIR__ . '/includes/logging/RenameuserLogFormatter.php',
30863089
'RenderAction' => __DIR__ . '/includes/actions/RenderAction.php',

docs/config-schema.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7249,7 +7249,9 @@ config-schema:
72497249
'null': NullJob
72507250
userEditCountInit: UserEditCountInitJob
72517251
parsoidCachePrewarm: { class: ParsoidCachePrewarmJob, services: [ParserOutputAccess, PageStore, RevisionLookup, ParsoidSiteConfig], needsPage: false }
7252-
renameUser: { class: MediaWiki\RenameUser\RenameUserJob, services: [MainConfig, DBLoadBalancerFactory] }
7252+
renameUserTable: { class: MediaWiki\RenameUser\Job\RenameUserTableJob, services: [MainConfig, DBLoadBalancerFactory] }
7253+
renameUserDerived: { class: MediaWiki\RenameUser\Job\RenameUserDerivedJob, services: [RenameUserFactory, UserFactory] }
7254+
renameUser: { class: MediaWiki\RenameUser\Job\RenameUserTableJob, services: [MainConfig, DBLoadBalancerFactory] }
72537255
type: object
72547256
description: |-
72557257
Maps jobs to their handlers; extensions

includes/MainConfigSchema.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
use MediaWiki\Permissions\GrantsInfo;
6060
use MediaWiki\RCFeed\RedisPubSubFeedEngine;
6161
use MediaWiki\RCFeed\UDPRCFeedEngine;
62-
use MediaWiki\RenameUser\RenameUserJob;
62+
use MediaWiki\RenameUser\Job\RenameUserDerivedJob;
63+
use MediaWiki\RenameUser\Job\RenameUserTableJob;
6364
use MediaWiki\Request\WebRequest;
6465
use MediaWiki\Settings\Source\JsonSchemaTrait;
6566
use MediaWiki\Site\MediaWikiSite;
@@ -11594,8 +11595,24 @@ public static function getDefaultReadOnlyFile( $uploadDirectory ): string {
1159411595
// tell the JobFactory not to include the $page parameter in the constructor call
1159511596
'needsPage' => false
1159611597
],
11598+
'renameUserTable' => [
11599+
'class' => RenameUserTableJob::class,
11600+
'services' => [
11601+
'MainConfig',
11602+
'DBLoadBalancerFactory'
11603+
]
11604+
],
11605+
'renameUserDerived' => [
11606+
'class' => RenameUserDerivedJob::class,
11607+
'services' => [
11608+
'RenameUserFactory',
11609+
'UserFactory'
11610+
]
11611+
],
11612+
// 'renameUser' is a alias for backward compatibility
11613+
// it should be removed in the future releases
1159711614
'renameUser' => [
11598-
'class' => RenameUserJob::class,
11615+
'class' => RenameUserTableJob::class,
1159911616
'services' => [
1160011617
'MainConfig',
1160111618
'DBLoadBalancerFactory'

includes/MediaWikiServices.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
use MediaWiki\Preferences\PreferencesFactory;
136136
use MediaWiki\Preferences\SignatureValidatorFactory;
137137
use MediaWiki\Registration\ExtensionRegistry;
138+
use MediaWiki\RenameUser\RenameUserFactory;
138139
use MediaWiki\Request\ProxyLookup;
139140
use MediaWiki\ResourceLoader\ResourceLoader;
140141
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
@@ -1745,6 +1746,13 @@ public function getRedirectStore(): RedirectStore {
17451746
return $this->getService( 'RedirectStore' );
17461747
}
17471748

1749+
/**
1750+
* @since 1.44
1751+
*/
1752+
public function getRenameUserFactory(): RenameUserFactory {
1753+
return $this->getService( 'RenameUserFactory' );
1754+
}
1755+
17481756
/**
17491757
* @since 1.34
17501758
*/

includes/Permissions/PermissionManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class PermissionManager {
195195
'protect',
196196
'read',
197197
'renameuser',
198+
'renameuser-global',
198199
'reupload',
199200
'reupload-own',
200201
'reupload-shared',
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace MediaWiki\RenameUser\Job;
4+
5+
use Job;
6+
use MediaWiki\Logger\LoggerFactory;
7+
use MediaWiki\RenameUser\RenameUserFactory;
8+
use MediaWiki\Title\Title;
9+
use MediaWiki\User\UserFactory;
10+
11+
/**
12+
* Custom job to perform user rename on wiki family using shared tables or virtual domains.
13+
*
14+
* This job only performs derived local renames, so the shared tables must be updated before
15+
* enqueuing this job.
16+
*
17+
* If the user table is not shared on this wiki, or the target user does not have a proper name,
18+
* the job will fail silently.
19+
*
20+
* Job parameters include:
21+
* - oldname : The old user name
22+
* - newname : The new user name
23+
* - uid : The user id
24+
* - performer : The renamer user id
25+
* - reason : Reason
26+
* - movePages : Whether user pages should be moved
27+
* - suppressRedirect : Suppress redirect when moving user pages, when possible
28+
*/
29+
class RenameUserDerivedJob extends Job {
30+
/** @var RenameUserFactory */
31+
private $renameUserFactory;
32+
/** @var UserFactory */
33+
private $userFactory;
34+
35+
public function __construct(
36+
Title $title,
37+
$params,
38+
RenameUserFactory $renameUserFactory,
39+
UserFactory $userFactory
40+
) {
41+
parent::__construct( 'renameUserDerived', $title, $params );
42+
43+
$this->renameUserFactory = $renameUserFactory;
44+
$this->userFactory = $userFactory;
45+
}
46+
47+
public function run() {
48+
$oldName = $this->params['oldname'];
49+
$newName = $this->params['newname'];
50+
$uid = $this->params['uid'];
51+
$performerUid = $this->params['performer'];
52+
$reason = $this->params['reason'];
53+
$movePages = $this->params['movePages'] ?? true;
54+
$suppressRedirect = $this->params['suppressRedirect'] ?? false;
55+
56+
$user = $this->userFactory->newFromId( $uid );
57+
$performer = $this->userFactory->newFromId( $performerUid );
58+
$logger = LoggerFactory::getInstance( 'RenameUser' );
59+
60+
// Check if this wiki has the same shared user database as the trigger wiki.
61+
if ( !$this->userFactory->isUserTableShared() ) {
62+
return true;
63+
}
64+
if ( $user->getName() !== $newName ) {
65+
$logger->info(
66+
"User to be renamed from ${oldName} to ${newName} does not have the expected name, skipping"
67+
);
68+
return true;
69+
}
70+
71+
// Do the rename
72+
$rename = $this->renameUserFactory->newDerivedRenameUser(
73+
$performer,
74+
$uid,
75+
$oldName,
76+
$newName,
77+
$reason,
78+
[
79+
'movePages' => $movePages,
80+
'suppressRedirect' => $suppressRedirect
81+
]
82+
);
83+
$status = $rename->renameLocal();
84+
if ( !$status->isGood() ) {
85+
$logger->error(
86+
"Cannot finish derived local user rename from ${oldName} to ${newName}: ${status}"
87+
);
88+
}
89+
90+
return $status->isOK();
91+
}
92+
}

includes/RenameUser/RenameUserJob.php renamed to includes/RenameUser/Job/RenameUserTableJob.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace MediaWiki\RenameUser;
3+
namespace MediaWiki\RenameUser\Job;
44

55
use InvalidArgumentException;
66
use Job;
@@ -33,7 +33,7 @@
3333
* - userID : The ID of the user to update
3434
* - uidColumn : The *_user_id column
3535
*/
36-
class RenameUserJob extends Job {
36+
class RenameUserTableJob extends Job {
3737
/** @var int */
3838
private $updateRowsPerQuery;
3939

@@ -46,7 +46,7 @@ public function __construct(
4646
Config $config,
4747
ILBFactory $lbFactory
4848
) {
49-
parent::__construct( 'renameUser', $title, $params );
49+
parent::__construct( 'renameUserTable', $title, $params );
5050

5151
$this->updateRowsPerQuery = $config->get( MainConfigNames::UpdateRowsPerQuery );
5252
$this->lbFactory = $lbFactory;
@@ -127,4 +127,4 @@ public function run() {
127127
}
128128
}
129129
/** @deprecated class alias since 1.43 */
130-
class_alias( RenameUserJob::class, 'RenameUserJob' );
130+
class_alias( RenameUserTableJob::class, 'RenameUserJob' );

0 commit comments

Comments
 (0)