MediaWiki  1.29.1
ApiRemoveAuthenticationData.php
Go to the documentation of this file.
1 <?php
24 
31 
32  private $authAction;
33  private $operation;
34 
35  public function __construct( ApiMain $main, $action ) {
36  parent::__construct( $main, $action );
37 
38  $this->authAction = $action === 'unlinkaccount'
39  ? AuthManager::ACTION_UNLINK
40  : AuthManager::ACTION_REMOVE;
41  $this->operation = $action === 'unlinkaccount'
42  ? 'UnlinkAccount'
43  : 'RemoveCredentials';
44  }
45 
46  public function execute() {
47  if ( !$this->getUser()->isLoggedIn() ) {
48  $this->dieWithError( 'apierror-mustbeloggedin-removeauth', 'notloggedin' );
49  }
50 
51  $params = $this->extractRequestParams();
52  $manager = AuthManager::singleton();
53 
54  // Check security-sensitive operation status
55  ApiAuthManagerHelper::newForModule( $this )->securitySensitiveOperation( $this->operation );
56 
57  // Fetch the request. No need to load from the request, so don't use
58  // ApiAuthManagerHelper's method.
59  $blacklist = $this->authAction === AuthManager::ACTION_REMOVE
60  ? array_flip( $this->getConfig()->get( 'RemoveCredentialsBlacklist' ) )
61  : [];
62  $reqs = array_filter(
63  $manager->getAuthenticationRequests( $this->authAction, $this->getUser() ),
64  function ( $req ) use ( $params, $blacklist ) {
65  return $req->getUniqueId() === $params['request'] &&
66  !isset( $blacklist[get_class( $req )] );
67  }
68  );
69  if ( count( $reqs ) !== 1 ) {
70  $this->dieWithError( 'apierror-changeauth-norequest', 'badrequest' );
71  }
72  $req = reset( $reqs );
73 
74  // Perform the removal
75  $status = $manager->allowsAuthenticationDataChange( $req, true );
76  Hooks::run( 'ChangeAuthenticationDataAudit', [ $req, $status ] );
77  if ( !$status->isGood() ) {
78  $this->dieStatus( $status );
79  }
80  $manager->changeAuthenticationData( $req );
81 
82  $this->getResult()->addValue( null, $this->getModuleName(), [ 'status' => 'success' ] );
83  }
84 
85  public function isWriteMode() {
86  return true;
87  }
88 
89  public function needsToken() {
90  return 'csrf';
91  }
92 
93  public function getAllowedParams() {
94  return ApiAuthManagerHelper::getStandardParams( $this->authAction,
95  'request'
96  );
97  }
98 
99  protected function getExamplesMessages() {
100  $path = $this->getModulePath();
101  $action = $this->getModuleName();
102  return [
103  "action={$action}&request=FooAuthenticationRequest&token=123ABC"
104  => "apihelp-{$path}-example-simple",
105  ];
106  }
107 
108  public function getHelpUrls() {
109  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data';
110  }
111 }
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
ApiRemoveAuthenticationData\needsToken
needsToken()
Returns the token type this module requires in order to execute.
Definition: ApiRemoveAuthenticationData.php:89
ApiRemoveAuthenticationData\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiRemoveAuthenticationData.php:85
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
ApiRemoveAuthenticationData\$authAction
$authAction
Definition: ApiRemoveAuthenticationData.php:32
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
ApiRemoveAuthenticationData\__construct
__construct(ApiMain $main, $action)
Definition: ApiRemoveAuthenticationData.php:35
$params
$params
Definition: styleTest.css.php:40
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
ApiRemoveAuthenticationData\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiRemoveAuthenticationData.php:99
ApiBase\getModulePath
getModulePath()
Get the path to this module.
Definition: ApiBase.php:554
ApiRemoveAuthenticationData\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiRemoveAuthenticationData.php:108
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:718
ApiRemoveAuthenticationData
Remove authentication data from AuthManager.
Definition: ApiRemoveAuthenticationData.php:30
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:82
ApiRemoveAuthenticationData\$operation
$operation
Definition: ApiRemoveAuthenticationData.php:33
$path
$path
Definition: NoLocalSettings.php:26
ApiRemoveAuthenticationData\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiRemoveAuthenticationData.php:93
ApiBase\dieStatus
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition: ApiBase.php:1861
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:490
ApiAuthManagerHelper\newForModule
static newForModule(ApiBase $module)
Static version of the constructor, for chaining.
Definition: ApiAuthManagerHelper.php:59
ApiRemoveAuthenticationData\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiRemoveAuthenticationData.php:46
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131