| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
ason |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
om> |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
require_once __DIR__ . '/Maintenance.php'; |
| 29 |
|
| 30 |
|
| 31 |
use MediaWiki\Logger\LoggerFactory; |
| 32 |
use MediaWiki\Maintenance\Maintenance; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class ChangePassword extends Maintenance { |
| 40 |
public function __construct() { |
| 41 |
parent::__construct(); |
| 42 |
$this->addOption( "user", "The username to operate on", false, true ); |
| 43 |
$this->addOption( "userid", "The user id to operate on", false, true ); |
| 44 |
$this->addOption( "password", "The password to use", true, true ); |
| 45 |
$this->addOption( 'reason', 'Reason for the password change (ticket number etc)', false, true ); |
| 46 |
$this->addDescription( "Change a user's password" ); |
| 47 |
} |
| 48 |
|
| 49 |
public function execute() { |
| 50 |
$user = $this->validateUserOption( "A \"user\" or \"userid\" must be set to change the password for" ); |
| 51 |
$password = $this->getOption( 'password' ); |
| 52 |
$status = $user->changeAuthenticationData( [ |
| 53 |
'username' => $user->getName(), |
| 54 |
'password' => $password, |
| 55 |
'retype' => $password, |
| 56 |
] ); |
| 57 |
if ( $status->isGood() ) { |
| 58 |
$this->output( "Password set for " . $user->getName() . "\n" ); |
| 59 |
|
| 60 |
LoggerFactory::getInstance( 'authentication' )->info( |
| 61 |
'Password for {user} changed via changePassword.php', [ |
| 62 |
'user' => $user->getName(), |
| 63 |
'reason' => $this->getOption( 'reason', '' ), |
| 64 |
] |
| 65 |
); |
| 66 |
|
| 67 |
$invalidator = $this->createChild( InvalidateUserSessions::class ); |
| 68 |
$invalidator->setOption( 'user', $user->getName() ); |
| 69 |
$invalidator->execute(); |
| 70 |
} else { |
| 71 |
$this->fatalError( $status ); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
$maintClass = ChangePassword::class; |
| 78 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 79 |
|