====== MediaWiki to Dokuwiki Converter ====== **I hosted this site on [[http://wiki.splitbrain.org/wiki:mediawiki_to_dokuwiki_converter|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. [[http://wiki.splitbrain.org/wiki:mediawiki_to_dokuwiki_converter|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 # Licence: GPL (http://www.gnu.org/licenses/gpl.txt) # Headings cat mediawiki | \ perl -pe 's/^[ ]*=([^=])/

${1}/g' | \ perl -pe 's/([^=])=[ ]*$/${1} <\/h1>/g' | \ perl -pe 's/^[ ]*==([^=])/

${1}/g' | \ perl -pe 's/([^=])==[ ]*$/${1} <\/h2>/g' | \ perl -pe 's/^[ ]*===([^=])/

${1}/g' | \ perl -pe 's/([^=])===[ ]*$/${1} <\/h3>/g' | \ perl -pe 's/^[ ]*====([^=])/

${1}/g' | \ perl -pe 's/([^=])====[ ]*$/${1} <\/h4>/g' | \ perl -pe 's/^[ ]*=====([^=])/

${1}/g' | \ perl -pe 's/([^=])=====[ ]*$/${1} <\/h5>/g' | \ perl -pe 's/^[ ]*======([^=])/
${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/
//g" |
  perl -pe "s/<\/pre>/<\/code>/g" 
  > mediawiki8

cat mediawiki8 > dokuwiki

==== Howto use (for shell newbies) ====
  - Make sure you are under Linux/Unix ;-)
  - Save the code above in a file named ''mediawiki2dokuwiki.sh''.
  - Save the Mediawiki Site you want to transform to a file called ''mediawiki'' in the same directory.
  - 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

  - Now you got some files called mediawiki+a number. These are debugging steps (ignore).
  - In the file '''dokuwiki''' you'll find your DokuWiki-Syntax.

Remember, all the fame goes to me, cause I started this ;-)! --- //[[buchner.johannes@gmx.at|Johannes Buchner]] 2006-01-26 19:27//
==== Changelog ====
  * added Talkings --- //[[buchner.johannes@gmx.at|Johannes Buchner]] 2006-01-27 11:37//
==== ToDo ====
Would be great if someone wants to improve this! What is needed:
  * See Limitations & Missing features
  * A webbased service: now available: [[http://johbuc6.coconia.net/mediawiki2dokuwiki.php]].
==== Feedback & discussion ====
  * Yeah, i could remove leading whitespaces at all, but this might ruin the design. //[[buchner.johannes@gmx.at|Johannes Buchner]] 2006-01-27 11:41//
  * I just began to implement tables with: 
  perl -pe "s/^[ ]*\{\|[^\|]*$//g" |
  perl -pe "s/^[ ]*\|\}[ ]*$//g" |
  perl -pe "s/^[ ]*\|([^\|]+)\|[ ]*$/|${1}|/g" 
  # ...
 But [[http://meta.wikimedia.org/wiki/Help:Table|tables in Wikimedia]] are crap. I suggest to use a html2wiki implementation for this need ('cause the needs will be very special) like [[http://diberri.dyndns.org/html2wiki.html]] //[[buchner.johannes@gmx.at|Johannes Buchner]] 2006-01-27 12:00//
  * [[http://wiki.splitbrain.org/wiki:mediawiki_to_dokuwiki_converter|Post there!]]