46 lines
900 B
Ruby
46 lines
900 B
Ruby
require 'yaml'
|
|
require 'json'
|
|
require './MWClient.rb'
|
|
|
|
class Wiki
|
|
@client = nil
|
|
@text = nil
|
|
@dummy = false
|
|
|
|
def initialize
|
|
config = YAML::load_file(File.join(__dir__, 'config.yaml'))
|
|
@client = MWClient.new config["url"]
|
|
@client.log_in config["username"], config["password"]
|
|
@dummy = config["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'
|
|
return list.data
|
|
end
|
|
def get_text(page_title)
|
|
return @client.get_wikitext(page_title)
|
|
end
|
|
|
|
attr_accessor :dummy
|
|
end
|