Recently, I needed to make some fairly large bodies of XML available for editing by a group of people. In this case the data was stored in the Topic Maps format (XTM), and –as long as I was the only one editing the files– this had been working just fine.
But with more people about to join in, it was clear that editing the files in a simple text editor wasn’t such a good idea. So, to avoid the risk of ending up with different versions (and people endlessly complaining about editing XML), I decided to turn the whole thing into a wiki.
Now, MediaWiki has the Special:Export tool for migrating wikis (‘transwikiing’). It exports pages in a simple XML format, so that you can import it to another wiki. This way you’re able to create a wiki simply by emulating the MediaWiki XML export format.
How to
If you want to try it, the MediaWiki output has to look a little something like this:
<?xml version="1.0" encoding="utf-8"?>
<mediawiki xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.mediawiki.org/xml/export-0.3/"
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/
http://www.mediawiki.org/xml/export-0.3.xsd"
version="0.3" xml:lang="da">
<page>
<title>Google</title>
<id>1</id>
<revision>
<id>1</id>
<timestamp/>
<contributor>
<username>yourUserName</username>
<id>1</id>
</contributor>
<text xml:space="preserve">
<!-- Wikitext goes here -->
==Link==
[http://www.google.com]
</text>
</revision>
</page>
<page>
<title>Microsoft</title>
<id>2</id>
...
</page>
</mediawiki>
If your data is XTM, your starting point might be something like this made-up Topic Map with names and links of three companies:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topicMap SYSTEM "xtm1.dtd">
<topicMap id="companies-tm.xtm"
xmlns="http://www.topicmaps.org/xtm/1.0/"
xmlns:xlink="http://www.w3.org/1999/xlink">
<topic id="001">
<baseName>
<baseNameString>Google</baseNameString>
</baseName>
<occurrence>
<resourceRef xlink:href="http://www.google.com"/>
</occurrence>
</topic>
<topic id="002">
<baseName>
<baseNameString>Microsoft</baseNameString>
</baseName>
<occurrence>
<resourceRef xlink:href="http://www.microsoft.com"/>
</occurrence>
</topic>
<topic id="003">
<baseName>
<baseNameString>Oracle<baseNameString>
</baseName>
<occurrence>
<resourceRef xlink:href="http://www.oracle.com"/>
</occurrence>
</topic>
</topicMap>
In this case the following XSLT stylesheet will do the job:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tm="http://www.topicmaps.org xtm/1.0/" xmlns:tmlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="tm tmlink" version="2.0"> <xsl:output method="xml" encoding="utf-8" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="tm:topicMap"/> </xsl:template> <xsl:template match="tm:topicMap"> <mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="da"> <xsl:apply-templates select="tm:topic"/> </mediawiki> </xsl:template> <xsl:template match="tm:topic"> <page> <title> <xsl:apply-templates select="tm:baseName/tm:baseNameString"/> </title> <id><!--To give each page a unique number, use the xsl:number instruction--><xsl:number/></id> <revision> <id>1</id> <timestamp/> <contributor> <username>yourUserName</username> <id>2</id> </contributor> <!--Since whitespace is crucial to the layout of your wikipage, you should add the xml:space attribute and set the value to 'preserve'--> <text xml:space="preserve"> <!--Now start building your wikipage --> ==Links== <xsl:value-of select="tm:occurrence"/> </text> </revision> </page> </xsl:template> </xsl:stylesheet>
Therefore:
- Make sure that your wiki is installed, AND that you have admin rights
- Create a stylesheet, somewhat like the one provided above
- Run the stylesheet on your XML file, for instance from your command line with saxon:
$ saxon topics.xtm topicMaps2Mediawiki.xsl > mediawikiTopics.xml
- Go to the Special:Import page on your wiki
- Browse for the file, and
- Upload! Do remember, however, that the filesize maximum defaults to around 1.4 MB. To change it, you need to go to php.ini and simply change the parameters for maxuploadsize=.
After uploading the file, you’ll receive a list of links to the pages, you just made.