MediaWiki REL1_33
AuthManagerSpecialPage.php
Go to the documentation of this file.
1<?php
2
8
14abstract class AuthManagerSpecialPage extends SpecialPage {
17 protected static $allowedActions = [
18 AuthManager::ACTION_LOGIN, AuthManager::ACTION_LOGIN_CONTINUE,
19 AuthManager::ACTION_CREATE, AuthManager::ACTION_CREATE_CONTINUE,
20 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
21 AuthManager::ACTION_CHANGE, AuthManager::ACTION_REMOVE, AuthManager::ACTION_UNLINK,
22 ];
23
25 protected static $messages = [];
26
28 protected $authAction;
29
31 protected $authRequests;
32
34 protected $subPage;
35
37 protected $isReturn;
38
40 protected $savedRequest;
41
53 public function onAuthChangeFormFields(
54 array $requests, array $fieldInfo, array &$formDescriptor, $action
55 ) {
56 return true;
57 }
58
59 protected function getLoginSecurityLevel() {
60 return $this->getName();
61 }
62
63 public function getRequest() {
64 return $this->savedRequest ?: $this->getContext()->getRequest();
65 }
66
75 protected function setRequest( array $data, $wasPosted = null ) {
76 $request = $this->getContext()->getRequest();
77 if ( $wasPosted === null ) {
78 $wasPosted = $request->wasPosted();
79 }
80 $this->savedRequest = new DerivativeRequest( $request, $data + $request->getQueryValues(),
81 $wasPosted );
82 }
83
84 protected function beforeExecute( $subPage ) {
85 $this->getOutput()->disallowUserJs();
86
87 return $this->handleReturnBeforeExecute( $subPage )
89 }
90
107 protected function handleReturnBeforeExecute( $subPage ) {
108 $authManager = AuthManager::singleton();
109 $key = 'AuthManagerSpecialPage:return:' . $this->getName();
110
111 if ( $subPage === 'return' ) {
112 $this->loadAuth( $subPage );
113 $preservedParams = $this->getPreservedParams( false );
114
115 // FIXME save POST values only from request
116 $authData = array_diff_key( $this->getRequest()->getValues(),
117 $preservedParams, [ 'title' => 1 ] );
118 $authManager->setAuthenticationSessionData( $key, $authData );
119
120 $url = $this->getPageTitle()->getFullURL( $preservedParams, false, PROTO_HTTPS );
121 $this->getOutput()->redirect( $url );
122 return false;
123 }
124
125 $authData = $authManager->getAuthenticationSessionData( $key );
126 if ( $authData ) {
127 $authManager->removeAuthenticationSessionData( $key );
128 $this->isReturn = true;
129 $this->setRequest( $authData, true );
130 }
131
132 return true;
133 }
134
145 protected function handleReauthBeforeExecute( $subPage ) {
146 $authManager = AuthManager::singleton();
147 $request = $this->getRequest();
148 $key = 'AuthManagerSpecialPage:reauth:' . $this->getName();
149
150 $securityLevel = $this->getLoginSecurityLevel();
151 if ( $securityLevel ) {
152 $securityStatus = AuthManager::singleton()
153 ->securitySensitiveOperationStatus( $securityLevel );
154 if ( $securityStatus === AuthManager::SEC_REAUTH ) {
155 $queryParams = array_diff_key( $request->getQueryValues(), [ 'title' => true ] );
156
157 if ( $request->wasPosted() ) {
158 // unique ID in case the same special page is open in multiple browser tabs
159 $uniqueId = MWCryptRand::generateHex( 6 );
160 $key .= ':' . $uniqueId;
161
162 $queryParams = [ 'authUniqueId' => $uniqueId ] + $queryParams;
163 $authData = array_diff_key( $request->getValues(),
164 $this->getPreservedParams( false ), [ 'title' => 1 ] );
165 $authManager->setAuthenticationSessionData( $key, $authData );
166 }
167
168 $title = SpecialPage::getTitleFor( 'Userlogin' );
169 $url = $title->getFullURL( [
170 'returnto' => $this->getFullTitle()->getPrefixedDBkey(),
171 'returntoquery' => wfArrayToCgi( $queryParams ),
172 'force' => $securityLevel,
173 ], false, PROTO_HTTPS );
174
175 $this->getOutput()->redirect( $url );
176 return false;
177 } elseif ( $securityStatus !== AuthManager::SEC_OK ) {
178 throw new ErrorPageError( 'cannotauth-not-allowed-title', 'cannotauth-not-allowed' );
179 }
180 }
181
182 $uniqueId = $request->getVal( 'authUniqueId' );
183 if ( $uniqueId ) {
184 $key .= ':' . $uniqueId;
185 $authData = $authManager->getAuthenticationSessionData( $key );
186 if ( $authData ) {
187 $authManager->removeAuthenticationSessionData( $key );
188 $this->setRequest( $authData, true );
189 }
190 }
191
192 return true;
193 }
194
201 abstract protected function getDefaultAction( $subPage );
202
209 protected function messageKey( $defaultKey ) {
210 return array_key_exists( $defaultKey, static::$messages )
211 ? static::$messages[$defaultKey] : $defaultKey;
212 }
213
218 protected function getRequestBlacklist() {
219 return [];
220 }
221
231 protected function loadAuth( $subPage, $authAction = null, $reset = false ) {
232 // Do not load if already loaded, to cut down on the number of getAuthenticationRequests
233 // calls. This is important for requests which have hidden information so any
234 // getAuthenticationRequests call would mean putting data into some cache.
235 if (
236 !$reset && $this->subPage === $subPage && $this->authAction
237 && ( !$authAction || $authAction === $this->authAction )
238 ) {
239 return;
240 }
241
242 $request = $this->getRequest();
243 $this->subPage = $subPage;
244 $this->authAction = $authAction ?: $request->getText( 'authAction' );
245 if ( !in_array( $this->authAction, static::$allowedActions, true ) ) {
246 $this->authAction = $this->getDefaultAction( $subPage );
247 if ( $request->wasPosted() ) {
248 $continueAction = $this->getContinueAction( $this->authAction );
249 if ( in_array( $continueAction, static::$allowedActions, true ) ) {
250 $this->authAction = $continueAction;
251 }
252 }
253 }
254
255 $allReqs = AuthManager::singleton()->getAuthenticationRequests(
256 $this->authAction, $this->getUser() );
257 $this->authRequests = array_filter( $allReqs, function ( $req ) {
258 return !in_array( get_class( $req ), $this->getRequestBlacklist(), true );
259 } );
260 }
261
266 protected function isContinued() {
267 return in_array( $this->authAction, [
268 AuthManager::ACTION_LOGIN_CONTINUE,
269 AuthManager::ACTION_CREATE_CONTINUE,
270 AuthManager::ACTION_LINK_CONTINUE,
271 ], true );
272 }
273
279 protected function getContinueAction( $action ) {
280 switch ( $action ) {
281 case AuthManager::ACTION_LOGIN:
282 $action = AuthManager::ACTION_LOGIN_CONTINUE;
283 break;
284 case AuthManager::ACTION_CREATE:
285 $action = AuthManager::ACTION_CREATE_CONTINUE;
286 break;
287 case AuthManager::ACTION_LINK:
288 $action = AuthManager::ACTION_LINK_CONTINUE;
289 break;
290 }
291 return $action;
292 }
293
302 protected function isActionAllowed( $action ) {
303 $authManager = AuthManager::singleton();
304 if ( !in_array( $action, static::$allowedActions, true ) ) {
305 throw new InvalidArgumentException( 'invalid action: ' . $action );
306 }
307
308 // calling getAuthenticationRequests can be expensive, avoid if possible
309 $requests = ( $action === $this->authAction ) ? $this->authRequests
310 : $authManager->getAuthenticationRequests( $action );
311 if ( !$requests ) {
312 // no provider supports this action in the current state
313 return false;
314 }
315
316 switch ( $action ) {
317 case AuthManager::ACTION_LOGIN:
318 case AuthManager::ACTION_LOGIN_CONTINUE:
319 return $authManager->canAuthenticateNow();
320 case AuthManager::ACTION_CREATE:
321 case AuthManager::ACTION_CREATE_CONTINUE:
322 return $authManager->canCreateAccounts();
323 case AuthManager::ACTION_LINK:
324 case AuthManager::ACTION_LINK_CONTINUE:
325 return $authManager->canLinkAccounts();
326 case AuthManager::ACTION_CHANGE:
327 case AuthManager::ACTION_REMOVE:
328 case AuthManager::ACTION_UNLINK:
329 return true;
330 default:
331 // should never reach here but makes static code analyzers happy
332 throw new InvalidArgumentException( 'invalid action: ' . $action );
333 }
334 }
335
342 protected function performAuthenticationStep( $action, array $requests ) {
343 if ( !in_array( $action, static::$allowedActions, true ) ) {
344 throw new InvalidArgumentException( 'invalid action: ' . $action );
345 }
346
347 $authManager = AuthManager::singleton();
348 $returnToUrl = $this->getPageTitle( 'return' )
349 ->getFullURL( $this->getPreservedParams( true ), false, PROTO_HTTPS );
350
351 switch ( $action ) {
352 case AuthManager::ACTION_LOGIN:
353 return $authManager->beginAuthentication( $requests, $returnToUrl );
354 case AuthManager::ACTION_LOGIN_CONTINUE:
355 return $authManager->continueAuthentication( $requests );
356 case AuthManager::ACTION_CREATE:
357 return $authManager->beginAccountCreation( $this->getUser(), $requests,
358 $returnToUrl );
359 case AuthManager::ACTION_CREATE_CONTINUE:
360 return $authManager->continueAccountCreation( $requests );
361 case AuthManager::ACTION_LINK:
362 return $authManager->beginAccountLink( $this->getUser(), $requests, $returnToUrl );
363 case AuthManager::ACTION_LINK_CONTINUE:
364 return $authManager->continueAccountLink( $requests );
365 case AuthManager::ACTION_CHANGE:
366 case AuthManager::ACTION_REMOVE:
367 case AuthManager::ACTION_UNLINK:
368 if ( count( $requests ) > 1 ) {
369 throw new InvalidArgumentException( 'only one auth request can be changed at a time' );
370 } elseif ( !$requests ) {
371 throw new InvalidArgumentException( 'no auth request' );
372 }
373 $req = reset( $requests );
374 $status = $authManager->allowsAuthenticationDataChange( $req );
375 Hooks::run( 'ChangeAuthenticationDataAudit', [ $req, $status ] );
376 if ( !$status->isGood() ) {
377 return AuthenticationResponse::newFail( $status->getMessage() );
378 }
379 $authManager->changeAuthenticationData( $req );
380 return AuthenticationResponse::newPass();
381 default:
382 // should never reach here but makes static code analyzers happy
383 throw new InvalidArgumentException( 'invalid action: ' . $action );
384 }
385 }
386
397 protected function trySubmit() {
398 $status = false;
399
400 $form = $this->getAuthForm( $this->authRequests, $this->authAction );
401 $form->setSubmitCallback( [ $this, 'handleFormSubmit' ] );
402
403 if ( $this->getRequest()->wasPosted() ) {
404 // handle tokens manually; $form->tryAuthorizedSubmit only works for logged-in users
405 $requestTokenValue = $this->getRequest()->getVal( $this->getTokenName() );
406 $sessionToken = $this->getToken();
407 if ( $sessionToken->wasNew() ) {
408 return Status::newFatal( $this->messageKey( 'authform-newtoken' ) );
409 } elseif ( !$requestTokenValue ) {
410 return Status::newFatal( $this->messageKey( 'authform-notoken' ) );
411 } elseif ( !$sessionToken->match( $requestTokenValue ) ) {
412 return Status::newFatal( $this->messageKey( 'authform-wrongtoken' ) );
413 }
414
415 $form->prepareForm();
416 $status = $form->trySubmit();
417
418 // HTMLForm submit return values are a mess; let's ensure it is false or a Status
419 // FIXME this probably should be in HTMLForm
420 if ( $status === true ) {
421 // not supposed to happen since our submit handler should always return a Status
422 throw new UnexpectedValueException( 'HTMLForm::trySubmit() returned true' );
423 } elseif ( $status === false ) {
424 // form was not submitted; nothing to do
425 } elseif ( $status instanceof Status ) {
426 // already handled by the form; nothing to do
427 } elseif ( $status instanceof StatusValue ) {
428 // in theory not an allowed return type but nothing stops the submit handler from
429 // accidentally returning it so best check and fix
430 $status = Status::wrap( $status );
431 } elseif ( is_string( $status ) ) {
432 $status = Status::newFatal( new RawMessage( '$1', $status ) );
433 } elseif ( is_array( $status ) ) {
434 if ( is_string( reset( $status ) ) ) {
435 $status = Status::newFatal( ...$status );
436 } elseif ( is_array( reset( $status ) ) ) {
437 $status = Status::newGood();
438 foreach ( $status as $message ) {
439 $status->fatal( ...$message );
440 }
441 } else {
442 throw new UnexpectedValueException( 'invalid HTMLForm::trySubmit() return value: '
443 . 'first element of array is ' . gettype( reset( $status ) ) );
444 }
445 } else {
446 // not supposed to happen but HTMLForm does not actually verify the return type
447 // from the submit callback; better safe then sorry
448 throw new UnexpectedValueException( 'invalid HTMLForm::trySubmit() return type: '
449 . gettype( $status ) );
450 }
451
452 if ( ( !$status || !$status->isOK() ) && $this->isReturn ) {
453 // This is awkward. There was a form validation error, which means the data was not
454 // passed to AuthManager. Normally we would display the form with an error message,
455 // but for the data we received via the redirect flow that would not be helpful at all.
456 // Let's just submit the data to AuthManager directly instead.
457 LoggerFactory::getInstance( 'authentication' )
458 ->warning( 'Validation error on return', [ 'data' => $form->mFieldData,
459 'status' => $status->getWikiText( false, false, 'en' ) ] );
460 $status = $this->handleFormSubmit( $form->mFieldData );
461 }
462 }
463
464 $changeActions = [
465 AuthManager::ACTION_CHANGE, AuthManager::ACTION_REMOVE, AuthManager::ACTION_UNLINK
466 ];
467 if ( in_array( $this->authAction, $changeActions, true ) && $status && !$status->isOK() ) {
468 Hooks::run( 'ChangeAuthenticationDataAudit', [ reset( $this->authRequests ), $status ] );
469 }
470
471 return $status;
472 }
473
480 public function handleFormSubmit( $data ) {
481 $requests = AuthenticationRequest::loadRequestsFromSubmission( $this->authRequests, $data );
482 $response = $this->performAuthenticationStep( $this->authAction, $requests );
483
484 // we can't handle FAIL or similar as failure here since it might require changing the form
485 return Status::newGood( $response );
486 }
487
495 protected function getPreservedParams( $withToken = false ) {
496 $params = [];
497 if ( $this->authAction !== $this->getDefaultAction( $this->subPage ) ) {
498 $params['authAction'] = $this->getContinueAction( $this->authAction );
499 }
500 if ( $withToken ) {
501 $params[$this->getTokenName()] = $this->getToken()->toString();
502 }
503 return $params;
504 }
505
512 protected function getAuthFormDescriptor( $requests, $action ) {
513 $fieldInfo = AuthenticationRequest::mergeFieldInfo( $requests );
514 $formDescriptor = $this->fieldInfoToFormDescriptor( $requests, $fieldInfo, $action );
515
517
518 return $formDescriptor;
519 }
520
526 protected function getAuthForm( array $requests, $action ) {
527 $formDescriptor = $this->getAuthFormDescriptor( $requests, $action );
528 $context = $this->getContext();
529 if ( $context->getRequest() !== $this->getRequest() ) {
530 // We have overridden the request, need to make sure the form uses that too.
531 $context = new DerivativeContext( $this->getContext() );
532 $context->setRequest( $this->getRequest() );
533 }
534 $form = HTMLForm::factory( 'ooui', $formDescriptor, $context );
535 $form->setAction( $this->getFullTitle()->getFullURL( $this->getPreservedParams() ) );
536 $form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() );
537 $form->addHiddenField( 'authAction', $this->authAction );
538 $form->suppressDefaultSubmit( !$this->needsSubmitButton( $requests ) );
539
540 return $form;
541 }
542
547 protected function displayForm( $status ) {
548 if ( $status instanceof StatusValue ) {
549 $status = Status::wrap( $status );
550 }
551 $form = $this->getAuthForm( $this->authRequests, $this->authAction );
552 $form->prepareForm()->displayForm( $status );
553 }
554
565 protected function needsSubmitButton( array $requests ) {
566 $customSubmitButtonPresent = false;
567
568 // Secondary and preauth providers always need their data; they will not care what button
569 // is used, so they can be ignored. So can OPTIONAL buttons createdby primary providers;
570 // that's the point in being optional. Se we need to check whether all primary providers
571 // have their own buttons and whether there is at least one button present.
572 foreach ( $requests as $req ) {
573 if ( $req->required === AuthenticationRequest::PRIMARY_REQUIRED ) {
574 if ( $this->hasOwnSubmitButton( $req ) ) {
575 $customSubmitButtonPresent = true;
576 } else {
577 return true;
578 }
579 }
580 }
581 return !$customSubmitButtonPresent;
582 }
583
590 foreach ( $req->getFieldInfo() as $field => $info ) {
591 if ( $info['type'] === 'button' ) {
592 return true;
593 }
594 }
595 return false;
596 }
597
603 protected function addTabIndex( &$formDescriptor ) {
604 $i = 1;
605 foreach ( $formDescriptor as $field => &$definition ) {
606 $class = false;
607 if ( array_key_exists( 'class', $definition ) ) {
608 $class = $definition['class'];
609 } elseif ( array_key_exists( 'type', $definition ) ) {
610 $class = HTMLForm::$typeMappings[$definition['type']];
611 }
612 if ( $class !== HTMLInfoField::class ) {
613 $definition['tabindex'] = $i;
614 $i++;
615 }
616 }
617 }
618
623 protected function getToken() {
624 return $this->getRequest()->getSession()->getToken( 'AuthManagerSpecialPage:'
625 . $this->getName() );
626 }
627
632 protected function getTokenName() {
633 return 'wpAuthToken';
634 }
635
645 protected function fieldInfoToFormDescriptor( array $requests, array $fieldInfo, $action ) {
646 $formDescriptor = [];
647 foreach ( $fieldInfo as $fieldName => $singleFieldInfo ) {
648 $formDescriptor[$fieldName] = self::mapSingleFieldInfo( $singleFieldInfo, $fieldName );
649 }
650
651 $requestSnapshot = serialize( $requests );
652 $this->onAuthChangeFormFields( $requests, $fieldInfo, $formDescriptor, $action );
653 \Hooks::run( 'AuthChangeFormFields', [ $requests, $fieldInfo, &$formDescriptor, $action ] );
654 if ( $requestSnapshot !== serialize( $requests ) ) {
655 LoggerFactory::getInstance( 'authentication' )->warning(
656 'AuthChangeFormFields hook changed auth requests' );
657 }
658
659 // Process the special 'weight' property, which is a way for AuthChangeFormFields hook
660 // subscribers (who only see one field at a time) to influence ordering.
662
663 return $formDescriptor;
664 }
665
673 protected static function mapSingleFieldInfo( $singleFieldInfo, $fieldName ) {
674 $type = self::mapFieldInfoTypeToFormDescriptorType( $singleFieldInfo['type'] );
675 $descriptor = [
676 'type' => $type,
677 // Do not prefix input name with 'wp'. This is important for the redirect flow.
678 'name' => $fieldName,
679 ];
680
681 if ( $type === 'submit' && isset( $singleFieldInfo['label'] ) ) {
682 $descriptor['default'] = $singleFieldInfo['label']->plain();
683 } elseif ( $type !== 'submit' ) {
684 $descriptor += array_filter( [
685 // help-message is omitted as it is usually not really useful for a web interface
686 'label-message' => self::getField( $singleFieldInfo, 'label' ),
687 ] );
688
689 if ( isset( $singleFieldInfo['options'] ) ) {
690 $descriptor['options'] = array_flip( array_map( function ( $message ) {
692 return $message->parse();
693 }, $singleFieldInfo['options'] ) );
694 }
695
696 if ( isset( $singleFieldInfo['value'] ) ) {
697 $descriptor['default'] = $singleFieldInfo['value'];
698 }
699
700 if ( empty( $singleFieldInfo['optional'] ) ) {
701 $descriptor['required'] = true;
702 }
703 }
704
705 return $descriptor;
706 }
707
714 protected static function sortFormDescriptorFields( array &$formDescriptor ) {
715 $i = 0;
716 foreach ( $formDescriptor as &$field ) {
717 $field['__index'] = $i++;
718 }
719 uasort( $formDescriptor, function ( $first, $second ) {
720 return self::getField( $first, 'weight', 0 ) <=> self::getField( $second, 'weight', 0 )
721 ?: $first['__index'] <=> $second['__index'];
722 } );
723 foreach ( $formDescriptor as &$field ) {
724 unset( $field['__index'] );
725 }
726 }
727
735 protected static function getField( array $array, $fieldName, $default = null ) {
736 if ( array_key_exists( $fieldName, $array ) ) {
737 return $array[$fieldName];
738 } else {
739 return $default;
740 }
741 }
742
749 protected static function mapFieldInfoTypeToFormDescriptorType( $type ) {
750 $map = [
751 'string' => 'text',
752 'password' => 'password',
753 'select' => 'select',
754 'checkbox' => 'check',
755 'multiselect' => 'multiselect',
756 'button' => 'submit',
757 'hidden' => 'hidden',
758 'null' => 'info',
759 ];
760 if ( !array_key_exists( $type, $map ) ) {
761 throw new \LogicException( 'invalid field type: ' . $type );
762 }
763 return $map[$type];
764 }
765}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
serialize()
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
A special page subclass for authentication-related special pages.
getContinueAction( $action)
Gets the _CONTINUE version of an action.
handleReturnBeforeExecute( $subPage)
Handle redirection from the /return subpage.
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
handleReauthBeforeExecute( $subPage)
Handle redirection when the user needs to (re)authenticate.
beforeExecute( $subPage)
Gets called before.
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
WebRequest null $savedRequest
If set, will be used instead of the real request.
string $authAction
one of the AuthManager::ACTION_* constants.
performAuthenticationStep( $action, array $requests)
getAuthForm(array $requests, $action)
displayForm( $status)
Display the form.
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
bool $isReturn
True if the current request is a result of returning from a redirect flow.
static mapFieldInfoTypeToFormDescriptorType( $type)
Maps AuthenticationRequest::getFieldInfo() types to HTMLForm types.
fieldInfoToFormDescriptor(array $requests, array $fieldInfo, $action)
Turns a field info array into a form descriptor.
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
handleFormSubmit( $data)
Submit handler callback for HTMLForm.
static array $messages
Customized messages.
AuthenticationRequest[] $authRequests
needsSubmitButton(array $requests)
Returns true if the form built from the given AuthenticationRequests needs a submit button.
string $subPage
Subpage of the special page.
isContinued()
Returns true if this is not the first step of the authentication.
hasOwnSubmitButton(AuthenticationRequest $req)
Checks whether the given AuthenticationRequest has its own submit button.
getRequestBlacklist()
Allows blacklisting certain request types.
static mapSingleFieldInfo( $singleFieldInfo, $fieldName)
Maps an authentication field configuration for a single field (as returned by AuthenticationRequest::...
static getField(array $array, $fieldName, $default=null)
Get an array value, or a default if it does not exist.
getRequest()
Get the WebRequest being used for this instance.
messageKey( $defaultKey)
Return custom message key.
setRequest(array $data, $wasPosted=null)
Override the POST data, GET data from the real request is preserved.
trySubmit()
Attempts to do an authentication step with the submitted data.
getToken()
Returns the CSRF token.
static sortFormDescriptorFields(array &$formDescriptor)
Sort the fields of a form descriptor by their 'weight' property.
addTabIndex(&$formDescriptor)
Adds a sequential tabindex starting from 1 to all form elements.
getAuthFormDescriptor( $requests, $action)
Generates a HTMLForm descriptor array from a set of authentication requests.
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Change the form descriptor that determines how a field will look in the authentication form.
getPreservedParams( $withToken=false)
Returns URL query parameters which can be used to reload the page (or leave and return) while preserv...
getTokenName()
Returns the name of the CSRF token (under which it should be found in the POST or GET data).
static string[] $allowedActions
The list of actions this special page deals with.
An IContextSource implementation which will inherit context from another source but allow individual ...
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
An error page which can definitely be safely rendered using the OutputPage.
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
This serves as the entry point to the authentication system.
This is a value object for authentication requests.
This is a value object to hold authentication response data.
PSR-3 logger instance factory.
Value object representing a CSRF token.
Definition Token.php:32
Variant of the Message class.
Parent class for all special pages.
getName()
Get the name of this Special Page.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
getPageTitle( $subpage=false)
Get a self-referential title object.
getFullTitle()
Return the full title, including $par.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
const PROTO_HTTPS
Definition Defines.php:229
this hook is for auditing only $req
Definition hooks.txt:979
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2843
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead & $formDescriptor
Definition hooks.txt:2157
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition hooks.txt:1266
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2848
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
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:273
this hook is for auditing only $response
Definition hooks.txt:780
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
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))
$params