Permalink
Browse files

php2media wiki conversion tool

  • Loading branch information...
0 parents commit 129435cfeb9bc00ee282d26735456a8933d7a15e @cosimo committed Jan 20, 2011
Showing with 149 additions and 0 deletions.
  1. +42 −0 PhpWikiToMediaWikiManual.phpwiki
  2. +38 −0 README
  3. +69 −0 phpwiki2mediawiki.php
@@ -0,0 +1,42 @@
+! PhpWikiToMediaWikiManual
+
+!! Introduction
+
+This tool can help you quickly convert a phpwiki page into a mediawiki page.
+It's not a batch tool, but it can assist you build one.
+
+!! Requirements
+
+It requires php5 to run.
+Usually the =php5-cli= package is all you need.
+
+<verbatim>
+sudo aptitude install php5-cli
+</verbatim>
+
+!! How it works
+
+It reads the phpwiki page content from STDIN, and outputs the content converted
+to mediawiki format to STDOUT.
+
+!!! Example
+
+<verbatim>
+$ php5 ./phpwiki2mediawiki.php < Sample.phpwiki > Sample.mediawiki
+</verbatim>
+
+No additional format checks are done.
+If the format is not phpwiki, then you're basically screwed.
+It helped me at least.
+
+Good luck!
+
+!! Where does this come from?
+
+It comes from another phpwiki-to-mediawiki conversion tool I've seen
+on the Internetz, plus a few more bonus fixes thrown in.
+Here's the original source of inspiration:
+
+http://www.webforce.co.nz/phpwiki2mediawiki.php.txt
+
+
@@ -0,0 +1,38 @@
+phpwiki2mediawiki
+=================
+
+= Introduction =
+
+This tool can help you quickly convert a phpwiki page into a mediawiki page.
+It's not a batch tool, but it can assist you build one.
+
+== Requirements ==
+
+It requires php5 to run.
+Usually the =php5-cli= package is all you need.
+
+ sudo aptitude install php5-cli
+
+== How it works ==
+
+It reads the phpwiki page content from STDIN, and outputs the content converted
+to mediawiki format to STDOUT.
+
+=== Example ===
+
+ $ php5 ./phpwiki2mediawiki.php < Sample.phpwiki > Sample.mediawiki
+
+No additional format checks are done.
+If the format is not phpwiki, then you're basically screwed.
+It helped me at least.
+
+Good luck!
+
+== Where does this come from? ==
+
+It comes from another phpwiki-to-mediawiki conversion tool I've seen
+on the Internetz, plus a few more bonus fixes thrown in.
+Here's the original source of inspiration:
+
+http://www.webforce.co.nz/phpwiki2mediawiki.php.txt
+
@@ -0,0 +1,69 @@
+<?php
+
+ //
+ // Original version from:
+ //
+ // http://www.webforce.co.nz/phpwiki2mediawiki.php.txt
+ //
+
+ $phpwiki_content = file_get_contents('php://stdin');
+
+ // Add a newline to make pattern matching easier
+ $t = "\n" . $phpwiki_content . "\n";
+
+ // Convert !!!foo to === foo ==
+ $t = preg_replace("/\n!!!\s*(.*?)(\r?\n)/","\n== $1 ==$2",$t);
+ $t = preg_replace("/\n!!\s*(.*?)(\r?\n)/","\n=== $1 ===$2",$t);
+ $t = preg_replace("/\n!\s*(.*?)(\r?\n)/","\n==== $1 ====$2",$t);
+
+ // Convert %%% to newline
+ $t = preg_replace("/%%%/","<br>",$t);
+
+ // Convert strong (__)
+ $t = preg_replace("/__([^\n]+?)__/","'''$1'''",$t);
+
+ // Convert em
+ $t = preg_replace("/_([^\n]+?)_/","''$1''",$t);
+
+ // Convert strong
+ $t = preg_replace("/\*([^\n]+?)\*/","'''$1'''",$t);
+
+ // Convert <verbatim> to <nowiki>
+ $t = preg_replace("/<verbatim>(.*?)<\/verbatim>/s","<pre>$1</pre>",$t);
+
+ // Convert definitions
+ $t = preg_replace("/\n(.*?):\s*?\n\s{2,}([^\s]*?)/","\n; $1 : $2",$t);
+
+ // Convert single indents
+ $t = preg_replace("/\n {2,}([^\s]*?)/","\n: $1",$t);
+
+ // Convert WikiWord to [[WikiWord]]
+ $t = preg_replace("/(?<![[:alnum:]])((?:[[:upper:]][[:lower:]]+){2,})(?![[:alnum:]])/","[$1]",$t);
+
+ // Convert [[WikiWord]] to [[Wiki Word]]
+ $t = preg_replace("/(\[.*?[[:lower:]])([[:upper:]].*?\])/","$1 $2",$t);
+
+ // Convert [foo] to [[foo]]
+ $t = preg_replace("/\[([^|]+?)\]/","[[$1]]",$t);
+
+ // Convert http://foo to [http://foo]
+ //$t = preg_replace("/(\s*)([a-z]+:\/\/[^\s]+)/","$1[$2]",$t);
+
+ // Convert [[http://foo]] to [http://foo]
+ $t = preg_replace("/\[\[([a-z]+:\/\/.+?)\]\]/","$1",$t);
+
+ // Convert links [Foo|http://foo] to [http://foo foo]
+ $t = preg_replace("/\[([^|\n]+?) *\| *(.+?) *\]/","[$2 $1]",$t);
+
+ // Convert links [[http://foo foo]] to [http://foo foo]
+ $t = preg_replace("/\[\[([a-z]+:\/\/.+?\s+.+?)\]\]/","[$1]",$t);
+
+ // Convert
+ //$t = preg_replace("//","",$t);
+
+ // Strip the first newline
+ $t = substr($t,1);
+
+ echo $t;
+?>
+

0 comments on commit 129435c

Please sign in to comment.