Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikimediaIncubatorSecondaryAuthenticationProvider
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getAuthenticationRequests
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 beginSecondaryAuthentication
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 beginSecondaryAccountCreation
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace MediaWiki\Extension\WikimediaIncubator;
4
5use MediaWiki\Auth\AbstractSecondaryAuthenticationProvider;
6use MediaWiki\Auth\AuthenticationRequest;
7use MediaWiki\Auth\AuthenticationResponse;
8use MediaWiki\Auth\AuthManager;
9use MediaWiki\User\Options\UserOptionsManager;
10
11/**
12 * If URL parameters "testwikiproject" and "testwikicode" are set
13 * on account creation form, set them as user preference.
14 * This can be used to work with links on other sites
15 * referring to the account creation form so users don't *have* to
16 * change their preferences (automatically is always better :p)
17 */
18class WikimediaIncubatorSecondaryAuthenticationProvider
19    extends AbstractSecondaryAuthenticationProvider {
20
21    /** @var UserOptionsManager */
22    private $userOptionsManager;
23
24    /**
25     * @param UserOptionsManager $userOptionsManager
26     * @param array $params
27     */
28    public function __construct( UserOptionsManager $userOptionsManager, $params = [] ) {
29        $this->userOptionsManager = $userOptionsManager;
30    }
31
32    public function getAuthenticationRequests( $action, array $options ) {
33        if ( $action === AuthManager::ACTION_CREATE ) {
34            return [ new WikimediaIncubatorAuthenticationRequest ];
35        }
36
37        return [];
38    }
39
40    public function beginSecondaryAuthentication( $user, array $reqs ) {
41        return AuthenticationResponse::newAbstain();
42    }
43
44    public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
45        global $wmincPref;
46
47        $req = AuthenticationRequest::getRequestByClass(
48            $reqs, WikimediaIncubatorAuthenticationRequest::class
49        );
50
51        if ( $req ) {
52            '@phan-var WikimediaIncubatorAuthenticationRequest $req';
53            $this->userOptionsManager->setOption( $user, $wmincPref . '-project', $req->testwikiproject );
54            $this->userOptionsManager->setOption( $user, $wmincPref . '-code', $req->testwikicode );
55            $this->userOptionsManager->saveOptions( $user );
56        }
57
58        return AuthenticationResponse::newPass();
59    }
60}