[Mediawiki-l] Re: batch image upload

FxParlant f-x.p at laposte.net
Fri Jan 6 09:24:11 UTC 2006


Hi Jan,

I just hoped that a new version of mediawiki would have this batch image
upload:
- I didn't see anything in CVS extensions
- did you check meta wikipedia category:extensions ?

Since february, mediawiki has evolved, and a new version (1.5), using a
different database structure has come up.

My file, I'm afraid is totally deprecated for this.

Then, this was to transfer media from another wiki (Dokuwiki) to
mediawiki: therefore a lot of lines in the script are caracters replacement.

HOW I USED IT

Actually, as I had to correct this file many times before succeeding,
- I simply installed apache, php, mysql on my computer.
- I installed the wiki in local mode
- Then, I exported the wikidatabase (dump) from my online site and I
imported it on my local database
- I ran the php file by just accessing it on my local server, and it
output all the details about what was ok and what was wrong
- If all was messed up, I deleted the local wikidatabase and reimported it
- When everything was ok, in the database and in the media folder, I
exported this local database and imported it on my online database
- Then I uploaded the media folder from local to online

This procedure, explains why the folder paths of my script are local
paths. And as it takes many errors to succeed, better do this
maintenance in local.

WARNING
My host uses what he considers as "stable" versions of mysql and php and
phpmyadmin. These version could be considered as oldish. I had to use
the same versions, because there was some uncompatibility in export and
import between two different versions of mysql.


I know this won't help you. Very Sorry.

FxParlant
(François)




Jan wrote:
> Hi Community,
> 
> this answer is related to an email from Feb 22, 2005 from FxParlant.
> 
> Full Email-Text in Archiv online:
> http://mail.wikipedia.org/pipermail/mediawiki-l/2005-February/003673.html
> 
> He postet a php-file to to a batchupload of images.
> 
> Now, I have to upload appr. 400 images to my Wiki; all images are in one
> Folder (and have different filenames).
> 
> I have access to my wiki my FTP, and to the database my phpMyAdmin or ODBC.
> 
> 1. Where I have to place the quoted php-File?
> 2. What I need to change in the Code of that file?
> 3. Is it compatible with MediaWiki 1.5.4 ?
> 
> Thanks for your attention,
> Jan
> 
> --------------------------------------------------
> 
> QUOTE: Code of the postet php-File:
> 
> <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>




More information about the MediaWiki-l mailing list