You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.5 KiB

require 'rubygems'
require 'hpricot'
require 'gollum'
require 'gollum-lib'
require 'optparse'
require 'git'
# from
# gem install hpricot gollum git wikicloth
# Parse command line options
# ToDo: Make command line options mandatory
options = {} do |opts|
opts.banner = 'Usage: ruby mw-to-gollum.rb --file input-file.xml --directory'
opts.on('-f FILE', '--file FILE', 'MediaWiki export file to import') do |v|
options[:file] = v
opts.on('-d DIRECTORY', '--directory DIRECTORY', 'Destination directory in which to create a new Gollum wiki') do |v|
options[:destination] = v
# Open the input file and create the output repo if it doesn't already exist
file =[:file], 'r')
git = Git.init(options[:destination])
wiki =[:destination])
doc = Hpricot(file)
# Get the Git user name and email
name = git.config('')
email = git.config('')
# Loop through each page in the MediaWiki dump file and create a new page in the Gollum wiki'/mediawiki/page').each do |el|
title ='title')":", " ")
content ='text').inner_text
commit = { :message => "Import MediaWiki page #{title} into Gollum",
:name => name,
:email => email}
puts "Writing page #{title}"
wiki.write_page(title, :mediawiki, content, commit)
rescue Gollum::DuplicatePageError
puts "Duplicate #{title}"
rescue Exception
puts $!, $@