Add ability to override mb_strtoupper in Language::ucfirst
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
index d3efca6..93614e0 100644 (file)
@@ -31,7 +31,7 @@ require_once __DIR__ . '/Maintenance.php';
  * @ingroup Maintenance
  */
 class CreateAndPromote extends Maintenance {
-       private static $permitRoles = [ 'sysop', 'bureaucrat', 'bot' ];
+       private static $permitRoles = [ 'sysop', 'bureaucrat', 'interface-admin', 'bot' ];
 
        public function __construct() {
                parent::__construct();
@@ -66,7 +66,7 @@ class CreateAndPromote extends Maintenance {
                        $this->fatalError( "invalid username." );
                }
 
-               $exists = ( 0 !== $user->idForName() );
+               $exists = ( $user->idForName() !== 0 );
 
                if ( $exists && !$force ) {
                        $this->fatalError( "Account exists. Perhaps you want the --force option?" );
@@ -112,9 +112,16 @@ class CreateAndPromote extends Maintenance {
                }
 
                if ( !$exists ) {
-                       # Insert the account into the database
-                       $user->addToDatabase();
-                       $user->saveSettings();
+                       // Create the user via AuthManager as there may be various side
+                       // effects that are perfomed by the configured AuthManager chain.
+                       $status = MediaWiki\Auth\AuthManager::singleton()->autoCreateUser(
+                               $user,
+                               MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_MAINT,
+                               false
+                       );
+                       if ( !$status->isGood() ) {
+                               $this->fatalError( $status->getWikiText( null, null, 'en' ) );
+                       }
                }
 
                if ( $password ) {