MediaWiki REL1_28
SpecialPasswordReset.php
Go to the documentation of this file.
1<?php
25
38
42 private $passwords = [];
43
47 private $result;
48
52 private $method;
53
54 public function __construct() {
55 parent::__construct( 'PasswordReset', 'editmyprivateinfo' );
56 $this->passwordReset = new PasswordReset( $this->getConfig(), AuthManager::singleton() );
57 }
58
59 public function doesWrites() {
60 return true;
61 }
62
63 public function userCanExecute( User $user ) {
64 return $this->passwordReset->isAllowed( $user )->isGood();
65 }
66
67 public function checkExecutePermissions( User $user ) {
68 $status = Status::wrap( $this->passwordReset->isAllowed( $user ) );
69 if ( !$status->isGood() ) {
70 throw new ErrorPageError( 'internalerror', $status->getMessage() );
71 }
72
73 parent::checkExecutePermissions( $user );
74 }
75
76 protected function getFormFields() {
77 $resetRoutes = $this->getConfig()->get( 'PasswordResetRoutes' );
78 $a = [];
79 if ( isset( $resetRoutes['username'] ) && $resetRoutes['username'] ) {
80 $a['Username'] = [
81 'type' => 'text',
82 'label-message' => 'passwordreset-username',
83 ];
84
85 if ( $this->getUser()->isLoggedIn() ) {
86 $a['Username']['default'] = $this->getUser()->getName();
87 }
88 }
89
90 if ( isset( $resetRoutes['email'] ) && $resetRoutes['email'] ) {
91 $a['Email'] = [
92 'type' => 'email',
93 'label-message' => 'passwordreset-email',
94 ];
95 }
96
97 if ( $this->getUser()->isAllowed( 'passwordreset' ) ) {
98 $a['Capture'] = [
99 'type' => 'check',
100 'label-message' => 'passwordreset-capture',
101 'help-message' => 'passwordreset-capture-help',
102 ];
103 }
104
105 return $a;
106 }
107
108 protected function getDisplayFormat() {
109 return 'ooui';
110 }
111
112 public function alterForm( HTMLForm $form ) {
113 $resetRoutes = $this->getConfig()->get( 'PasswordResetRoutes' );
114
115 $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
116
117 $i = 0;
118 if ( isset( $resetRoutes['username'] ) && $resetRoutes['username'] ) {
119 $i++;
120 }
121 if ( isset( $resetRoutes['email'] ) && $resetRoutes['email'] ) {
122 $i++;
123 }
124
125 $message = ( $i > 1 ) ? 'passwordreset-text-many' : 'passwordreset-text-one';
126
127 $form->setHeaderText( $this->msg( $message, $i )->parseAsBlock() );
128 $form->setSubmitTextMsg( 'mailmypassword' );
129 }
130
140 public function onSubmit( array $data ) {
141 if ( isset( $data['Capture'] ) && !$this->getUser()->isAllowed( 'passwordreset' ) ) {
142 // The user knows they don't have the passwordreset permission,
143 // but they tried to spoof the form. That's naughty
144 throw new PermissionsError( 'passwordreset' );
145 }
146
147 $username = isset( $data['Username'] ) ? $data['Username'] : null;
148 $email = isset( $data['Email'] ) ? $data['Email'] : null;
149 $capture = !empty( $data['Capture'] );
150
151 $this->method = $username ? 'username' : 'email';
152 $this->result = Status::wrap(
153 $this->passwordReset->execute( $this->getUser(), $username, $email, $capture ) );
154 if ( $capture && $this->result->isOK() ) {
155 $this->passwords = $this->result->getValue();
156 }
157
158 if ( $this->result->hasMessage( 'actionthrottledtext' ) ) {
159 throw new ThrottledError;
160 }
161
162 return $this->result;
163 }
164
165 public function onSuccess() {
166 if ( $this->getUser()->isAllowed( 'passwordreset' ) && $this->passwords ) {
167 // @todo Logging
168
169 if ( $this->result->isGood() ) {
170 $this->getOutput()->addWikiMsg( 'passwordreset-emailsent-capture2',
171 count( $this->passwords ) );
172 } else {
173 $this->getOutput()->addWikiMsg( 'passwordreset-emailerror-capture2',
174 $this->result->getMessage(), key( $this->passwords ), count( $this->passwords ) );
175 }
176
177 $this->getOutput()->addHTML( Html::openElement( 'ul' ) );
178 foreach ( $this->passwords as $username => $pwd ) {
179 $this->getOutput()->addHTML( Html::rawElement( 'li', [],
180 htmlspecialchars( $username, ENT_QUOTES )
181 . $this->msg( 'colon-separator' )->text()
182 . htmlspecialchars( $pwd, ENT_QUOTES )
183 ) );
184 }
185 $this->getOutput()->addHTML( Html::closeElement( 'ul' ) );
186 }
187
188 if ( $this->method === 'email' ) {
189 $this->getOutput()->addWikiMsg( 'passwordreset-emailsentemail' );
190 } else {
191 $this->getOutput()->addWikiMsg( 'passwordreset-emailsentusername' );
192 }
193
194 $this->getOutput()->returnToMain();
195 }
196
201 public function isListed() {
202 if ( $this->passwordReset->isAllowed( $this->getUser() )->isGood() ) {
203 return parent::isListed();
204 }
205
206 return false;
207 }
208
209 protected function getGroupName() {
210 return 'users';
211 }
212}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
An error page which can definitely be safely rendered using the OutputPage.
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:128
setHeaderText( $msg, $section=null)
Set header text, inside the form.
Definition HTMLForm.php:779
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition HTMLForm.php:911
This serves as the entry point to the authentication system.
Helper class for the password reset functionality shared by the web UI and the API.
Show an error when a user tries to do something they do not have the necessary permissions for.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
msg()
Wrapper around wfMessage that sets the current context.
Special page for requesting a password reset email.
getDisplayFormat()
Get display format for the form.
getFormFields()
Get an HTMLForm descriptor array.
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...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
isListed()
Hide the password reset page if resets are disabled.
onSubmit(array $data)
Process the form.
string[] $passwords
Temporary storage for the passwords which have been sent out, keyed by username.
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
userCanExecute(User $user)
Checks if the given user (identified by an object) can execute this special page (as defined by $mRes...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
Show an error when the user hits a rate limit.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition design.txt:26
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
the array() calling protocol came about after MediaWiki 1.4rc1.
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:249
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:807
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:37