Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Imports a MediaWiki XML export into a Gollum wiki
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'gollum'
wiki = Gollum::Wiki.new('openaustralia.wiki')
file = File.open("OpenAustralia-20110309232515.xml", "r")
doc = Hpricot(file)
doc.search('/mediawiki/page').each do |el|
title = el.at('title').inner_text
content = el.at('text').inner_text
commit = { :message => "Import MediaWiki page #{title} into Gollum",
:name => 'Henare Degan',
:email => 'henare.degan@gmail.com' }
begin
puts "Writing page #{title}"
wiki.write_page(title, :mediawiki, content, commit)
rescue Gollum::DuplicatePageError => e
p "Duplicate #{title}"
end
end
file.close
@domenkozar

This comment has been minimized.

Copy link

@domenkozar domenkozar commented Apr 1, 2013

Wonderful. Quick details how to import that into github, once you have xml export:

sudo gem install hpricot gollum

mkdir openaustralia.wiki
cd openaustralia.wiki
git init
cd ..
ruby mw-to-gollum.rb

@schmunk42

This comment has been minimized.

Copy link

@schmunk42 schmunk42 commented Jun 3, 2013

Very nice! I had to add require 'gollum-lib'

@fyrk

This comment has been minimized.

Copy link

@fyrk fyrk commented Sep 4, 2013

Thanks a lot, this was a big help! Like @schmunk42, I had to require 'gollum-lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.