|
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\Fragments; |
|
11
|
|
|
|
|
12
|
|
|
use Waca\DataObjects\Comment; |
|
13
|
|
|
use Waca\DataObjects\JobQueue; |
|
14
|
|
|
use Waca\DataObjects\User; |
|
15
|
|
|
use Waca\Helpers\SearchHelpers\JobQueueSearchHelper; |
|
16
|
|
|
use Waca\Pages\PageBan; |
|
17
|
|
|
use Waca\Pages\PageDomainManagement; |
|
18
|
|
|
use Waca\Pages\PageEmailManagement; |
|
19
|
|
|
use Waca\Pages\PageErrorLogViewer; |
|
20
|
|
|
use Waca\Pages\PageJobQueue; |
|
21
|
|
|
use Waca\Pages\PageListFlaggedComments; |
|
22
|
|
|
use Waca\Pages\PageLog; |
|
23
|
|
|
use Waca\Pages\PageMain; |
|
24
|
|
|
use Waca\Pages\PageQueueManagement; |
|
25
|
|
|
use Waca\Pages\PageRequestFormManagement; |
|
26
|
|
|
use Waca\Pages\PageSearch; |
|
27
|
|
|
use Waca\Pages\PageSiteNotice; |
|
28
|
|
|
use Waca\Pages\PageUserManagement; |
|
29
|
|
|
use Waca\Pages\PageViewRequest; |
|
30
|
|
|
use Waca\Pages\PageWelcomeTemplateManagement; |
|
31
|
|
|
use Waca\Pages\Statistics\StatsMain; |
|
32
|
|
|
use Waca\Pages\Statistics\StatsUsers; |
|
33
|
|
|
use Waca\PdoDatabase; |
|
34
|
|
|
use Waca\Security\IDomainAccessManager; |
|
35
|
|
|
use Waca\Security\ISecurityManager; |
|
36
|
|
|
use Waca\Security\RoleConfigurationBase; |
|
37
|
|
|
|
|
38
|
|
|
trait NavigationMenuAccessControl |
|
39
|
|
|
{ |
|
40
|
|
|
protected abstract function assign($name, $value); |
|
41
|
|
|
|
|
42
|
|
|
protected abstract function getSecurityManager(): ISecurityManager; |
|
43
|
|
|
|
|
44
|
|
|
public abstract function getDomainAccessManager(): IDomainAccessManager; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param $currentUser |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function setupNavMenuAccess($currentUser) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assign('nav__canRequests', $this->getSecurityManager() |
|
52
|
|
|
->allows(PageMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
53
|
|
|
|
|
54
|
|
|
$this->assign('nav__canLogs', $this->getSecurityManager() |
|
55
|
|
|
->allows(PageLog::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
56
|
|
|
$this->assign('nav__canUsers', $this->getSecurityManager() |
|
57
|
|
|
->allows(StatsUsers::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
58
|
|
|
$this->assign('nav__canSearch', $this->getSecurityManager() |
|
59
|
|
|
->allows(PageSearch::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
60
|
|
|
$this->assign('nav__canStats', $this->getSecurityManager() |
|
61
|
|
|
->allows(StatsMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
62
|
|
|
|
|
63
|
|
|
$this->assign('nav__canBan', $this->getSecurityManager() |
|
64
|
|
|
->allows(PageBan::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
65
|
|
|
$this->assign('nav__canEmailMgmt', $this->getSecurityManager() |
|
66
|
|
|
->allows(PageEmailManagement::class, RoleConfigurationBase::MAIN, |
|
67
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
68
|
|
|
$this->assign('nav__canWelcomeMgmt', $this->getSecurityManager() |
|
69
|
|
|
->allows(PageWelcomeTemplateManagement::class, RoleConfigurationBase::MAIN, |
|
70
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
71
|
|
|
$this->assign('nav__canSiteNoticeMgmt', $this->getSecurityManager() |
|
72
|
|
|
->allows(PageSiteNotice::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
73
|
|
|
$this->assign('nav__canUserMgmt', $this->getSecurityManager() |
|
74
|
|
|
->allows(PageUserManagement::class, RoleConfigurationBase::MAIN, |
|
75
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
76
|
|
|
$this->assign('nav__canJobQueue', $this->getSecurityManager() |
|
77
|
|
|
->allows(PageJobQueue::class, RoleConfigurationBase::MAIN, |
|
78
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
79
|
|
|
$this->assign('nav__canDomainMgmt', $this->getSecurityManager() |
|
80
|
|
|
->allows(PageDomainManagement::class, RoleConfigurationBase::MAIN, |
|
81
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
82
|
|
|
$this->assign('nav__canFlaggedComments', $this->getSecurityManager() |
|
83
|
|
|
->allows(PageListFlaggedComments::class, RoleConfigurationBase::MAIN, |
|
84
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
85
|
|
|
$this->assign('nav__canQueueMgmt', $this->getSecurityManager() |
|
86
|
|
|
->allows(PageQueueManagement::class, RoleConfigurationBase::MAIN, |
|
87
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
88
|
|
|
$this->assign('nav__canFormMgmt', $this->getSecurityManager() |
|
89
|
|
|
->allows(PageRequestFormManagement::class, RoleConfigurationBase::MAIN, |
|
90
|
|
|
$currentUser) === ISecurityManager::ALLOWED); |
|
91
|
|
|
$this->assign('nav__canErrorLog', $this->getSecurityManager() |
|
92
|
|
|
->allows(PageErrorLogViewer::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
93
|
|
|
|
|
94
|
|
|
$this->assign('nav__canViewRequest', $this->getSecurityManager() |
|
95
|
|
|
->allows(PageViewRequest::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
96
|
|
|
|
|
97
|
|
|
$this->assign('nav__domainList', []); |
|
98
|
|
|
if ($this->getDomainAccessManager() !== null) { |
|
99
|
|
|
$this->assign('nav__domainList', $this->getDomainAccessManager()->getAllowedDomains($currentUser)); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Sets up the badges to draw attention to issues on various admin pages. |
|
105
|
|
|
* |
|
106
|
|
|
* This function checks to see if a user can access the pages, and if so checks the count of problem areas. |
|
107
|
|
|
* If problem areas are found, a number greater than 0 will cause the badge to show up. |
|
108
|
|
|
* |
|
109
|
|
|
* @param User $currentUser The current user |
|
110
|
|
|
* @param PdoDatabase $database Database instance |
|
111
|
|
|
* |
|
112
|
|
|
* @return void |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setUpNavBarBadges(User $currentUser, PdoDatabase $database) { |
|
115
|
|
|
// Set up some variables. |
|
116
|
|
|
// A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine. |
|
117
|
|
|
$countOfFlagged = 0; |
|
118
|
|
|
$countOfJobQueue = 0; |
|
119
|
|
|
|
|
120
|
|
|
// Count of flagged comments: |
|
121
|
|
|
if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) { |
|
|
|
|
|
|
122
|
|
|
// We want all flagged comments that haven't been acknowledged if we can visit the page. |
|
123
|
|
|
$countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
// Count of failed job queue changes: |
|
127
|
|
|
if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) { |
|
128
|
|
|
// We want all failed jobs that haven't been acknowledged if we can visit the page. |
|
129
|
|
|
JobQueueSearchHelper::get($database, 1) // FIXME: domains |
|
130
|
|
|
->statusIn([JobQueue::STATUS_FAILED]) |
|
131
|
|
|
->notAcknowledged() |
|
132
|
|
|
->getRecordCount($countOfJobQueue); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
// To generate the main badge, add both up. |
|
136
|
|
|
// If we add more badges in the future, don't forget to add them here! |
|
137
|
|
|
$countOfAll = $countOfFlagged + $countOfJobQueue; |
|
138
|
|
|
|
|
139
|
|
|
// Set badge variables |
|
140
|
|
|
$this->assign("nav__numFlaggedComments", $countOfFlagged); |
|
141
|
|
|
$this->assign("nav__numJobQueueFailed", $countOfJobQueue); |
|
142
|
|
|
$this->assign("nav__numAdmin", $countOfAll); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|