Extension:AssertEdit


 * 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 forgot to supply the  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.

Usage
To use the extension, supply an additional parameter -- either assert or nassert -- when editing a page, whether through the UI (index.php) or API (api.php).

The value of the assert (or nassert) parameter should be the desired assertion. If it succeeds, the extension does nothing, and the edit proceeds as normal; if it fails, an error message is returned. assert ensures that assertion is positive, while nassert ensures it is negative. Unrecognized assertions will always fail, whether assert or nassert is used. Installations may add their own assertions; this can be used to ensure processes intended only for that site do not affect other sites. If both a positive and negative assertion are specified, then both must succeed.

Example
Having a 'bot' submit edits to the following URL (plus additional required parameters)


 * ... /api.php?action=edit&assert=bot&nassert=exists

will cause it to fail if the account becomes logged out or loses its bot status, or when trying to edit a page that already exists.

Downloading
svn checkout http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/AssertEdit/
 * To download this, issue the following shell command:

Installation
To install, add a line to your LocalSettings.php like

New asssertions can then be added with, 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 if value is of the wrong type, or key corresponds to an assertion that cannot be overridden.