API:Restricting API usage/ja

Category:MediaWiki action API/ja

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.

Category:MediaWiki action API/ja