Created
March 12, 2016 03:18
-
-
Save dccampbell/da49e243319b2f0374f3 to your computer and use it in GitHub Desktop.
Cleaned up version of http://johbuc6.coconia.net/mediawiki2dokuwiki.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getInput() { | |
return !empty($_POST['mediawiki']) ? $_POST['mediawiki'] : ''; | |
} | |
function convertSyntax() { | |
$mediawiki = getInput(); | |
if(empty($mediawiki)) return ''; | |
$replacements = array( | |
'^[ ]*=([^=])'=>'<h1> ${1}', '([^=])=[ ]*$'=>'${1} </h1>', | |
'^[ ]*==([^=])'=>'<h2> ${1}', '([^=])==[ ]*$'=>'${1} </h2>', | |
'^[ ]*===([^=])'=>'<h3> ${1}', '([^=])===[ ]*$'=>'${1} </h3>', | |
'^[ ]*====([^=])'=>'<h4> ${1}', '([^=])====[ ]*$'=>'${1} </h4>', | |
'^[ ]*=====([^=])'=>'<h5> ${1}', '([^=])=====[ ]*$'=>'${1} </h5>', | |
'^[ ]*======([^=])'=>'<h6> ${1}', '([^=])======[ ]*$'=>'${1} </h6>', | |
'<\/?h1>'=>'======', '<\/?h2>'=>'=====', '<\/?h3>'=>'====', '<\/?h4>'=>'===', '<\/?h5>'=>'==', '<\/?h6>'=>'=', | |
'^[\*#]{4}\* ?'=>' * ', '^[\*#]{3}\* ?'=>' * ', '^[\*#]{2}\* ?'=>' * ', '^[\*#]{1}\* ?'=>' * ', '^\* ?'=>' * ', | |
'^[\*#]{4}# ?'=>' \- ', '^[\*\#]{3}\# ?'=>' \- ', '^[\*\#]{2}\# ?'=>' \- ', '^[\*\#]{1}\# ?'=>' \- ', '^\# ?'=>' - ', | |
'([^\[])\[([^\[])'=>'${1}[[${2}', '^\[([^\[])'=>'[[${1}', '([^\]])\]([^\]])'=>'${1}]]${2}', '([^\]])\]$'=>'${1}]]', '(\[\[[^| \]]*) ([^|\]]*\]\])'=>'${1}|${2}', | |
"'''"=>"**", "''"=>"//", | |
"^[ ]*:"=>">", ">:"=>">>", ">>:"=>">>>", ">>>:"=>">>>>", ">>>>:"=>">>>>>", ">>>>>:"=>">>>>>>", ">>>>>>:"=>">>>>>>>", | |
"<pre>"=>"<code>", | |
"<br[^>]*>"=>"\\\\\\\\", | |
"<\/pre>"=>"<\/code>" | |
); | |
$dokuwiki = split("\r\n",stripslashes($mediawiki)); | |
if(!empty($dokuwiki)) { | |
foreach($replacements as $k=>$v){ | |
$dokuwiki = preg_replace('/'.$k.'/',$v,$dokuwiki); | |
} | |
} | |
return join("\r\n",$dokuwiki); | |
} | |
?><!DOCTYPE html> | |
<html> | |
<head><title>Mediawiki to Dokuwiki Converter</title></head> | |
<body> | |
<form action="" method="post"> | |
<div style="float:left; width: 49%;"> | |
<h2>Mediawiki:</h2> | |
<textarea name="mediawiki" style="min-height:400px; width:98%;"><?= getInput() ?></textarea> | |
</div> | |
<div style="float:left; width: 49%;"> | |
<h2>Dokuwiki:</h2> | |
<textarea name="dokuwiki" style="min-height:400px; width:98%; background-color:#F8F8F8" readonly><?= convertSyntax() ?></textarea> | |
</div> | |
<div style="clear:both;"> | |
<input type="submit" value="convert"> | |
</div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment