Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
23.08% covered (danger)
23.08%
6 / 26
22.22% covered (danger)
22.22%
2 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialCreateLocalAccount
23.08% covered (danger)
23.08%
6 / 26
22.22% covered (danger)
22.22%
2 / 9
45.87
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 doesWrites
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDisplayFormat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 preHtml
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getFormFields
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 onSubmit
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 onSuccess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CentralAuth\Special;
4
5use MediaWiki\Extension\CentralAuth\User\CentralAuthForcedLocalCreationService;
6use MediaWiki\Extension\CentralAuth\Widget\HTMLGlobalUserTextField;
7use MediaWiki\SpecialPage\FormSpecialPage;
8use MediaWiki\Status\Status;
9
10/**
11 * Special page that can be used to manually create a local account for a global account.
12 *
13 * @author Taavi "Majavah" Väänänen
14 * @ingroup SpecialPage
15 * @since 1.36
16 */
17class SpecialCreateLocalAccount extends FormSpecialPage {
18
19    private CentralAuthForcedLocalCreationService $forcedLocalCreationService;
20
21    public function __construct( CentralAuthForcedLocalCreationService $forcedLocalCreationService ) {
22        parent::__construct( 'CreateLocalAccount', 'centralauth-createlocal' );
23        $this->forcedLocalCreationService = $forcedLocalCreationService;
24    }
25
26    /**
27     * @return bool
28     */
29    public function doesWrites() {
30        return true;
31    }
32
33    /**
34     * @return string
35     */
36    protected function getGroupName() {
37        return 'users';
38    }
39
40    /**
41     * @return string
42     */
43    protected function getDisplayFormat() {
44        return 'ooui';
45    }
46
47    protected function preHtml() {
48        return $this->msg( 'centralauth-createlocal-pretext' )->parse();
49    }
50
51    /** @inheritDoc */
52    public function execute( $par ) {
53        $this->requireNamedUser();
54        $this->checkPermissions();
55
56        $this->addHelpLink( 'Help:Extension:CentralAuth/CreateLocalAccount' );
57
58        parent::execute( $par );
59    }
60
61    /**
62     * @return array[]
63     */
64    public function getFormFields() {
65        return [
66            'username' => [
67                'class' => HTMLGlobalUserTextField::class,
68                'name' => 'target',
69                'label-message' => 'centralauth-createlocal-username',
70            ],
71            'reason' => [
72                'type' => 'text',
73                'label-message' => 'centralauth-createlocal-reason',
74            ]
75        ];
76    }
77
78    /**
79     * @param array $data
80     * @return Status
81     */
82    public function onSubmit( array $data ) {
83        $username = $data['username'];
84        $reason = $data['reason'];
85
86        return $this->forcedLocalCreationService
87            ->attemptAutoCreateLocalUserFromName( $username, $this->getUser(), $reason );
88    }
89
90    public function onSuccess() {
91        $this->getOutput()->addWikiMsg( 'centralauth-createlocal-success' );
92    }
93}