Skip to content

dvandersluis/wikibot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Ruby framework for MediaWiki bots

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages