MediaWiki  1.34.0
ApiQueryOATH.php
Go to the documentation of this file.
1 <?php
20 
22 use ApiQueryBase;
23 use ApiBase;
24 use ApiResult;
25 use User;
26 
37 class ApiQueryOATH extends ApiQueryBase {
38  public function __construct( $query, $moduleName ) {
39  parent::__construct( $query, $moduleName, 'oath' );
40  }
41 
42  public function execute() {
43  $params = $this->extractRequestParams();
44  if ( $params['user'] === null ) {
45  $params['user'] = $this->getUser()->getName();
46  }
47 
48  $this->checkUserRightsAny( 'oathauth-api-all' );
49 
50  $user = User::newFromName( $params['user'] );
51  if ( $user === false ) {
52  $this->dieWithError( 'noname' );
53  }
54 
55  $result = $this->getResult();
56  $data = [
57  ApiResult::META_BC_BOOLS => [ 'enabled' ],
58  'enabled' => false,
59  ];
60 
61  if ( !$user->isAnon() ) {
62  $userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
63  $authUser = $userRepo->findByUser( $user );
64  $data['enabled'] = $authUser &&
65  $authUser->getModule() !== null &&
66  $authUser->getModule()->isEnabled( $authUser );
67  }
68  $result->addValue( 'query', $this->getModuleName(), $data );
69  }
70 
76  public function getCacheMode( $params ) {
77  return 'private';
78  }
79 
80  public function isInternal() {
81  return true;
82  }
83 
84  public function getAllowedParams() {
85  return [
86  'user' => [
87  ApiBase::PARAM_TYPE => 'user',
88  ],
89  ];
90  }
91 
92  protected function getExamplesMessages() {
93  return [
94  'action=query&meta=oath'
95  => 'apihelp-query+oath-example-1',
96  'action=query&meta=oath&oathuser=Example'
97  => 'apihelp-query+oath-example-2',
98  ];
99  }
100 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:2014
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:94
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:640
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryOATH.php:42
ApiBase\checkUserRightsAny
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
Definition: ApiBase.php:2130
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:515
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:138
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryOATH.php:84
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiResult\META_BC_BOOLS
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
Definition: ApiResult.php:136
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:761
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH\getCacheMode
getCacheMode( $params)
Definition: ApiQueryOATH.php:76
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH
Query module to check if a user has OATH authentication enabled.
Definition: ApiQueryOATH.php:37
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:520
MediaWiki\Extension\OATHAuth\Api\Module
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: ApiOATHValidate.php:19
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH\__construct
__construct( $query, $moduleName)
Definition: ApiQueryOATH.php:38
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH\isInternal
isInternal()
Indicates whether this module is "internal" Internal API modules are not (yet) intended for 3rd party...
Definition: ApiQueryOATH.php:80
MediaWiki\Extension\OATHAuth\Api\Module\ApiQueryOATH\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryOATH.php:92