]> sipb.mit.edu Git - ikiwiki.git/blob - doc/tips/convert_mediawiki_to_ikiwiki.mdwn
Merge branch 'master' of git://git.ikiwiki.info
[ikiwiki.git] / doc / tips / convert_mediawiki_to_ikiwiki.mdwn
1 Mediawiki is a dynamically-generated wiki which stores it's data in a
2 relational database. Pages are marked up using a proprietary markup. It is
3 possible to import the contents of a Mediawiki site into an ikiwiki,
4 converting some of the Mediawiki conventions into Ikiwiki ones.
5
6 The following instructions describe ways of obtaining the current version of
7 the wiki. We do not yet cover importing the history of edits.
8
9 ## Step 1: Getting a list of pages
10
11 The first bit of information you require is a list of pages in the Mediawiki.
12 There are several different ways of obtaining these.
13
14 ### Parsing the output of `Special:Allpages`
15
16 Mediawikis have a special page called `Special:Allpages` which list all the
17 pages for a given namespace on the wiki.
18
19 If you fetch the output of this page to a local file with something like
20
21     wget -q -O tmpfile 'http://your-mediawiki/wiki/Special:Allpages'
22
23 You can extract the list of page names using the following python script. Note
24 that this script is sensitive to the specific markup used on the page, so if
25 you have tweaked your mediawiki theme a lot from the original, you will need
26 to adjust this script too:
27
28     from xml.dom.minidom import parse, parseString
29     
30     dom = parse(argv[1])
31     tables = dom.getElementsByTagName("table")
32     pagetable = tables[-1]
33     anchors = pagetable.getElementsByTagName("a")
34     for a in anchors:
35         print a.firstChild.toxml().\
36             replace('&,'&').\
37             replace('&lt;','<').\
38             replace('&gt;','>')
39
40 Also, if you have pages with titles that need to be encoded to be represented
41 in HTML, you may need to add further processing to the last line.
42
43 ### Querying the database
44
45 If you have access to the relational database in which your mediawiki data is
46 stored, it is possible to derive a list of page names from this.
47
48 ## Step 2: fetching the page data
49
50 Once you have a list of page names, you can fetch the data for each page.
51
52 ### Method 1: via HTTP and `action=raw`
53
54 You need to create two derived strings from the page titles already: the
55 destination path for the page and the source URL. Assuming `$pagename` 
56 contains a pagename obtained above, and `$wiki` contains the URL to your
57 mediawiki's `index.php` file:
58
59     src=`echo "$pagename" | tr ' ' _ | sed 's,&,&amp;,g'`
60     dest=`"$pagename" | tr ' ' _ | sed 's,&,__38__,g'`
61     
62     mkdir -p `dirname "$dest"`
63     wget -q "$wiki?title=$src&action=raw" -O "$dest"
64
65 ### Method 2: via HTTP and `Special:Export`
66
67 Mediawiki also has a special page `Special:Export` which can be used to obtain
68 the source of the page and other metadata such as the last contributor, or the
69 full history, etc.
70
71 You need to send a `POST` request to the `Special:Export` page. See the source
72 of the page fetched via `GET` to determine the correct arguments.
73
74 You will then need to write an XML parser to extract the data you need from
75 the result.
76
77 ### Method 3: via the database
78
79 It is possible to extract the page data from the database with some
80 well-crafted queries.
81
82 ## Step 2: format conversion
83
84 The next step is to convert Mediawiki conventions into Ikiwiki ones. These
85 include
86
87  * convert Categories into tags
88  * ...
89
90 ## External links
91
92 [[sabr]] used to explain how to [import MediaWiki content into
93 git](http://u32.net/Mediawiki_Conversion/index.html?updated), including full
94 edit history, but as of 2009/10/16 that site is not available.
95
96 The [[plugins/contrib/mediawiki]] plugin can then be used by ikiwiki to build
97 the wiki.