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