(no commit message)
[ikiwiki] / doc / tips / convert_mediawiki_to_ikiwiki / discussion.mdwn
1 The u32 page is excellent, but I wonder if documenting the procedure here
2 would be worthwhile. Who knows, the remote site might disappear. But also
3 there are some variations on the approach that might be useful:
4
5  * using a python script and the dom library to extract the page names from
6    Special:Allpages (such as
7    <http://www.staff.ncl.ac.uk/jon.dowland/unix/docs/get_pagenames.py>)
8  * Or, querying the mysql back-end to get the names
9  * using WWW::MediaWiki for importing/exporting pages from the wiki, instead
10    of Special::Export
11
12 Also, some detail on converting mediawiki transclusion to ikiwiki inlines...
13
14 -- [[users/Jon]]
15
16 > "Who knows, the remote site might disappear.". Right now, it appears to
17 > have done just that. -- [[users/Jon]]
18
19
20 The iki-fast-load ruby script from the u32 page is given below:
21
22         #!/usr/bin/env ruby
23
24         # This script is called on the final sorted, de-spammed revision
25         # XML file.
26         #
27         # It doesn't currently check for no-op revisions...  I believe
28         # that git-fast-load will dutifully load them even though nothing
29         # happened.  I don't care to solve this by adding a file cache
30         # to this script.  You can run iki-diff-next.rb to highlight any
31         # empty revisions that need to be removed.
32         #
33         # This turns each node into an equivalent file.
34         #    It does not convert spaces to underscores in file names.
35         #       This would break wikilinks.
36         #       I suppose you could fix this with mod_speling or mod_rewrite.
37         #
38         # It replaces nodes in the Image: namespace with the files themselves.
39
40
41         require 'rubygems'
42         require 'node-callback'
43         require 'time'
44         require 'ostruct'
45
46
47         # pipe is the stream to receive the git-fast-import commands
48         # putfrom is true if this branch has existing commits on it, false if not.
49         def format_git_commit(pipe, f)
50            # Need to escape backslashes and double-quotes for git?
51            # No, git breaks when I do this. 
52            # For the filename "path with \\", git sez: bad default revision 'HEAD'
53            # filename = '"' + filename.gsub('\\', '\\\\\\\\').gsub('"', '\\"') + '"'
54
55            # In the calls below, length must be the size in bytes!!
56            # TODO: I haven't figured out how this works in the land of UTF8 and Ruby 1.9.
57            pipe.puts "commit #{f.branch}"
58            pipe.puts "committer #{f.username} <#{f.email}> #{f.timestamp.rfc2822}"
59            pipe.puts "data #{f.message.length}\n#{f.message}\n"
60            pipe.puts "from #{f.branch}^0" if f.putfrom
61            pipe.puts "M 644 inline #{f.filename}"
62            pipe.puts "data #{f.content.length}\n#{f.content}\n"
63            pipe.puts
64         end
65