mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 14:13:54 +00:00
Merge "Use new User::newSystemUser() when available"
This commit is contained in:
commit
d1940b4b45
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue