API:Restricting API usage/ja
![]() | このページは MediaWiki 操作 API の説明文書の一部です。 |
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'.
モジュールの無効化
LocalSettings.php
に行を追加することで、すべての利用者に対してモジュールを個別に無効化できます。
Exactly what to add depends on the type of module you want to disable:
action=
モジュールの場合は、$wgAPIModules ['modulename'] = 'ApiDisabled';
を使用してくださいprop=
モジュールの場合は、$wgAPIPropModules ['modulename'] = 'ApiQueryDisabled';
を使用してくださいlist=
モジュールの場合は、$wgAPIListModules ['modulename'] = 'ApiQueryDisabled';
を使用してくださいmeta=
モジュールの場合は、$wgAPIMetaModules ['modulename'] = 'ApiQueryDisabled';
を使用してください
例
action=edit
の使用を無効化するには:
$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.