Extension talk:ImportUsers/Archive

Version 0.0.3

 * Blank line handling corrected (used to produce error message)
 * Added "UTF-8" to upload control label to suggest that import file should be UTF-8 encoded

Version 0.0.2

 * Initial public release

Compatible with Version 1.8.2
Hi, I wanted to know if this Extension is also working with MediaWiki 1.8.2.

Please contact me: claudia.oswald@gmail.com

THX

Tested with 1.10 - OK!

 * a single test on a siteground hosted site. - works fine -
 * needed to make the minor fix to the message that displays the data format (see below).

Added features to code - only tested with 1.9.3
I added some functionality to this version - and don't know whether I should post as new or just let the original authors decide. These features allow users to be imported, notified, and automatically assigned to groups as they are loaded. --Jpond 22:16, 27 March 2007 (UTC)

The additional features are:


 * 1) Gives option to send email notifying added users as they are imported (if notification is enabled on wiki)
 * 2) Add user to specified group when adding if box is checked

For imported user to be added to a group the following must be true:


 * 1) Logged on user importing must have 'userrights'
 * 2) The user must have checked the "Add users to groups" box
 * 3) The CSV line must have a group to add to(e.g. approved)
 * 4) The permission requested must be one of the available groups - does not create a new group
 * 5) The user has not already been assigned to that group

If you wanted to add the user(s) to more than one group, you could rerun the import after changing the group in the CSV file, then use the 'Update existing users' checkbox.

The CSV now has up to five columns (first 2 required):


 * 1) username
 * 2) password
 * 3) email
 * 4) real name
 * 5) add to this group [must be existing group]

Delimited with commas. For an example:

user1,pass1,user1@gmail.com,User One, Group 1 user2,pass2,user2@gmail.com,User Two, Group 2 user3,pass3,user3@gmail.com,User Three, Group 3 user4,pass4,user4@gmail.com,User Four, Group 4 user5,pass5,user5@gmail.com,User Five, Group 5 user6,pass6,user6@gmail.com,User Six, Group 6 . . . userN,passN,userN@gmail.com,User Nnn, Group nnn

New, Modified Code - Tested on MediaWiki V 1.9.3
See below for a complete remastering of the code which integrates the changes presented here.

--Jpond 23:11, 27 March 2007 (UTC)

';     $output.=' '; $output.=' '; return $output; }

function AnalizeUsers($fileinfo,$replace_present,$importusers_send_email,$importusers_add_to_group) { global $IP, $wgOut, $wgEmailAuthentication ;
 * 1) Jack D. Pond added global $wgEmailAuthentication

require_once "$IP/includes/User.php"; $summary=array('all'=>0,'added'=>0,'updated'=>0,'email_sent'=>0,'email_failed'=>0);
 * 1) Jack D. Pond added email_sent and email_failed counters to array

$filedata=explode("\n",rtrim(file_get_contents($fileinfo['tmp_name']))); $output=' '.wfMsg( 'importusers_log' ).' '; foreach ($filedata as $line=>$newuserstr) { $newuserarray=explode(',', trim( $newuserstr ) ); if (count($newuserarray)<2) { $output.=sprintf(wfMsg( 'importusers_user_invalid_format' ) ,$line+1 ).' ';         continue; }       if (!IsSet($newuserarray[2])) $newuserarray[2]=''; if (!IsSet($newuserarray[3])) $newuserarray[3]=''; $NextUser=User::newFromName( $newuserarray[0] ); $NextUser->setEmail( $newuserarray[2] ); $NextUser->setRealName( $newuserarray[3] ); $uid=$NextUser->idForName; if ($uid===0) { $NextUser->addToDatabase; $NextUser->setPassword( $newuserarray[1] ); $NextUser->saveSettings; $this->AddToGroup($NextUser,$newuserarray,$importusers_add_to_group); if( $wgEmailAuthentication && $importusers_send_email && User::isValidEmailAddr( $NextUser->getEmail ) ) {				global $wgOut; $error = $NextUser->sendConfirmationMail; if( WikiError::isError( $error ) ) {					$output.=sprintf(wfMsg( 'importusers_user_invalid_email' ) ,$line+1 ).' ';					$summary['email_failed']++; } else {					$summary['email_sent']++; }			}         $output.=sprintf(wfMsg( 'importusers_user_added' ) ,$newuserarray[0] ).' ';         $summary['added']++; }       else { if ($replace_present) { $NextUser->setPassword( $newuserarray[1] ); $NextUser->saveSettings; $this->AddToGroup($NextUser,$newuserarray,$importusers_add_to_group); $output.=sprintf( wfMsg( 'importusers_user_present_update' ) ,$newuserarray[0] ).' ';           $summary['updated']++; }         else $output.=sprintf(wfMsg( 'importusers_user_present_not_update' ) ,$newuserarray[0] ).' ';       }        $summary['all']++; }     $output.=''.wfMsg( 'importusers_log_summary' ).' ';     $output.=wfMsg( 'importusers_log_summary_all' ).': '.$summary['all'].' ';     $output.=wfMsg( 'importusers_log_summary_added' ).': '.$summary['added'].' ';     $output.=wfMsg( 'importusers_log_summary_updated' ).': '.$summary['updated'].' ';     $output.=wfMsg( 'importusers_log_summary_email_sent' ).': '.$summary['email_sent'].' ';     $output.=wfMsg( 'importusers_log_summary_email_failed' ).': '.$summary['email_failed']; return $output; }
 * 1) Added line to import user group assignment too
 * 1) Extended by Jack D. Pond to send email notifications to users (if enabled)
 * 1) May want to delete here to end of extend if not using email addresses in import
 * 1) End Extend
 * 1) Added line to import user group assignment too
 * 1) Extended by Jack D. Pond to inform importer if any email addresses didn't check out
 * 1) Extension end

function AddToGroup($u,$user_array,$add_to_group_checked){ global $wgOut, $wgUser; if( $wgUser->isAllowed( 'userrights' ) && $add_to_group_checked && IsSet($user_array[4])) { if ( in_array($user_array[4],User::getAllGroups)){ if ( !in_array($user_array[4],$u->getGroups)){ $u->addGroup( $user_array[4] ); }			}		}	} }
 * 1) Extension by Jack D. Pond that adds imported user to the group in the last parameter in the line (4)
 * 2) under the following conditions:
 * 3) Logged on user importing must have 'userrights'
 * 4) The user must have checked the "Add users to groups" box
 * 5) The CSV line must have a group to add to(e.g. approved)
 * 6) The permission requested must be one of the available groups - does not create a new group
 * 7) The user has not already been assigned to that group
 * 1) The user has not already been assigned to that group

SpecialPage::addPage (new SpecialImportUsers); }

?>

Added Bonus - MS Excel Template for creating CSV with password generator
This [[Media:ImportCSV with Password Generator.xls| password generator]] might be of use to others.

The second tab is a template for creating csv file using MS Excel. You would use this template and use the file->save as->type=(.csv). Gives a couple of funky messages - but you'll be able to figure those out.

The first tab will actually generate random (or at least as random as MS Excel will allow) passwords. Code is signed.

Hope this helps someone else out. --Jpond 01:29, 29 March 2007 (UTC)

Minor Code Edit
The line: $output.='User file format (csv): &amp;lt;login-name&amp;gt;,&amp;lt;password&amp;gt;,&amp;lt;email&amp;gt;,&amp;lt;real-name&amp;gt;'; was being rendered as: $output.='User file format (csv): ,, ,'; which, when copy-pasted out, was causing the user file format to appear as ",,," on the Special:ImportUsers page. I edited it to read: $output.='User file format (csv): </dt>&amp;amp;lt;login-name&amp;amp;gt;,&amp;amp;lt;password&amp;amp;gt;,&aamp;mp;lt;email&amp;amp;gt;,&amp;amp;lt;real-name&amp;amp;gt;</dd></dl>'; so it would render correctly when copy-pasted.

--Swalsh 23:31, 15 May 2007 (UTC)

Header information already sent bug. (WM 1.11) Solved
My mediawiki 1.11 gives errors:

Warning: Cannot modify header information - headers already sent by (output started at
 * /wiki/extensions/ImportUser/SpecialImportUser.php:1) in
 * /wiki/includes/WebResponse.php on line 10

Could not find anything relating to this warning... I know production servers have warnings mostly disabled, but imho good script should never yeld warnings.

Anybody suggestions?

Kaspera 12:10, 22 October 2007 (UTC)


 * Solved after reading this article about a byte-order mark issue. This solved many other issues with headers already sent. Hope this helps other a lot of headache! Kaspera 09:25, 27 November 2007 (UTC)

Problem running with MW 1.11.0
I copied the code from the extension page, and followed the installation instructions. I run and get the error below.

The website cannot display the page HTTP 500 Most likely causes: * The website is under maintenance. * The website has a programming error.

I checked the logs, but there are no details there. Any suggestions on how to fix this?

TIA Alex Abramov (alexa at avid-tech dot com)

Version Info: MediaWiki: 1.11.0 PHP: 5.2.3 (cgi-fcgi) MySQL: 5.0.24-community-nt

Problems with 1.12 final
I have an incompatibility with my MW 1.12 final version. When I require the ImportUsers extension, my MediaWiki crashes every time, showing only a blank page. I verified the path... I don't think the problem is on my side.--Rmatt 17:14, 21 March 2008 (UTC)

Same here, it looks for ExtensionFunctions.php, does not find it and aborts. fix it by putting http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/ExtensionFunctions.php into your Extensions folder. 193.175.73.201 14:28, 28 March 2008 (UTC)


 * Thanks, it solved the problem for me too !

Importing with password field containing a comma
--Hiloboys 15:44, 11 August 2009 (HST)

Media Wiki: 1.14.0

It works great, but I ran into this 1 problem which I think probably is something easy to figure out I just have been banging my head against my table so much and have probably lost the basic brain cells that contain the answer.

Id say about 3/4 of my users have a comma in their assigned password they been using for years. (yes cant make em change it without confusing 1000s of them and getting tons of tech support emails.) and as you know having a comma in CSV format is just like telling it to move to the next block or field.

Normally I would use username,"example,password",email,name which would normally fix the cell when using CSV format. However, when I try to do this, there is still no avail and ceases to function properly.

The account is create and is added to my database, however when trying to log in using the password containing the comma, it will say incorrect password. Ive tried over 10 times as many differ ways as I can think of.

Then I created an account using this method without the comma in the password and it worked just fine.

Using Excel saved in .csv format (Comma Delimited not mac or MS-DOS) Also tried in just plain .txt format with comma's separating each field.

Password cannot be equal to username
Media Wiki 1.13

I tried to batch enter a lot of usernames, and since I wanted something simple for password, I just entered the username a second time. Apparently this does not work, as when I changed the passwords to a different value, suddenly it worked. Ironically if I only had one record in my .csv file, it did work, but then did not work for more than one. Unfortunately this made me think it was something involved with my file format which it turns out was not the case.

Troubleshooting
I made my CVS file in Excel and the plugin didnt work cause the line break was '\r' and not '\n'. I edited the _body.php file and it worked perfect.

Installation
Works fine in MW 1.18 alpha, but the code in LocalSettings.php has to be (without the "Special") - or am I missing something? --TnEaM 16:40, 14 March 2011 (UTC)

I downloaded version fro MW 1.16 from Extension page linke, but was not able to get the posted require statement to work with MW 1.16. The error was that the script set was looking for a file named "SpecialImportUsers.php" instead of "ImportUsers.php". I changed the statement to this, and it worked:

Hope this helps. Should the main Extension Page for this tool be updated? I'm pretty much a yucker at coding, so changed main page, and then realized it may just be specific to my instance, so reverted and posted solution here. - Johncn (jconcilus@bssd.org)

Running 1.16 and the correct snapshot for that MW version. Mac users in our organization had issues with CSV files created in latest Excel. Only the first record would be imported. The rest were ignored. We suspected line break mismatches or encoding. The workaround for us was to open the file in BBEdit, and save it. This healed the file, and we used Line Breaks: Unix and Encoding Unicode UTF-8 setting under "Save As". Now works like a charm. - Johncn (jconcilus@bssd.org)

User Creation Log
This extension does not seem to make entries in the user creation log. Is this expected or is something broken in my installation? Would this functionality be hard to add?--John.james 03:10, 17 October 2010 (UTC)

Added Features
Mr. Pond posted a number of excellent added features in 2007. I see that this extension was updated a few months ago, but none of those features were added according to the Extension page. Do the developers have plans to add these features or to continue providing support for this extension? --Jlemley 05:53, 17 May 2011 (UTC)

Warning: Don't Quote Fields!
Although it's fairly standard in CSV files, placing double-quotes around your field values results in unexpected behavior with this extension: the double-quotes are treated as part of the value! (This likely also explains the problem reported above with passwords containing commas: since the double-quotes aren't honored, the comma in the password is treated as a delimiter even if you quoted the password.) Szarka (talk) 21:58, 17 March 2012 (UTC)

Works with MW 1.20.4
Works with MW 1.20.4, but you have to choose UTF-8 without BOM encoding. If you use UTF-8, the user was created, but I wasn't able to log in or assign some rights. The username in the database looks like this: ï»¿username. I don`t know if this is common knowledge out there, but it took me some time to figure it out, so I thought it might be helpful for some other newbie like me. :-) --Dadai12 14:23, 26 June 2013 (UTC)

Code remastering according to Jpond: add to group, notify by e-mail, MW-1.19
I could successfully integrate the above code by Jpond into the original extension. The additional features seem to work well so far on MediaWiki 1.19.7.

As an additional feature it is now possible to add users to several groups. All entries after the user name will be interpreted as groups to which the newly created user will be added. The groups are checked for existence so that such a mistake would not result in a fatal error.

I put the remastered code in a sub-page in order to keep things tidy around here. Please add comments here, especially if you found this code working on your particular version of MediaWiki.