Author image dcollins
and 1 contributors


Perlwikipedia - a Wikipedia bot framework written in Perl


use Perlwikipedia;

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


Perlwikipedia is a framework that can be used to write Wikipedia bots.

Many of the methods use the MediaWiki API (


The Perlwikipedia team (Alex Rowe, Jmax, Oleg Alexandrov) and others.


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

Calling Perlwikipedia->new will create a new Perlwikipedia 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.


Tells Perlwikipedia to start using the APIHighLimits for certain queries.


set_wiki will cause the Perlwikipedia object to use the wiki specified, e.g set_wiki('','w') will tell Perlwikipedia to use The Perlwikipedia default settings are '' with a path of 'w'.


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


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


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


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.


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


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


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


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


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.


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


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


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.


Purges the server cache of the specified page.


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.


Checks if a user is currently blocked.


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)

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.

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

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


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.


Uses the API to count $user's contributions.


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


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.


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.


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


All Perlwikipedia functions will return either 0 or 1 if they do not return data. If an error occurs in a function, $perlwikipedia_object->{errstr} is set to the error message and the function will return 1. A robust bot should check $perlwikipedia_object->{errstr} for messages after performing any action with the object.