Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/165097
Change subject: Add LocalRenameUserJob::promoteToGlobal()
......................................................................
Add LocalRenameUserJob::promoteToGlobal()
Allows us to easily promote a user account we've just renamed
into a global one.
This is currently not used, but will be necessary for the
finalisation scripts.
Change-Id: I3c6ab014fbbd241b3bab2934126948203c19a3e1
---
M includes/CentralAuthUser.php
M includes/GlobalRename/GlobalRenameUser.php
M includes/LocalRenameJob/LocalRenameUserJob.php
3 files changed, 61 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth
refs/changes/97/165097/1
diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index 13d6930..58cb980 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -840,6 +840,40 @@
}
/**
+ * Promote an unattached account to a
+ * global one, using the provided homewiki
+ *
+ * @param string $wiki
+ * @return Status
+ */
+ public function promoteToGlobal( $wiki ) {
+ $unattached = $this->queryUnattached();
+ if ( !isset( $unattached[$wiki] ) ) {
+ return Status::newFatal( 'promote-not-on-wiki' );
+ }
+
+ $info = $unattached[$wiki];
+
+ if ( $this->exists() ) {
+ return Status::newFatal( 'promote-already-exists' );
+ }
+
+ $ok = $this->storeGlobalData(
+ $info['id'],
+ $info['password'],
+ $info['email'],
+ $info['emailAuthenticated']
+ );
+ if ( !$ok ) {
+ // Race condition?
+ return Status::newFatal( 'promote-already-exists' );
+ }
+
+ $this->attach( $wiki, 'primary' );
+ return Status::newGood();
+ }
+
+ /**
* Pick a winning master account and try to auto-merge as many as
possible.
* @fixme add some locking or something
*
diff --git a/includes/GlobalRename/GlobalRenameUser.php
b/includes/GlobalRename/GlobalRenameUser.php
index c6163bb..edeacdc 100644
--- a/includes/GlobalRename/GlobalRenameUser.php
+++ b/includes/GlobalRename/GlobalRenameUser.php
@@ -177,6 +177,7 @@
'renamer' => $this->performingUser->getName(),
'movepages' => $options['movepages'],
'suppressredirects' => $options['suppressredirects'],
+ 'promotetoglobal' => false,
);
$title = Title::newFromText( 'Global rename job' ); // This
isn't used anywhere!
diff --git a/includes/LocalRenameJob/LocalRenameUserJob.php
b/includes/LocalRenameJob/LocalRenameUserJob.php
index 12bdd2a..f6b7364 100644
--- a/includes/LocalRenameJob/LocalRenameUserJob.php
+++ b/includes/LocalRenameJob/LocalRenameUserJob.php
@@ -21,6 +21,10 @@
* @param int $id
*/
public function __construct( $title, $params, $id = 0 ) {
+ // For back-compat
+ if ( !isset( $params['promotetoglobal'] ) ) {
+ $params['promotetoglobal'] = false;
+ }
parent::__construct( 'LocalRenameUserJob', $title, $params, $id
);
}
@@ -47,12 +51,34 @@
// until a sysadmin intervenes...
throw new MWException( 'RenameuserSQL::rename returned
false.' );
}
+
+ if ( $this->params['promotetoglobal'] ) {
+ $this->promoteToGlobal();
+ }
+
if ( $this->params['movepages'] ) {
$this->movePages();
}
$this->done();
}
+ private function promoteToGlobal() {
+ $newName = $this->params['to'];
+ $caUser = new CentralAuthUser( $newName );
+ $status = $caUser->promoteToGlobal( wfWikiID() );
+ if ( !$status->isOK() ) {
+ if ( $status->hasMessage( 'promote-not-on-wiki' ) ) {
+ // Eh, what?
+ throw new MWException( "Tried to promote
'$newName' to a global account except it doesn't exist locally" );
+ } elseif ( $status->hasMessage(
'promote-already-exists' ) ) {
+ // Even more wtf.
+ throw new MWException( "Tried to prommote
'$newName' to a global account except it already exists" );
+ }
+ }
+
+ $caUser->quickInvalidateCache();
+ }
+
/**
* FIXME: on a of scale one to evil, this is super evil
*/
--
To view, visit https://gerrit.wikimedia.org/r/165097
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c6ab014fbbd241b3bab2934126948203c19a3e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits