|
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; |
|
10
|
|
|
|
|
11
|
|
|
use Waca\DataObjects\Domain; |
|
12
|
|
|
use Waca\DataObjects\EmailTemplate; |
|
13
|
|
|
use Waca\DataObjects\User; |
|
14
|
|
|
use Waca\Exceptions\AccessDeniedException; |
|
15
|
|
|
use Waca\Helpers\Logger; |
|
16
|
|
|
use Waca\SessionAlert; |
|
17
|
|
|
use Waca\Tasks\InternalPageBase; |
|
18
|
|
|
use Waca\WebRequest; |
|
19
|
|
|
|
|
20
|
|
|
class PageDomainManagement extends InternalPageBase |
|
21
|
|
|
{ |
|
22
|
|
|
protected function main() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->setHtmlTitle('Domain Management'); |
|
25
|
|
|
|
|
26
|
|
|
$database = $this->getDatabase(); |
|
27
|
|
|
$currentUser = User::getCurrent($database); |
|
28
|
|
|
|
|
29
|
|
|
/** @var Domain[] $domains */ |
|
30
|
|
|
$domains = Domain::getAll($database); |
|
31
|
|
|
|
|
32
|
|
|
$templates = []; |
|
33
|
|
|
foreach ($domains as $domain) { |
|
34
|
|
|
if ($domain->getDefaultClose() !== null) { |
|
35
|
|
|
$templates[$domain->getDefaultClose()] = EmailTemplate::getById($domain->getDefaultClose(), $database); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$canEdit = $this->barrierTest('edit', $currentUser); |
|
40
|
|
|
$canEditAll = $this->barrierTest('editAll', $currentUser); |
|
41
|
|
|
$canCreate = $this->barrierTest('create', $currentUser); |
|
42
|
|
|
$this->assign('canEdit', $canEdit); |
|
43
|
|
|
$this->assign('canEditAll', $canEditAll); |
|
44
|
|
|
$this->assign('canCreate', $canCreate); |
|
45
|
|
|
|
|
46
|
|
|
$this->assign('domains', $domains); |
|
47
|
|
|
$this->assign('closeTemplates', $templates); |
|
48
|
|
|
$this->assign('currentDomain', Domain::getCurrent($database)); |
|
49
|
|
|
$this->setTemplate('domain-management/main.tpl'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function create() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->setHtmlTitle('Domain Management'); |
|
55
|
|
|
$database = $this->getDatabase(); |
|
56
|
|
|
$currentUser = User::getCurrent($database); |
|
57
|
|
|
|
|
58
|
|
|
// quickly check the user is allowed to edit all fields. If not, then they shouldn't be allowed to create |
|
59
|
|
|
// new domains either. With any luck, a competent developer would never grant create without editAll to a role |
|
60
|
|
|
// anyway, so this will never be hit. |
|
61
|
|
|
if (!$this->barrierTest('editAll', $currentUser)) { |
|
62
|
|
|
throw new AccessDeniedException(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (WebRequest::wasPosted()) { |
|
66
|
|
|
$this->validateCSRFToken(); |
|
67
|
|
|
|
|
68
|
|
|
$domain = new Domain(); |
|
69
|
|
|
$domain->setDatabase($database); |
|
70
|
|
|
|
|
71
|
|
|
$domain->setShortName(WebRequest::postString('shortName')); |
|
|
|
|
|
|
72
|
|
|
$domain->setLongName(WebRequest::postString('longName')); |
|
|
|
|
|
|
73
|
|
|
$domain->setWikiArticlePath(WebRequest::postString('articlePath')); |
|
|
|
|
|
|
74
|
|
|
$domain->setWikiApiPath(WebRequest::postString('apiPath')); |
|
|
|
|
|
|
75
|
|
|
$domain->setEnabled(WebRequest::postBoolean('enabled')); |
|
76
|
|
|
$domain->setDefaultLanguage(WebRequest::postString('defaultLanguage')); |
|
|
|
|
|
|
77
|
|
|
$domain->setDefaultClose(null); |
|
78
|
|
|
$domain->setEmailSender(WebRequest::postString('emailSender')); |
|
|
|
|
|
|
79
|
|
|
$domain->setNotificationTarget(WebRequest::postString('notificationTarget')); |
|
80
|
|
|
|
|
81
|
|
|
$domain->save(); |
|
82
|
|
|
|
|
83
|
|
|
Logger::domainCreated($database, $domain); |
|
84
|
|
|
$this->redirect('domainManagement'); |
|
85
|
|
|
} |
|
86
|
|
|
else { |
|
87
|
|
|
$this->assignCSRFToken(); |
|
88
|
|
|
|
|
89
|
|
|
$this->assign('shortName', ''); |
|
90
|
|
|
$this->assign('longName', ''); |
|
91
|
|
|
$this->assign('articlePath', ''); |
|
92
|
|
|
$this->assign('apiPath', ''); |
|
93
|
|
|
$this->assign('enabled', false); |
|
94
|
|
|
$this->assign('defaultLanguage', 'en'); |
|
95
|
|
|
$this->assign('emailSender', ''); |
|
96
|
|
|
$this->assign('notificationTarget', ''); |
|
97
|
|
|
|
|
98
|
|
|
$this->assign('createMode', true); |
|
99
|
|
|
$this->assign('canEditAll', true); |
|
100
|
|
|
|
|
101
|
|
|
$this->setTemplate('domain-management/edit.tpl'); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
protected function edit() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->setHtmlTitle('Domain Management'); |
|
108
|
|
|
$database = $this->getDatabase(); |
|
109
|
|
|
$currentUser = User::getCurrent($database); |
|
110
|
|
|
|
|
111
|
|
|
$canEditAll = $this->barrierTest('editAll', $currentUser); |
|
112
|
|
|
|
|
113
|
|
|
/** @var Domain $domain */ |
|
114
|
|
|
$domain = Domain::getById(WebRequest::getInt('domain'), $database); |
|
115
|
|
|
|
|
116
|
|
|
if (WebRequest::wasPosted()) { |
|
117
|
|
|
$this->validateCSRFToken(); |
|
118
|
|
|
|
|
119
|
|
|
$domain->setLongName(WebRequest::postString('longName')); |
|
|
|
|
|
|
120
|
|
|
$domain->setDefaultLanguage(WebRequest::postString('defaultLanguage')); |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
/** @var EmailTemplate $template */ |
|
123
|
|
|
$template = EmailTemplate::getById(WebRequest::postInt('defaultClose'), $database); |
|
124
|
|
|
if ($template->getActive() |
|
125
|
|
|
&& $template->getPreloadOnly() === false |
|
126
|
|
|
&& $template->getDefaultAction() === EmailTemplate::ACTION_CREATED) { |
|
127
|
|
|
$domain->setDefaultClose(WebRequest::postInt('defaultClose')); |
|
128
|
|
|
} |
|
129
|
|
|
else { |
|
130
|
|
|
SessionAlert::warning("Chosen email template is not valid for use as the default creation template"); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if ($canEditAll) { |
|
134
|
|
|
$domain->setWikiArticlePath(WebRequest::postString('articlePath')); |
|
|
|
|
|
|
135
|
|
|
$domain->setWikiApiPath(WebRequest::postString('apiPath')); |
|
|
|
|
|
|
136
|
|
|
$domain->setEnabled(WebRequest::postBoolean('enabled')); |
|
137
|
|
|
$domain->setEmailSender(WebRequest::postString('emailSender')); |
|
|
|
|
|
|
138
|
|
|
$domain->setNotificationTarget(WebRequest::postString('notificationTarget')); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$domain->save(); |
|
142
|
|
|
|
|
143
|
|
|
Logger::domainEdited($database, $domain); |
|
144
|
|
|
$this->redirect('domainManagement'); |
|
145
|
|
|
} |
|
146
|
|
|
else { |
|
147
|
|
|
$this->assignCSRFToken(); |
|
148
|
|
|
|
|
149
|
|
|
$templates = EmailTemplate::getActiveNonpreloadTemplates(EmailTemplate::ACTION_CREATED, $database); |
|
150
|
|
|
$this->assign('closeTemplates', $templates); |
|
151
|
|
|
|
|
152
|
|
|
$this->assign('shortName', $domain->getShortName()); |
|
153
|
|
|
$this->assign('longName', $domain->getLongName()); |
|
154
|
|
|
$this->assign('articlePath', $domain->getWikiArticlePath()); |
|
155
|
|
|
$this->assign('apiPath', $domain->getWikiApiPath()); |
|
156
|
|
|
$this->assign('enabled', $domain->isEnabled()); |
|
157
|
|
|
$this->assign('defaultClose', $domain->getDefaultClose()); |
|
158
|
|
|
$this->assign('defaultLanguage', $domain->getDefaultLanguage()); |
|
159
|
|
|
$this->assign('emailSender', $domain->getEmailSender()); |
|
160
|
|
|
$this->assign('notificationTarget', $domain->getNotificationTarget()); |
|
161
|
|
|
|
|
162
|
|
|
$this->assign('createMode', false); |
|
163
|
|
|
$this->assign('canEditAll', $canEditAll); |
|
164
|
|
|
|
|
165
|
|
|
$this->setTemplate('domain-management/edit.tpl'); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|