neingeist
/
neinomaten
Archived
1
0
Fork 0

add a few more category methods

master
neingeist 19 years ago
parent e53bd9ae65
commit 9a688fc5c6

@ -37,6 +37,10 @@ class WikiBot
return @wiki + "index.php?title=" + url_encode(title) + "&redirect=no" return @wiki + "index.php?title=" + url_encode(title) + "&redirect=no"
end end
def url_page (title)
return @wiki + "index.php?title=" + url_encode(title)
end
def url_raw (title) def url_raw (title)
return @wiki + "index.php?title=" + url_encode(title) + "&action=raw" return @wiki + "index.php?title=" + url_encode(title) + "&action=raw"
end end
@ -197,6 +201,31 @@ class WikiBot
return articles return articles
end end
def get_categories(title)
if is_redirect?(title)
return []
end
categories = []
categories_html = @client.get_content(url_page(title)).scan(/<div id="catlinks">(.*?)<\/div>/)[0][0]
categories_html.scan(/title="(.*?)"/) do |m|
category = CGI.unescapeHTML(m[0])
categories.push(category)
end
return categories[1..-1]
end
def is_in_category?(title, category)
if is_redirect?(title)
return false
end
get_categories(title).member?(category)
end
end # class WikiBot end # class WikiBot
end # module MediaWikiBot end # module MediaWikiBot