Jump to content
MediaWiki

API:API の使用の制限

From mediawiki.org
This page is a translated version of the page API:Restricting API usage and the translation is 64% complete.
このページは MediaWiki 操作 API の説明文書の一部です。
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();
 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 if (
 $moduleName == 'action' &&
 !$permissionManager->userHasRight( $user, 'right' )
 ) {
 $message = 'apierror-action-notallowed';
 return false;
 }
 return true;
}

Replace 'action', 'right' and 'apierror-action-notallowed' with the appropriate values.

AltStyle によって変換されたページ (->オリジナル) /