MediaWiki REL1_34
ApiQueryOATH.php
Go to the documentation of this file.
1<?php
20
22use ApiQueryBase;
23use ApiBase;
24use ApiResult;
25use User;
26
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}
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:42
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
Definition ApiBase.php:2130
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:2014
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:94
getResult()
Get the result object.
Definition ApiBase.php:640
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:761
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:520
This is a base class for all Query modules.
This class represents the result of the API operations.
Definition ApiResult.php:35
Query module to check if a user has OATH authentication enabled.
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
isInternal()
Indicates whether this module is "internal" Internal API modules are not (yet) intended for 3rd party...
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:518
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...