wikitext improvements
This commit is contained in:
parent
fe99d98226
commit
517d67c64b
|
@ -1,7 +0,0 @@
|
|||
require 'mediawiki_api'
|
||||
|
||||
class MWClient < MediawikiApi::Client
|
||||
def get_wikitext(title)
|
||||
@conn.get '/index.php', action: 'raw', title: title
|
||||
end
|
||||
end
|
14
Wiki.rb
14
Wiki.rb
|
@ -1,6 +1,6 @@
|
|||
require 'yaml'
|
||||
require 'json'
|
||||
require './MWClient.rb'
|
||||
require 'mediawiki_api'
|
||||
|
||||
class Wiki
|
||||
@client = nil
|
||||
|
@ -8,7 +8,7 @@ class Wiki
|
|||
@dummy = false
|
||||
|
||||
def initialize(url, username, password, dummy = false)
|
||||
@client = MWClient.new url
|
||||
@client = MediawikiApi::Client.new url
|
||||
@client.log_in username, password
|
||||
@dummy = dummy
|
||||
end
|
||||
|
@ -37,7 +37,15 @@ class Wiki
|
|||
return list.data
|
||||
end
|
||||
def get_text(page_title)
|
||||
return @client.get_wikitext(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
|
||||
|
|
21
undo.rb
Executable file
21
undo.rb
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/ruby
|
||||
require './Wiki.rb'
|
||||
|
||||
config = YAML::load_file(File.join(__dir__, 'config.yaml'))
|
||||
config["sites"].each do |site|
|
||||
wiki = Wiki.new(site["url"], site["username"], site["password"], config["dummy"])
|
||||
list = wiki.get_list()['allpages']
|
||||
for page in list do
|
||||
if page['title'] == 'Main Page' || page['title'] == 'עמוד ראשי' then
|
||||
next
|
||||
end
|
||||
puts page['title']
|
||||
page_text = wiki.get_text(page['title'])
|
||||
puts page_text
|
||||
exit # TODO - REMOVE
|
||||
changed = false
|
||||
if changed then
|
||||
wiki.create_page(page['title'], page_text)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue