From 6ee605a08872e323abf52f190ab1540d5f289c8a Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 13 May 2016 14:35:41 -0400 Subject: [PATCH] Use User::newSystemUser when available Change-Id: I0be561ff0a28a728451224239e20f243543c311d --- cleanup.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cleanup.php b/cleanup.php index 224f04ed..8eb23ce1 100644 --- a/cleanup.php +++ b/cleanup.php @@ -56,14 +56,18 @@ function cleanupArticle( Revision $rev, $regexes, $match ) { //------------------------------------------------------------------------------ $username = 'Spam cleanup script'; -$wgUser = User::newFromName( $username ); -if ( $wgUser->idForName() == 0 ) { - // Create the user - $status = $wgUser->addToDatabase(); - if ( $status === null || $status->isOK() ) { - $dbw = wfGetDB( DB_MASTER ); - $dbw->update( 'user', array( 'user_password' => 'nologin' ), - array( 'user_name' => $username ), $username ); +if ( method_exists( 'User', 'newSystemUser' ) ) { + $wgUser = User::newSystemUser( $username, array( 'steal' => true ) ); +} else { + $wgUser = User::newFromName( $username ); + if ( $wgUser->idForName() == 0 ) { + // Create the user + $status = $wgUser->addToDatabase(); + if ( $status === null || $status->isOK() ) { + $dbw = wfGetDB( DB_MASTER ); + $dbw->update( 'user', array( 'user_password' => 'nologin' ), + array( 'user_name' => $username ), $username ); + } } }