53 lines
1.1 KiB
Ruby
53 lines
1.1 KiB
Ruby
require 'yaml'
|
|
require 'json'
|
|
require 'mediawiki_api'
|
|
|
|
class Wiki
|
|
@client = nil
|
|
@text = nil
|
|
@dummy = false
|
|
|
|
def initialize(url, username, password, dummy = false)
|
|
@client = MediawikiApi::Client.new url
|
|
@client.log_in username, password
|
|
@dummy = dummy
|
|
end
|
|
|
|
def create_page(name, content)
|
|
if not @dummy then
|
|
@client.create_page name, content
|
|
return true
|
|
else
|
|
if @dummy then
|
|
puts "Draft mode.\n"
|
|
end
|
|
puts @text
|
|
return true
|
|
end
|
|
end
|
|
def exists?(name)
|
|
status = @client.get_wikitext(name).status
|
|
if status.to_i == 404 then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
def get_list
|
|
list = @client.query list: 'allpages', aplimit:'max'
|
|
return list.data
|
|
end
|
|
def get_text(page_title)
|
|
history = @client.action :query,
|
|
prop: 'revisions',
|
|
titles: [page_title],
|
|
token_type: false,
|
|
rvprop: 'content'
|
|
history = history.data['pages']
|
|
page = history.keys.first
|
|
revision = history[page]['revisions'].first
|
|
return revision['*'].force_encoding("UTF-8")
|
|
end
|
|
|
|
attr_accessor :dummy, :client
|
|
end
|