MediaWiki REL1_34
DisableOATHForUser.php
Go to the documentation of this file.
1<?php
2
4
10use HTMLForm;
11use User;
15use Message;
16use MWException;
18
21 private $userRepo;
22
23 public function __construct() {
24 parent::__construct( 'DisableOATHForUser', 'oathauth-disable-for-user' );
25
26 $this->userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
27 }
28
29 public function doesWrites() {
30 return true;
31 }
32
33 protected function getLoginSecurityLevel() {
34 return $this->getName();
35 }
36
42 public function alterForm( HTMLForm $form ) {
43 $form->setMessagePrefix( 'oathauth' );
44 $form->setWrapperLegend( $this->msg( 'oathauth-disable-header' ) );
45 $form->setPreText( $this->msg( 'oathauth-disable-intro' ) );
46 $form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable-for-user' ) );
47 }
48
52 protected function getDisplayFormat() {
53 return 'ooui';
54 }
55
59 public function requiresUnblock() {
60 return false;
61 }
62
68 protected function checkExecutePermissions( User $user ) {
69 parent::checkExecutePermissions( $user );
70
71 $this->requireLogin();
72 }
73
77 public function execute( $par ) {
78 $this->getOutput()->disallowUserJs();
79 parent::execute( $par );
80 }
81
85 protected function getFormFields() {
86 return [
87 'user' => [
88 'type' => 'user',
89 'default' => '',
90 'label-message' => 'oathauth-enteruser',
91 'name' => 'user',
92 'required' => true,
93 ],
94 'reason' => [
95 'type' => 'text',
96 'default' => '',
97 'label-message' => 'oathauth-enterreason',
98 'name' => 'reason',
99 'required' => true,
100 ],
101 ];
102 }
103
110 public function onSubmit( array $formData ) {
111 $user = User::newFromName( $formData['user'] );
112 if ( $user && $user->getId() === 0 ) {
113 return [ 'oathauth-user-not-found' ];
114 }
115 $oathUser = $this->userRepo->findByUser( $user );
116
117 if ( !( $oathUser->getModule() instanceof IModule ) ||
118 !$oathUser->getModule()->isEnabled( $oathUser ) ) {
119 return [ 'oathauth-user-not-does-not-have-oath-enabled' ];
120 }
121
122 if ( $this->getUser()->pingLimiter( 'disableoath', 0 ) ) {
123 // Arbitrary duration given here
124 return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
125 }
126
127 $oathUser->disable();
128 $this->userRepo->remove( $oathUser, $this->getRequest()->getIP() );
129
130 $logEntry = new ManualLogEntry( 'oath', 'disable-other' );
131 $logEntry->setPerformer( $this->getUser() );
132 $logEntry->setTarget( $user->getUserPage() );
133 $logEntry->setComment( $formData['reason'] );
134 $logEntry->insert();
135
136 LoggerFactory::getInstance( 'authentication' )->info(
137 'OATHAuth disabled for {usertarget} by {user} from {clientip}', [
138 'user' => $this->getUser()->getName(),
139 'usertarget' => $formData['user'],
140 'clientip' => $this->getRequest()->getIP(),
141 ]
142 );
143
144 return true;
145 }
146
147 public function onSuccess() {
148 $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
149 $this->getOutput()->returnToMain();
150 }
151
152}
Exceptions for config failures.
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 in a reusabl...
Definition HTMLForm.php:131
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition HTMLForm.php:764
setMessagePrefix( $p)
Set the prefix for various default messages.
MediaWiki exception.
Class for creating new log entries and inserting them into the database.
doesWrites()
Indicates whether this special page may perform database writes.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
The Message class provides methods which fulfil two basic services:
Definition Message.php:162
static durationParam( $duration)
Definition Message.php:1049
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,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
Show an error when the user tries to do something whilst blocked.
Redirect a user to the login page.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:518
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...