Extension talk:ImportUsers

About this board

Archived talk


Patching for a 1.37 version

2
Summary by Elcapitan68

Patch is created and merged.

Daviduclsop (talkcontribs)

I rely on this extension for periodically enrolling about 200 students into a wiki. I have now upgraded to wiki 1.37 from 1.31 and need this extension.

My understanding of the mediawiki processes involved and my PHP is not up to a complete repair but I can see what is wrong and have modified a version that will work.

ImportUsers is a relatively simple extension and has broken due to one method, user->setPassword(), being removed.

This is line 134 on the 1.37 download version with the single SpecialImportusers.php file. There is a second instance further down if the 'Replace existing users' option is used.

The maintenance script referred to below this comment is not really useful in that it does not add real name and email when creating the user. However it does set passwords.

The working script section for the password can be lifted from createAndPromote.php and pasted into the extension where it needs to set the password.

This will then use the correct mediawiki process to set the password.:The section starts at line 131 in my createAndPromote.php in the 1.37 maintenance folder.

I removed the try / catch section that checks the status return both for simplicity, complexity in displaying the errors and also because it is not so useful. It does not check for invalid passwords, only for those in the common password list such as 'pass'. Then if you catch the password, the account has already been created but with no password.

The status return can be used to add a warning that the account is created with no password. A similar message can added in replace users section.

Potential password errors can best be avoided by care in generating the csv file.

The modified script section in SpecialImportusers.php is as follows. There are no other files that need to be changed.

   # $nextUser->setPassword( $newuserarray[1] ); # comment out this line - this method has now been removed with the Authentication changes

   $password = $newuserarray[1];    # changing the variable for simplicity - single variable - more readable    

   $status = $nextUser->changeAuthenticationData( [ # Sets the password with correct default type :pbkdf2:

            'username' => $nextUser->getName(),

            'password' => $password,

            'retype' => $password,

     ] );

    # the try / catch block for status check of the password is removed.

    # The status error return is not very useful. It does not check invalid passwords only those on a list of common passwords.

    if ( !$status->isGood() ) { # warning message for password error

        $output .= '<br><b> The "'.$password.'" password for user '.$nextUser->getName().' is invalid. It belongs to the group of common passwords </b><br>The user has been created with no password. Use replace user option with valid password.<br>';

    }

   # so assume password correct - check input csv file to make sure - so no errors

   # followed by

   $nextUser->saveSettings(); # this writes the user details to the database


To use the 'replace existing users' option the setPassword() function needs to be replaced in the same way in the ''} elseif ( $replace_present ) {'' block, lower down.

It will generate the original error if this is not done and the option is selected.

Care needs to be taken that the password in the csv file is valid.

I have not used the add to groups. In fact in my version I have removed the option.

However, with the simple change implemented, the extension will work.

This is not a complete repair and so I am not adding it as a working extension.

Hopefully someone else can take this and add the error checking and replace the extension as a workable unit.

Bawolff (talkcontribs)

Cobbled together a replacement script with less than half the functionality

2
134.174.110.12 (talkcontribs)

if (($handle = fopen("accounts.csv", "r")) !== FALSE) {

   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

       $output = shell_exec('php maintenance\createAndPromote.php "'.$data[0].'" '.$data[1].' --force');

       $row++;

       echo $row . "\r\n";

       $output = shell_exec('php maintenance\resetUserEmail.php "'.$data[0].'" '.$data[2]);

       echo $output;

   }

   fclose($handle);


If you're in dire straits and can upload the csv file into the root mediawiki directory, the above script might help you.

Had some issues with the initial import not respecting the passwords in the file, --force was necessary before the passwords were respected.

134.174.110.12 (talkcontribs)

Missed a line in above script.


$row = 1;

if (($handle = fopen("accounts.csv", "r")) !== FALSE) {

   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

       $output = shell_exec('php maintenance\createAndPromote.php "'.$data[0].'" '.$data[1].' --force');

       $row++;

       echo $row . "\r\n";

       $output = shell_exec('php maintenance\resetUserEmail.php "'.$data[0].'" '.$data[2]);

       echo $output;

   }

   fclose($handle);

}

Reply to "Cobbled together a replacement script with less than half the functionality"
Sm8ps (talkcontribs)

It seems that this extension is no longer maintained and has become defunct. As a long-time user of it I have been looking from alternatives and found the following substitute using the API.

  1. Create a bot from an account that has administrative permissions.
  2. Use the API to ...
    • get a login token and log in.
    • retrieve an account create token.
    • create accounts with the information from a CSV file.

Using the samples for the API, I wrote a simple Python program that performs the related actions. It can be run from the client side.

The one thing missing is adding users to local groups which seemingly cannot be performed via the API. I did this manually for 25 users but the maintenance script createAndPromote.php looks like a promising alternative. however, it must be run on the server.

Hope this helps!

Reply to "Alternative: API"

Fatal exception of type "Error"

12
Wpinfold (talkcontribs)

I have a Mediawiki 1.35.4/Semantic Mediawiki 3.2.3 site and need to bring in 100 users. This looks like the perfect extension. I have been unable to make it work getting the error 'Fatal exception of type "Error"' when I bring in any CSV. Probably something I have missed - can someone suggest a path to fixing this?

Kghbln (talkcontribs)

You need to turn on error reporting and see what detailed error warning you are getting. Without this we do not have a chance to even point into a direction.

Anyhow chances are high that this extension no longer works. Admittedly my hobby coding knowledge is nowadays degraded towards 0 ability.

Wpinfold (talkcontribs)

Thank you this gave much better information

[0f3c6338f8756db35a0c151d] /Special:ImportUsers Error from line 134 of /var/www/html/extensions/ImportUsers/ImportUsers_body.php: Call to undefined method User::setPassword()


Backtrace:


#0 /var/www/html/extensions/ImportUsers/ImportUsers_body.php(40): SpecialImportUsers->analyzeUsers()

#1 /var/www/html/includes/specialpage/SpecialPage.php(600): SpecialImportUsers->execute()

#2 /var/www/html/includes/specialpage/SpecialPageFactory.php(635): SpecialPage->run()

#3 /var/www/html/includes/MediaWiki.php(307): MediaWiki\SpecialPage\SpecialPageFactory->executePath()

#4 /var/www/html/includes/MediaWiki.php(940): MediaWiki->performRequest()

#5 /var/www/html/includes/MediaWiki.php(543): MediaWiki->main()

#6 /var/www/html/index.php(53): MediaWiki->run()

#7 /var/www/html/index.php(46): wfIndexMain()

#8 {main}

Kghbln (talkcontribs)

I just realize that this is already tracked with task T135265.

Wpinfold (talkcontribs)

I am not trying to replace existing users just add new ones. I would be very happy to let extension set a temporary password and have the user change it when they log in. Is there a way to do that in the CSV file? What am I missing?

Kghbln (talkcontribs)

The extension in it's entirety appears to be broken, since the now removed method is called no matter what you do with it.

Wpinfold (talkcontribs)

Thanks for walking me through this. Is there another way to register a large number of users?

Kghbln (talkcontribs)

Ideally this extension needs to be fixed. There is the createAndPromote.php script which you can use to create accounts. It will require some work to do create a shell script to mass create but with a little help of a spreadsheet ...

Wpinfold (talkcontribs)

That is an excellent suggestion. I also need to set an email address so users could get a new password request. resetUserEmail.php did that so the two together did exactly what I needed. Thank you.

Kghbln (talkcontribs)

You are welcome. Glad that the way out worked. Still, getting this extension fixed will be cool.

Wpinfold (talkcontribs)

It would. My PHP is probably not up to the task but I will loop back and look at it when I have a moment. Seems like making the only option to create a temporary password should not be a huge amount of work but for me it would require some learning.

Kghbln (talkcontribs)

If time permits it will indeed be great. Sadly I have basically no PHP knowledge at all.

Reply to "Fatal exception of type "Error""

Internal Error: Fatal exception of type "LogicException"

1
115.66.216.75 (talkcontribs)

Hi,

I tried to import a .csv file of users but am facing this "Fatal exception of type "LogicException" and can't seem to figure out what is causing this. It was working for me previously, but am not sure why it doesn't seem to work anymore. Could you kindly advise?


Thank you.

Reply to "Internal Error: Fatal exception of type "LogicException""

Works fine in MW 1.31

1
Krabina (talkcontribs)

just tried the extension in MW 1.31 and everything works as expected.

Reply to "Works fine in MW 1.31"

Add user to existing group

3
JosefAssad (talkcontribs)

What does that option do? Is it correct that, if the option "Replace existing users" is selected, then selecting the option "Add user to existing group" will add any groups in the input file to the user which the user is NOT already a member of? And corresponding, if the option "Replace existing users" is selected, then the option "Add user to existing group" is '''not''' selected, then any extra groups in the input file which the user is not already a member of will be ignored?

Thanks!

Kghbln (talkcontribs)

I will have to test this. This was a feature added along the way. If you tick "Replace existing users" I would expect that the current record in the database gets overwritten by whatever there is in the import file. So the option "Add user to existing group" should have any effect.

Krabina (talkcontribs)

I just tested this. If the option "Add user to existing group" is not checked, then user groups don't get set even if they are included in the CSV. So to set user groups, you have to check the option.

Reply to "Add user to existing group"

Problem when trying to add invalid characters.

1
AJ Quick (talkcontribs)

When trying to add characters that are in violation of the $wgLegalTitleChars the program doesn't error out or skip the input gracefully, but instead crashes and doesn't provide meaningful output.

Common error:

[XDmdMwNiX64pb2H-OgFOtQAAAAk] /wiki/Special:ImportUsers Error from line 129 of /home/xxxx/public_html/w/extensions/ImportUsers/ImportUsers_body.php: Call to a member function setEmail() on boolean
Reply to "Problem when trying to add invalid characters."

What if I want them to get a temporary password by email?

2
79.182.137.171 (talkcontribs)

Instead of choosing a password on their behalf.

Kghbln (talkcontribs)

This would indeed be a nice feature but this extension cannot do this currently. If you are a programmer an would like to pick this up I am all for it.

Reply to "What if I want them to get a temporary password by email?"

Bug for username with special characters

2
Dieudo (talkcontribs)

A bug has been identified when using usernames such as :

  • André
  • Jérémy

The user appears in the user list but doesn't seem to be recognised elsewhere like for the userpage. It becomes then possible to create an other user with the same name through the ordinary way, making appearing two users with the same name in the user list.

My configuration is MW 1.23.2

Kghbln (talkcontribs)

Thanks for reporting this issue. I filed it as task T118184 so it does not get lost.

Reply to "Bug for username with special characters"
Return to "ImportUsers" page.