16 private $userGroupManager;
23 return [
'services',
'extension-tables' ];
27 return [
'created-user-names' ];
32 $status = $this->createUser( $this->
getOption(
'AdminName' ) );
33 $createdUserNames = [];
34 if ( $status->isOK() && $status->value !==
null ) {
35 $createdUserNames[] = $status->value;
37 $this->
getContext()->provide(
'created-user-names', $createdUserNames );
41 private function createUser( $name ) {
42 $user = $this->userFactory->newFromName( $name );
46 return Status::newFatal(
'config-admin-error-user', $name );
49 if ( $user->idForName() == 0 ) {
50 $user->addToDatabase();
52 $password = $this->getOption(
'AdminPassword' );
53 $status = $user->changeAuthenticationData( [
54 'username' => $user->getName(),
55 'password' => $password,
56 'retype' => $password,
58 if ( !$status->isGood() ) {
59 return Status::newFatal(
'config-admin-error-password',
60 $name, $status->getWikiText(
false,
false, $this->getOption(
'UserLang' ) ) );
63 $this->userGroupManager->addUserToGroup( $user,
'sysop' );
64 $this->userGroupManager->addUserToGroup( $user,
'bureaucrat' );
65 $this->userGroupManager->addUserToGroup( $user,
'interface-admin' );
66 if ( $this->getOption(
'AdminEmail' ) ) {
67 $user->setEmail( $this->getOption(
'AdminEmail' ) );
69 $user->saveSettings();
72 $ssUpdate = SiteStatsUpdate::factory( [
'users' => 1 ] );
73 $ssUpdate->doUpdate();
75 return Status::newGood( $user->getName() );
78 return Status::newGood();
81 private function initServices( MediaWikiServices $services ) {
82 $this->userFactory = $services->getUserFactory();
83 $this->userGroupManager = $services->getUserGroupManager();