Extension:AssertEdit

From MediaWiki.org
(Redirected from Extension:Assert Edit)
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
AssertEdit

Release status: stable

Assert Edit.jpg
Implementation Page action
Description Adds edit assertions, for safer bot edits
Author(s) Steve Sanbeg
MediaWiki 1.13+
PHP 5.3+
Database changes No
License GNU General Public License 2.0 or later
Download
Parameters

AssertEdit::setAssert()

Hooks used
APIEditBeforeSave

APIGetAllowedParams
APIGetParamDescription
AlternateEdit

Translate the AssertEdit extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

Issues:

Open tasks · Report a bug

The AssertEdit extension adds edit assertions, to help bots ensure they stay logged in and are working with the right wiki.

Rationale[edit | edit source]

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 -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.

Usage[edit | edit source]

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[edit | edit source]

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.

Default assertions[edit | edit source]

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.

Download[edit | edit source]

The extension can be retrieved directly from Git [?]:

  • Browse code
  • Some extensions have tags for stable releases.
  • Each branch is associated with a past MediaWiki release. There is also a "master" branch containing the latest alpha version (might require an alpha version of MediaWiki).

Extract the snapshot and place it in the extensions/AssertEdit/ directory of your MediaWiki installation.

If you are familiar with git and have shell access to your server, you can also obtain the extension as follows:

cd extensions/
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/AssertEdit.git

Installation[edit | edit source]

  • Download and extract the tarball in your extensions/ folder. It should generate a new folder called AssertEdit directly inside your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/AssertEdit/AssertEdit.php";
  • Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

Configuration[edit | edit source]

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

Language: English  • 日本語