DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:twiki_to_dokuwiki_conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tips:twiki_to_dokuwiki_conversion [2009-08-27 18:45] 88.153.25.67tips:twiki_to_dokuwiki_conversion [2010-03-20 21:23] (current) 88.66.13.59
Line 18: Line 18:
   * Headings   * Headings
   * Unordered Lists   * Unordered Lists
 +  * Ordered Lists
   * Bold, Italic, Bold-Italic Text   * Bold, Italic, Bold-Italic Text
   * <b>, <i>, <u> to Doku syntax   * <b>, <i>, <u> to Doku syntax
Line 27: Line 28:
  
   * I **highly** recommend running this script on a copy of your existing TWiki site...but that goes without saying.   * I **highly** recommend running this script on a copy of your existing TWiki site...but that goes without saying.
-  * Assuming your copied TWiki data is in /twikibackup remove all the RCS ,v files. DokuWiki does not need them. +  * Using these two scripts in tandem will copy your existing Twiki one namespace at a time 
-    * <code>find twikibackup -name "*,v" -exec rm -f {} \;</code>+    * Use the first script to copy the data and it will call the second script to do the transformations
   * Save the code below into a file with a .sh extension e.g. twikiconverter.sh. The filename does not matter.   * Save the code below into a file with a .sh extension e.g. twikiconverter.sh. The filename does not matter.
   * Open a terminal window and browse to the directory into which you saved the twikiconverter.sh file.   * Open a terminal window and browse to the directory into which you saved the twikiconverter.sh file.
   * Change the permission of this file to allow execution   * Change the permission of this file to allow execution
-    * <code>chmod u+x ./twikiconverter.sh</code> +    * <code> 
-  * From the terminal, run the twikiconverter.sh script against a file or set of files +chmod u+x ./migratenamespace.sh 
-    * <code>./twikiconverter.sh TwikDocument1.txt or ./twikiconverter.sh *.txt</code> +chmod u+x ./twikiconverter.sh</code> 
-  * Thats it! All of your TWiki documents are now DokuWiki documents ready for importation into your new Wiki. +  * From the terminal, run the migratenamespace.sh script against a twiki namespace 
 +    * <code>./migratenamespace.sh MyWikiNamespace</code> 
 +  * Thats it! All of your TWiki documents are now DokuWiki documents imported into you new dokuwiki.
 ===== Source Code ===== ===== Source Code =====
 +<code bash migratenamespace.sh>
 +#!/bin/bash
 +#Twiki to DokuWiki File Converter
 +#Developed by Thomas Vachon <vachon-dokuwiki ATgamelogicDOTcom>
 +#Licensed under the GPL: (http://www.gnu.org/licenses/gpl.txt)
 +
 +if [ -z "$1" ]; then
 +echo "Usage: $0 TwikiNamespace"
 +exit
 +fi
 +
 +#Copy the files to your present directory (run this in the data directory of the doku desination)
 +rsync -arv /var/lib/twiki/data/$1 .
 +cd $1
 +rm *,v *.lock
 +
 +#Makes all the filenames lowercase (as it is a dokuwiki requirement)
 +for f in *; do
 +g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
 +mv "$f" "$g"
 +done
 +
 +cd ../
 +
 +#make the namespace directory lowercase
 +namespace=`echo $1 | tr '[:upper:]' '[:lower:]'`
 +mv $1 $namespace
 +./twikiconverter $namespace/*.txt
 +</code>
 +
  
-<code bash>+<code bash twikiconverter>
 #!/bin/bash #!/bin/bash
-#Twiki to DokuWiki Converter+#Twiki to DokuWiki Syntax Converter
 #Developed by Ben Chapman <bkchapman atgmaildotcom> #Developed by Ben Chapman <bkchapman atgmaildotcom>
 +#Supplemented by Thomas Vachon <vachon-dokuwiki ATgamelogicDOTcom>
 #Licensed under the GPL: (http://www.gnu.org/licenses/gpl.txt) #Licensed under the GPL: (http://www.gnu.org/licenses/gpl.txt)
  
Line 53: Line 86:
 INPUT=$* INPUT=$*
  
-Removing carriage returns +#Remove the ---+++++ !! (headed links) 
-perl -pi -e 's/\r//g' $*+perl -pi -e 's/\-\-\-\+\+\+\+\+ \!\!//g' $* 
 + 
 +# Substituting newlines for carriage returns 
 +perl -pi -e 's/\r/\n\n/g' $*
  
 # Stripping Twiki %META information # Stripping Twiki %META information
Line 87: Line 123:
  
 # Converting unordered lists # Converting unordered lists
-# I'm using %^ as a placeholder so the +# I'm using %^ as a placeholder so the
 # bold conversion below does not mess with # bold conversion below does not mess with
 # our lists. Don't worry it gets fixed below. # our lists. Don't worry it gets fixed below.
Line 98: Line 134:
 perl -pi -e 's/   \*/  \%\^/g' $* perl -pi -e 's/   \*/  \%\^/g' $*
  
-Twiki'support for ordered lists is pretty +Commented out. See below 
-weak...not worth trying to script.+# Convert Ordered Lists v1 
 +#perl -pi -e 's/\t\t\t\1/      \-/g' $* 
 +#perl -pi -e 's/\t\t\1/    \-/g' $* 
 +#perl -pi -e 's/\t\1/   \-/g' $* 
 +#perl -pi -e 's/            \1/        \-/g' $* 
 +#perl -pi -e 's/         \1/      \-/g' $* 
 +#perl -pi -e 's/      \1/    \-/g' $* 
 +#perl -pi -e 's/   \1/  \-/g' $* 
 + 
 +# In Perl 5.1, the \1 in the capture group is supposed to reference a capturing group I assume the original author intended that to be a single "1" instead When the original set of commands are run against 5.1 an error is thrown and the text is not converted properly The modified version below throws no errors. 
 +# Convert Ordered Lists v2 
 +perl -pi -e 's/\t\t\t1/      \-/g' $* 
 +perl -pi -e 's/\t\t1/    \-/g' $* 
 +perl -pi -e 's/\t1/   \-/g' $* 
 +perl -pi -e 's/            1/        \-/g' $* 
 +perl -pi -e 's/         1/      \-/g' $* 
 +perl -pi -e 's/      1/    \-/g' $* 
 +perl -pi -e 's/   1/  \-/g' $*
  
 # Converting bold-italic text # Converting bold-italic text
Line 120: Line 173:
 perl -pi -e 's/<verbatim>/<file>/g' $* perl -pi -e 's/<verbatim>/<file>/g' $*
 perl -pi -e 's/<\/verbatim>/<\/file>/g' $* perl -pi -e 's/<\/verbatim>/<\/file>/g' $*
- 
 # Removing <nop>...no more CamelCase # Removing <nop>...no more CamelCase
 perl -pi -e 's/<nop>//g' $* perl -pi -e 's/<nop>//g' $*
Line 140: Line 192:
 perl -pi -e 's/\*\*  \^/  \^/g' $* perl -pi -e 's/\*\*  \^/  \^/g' $*
 perl -pi -e 's/\*\*  \|/  \^/g' $* perl -pi -e 's/\*\*  \|/  \^/g' $*
 +
 +#Remove !!
 +perl -pi -e 's/\!\!//g' $*
 +
 +#Remove %TOC%
 +perl -pi -e 's/\%TOC\%//g' $*
 +
 +#Fix named links
 +perl -pi -e 's/\]\[/\|/g' $*
 +
 +#Remove unneeded META info and HTML 4.0 Traditional br's
 +perl -pi -e 's/\%META.*//g' $*
 +perl -pi -e 's/\<br\>/\n/g' $*
 +
 +#Name pre-formatted text as code
 +perl -pi -e 's/\<pre\>/\<code\>/g' $*
 +perl -pi -e 's/\<\/pre\>/\<\/code\>/g' $*
 +perl -pi -e 's/\<PRE\>/\<code\>/g' $*
 +perl -pi -e 's/\<\/PRE\>/\<\/code\>/g' $*
 +
 +#Fix Twiki's abuse of spaces in links
 +#Yes, I know this is ugly, but it works, feel free to clean it up
 +perl -pi -e 's/\[\[(\w+)\s(\w+)/\[\[\1\2/g' $*
 +perl -pi -e 's/\[\[(\w+)\s(\w+)\s(\w+)/\[\[\1\2\3/g' $*
 +perl -pi -e 's/\[\[(\w+)\s(\w+)\s(\w+)\s(\w+)/\[\[\1\2\3\4/g' $*
 +perl -pi -e 's/\[\[(\w+)\s(\w+)\s(\w+)\s(\w+)\s(\w+)/\[\[\1\2\3\4\5/g' $*
 +perl -pi -e 's/\[\[(\w+)\s(\w+)\s(\w+)\s(\w+)\s(\w+)\s(\w+)/\[\[\1\2\3\4\5\6/g' $*
 +perl -pi -e 's/\[\[(\w+)\s(\w+)\s(\w+)\s(\w+)\s(\w+)\s(\w+)\s(\w+)/\[\[\1\2\3\4\5\6\7/g' $*
  
 exit 0 exit 0
Line 154: Line 234:
  
 --- [[bkchapman@gmail.com|Ben Chapman]] --- [[bkchapman@gmail.com|Ben Chapman]]
 +
 +  * This code has been updated (Nov 17, 2009) to support (at least in part) Twiki syntax as of 1.4.0. Although we had some legacy markup.  This also now handles ordered lists and other annoyances we found in the use of the tool, such as Twiki allowing spaces in page links and dokuwiki not.
 +  * This will now import entire namespaces, instead of just converting existing files.
 +
 +--- [[vachon-dokuwiki@gamelogic.com|Thomas Vachon]] 
 +  
  
   * If you are running this script on Windows, you may encounter the "Can't do inplace edit without backup" error. You can fix this by replacing "perl -pi" by "perl -p -i'.bak'" and "perl -ni" by "perl -n -i'.bak'". This will create backup files with ".bak" extension that you can remove afterwards,   * If you are running this script on Windows, you may encounter the "Can't do inplace edit without backup" error. You can fix this by replacing "perl -pi" by "perl -p -i'.bak'" and "perl -ni" by "perl -n -i'.bak'". This will create backup files with ".bak" extension that you can remove afterwards,
tips/twiki_to_dokuwiki_conversion.1251391516.txt.gz · Last modified: 2009-08-27 18:45 by 88.153.25.67

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki