MediaWiki REL1_33
SpecialDisableOATHForUser.php
Go to the documentation of this file.
1<?php
2
6
7 public function __construct() {
8 parent::__construct( 'DisableOATHForUser', 'oathauth-disable-for-user' );
9
10 $this->OATHRepository = OATHAuthHooks::getOATHUserRepository();
11 }
12
13 public function doesWrites() {
14 return true;
15 }
16
17 protected function getLoginSecurityLevel() {
18 return $this->getName();
19 }
20
26 public function alterForm( HTMLForm $form ) {
27 $form->setMessagePrefix( 'oathauth' );
28 $form->setWrapperLegend( $this->msg( 'oathauth-disable-header' ) );
29 $form->setPreText( $this->msg( 'oathauth-disable-intro' ) );
30 $form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable-for-user' ) );
31 }
32
36 protected function getDisplayFormat() {
37 return 'ooui';
38 }
39
43 public function requiresUnblock() {
44 return false;
45 }
46
52 protected function checkExecutePermissions( User $user ) {
53 parent::checkExecutePermissions( $user );
54
55 $this->requireLogin();
56 }
57
61 public function execute( $par ) {
62 $this->getOutput()->disallowUserJs();
63 parent::execute( $par );
64 }
65
69 protected function getFormFields() {
70 return [
71 'user' => [
72 'type' => 'user',
73 'default' => '',
74 'label-message' => 'oathauth-enteruser',
75 'name' => 'user'
76 ]
77 ];
78 }
79
85 public function onSubmit( array $formData ) {
86 $user = User::newFromName( $formData['user'] );
87 if ( $user && $user->getId() === 0 ) {
88 return [ 'oathauth-user-not-found' ];
89 }
90 $oathUser = $this->OATHRepository->findByUser( $user );
91
92 if ( $oathUser->getKey() === null ) {
93 return [ 'oathauth-user-not-does-not-have-oath-enabled' ];
94 }
95
96 if ( $this->getUser()->pingLimiter( 'disableoath', 0 ) ) {
97 // Arbitrary duration given here
98 return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
99 }
100
101 $oathUser->setKey( null );
102 $this->OATHRepository->remove( $oathUser, $this->getRequest()->getIP() );
103
104 \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )->info(
105 'OATHAuth disabled for {usertarget} by {user} from {clientip}', [
106 'user' => $this->getUser()->getName(),
107 'usertarget' => $formData['user'],
108 'clientip' => $this->getRequest()->getIP(),
109 ]
110 );
111
112 return true;
113 }
114
115 public function onSuccess() {
116 $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
117 $this->getOutput()->returnToMain();
118 }
119
120}
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:133
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:734
static getOATHUserRepository()
Get the singleton OATH user repository.
doesWrites()
Indicates whether this special page may perform database writes.
checkExecutePermissions(User $user)
Require users to be logged in.
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
getName()
Get the name of this Special Page.
getOutput()
Get the OutputPage being used for this instance.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:585
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))