API:Restricting API usage/da
This page is part of the MediaWiki Action API documentation. |
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.
Restricting access to the write API
You can deny certain groups the right to use the write API by denying them the writeapi right. By default, all groups have the writeapi right.
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:
- For
action=
moduler, brug$wgAPIModules ['modulename'] = 'ApiDisabled';
- For
prop=
moduler, brug$wgAPIPropModules ['modulename'] = 'ApiQueryDisabled';
- For
list=
moduler, brug$wgAPIListModules ['modulename'] = 'ApiQueryDisabled';
- For
meta=
moduler, brug$wgAPIMetaModules ['modulename'] = 'ApiQueryDisabled';
Eksempel
To disable anyone who isn't a sysop from using action=edit
:
if ( !in_array( 'sysop', $wgUser->getGroups() ) ) {
$wgAPIModules['edit'] = 'ApiDisabled';
}
To limit the access of an API action, add the following hook for ApiCheckCanExecute :
static function onApiCheckCanExecute( $module, $user, &$message ) {
$moduleName = $module->getModuleName();
if (
$moduleName == 'action' &&
!in_array( 'right', $user->getRights() )
) {
$message = 'apierror-action-notallowed';
return false;
}
return true;
}
Replace 'action'
, 'right'
and 'apierror-action-notallowed'
with the appropriate values.