An open API service indexing awesome lists of open source software.

https://github.com/dvandersluis/wikibot

Ruby framework for MediaWiki bots
https://github.com/dvandersluis/wikibot

Last synced: about 1 year ago
JSON representation

Ruby framework for MediaWiki bots

Awesome Lists containing this project

README

          

h1=(). WikiBot

h2. 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).

h2. Installation

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

bc. gem install wikibot

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

* "curb":curb >= 0.5.4.0 (the taf2-curb gem can be used as well)
* "xml-simple":xml >= 1.0.12
* "deep_merge":dm >= 0.1.0
* "andand":aa >= 1.3.1

h2. Usage

bc. 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@.

h2. Examples

h3. Grabbing the text of a page

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

h3. Setting up some options

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

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

bc. 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)

[curb]http://rubygems.org/gems/curb
[xml]http://rubygems.org/gems/xml-simple
[dm]http://rubygems.org/gems/deep_merge
[aa]http://rubygems.org/gems/andand