MediaWiki::Bot - a Wikipedia bot framework written in Perl
use MediaWiki::Bot;
my $editor = MediaWiki::Bot->new('Account'); $editor->login('Account', 'password'); $editor->revert('Wikipedia:Sandbox', 'Reverting vandalism', '38484848');
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).
The MediaWiki::Bot team (Alex Rowe, Jmax, Oleg Alexandrov, Dan Collins) and others.
Copyright (C) 2006, 2007 by the MediaWiki::Bot team
This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
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.
Tells MediaWiki::Bot to start using the APIHighLimits for certain queries.
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'.
Logs the 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. Also handles redirects or article names that use namespace aliases
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.
Deletes the page with the specified summary.
Deletes the specified revision of the image with the specified summary.
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.
Unblocks the user.
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.
Gets the most recent editors to $page, up to $limit, starting from $revision and goint in $direction.
Returns 1 if $user has been blocked.
Expands templates on $page, using $text if provided, otherwise loading the page text automatically.
Undeletes $page with $summary.
Returns an array of all users. Default limit is 500.
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}.
To install MediaWiki::Bot, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MediaWiki::Bot
CPAN shell
perl -MCPAN -e shell install MediaWiki::Bot
For more information on module installation, please visit the detailed CPAN module installation guide.