1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
4
|
|
|
* * |
5
|
|
|
* All code in this file is released into the public domain by the ACC * |
6
|
|
|
* Development Team. Please see team.json for a list of contributors. * |
7
|
|
|
******************************************************************************/ |
8
|
|
|
|
9
|
|
|
namespace Waca\Pages\UserAuth; |
10
|
|
|
|
11
|
|
|
use Waca\DataObjects\User; |
12
|
|
|
use Waca\Helpers\OAuthUserHelper; |
13
|
|
|
use Waca\SessionAlert; |
14
|
|
|
use Waca\Tasks\InternalPageBase; |
15
|
|
|
use Waca\WebRequest; |
16
|
|
|
|
17
|
|
|
class PagePreferences extends InternalPageBase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Main function for this page, when no specific actions are called. |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
protected function main() |
24
|
|
|
{ |
25
|
|
|
$this->setHtmlTitle('Preferences'); |
26
|
|
|
|
27
|
|
|
$enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
28
|
|
|
$database = $this->getDatabase(); |
29
|
|
|
$user = User::getCurrent($database); |
30
|
|
|
|
31
|
|
|
// Dual mode |
32
|
|
|
if (WebRequest::wasPosted()) { |
33
|
|
|
$this->validateCSRFToken(); |
34
|
|
|
$user->setWelcomeSig(WebRequest::postString('sig')); |
35
|
|
|
$user->setEmailSig(WebRequest::postString('emailsig')); |
36
|
|
|
$user->setAbortPref(WebRequest::postBoolean('abortpref') ? 1 : 0); |
37
|
|
|
$this->setCreationMode($user); |
38
|
|
|
|
39
|
|
|
$newSkin = WebRequest::postString('skintype'); |
40
|
|
|
if ($newSkin === 'main' || $newSkin === 'alt' || $newSkin === 'auto') { |
41
|
|
|
$user->setSkin($newSkin); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$email = WebRequest::postEmail('email'); |
45
|
|
|
if ($email !== null) { |
46
|
|
|
$user->setEmail($email); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$user->save(); |
50
|
|
|
SessionAlert::success("Preferences updated!"); |
51
|
|
|
|
52
|
|
|
$this->redirect(''); |
53
|
|
|
} |
54
|
|
|
else { |
55
|
|
|
$this->assignCSRFToken(); |
56
|
|
|
$this->setTemplate('preferences/prefs.tpl'); |
57
|
|
|
$this->assign("enforceOAuth", $enforceOAuth); |
58
|
|
|
|
59
|
|
|
$this->assign('canManualCreate', |
60
|
|
|
$this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
61
|
|
|
$this->assign('canOauthCreate', |
62
|
|
|
$this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
63
|
|
|
$this->assign('canBotCreate', |
64
|
|
|
$this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
65
|
|
|
|
66
|
|
|
$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
67
|
|
|
$this->getSiteConfiguration()); |
68
|
|
|
$this->assign('oauth', $oauth); |
69
|
|
|
|
70
|
|
|
$identity = null; |
71
|
|
|
if ($oauth->isFullyLinked()) { |
72
|
|
|
$identity = $oauth->getIdentity(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->assign('identity', $identity); |
76
|
|
|
$this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function refreshOAuth() |
81
|
|
|
{ |
82
|
|
|
if (!WebRequest::wasPosted()) { |
83
|
|
|
$this->redirect('preferences'); |
84
|
|
|
|
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$database = $this->getDatabase(); |
89
|
|
|
$oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(), |
90
|
|
|
$this->getSiteConfiguration()); |
91
|
|
|
if ($oauth->isFullyLinked()) { |
92
|
|
|
$oauth->refreshIdentity(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->redirect('preferences'); |
96
|
|
|
|
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param User $user |
102
|
|
|
*/ |
103
|
|
|
protected function setCreationMode(User $user) |
104
|
|
|
{ |
105
|
|
|
// if the user is selecting a creation mode that they are not allowed, do nothing. |
106
|
|
|
// this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
107
|
|
|
// or that they have kept from when they previously had certain access. |
108
|
|
|
$creationMode = WebRequest::postInt('creationmode'); |
109
|
|
|
if ($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
110
|
|
|
$user->setCreationMode($creationMode); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|