MediaWiki  1.29.1
ApiChangeAuthenticationData.php
Go to the documentation of this file.
1 <?php
24 
31 
32  public function __construct( ApiMain $main, $action ) {
33  parent::__construct( $main, $action, 'changeauth' );
34  }
35 
36  public function execute() {
37  if ( !$this->getUser()->isLoggedIn() ) {
38  $this->dieWithError( 'apierror-mustbeloggedin-changeauthenticationdata', 'notloggedin' );
39  }
40 
41  $helper = new ApiAuthManagerHelper( $this );
42  $manager = AuthManager::singleton();
43 
44  // Check security-sensitive operation status
45  $helper->securitySensitiveOperation( 'ChangeCredentials' );
46 
47  // Fetch the request
49  $helper->loadAuthenticationRequests( AuthManager::ACTION_CHANGE ),
50  $this->getConfig()->get( 'ChangeCredentialsBlacklist' )
51  );
52  if ( count( $reqs ) !== 1 ) {
53  $this->dieWithError( 'apierror-changeauth-norequest', 'badrequest' );
54  }
55  $req = reset( $reqs );
56 
57  // Make the change
58  $status = $manager->allowsAuthenticationDataChange( $req, true );
59  Hooks::run( 'ChangeAuthenticationDataAudit', [ $req, $status ] );
60  if ( !$status->isGood() ) {
61  $this->dieStatus( $status );
62  }
63  $manager->changeAuthenticationData( $req );
64 
65  $this->getResult()->addValue( null, 'changeauthenticationdata', [ 'status' => 'success' ] );
66  }
67 
68  public function isWriteMode() {
69  return true;
70  }
71 
72  public function needsToken() {
73  return 'csrf';
74  }
75 
76  public function getAllowedParams() {
77  return ApiAuthManagerHelper::getStandardParams( AuthManager::ACTION_CHANGE,
78  'request'
79  );
80  }
81 
82  public function dynamicParameterDocumentation() {
83  return [ 'api-help-authmanagerhelper-additional-params', AuthManager::ACTION_CHANGE ];
84  }
85 
86  protected function getExamplesMessages() {
87  return [
88  'action=changeauthenticationdata' .
89  '&changeauthrequest=MediaWiki%5CAuth%5CPasswordAuthenticationRequest' .
90  '&password=ExamplePassword&retype=ExamplePassword&changeauthtoken=123ABC'
91  => 'apihelp-changeauthenticationdata-example-password',
92  ];
93  }
94 
95  public function getHelpUrls() {
96  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data';
97  }
98 }
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:45
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
ApiChangeAuthenticationData\needsToken
needsToken()
Returns the token type this module requires in order to execute.
Definition: ApiChangeAuthenticationData.php:72
ApiChangeAuthenticationData\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiChangeAuthenticationData.php:76
ApiChangeAuthenticationData\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiChangeAuthenticationData.php:86
captcha-old.count
count
Definition: captcha-old.py:225
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1796
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:610
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$req
this hook is for auditing only $req
Definition: hooks.txt:990
ApiChangeAuthenticationData\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiChangeAuthenticationData.php:36
ApiChangeAuthenticationData\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiChangeAuthenticationData.php:68
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
ApiAuthManagerHelper\getStandardParams
static getStandardParams( $action, $param)
Fetch the standard parameters this helper recognizes.
Definition: ApiAuthManagerHelper.php:351
php
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
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:41
ApiChangeAuthenticationData\__construct
__construct(ApiMain $main, $action)
Definition: ApiChangeAuthenticationData.php:32
ApiAuthManagerHelper
Helper class for AuthManager-using API modules.
Definition: ApiAuthManagerHelper.php:36
ApiChangeAuthenticationData\dynamicParameterDocumentation
dynamicParameterDocumentation()
Indicate if the module supports dynamically-determined parameters that cannot be included in self::ge...
Definition: ApiChangeAuthenticationData.php:82
ApiAuthManagerHelper\blacklistAuthenticationRequests
static blacklistAuthenticationRequests(array $reqs, array $blacklist)
Filter out authentication requests by class name.
Definition: ApiAuthManagerHelper.php:121
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:82
ApiChangeAuthenticationData
Change authentication data with AuthManager.
Definition: ApiChangeAuthenticationData.php:30
ApiChangeAuthenticationData\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiChangeAuthenticationData.php:95
ApiBase\dieStatus
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition: ApiBase.php:1861
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131