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