Mediawiki output


/ Published in: Ruby
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. #!/usr/bin/ruby -w
  2.  
  3. require "mysql"
  4.  
  5. def grab(dbh, title)
  6. 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}'));")
  7. end
  8.  
  9. def all(dbh)
  10. dbh.query("select page_title,old_text from page,revision,text where rev_id = page_latest and old_id = rev_text_id;")
  11. end
  12.  
  13. begin
  14. dbh = Mysql.real_connect("localhost", "wikiuser", ARG[0], "wikidb")
  15. @title = "Main_Page"
  16. rescue Mysql::Error => e
  17. puts "Error code: #{e.errno}"
  18. puts "Error message: #{e.error}"
  19. puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
  20. ensure
  21. # r = grab(dbh, @title)
  22. r = all(dbh)
  23. r.each do |row|
  24. File.open("/data/shared/backup/wiki/#{row[0]}", "w") do |f|
  25. f.write(row[1])
  26. end
  27. end
  28. dbh.close if dbh
  29. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.