Skip to content

Instantly share code, notes, and snippets.

@henare
Created March 10, 2011 02:41
Show Gist options
  • Save henare/863476 to your computer and use it in GitHub Desktop.
Save henare/863476 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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

@skyggeovn
Copy link

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

@carlohamalainen
Copy link

And here in 2024, the Ruby script worked well! Thanks!

I then converted everything to Github flavoured Markdown using:

#!/bin/bash

for file in *.mediawiki
do
    base_name="${file%.mediawiki}"
    
    pandoc -f mediawiki -t gfm -o "${base_name}.md" "$file"
    
    echo "Converted $file to ${base_name}.md"
done

echo "Conversion complete!"

@henare
Copy link
Author

henare commented Jul 29, 2024

This made my day hearing this was still useful 14 years later, thank you @carlohamalainen 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment