Completed
Push — newinternal-releasecandidate ( 06bb07...1c5b59 )
by Simon
06:04
created
includes/ApplicationBase.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -25,155 +25,155 @@
 block discarded – undo
25 25
 
26 26
 abstract class ApplicationBase
27 27
 {
28
-    private $configuration;
29
-
30
-    public function __construct(SiteConfiguration $configuration)
31
-    {
32
-        $this->configuration = $configuration;
33
-    }
34
-
35
-    /**
36
-     * Application entry point.
37
-     *
38
-     * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
-     */
40
-    public function run()
41
-    {
42
-        try {
43
-            if ($this->setupEnvironment()) {
44
-                $this->main();
45
-            }
46
-        }
47
-        catch (Exception $ex) {
48
-            print $ex->getMessage();
49
-        }
50
-        finally {
51
-            $this->cleanupEnvironment();
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Environment setup
57
-     *
58
-     * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
-     * and shut down prematurely.
60
-     *
61
-     * @return bool
62
-     * @throws EnvironmentException
63
-     */
64
-    protected function setupEnvironment()
65
-    {
66
-        $this->setupDatabase();
67
-
68
-        return true;
69
-    }
70
-
71
-    /**
72
-     * @return PdoDatabase
73
-     * @throws EnvironmentException
74
-     * @throws Exception
75
-     */
76
-    protected function setupDatabase()
77
-    {
78
-        // check the schema version
79
-        $database = PdoDatabase::getDatabaseConnection('acc');
80
-
81
-        /** @var int $actualVersion */
82
-        $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
-        if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
-            throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
-        }
86
-
87
-        return $database;
88
-    }
89
-
90
-    /**
91
-     * @return SiteConfiguration
92
-     */
93
-    public function getConfiguration()
94
-    {
95
-        return $this->configuration;
96
-    }
97
-
98
-    /**
99
-     * Main application logic
100
-     * @return void
101
-     */
102
-    abstract protected function main();
103
-
104
-    /**
105
-     * Any cleanup tasks should go here
106
-     *
107
-     * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
-     * This should *only* be for cleaning up, no logic should go here.
109
-     *
110
-     * @return void
111
-     */
112
-    abstract protected function cleanupEnvironment();
113
-
114
-    /**
115
-     * @param ITask             $page
116
-     * @param SiteConfiguration $siteConfiguration
117
-     * @param PdoDatabase       $database
118
-     * @param PdoDatabase       $notificationsDatabase
119
-     *
120
-     * @return void
121
-     */
122
-    protected function setupHelpers(
123
-        ITask $page,
124
-        SiteConfiguration $siteConfiguration,
125
-        PdoDatabase $database,
126
-        PdoDatabase $notificationsDatabase = null
127
-    ) {
128
-        $page->setSiteConfiguration($siteConfiguration);
129
-
130
-        // setup the global database object
131
-        $page->setDatabase($database);
132
-
133
-        // set up helpers and inject them into the page.
134
-        $httpHelper = new HttpHelper(
135
-            $siteConfiguration->getUserAgent(),
136
-            $siteConfiguration->getCurlDisableVerifyPeer()
137
-        );
138
-
139
-        $page->setEmailHelper(new EmailHelper());
140
-        $page->setHttpHelper($httpHelper);
141
-        $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
-
143
-        if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
-            $page->setLocationProvider(new FakeLocationProvider());
145
-        }
146
-        else {
147
-            $page->setLocationProvider(
148
-                new IpLocationProvider(
149
-                    $database,
150
-                    $siteConfiguration->getLocationProviderApiKey(),
151
-                    $httpHelper
152
-                ));
153
-        }
154
-
155
-        $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
-
157
-        $page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
-
159
-        $page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
-            $database,
161
-            $this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
-            $httpHelper));
163
-
164
-        $page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
-            $siteConfiguration->getOAuthBaseUrl(),
166
-            $siteConfiguration->getOAuthConsumerToken(),
167
-            $siteConfiguration->getOAuthConsumerSecret(),
168
-            $httpHelper,
169
-            $siteConfiguration->getMediawikiWebServiceEndpoint()
170
-        ));
171
-
172
-        $page->setNotificationHelper(new IrcNotificationHelper(
173
-            $siteConfiguration,
174
-            $database,
175
-            $notificationsDatabase));
176
-
177
-        $page->setTorExitProvider(new TorExitProvider($database));
178
-    }
28
+	private $configuration;
29
+
30
+	public function __construct(SiteConfiguration $configuration)
31
+	{
32
+		$this->configuration = $configuration;
33
+	}
34
+
35
+	/**
36
+	 * Application entry point.
37
+	 *
38
+	 * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
+	 */
40
+	public function run()
41
+	{
42
+		try {
43
+			if ($this->setupEnvironment()) {
44
+				$this->main();
45
+			}
46
+		}
47
+		catch (Exception $ex) {
48
+			print $ex->getMessage();
49
+		}
50
+		finally {
51
+			$this->cleanupEnvironment();
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Environment setup
57
+	 *
58
+	 * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
+	 * and shut down prematurely.
60
+	 *
61
+	 * @return bool
62
+	 * @throws EnvironmentException
63
+	 */
64
+	protected function setupEnvironment()
65
+	{
66
+		$this->setupDatabase();
67
+
68
+		return true;
69
+	}
70
+
71
+	/**
72
+	 * @return PdoDatabase
73
+	 * @throws EnvironmentException
74
+	 * @throws Exception
75
+	 */
76
+	protected function setupDatabase()
77
+	{
78
+		// check the schema version
79
+		$database = PdoDatabase::getDatabaseConnection('acc');
80
+
81
+		/** @var int $actualVersion */
82
+		$actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
+		if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
+			throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
+		}
86
+
87
+		return $database;
88
+	}
89
+
90
+	/**
91
+	 * @return SiteConfiguration
92
+	 */
93
+	public function getConfiguration()
94
+	{
95
+		return $this->configuration;
96
+	}
97
+
98
+	/**
99
+	 * Main application logic
100
+	 * @return void
101
+	 */
102
+	abstract protected function main();
103
+
104
+	/**
105
+	 * Any cleanup tasks should go here
106
+	 *
107
+	 * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
+	 * This should *only* be for cleaning up, no logic should go here.
109
+	 *
110
+	 * @return void
111
+	 */
112
+	abstract protected function cleanupEnvironment();
113
+
114
+	/**
115
+	 * @param ITask             $page
116
+	 * @param SiteConfiguration $siteConfiguration
117
+	 * @param PdoDatabase       $database
118
+	 * @param PdoDatabase       $notificationsDatabase
119
+	 *
120
+	 * @return void
121
+	 */
122
+	protected function setupHelpers(
123
+		ITask $page,
124
+		SiteConfiguration $siteConfiguration,
125
+		PdoDatabase $database,
126
+		PdoDatabase $notificationsDatabase = null
127
+	) {
128
+		$page->setSiteConfiguration($siteConfiguration);
129
+
130
+		// setup the global database object
131
+		$page->setDatabase($database);
132
+
133
+		// set up helpers and inject them into the page.
134
+		$httpHelper = new HttpHelper(
135
+			$siteConfiguration->getUserAgent(),
136
+			$siteConfiguration->getCurlDisableVerifyPeer()
137
+		);
138
+
139
+		$page->setEmailHelper(new EmailHelper());
140
+		$page->setHttpHelper($httpHelper);
141
+		$page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
+
143
+		if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
+			$page->setLocationProvider(new FakeLocationProvider());
145
+		}
146
+		else {
147
+			$page->setLocationProvider(
148
+				new IpLocationProvider(
149
+					$database,
150
+					$siteConfiguration->getLocationProviderApiKey(),
151
+					$httpHelper
152
+				));
153
+		}
154
+
155
+		$page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
+
157
+		$page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
+
159
+		$page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
+			$database,
161
+			$this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
+			$httpHelper));
163
+
164
+		$page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
+			$siteConfiguration->getOAuthBaseUrl(),
166
+			$siteConfiguration->getOAuthConsumerToken(),
167
+			$siteConfiguration->getOAuthConsumerSecret(),
168
+			$httpHelper,
169
+			$siteConfiguration->getMediawikiWebServiceEndpoint()
170
+		));
171
+
172
+		$page->setNotificationHelper(new IrcNotificationHelper(
173
+			$siteConfiguration,
174
+			$database,
175
+			$notificationsDatabase));
176
+
177
+		$page->setTorExitProvider(new TorExitProvider($database));
178
+	}
179 179
 }
180 180
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleStart.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -15,74 +15,74 @@
 block discarded – undo
15 15
 
16 16
 class ConsoleStart extends ApplicationBase
17 17
 {
18
-    /**
19
-     * @var ConsoleTaskBase
20
-     */
21
-    private $consoleTask;
18
+	/**
19
+	 * @var ConsoleTaskBase
20
+	 */
21
+	private $consoleTask;
22 22
 
23
-    /**
24
-     * ConsoleStart constructor.
25
-     *
26
-     * @param SiteConfiguration $configuration
27
-     * @param ConsoleTaskBase   $consoleTask
28
-     */
29
-    public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
-    {
31
-        parent::__construct($configuration);
32
-        $this->consoleTask = $consoleTask;
33
-    }
23
+	/**
24
+	 * ConsoleStart constructor.
25
+	 *
26
+	 * @param SiteConfiguration $configuration
27
+	 * @param ConsoleTaskBase   $consoleTask
28
+	 */
29
+	public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
+	{
31
+		parent::__construct($configuration);
32
+		$this->consoleTask = $consoleTask;
33
+	}
34 34
 
35
-    protected function setupEnvironment()
36
-    {
37
-        // initialise super-global providers
38
-        WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
35
+	protected function setupEnvironment()
36
+	{
37
+		// initialise super-global providers
38
+		WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
39 39
 
40
-        if (WebRequest::method() !== null) {
41
-            throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
-        }
40
+		if (WebRequest::method() !== null) {
41
+			throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
+		}
43 43
 
44
-        return parent::setupEnvironment();
45
-    }
44
+		return parent::setupEnvironment();
45
+	}
46 46
 
47
-    protected function cleanupEnvironment()
48
-    {
49
-    }
47
+	protected function cleanupEnvironment()
48
+	{
49
+	}
50 50
 
51
-    /**
52
-     * Main application logic
53
-     */
54
-    protected function main()
55
-    {
56
-        $database = PdoDatabase::getDatabaseConnection('acc');
51
+	/**
52
+	 * Main application logic
53
+	 */
54
+	protected function main()
55
+	{
56
+		$database = PdoDatabase::getDatabaseConnection('acc');
57 57
 
58
-        if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
-            $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
-        }
61
-        else {
62
-            // pass through null
63
-            $notificationsDatabase = null;
64
-        }
58
+		if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
+			$notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
+		}
61
+		else {
62
+			// pass through null
63
+			$notificationsDatabase = null;
64
+		}
65 65
 
66
-        $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
66
+		$this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
67 67
 
68
-        // initialise a database transaction
69
-        if (!$database->beginTransaction()) {
70
-            throw new Exception('Failed to start transaction on primary database.');
71
-        }
68
+		// initialise a database transaction
69
+		if (!$database->beginTransaction()) {
70
+			throw new Exception('Failed to start transaction on primary database.');
71
+		}
72 72
 
73
-        try {
74
-            // run the task
75
-            $this->consoleTask->execute();
73
+		try {
74
+			// run the task
75
+			$this->consoleTask->execute();
76 76
 
77
-            if ($database->hasActiveTransaction()) {
78
-                $database->commit();
79
-            }
80
-        }
81
-        finally {
82
-            // Catch any hanging on transactions
83
-            if ($database->hasActiveTransaction()) {
84
-                $database->rollBack();
85
-            }
86
-        }
87
-    }
77
+			if ($database->hasActiveTransaction()) {
78
+				$database->commit();
79
+			}
80
+		}
81
+		finally {
82
+			// Catch any hanging on transactions
83
+			if ($database->hasActiveTransaction()) {
84
+				$database->rollBack();
85
+			}
86
+		}
87
+	}
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/RefreshOAuthDataTask.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -17,35 +17,35 @@
 block discarded – undo
17 17
 
18 18
 class RefreshOAuthDataTask extends ConsoleTaskBase
19 19
 {
20
-    public function execute()
21
-    {
22
-        $database = $this->getDatabase();
23
-
24
-        $idList = $database
25
-            ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL')
26
-            ->fetchAll(PDO::FETCH_COLUMN);
27
-
28
-        if (count($idList) > 0) {
29
-            /** @var User[] $users */
30
-            $users = UserSearchHelper::get($database)->inIds($idList)->fetch();
31
-
32
-            $expiredStatement = $database
33
-                ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\'');
34
-
35
-            foreach ($users as $u) {
36
-                $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(),
37
-                    $this->getSiteConfiguration());
38
-
39
-                try {
40
-                    $oauth->refreshIdentity();
41
-                }
42
-                catch (OAuthException $ex) {
43
-                    $expiredStatement->execute(array(':u' => $u->getId()));
44
-                }
45
-            }
46
-        }
47
-
48
-        $this->getDatabase()
49
-            ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\'');
50
-    }
20
+	public function execute()
21
+	{
22
+		$database = $this->getDatabase();
23
+
24
+		$idList = $database
25
+			->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL')
26
+			->fetchAll(PDO::FETCH_COLUMN);
27
+
28
+		if (count($idList) > 0) {
29
+			/** @var User[] $users */
30
+			$users = UserSearchHelper::get($database)->inIds($idList)->fetch();
31
+
32
+			$expiredStatement = $database
33
+				->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\'');
34
+
35
+			foreach ($users as $u) {
36
+				$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(),
37
+					$this->getSiteConfiguration());
38
+
39
+				try {
40
+					$oauth->refreshIdentity();
41
+				}
42
+				catch (OAuthException $ex) {
43
+					$expiredStatement->execute(array(':u' => $u->getId()));
44
+				}
45
+			}
46
+		}
47
+
48
+		$this->getDatabase()
49
+			->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\'');
50
+	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/ClearOAuthDataTask.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 
15 15
 class ClearOAuthDataTask extends ConsoleTaskBase
16 16
 {
17
-    public function execute()
18
-    {
19
-        $database = $this->getDatabase();
17
+	public function execute()
18
+	{
19
+		$database = $this->getDatabase();
20 20
 
21
-        $users = UserSearchHelper::get($database)->inIds(
22
-            $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
21
+		$users = UserSearchHelper::get($database)->inIds(
22
+			$database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
25
-            $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26
-            $oauth->detach();
27
-        }
24
+		foreach ($users as $u){
25
+			$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26
+			$oauth->detach();
27
+		}
28 28
 
29
-        $database->exec('DELETE FROM oauthtoken');
30
-        $database->exec('DELETE FROM oauthidentity');
31
-    }
29
+		$database->exec('DELETE FROM oauthtoken');
30
+		$database->exec('DELETE FROM oauthidentity');
31
+	}
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/RequestAction/RequestActionBase.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -19,54 +19,54 @@
 block discarded – undo
19 19
 
20 20
 abstract class RequestActionBase extends InternalPageBase
21 21
 {
22
-    /**
23
-     * @param PdoDatabase $database
24
-     *
25
-     * @return Request
26
-     * @throws ApplicationLogicException
27
-     */
28
-    protected function getRequest(PdoDatabase $database)
29
-    {
30
-        $requestId = WebRequest::postInt('request');
31
-        if ($requestId === null) {
32
-            throw new ApplicationLogicException('Request ID not found');
33
-        }
22
+	/**
23
+	 * @param PdoDatabase $database
24
+	 *
25
+	 * @return Request
26
+	 * @throws ApplicationLogicException
27
+	 */
28
+	protected function getRequest(PdoDatabase $database)
29
+	{
30
+		$requestId = WebRequest::postInt('request');
31
+		if ($requestId === null) {
32
+			throw new ApplicationLogicException('Request ID not found');
33
+		}
34 34
 
35
-        /** @var Request $request */
36
-        $request = Request::getById($requestId, $database);
35
+		/** @var Request $request */
36
+		$request = Request::getById($requestId, $database);
37 37
 
38
-        if ($request === false) {
39
-            throw new ApplicationLogicException('Request not found');
40
-        }
38
+		if ($request === false) {
39
+			throw new ApplicationLogicException('Request not found');
40
+		}
41 41
 
42
-        return $request;
43
-    }
42
+		return $request;
43
+	}
44 44
 
45
-    final protected function checkPosted()
46
-    {
47
-        // if the request was not posted, send the user away.
48
-        if (!WebRequest::wasPosted()) {
49
-            throw new ApplicationLogicException('This page does not support GET methods.');
50
-        }
45
+	final protected function checkPosted()
46
+	{
47
+		// if the request was not posted, send the user away.
48
+		if (!WebRequest::wasPosted()) {
49
+			throw new ApplicationLogicException('This page does not support GET methods.');
50
+		}
51 51
 
52
-        // validate the CSRF token
53
-        $this->validateCSRFToken();
54
-    }
52
+		// validate the CSRF token
53
+		$this->validateCSRFToken();
54
+	}
55 55
 
56
-    /**
57
-     * @param Request     $request
58
-     * @param             $parentTaskId
59
-     * @param User        $user
60
-     * @param PdoDatabase $database
61
-     */
62
-    protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database)
63
-    {
64
-        $welcomeTask = new JobQueue();
65
-        $welcomeTask->setTask(WelcomeUserTask::class);
66
-        $welcomeTask->setRequest($request->getId());
67
-        $welcomeTask->setParent($parentTaskId);
68
-        $welcomeTask->setTriggerUserId($user->getId());
69
-        $welcomeTask->setDatabase($database);
70
-        $welcomeTask->save();
71
-    }
56
+	/**
57
+	 * @param Request     $request
58
+	 * @param             $parentTaskId
59
+	 * @param User        $user
60
+	 * @param PdoDatabase $database
61
+	 */
62
+	protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database)
63
+	{
64
+		$welcomeTask = new JobQueue();
65
+		$welcomeTask->setTask(WelcomeUserTask::class);
66
+		$welcomeTask->setRequest($request->getId());
67
+		$welcomeTask->setParent($parentTaskId);
68
+		$welcomeTask->setTriggerUserId($user->getId());
69
+		$welcomeTask->setDatabase($database);
70
+		$welcomeTask->save();
71
+	}
72 72
 }
73 73
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageDropRequest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
 
16 16
 class PageDropRequest extends PageCloseRequest
17 17
 {
18
-    protected function getTemplate(PdoDatabase $database)
19
-    {
20
-        return EmailTemplate::getDroppedTemplate();
21
-    }
18
+	protected function getTemplate(PdoDatabase $database)
19
+	{
20
+		return EmailTemplate::getDroppedTemplate();
21
+	}
22 22
 
23
-    protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
24
-    {
25
-        return false;
26
-    }
23
+	protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
24
+	{
25
+		return false;
26
+	}
27 27
 
28
-    protected function confirmAccountCreated(Request $request, EmailTemplate $template)
29
-    {
30
-        return false;
31
-    }
28
+	protected function confirmAccountCreated(Request $request, EmailTemplate $template)
29
+	{
30
+		return false;
31
+	}
32 32
 
33
-    protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList)
34
-    {
35
-    }
33
+	protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList)
34
+	{
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageOAuth.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -21,77 +21,77 @@
 block discarded – undo
21 21
 
22 22
 class PageOAuth extends InternalPageBase
23 23
 {
24
-    /**
25
-     * Attach entry point
26
-     *
27
-     * must be posted, or will redirect to preferences
28
-     */
29
-    protected function attach()
30
-    {
31
-        if (!WebRequest::wasPosted()) {
32
-            $this->redirect('preferences');
33
-
34
-            return;
35
-        }
36
-
37
-        $database = $this->getDatabase();
38
-
39
-        $this->validateCSRFToken();
40
-
41
-        $oauthProtocolHelper = $this->getOAuthProtocolHelper();
42
-        $user = User::getCurrent($database);
43
-        $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
44
-
45
-        try {
46
-            $authoriseUrl = $oauth->getRequestToken();
47
-            $this->redirectUrl($authoriseUrl);
48
-        }
49
-        catch (CurlException $ex) {
50
-            throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
51
-        }
52
-    }
53
-
54
-    /**
55
-     * Detach account entry point
56
-     */
57
-    protected function detach()
58
-    {
59
-        if ($this->getSiteConfiguration()->getEnforceOAuth()) {
60
-            throw new AccessDeniedException($this->getSecurityManager());
61
-        }
62
-
63
-        $database = $this->getDatabase();
64
-        $user = User::getCurrent($database);
65
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
66
-
67
-        try {
68
-            $oauth->refreshIdentity();
69
-        }
70
-        catch (CurlException $ex) {
71
-            // do nothing. The user's already revoked this access anyway.
72
-        }
73
-        catch (OAuthException $ex) {
74
-            // do nothing. The user's already revoked this access anyway.
75
-        }
76
-
77
-        $oauth->detach();
78
-
79
-        // TODO: figure out why we need to force logout after a detach.
80
-        $user->setForcelogout(true);
81
-        $user->save();
82
-
83
-        // force the user to log out
84
-        Session::destroy();
85
-
86
-        $this->redirect('login');
87
-    }
88
-
89
-    /**
90
-     * Main function for this page, when no specific actions are called.
91
-     * @return void
92
-     */
93
-    protected function main()
94
-    {
95
-        $this->redirect('preferences');
96
-    }
24
+	/**
25
+	 * Attach entry point
26
+	 *
27
+	 * must be posted, or will redirect to preferences
28
+	 */
29
+	protected function attach()
30
+	{
31
+		if (!WebRequest::wasPosted()) {
32
+			$this->redirect('preferences');
33
+
34
+			return;
35
+		}
36
+
37
+		$database = $this->getDatabase();
38
+
39
+		$this->validateCSRFToken();
40
+
41
+		$oauthProtocolHelper = $this->getOAuthProtocolHelper();
42
+		$user = User::getCurrent($database);
43
+		$oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
44
+
45
+		try {
46
+			$authoriseUrl = $oauth->getRequestToken();
47
+			$this->redirectUrl($authoriseUrl);
48
+		}
49
+		catch (CurlException $ex) {
50
+			throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
51
+		}
52
+	}
53
+
54
+	/**
55
+	 * Detach account entry point
56
+	 */
57
+	protected function detach()
58
+	{
59
+		if ($this->getSiteConfiguration()->getEnforceOAuth()) {
60
+			throw new AccessDeniedException($this->getSecurityManager());
61
+		}
62
+
63
+		$database = $this->getDatabase();
64
+		$user = User::getCurrent($database);
65
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
66
+
67
+		try {
68
+			$oauth->refreshIdentity();
69
+		}
70
+		catch (CurlException $ex) {
71
+			// do nothing. The user's already revoked this access anyway.
72
+		}
73
+		catch (OAuthException $ex) {
74
+			// do nothing. The user's already revoked this access anyway.
75
+		}
76
+
77
+		$oauth->detach();
78
+
79
+		// TODO: figure out why we need to force logout after a detach.
80
+		$user->setForcelogout(true);
81
+		$user->save();
82
+
83
+		// force the user to log out
84
+		Session::destroy();
85
+
86
+		$this->redirect('login');
87
+	}
88
+
89
+	/**
90
+	 * Main function for this page, when no specific actions are called.
91
+	 * @return void
92
+	 */
93
+	protected function main()
94
+	{
95
+		$this->redirect('preferences');
96
+	}
97 97
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageChangePassword.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
 
18 18
 class PageChangePassword extends InternalPageBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @return void
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Change Password');
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @return void
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Change Password');
27 27
 
28
-        if (WebRequest::wasPosted()) {
29
-            $this->validateCSRFToken();
30
-            try {
31
-                $oldPassword = WebRequest::postString('oldpassword');
32
-                $newPassword = WebRequest::postString('newpassword');
33
-                $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm');
28
+		if (WebRequest::wasPosted()) {
29
+			$this->validateCSRFToken();
30
+			try {
31
+				$oldPassword = WebRequest::postString('oldpassword');
32
+				$newPassword = WebRequest::postString('newpassword');
33
+				$newPasswordConfirmation = WebRequest::postString('newpasswordconfirm');
34 34
 
35
-                $user = User::getCurrent($this->getDatabase());
36
-                if (!$user instanceof User) {
37
-                    throw new ApplicationLogicException('User not found');
38
-                }
35
+				$user = User::getCurrent($this->getDatabase());
36
+				if (!$user instanceof User) {
37
+					throw new ApplicationLogicException('User not found');
38
+				}
39 39
 
40
-                $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user);
41
-            }
42
-            catch (ApplicationLogicException $ex) {
43
-                SessionAlert::error($ex->getMessage());
44
-                $this->redirect('changePassword');
40
+				$this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user);
41
+			}
42
+			catch (ApplicationLogicException $ex) {
43
+				SessionAlert::error($ex->getMessage());
44
+				$this->redirect('changePassword');
45 45
 
46
-                return;
47
-            }
46
+				return;
47
+			}
48 48
 
49
-            $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
50
-            $passwordProvider->setCredential($user, 1, $newPassword);
49
+			$passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
50
+			$passwordProvider->setCredential($user, 1, $newPassword);
51 51
 
52
-            SessionAlert::success('Password changed successfully!');
52
+			SessionAlert::success('Password changed successfully!');
53 53
 
54
-            $this->redirect('preferences');
55
-        }
56
-        else {
57
-            $this->assignCSRFToken();
58
-            $this->setTemplate('preferences/changePassword.tpl');
59
-        }
60
-    }
54
+			$this->redirect('preferences');
55
+		}
56
+		else {
57
+			$this->assignCSRFToken();
58
+			$this->setTemplate('preferences/changePassword.tpl');
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * @param string $oldPassword
64
-     * @param string $newPassword
65
-     * @param string $newPasswordConfirmation
66
-     * @param User   $user
67
-     *
68
-     * @throws ApplicationLogicException
69
-     */
70
-    protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user)
71
-    {
72
-        if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) {
73
-            throw new ApplicationLogicException('All three fields must be completed to change your password');
74
-        }
62
+	/**
63
+	 * @param string $oldPassword
64
+	 * @param string $newPassword
65
+	 * @param string $newPasswordConfirmation
66
+	 * @param User   $user
67
+	 *
68
+	 * @throws ApplicationLogicException
69
+	 */
70
+	protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user)
71
+	{
72
+		if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) {
73
+			throw new ApplicationLogicException('All three fields must be completed to change your password');
74
+		}
75 75
 
76
-        if ($newPassword !== $newPasswordConfirmation) {
77
-            throw new ApplicationLogicException('Your new passwords did not match!');
78
-        }
76
+		if ($newPassword !== $newPasswordConfirmation) {
77
+			throw new ApplicationLogicException('Your new passwords did not match!');
78
+		}
79 79
 
80
-        // TODO: adapt for MFA support
81
-        $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
82
-        if (!$passwordProvider->authenticate($user, $oldPassword)) {
83
-            throw new ApplicationLogicException('The password you entered was incorrect.');
84
-        }
85
-    }
80
+		// TODO: adapt for MFA support
81
+		$passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
82
+		if (!$passwordProvider->authenticate($user, $oldPassword)) {
83
+			throw new ApplicationLogicException('The password you entered was incorrect.');
84
+		}
85
+	}
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/MediaWikiHelper.php 1 patch
Indentation   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -15,245 +15,245 @@
 block discarded – undo
15 15
 
16 16
 class MediaWikiHelper
17 17
 {
18
-    /**
19
-     * @var IMediaWikiClient
20
-     */
21
-    private $mediaWikiClient;
22
-    /**
23
-     * @var SiteConfiguration
24
-     */
25
-    private $siteConfiguration;
26
-
27
-    /**
28
-     * MediaWikiHelper constructor.
29
-     *
30
-     * @param IMediaWikiClient  $mediaWikiClient
31
-     * @param SiteConfiguration $siteConfiguration
32
-     */
33
-    public function __construct(IMediaWikiClient $mediaWikiClient, SiteConfiguration $siteConfiguration)
34
-    {
35
-        $this->mediaWikiClient = $mediaWikiClient;
36
-        $this->siteConfiguration = $siteConfiguration;
37
-    }
38
-
39
-    /**
40
-     * @todo handle override antispoof and titleblacklist issues
41
-     *
42
-     * @param string $username
43
-     * @param string $emailAddress
44
-     * @param string $reason
45
-     *
46
-     * @throws Exception
47
-     * @throws MediaWikiApiException
48
-     */
49
-    public function createAccount($username, $emailAddress, $reason)
50
-    {
51
-        // get token
52
-        $tokenParams = array(
53
-            'action' => 'query',
54
-            'meta'   => 'tokens',
55
-            'type'   => 'createaccount',
56
-        );
57
-
58
-        $response = $this->mediaWikiClient->doApiCall($tokenParams, 'POST');
59
-
60
-        if (isset($response->error)) {
61
-            throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
62
-        }
63
-
64
-        $token = $response->query->tokens->createaccounttoken;
65
-
66
-        $callback = $this->siteConfiguration->getBaseUrl() . '/internal.php/oauth/createCallback';
67
-
68
-        $checkboxFields = array();
69
-        $requiredFields = array();
70
-        $this->getCreationFieldData($requiredFields, $checkboxFields);
71
-
72
-        $apiCallData = array(
73
-            'action'              => 'createaccount',
74
-            'createreturnurl'     => $callback,
75
-            'createtoken'         => $token,
76
-            'createmessageformat' => 'html',
77
-        );
78
-
79
-        $createParams = array_fill_keys($requiredFields, '') + $apiCallData;
80
-
81
-        $createParams['username'] = $username;
82
-        $createParams['mailpassword'] = true;
83
-        $createParams['email'] = $emailAddress;
84
-        $createParams['reason'] = $reason;
85
-
86
-        $createResponse = $this->mediaWikiClient->doApiCall($createParams, 'POST');
87
-
88
-        if (isset($createResponse->error)) {
89
-            throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
90
-        }
91
-
92
-        if (!isset($createResponse->createaccount) || !isset($createResponse->createaccount->status)) {
93
-            throw new MediaWikiApiException('Unknown error creating account');
94
-        }
95
-
96
-        if ($createResponse->createaccount->status === 'FAIL') {
97
-            throw new MediaWikiApiException($createResponse->createaccount->message);
98
-        }
99
-
100
-        if ($createResponse->createaccount->status === 'PASS') {
101
-            // success!
102
-            return;
103
-        }
104
-
105
-        throw new Exception('API result reported status of ' . $createResponse->createaccount->status);
106
-    }
107
-
108
-    /**
109
-     * @param string $username
110
-     * @param string $title
111
-     * @param        $summary
112
-     * @param string $message
113
-     * @param bool   $createOnly
114
-     *
115
-     * @throws MediaWikiApiException
116
-     */
117
-    public function addTalkPageMessage($username, $title, $summary, $message, $createOnly = true)
118
-    {
119
-        // get token
120
-        $tokenParams = array(
121
-            'action' => 'query',
122
-            'meta'   => 'tokens',
123
-            'type'   => 'csrf',
124
-        );
125
-
126
-        $response = $this->mediaWikiClient->doApiCall($tokenParams, 'POST');
127
-
128
-        if (isset($response->error)) {
129
-            throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
130
-        }
131
-
132
-        $token = $response->query->tokens->csrftoken;
133
-
134
-        if ($token === null) {
135
-            throw new MediaWikiApiException('Edit token could not be acquired');
136
-        }
137
-
138
-        $editParameters = array(
139
-            'action'       => 'edit',
140
-            'title'        => 'User talk:' . $username,
141
-            'section'      => 'new',
142
-            'sectiontitle' => $title,
143
-            'summary'      => $summary,
144
-            'text'         => $message,
145
-            'token'        => $token,
146
-        );
147
-
148
-        if ($createOnly) {
149
-            $editParameters['createonly'] = true;
150
-        }
151
-
152
-        $response = $this->mediaWikiClient->doApiCall($editParameters, 'POST');
153
-
154
-        if (!isset($response->edit)) {
155
-            if (isset($response->error)) {
156
-                throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
157
-            }
158
-
159
-            throw new MediaWikiApiException('Unknown error encountered during editing.');
160
-        }
161
-
162
-        $editResponse = $response->edit;
163
-        if ($editResponse->result === "Success") {
164
-            return;
165
-        }
166
-
167
-        throw new MediaWikiApiException('Edit status unsuccessful: ' . $editResponse->result);
168
-    }
169
-
170
-    public function getCreationFieldData(&$requiredFields, &$checkboxFields)
171
-    {
172
-        // get token
173
-        $params = array(
174
-            'action'         => 'query',
175
-            'meta'           => 'authmanagerinfo',
176
-            'amirequestsfor' => 'create',
177
-        );
178
-
179
-        $response = $this->mediaWikiClient->doApiCall($params, 'GET');
180
-
181
-        if (isset($response->error)) {
182
-            throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
183
-        }
184
-
185
-        $requests = $response->query->authmanagerinfo->requests;
186
-
187
-        // We don't want to deal with these providers ever.
188
-        $discardList = array(
189
-            // Requires a username and password
190
-            'MediaWiki\\Auth\\PasswordAuthenticationRequest',
191
-        );
192
-
193
-        // We require these providers to function
194
-        $requireList = array(
195
-            'MediaWiki\\Auth\\TemporaryPasswordAuthenticationRequest',
196
-            'MediaWiki\\Auth\\UsernameAuthenticationRequest',
197
-            'MediaWiki\\Auth\\UserDataAuthenticationRequest',
198
-            'MediaWiki\\Auth\\CreationReasonAuthenticationRequest',
199
-        );
200
-
201
-        $requiredFields = array();
202
-        // Keep checkbox fields separate, since "required" actually means optional as absent == false.
203
-        $checkboxFields = array();
204
-
205
-        foreach ($requests as $req) {
206
-            // Immediately discard anything that is on the discard list.
207
-            if (in_array($req->id, $discardList)) {
208
-                continue;
209
-            }
210
-
211
-            $required = false;
212
-
213
-            if ($req->required === 'primary-required' && !in_array($req->id, $requireList)) {
214
-                // Only want one.
215
-                continue;
216
-            }
217
-
218
-            if (in_array($req->id, $requireList)) {
219
-                unset($requireList[$req->id]);
220
-                $required = true;
221
-            }
222
-
223
-            if ($req->required === 'required') {
224
-                $required = true;
225
-            }
226
-
227
-            if ($required) {
228
-                foreach ($req->fields as $name => $data) {
229
-                    if ($data->type === 'checkbox') {
230
-                        $checkboxFields[] = $name;
231
-                    }
232
-                    else {
233
-                        $requiredFields[] = $name;
234
-                    }
235
-                }
236
-            }
237
-        }
238
-    }
239
-
240
-    /**
241
-     * @param string $username
242
-     * @return bool
243
-     */
244
-    public function checkAccountExists($username) {
245
-        $parameters = array(
246
-            'action'  => 'query',
247
-            'list'    => 'users',
248
-            'format'  => 'php',
249
-            'ususers' => $username,
250
-        );
251
-
252
-        $apiResult = $this->mediaWikiClient->doApiCall($parameters, 'GET');
253
-
254
-        $entry = $apiResult->query->users[0];
255
-        $exists = !isset($entry->missing);
256
-
257
-        return $exists;
258
-    }
18
+	/**
19
+	 * @var IMediaWikiClient
20
+	 */
21
+	private $mediaWikiClient;
22
+	/**
23
+	 * @var SiteConfiguration
24
+	 */
25
+	private $siteConfiguration;
26
+
27
+	/**
28
+	 * MediaWikiHelper constructor.
29
+	 *
30
+	 * @param IMediaWikiClient  $mediaWikiClient
31
+	 * @param SiteConfiguration $siteConfiguration
32
+	 */
33
+	public function __construct(IMediaWikiClient $mediaWikiClient, SiteConfiguration $siteConfiguration)
34
+	{
35
+		$this->mediaWikiClient = $mediaWikiClient;
36
+		$this->siteConfiguration = $siteConfiguration;
37
+	}
38
+
39
+	/**
40
+	 * @todo handle override antispoof and titleblacklist issues
41
+	 *
42
+	 * @param string $username
43
+	 * @param string $emailAddress
44
+	 * @param string $reason
45
+	 *
46
+	 * @throws Exception
47
+	 * @throws MediaWikiApiException
48
+	 */
49
+	public function createAccount($username, $emailAddress, $reason)
50
+	{
51
+		// get token
52
+		$tokenParams = array(
53
+			'action' => 'query',
54
+			'meta'   => 'tokens',
55
+			'type'   => 'createaccount',
56
+		);
57
+
58
+		$response = $this->mediaWikiClient->doApiCall($tokenParams, 'POST');
59
+
60
+		if (isset($response->error)) {
61
+			throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
62
+		}
63
+
64
+		$token = $response->query->tokens->createaccounttoken;
65
+
66
+		$callback = $this->siteConfiguration->getBaseUrl() . '/internal.php/oauth/createCallback';
67
+
68
+		$checkboxFields = array();
69
+		$requiredFields = array();
70
+		$this->getCreationFieldData($requiredFields, $checkboxFields);
71
+
72
+		$apiCallData = array(
73
+			'action'              => 'createaccount',
74
+			'createreturnurl'     => $callback,
75
+			'createtoken'         => $token,
76
+			'createmessageformat' => 'html',
77
+		);
78
+
79
+		$createParams = array_fill_keys($requiredFields, '') + $apiCallData;
80
+
81
+		$createParams['username'] = $username;
82
+		$createParams['mailpassword'] = true;
83
+		$createParams['email'] = $emailAddress;
84
+		$createParams['reason'] = $reason;
85
+
86
+		$createResponse = $this->mediaWikiClient->doApiCall($createParams, 'POST');
87
+
88
+		if (isset($createResponse->error)) {
89
+			throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
90
+		}
91
+
92
+		if (!isset($createResponse->createaccount) || !isset($createResponse->createaccount->status)) {
93
+			throw new MediaWikiApiException('Unknown error creating account');
94
+		}
95
+
96
+		if ($createResponse->createaccount->status === 'FAIL') {
97
+			throw new MediaWikiApiException($createResponse->createaccount->message);
98
+		}
99
+
100
+		if ($createResponse->createaccount->status === 'PASS') {
101
+			// success!
102
+			return;
103
+		}
104
+
105
+		throw new Exception('API result reported status of ' . $createResponse->createaccount->status);
106
+	}
107
+
108
+	/**
109
+	 * @param string $username
110
+	 * @param string $title
111
+	 * @param        $summary
112
+	 * @param string $message
113
+	 * @param bool   $createOnly
114
+	 *
115
+	 * @throws MediaWikiApiException
116
+	 */
117
+	public function addTalkPageMessage($username, $title, $summary, $message, $createOnly = true)
118
+	{
119
+		// get token
120
+		$tokenParams = array(
121
+			'action' => 'query',
122
+			'meta'   => 'tokens',
123
+			'type'   => 'csrf',
124
+		);
125
+
126
+		$response = $this->mediaWikiClient->doApiCall($tokenParams, 'POST');
127
+
128
+		if (isset($response->error)) {
129
+			throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
130
+		}
131
+
132
+		$token = $response->query->tokens->csrftoken;
133
+
134
+		if ($token === null) {
135
+			throw new MediaWikiApiException('Edit token could not be acquired');
136
+		}
137
+
138
+		$editParameters = array(
139
+			'action'       => 'edit',
140
+			'title'        => 'User talk:' . $username,
141
+			'section'      => 'new',
142
+			'sectiontitle' => $title,
143
+			'summary'      => $summary,
144
+			'text'         => $message,
145
+			'token'        => $token,
146
+		);
147
+
148
+		if ($createOnly) {
149
+			$editParameters['createonly'] = true;
150
+		}
151
+
152
+		$response = $this->mediaWikiClient->doApiCall($editParameters, 'POST');
153
+
154
+		if (!isset($response->edit)) {
155
+			if (isset($response->error)) {
156
+				throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
157
+			}
158
+
159
+			throw new MediaWikiApiException('Unknown error encountered during editing.');
160
+		}
161
+
162
+		$editResponse = $response->edit;
163
+		if ($editResponse->result === "Success") {
164
+			return;
165
+		}
166
+
167
+		throw new MediaWikiApiException('Edit status unsuccessful: ' . $editResponse->result);
168
+	}
169
+
170
+	public function getCreationFieldData(&$requiredFields, &$checkboxFields)
171
+	{
172
+		// get token
173
+		$params = array(
174
+			'action'         => 'query',
175
+			'meta'           => 'authmanagerinfo',
176
+			'amirequestsfor' => 'create',
177
+		);
178
+
179
+		$response = $this->mediaWikiClient->doApiCall($params, 'GET');
180
+
181
+		if (isset($response->error)) {
182
+			throw new MediaWikiApiException($response->error->code . ': ' . $response->error->info);
183
+		}
184
+
185
+		$requests = $response->query->authmanagerinfo->requests;
186
+
187
+		// We don't want to deal with these providers ever.
188
+		$discardList = array(
189
+			// Requires a username and password
190
+			'MediaWiki\\Auth\\PasswordAuthenticationRequest',
191
+		);
192
+
193
+		// We require these providers to function
194
+		$requireList = array(
195
+			'MediaWiki\\Auth\\TemporaryPasswordAuthenticationRequest',
196
+			'MediaWiki\\Auth\\UsernameAuthenticationRequest',
197
+			'MediaWiki\\Auth\\UserDataAuthenticationRequest',
198
+			'MediaWiki\\Auth\\CreationReasonAuthenticationRequest',
199
+		);
200
+
201
+		$requiredFields = array();
202
+		// Keep checkbox fields separate, since "required" actually means optional as absent == false.
203
+		$checkboxFields = array();
204
+
205
+		foreach ($requests as $req) {
206
+			// Immediately discard anything that is on the discard list.
207
+			if (in_array($req->id, $discardList)) {
208
+				continue;
209
+			}
210
+
211
+			$required = false;
212
+
213
+			if ($req->required === 'primary-required' && !in_array($req->id, $requireList)) {
214
+				// Only want one.
215
+				continue;
216
+			}
217
+
218
+			if (in_array($req->id, $requireList)) {
219
+				unset($requireList[$req->id]);
220
+				$required = true;
221
+			}
222
+
223
+			if ($req->required === 'required') {
224
+				$required = true;
225
+			}
226
+
227
+			if ($required) {
228
+				foreach ($req->fields as $name => $data) {
229
+					if ($data->type === 'checkbox') {
230
+						$checkboxFields[] = $name;
231
+					}
232
+					else {
233
+						$requiredFields[] = $name;
234
+					}
235
+				}
236
+			}
237
+		}
238
+	}
239
+
240
+	/**
241
+	 * @param string $username
242
+	 * @return bool
243
+	 */
244
+	public function checkAccountExists($username) {
245
+		$parameters = array(
246
+			'action'  => 'query',
247
+			'list'    => 'users',
248
+			'format'  => 'php',
249
+			'ususers' => $username,
250
+		);
251
+
252
+		$apiResult = $this->mediaWikiClient->doApiCall($parameters, 'GET');
253
+
254
+		$entry = $apiResult->query->users[0];
255
+		$exists = !isset($entry->missing);
256
+
257
+		return $exists;
258
+	}
259 259
 }
Please login to merge, or discard this patch.