API:Restricting API usage/es: Difference between revisions
Created page with "Puedes deshabilitar la API en su conjunto configurando $EnableAPI en $LocalSettings." |
Updating to match new version of source page |
||
| (39 intermediate revisions by 3 users not shown) | |||
| Line 4: | Line 4: | ||
Algunos de estos requieren [[Special:MyLanguage/Manual:User rights|cambiar los permisos de grupo]]. |
Algunos de estos requieren [[Special:MyLanguage/Manual:User rights|cambiar los permisos de grupo]]. |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
{{anchor|Disabling the entire API}} |
|||
== |
== Disabling general access == |
||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">There is no dedicated user permission for accessing the API.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">To disable API access for a specific user group, you can disable <code>read</code> permissions for that group.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">For instance, to disallow anonymous requests,</span> |
|||
<syntaxhighlight lang="php"> |
|||
Puedes deshabilitar la API en su conjunto configurando <code>{{ll|Manual:$wgEnableAPI|$wgEnableAPI}} = false;</code> en {{ll|Manual:LocalSettings.php|LocalSettings.php}}. |
|||
$wgGroupPermissions['*']['read'] = false; |
|||
The API is enabled by default. |
|||
</syntaxhighlight> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Note that some API modules may be available regardless.</span> |
|||
{{note|1=This configuration setting was deprecated starting with MediaWiki 1.31.0 and will be removed in future versions meaning that disabling the API will no longer be possible.}} |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">If access is successfully prevented, the API output will usually show the error code <code>readapidenied</code>.</span> |
|||
<span id="Disabling_modules"></span> |
|||
== Disabling the write API == |
|||
== Deshabilitar módulos == |
|||
Puedes deshabilitar módulos individuales para todos los usuarios agregando una línea a <code>LocalSettings.php</code>. |
|||
Exactamente qué añadir, depende del tipo de módulo que desee deshabilitar: |
|||
| ⚫ | |||
You can disable all [[Special:MyLanguage/API:Changing wiki content|write modules]] by setting <code>{{ll|Manual:$wgEnableWriteAPI|$wgEnableWriteAPI}} = false;</code> in LocalSettings.php. |
|||
| ⚫ | |||
The write API is enabled by default as of MediaWiki 1.14, and disabled by default in older versions. |
|||
| ⚫ | |||
| ⚫ | |||
{{note|1=This configuration setting was deprecated starting with MediaWiki 1.31.0 and will be removed in future versions meaning that disabling the write API will no longer be possible.}} |
|||
== 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. |
|||
However, both the writeapi right and <code>$wgEnableWriteAPI = true;</code> are required in order to use the write API. |
|||
== 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: |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
<span id="Examples"></span> |
|||
=== Ejemplo === |
=== Ejemplo === |
||
<div class="mw-translate-fuzzy"> |
|||
To disable anyone who isn't a sysop from using <code>action=edit</code>: |
|||
Para deshabilitar a cualquiera que no sea un sysop usando <code>action=edit</code>: |
|||
</div> |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
| ⚫ | |||
if ( !in_array( 'sysop', $wgUser->getGroups() ) ) { |
|||
| ⚫ | |||
} |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
Para limitar el acceso de una acción de API, agrega el siguiente enlace para {{ll|Manual:Hooks/ApiCheckCanExecute|ApiCheckCanExecute}}: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
static function onApiCheckCanExecute( $module, $user, &$message ) { |
static function onApiCheckCanExecute( $module, $user, &$message ) { |
||
$moduleName = $module->getModuleName(); |
$moduleName = $module->getModuleName(); |
||
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); |
|||
if ( |
if ( |
||
$moduleName == 'action' && |
$moduleName == 'action' && |
||
! |
!$permissionManager->userHasRight( $user, 'right' ) |
||
) { |
) { |
||
$message = 'apierror-action-notallowed'; |
$message = 'apierror-action-notallowed'; |
||
| Line 61: | Line 56: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
Reemplaza <code>'action'</code>, <code>'right'</code> y <code>'apierror-action-notallowed'</code> con los valores apropiados. |
|||
Latest revision as of 11:32, 19 October 2025
| Esta página es parte de la documentación de la API de acciones de MediaWiki. |
Hay varias maneras de restringir el uso de (ciertas partes de) el API a ciertos grupos de usuarios, o deshabilitarla por completo. Algunos de estos requieren cambiar los permisos de grupo.
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.
Deshabilitar módulos
Puedes deshabilitar módulos individuales para todos los usuarios agregando una línea a LocalSettings.php.
Exactamente qué añadir, depende del tipo de módulo que desee deshabilitar:
- Para módulos
action=, use$wgAPIModules['modulename'] = 'ApiDisabled'; - Para módulos
prop=, use$wgAPIPropModules['modulename'] = 'ApiQueryDisabled'; - Para módulos
list=, use$wgAPIListModules['modulename'] = 'ApiQueryDisabled'; - Para módulos
meta=, use$wgAPIMetaModules['modulename'] = 'ApiQueryDisabled';
Ejemplo
Para deshabilitar a cualquiera que no sea un sysop usando action=edit:
$wgAPIModules['edit'] = 'ApiDisabled';
Para limitar el acceso de una acción de API, agrega el siguiente enlace para 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;
}
Reemplaza 'action', 'right' y 'apierror-action-notallowed' con los valores apropiados.