MediaWiki REL1_35
ApiChangeAuthenticationData.php
Go to the documentation of this file.
1<?php
25
32
33 public function __construct( ApiMain $main, $action ) {
34 parent::__construct( $main, $action, 'changeauth' );
35 }
36
37 public function execute() {
38 if ( !$this->getUser()->isLoggedIn() ) {
39 $this->dieWithError( 'apierror-mustbeloggedin-changeauthenticationdata', 'notloggedin' );
40 }
41
42 $manager = MediaWikiServices::getInstance()->getAuthManager();
43 $helper = new ApiAuthManagerHelper( $this, $manager );
44
45 // Check security-sensitive operation status
46 $helper->securitySensitiveOperation( 'ChangeCredentials' );
47
48 // Fetch the request
50 $helper->loadAuthenticationRequests( AuthManager::ACTION_CHANGE ),
51 $this->getConfig()->get( 'ChangeCredentialsBlacklist' )
52 );
53 if ( count( $reqs ) !== 1 ) {
54 $this->dieWithError( 'apierror-changeauth-norequest', 'badrequest' );
55 }
56 $req = reset( $reqs );
57
58 // Make the change
59 $status = $manager->allowsAuthenticationDataChange( $req, true );
60 $this->getHookRunner()->onChangeAuthenticationDataAudit( $req, $status );
61 if ( !$status->isGood() ) {
62 $this->dieStatus( $status );
63 }
64 $manager->changeAuthenticationData( $req );
65
66 $this->getResult()->addValue( null, 'changeauthenticationdata', [ 'status' => 'success' ] );
67 }
68
69 public function isWriteMode() {
70 return true;
71 }
72
73 public function needsToken() {
74 return 'csrf';
75 }
76
77 public function getAllowedParams() {
78 return ApiAuthManagerHelper::getStandardParams( AuthManager::ACTION_CHANGE,
79 'request'
80 );
81 }
82
84 return [ 'api-help-authmanagerhelper-additional-params', AuthManager::ACTION_CHANGE ];
85 }
86
87 protected function getExamplesMessages() {
88 return [
89 'action=changeauthenticationdata' .
90 '&changeauthrequest=MediaWiki%5CAuth%5CPasswordAuthenticationRequest' .
91 '&password=ExamplePassword&retype=ExamplePassword&changeauthtoken=123ABC'
92 => 'apihelp-changeauthenticationdata-example-password',
93 ];
94 }
95
96 public function getHelpUrls() {
97 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data';
98 }
99}
Helper class for AuthManager-using API modules.
static getStandardParams( $action,... $wantedParams)
Fetch the standard parameters this helper recognizes.
static blacklistAuthenticationRequests(array $reqs, array $blacklist)
Filter out authentication requests by class name.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:52
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1437
getResult()
Get the result object.
Definition ApiBase.php:620
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:1495
getHookRunner()
Get an ApiHookRunner for running core API hooks.
Definition ApiBase.php:717
Change authentication data with AuthManager.
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
isWriteMode()
Indicates whether this module requires write mode.
needsToken()
Returns the token type this module requires in order to execute.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
dynamicParameterDocumentation()
Indicate if the module supports dynamically-determined parameters that cannot be included in self::ge...
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:47
getUser()
Stable to override.
This serves as the entry point to the authentication system.
MediaWikiServices is the service locator for the application scope of MediaWiki.