API: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.
API 全体の無効化
LocalSettings.php 内の $wgEnableAPI = false;
を設定することで API 全体を無効化することができます。
APIは既定では有効です。
書き込み API の無効化
LocalSettings.php 中の $wgEnableWriteAPI = false;
を設定することで、すべての書き込みモジュールを無効化することができます。
書き込みAPIはMediaWiki 1.14以降は既定で有効となっていて、それより古いバージョンでは既定で無効となっています。
書き込み API へのアクセス制限
You can deny certain groups the right to use the write API by denying them the writeapi right.
既定では、すべてのグループが writeapi 権限を持っています。
ただし、writeapi 権限と $wgEnableWriteAPI = true;
の両方が書き込みAPIを使用するために必要です。
モジュールの無効化
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
の使用を無効化する:
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.