Extension talk:UploadCSV

Excellent! How far away do you think this extension is before ready? I was about to write exactly this same functionality but thought I better check what's available ;-) I was going to use it to importing spreadsheet information with time information added using Extension:When so that DPL queries could be used to select by account and time period etc. --Nad 11:40, 1 May 2007 (UTC)
 * Could the delimeter used be a global variable instead of fixed to semicolon? --Nad 11:46, 1 May 2007 (UTC)
 * Hi Nad, actually it is working, so I will supply a link with the source code these days. --GunterS 18:00, 2 May 2007 (UTC)
 * Excellent! thanks a lot ;-) --Nad 21:49, 2 May 2007 (UTC)

List of changes I've made
I'm testing it at www.wikifs.org/Special:UploadCSV, here's a list of the changes I've made during the process of getting it to function and also some extra features:
 * (diff) Need to use $wgRequest->getFileTempname to access uploaded data
 * (diff) Form needs enctype="multipart/form-data" for data to be uploaded
 * (diff) File reads were reading 4096 bytes, changed from fgets to fscanf to read one text-line at a time (not quite working yet)
 * (diff) Changed the template text-input into a dropdown list of all the templates
 * (diff) Allow separator to be set in form, also allows escaping separator in content (e.g. \;).
 * I noticed the header file-read was also getting 4096 bytes, so changed to read a single line
 * I also temporarily changed the form here, but it's chanegd back again now
 * (diff) Removed the update of the client-side form info from inside main row-processing loop
 * (diff) Made loop process from start-line to end-line and then update the form ready for another block of same size
 * (diff) The tmp file needs to be moved if we want to continue processing it without re-uploading (currently the moved files are not deleted)
 * (diff) Moved upload button into second column of table
 * (diff) Simplified main work loop: LoadTemplate seems redundant.
 * (diff) Changed back to fgets, omitting second parameter reads a single line (since PHP4.3)
 * --Nad

Problems

 * Uploaded files are never deleted currently - maybe add an expiry time?

Error: File not found.
Hi GunterS
 * When I used this extension I got a massage "Error: File not found.". But I had checked some things as followed.
 * Setting Localsetting.php with

$wgEnableUploads = true; $wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'mpg', 'mm', 'doc', 'txt', 'csv' );
 * The name of template( To confirm the template name such as "classmate" and "template:classmate").
 * The location of .csv file (such as C:\classmate.csv).
 * changing the interface of Mediawiki from Zh-tw to En(English).
 * But it still didn't work. Are there anythings that I hadn't tryed? Please give me a hand.

Roc michael 15:38, 22 June 2007 (UTC)
 * 1) Win XP
 * 2) MediaWiki: 1.9.3
 * 3) The AppServ Open Project - 2.5.7 for Windows
 * 4) * Apache Web Server Version 2.2.3
 * 5) * PHP Script Language Version 5.1.6
 * 6) * MySQL Database Version 5.0.24a
 * I had fixed a number of bugs etc shown in the diff's above, but I don't think the code in the downloadable zip has been updated as Gunter hasn't been around for a while... maybe on holiday or something? but the local source Extension:UploadCSV/UploadCSV.php is up to date and functional but still very beta. --Nad 20:57, 22 June 2007 (UTC)
 * Thanks Nad. when I used the code written in Extension:UploadCSV/UploadCSV.php I got an error.
 * When I finished the uploading, the filed besides the "Upload file" bottom in the "Article creation and update with csv-file" page would show the follow massage.

D:\AppServ\www\testwiki/images/php5D.tmp
 * As you know, I use Windows system, so I change the code in line 104

$curUploadFile = "$wgUploadDirectory/".basename($tmp);
 * to

$curUploadFile = "$wgUploadDirectory\".basename($tmp);
 * Then I got the error like followed.

Parse error: parse error, unexpected T_STRING in D:\AppServ\www\testwiki\extensions\UploadCSV\UploadCSV.php on line 111
 * Please do me a favor.Roc michael
 * I think the slash should stay as it was because they're ok both ways, you need to double up all backslashes since they have special meaning in PHP, but even doubled up it will probably give the same error as when using the forward slash. What is the exact error and line number that's occuring with the unmodified code? --Nad 00:27, 23 June 2007 (UTC)
 * Thanks Nad. When I pressed the Upload file button with no any change code, the temporary file "such like php5D.tmp" generated in the correct location(D:\AppServ\www\testwiki\images), but there was no any new wiki pages to be generated and the Status still stay in "start".
 * The contents of upload file named classmate.csv are followed:

pagetitle;name;lastname Classmate_1;Michael;Chang Classmate_2;Mark_1;Wu Classmate_3;Mark_2;Wu Classmate_4;Mark_3;Wu Classmate_5;Mark_4;Wu Classmate_6;Mark_5;Wu Classmate_7;Mark_6;Wu
 * and the contents of Template:classmate in my wiki are followed:


 * Lastname:
 * Name:
 * Some times the webpage showed the massage like followed:

Finished, 3 articles have been created or updated.
 * But there weren't any new pages created in my wiki.
 * Could you tell me what's wrong ,please! Roc michael

It looks like you're using it in the right way, and it's working on the wikifs.org which I see you've had a look at, so it could be a windows-specific problem. I'll have a look at it again soon and see if I can see what's wrong. I'm writing another extension which will work very well with this one called SimpleDatabase which allows you to render lists of structured articles as a spreadsheet table which you can filter by date or transaction type etc --Nad 00:14, 24 June 2007 (UTC)
 * The one running on wikifs was not the current version, I updated it and had the same problem as you on your windows one. I found this minor bug which fixed it. I've updated the code on this wiki and on organicdesign, so give it a try now. Remember this extension is still very early in development so don't use it for anything important yet ;-) --Nad 01:14, 24 June 2007 (UTC)
 * Thank you Nad. You are very kind. I'v tried it. Generally It's works, but the result of running something different between the one on the http://www.wikifs.org and one of the results "the page title is Classmate_3" look like followed：

1182675138
 * But since you're writing another extension which function like this one "I guess the new extension will be more powerful then this one", I would like to wait to use it. By the way take care of yourself. It seems that you don't need to sleep. Roc michael
 * The new one isn't a replacement for this one, it compliments it - SimpleForms, Extension:When, DPL, SimpleDatabase and this extension will all work very well together. I don't need much sleep because I lead a very low-stress life, but thanks for your concern ;-) --Nad 11:44, 24 June 2007 (UTC)

It can't work with Chinese file
One column needs to be defined as "pagetitle". For example, what you see the followed: pagetitle;name;lastname 一;張;三 二;李;四 I see it as followed:
 * I tried this extension with English CSV files. It's OK! But when I use Chinese files "The files' name are all in English", I would get wrong pages or an error message.
 * First, when I use a CSV file with BIG5 encoding I would get some new wiki pages with wrong page names and contents.
 * However, when I use a CSV file with utf8 encoding, I will get an error message like followed:

or

Oh! Chinese is a very different language. Right? Could you give me a hand?Roc michael
 * Hi Nad, I'v found a way to import structured data using a xml file made by MS Word and Excel "forgive me, I am a softwares user not a programer" and I will share the way these days.Roc michael

Another Error: File not found
I've tried to install this on MW 1.10, and am having some issues. If I try to upload to a template that does not exist, I get the correct message "not template" or similar. If I have a template without variables, it says "novar" as the error. But when I do everything right (or I think so!) I get "File not found". The upload selection autofills to the space next to the upload button, but nothing seems to happen when I click "Upload".

So, I tried Nad's code from his test site, and I get a slightly different dialogue box....nothing happens. No error message, but I get an address for a temporary file (?) in my upload directory....Status says "Start". Nothing happens. On Nad's site the same thing occurs.

I am using MW 1.10, and test files are created on a Mac OS X machine with Firefox and in BBEdit or Excel as .csv files...delimiter is comma, but I've tried switching to ";" wihtout result.

Thanks in advance for any ideas. I really need this capability....and was thrilled Gunter had the extension started. --Johncn 18:20, 23 July 2007 (UTC)

Getting Webresponse.php errors
I'm getting these errors upon trying to install the UploadCSV extension:

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/tageye/domains/tageye.com/public_html/part1/extensions/UploadCSV/UploadCSV.php:485) in /home/tageye/domains/tageye.com/public_html/part1/includes/WebResponse.php on line 10

What did I do wrong?

Problem with Template loading (solved)
I add a problem with template pages fetching with the last version on SVN(the combo box was empty, and I had the error  "mysql_fetch_array: supplied argument is not a valid MySQL result resource in /var/www/mw/extensions/UploadCSV/UploadCSV.php on line 77" ).

I changed line 77 of UploadCSV.php from

while ($row = mysql_fetch_array($result)) { to while ($row = mysql_fetch_array($result->result)) { and it worked fine. If this can help anyone... :)

-- Gizmhail 14:41, 11 January 2008 (UTC)