Extension:Assert Edit

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Assert Edit

Release status: stable

Implementation Page action
Description Adds edit assertions, for safer bot edits.
Author(s) Steve Sanbeg
Version 2008-01-31 (2008-01-31)
MediaWiki 1.12a
Download SVN
Parameters AssertEdit::setAssert()
Hooks used

AlternateEdit

Help your bots to help your wiki.

When I started working with bots, I realised the potential for a simple operator error to make a lot of bad edits; such as a bot intended to run on a test wiki accidently running on wikipedia, because someone forget to supply the -family option. It also happens that a bot may get logged out, and unknowingly continue editing anonymously, without the bot flag, until it's blocked.

It's not easy for a bot to determine whether it is logged in, without some server side support. Unfortunately, no such support was available, until now.

[edit] How it works

When editing, the bot would add an assertion to the URL. If this assertion succeeds, the extension does nothing, and the edit proceeds as normal. If the assert fails, the extension replaces the normal edit interface with a simple error message. The bot could detect this message, and display an error to the operator; but even a bot that didn't look for that would fail in an obvious fashion, preventing the bad edit from occuring.

This is done simply by adding &assert=assertion or &nassert=assertion to the end of the URL. assert ensures that assertion is positive, while nassert ensures it is negative. Unrecognized assertions will always fail, whether assert or nassert is used, allowing mistyped assertions to be discovered quickly. Additionally, sites may add their own assertions, so that local bots won't accidently hit other sites.

If both a positive and negative assertion are specified, then both must succeed. For example, action=edit&assert=bot&nassert=exists would fail if the bot gets logged out or tries to edit a preexisting page.

[edit] Default Assertions

keyword meaning
user Verify that bot is logged in, to prevent anonymous edits.
bot Verify that bot is logged in and has a bot flag.
true Always true; nassert=true will fail if the extension is installed.
false Always false; assert=false will fail if the extension is installed.
exists Verify that page exists. Could be useful from other extensions, i.e. adding nassert=exists to the inputbox extension.
test Verify that this wiki allows random testing. Defaults to false, but can be overridden in LocalSettings.php.

[edit] Installation

To install this, download the AssertEdit.php file, place is in ./extensions/AssertEdit/, the add a line to your LocalSettings.php like

require_once( "$IP/extensions/AssertEdit/AssertEdit.php" );

New asssertions can then be added with AssertEdit::setAssert(key, value);, where key is the name of the assertion, and value is its value; true means the assertion will succeed, false will fail.

value must either be a boolean (true or false) or a function (as defined by the PHP is_callable() function) which returns a boolean value.

AssertEdit::setAssert will fail value is the wrong type, or key corresponds to an assertion that cannot be overridden.

This extension is being used on one or more of Wikimedia's wikis. It means that the extension is stable and works well enough to be used by such high traffic websites. A full list of the extensions installed on a particular wiki is produced by Special:Version on that wiki.

Personal tools