API:Restricting API usage/pl
![]() | Ta strona jest częścią dokumentacji API akcji MediaWiki. |
There are several ways to restrict usage of (certain parts of) the API to certain groups of users, or to disable it altogether.Some of these require changing group permissions.
Disabling general access
There is no dedicated user permission for accessing the API. To disable API access for a specific user group, you can disable read
permissions for that group. For instance, to disallow anonymous requests,
$wgGroupPermissions['*']['read']=false;
Note that some API modules may be available regardless. If access is successfully prevented, the API output will usually show the error code 'readapidenied'.
Disabling modules
You can disable individual modules for all users by adding a line to LocalSettings.php
.Exactly what to add depends on the type of module you want to disable:
- Dla modułów
action=
, użyj$wgAPIModules ['modulename'] = 'ApiDisabled';
- Dla modułów
prop=
, użyj$wgAPIPropModules ['modulename'] = 'ApiQueryDisabled';
- Dla modułów
list=
, użyj$wgAPIListModules ['modulename'] = 'ApiQueryDisabled';
- Dla modułów
meta=
, użyj$wgAPIMetaModules ['modulename'] = 'ApiQueryDisabled';
Przykłady
To disable anyone from using action=edit
:
$wgAPIModules['edit']='ApiDisabled';
To limit the access of an API action, add the following hook for ApiCheckCanExecute :
staticfunctiononApiCheckCanExecute($module,$user,&$message){$moduleName=$module->getModuleName();if($moduleName=='action'&&!in_array('right',$user->getRights())){$message='apierror-action-notallowed';returnfalse;}returntrue;}
Replace 'action'
, 'right'
and 'apierror-action-notallowed'
with the appropriate values.