Hope my script helps
Bart Q. Simon wrote:
Hello, very useful mailing list here.
Question:
Does anyone have a workable method for uploading multiple files (images in my case) to wiki? I have a ton of images and I'd like to set up a <gallery></gallery> with them, but doing it piecemeal just isn't going to work. I need to upload them as a batch (either by selecting all the images at once or selecting their parent folder).
The overall idea is that I'd like users to see a very large list of images, be able to click on any image, and then comment on it. It all seems workable except the part about actually getting the images into wiki and automatically building the gallery page :).
Is there php that would support this? Has anyone successfully added this data directly to mysql? I'm a little lost.
Thanks!
Bart
<html> <body> <?php /* Help the batch upload images from Dokuwiki to Mediawiki INspired from: 1 - mediawiki/include/specialUpload.php 2 - mediawiki/include/globalFunctions.php line 480 function wfImageDir( $fname )
You need: 1) to put all the image files in the same directory (no more sub directories). That means that you must rename your file who have the same names, to avoid any conflict. The best way is maybe to create a script which will add the subdirectories names to the image name. */ $filePathIn = "C:/Fxp/Prog/wikis/Mywiki/media"; $baseFileIn = "C:/Fxp/Prog/wikis/Mywiki/media"; $baseFileOut = "C:/apachefriends/xampp/htdocs/wikis/media4"; recurseAction($filePathIn);
function recurseAction($filePathIn){
global $baseFileIn,$baseFileOut;
$replace = false; $target = "db"; // file oder db $dh = opendir($filePathIn) or die("couldn't open directory");
while (!(($file = readdir($dh)) === false)) { if (is_dir("$filePathIn/$file") & (!(($file==".")|($file=="..")))) { print "<b>$file</b><br />\n"; print "<u>$filePathIn/$file</u><br />\n"; recurseAction("$filePathIn/$file"); }
elseif (is_file("$filePathIn/$file") & (!(($file==".")|($file=="..")))) { $fileName = "$file"; //$filePathIn = "C:/Fxp/Prog/wikis/Mywiki/media"; list($filename, $fileext) = explode(".", $fileName); $file = "$filePathIn/$file";
if ($fp = fopen($file, "r")) { $count++; //$baseName = basename($file);
$baseName = str_replace($baseFileIn."/","", $file); $baseName = str_replace('cib/', '', $baseName); $baseName = str_replace('/', ' ', $baseName); $baseName = preg_replace("/([a-z])([A-Z])/", "$1 $2", $baseName); $baseName = preg_replace("/([a-zA-Z])([\d])/", "$1 $2", $baseName); $baseName = preg_replace("/([\d])([a-zA-Z])/", "$1 $2", $baseName); $baseName = str_replace("_", " ", $baseName); $baseName = preg_replace("/([A-Z:])([A-Z][^A-Z])/", "$1 $2", $baseName); $baseName = ucwords($baseName); print "<i>$baseName</i>"; $baseName = str_replace(' ', '_', $baseName);
$hash = md5( $baseName ); $oldumask = umask(0); $wgUploadDirectory = 'C:/apachefriends/xampp/htdocs/wikis/mediawiki-1.3.9/images'; $dest = $wgUploadDirectory . '/' . $hash{0}; if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); } $dest .= '/' . substr( $hash, 0, 2 ); if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
$newfile= "$dest/$baseName"; $myfile= "$file"; copy($myfile, $newfile); echo "$newfile<br />";
$filename2 = preg_replace("/([a-z])([A-Z])/", "$1 $2", $filename); $filename2 = str_replace("_", " ", $filename2); $filename2 = preg_replace("/([A-Z:])([A-Z][^A-Z])/", "$1 $2", $filename2);
if (($target == "db")|($target == "both")){ // process form $db = mysql_connect("localhost", "root", "xxxxx"); $creator = "admin"; mysql_select_db("wikidb",$db); if ($replace){ $sql = "DELETE FROM tiki_pages WHERE pageName = '$baseName'"; $result = mysql_query($sql); $err = mysql_error(); printf("Erased: $baseName -- $err<br />\n"); } $sql = "INSERT INTO cur (cur_namespace, cur_title,cur_text, cur_timestamp) VALUES('6','$baseName','$filename2', now()+0)"; //echo = "Query: $result = mysql_query($sql); //$result = mysql_query($sql)or die(mysql_error()); $err = mysql_error(); printf("$count: $baseName...$err<br />\n"); }
elseif(($target == "file")|($target == "both")){ $outputDir = "/out2/"; $outputFile = ($outputDir . $baseName.".txt"); $out = fopen($outputFile, "w"); fwrite($out,$strFile); printf("$count: $baseName ...$err<br />\n"); }
}
} }
} ?> </body> </html>