Jump to content

Extension:BlockAI

From mediawiki.org
MediaWiki extensions manual
BlockAI
Release status: experimental
Implementation Hook , Artificial intelligence
Description AI and bot crawler blocker for MediaWiki
Author(s) Alexey (Vedmakatalk)
MediaWiki >= 1.39
Database changes No
License MIT License
Download
$wgBlockAIThreshold
This extension is not compatible with wikis where anonymous users are allowed to edit pages.

The BlockAI extension enforces a set of rules that are intended to block AI crawlers and random bots spamming your wiki with requests to expensive pages like Special:RecentChanges and Special:RecentChangesLinked.

The extension evaluates only requests coming from anonymous users and ignores logged-in users completely. Every request is evaluated against a set of eval-rules, and a decision is made based on the request evaluation score.

For the requests that were blocked, the extension forces an early HTTP 418 I am a teapot response.

Installation

[edit]
  • Download, extract and place the file(s) in a directory called BlockAI in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'BlockAI' ); 
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Embedded evaluation rules

[edit]
  • InvalidRequest - fails for requests that are missing required headers
  • ExpensiveActions - fails for requests that trigger expensive actions (any action except `view` and `info` is considered expensive)
  • ForeignPosts - fails for requests that do POST but contain no Referrer header
  • QueryParamsOrder - fails for requests that contain query parameters in a different order than expected by MediaWiki
  • SpecialPageLock - fails for requests that access Special: pages that are considered expensive. All the Special pages are considered expensive except UserLogin, CreateAccount, Search, Random, PasswordReset, ConfirmEmail.

Configuration parameters

[edit]
Parameter Default value Description
$wgBlockAIThreshold 1.0 Adjusts the threshold for marking a request as spammy. The default value is 1.0. Every evaluation rule may have its own weight, with the default weight being 1 for all the embedded evaluation rules

At the moment, all the embedded evaluation rules have a weight of 1, thus you can either disable the blocks completely by setting the threshold to 0 or enable the blocks by setting it to 1. Any other values would take no effect until custom evaluation rules are added with weights < 1

See more details on the scoring logic at README.md

Adding custom evaluation rules

[edit]

You can add your own evaluation rules by creating new classes that implement the IEval interface. The classes should be part of an extension, be loaded by the autoloader, and registered through extension attributes. See BlockAISample for more details and a sample custom evaluation rule.

See also

[edit]