The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MediaWiki::Bot - a Wikipedia bot framework written in Perl

SYNOPSIS

use MediaWiki::Bot;

my $editor = MediaWiki::Bot->new('Account'); $editor->login('Account', 'password'); $editor->revert('Wikipedia:Sandbox', 'Reverting vandalism', '38484848');

DESCRIPTION

MediaWiki::Bot is a framework that can be used to write Wikipedia bots.

Many of the methods use the MediaWiki API (http://en.wikipedia.org/w/api.php).

AUTHOR

The MediaWiki::Bot team (Alex Rowe, Jmax, Oleg Alexandrov, Dan Collins) and others.

METHODS

new([$agent[, $assert[, $operator]]])

Calling MediaWiki::Bot->new will create a new MediaWiki::Bot object. $agent sets a custom useragent, $assert sets a parameter for the assertedit extension, common is "&assert=bot", $operator allows the bot to send you a message when it fails an assert. The message will tell you that $agent is logged out, so use a descriptive $agent.

set_highlimits([$flag])

Tells MediaWiki::Bot to start using the APIHighLimits for certain queries.

set_wiki([$wiki_host[,$wiki_path]])

set_wiki will cause the MediaWiki::Bot object to use the wiki specified, e.g set_wiki('de.wikipedia.org','w') will tell it to use http://de.wikipedia.org/w/index.php. The default settings are 'en.wikipedia.org' with a path of 'w'.

login($username,$password)

Logs the object into the specified wiki. If the login was a success, it will return 'Success', otherwise, 'Fail'.

edit($pagename,$page_text,[$edit_summary],[$is_minor],[$assert])

Edits the specified page $pagename and replaces it with $page_text with an edit summary of $edit_summary, optionally marking the edit as minor if specified, and adding an assertion, if requested. Assertions should be of the form "user".

get_history($pagename,$limit)

Returns an array containing the history of the specified page, with $limit number of revisions. The array structure contains 'revid','user','comment','timestamp_date', and 'timestamp_time'.

get_text($pagename,[$revid,$section_number])

Returns the text of the specified page. If $revid is defined, it will return the text of that revision; if $section_number is defined, it will return the text of that section. Returns 2 if page does not exist.

get_pages(@pages)

Returns the text of the specified pages in a hashref. Content of '2' means page does not exist.

revert($pagename,$edit_summary,$old_revision_id)

Reverts the specified page to $old_revision_id, with an edit summary of $edit_summary.

undo($pagename,$edit_summary,$revision_id,$after)

Reverts the specified page to $revision_id, with an edit summary of $edit_summary, using the undo function. To use old revision id instead of new, set last param to 'after'.

get_last($pagename,$username)

Returns the number of the last revision not made by $username.

update_rc([$limit])

Returns an array containing the Recent Changes to the wiki Main namespace. The array structure contains 'pagename', 'revid', 'oldid', 'timestamp_date', and 'timestamp_time'.

Returns an array containing a list of all pages linking to the given page. The array structure contains 'title' and 'type', the type being a transclusion, redirect, or neither.

get_pages_in_category($category_name)

Returns an array containing the names of all pages in the specified category. Does not go into sub-categories.

get_all_pages_in_category($category_name)

Returns an array containing the names of ALL pages in the specified category, including sub-categories.

linksearch($link)

Runs a linksearch on the specified link and returns an array containing anonymous hashes with keys "link" for the outbound link name, and "page" for the page the link is on.

purge_page($pagename)

Purges the server cache of the specified page.

get_namespace_names

get_namespace_names returns a hash linking the namespace id, such as 1, to its named equivalent, such as "Talk".

Gets a list of pages which include a certain image.

test_blocked($user)

Checks if a user is currently blocked.

test_image_exists($page)

Checks if an image exists at $page. 0 means no, 1 means yes, local, 2 means on commons, 3 means doesn't exist but there is text on the page.

delete_page($page[, $summary])

Deletes the page with the specified summary.

delete_old_image($page, $revision[, $summary])

Deletes the specified revision of the image with the specified summary.

block($user, $length, $summary, $anononly, $autoblock, $blockaccountcreation, $blockemail, $blocktalk)

Blocks the user with the specified options. All options optional except $user and $length. Last four are true/false. Defaults to empty summary, all options disabled.

unblock($user)

Unblocks the user.

protect($page, $reason, $editlvl, $movelvl, $time, $cascade)

Protects (or unprotects) the page. $editlvl and $movelvl may be '', 'autoconfirmed', or 'sysop'. $cascade is true/false.

get_pages_in_namespace($namespace_id,$page_limit)

Returns an array containing the names of all pages in the specified namespace. The $namespace_id must be a number, not a namespace name. Setting $page_limit is optional. If $page_limit is over 500, it will be rounded up to the next multiple of 500.

count_contributions($user)

Uses the API to count $user's contributions.

last_active($user)

Returns the last active time of $user in YYYY-MM-DDTHH:MM:SSZ

recent_edit_to_page($page)

Returns timestamp and username for most recent edit to $page.

get_users($page, $limit, $revision, $direction)

Gets the most recent editors to $page, up to $limit, starting from $revision and goint in $direction.

test_block_hist($user)

Returns 1 if $user has been blocked.

expandtemplates($page[, $text])

Expands templates on $page, using $text if provided, otherwise loading the page text automatically.

undelete($page, $summary)

Undeletes $page with $summary.

get_allusers($limit)

Returns an array of all users. Default limit is 500.

ERROR HANDLING

All functions will return an integer error value in any handled error situation. Error codes are stored in $agent->{error}->{code}, error text in $agent->{error}->{details}.