#!/usr/local/bin/php cur_title, $not_pages)) { $title[$a] = $row->cur_title; $text[$a] = $row->cur_text; $a++; } } $dir = "mediawiki_pages"; if(file_exists($dir)){ rmdirr($dir); mkdir($dir); } else{ mkdir($dir); } chdir("./$dir") or die; $a = 0; while ($a < count($title)) { echo "$title[$a]\n"; $title[$a] = utf8_encode(str_replace(" ", "_", $title[$a])); $quoted = array(); $in_parenthesis = false; for ($i = 0; $i < strlen($title[$a]); $i++) { $curchar = substr ($title[$a], $i, 1); if (ereg('[^a-zA-Z0-9_]', $curchar)) { if (!$in_parenthesis) { $quoted[] = '('; $in_parenthesis = true; } $quoted[] = str_pad(dechex(ord($curchar)), 2, '0', STR_PAD_LEFT); } else { if ($in_parenthesis) { $quoted[] = ')'; $in_parenthesis = false; } $quoted[] = $curchar; } } if ($in_parenthesis) $quoted[] = ')'; $title[$a] = implode('', $quoted); unset($quoted); mkdir($title[$a]); chdir($title[$a]); $file = fopen("current", "w"); fputs($file, "00000001"); fclose($file); mkdir("revisions"); chdir("revisions"); $file = fopen("00000001", "w"); #break up one string into lines $file_text = explode("\n", $text[$a]); $file_text = change_syntax($file_text); $b = 0; while ($b < count($file_text)) { fputs($file, rtrim($file_text[$b]) . "\n"); $b++; } unset($file_text); fclose($file); chdir(".."); chdir(".."); $a++; } chdir(".."); ###End of Main function change_syntax ($textString) { #$a = 0; for($a = 0; $a < count($textString); $a++){ #print "str(before mod) = $textString[$a] \n"; #custom plugin #if(preg_match("/\.+\<\/fileshare\>/",$textString[$a])){ # $textString[$a] = fileShare($textString[$a]); #} #strpos : Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used. #substr() returns the portion of string specified by the start and length parameters. #string substr ( string string, int start [, int length] ) if(substr($textString[$a], 0, 1) == '*'){ $textString[$a] = bullets($textString[$a]); } if(preg_match("/^#/",$textString[$a])){ $textString[$a] = numberedList( $textString[$a]); } #headings if(preg_match("/^==.+==/",$textString[$a])){ $textString[$a] = heading( $textString[$a]); } #wikilink if(preg_match("/\[\[.+\]\]/",$textString[$a])){ $textString[$a] = wikiLinks($textString[$a]); } #media wiki new line or
#must be after wiki links if (preg_match("/\/i", $textString[$a])) { $textString[$a] = preg_replace("/\\/i", "[[BR]]",$textString[$a]); #print "result = $textString[$a]\n"; } } return $textString; } #custom plugin #function fileShare($string) { # $fileshare = substr($string, strpos($string, "\\\\")); # $fileshare = preg_replace("/<\/fileshare>/","",$fileshare); # $string = "[file:" .$fileshare ."]"; # return $string; #} function heading($string){ $theHeading = $string; $headingLevel = 0; #strip the left side '=' chars while($headingLevel < strlen($theHeading)){ if(substr($theHeading, 0, 1) == '='){ $theHeading = substr($theHeading, 1); } else{ #no more ='s in front of text break; } $headingLevel++; } #the left side '=' chars are now removed #now strip right side '=' chars $theHeading = substr($theHeading, 0, strpos($theHeading, '=')); $theSyntax = ""; #note moinmoin uses 1 less = for heading levels #so mediawiki "===" is the same as moinmoin "==" for($i = 1; $i < $headingLevel; $i++){ $theSyntax .= "="; } $string = $theSyntax ." $theHeading " .$theSyntax; return $string; } function bullets ($string) { $a = 0; while ($a < strlen($string)) { $a++; if (substr($string, 1, 1) == "*") $string = substr($string, 1); else break; } while ($a > 0) { $string = " " . $string; $a--; } return $string; } function numberedList ($string) { if(preg_match("/^#/",$string)){ $string = preg_replace("/^#/", " 1.", $string); } elseif(preg_match("/^##/",$string)){ $string = preg_replace("/^##/", " 1.", $string); } return $string; } function wikiLinks ($string) { global $WIKI_LINK_START; global $WIKI_LINK_END; while (strpos($string, "[[") !== false && strpos($string, "]]") !== false) { #isolate link $link = substr($string, strpos($string, "[[") + 2); $link = substr($link, 0, strpos($link, "]]") + 0); if (strpos($link, "|") == false){ #add new link syntax $link = $WIKI_LINK_START ."\"". $link ."\"" .$WIKI_LINK_END; } else{ $dividerPosition = strpos($link, "|"); $wikilink = substr($link, 0, $dividerPosition); $label = substr($link, $dividerPosition + 1, strlen($link) - $dividerPosition); #remove whitespace from beginning and end $label = trim($label); $link = $WIKI_LINK_START .":" .$wikilink .": " .$label .$WIKI_LINK_END; } $string = substr($string, 0, strpos($string, "[[") - 0) . $link .substr($string, strpos($string, "]]") + 2); } return $string; } function externalLinks($string){ global $EXTERNAL_LINK_START; global $EXTERNAL_LINK_END; global $EXTERNAL_LINK_DIVIDER; #external link syntax is the same except for the label divider if(preg_match("/| /")){ $string = preg_replace("/| /", " ", $string); } elseif(preg_match("/|/")){ $string = preg_replace("/|/", " ", $string); } return $string; } function rmdirr($dir) { if($objs = glob($dir."/*")){ foreach($objs as $obj) { is_dir($obj)? rmdirr($obj) : unlink($obj); } } rmdir($dir); } ?>