Class: MediaWiki

Inherits:
Object
  • Object
show all
Defined in:
lib/mediawiki.rb

Overview

The MediaWiki class allows one to interface with the MediaWiki API. Everything about it is incomplete and I promise that it will eat your kids and/or small furry woodland creatures. These things happen.

Usage

To use, you construct a MediaWiki object for the site

require 'mediawiki'
example_wiki = MediaWiki.new("http://example.com/w/api.php")

From here you can query based on title or pageid for individual pages or collections

# By pageid
page = example_wiki.find(10)
page.title #=> "foo"

# By title
page = example_wiki.find_by_title("foo")
page.pageid #=> 10

# a collection by pageids
result = example_wiki.find_by_pageids(10,11)
result.pages.collect(&:title) #=> ["foo", "bar"]

# a collection by titles
result = example_wiki.find_by_titles("foo", "bar")
result.pages.collect(&:pageid) #=> [10, 11]

Defined Under Namespace

Classes: MediaWikiBase

Constant Summary collapse

PROPS =
[:info, :revisions, :links, :langlinks, :images, :imageinfo,
:templates, :categories, :extlinks, :categoryinfo]
RVPROPS =
[:ids, :flags, :timestamp, :user, :size, :comment, :content]

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ MediaWiki

Returns a new instance of MediaWiki.



69
70
71
# File 'lib/mediawiki.rb', line 69

def initialize(url)
  @url = url
end

Instance Method Details

#find(*opts) ⇒ Object

find by pageid



74
75
76
# File 'lib/mediawiki.rb', line 74

def find(*opts)
  find_by_pageids(opts).pages.first
end

#find_by_pageids(*opts) ⇒ Object

find the articles identified by the Array page_ids



79
80
81
82
83
# File 'lib/mediawiki.rb', line 79

def find_by_pageids(*opts)
  page_ids, opts_qs = handle_options(opts)
  page_ids_qs = make_qs("pageids", page_ids)
  MediaWikiBase.new(make_url(opts_qs.push(page_ids_qs)))
end

#find_by_title(*opts) ⇒ Object

Same as find_by_titles but returns a single page



86
87
88
# File 'lib/mediawiki.rb', line 86

def find_by_title(*opts)
  find_by_titles(opts).pages.first
end

#find_by_titles(*opts) ⇒ Object

find the articles identified by the Array titles



91
92
93
94
95
# File 'lib/mediawiki.rb', line 91

def find_by_titles(*opts)
  titles, opts_qs = handle_options(opts)
  titles_qs = make_qs("titles", titles)
  MediaWikiBase.new(make_url(opts_qs.push(titles_qs)))
end