MediaWiki REL1_32
SpecialOATHDisable.php
Go to the documentation of this file.
1<?php
27
29 private $OATHUser;
30
37 public function __construct( OATHUserRepository $repository, OATHUser $user ) {
38 parent::__construct( 'OATH', '', false );
39 $this->OATHRepository = $repository;
40 $this->OATHUser = $user;
41 }
42
43 public function doesWrites() {
44 return true;
45 }
46
52 public function alterForm( HTMLForm $form ) {
53 $form->setMessagePrefix( 'oathauth' );
54 $form->setWrapperLegend( false );
55 $form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable' ) );
56 }
57
61 protected function getDisplayFormat() {
62 return 'ooui';
63 }
64
68 public function requiresUnblock() {
69 return false;
70 }
71
79 protected function checkExecutePermissions( User $user ) {
80 parent::checkExecutePermissions( $user );
81
82 $this->requireLogin();
83 }
84
88 protected function getFormFields() {
89 return [
90 'token' => [
91 'type' => 'text',
92 'label-message' => 'oathauth-entertoken',
93 'name' => 'token',
94 'required' => true,
95 'autofocus' => true,
96 ],
97 'returnto' => [
98 'type' => 'hidden',
99 'default' => $this->getRequest()->getVal( 'returnto' ),
100 'name' => 'returnto',
101 ],
102 'returntoquery' => [
103 'type' => 'hidden',
104 'default' => $this->getRequest()->getVal( 'returntoquery' ),
105 'name' => 'returntoquery',
106 ]
107 ];
108 }
109
115 public function onSubmit( array $formData ) {
116 // Don't increase pingLimiter, just check for limit exceeded.
117 if ( $this->OATHUser->getUser()->pingLimiter( 'badoath', 0 ) ) {
118 // Arbitrary duration given here
119 return [ 'oathauth-throttled', Message::durationParam( 60 ) ];
120 }
121
122 if ( !$this->OATHUser->getKey()->verifyToken( $formData['token'], $this->OATHUser ) ) {
123 return [ 'oathauth-failedtovalidateoath' ];
124 }
125
126 $this->OATHUser->setKey( null );
127 $this->OATHRepository->remove( $this->OATHUser );
128
129 return true;
130 }
131
132 public function onSuccess() {
133 $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' );
134 $this->getOutput()->returnToMain();
135 }
136}
Special page which uses an HTMLForm to handle processing.
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:136
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition OATHUser.php:24
getKey()
Get the key associated with this user.
Definition OATHUser.php:71
setKey(OATHAuthKey $key=null)
Set the key associated with this user.
Definition OATHUser.php:80
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
checkExecutePermissions(User $user)
Require users to be logged in.
__construct(OATHUserRepository $repository, OATHUser $user)
Initialize the OATH user based on the current local User object in the context.
onSubmit(array $formData)
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...
alterForm(HTMLForm $form)
Set the page title and add JavaScript RL modules.
OATHUserRepository $OATHRepository
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.
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:47
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
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))