Skip to content

Instantly share code, notes, and snippets.

Forked from henare/mw-to-gollum.rb
Last active June 26, 2016 15:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save skyggeovn/6440594 to your computer and use it in GitHub Desktop.
Save skyggeovn/6440594 to your computer and use it in GitHub Desktop.
Convert a wiki from MediaWiki to Gollum.

Note that while this will convert a wiki from MediaWiki to Gollum, and links will be preserved, content formatting for the most part will be broken until you set the proper content type for Gollum.

  1. Install dependancies:

    gem install hpricot
    gem install gollum
    gem install gollum-lib
    gem install wikicloth
  2. Perform a Special:Export

  3. Place the XML in a Gollum repo directory, along with the .rb

  4. Edit the .rb for your particular needs (.xml path, commit credentials)

  5. Run the .rb

    ruby mw-to-gollum.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'gollum'
require 'gollum-lib'
wiki =".")
file ="G.R.A.C.E.-20130904175032.xml", "r")
doc = Hpricot(file)'/mediawiki/page').each do |el|
title ='title').inner_text
content ='text').inner_text
commit = { :message => "Import MediaWiki page #{title} into Gollum",
:name => 'Tim Honeywell',
:email => '' }
puts "Writing page #{title}"
wiki.write_page(title, :mediawiki, content, commit)
rescue Gollum::DuplicatePageError => e
p "Duplicate #{title}"
Copy link

davidar commented Dec 2, 2015

For anyone else getting encoding errors: gollum/gollum#843

Copy link

MattiSG commented Apr 14, 2016

If you get encoding errors: the problem is indeed the one listed by @davidar (tl;dr: creating a file with accented characters is a problem with Git), but the solution is hard to put in place, and didn't work in my case.

I simply used Ruby's native i18n to remove diacritics. This UTF-supporting (with updated install instructions) version can convert international MediaWiki to Gollum / GitHub wiki pages.

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