Manual:Wikibot

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
<translate> Manual on MediaWiki Tools</translate>
Wikibot
<translate> Release status:</translate> <translate> experimental</translate>
<translate> Implementation</translate> Bot
<translate> Description</translate> Configurable bot framework
<translate> Author(s)</translate> Cobi, Tisane
<translate> Latest version</translate> 1.0.0
MediaWiki 1.16+
<translate> License</translate> GPL
<translate> Download</translate> Subversion [<translate> Help</translate> ]
<translate> Browse source code</translate>
Not to be confused with Manual:IRC RC Bot

Wikibot is a PHP-based MediaWiki bot framework. It is based upon w:User:ClueBot/Source, but is designed to be more configurable and flexible. Make sure that the appropriate subpage of the bot's userpage, e.g. User:MyBot/Run, exists, or some bots may not work.

Configuration

The bot can be configured using the file wikibot.config.php. For instance, if you want to configure a bot username of TestBot, a bot password of password, and to have it edit testwiki.org, you might put the following configuration settings in wikibot.config.php:

$wikibotSetting['user']['TestBot']['Testwiki'] = 'TestBot'; # Username
$wikibotSetting['pass']['TestBot']['Testwiki'] = 'password'; # Password
$wikibotSetting['apiurl']['*']['Testwiki'] = 'http://testwiki.org/w/api.php';
$wikibotSetting['queryurl']['*']['Testwiki'] = 'http://testwiki.org/w/query.php';
$wikibotSetting['indexurl']['*']['Testwiki'] = 'http://testwiki.org/w/index.php';
  • The first bracket contains the name of the configuration setting.
  • The second bracket contains the name of the bot or the wildcard "*" to apply the setting to all bots.
  • The third bracket contains the wiki name or the wildcard "*" to apply the setting to all wikis.

If there is any conflict between a wildcarded setting and a more specific setting, the more specific setting will prevail. For example, suppose you have the following:

$wikibotSetting['user']['*']['*'] = 'AwesomeBot';
$wikibotSetting['user']['TestBot']['Testwiki'] = 'TestBot';

In this example, the TestBot setting would override the less specific AwesomeBot setting for purposes of commands such as this:

$user = getWikibotSetting( 'user', 'TestBot', 'Testwiki' );

Sample bot

Here is a sample bot that uses this framework to edit the page "Sandbox" on testwiki.org:

<?php
# This bot logs in to testwiki.org and edits the sandbox to say "Hello world!"

error_reporting( E_ALL | E_STRICT );
include 'wikibot.classes.php'; /* The wikipedia classes. */

$bot = 'TestBot';
$wiki = 'Testwiki';

$wpapi	= new wikipediaapi ( '', '', '', $bot, $wiki, true );
$wpq	= new wikipediaquery ( '', '', '', $bot, $wiki, true );
$wpi	= new wikipediaindex ( '', '', '', $bot, $wiki, true );
$user = getWikibotSetting( 'user', $bot, $wiki );
$pass = getWikibotSetting( 'pass', $bot, $wiki );
if ( $wpapi->login( $user, $pass ) != 'true' ) {
    echo "Login failure";
    die();
}
sleep( 1 );

var_dump( $wpapi->edit( 'Sandbox', 'Hello world!', 'This is a test', false, false, null, null, false ) );

See also