mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/OATHAuth
synced 2024-12-21 04:13:49 +00:00
a95802a14e
Bug: T195207 Change-Id: I695a376e15e8a95a02849a6ec67b882228852ef8
101 lines
2.1 KiB
PHP
101 lines
2.1 KiB
PHP
<?php
|
|
|
|
class SpecialDisableOATHForUser extends FormSpecialPage {
|
|
/** @var OATHUserRepository */
|
|
private $OATHRepository;
|
|
|
|
public function __construct() {
|
|
parent::__construct( 'DisableOATHForUser', 'oathauth-disable-for-user' );
|
|
|
|
$this->OATHRepository = OATHAuthHooks::getOATHUserRepository();
|
|
}
|
|
|
|
public function doesWrites() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Set the page title and add JavaScript RL modules
|
|
*
|
|
* @param HTMLForm $form
|
|
*/
|
|
public function alterForm( HTMLForm $form ) {
|
|
$form->setMessagePrefix( 'oathauth' );
|
|
$form->setWrapperLegend( $this->msg( 'oathauth-disable-header' ) );
|
|
$form->setPreText( $this->msg( 'oathauth-disable-intro' ) );
|
|
$form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable-for-user' ) );
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected function getDisplayFormat() {
|
|
return 'ooui';
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function requiresUnblock() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Require users to be logged in
|
|
*
|
|
* @param User $user
|
|
*/
|
|
protected function checkExecutePermissions( User $user ) {
|
|
parent::checkExecutePermissions( $user );
|
|
|
|
$this->requireLogin();
|
|
}
|
|
|
|
/**
|
|
* @return array[]
|
|
*/
|
|
protected function getFormFields() {
|
|
return [
|
|
'user' => [
|
|
'type' => 'user',
|
|
'default' => '',
|
|
'label-message' => 'oathauth-enteruser',
|
|
'name' => 'user'
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array $formData
|
|
*
|
|
* @return array|bool
|
|
*/
|
|
public function onSubmit( array $formData ) {
|
|
$user = User::newFromName( $formData['user'] );
|
|
if ( $user && $user->getId() === 0 ) {
|
|
return [ 'user-not-found' ];
|
|
}
|
|
$oathUser = $this->OATHRepository->findByUser( $user );
|
|
|
|
if ( $oathUser->getKey() === null ) {
|
|
return [ 'oathauth-user-not-does-not-have-oath-enabled' ];
|
|
}
|
|
|
|
if ( $this->getUser()->pingLimiter( 'disableoath', 0 ) ) {
|
|
// Arbitrary duration given here
|
|
return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
|
|
}
|
|
|
|
$oathUser->setKey( null );
|
|
$this->OATHRepository->remove( $oathUser );
|
|
|
|
return true;
|
|
}
|
|
|
|
public function onSuccess() {
|
|
$this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
|
|
$this->getOutput()->returnToMain();
|
|
}
|
|
|
|
}
|