mediawiki-extensions-OATHAuth/maintenance/disableOATHAuthForUser.php
Reedy 1871a9abe1 Re-instate "Add some logging of OATHAuth actions"
This reverts commit 69b6292c12.

Bug: T151010
Change-Id: I6f610551bc4bd1e78c0282011b80a3f3e70b8885
2018-12-18 17:34:37 +00:00

41 lines
1 KiB
PHP

<?php
if ( getenv( 'MW_INSTALL_PATH' ) ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
class DisableOATHAuthForUser extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'Remove OATHAuth from a specific user';
$this->addArg( 'user', 'The username to remove OATHAuth from.' );
$this->requireExtension( 'OATHAuth' );
}
public function execute() {
$username = $this->getArg( 0 );
$user = User::newFromName( $username );
if ( $user && $user->getId() === 0 ) {
$this->error( "User $username doesn't exist!", 1 );
}
$repo = OATHAuthHooks::getOATHUserRepository();
$oathUser = $repo->findByUser( $user );
if ( $oathUser->getKey() === null ) {
$this->error( "User $username doesn't have OATHAuth enabled!", 1 );
}
$repo->remove( $oathUser, 'Maintenance script' );
$this->output( "OATHAuth disabled for $username.\n" );
}
}
$maintClass = "DisableOATHAuthForUser";
require_once RUN_MAINTENANCE_IF_MAIN;