From a926b2b44fe5fe136accf40292f1e63154cce565 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 17 Sep 2015 11:31:51 -0400 Subject: [PATCH] Use new User::newSystemUser() when available See core change I2c736ad72d946fa9b859e6cd335fa58aececc0d5. Change-Id: I3f20b408c039937c1f08c9232c336268ba13895d --- AbuseFilter.class.php | 43 ++++++++++++++++++++++++------------------- AbuseFilter.hooks.php | 27 ++++++++++++++++----------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php index 1efa44eb3..864b52c52 100755 --- a/AbuseFilter.class.php +++ b/AbuseFilter.class.php @@ -1617,26 +1617,31 @@ class AbuseFilter { * @return User */ public static function getFilterUser() { - $user = User::newFromName( wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text() ); - $user->load(); - if ( $user->getId() && $user->mPassword == '' ) { - // Already set up. - return $user; - } - - // Not set up. Create it. - if ( !$user->getId() ) { - print 'Trying to create account -- user id is ' . $user->getId(); - $user->addToDatabase(); - $user->saveSettings(); - // Increment site_stats.ss_users - $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); - $ssu->doUpdate(); + $username = wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text(); + if ( method_exists( 'User', 'newSystemUser' ) ) { + $user = User::newSystemUser( $username, array( 'steal' => true ) ); } else { - // Take over the account - $user->setPassword( null ); - $user->setEmail( null ); - $user->saveSettings(); + $user = User::newFromName( $username ); + $user->load(); + if ( $user->getId() && $user->mPassword == '' ) { + // Already set up. + return $user; + } + + // Not set up. Create it. + if ( !$user->getId() ) { + print 'Trying to create account -- user id is ' . $user->getId(); + $user->addToDatabase(); + $user->saveSettings(); + // Increment site_stats.ss_users + $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); + $ssu->doUpdate(); + } else { + // Take over the account + $user->setPassword( null ); + $user->setEmail( null ); + $user->saveSettings(); + } } // Promote user so it doesn't look too crazy. diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php index 27c715253..c7bb11c9a 100755 --- a/AbuseFilter.hooks.php +++ b/AbuseFilter.hooks.php @@ -559,20 +559,25 @@ class AbuseFilterHooks { * @param $updater DatabaseUpdater */ public static function createAbuseFilterUser( $updater ) { - $user = User::newFromName( wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text() ); + $username = wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text(); + $user = User::newFromName( $username ); if ( $user && !$updater->updateRowExists( 'create abusefilter-blocker-user' ) ) { - if ( !$user->getId() ) { - $user->addToDatabase(); - $user->saveSettings(); - # Increment site_stats.ss_users - $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); - $ssu->doUpdate(); + if ( method_exists( 'User', 'newSystemUser' ) ) { + $user = User::newSystemUser( $username, array( 'steal' => true ) ); } else { - // Sorry dude, we need this account. - $user->setPassword( null ); - $user->setEmail( null ); - $user->saveSettings(); + if ( !$user->getId() ) { + $user->addToDatabase(); + $user->saveSettings(); + # Increment site_stats.ss_users + $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); + $ssu->doUpdate(); + } else { + // Sorry dude, we need this account. + $user->setPassword( null ); + $user->setEmail( null ); + $user->saveSettings(); + } } $updater->insertUpdateRow( 'create abusefilter-blocker-user' ); # Promote user so it doesn't look too crazy.