MediaWiki  1.27.2
SpecialChangeCredentials.php
Go to the documentation of this file.
1 <?php
2 
7 
14  protected static $allowedActions = [ AuthManager::ACTION_CHANGE ];
15 
16  protected static $messagePrefix = 'changecredentials';
17 
19  protected static $loadUserData = true;
20 
21  public function __construct( $name = 'ChangeCredentials' ) {
22  parent::__construct( $name, 'editmyprivateinfo' );
23  }
24 
25  protected function getGroupName() {
26  return 'users';
27  }
28 
29  public function isListed() {
30  $this->loadAuth( '' );
31  return (bool)$this->authRequests;
32  }
33 
34  public function doesWrites() {
35  return true;
36  }
37 
38  protected function getDefaultAction( $subPage ) {
39  return AuthManager::ACTION_CHANGE;
40  }
41 
42  protected function getPreservedParams( $withToken = false ) {
43  $request = $this->getRequest();
44  $params = parent::getPreservedParams( $withToken );
45  $params += [
46  'returnto' => $request->getVal( 'returnto' ),
47  'returntoquery' => $request->getVal( 'returntoquery' ),
48  ];
49  return $params;
50  }
51 
52  public function onAuthChangeFormFields(
53  array $requests, array $fieldInfo, array &$formDescriptor, $action
54  ) {
55  // This method is never called for remove actions.
56 
57  $extraFields = [];
58  Hooks::run( 'ChangePasswordForm', [ &$extraFields ], '1.27' );
59  foreach ( $extraFields as $extra ) {
60  list( $name, $label, $type, $default ) = $extra;
61  $formDescriptor[$name] = [
62  'type' => $type,
63  'name' => $name,
64  'label-message' => $label,
65  'default' => $default,
66  ];
67 
68  }
69 
70  return parent::onAuthChangeFormFields( $requests, $fieldInfo, $formDescriptor, $action );
71  }
72 
73  public function execute( $subPage ) {
74  $this->setHeaders();
75  $this->outputHeader();
76 
77  $this->loadAuth( $subPage );
78 
79  if ( !$subPage ) {
80  $this->showSubpageList();
81  return;
82  }
83 
84  if ( $this->getRequest()->getCheck( 'wpCancel' ) ) {
85  $returnUrl = $this->getReturnUrl() ?: Title::newMainPage()->getFullURL();
86  $this->getOutput()->redirect( $returnUrl );
87  return;
88  }
89 
90  if ( !$this->authRequests ) {
91  // messages used: changecredentials-invalidsubpage, removecredentials-invalidsubpage
92  $this->showSubpageList( $this->msg( static::$messagePrefix . '-invalidsubpage', $subPage ) );
93  return;
94  }
95 
96  $status = $this->trySubmit();
97 
98  if ( $status === false || !$status->isOK() ) {
99  $this->displayForm( $status );
100  return;
101  }
102 
103  $response = $status->getValue();
104 
105  switch ( $response->status ) {
106  case AuthenticationResponse::PASS:
107  $this->success();
108  break;
109  case AuthenticationResponse::FAIL:
110  $this->displayForm( Status::newFatal( $response->message ) );
111  break;
112  default:
113  throw new LogicException( 'invalid AuthenticationResponse' );
114  }
115  }
116 
117  protected function loadAuth( $subPage, $authAction = null, $reset = false ) {
118  parent::loadAuth( $subPage, $authAction );
119  if ( $subPage ) {
120  $this->authRequests = array_filter( $this->authRequests, function ( $req ) use ( $subPage ) {
121  return $req->getUniqueId() === $subPage;
122  } );
123  if ( count( $this->authRequests ) > 1 ) {
124  throw new LogicException( 'Multiple AuthenticationRequest objects with same ID!' );
125  }
126  }
127  }
128 
129  protected function getAuthFormDescriptor( $requests, $action ) {
130  if ( !static::$loadUserData ) {
131  return [];
132  } else {
133  return parent::getAuthFormDescriptor( $requests, $action );
134  }
135  }
136 
137  protected function getAuthForm( array $requests, $action ) {
138  $form = parent::getAuthForm( $requests, $action );
139  $req = reset( $requests );
140  $info = $req->describeCredentials();
141 
142  $form->addPreText(
143  Html::openElement( 'dl' )
144  . Html::element( 'dt', [], wfMessage( 'credentialsform-provider' ) )
145  . Html::element( 'dd', [], $info['provider'] )
146  . Html::element( 'dt', [], wfMessage( 'credentialsform-account' ) )
147  . Html::element( 'dd', [], $info['account'] )
148  . Html::closeElement( 'dl' )
149  );
150 
151  // messages used: changecredentials-submit removecredentials-submit
152  // changecredentials-submit-cancel removecredentials-submit-cancel
153  $form->setSubmitTextMsg( static::$messagePrefix . '-submit' );
154  $form->addButton( [
155  'name' => 'wpCancel',
156  'value' => $this->msg( static::$messagePrefix . '-submit-cancel' )->text()
157  ] );
158 
159  return $form;
160  }
161 
162  protected function needsSubmitButton( array $requests ) {
163  // Change/remove forms show are built from a single AuthenticationRequest and do not allow
164  // for redirect flow; they always need a submit button.
165  return true;
166  }
167 
168  public function handleFormSubmit( $data ) {
169  // remove requests do not accept user input
171  if ( static::$loadUserData ) {
172  $requests = AuthenticationRequest::loadRequestsFromSubmission( $this->authRequests, $data );
173  }
174 
175  $response = $this->performAuthenticationStep( $this->authAction, $requests );
176 
177  // we can't handle FAIL or similar as failure here since it might require changing the form
178  return Status::newGood( $response );
179  }
180 
184  protected function showSubpageList( $error = null ) {
185  $out = $this->getOutput();
186 
187  if ( $error ) {
188  $out->addHTML( $error->parse() );
189  }
190 
191  $groupedRequests = [];
192  foreach ( $this->authRequests as $req ) {
193  $info = $req->describeCredentials();
194  $groupedRequests[(string)$info['provider']][] = $req;
195  }
196 
197  $out->addHTML( Html::openElement( 'dl' ) );
198  foreach ( $groupedRequests as $group => $members ) {
199  $out->addHTML( Html::element( 'dt', [], $group ) );
200  foreach ( $members as $req ) {
202  $info = $req->describeCredentials();
203  $out->addHTML( Html::rawElement( 'dd', [],
204  Linker::link( $this->getPageTitle( $req->getUniqueId() ),
205  htmlspecialchars( $info['account'], ENT_QUOTES ) )
206  ) );
207  }
208  }
209  $out->addHTML( Html::closeElement( 'dl' ) );
210  }
211 
212  protected function success() {
213  $session = $this->getRequest()->getSession();
214  $user = $this->getUser();
215  $out = $this->getOutput();
216  $returnUrl = $this->getReturnUrl();
217 
218  // change user token and update the session
219  SessionManager::singleton()->invalidateSessionsForUser( $user );
220  $session->setUser( $user );
221  $session->resetId();
222 
223  if ( $returnUrl ) {
224  $out->redirect( $returnUrl );
225  } else {
226  // messages used: changecredentials-success removecredentials-success
227  $out->wrapWikiMsg( "<div class=\"successbox\">\n$1\n</div>", static::$messagePrefix
228  . '-success' );
229  $out->returnToMain();
230  }
231  }
232 
236  protected function getReturnUrl() {
237  $request = $this->getRequest();
238  $returnTo = $request->getText( 'returnto' );
239  $returnToQuery = $request->getText( 'returntoquery', '' );
240 
241  if ( !$returnTo ) {
242  return null;
243  }
244 
246  return $title->getFullUrlForRedirect( $returnToQuery );
247  }
248 
249  protected function getRequestBlacklist() {
250  return $this->getConfig()->get( 'ChangeCredentialsBlacklist' );
251  }
252 }
static closeElement($element)
Returns "".
Definition: Html.php:306
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:762
the array() calling protocol came about after MediaWiki 1.4rc1.
A special page subclass for authentication-related special pages.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string & $returnToQuery
Definition: hooks.txt:2338
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:569
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:177
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
this hook is for auditing only $response
Definition: hooks.txt:762
static newFatal($message)
Factory function for fatal errors.
Definition: Status.php:89
displayForm($status)
Display the form.
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getAuthForm(array $requests, $action)
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
getAuthFormDescriptor($requests, $action)
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
$params
performAuthenticationStep($action, array $requests)
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks hooks can tweak the array to change how login etc forms should look $requests
Definition: hooks.txt:312
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
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:12
loadAuth($subPage, $authAction=null, $reset=false)
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
Definition: distributors.txt:9
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:242
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:195
AuthenticationRequest[] $authRequests
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
this hook is for auditing only $req
Definition: hooks.txt:965
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2418
Special change to change credentials (such as the password).
getUser()
Shortcut to get the User executing this instance.
getConfig()
Shortcut to get main config object.
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:1004
__construct($name= 'ChangeCredentials')
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect & $returnTo
Definition: hooks.txt:2338
string $subPage
Subpage of the special page.
static $loadUserData
Change action needs user data; remove action does not.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2338
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
static newGood($value=null)
Factory function for good results.
Definition: Status.php:101
string $authAction
one of the AuthManager::ACTION_* constants.
getPageTitle($subpage=false)
Get a self-referential title object.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310
trySubmit()
Attempts to do an authentication step with the submitted data.