tips:tikiwiki2dokuwiki
This is an old revision of the document!
Tikiwiki2Dokuwiki
I've done this script to migrate our tikiwiki. It is provided as is without guaranty or support of any kind. Feel free to improve or modify it as you need.
It export the pages from the Tikiwiki database and convert some of the syntax. There is no history export.
After it's done, copy the files in /pages directory to your wiki.
— Jean-Michel LACROIX 2008/04/11 12:02
<?php // You must copy utf8.php from Dokuwki in the same directory // and create a pages directory. require_once('utf8.php'); $conf = array(); $conf['sepchar'] = "_"; $conf['useslash'] = false; $conf['deaccent'] = 1; // Function cleanID copied from Dokuwiki /** * Remove unwanted chars from ID * * Cleans a given ID to only use allowed characters. Accented characters are * converted to unaccented ones * * @author Andreas Gohr <andi@splitbrain.org> * @param string $raw_id The pageid to clean * @param boolean $ascii Force ASCII */ function cleanID($raw_id,$ascii=false){ global $conf; static $sepcharpat = null; global $cache_cleanid; $cache = & $cache_cleanid; $sepchar = $conf['sepchar']; if($sepcharpat == null) // build string only once to save clock cycles $sepcharpat = '#\\'.$sepchar.'+#'; $id = trim($raw_id); $id = utf8_strtolower($id); //alternative namespace seperator $id = strtr($id,';',':'); if($conf['useslash']){ $id = strtr($id,'/',':'); }else{ $id = strtr($id,'/',$sepchar); } if($conf['deaccent'] == 2 || $ascii) $id = utf8_romanize($id); if($conf['deaccent'] || $ascii) $id = utf8_deaccent($id,-1); //remove specials $id = utf8_stripspecials($id,$sepchar,'\*'); if($ascii) $id = utf8_strip($id); //clean up $id = preg_replace($sepcharpat,$sepchar,$id); $id = preg_replace('#:+#',':',$id); $id = trim($id,':._-'); $id = preg_replace('#:[:\._\-]+#',':',$id); $cache[$raw_id] = $id; return($id); } print "<pre>"; $query = "SELECT pageName, data FROM tiki_pages"; // LIMIT 1,10 WHERE page_id = '1' $link = mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error()); mysql_select_db("tikiwiki") or die("Could not select database"); $result = mysql_query($query) or die("Query failed : " . mysql_error()); $x = 0; while ($line = mysql_fetch_array($result)) { $x++; print $x . " " . $line['pageName'] . " ---> " .cleanID($line['pageName']) ."\n"; // Conversion from Tikiwiki 2 Dokuwiki syntax $line['data'] = str_replace("\r", "", $line['data']); $line['data'] = preg_replace('/^\* */m', " * ", $line['data']); // List $line['data'] = preg_replace('/^- */m', " * ", $line['data']); // List $line['data'] = preg_replace('/^# */m', " - ", $line['data']); // Numeroted list $line['data'] = preg_replace('/\[(.*?)\]/', "[[\\1]]", $line['data']); // Externals links $line['data'] = preg_replace('/\(\((.*?)\)\)/', "[[\\1]]", $line['data']); // Internals links $line['data'] = preg_replace("/^!!!(.+?)$/m", "==== \\1 ====", $line['data']); // Heading 3 $line['data'] = preg_replace("/^!!(.+?)$/m", "===== \\1 =====", $line['data']); // Heading 2 $line['data'] = preg_replace('/^!(.+?)$/m', "====== \\1 ======", $line['data']); // Heading 1 $line['data'] = preg_replace('/^-=(.+?)=-$/m', "====== \\1 ======", $line['data']); // Heading 1 $line['data'] = preg_replace('/( *: *)(?=====)/', " ", $line['data']); // Remove ":" from heading // table $line['data'] = preg_replace("/\[\[([^]]*)\|([^]]*)\]\]/m", "[[\\1__TEMP__\\2]]", $line['data']); // [[ | ]] -> [[ TEMP ]] to avoid conflict $line['data'] = preg_replace("/^\|\|$/m", "", $line['data']); // Remove "||" $line['data'] = preg_replace("/^\|\|/m", "", $line['data']); $line['data'] = preg_replace("/\|\|$/m", "", $line['data']); $line['data'] = preg_replace("/^([^|\n]+?\|[^\n]+?[^|\n])$/m", "|\\1|", $line['data']); // blabla | blabla $line['data'] = preg_replace("/^(\|)([^|\n]*?)$/m", "|\\2|", $line['data']); // | blabla $line['data'] = preg_replace("/^([^|\n]*?)(\|)$/m", "|\\1|", $line['data']); // blabla | $line['data'] = preg_replace("/\[\[([^]]*)__TEMP__([^]]*)\]\]/m", "[[\\1|\\2]]", $line['data']); // [[ TEMP ]] -> [[ | ]] // end of table conversion $line['data'] = preg_replace("/(\^)([^\^]*?)(\^)/", "<code>\\2</code>", $line['data']); // ^ -> <code> $line['data'] = preg_replace("!(~np~|~/np~)!", "", $line['data']); // remove ~np~ $line['data'] = preg_replace("/~~#[0-9A-F]+:([^~]*)~~/i", "\\1", $line['data']); // Remove color $line['data'] = preg_replace("/__(.*?)__/", "**\\1**", $line['data']); // Bold //$line['data'] = preg_replace("/([^\n=])\n( *[^\n])/", "\\1\\\\\\\\\n\\2", $line['data']); // not all emote are in dokuwiki $tikiwiki_emote = array("(:biggrin:)", "(:confused:)", "(:cool:)", "(:cry:)", "(:eek:)", "(:evil:)", "(:exclaim:)", "(:frown:)", "(:idea:)", "(:lol:)", "(:mad:)", "(:mrgreen:)", "(:neutral:)", "(:question:)", "(:razz:)", "(:redface:)", "(:rolleyes:)", "(:sad:)", "(:smile:)", "(:surprised:)", "(:twisted:)", "(:wink:)", "(:arrow:)"); $dokuwiki_emote = array(":-D" , ":-?" , "8-)", ":-(" , "8-O" , "8-)" , ":!:" , ":-(" , ":!:" , "LOL" , "8-O" , "8-)" , ":-|" , ":?:" , "^_^" , "" , "" , ":-(" , ":-)" , ":-O" , "^_^" , ";-)" , "->"); $line['data'] = str_replace($tikiwiki_emote, $dokuwiki_emote, $line['data']); $filename = dirname(__FILE__) . "/pages/" . cleanID($line['pageName']) . ".txt"; $handle = fopen($filename, "w+"); fwrite($handle, $line['data']); fclose ($handle); } mysql_free_result($result); mysql_close($link);
tips/tikiwiki2dokuwiki.1208432914.txt.gz · Last modified: 2014-02-25 22:04 (external edit)