MediaWiki to Dokuwiki Converter

I hosted this site on wiki.splitbrain.org, the official site, because it fits in there and the bandwidth here is not the best. I’ll try to keep these pages in sync. Post there!

A online converter is now hosted at http://johbuc6.coconia.net/mediawiki2dokuwiki.php.

Hey, I was playing with awk & perl a little bit. I created a MediaWiki to Dokuwiki Converter.

Requirements

  • bash
  • perl

Capabilities

It is able to transform

  • Links
  • Bold/italic text
  • Lists
  • Talkings
  • Code

Limitations

  • One Page at once

Missing features (yet)

It is not able to transform

  • tables

Source

File mediawiki2dokuwiki.sh:

#! /bin/sh
# Mediawiki2Dokuwiki Converter
# originally by Johannes Buchner <buchner.johannes [at] gmx.at>
# Licence: GPL (http://www.gnu.org/licenses/gpl.txt)
 
# Headings
cat mediawiki | \
   perl -pe 's/^[ ]*=([^=])/<h1> ${1}/g' | \
   perl -pe 's/([^=])=[ ]*$/${1} <\/h1>/g' | \
   perl -pe 's/^[ ]*==([^=])/<h2> ${1}/g' | \
   perl -pe 's/([^=])==[ ]*$/${1} <\/h2>/g' | \
   perl -pe 's/^[ ]*===([^=])/<h3> ${1}/g' | \
   perl -pe 's/([^=])===[ ]*$/${1} <\/h3>/g' | \
   perl -pe 's/^[ ]*====([^=])/<h4> ${1}/g' | \
   perl -pe 's/([^=])====[ ]*$/${1} <\/h4>/g' | \
   perl -pe 's/^[ ]*=====([^=])/<h5> ${1}/g' | \
   perl -pe 's/([^=])=====[ ]*$/${1} <\/h5>/g' | \
   perl -pe 's/^[ ]*======([^=])/<h6> ${1}/g' | \
   perl -pe 's/([^=])======[ ]*$/${1} <\/h6>/g' \
    > mediawiki1
 
cat mediawiki1 | \
   perl -pe 's/<\/?h1>/======/g' | \
   perl -pe 's/<\/?h2>/=====/g' | \
   perl -pe 's/<\/?h3>/====/g' | \
   perl -pe 's/<\/?h4>/===/g' | \
   perl -pe 's/<\/?h5>/==/g' | \
   perl -pe 's/<\/?h6>/=/g' | \
   cat > mediawiki2
 
# lists
cat mediawiki2 |
  perl -pe 's/^[\*#]{4}\*/          * /g'  | \
  perl -pe 's/^[\*#]{3}\*/        * /g'    | \
  perl -pe 's/^[\*#]{2}\*/      * /g'      | \
  perl -pe 's/^[\*#]{1}\*/    * /g'        | \
  perl -pe 's/^\*/  * /g'                  | \
  perl -pe 's/^[\*#]{4}#/          \- /g'  | \
  perl -pe 's/^[\*\#]{3}\#/      \- /g'    | \
  perl -pe 's/^[\*\#]{2}\#/    \- /g'      | \
  perl -pe 's/^[\*\#]{1}\#/  \- /g'        | \
  perl -pe 's/^\#/  - /g'                  | \
  cat > mediawiki3
 
#[link] => [[link]]
cat mediawiki3 |
  perl -pe 's/([^\[])\[([^\[])/${1}[[${2}/g' |
  perl -pe 's/^\[([^\[])/[[${1}/g' |
  perl -pe 's/([^\]])\]([^\]])/${1}]]${2}/g' |
  perl -pe 's/([^\]])\]$/${1}]]/g' \
  > mediawiki4
 
#[[url text]] => [[url|text]]
cat mediawiki4 |
  perl -pe 's/(\[\[[^| \]]*) ([^|\]]*\]\])/${1}|${2}/g' \
  > mediawiki5
 
# bold, italic
cat mediawiki5 |
  perl -pe "s/'''/**/g" |
  perl -pe "s/''/\/\//g" \
  > mediawiki6
 
# talks
cat mediawiki6 |
  perl -pe "s/^[ ]*:/>/g" |
  perl -pe "s/>:/>>/g" |
  perl -pe "s/>>:/>>>/g" |
  perl -pe "s/>>>:/>>>>/g" |
  perl -pe "s/>>>>:/>>>>>/g" |
  perl -pe "s/>>>>>:/>>>>>>/g" |
  perl -pe "s/>>>>>>:/>>>>>>>/g" \
  > mediawiki7
 
cat mediawiki7 |
  perl -pe "s/<pre>/<code>/g" |
  perl -pe "s/<\/pre>/<\/code>/g" 
  > mediawiki8
 
cat mediawiki8 > dokuwiki

Howto use (for shell newbies)

  1. Make sure you are under Linux/Unix ;-)
  2. Save the code above in a file named mediawiki2dokuwiki.sh.
  3. Save the Mediawiki Site you want to transform to a file called mediawiki in the same directory.
  4. In the shell go to the directoy (using cd) and execute:
    chmod +x mediawiki2dokuwiki.sh #we want to be able to execute it
    ./mediawiki2dokuwiki.sh
  5. Now you got some files called mediawiki+a number. These are debugging steps (ignore).
  6. In the file ‘dokuwiki’ you’ll find your DokuWiki-Syntax.

Remember, all the fame goes to me, cause I started this ;-)! — Johannes Buchner 2006-01-26 19:27

Changelog

ToDo

Would be great if someone wants to improve this! What is needed:

Feedback & discussion