Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Category support
Browse files Browse the repository at this point in the history
git-svn-id: svn://78.47.249.61/ruby-mediawiki/trunk@23 ba9c31aa-a806-0410-9a81-9f13d15ee83b
  • Loading branch information
astro committed Dec 11, 2005
1 parent 26885df commit b94b5c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mediawiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'uri'

require 'mediawiki/article'
require 'mediawiki/category'
require 'mediawiki/minibrowser'

module MediaWiki
Expand Down Expand Up @@ -30,6 +31,10 @@ def login( username, password )
end
end

def category(name)
Category.new(self, name)
end

def article(name, section = nil)
Article.new(self, name, section)
end
Expand Down
29 changes: 29 additions & 0 deletions lib/mediawiki/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rexml/document'

module MediaWiki
class Category
def initialize(wiki, name)
@cached = false
@doc = nil
@wiki = wiki
@name = name
end

def reload
@doc = REXML::Document.new(@wiki.browser.get_content(@wiki.article_url("Category:#{@name}"))).root
@cached = true
end

def articles
unless @cached
reload
end

res = []
@doc.each_element('//div[@id="bodyContent"]//ul/li/a') { |a,|
res << a.attributes['title']
}
res
end
end
end

0 comments on commit b94b5c4

Please sign in to comment.