MediaWiki  1.33.0
SpecialDisableOATHForUser.php
Go to the documentation of this file.
1 <?php
2 
5  private $OATHRepository;
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  protected function getFormFields() {
62  return [
63  'user' => [
64  'type' => 'user',
65  'default' => '',
66  'label-message' => 'oathauth-enteruser',
67  'name' => 'user'
68  ]
69  ];
70  }
71 
77  public function onSubmit( array $formData ) {
78  $user = User::newFromName( $formData['user'] );
79  if ( $user && $user->getId() === 0 ) {
80  return [ 'oathauth-user-not-found' ];
81  }
82  $oathUser = $this->OATHRepository->findByUser( $user );
83 
84  if ( $oathUser->getKey() === null ) {
85  return [ 'oathauth-user-not-does-not-have-oath-enabled' ];
86  }
87 
88  if ( $this->getUser()->pingLimiter( 'disableoath', 0 ) ) {
89  // Arbitrary duration given here
90  return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
91  }
92 
93  $oathUser->setKey( null );
94  $this->OATHRepository->remove( $oathUser, $this->getRequest()->getIP() );
95 
96  \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' )->info(
97  'OATHAuth disabled for {usertarget} by {user} from {clientip}', [
98  'user' => $this->getUser()->getName(),
99  'usertarget' => $formData['user'],
100  'clientip' => $this->getRequest()->getIP(),
101  ]
102  );
103 
104  return true;
105  }
106 
107  public function onSuccess() {
108  $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
109  $this->getOutput()->returnToMain();
110  }
111 
112 }
SpecialDisableOATHForUser\onSuccess
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Definition: SpecialDisableOATHForUser.php:107
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
SpecialDisableOATHForUser\getDisplayFormat
getDisplayFormat()
Definition: SpecialDisableOATHForUser.php:36
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
HTMLForm\setPreText
setPreText( $msg)
Set the introductory message HTML, overwriting any existing message.
Definition: HTMLForm.php:734
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
OATHUserRepository
Definition: OATHUserRepository.php:23
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
SpecialDisableOATHForUser\requiresUnblock
requiresUnblock()
Definition: SpecialDisableOATHForUser.php:43
FormSpecialPage
Special page which uses an HTMLForm to handle processing.
Definition: FormSpecialPage.php:31
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
SpecialDisableOATHForUser\onSubmit
onSubmit(array $formData)
Definition: SpecialDisableOATHForUser.php:77
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:152
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SpecialDisableOATHForUser\alterForm
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
Definition: SpecialDisableOATHForUser.php:26
SpecialDisableOATHForUser\getFormFields
getFormFields()
Definition: SpecialDisableOATHForUser.php:61
SpecialDisableOATHForUser
Definition: SpecialDisableOATHForUser.php:3
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:112
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:735
HTMLForm\setMessagePrefix
setMessagePrefix( $p)
Set the prefix for various default messages.
Definition: HTMLForm.php:1563
array
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))
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:339
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
SpecialDisableOATHForUser\getLoginSecurityLevel
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
Definition: SpecialDisableOATHForUser.php:17
SpecialDisableOATHForUser\__construct
__construct()
Definition: SpecialDisableOATHForUser.php:7
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:715
HTMLForm\setWrapperLegend
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
Definition: HTMLForm.php:1530
SpecialDisableOATHForUser\checkExecutePermissions
checkExecutePermissions(User $user)
Require users to be logged in.
Definition: SpecialDisableOATHForUser.php:52
SpecialDisableOATHForUser\$OATHRepository
OATHUserRepository $OATHRepository
Definition: SpecialDisableOATHForUser.php:5
SpecialDisableOATHForUser\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialDisableOATHForUser.php:13
OATHAuthHooks\getOATHUserRepository
static getOATHUserRepository()
Get the singleton OATH user repository.
Definition: OATHAuthHooks.php:34
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:133