Merge "Use new User::newSystemUser() when available"

This commit is contained in:
Umherirrender 2015-10-11 17:03:51 +00:00 committed by Gerrit Code Review
commit d1940b4b45
2 changed files with 40 additions and 30 deletions

View file

@ -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.

View file

@ -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.