Project

wikibot

0.0
No commit activity in last 3 years
No release in over 3 years
Mediawiki Bot framework
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.3.1
>= 0.5.4.0
>= 0.1.0
>= 1.0.12
 Project Readme

WikiBot

About

WikiBot was originally a PHP-based framework for bots I run on Wikipedia, however when it broke due to changes in mediawiki code, I decided to rewrite it in Ruby, using the MediaWiki API instead of screen-scraping. This is the result.

By default, the bot uses the English Wikipedia. A different instance of MediaWiki can be used by specifying the :api key when instantiating the class.

The bot is not yet fully-featured, in that it doesn’t abstract every possible MediaWiki API feature. However, unsupported queries can be constructed and will return a Hash based on the result XML (see Examples).

Installation

WikiBot is now a gem on rubygems, so installation is as simple as

gem install wikibot

If you want to install manually, the following gem dependencies are required:

Usage

wb = WikiBot::Bot.new( "username", "password", { options } )

When initializing a new WikiBot, the following options are available:

  • autologin (default: false) – specifies if the bot should log into the mediawiki automatically. WikiBot::Bot#login can be used to login otherwise.
  • api (default: http://en.wikipedia.org/w/api.php) – the URL of the API to use
  • readonly (default: false) – if true, the bot will not perform any write operation
  • debug (default: false) – outputs Curb debug messages

Logging in is not required for queries that use GET, but is for queries that use POST.

Examples

Grabbing the text of a page

wb = WikiBot::Bot.new("username", "password")
page = wb.page("Main Page")
text = page.text

Setting up some options

wb = WikiBot::Bot.new("username", "password", :autologin => true, :api => "http://fr.wikipedia.org/w/api.php")

Performing an unsupported query

WikiBot::Bot#query_api can be used to send an arbitrary query to the API. For this example, we’ll get image info from the Main Page.

wb = WikiBot::Bot.new("username", "password", :autologin => true)
query_data = {
  :action => :query,
  :prop   => :images,
  :titles => "Main Page"
}
xml_hash = wb.query_api(:get, query_data)