Return to Snippet

Revision: 6323
at May 16, 2008 08:30 by felipec


Initial Code
#!/usr/bin/ruby -w

require "mysql"

def grab(dbh, title)
	dbh.query("select old_text from text where old_id=(select rev_text_id from revision where rev_id=(select page_latest from page where page_title='#{title}'));")
end

def all(dbh)
	dbh.query("select page_title,old_text from page,revision,text where rev_id = page_latest and old_id = rev_text_id;")
end

begin
	dbh = Mysql.real_connect("localhost", "wikiuser", ARG[0], "wikidb")
	@title = "Main_Page"
rescue Mysql::Error => e
	puts "Error code: #{e.errno}"
		puts "Error message: #{e.error}"
		puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
ensure
	# r = grab(dbh, @title)
	r = all(dbh)
	r.each do |row|
		File.open("/data/shared/backup/wiki/#{row[0]}", "w") do |f|
			f.write(row[1])
		end
	end
	dbh.close if dbh
end

Initial URL

                                

Initial Description
Gets either a specific article or all the articles from a mediawiki mysql database.

Initial Title
Mediawiki output

Initial Tags

                                

Initial Language
Ruby