@@ -19,50 +19,50 @@ |
||
| 19 | 19 | |
| 20 | 20 | class NotIdentifiedException extends ReadableException |
| 21 | 21 | { |
| 22 | - use NavigationMenuAccessControl; |
|
| 22 | + use NavigationMenuAccessControl; |
|
| 23 | 23 | |
| 24 | - private ISecurityManager $securityManager; |
|
| 25 | - private IDomainAccessManager $domainAccessManager; |
|
| 24 | + private ISecurityManager $securityManager; |
|
| 25 | + private IDomainAccessManager $domainAccessManager; |
|
| 26 | 26 | |
| 27 | - public function __construct(ISecurityManager $securityManager, IDomainAccessManager $domainAccessManager) |
|
| 28 | - { |
|
| 29 | - $this->securityManager = $securityManager; |
|
| 30 | - $this->domainAccessManager = $domainAccessManager; |
|
| 31 | - } |
|
| 27 | + public function __construct(ISecurityManager $securityManager, IDomainAccessManager $domainAccessManager) |
|
| 28 | + { |
|
| 29 | + $this->securityManager = $securityManager; |
|
| 30 | + $this->domainAccessManager = $domainAccessManager; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Returns a readable HTML error message that's displayable to the user using templates. |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getReadableError() |
|
| 38 | - { |
|
| 39 | - if (!headers_sent()) { |
|
| 40 | - header("HTTP/1.1 403 Forbidden"); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Returns a readable HTML error message that's displayable to the user using templates. |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getReadableError() |
|
| 38 | + { |
|
| 39 | + if (!headers_sent()) { |
|
| 40 | + header("HTTP/1.1 403 Forbidden"); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $this->setUpSmarty(); |
|
| 43 | + $this->setUpSmarty(); |
|
| 44 | 44 | |
| 45 | - // uck. We should still be able to access the database in this situation though. |
|
| 46 | - $database = PdoDatabase::getDatabaseConnection($this->getSiteConfiguration()); |
|
| 47 | - $currentUser = User::getCurrent($database); |
|
| 48 | - $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN)); |
|
| 49 | - $this->assign('currentUser', $currentUser); |
|
| 50 | - $this->assign('currentDomain', Domain::getCurrent($database)); |
|
| 45 | + // uck. We should still be able to access the database in this situation though. |
|
| 46 | + $database = PdoDatabase::getDatabaseConnection($this->getSiteConfiguration()); |
|
| 47 | + $currentUser = User::getCurrent($database); |
|
| 48 | + $this->assign('skin', PreferenceManager::getForCurrent($database)->getPreference(PreferenceManager::PREF_SKIN)); |
|
| 49 | + $this->assign('currentUser', $currentUser); |
|
| 50 | + $this->assign('currentDomain', Domain::getCurrent($database)); |
|
| 51 | 51 | |
| 52 | - if ($this->securityManager !== null) { |
|
| 53 | - $this->setupNavMenuAccess($currentUser); |
|
| 54 | - } |
|
| 52 | + if ($this->securityManager !== null) { |
|
| 53 | + $this->setupNavMenuAccess($currentUser); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $this->fetchTemplate("exception/not-identified.tpl"); |
|
| 57 | - } |
|
| 56 | + return $this->fetchTemplate("exception/not-identified.tpl"); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - protected function getSecurityManager(): ISecurityManager |
|
| 60 | - { |
|
| 61 | - return $this->securityManager; |
|
| 62 | - } |
|
| 59 | + protected function getSecurityManager(): ISecurityManager |
|
| 60 | + { |
|
| 61 | + return $this->securityManager; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function getDomainAccessManager(): IDomainAccessManager |
|
| 65 | - { |
|
| 66 | - return $this->domainAccessManager; |
|
| 67 | - } |
|
| 64 | + public function getDomainAccessManager(): IDomainAccessManager |
|
| 65 | + { |
|
| 66 | + return $this->domainAccessManager; |
|
| 67 | + } |
|
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -18,64 +18,64 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageLog extends PagedInternalPageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->setHtmlTitle('Logs'); |
|
| 27 | - |
|
| 28 | - $filterUser = WebRequest::getString('filterUser'); |
|
| 29 | - $filterAction = WebRequest::getString('filterAction'); |
|
| 30 | - $filterObjectType = WebRequest::getString('filterObjectType'); |
|
| 31 | - $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
| 32 | - |
|
| 33 | - $database = $this->getDatabase(); |
|
| 34 | - |
|
| 35 | - if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
| 36 | - $filterObjectType = null; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 40 | - |
|
| 41 | - // FIXME: domains |
|
| 42 | - $logSearch = LogSearchHelper::get($database, 1); |
|
| 43 | - |
|
| 44 | - if ($filterUser !== null) { |
|
| 45 | - $userObj = User::getByUsername($filterUser, $database); |
|
| 46 | - if ($userObj !== false) { |
|
| 47 | - $logSearch->byUser($userObj->getId()); |
|
| 48 | - } |
|
| 49 | - else { |
|
| 50 | - $logSearch->byUser(-1); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - if ($filterAction !== null) { |
|
| 54 | - $logSearch->byAction($filterAction); |
|
| 55 | - } |
|
| 56 | - if ($filterObjectType !== null) { |
|
| 57 | - $logSearch->byObjectType($filterObjectType); |
|
| 58 | - } |
|
| 59 | - if ($filterObjectId !== null) { |
|
| 60 | - $logSearch->byObjectId($filterObjectId); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $this->setSearchHelper($logSearch); |
|
| 64 | - $this->setupLimits(); |
|
| 65 | - |
|
| 66 | - /** @var Log[] $logs */ |
|
| 67 | - $logs = $logSearch->getRecordCount($count)->fetch(); |
|
| 68 | - |
|
| 69 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager()); |
|
| 70 | - |
|
| 71 | - $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId)); |
|
| 72 | - |
|
| 73 | - $this->assign("logs", $logData); |
|
| 74 | - $this->assign("users", $users); |
|
| 75 | - |
|
| 76 | - $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
| 77 | - $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
| 78 | - |
|
| 79 | - $this->setTemplate("logs/main.tpl"); |
|
| 80 | - } |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->setHtmlTitle('Logs'); |
|
| 27 | + |
|
| 28 | + $filterUser = WebRequest::getString('filterUser'); |
|
| 29 | + $filterAction = WebRequest::getString('filterAction'); |
|
| 30 | + $filterObjectType = WebRequest::getString('filterObjectType'); |
|
| 31 | + $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
| 32 | + |
|
| 33 | + $database = $this->getDatabase(); |
|
| 34 | + |
|
| 35 | + if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
| 36 | + $filterObjectType = null; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 40 | + |
|
| 41 | + // FIXME: domains |
|
| 42 | + $logSearch = LogSearchHelper::get($database, 1); |
|
| 43 | + |
|
| 44 | + if ($filterUser !== null) { |
|
| 45 | + $userObj = User::getByUsername($filterUser, $database); |
|
| 46 | + if ($userObj !== false) { |
|
| 47 | + $logSearch->byUser($userObj->getId()); |
|
| 48 | + } |
|
| 49 | + else { |
|
| 50 | + $logSearch->byUser(-1); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + if ($filterAction !== null) { |
|
| 54 | + $logSearch->byAction($filterAction); |
|
| 55 | + } |
|
| 56 | + if ($filterObjectType !== null) { |
|
| 57 | + $logSearch->byObjectType($filterObjectType); |
|
| 58 | + } |
|
| 59 | + if ($filterObjectId !== null) { |
|
| 60 | + $logSearch->byObjectId($filterObjectId); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $this->setSearchHelper($logSearch); |
|
| 64 | + $this->setupLimits(); |
|
| 65 | + |
|
| 66 | + /** @var Log[] $logs */ |
|
| 67 | + $logs = $logSearch->getRecordCount($count)->fetch(); |
|
| 68 | + |
|
| 69 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager()); |
|
| 70 | + |
|
| 71 | + $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId)); |
|
| 72 | + |
|
| 73 | + $this->assign("logs", $logData); |
|
| 74 | + $this->assign("users", $users); |
|
| 75 | + |
|
| 76 | + $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
| 77 | + $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
| 78 | + |
|
| 79 | + $this->setTemplate("logs/main.tpl"); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -29,309 +29,309 @@ |
||
| 29 | 29 | |
| 30 | 30 | class PageJobQueue extends PagedInternalPageBase |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * Main function for this page, when no specific actions are called. |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - protected function main() |
|
| 37 | - { |
|
| 38 | - $this->setHtmlTitle('Job Queue Management'); |
|
| 39 | - |
|
| 40 | - $this->prepareMaps(); |
|
| 41 | - |
|
| 42 | - $database = $this->getDatabase(); |
|
| 43 | - |
|
| 44 | - /** @var JobQueue[] $jobList */ |
|
| 45 | - // FIXME: domains |
|
| 46 | - $jobList = JobQueueSearchHelper::get($database, 1) |
|
| 47 | - ->statusIn([ |
|
| 48 | - JobQueue::STATUS_QUEUED, |
|
| 49 | - JobQueue::STATUS_READY, |
|
| 50 | - JobQueue::STATUS_WAITING, |
|
| 51 | - JobQueue::STATUS_RUNNING, |
|
| 52 | - JobQueue::STATUS_FAILED, |
|
| 53 | - ]) |
|
| 54 | - ->notAcknowledged() |
|
| 55 | - ->fetch(); |
|
| 56 | - |
|
| 57 | - $userIds = array(); |
|
| 58 | - $requestIds = array(); |
|
| 59 | - |
|
| 60 | - foreach ($jobList as $job) { |
|
| 61 | - $userIds[] = $job->getTriggerUserId(); |
|
| 62 | - $requestIds[] = $job->getRequest(); |
|
| 63 | - |
|
| 64 | - $job->setDatabase($database); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database))); |
|
| 68 | - |
|
| 69 | - $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
| 70 | - // FIXME: domains |
|
| 71 | - $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name')); |
|
| 72 | - |
|
| 73 | - $this->assign('joblist', $jobList); |
|
| 74 | - $this->setTemplate('jobqueue/main.tpl'); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - protected function all() |
|
| 78 | - { |
|
| 79 | - $this->setHtmlTitle('All Jobs'); |
|
| 80 | - |
|
| 81 | - $this->prepareMaps(); |
|
| 82 | - |
|
| 83 | - $database = $this->getDatabase(); |
|
| 84 | - |
|
| 85 | - // FIXME: domains |
|
| 86 | - $searchHelper = JobQueueSearchHelper::get($database, 1); |
|
| 87 | - $this->setSearchHelper($searchHelper); |
|
| 88 | - $this->setupLimits(); |
|
| 89 | - |
|
| 90 | - $filterUser = WebRequest::getString('filterUser'); |
|
| 91 | - $filterTask = WebRequest::getString('filterTask'); |
|
| 92 | - $filterStatus = WebRequest::getString('filterStatus'); |
|
| 93 | - $filterRequest = WebRequest::getString('filterRequest'); |
|
| 94 | - $order = WebRequest::getString('order'); |
|
| 95 | - |
|
| 96 | - if ($filterUser !== null) { |
|
| 97 | - $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($filterTask !== null) { |
|
| 101 | - $searchHelper->byTask($filterTask); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($filterStatus !== null) { |
|
| 105 | - $searchHelper->byStatus($filterStatus); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($filterRequest !== null) { |
|
| 109 | - $searchHelper->byRequest($filterRequest); |
|
| 110 | - } |
|
| 32 | + /** |
|
| 33 | + * Main function for this page, when no specific actions are called. |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + protected function main() |
|
| 37 | + { |
|
| 38 | + $this->setHtmlTitle('Job Queue Management'); |
|
| 39 | + |
|
| 40 | + $this->prepareMaps(); |
|
| 41 | + |
|
| 42 | + $database = $this->getDatabase(); |
|
| 43 | + |
|
| 44 | + /** @var JobQueue[] $jobList */ |
|
| 45 | + // FIXME: domains |
|
| 46 | + $jobList = JobQueueSearchHelper::get($database, 1) |
|
| 47 | + ->statusIn([ |
|
| 48 | + JobQueue::STATUS_QUEUED, |
|
| 49 | + JobQueue::STATUS_READY, |
|
| 50 | + JobQueue::STATUS_WAITING, |
|
| 51 | + JobQueue::STATUS_RUNNING, |
|
| 52 | + JobQueue::STATUS_FAILED, |
|
| 53 | + ]) |
|
| 54 | + ->notAcknowledged() |
|
| 55 | + ->fetch(); |
|
| 56 | + |
|
| 57 | + $userIds = array(); |
|
| 58 | + $requestIds = array(); |
|
| 59 | + |
|
| 60 | + foreach ($jobList as $job) { |
|
| 61 | + $userIds[] = $job->getTriggerUserId(); |
|
| 62 | + $requestIds[] = $job->getRequest(); |
|
| 63 | + |
|
| 64 | + $job->setDatabase($database); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database))); |
|
| 68 | + |
|
| 69 | + $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
| 70 | + // FIXME: domains |
|
| 71 | + $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name')); |
|
| 72 | + |
|
| 73 | + $this->assign('joblist', $jobList); |
|
| 74 | + $this->setTemplate('jobqueue/main.tpl'); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + protected function all() |
|
| 78 | + { |
|
| 79 | + $this->setHtmlTitle('All Jobs'); |
|
| 80 | + |
|
| 81 | + $this->prepareMaps(); |
|
| 82 | + |
|
| 83 | + $database = $this->getDatabase(); |
|
| 84 | + |
|
| 85 | + // FIXME: domains |
|
| 86 | + $searchHelper = JobQueueSearchHelper::get($database, 1); |
|
| 87 | + $this->setSearchHelper($searchHelper); |
|
| 88 | + $this->setupLimits(); |
|
| 89 | + |
|
| 90 | + $filterUser = WebRequest::getString('filterUser'); |
|
| 91 | + $filterTask = WebRequest::getString('filterTask'); |
|
| 92 | + $filterStatus = WebRequest::getString('filterStatus'); |
|
| 93 | + $filterRequest = WebRequest::getString('filterRequest'); |
|
| 94 | + $order = WebRequest::getString('order'); |
|
| 95 | + |
|
| 96 | + if ($filterUser !== null) { |
|
| 97 | + $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($filterTask !== null) { |
|
| 101 | + $searchHelper->byTask($filterTask); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($filterStatus !== null) { |
|
| 105 | + $searchHelper->byStatus($filterStatus); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($filterRequest !== null) { |
|
| 109 | + $searchHelper->byRequest($filterRequest); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - if ($order === null) { |
|
| 113 | - $searchHelper->newestFirst(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** @var JobQueue[] $jobList */ |
|
| 117 | - $jobList = $searchHelper->getRecordCount($count)->fetch(); |
|
| 112 | + if ($order === null) { |
|
| 113 | + $searchHelper->newestFirst(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** @var JobQueue[] $jobList */ |
|
| 117 | + $jobList = $searchHelper->getRecordCount($count)->fetch(); |
|
| 118 | 118 | |
| 119 | - $this->setupPageData($count, array( |
|
| 120 | - 'filterUser' => $filterUser, |
|
| 121 | - 'filterTask' => $filterTask, |
|
| 122 | - 'filterStatus' => $filterStatus, |
|
| 123 | - 'filterRequest' => $filterRequest, |
|
| 124 | - 'order' => $order, |
|
| 125 | - )); |
|
| 119 | + $this->setupPageData($count, array( |
|
| 120 | + 'filterUser' => $filterUser, |
|
| 121 | + 'filterTask' => $filterTask, |
|
| 122 | + 'filterStatus' => $filterStatus, |
|
| 123 | + 'filterRequest' => $filterRequest, |
|
| 124 | + 'order' => $order, |
|
| 125 | + )); |
|
| 126 | 126 | |
| 127 | - $userIds = array(); |
|
| 128 | - $requestIds = array(); |
|
| 127 | + $userIds = array(); |
|
| 128 | + $requestIds = array(); |
|
| 129 | 129 | |
| 130 | - foreach ($jobList as $job) { |
|
| 131 | - $userIds[] = $job->getTriggerUserId(); |
|
| 132 | - $requestIds[] = $job->getRequest(); |
|
| 130 | + foreach ($jobList as $job) { |
|
| 131 | + $userIds[] = $job->getTriggerUserId(); |
|
| 132 | + $requestIds[] = $job->getRequest(); |
|
| 133 | 133 | |
| 134 | - $job->setDatabase($database); |
|
| 135 | - } |
|
| 134 | + $job->setDatabase($database); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 138 | - return UserSearchHelper::get($database)->fetchColumn('username'); |
|
| 139 | - }); |
|
| 137 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 138 | + return UserSearchHelper::get($database)->fetchColumn('username'); |
|
| 139 | + }); |
|
| 140 | 140 | |
| 141 | - $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
| 142 | - // FIXME: domains! |
|
| 143 | - $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name')); |
|
| 141 | + $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username')); |
|
| 142 | + // FIXME: domains! |
|
| 143 | + $this->assign('requests', RequestSearchHelper::get($database, 1)->inIds($requestIds)->fetchMap('name')); |
|
| 144 | 144 | |
| 145 | - $this->assign('joblist', $jobList); |
|
| 145 | + $this->assign('joblist', $jobList); |
|
| 146 | 146 | |
| 147 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 147 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 148 | 148 | |
| 149 | - $this->setTemplate('jobqueue/all.tpl'); |
|
| 150 | - } |
|
| 149 | + $this->setTemplate('jobqueue/all.tpl'); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - protected function view() |
|
| 153 | - { |
|
| 154 | - $jobId = WebRequest::getInt('id'); |
|
| 155 | - $database = $this->getDatabase(); |
|
| 152 | + protected function view() |
|
| 153 | + { |
|
| 154 | + $jobId = WebRequest::getInt('id'); |
|
| 155 | + $database = $this->getDatabase(); |
|
| 156 | 156 | |
| 157 | - if ($jobId === null) { |
|
| 158 | - throw new ApplicationLogicException('No job specified'); |
|
| 159 | - } |
|
| 157 | + if ($jobId === null) { |
|
| 158 | + throw new ApplicationLogicException('No job specified'); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** @var JobQueue $job */ |
|
| 162 | - $job = JobQueue::getById($jobId, $database); |
|
| 161 | + /** @var JobQueue $job */ |
|
| 162 | + $job = JobQueue::getById($jobId, $database); |
|
| 163 | 163 | |
| 164 | - if ($job === false) { |
|
| 165 | - throw new ApplicationLogicException('Could not find requested job'); |
|
| 166 | - } |
|
| 164 | + if ($job === false) { |
|
| 165 | + throw new ApplicationLogicException('Could not find requested job'); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $this->prepareMaps(); |
|
| 168 | + $this->prepareMaps(); |
|
| 169 | 169 | |
| 170 | - $this->assign('user', User::getById($job->getTriggerUserId(), $database)); |
|
| 171 | - $this->assign('request', Request::getById($job->getRequest(), $database)); |
|
| 172 | - $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database)); |
|
| 173 | - $this->assign('parent', JobQueue::getById($job->getParent(), $database)); |
|
| 170 | + $this->assign('user', User::getById($job->getTriggerUserId(), $database)); |
|
| 171 | + $this->assign('request', Request::getById($job->getRequest(), $database)); |
|
| 172 | + $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database)); |
|
| 173 | + $this->assign('parent', JobQueue::getById($job->getParent(), $database)); |
|
| 174 | 174 | |
| 175 | - /** @var Log[] $logs */ |
|
| 176 | - // FIXME: domains |
|
| 177 | - $logs = LogSearchHelper::get($database, 1)->byObjectType('JobQueue') |
|
| 178 | - ->byObjectId($job->getId())->getRecordCount($logCount)->fetch(); |
|
| 179 | - if ($logCount === 0) { |
|
| 180 | - $this->assign('log', array()); |
|
| 181 | - } |
|
| 182 | - else { |
|
| 183 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager()); |
|
| 175 | + /** @var Log[] $logs */ |
|
| 176 | + // FIXME: domains |
|
| 177 | + $logs = LogSearchHelper::get($database, 1)->byObjectType('JobQueue') |
|
| 178 | + ->byObjectId($job->getId())->getRecordCount($logCount)->fetch(); |
|
| 179 | + if ($logCount === 0) { |
|
| 180 | + $this->assign('log', array()); |
|
| 181 | + } |
|
| 182 | + else { |
|
| 183 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager()); |
|
| 184 | 184 | |
| 185 | - $this->assign("log", $logData); |
|
| 186 | - $this->assign("users", $users); |
|
| 187 | - } |
|
| 185 | + $this->assign("log", $logData); |
|
| 186 | + $this->assign("users", $users); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - $this->assignCSRFToken(); |
|
| 189 | + $this->assignCSRFToken(); |
|
| 190 | 190 | |
| 191 | - $this->assign('job', $job); |
|
| 191 | + $this->assign('job', $job); |
|
| 192 | 192 | |
| 193 | - $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database))); |
|
| 194 | - $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database))); |
|
| 195 | - $this->assign('canCancel', $this->barrierTest('cancel', User::getCurrent($database))); |
|
| 193 | + $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database))); |
|
| 194 | + $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database))); |
|
| 195 | + $this->assign('canCancel', $this->barrierTest('cancel', User::getCurrent($database))); |
|
| 196 | 196 | |
| 197 | - if ($job->getTask() === UserCreationTask::class || $job->getTask() === BotCreationTask::class) { |
|
| 198 | - if ($job->getEmailTemplate() === null) { |
|
| 199 | - $params = json_decode($job->getParameters()); |
|
| 197 | + if ($job->getTask() === UserCreationTask::class || $job->getTask() === BotCreationTask::class) { |
|
| 198 | + if ($job->getEmailTemplate() === null) { |
|
| 199 | + $params = json_decode($job->getParameters()); |
|
| 200 | 200 | |
| 201 | - if (isset($params->emailText)) { |
|
| 202 | - $this->assign("creationEmailText", $params->emailText); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 201 | + if (isset($params->emailText)) { |
|
| 202 | + $this->assign("creationEmailText", $params->emailText); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $this->setHtmlTitle('Job #{$job->getId()|escape}'); |
|
| 208 | - $this->setTemplate('jobqueue/view.tpl'); |
|
| 209 | - } |
|
| 207 | + $this->setHtmlTitle('Job #{$job->getId()|escape}'); |
|
| 208 | + $this->setTemplate('jobqueue/view.tpl'); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - protected function acknowledge() |
|
| 212 | - { |
|
| 213 | - if (!WebRequest::wasPosted()) { |
|
| 214 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 215 | - } |
|
| 211 | + protected function acknowledge() |
|
| 212 | + { |
|
| 213 | + if (!WebRequest::wasPosted()) { |
|
| 214 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - $this->validateCSRFToken(); |
|
| 217 | + $this->validateCSRFToken(); |
|
| 218 | 218 | |
| 219 | - $jobId = WebRequest::postInt('job'); |
|
| 220 | - $database = $this->getDatabase(); |
|
| 219 | + $jobId = WebRequest::postInt('job'); |
|
| 220 | + $database = $this->getDatabase(); |
|
| 221 | 221 | |
| 222 | - if ($jobId === null) { |
|
| 223 | - throw new ApplicationLogicException('No job specified'); |
|
| 224 | - } |
|
| 222 | + if ($jobId === null) { |
|
| 223 | + throw new ApplicationLogicException('No job specified'); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** @var JobQueue $job */ |
|
| 227 | - $job = JobQueue::getById($jobId, $database); |
|
| 226 | + /** @var JobQueue $job */ |
|
| 227 | + $job = JobQueue::getById($jobId, $database); |
|
| 228 | 228 | |
| 229 | - if ($job === false) { |
|
| 230 | - throw new ApplicationLogicException('Could not find requested job'); |
|
| 231 | - } |
|
| 229 | + if ($job === false) { |
|
| 230 | + throw new ApplicationLogicException('Could not find requested job'); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
| 234 | - $job->setAcknowledged(true); |
|
| 235 | - $job->save(); |
|
| 233 | + $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
| 234 | + $job->setAcknowledged(true); |
|
| 235 | + $job->save(); |
|
| 236 | 236 | |
| 237 | - Logger::backgroundJobAcknowledged($database, $job); |
|
| 237 | + Logger::backgroundJobAcknowledged($database, $job); |
|
| 238 | 238 | |
| 239 | - $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - protected function cancel() |
|
| 243 | - { |
|
| 244 | - if (!WebRequest::wasPosted()) { |
|
| 245 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - $this->validateCSRFToken(); |
|
| 249 | - |
|
| 250 | - $jobId = WebRequest::postInt('job'); |
|
| 251 | - $database = $this->getDatabase(); |
|
| 252 | - |
|
| 253 | - if ($jobId === null) { |
|
| 254 | - throw new ApplicationLogicException('No job specified'); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** @var JobQueue $job */ |
|
| 258 | - $job = JobQueue::getById($jobId, $database); |
|
| 259 | - |
|
| 260 | - if ($job === false) { |
|
| 261 | - throw new ApplicationLogicException('Could not find requested job'); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($job->getStatus() !== JobQueue::STATUS_READY |
|
| 265 | - && $job->getStatus() !== JobQueue::STATUS_QUEUED |
|
| 266 | - && $job->getStatus() === JobQueue::STATUS_WAITING) { |
|
| 267 | - throw new ApplicationLogicException('Cannot cancel job not queued for execution'); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
| 271 | - $job->setStatus(JobQueue::STATUS_CANCELLED); |
|
| 272 | - $job->setError("Manually cancelled"); |
|
| 273 | - $job->setAcknowledged(null); |
|
| 274 | - $job->save(); |
|
| 275 | - |
|
| 276 | - Logger::backgroundJobCancelled($this->getDatabase(), $job); |
|
| 277 | - |
|
| 278 | - $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - protected function requeue() |
|
| 282 | - { |
|
| 283 | - if (!WebRequest::wasPosted()) { |
|
| 284 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 285 | - } |
|
| 239 | + $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + protected function cancel() |
|
| 243 | + { |
|
| 244 | + if (!WebRequest::wasPosted()) { |
|
| 245 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + $this->validateCSRFToken(); |
|
| 249 | + |
|
| 250 | + $jobId = WebRequest::postInt('job'); |
|
| 251 | + $database = $this->getDatabase(); |
|
| 252 | + |
|
| 253 | + if ($jobId === null) { |
|
| 254 | + throw new ApplicationLogicException('No job specified'); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** @var JobQueue $job */ |
|
| 258 | + $job = JobQueue::getById($jobId, $database); |
|
| 259 | + |
|
| 260 | + if ($job === false) { |
|
| 261 | + throw new ApplicationLogicException('Could not find requested job'); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($job->getStatus() !== JobQueue::STATUS_READY |
|
| 265 | + && $job->getStatus() !== JobQueue::STATUS_QUEUED |
|
| 266 | + && $job->getStatus() === JobQueue::STATUS_WAITING) { |
|
| 267 | + throw new ApplicationLogicException('Cannot cancel job not queued for execution'); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
| 271 | + $job->setStatus(JobQueue::STATUS_CANCELLED); |
|
| 272 | + $job->setError("Manually cancelled"); |
|
| 273 | + $job->setAcknowledged(null); |
|
| 274 | + $job->save(); |
|
| 275 | + |
|
| 276 | + Logger::backgroundJobCancelled($this->getDatabase(), $job); |
|
| 277 | + |
|
| 278 | + $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + protected function requeue() |
|
| 282 | + { |
|
| 283 | + if (!WebRequest::wasPosted()) { |
|
| 284 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - $this->validateCSRFToken(); |
|
| 287 | + $this->validateCSRFToken(); |
|
| 288 | 288 | |
| 289 | - $jobId = WebRequest::postInt('job'); |
|
| 290 | - $database = $this->getDatabase(); |
|
| 291 | - |
|
| 292 | - if ($jobId === null) { |
|
| 293 | - throw new ApplicationLogicException('No job specified'); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** @var JobQueue|false $job */ |
|
| 297 | - $job = JobQueue::getById($jobId, $database); |
|
| 298 | - |
|
| 299 | - if ($job === false) { |
|
| 300 | - throw new ApplicationLogicException('Could not find requested job'); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - $job->setStatus(JobQueue::STATUS_QUEUED); |
|
| 304 | - $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
| 305 | - $job->setAcknowledged(null); |
|
| 306 | - $job->setError(null); |
|
| 307 | - $job->save(); |
|
| 308 | - |
|
| 309 | - /** @var Request $request */ |
|
| 310 | - $request = Request::getById($job->getRequest(), $database); |
|
| 311 | - $request->setStatus(RequestStatus::JOBQUEUE); |
|
| 312 | - $request->save(); |
|
| 313 | - |
|
| 314 | - Logger::enqueuedJobQueue($database, $request); |
|
| 315 | - Logger::backgroundJobRequeued($database, $job); |
|
| 289 | + $jobId = WebRequest::postInt('job'); |
|
| 290 | + $database = $this->getDatabase(); |
|
| 291 | + |
|
| 292 | + if ($jobId === null) { |
|
| 293 | + throw new ApplicationLogicException('No job specified'); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** @var JobQueue|false $job */ |
|
| 297 | + $job = JobQueue::getById($jobId, $database); |
|
| 298 | + |
|
| 299 | + if ($job === false) { |
|
| 300 | + throw new ApplicationLogicException('Could not find requested job'); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + $job->setStatus(JobQueue::STATUS_QUEUED); |
|
| 304 | + $job->setUpdateVersion(WebRequest::postInt('updateVersion')); |
|
| 305 | + $job->setAcknowledged(null); |
|
| 306 | + $job->setError(null); |
|
| 307 | + $job->save(); |
|
| 308 | + |
|
| 309 | + /** @var Request $request */ |
|
| 310 | + $request = Request::getById($job->getRequest(), $database); |
|
| 311 | + $request->setStatus(RequestStatus::JOBQUEUE); |
|
| 312 | + $request->save(); |
|
| 313 | + |
|
| 314 | + Logger::enqueuedJobQueue($database, $request); |
|
| 315 | + Logger::backgroundJobRequeued($database, $job); |
|
| 316 | 316 | |
| 317 | - $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - protected function prepareMaps() |
|
| 321 | - { |
|
| 322 | - $taskNameMap = JobQueue::getTaskDescriptions(); |
|
| 323 | - |
|
| 324 | - $statusDecriptionMap = array( |
|
| 325 | - JobQueue::STATUS_CANCELLED => 'The job was cancelled', |
|
| 326 | - JobQueue::STATUS_COMPLETE => 'The job completed successfully', |
|
| 327 | - JobQueue::STATUS_FAILED => 'The job encountered an error', |
|
| 328 | - JobQueue::STATUS_QUEUED => 'The job is in the queue', |
|
| 329 | - JobQueue::STATUS_READY => 'The job is ready to be picked up by the next job runner execution', |
|
| 330 | - JobQueue::STATUS_RUNNING => 'The job is being run right now by the job runner', |
|
| 331 | - JobQueue::STATUS_WAITING => 'The job has been picked up by a job runner', |
|
| 332 | - JobQueue::STATUS_HELD => 'The job has manually held from processing', |
|
| 333 | - ); |
|
| 334 | - $this->assign('taskNameMap', $taskNameMap); |
|
| 335 | - $this->assign('statusDescriptionMap', $statusDecriptionMap); |
|
| 336 | - } |
|
| 317 | + $this->redirect('jobQueue', 'view', array('id' => $jobId)); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + protected function prepareMaps() |
|
| 321 | + { |
|
| 322 | + $taskNameMap = JobQueue::getTaskDescriptions(); |
|
| 323 | + |
|
| 324 | + $statusDecriptionMap = array( |
|
| 325 | + JobQueue::STATUS_CANCELLED => 'The job was cancelled', |
|
| 326 | + JobQueue::STATUS_COMPLETE => 'The job completed successfully', |
|
| 327 | + JobQueue::STATUS_FAILED => 'The job encountered an error', |
|
| 328 | + JobQueue::STATUS_QUEUED => 'The job is in the queue', |
|
| 329 | + JobQueue::STATUS_READY => 'The job is ready to be picked up by the next job runner execution', |
|
| 330 | + JobQueue::STATUS_RUNNING => 'The job is being run right now by the job runner', |
|
| 331 | + JobQueue::STATUS_WAITING => 'The job has been picked up by a job runner', |
|
| 332 | + JobQueue::STATUS_HELD => 'The job has manually held from processing', |
|
| 333 | + ); |
|
| 334 | + $this->assign('taskNameMap', $taskNameMap); |
|
| 335 | + $this->assign('statusDescriptionMap', $statusDecriptionMap); |
|
| 336 | + } |
|
| 337 | 337 | } |
@@ -30,578 +30,578 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class PageUserManagement extends InternalPageBase |
| 32 | 32 | { |
| 33 | - // FIXME: domains |
|
| 34 | - /** @var string */ |
|
| 35 | - private $adminMailingList = '[email protected]'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Main function for this page, when no specific actions are called. |
|
| 39 | - */ |
|
| 40 | - protected function main() |
|
| 41 | - { |
|
| 42 | - $this->setHtmlTitle('User Management'); |
|
| 43 | - |
|
| 44 | - $database = $this->getDatabase(); |
|
| 45 | - $currentUser = User::getCurrent($database); |
|
| 46 | - |
|
| 47 | - $userSearchRequest = WebRequest::getString('usersearch'); |
|
| 48 | - if ($userSearchRequest !== null) { |
|
| 49 | - $searchedUser = User::getByUsername($userSearchRequest, $database); |
|
| 50 | - if ($searchedUser !== false) { |
|
| 51 | - $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
|
| 52 | - return; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
| 57 | - // the template. I still don't have a particularly good way of handling this. |
|
| 58 | - OAuthUserHelper::prepareTokenCountStatement($database); |
|
| 59 | - |
|
| 60 | - if (WebRequest::getBoolean("showAll")) { |
|
| 61 | - $this->assign("showAll", true); |
|
| 62 | - |
|
| 63 | - $deactivatedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DEACTIVATED)->fetch(); |
|
| 64 | - $this->assign('deactivatedUsers', $deactivatedUsers); |
|
| 65 | - |
|
| 66 | - UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
| 67 | - } |
|
| 68 | - else { |
|
| 69 | - $this->assign("showAll", false); |
|
| 70 | - $this->assign('deactivatedUsers', array()); |
|
| 71 | - |
|
| 72 | - UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
| 76 | - $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
| 77 | - $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
| 78 | - $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
| 79 | - $stewards = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('steward')->fetch(); |
|
| 80 | - $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
| 81 | - $this->assign('newUsers', $newUsers); |
|
| 82 | - $this->assign('normalUsers', $normalUsers); |
|
| 83 | - $this->assign('adminUsers', $adminUsers); |
|
| 84 | - $this->assign('checkUsers', $checkUsers); |
|
| 85 | - $this->assign('stewards', $stewards); |
|
| 86 | - $this->assign('toolRoots', $toolRoots); |
|
| 87 | - |
|
| 88 | - $this->assign('roles', $roleMap); |
|
| 89 | - |
|
| 90 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 91 | - |
|
| 92 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
| 93 | - $this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser)); |
|
| 94 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
| 95 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
| 96 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
| 97 | - |
|
| 98 | - // FIXME: domains! |
|
| 99 | - /** @var Domain $domain */ |
|
| 100 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 101 | - $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
| 102 | - |
|
| 103 | - $this->setTemplate("usermanagement/main.tpl"); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - #region Access control |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Action target for editing the roles assigned to a user |
|
| 110 | - * |
|
| 111 | - * @throws ApplicationLogicException |
|
| 112 | - * @throws SmartyException |
|
| 113 | - * @throws OptimisticLockFailedException |
|
| 114 | - * @throws Exception |
|
| 115 | - */ |
|
| 116 | - protected function editRoles(): void |
|
| 117 | - { |
|
| 118 | - $this->setHtmlTitle('User Management'); |
|
| 119 | - $database = $this->getDatabase(); |
|
| 120 | - $domain = Domain::getCurrent($database); |
|
| 121 | - $userId = WebRequest::getInt('user'); |
|
| 122 | - |
|
| 123 | - /** @var User|false $user */ |
|
| 124 | - $user = User::getById($userId, $database); |
|
| 125 | - |
|
| 126 | - if ($user === false || $user->isCommunityUser()) { |
|
| 127 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database, $domain->getId())); |
|
| 131 | - |
|
| 132 | - // Dual-mode action |
|
| 133 | - if (WebRequest::wasPosted()) { |
|
| 134 | - $this->validateCSRFToken(); |
|
| 135 | - |
|
| 136 | - $reason = WebRequest::postString('reason'); |
|
| 137 | - if ($reason === false || trim($reason) === '') { |
|
| 138 | - throw new ApplicationLogicException('No reason specified for roles change'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** @var UserRole[] $delete */ |
|
| 142 | - $delete = array(); |
|
| 143 | - /** @var string[] $add */ |
|
| 144 | - $add = array(); |
|
| 145 | - |
|
| 146 | - /** @var UserRole[] $globalDelete */ |
|
| 147 | - $globalDelete = array(); |
|
| 148 | - /** @var string[] $globalAdd */ |
|
| 149 | - $globalAdd = array(); |
|
| 150 | - |
|
| 151 | - foreach ($roleData as $name => $r) { |
|
| 152 | - if ($r['allowEdit'] !== 1) { |
|
| 153 | - // not allowed, to touch this, so ignore it |
|
| 154 | - continue; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
| 158 | - if ($newValue !== $r['active']) { |
|
| 159 | - if ($newValue === 0) { |
|
| 160 | - if ($r['globalOnly']) { |
|
| 161 | - $globalDelete[] = $r['object']; |
|
| 162 | - } |
|
| 163 | - else { |
|
| 164 | - $delete[] = $r['object']; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if ($newValue === 1) { |
|
| 169 | - if ($r['globalOnly']) { |
|
| 170 | - $globalAdd[] = $name; |
|
| 171 | - } |
|
| 172 | - else { |
|
| 173 | - $add[] = $name; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Check there's something to do |
|
| 180 | - if ((count($add) + count($delete) + count($globalAdd) + count($globalDelete)) === 0) { |
|
| 181 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 182 | - SessionAlert::warning('No changes made to roles.'); |
|
| 183 | - |
|
| 184 | - return; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $removed = array(); |
|
| 188 | - $globalRemoved = array(); |
|
| 189 | - |
|
| 190 | - foreach ($delete as $d) { |
|
| 191 | - $removed[] = $d->getRole(); |
|
| 192 | - $d->delete(); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - foreach ($globalDelete as $d) { |
|
| 196 | - $globalRemoved[] = $d->getRole(); |
|
| 197 | - $d->delete(); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - foreach ($add as $x) { |
|
| 201 | - $a = new UserRole(); |
|
| 202 | - $a->setUser($user->getId()); |
|
| 203 | - $a->setRole($x); |
|
| 204 | - $a->setDomain($domain->getId()); |
|
| 205 | - $a->setDatabase($database); |
|
| 206 | - $a->save(); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - foreach ($globalAdd as $x) { |
|
| 210 | - $a = new UserRole(); |
|
| 211 | - $a->setUser($user->getId()); |
|
| 212 | - $a->setRole($x); |
|
| 213 | - $a->setDomain(null); |
|
| 214 | - $a->setDatabase($database); |
|
| 215 | - $a->save(); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ((count($add) + count($delete)) > 0) { |
|
| 219 | - Logger::userRolesEdited($database, $user, $reason, $add, $removed, $domain->getId()); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if ((count($globalAdd) + count($globalDelete)) > 0) { |
|
| 223 | - Logger::userGlobalRolesEdited($database, $user, $reason, $globalAdd, $globalRemoved); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
| 227 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 228 | - $user->save(); |
|
| 229 | - |
|
| 230 | - $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
| 231 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 232 | - |
|
| 233 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 234 | - } |
|
| 235 | - else { |
|
| 236 | - $this->assignCSRFToken(); |
|
| 237 | - $this->setTemplate('usermanagement/roleedit.tpl'); |
|
| 238 | - $this->assign('user', $user); |
|
| 239 | - $this->assign('roleData', $roleData); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Action target for deactivating users |
|
| 245 | - * |
|
| 246 | - * @throws ApplicationLogicException |
|
| 247 | - */ |
|
| 248 | - protected function deactivate() |
|
| 249 | - { |
|
| 250 | - $this->setHtmlTitle('User Management'); |
|
| 251 | - |
|
| 252 | - $database = $this->getDatabase(); |
|
| 253 | - |
|
| 254 | - $userId = WebRequest::getInt('user'); |
|
| 255 | - |
|
| 256 | - /** @var User $user */ |
|
| 257 | - $user = User::getById($userId, $database); |
|
| 258 | - |
|
| 259 | - if ($user === false || $user->isCommunityUser()) { |
|
| 260 | - throw new ApplicationLogicException('Sorry, the user you are trying to deactivate could not be found.'); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ($user->isDeactivated()) { |
|
| 264 | - throw new ApplicationLogicException('Sorry, the user you are trying to deactivate is already deactivated.'); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // Dual-mode action |
|
| 268 | - if (WebRequest::wasPosted()) { |
|
| 269 | - $this->validateCSRFToken(); |
|
| 270 | - $reason = WebRequest::postString('reason'); |
|
| 271 | - |
|
| 272 | - if ($reason === null || trim($reason) === '') { |
|
| 273 | - throw new ApplicationLogicException('No reason provided'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $user->setStatus(User::STATUS_DEACTIVATED); |
|
| 277 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 278 | - $user->save(); |
|
| 279 | - Logger::deactivatedUser($database, $user, $reason); |
|
| 280 | - |
|
| 281 | - $this->getNotificationHelper()->userDeactivated($user); |
|
| 282 | - SessionAlert::quick('Deactivated user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 283 | - |
|
| 284 | - // send email |
|
| 285 | - $this->sendStatusChangeEmail( |
|
| 286 | - 'Your WP:ACC account has been deactivated', |
|
| 287 | - 'usermanagement/emails/deactivated.tpl', |
|
| 288 | - $reason, |
|
| 289 | - $user, |
|
| 290 | - User::getCurrent($database)->getUsername() |
|
| 291 | - ); |
|
| 292 | - |
|
| 293 | - $this->redirect('userManagement'); |
|
| 294 | - |
|
| 295 | - return; |
|
| 296 | - } |
|
| 297 | - else { |
|
| 298 | - $this->assignCSRFToken(); |
|
| 299 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
| 300 | - $this->assign('user', $user); |
|
| 301 | - $this->assign('status', User::STATUS_DEACTIVATED); |
|
| 302 | - $this->assign("showReason", true); |
|
| 303 | - |
|
| 304 | - if (WebRequest::getString('preload')) { |
|
| 305 | - $this->assign('preload', WebRequest::getString('preload')); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Entry point for the approve action |
|
| 312 | - * |
|
| 313 | - * @throws ApplicationLogicException |
|
| 314 | - */ |
|
| 315 | - protected function approve() |
|
| 316 | - { |
|
| 317 | - $this->setHtmlTitle('User Management'); |
|
| 318 | - |
|
| 319 | - $database = $this->getDatabase(); |
|
| 320 | - |
|
| 321 | - $userId = WebRequest::getInt('user'); |
|
| 322 | - $user = User::getById($userId, $database); |
|
| 323 | - |
|
| 324 | - if ($user === false || $user->isCommunityUser()) { |
|
| 325 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - if ($user->isActive()) { |
|
| 329 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // Dual-mode action |
|
| 333 | - if (WebRequest::wasPosted()) { |
|
| 334 | - $this->validateCSRFToken(); |
|
| 335 | - $user->setStatus(User::STATUS_ACTIVE); |
|
| 336 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 337 | - $user->save(); |
|
| 338 | - Logger::approvedUser($database, $user); |
|
| 339 | - |
|
| 340 | - $this->getNotificationHelper()->userApproved($user); |
|
| 341 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 342 | - |
|
| 343 | - // send email |
|
| 344 | - $this->sendStatusChangeEmail( |
|
| 345 | - 'Your WP:ACC account has been approved', |
|
| 346 | - 'usermanagement/emails/approved.tpl', |
|
| 347 | - null, |
|
| 348 | - $user, |
|
| 349 | - User::getCurrent($database)->getUsername() |
|
| 350 | - ); |
|
| 351 | - |
|
| 352 | - $this->redirect("userManagement"); |
|
| 353 | - |
|
| 354 | - return; |
|
| 355 | - } |
|
| 356 | - else { |
|
| 357 | - $this->assignCSRFToken(); |
|
| 358 | - $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
| 359 | - $this->assign("user", $user); |
|
| 360 | - $this->assign("status", "Active"); |
|
| 361 | - $this->assign("showReason", false); |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - #endregion |
|
| 366 | - |
|
| 367 | - #region Renaming / Editing |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Entry point for the rename action |
|
| 371 | - * |
|
| 372 | - * @throws ApplicationLogicException |
|
| 373 | - */ |
|
| 374 | - protected function rename() |
|
| 375 | - { |
|
| 376 | - $this->setHtmlTitle('User Management'); |
|
| 377 | - |
|
| 378 | - $database = $this->getDatabase(); |
|
| 379 | - |
|
| 380 | - $userId = WebRequest::getInt('user'); |
|
| 381 | - $user = User::getById($userId, $database); |
|
| 382 | - |
|
| 383 | - if ($user === false || $user->isCommunityUser()) { |
|
| 384 | - throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - // Dual-mode action |
|
| 388 | - if (WebRequest::wasPosted()) { |
|
| 389 | - $this->validateCSRFToken(); |
|
| 390 | - $newUsername = WebRequest::postString('newname'); |
|
| 391 | - |
|
| 392 | - if ($newUsername === null || trim($newUsername) === "") { |
|
| 393 | - throw new ApplicationLogicException('The new username cannot be empty'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if (User::getByUsername($newUsername, $database) != false) { |
|
| 397 | - throw new ApplicationLogicException('The new username already exists'); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - $oldUsername = $user->getUsername(); |
|
| 401 | - $user->setUsername($newUsername); |
|
| 402 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 403 | - |
|
| 404 | - $user->save(); |
|
| 405 | - |
|
| 406 | - $logEntryData = serialize(array( |
|
| 407 | - 'old' => $oldUsername, |
|
| 408 | - 'new' => $newUsername, |
|
| 409 | - )); |
|
| 410 | - |
|
| 411 | - Logger::renamedUser($database, $user, $logEntryData); |
|
| 412 | - |
|
| 413 | - SessionAlert::quick("Changed User " |
|
| 414 | - . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
| 415 | - . " name to " |
|
| 416 | - . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
| 417 | - |
|
| 418 | - $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
| 419 | - |
|
| 420 | - // send an email to the user. |
|
| 421 | - $this->assign('targetUsername', $user->getUsername()); |
|
| 422 | - $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
| 423 | - $this->assign('oldUsername', $oldUsername); |
|
| 424 | - $this->assign('mailingList', $this->adminMailingList); |
|
| 425 | - |
|
| 426 | - // FIXME: domains! |
|
| 427 | - /** @var Domain $domain */ |
|
| 428 | - $domain = Domain::getById(1, $database); |
|
| 429 | - $this->getEmailHelper()->sendMail( |
|
| 430 | - $this->adminMailingList, |
|
| 431 | - $user->getEmail(), |
|
| 432 | - 'Your username on WP:ACC has been changed', |
|
| 433 | - $this->fetchTemplate('usermanagement/emails/renamed.tpl') |
|
| 434 | - ); |
|
| 435 | - |
|
| 436 | - $this->redirect("userManagement"); |
|
| 437 | - |
|
| 438 | - return; |
|
| 439 | - } |
|
| 440 | - else { |
|
| 441 | - $this->assignCSRFToken(); |
|
| 442 | - $this->setTemplate('usermanagement/renameuser.tpl'); |
|
| 443 | - $this->assign('user', $user); |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Entry point for the edit action |
|
| 449 | - * |
|
| 450 | - * @throws ApplicationLogicException |
|
| 451 | - */ |
|
| 452 | - protected function editUser() |
|
| 453 | - { |
|
| 454 | - $this->setHtmlTitle('User Management'); |
|
| 455 | - |
|
| 456 | - $database = $this->getDatabase(); |
|
| 457 | - |
|
| 458 | - $userId = WebRequest::getInt('user'); |
|
| 459 | - $user = User::getById($userId, $database); |
|
| 460 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 461 | - |
|
| 462 | - if ($user === false || $user->isCommunityUser()) { |
|
| 463 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - // FIXME: domains |
|
| 467 | - $prefs = new PreferenceManager($database, $user->getId(), 1); |
|
| 468 | - |
|
| 469 | - // Dual-mode action |
|
| 470 | - if (WebRequest::wasPosted()) { |
|
| 471 | - $this->validateCSRFToken(); |
|
| 472 | - $newEmail = WebRequest::postEmail('user_email'); |
|
| 473 | - $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
| 474 | - |
|
| 475 | - if ($newEmail === null) { |
|
| 476 | - throw new ApplicationLogicException('Invalid email address'); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if ($this->validateUnusedEmail($newEmail, $userId)) { |
|
| 480 | - throw new ApplicationLogicException('The specified email address is already in use.'); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) { |
|
| 484 | - if (trim($newOnWikiName) == "") { |
|
| 485 | - throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - $user->setOnWikiName($newOnWikiName); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - $user->setEmail($newEmail); |
|
| 492 | - |
|
| 493 | - $prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode')); |
|
| 494 | - |
|
| 495 | - $prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation')); |
|
| 496 | - |
|
| 497 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 498 | - |
|
| 499 | - $user->save(); |
|
| 500 | - |
|
| 501 | - Logger::userPreferencesChange($database, $user); |
|
| 502 | - $this->getNotificationHelper()->userPrefChange($user); |
|
| 503 | - SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
| 504 | - |
|
| 505 | - $this->redirect("userManagement"); |
|
| 506 | - |
|
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - else { |
|
| 510 | - $this->assignCSRFToken(); |
|
| 511 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 512 | - $this->getSiteConfiguration()); |
|
| 513 | - $this->setTemplate('usermanagement/edituser.tpl'); |
|
| 514 | - $this->assign('user', $user); |
|
| 515 | - $this->assign('oauth', $oauth); |
|
| 516 | - |
|
| 517 | - $this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE)); |
|
| 518 | - $this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE)); |
|
| 519 | - |
|
| 520 | - $this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false); |
|
| 521 | - |
|
| 522 | - $this->assign('canManualCreate', |
|
| 523 | - $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 524 | - $this->assign('canOauthCreate', |
|
| 525 | - $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 526 | - $this->assign('canBotCreate', |
|
| 527 | - $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation')); |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - #endregion |
|
| 532 | - |
|
| 533 | - private function validateUnusedEmail(string $email, int $userId) : bool { |
|
| 534 | - $query = 'SELECT COUNT(id) FROM user WHERE email = :email AND id <> :uid'; |
|
| 535 | - $statement = $this->getDatabase()->prepare($query); |
|
| 536 | - $statement->execute(array(':email' => $email, ':uid' => $userId)); |
|
| 537 | - $inUse = $statement->fetchColumn() > 0; |
|
| 538 | - $statement->closeCursor(); |
|
| 539 | - |
|
| 540 | - return $inUse; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Sends a status change email to the user. |
|
| 545 | - * |
|
| 546 | - * @param string $subject The subject of the email |
|
| 547 | - * @param string $template The smarty template to use |
|
| 548 | - * @param string|null $reason The reason for performing the status change |
|
| 549 | - * @param User $user The user affected |
|
| 550 | - * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
| 551 | - */ |
|
| 552 | - private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
| 553 | - { |
|
| 554 | - $this->assign('targetUsername', $user->getUsername()); |
|
| 555 | - $this->assign('toolAdmin', $toolAdminUsername); |
|
| 556 | - $this->assign('actionReason', $reason); |
|
| 557 | - $this->assign('mailingList', $this->adminMailingList); |
|
| 558 | - |
|
| 559 | - // FIXME: domains! |
|
| 560 | - /** @var Domain $domain */ |
|
| 561 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 562 | - $this->getEmailHelper()->sendMail( |
|
| 563 | - $this->adminMailingList, |
|
| 564 | - $user->getEmail(), |
|
| 565 | - $subject, |
|
| 566 | - $this->fetchTemplate($template) |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * @param UserRole[] $activeRoles |
|
| 572 | - * |
|
| 573 | - * @return array |
|
| 574 | - */ |
|
| 575 | - private function getRoleData($activeRoles) |
|
| 576 | - { |
|
| 577 | - $availableRoles = $this->getSecurityManager()->getAvailableRoles(); |
|
| 578 | - |
|
| 579 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 580 | - $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
| 581 | - |
|
| 582 | - $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
| 583 | - |
|
| 584 | - $roleData = array(); |
|
| 585 | - foreach ($availableRoles as $role => $data) { |
|
| 586 | - $intersection = array_intersect($data['editableBy'], $userRoles); |
|
| 587 | - |
|
| 588 | - $roleData[$role] = $initialValue; |
|
| 589 | - $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
| 590 | - $roleData[$role]['description'] = $data['description']; |
|
| 591 | - $roleData[$role]['globalOnly'] = $data['globalOnly']; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - foreach ($activeRoles as $role) { |
|
| 595 | - if (!isset($roleData[$role->getRole()])) { |
|
| 596 | - // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
| 597 | - $roleData[$role->getRole()] = $initialValue; |
|
| 598 | - $roleData[$role->getRole()]['allowEdit'] = 1; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - $roleData[$role->getRole()]['object'] = $role; |
|
| 602 | - $roleData[$role->getRole()]['active'] = 1; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - return $roleData; |
|
| 606 | - } |
|
| 33 | + // FIXME: domains |
|
| 34 | + /** @var string */ |
|
| 35 | + private $adminMailingList = '[email protected]'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Main function for this page, when no specific actions are called. |
|
| 39 | + */ |
|
| 40 | + protected function main() |
|
| 41 | + { |
|
| 42 | + $this->setHtmlTitle('User Management'); |
|
| 43 | + |
|
| 44 | + $database = $this->getDatabase(); |
|
| 45 | + $currentUser = User::getCurrent($database); |
|
| 46 | + |
|
| 47 | + $userSearchRequest = WebRequest::getString('usersearch'); |
|
| 48 | + if ($userSearchRequest !== null) { |
|
| 49 | + $searchedUser = User::getByUsername($userSearchRequest, $database); |
|
| 50 | + if ($searchedUser !== false) { |
|
| 51 | + $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
| 57 | + // the template. I still don't have a particularly good way of handling this. |
|
| 58 | + OAuthUserHelper::prepareTokenCountStatement($database); |
|
| 59 | + |
|
| 60 | + if (WebRequest::getBoolean("showAll")) { |
|
| 61 | + $this->assign("showAll", true); |
|
| 62 | + |
|
| 63 | + $deactivatedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DEACTIVATED)->fetch(); |
|
| 64 | + $this->assign('deactivatedUsers', $deactivatedUsers); |
|
| 65 | + |
|
| 66 | + UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
| 67 | + } |
|
| 68 | + else { |
|
| 69 | + $this->assign("showAll", false); |
|
| 70 | + $this->assign('deactivatedUsers', array()); |
|
| 71 | + |
|
| 72 | + UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
| 76 | + $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
| 77 | + $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
| 78 | + $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
| 79 | + $stewards = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('steward')->fetch(); |
|
| 80 | + $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
| 81 | + $this->assign('newUsers', $newUsers); |
|
| 82 | + $this->assign('normalUsers', $normalUsers); |
|
| 83 | + $this->assign('adminUsers', $adminUsers); |
|
| 84 | + $this->assign('checkUsers', $checkUsers); |
|
| 85 | + $this->assign('stewards', $stewards); |
|
| 86 | + $this->assign('toolRoots', $toolRoots); |
|
| 87 | + |
|
| 88 | + $this->assign('roles', $roleMap); |
|
| 89 | + |
|
| 90 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 91 | + |
|
| 92 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
| 93 | + $this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser)); |
|
| 94 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
| 95 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
| 96 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
| 97 | + |
|
| 98 | + // FIXME: domains! |
|
| 99 | + /** @var Domain $domain */ |
|
| 100 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 101 | + $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
| 102 | + |
|
| 103 | + $this->setTemplate("usermanagement/main.tpl"); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + #region Access control |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Action target for editing the roles assigned to a user |
|
| 110 | + * |
|
| 111 | + * @throws ApplicationLogicException |
|
| 112 | + * @throws SmartyException |
|
| 113 | + * @throws OptimisticLockFailedException |
|
| 114 | + * @throws Exception |
|
| 115 | + */ |
|
| 116 | + protected function editRoles(): void |
|
| 117 | + { |
|
| 118 | + $this->setHtmlTitle('User Management'); |
|
| 119 | + $database = $this->getDatabase(); |
|
| 120 | + $domain = Domain::getCurrent($database); |
|
| 121 | + $userId = WebRequest::getInt('user'); |
|
| 122 | + |
|
| 123 | + /** @var User|false $user */ |
|
| 124 | + $user = User::getById($userId, $database); |
|
| 125 | + |
|
| 126 | + if ($user === false || $user->isCommunityUser()) { |
|
| 127 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database, $domain->getId())); |
|
| 131 | + |
|
| 132 | + // Dual-mode action |
|
| 133 | + if (WebRequest::wasPosted()) { |
|
| 134 | + $this->validateCSRFToken(); |
|
| 135 | + |
|
| 136 | + $reason = WebRequest::postString('reason'); |
|
| 137 | + if ($reason === false || trim($reason) === '') { |
|
| 138 | + throw new ApplicationLogicException('No reason specified for roles change'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** @var UserRole[] $delete */ |
|
| 142 | + $delete = array(); |
|
| 143 | + /** @var string[] $add */ |
|
| 144 | + $add = array(); |
|
| 145 | + |
|
| 146 | + /** @var UserRole[] $globalDelete */ |
|
| 147 | + $globalDelete = array(); |
|
| 148 | + /** @var string[] $globalAdd */ |
|
| 149 | + $globalAdd = array(); |
|
| 150 | + |
|
| 151 | + foreach ($roleData as $name => $r) { |
|
| 152 | + if ($r['allowEdit'] !== 1) { |
|
| 153 | + // not allowed, to touch this, so ignore it |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
| 158 | + if ($newValue !== $r['active']) { |
|
| 159 | + if ($newValue === 0) { |
|
| 160 | + if ($r['globalOnly']) { |
|
| 161 | + $globalDelete[] = $r['object']; |
|
| 162 | + } |
|
| 163 | + else { |
|
| 164 | + $delete[] = $r['object']; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if ($newValue === 1) { |
|
| 169 | + if ($r['globalOnly']) { |
|
| 170 | + $globalAdd[] = $name; |
|
| 171 | + } |
|
| 172 | + else { |
|
| 173 | + $add[] = $name; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Check there's something to do |
|
| 180 | + if ((count($add) + count($delete) + count($globalAdd) + count($globalDelete)) === 0) { |
|
| 181 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 182 | + SessionAlert::warning('No changes made to roles.'); |
|
| 183 | + |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $removed = array(); |
|
| 188 | + $globalRemoved = array(); |
|
| 189 | + |
|
| 190 | + foreach ($delete as $d) { |
|
| 191 | + $removed[] = $d->getRole(); |
|
| 192 | + $d->delete(); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + foreach ($globalDelete as $d) { |
|
| 196 | + $globalRemoved[] = $d->getRole(); |
|
| 197 | + $d->delete(); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + foreach ($add as $x) { |
|
| 201 | + $a = new UserRole(); |
|
| 202 | + $a->setUser($user->getId()); |
|
| 203 | + $a->setRole($x); |
|
| 204 | + $a->setDomain($domain->getId()); |
|
| 205 | + $a->setDatabase($database); |
|
| 206 | + $a->save(); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + foreach ($globalAdd as $x) { |
|
| 210 | + $a = new UserRole(); |
|
| 211 | + $a->setUser($user->getId()); |
|
| 212 | + $a->setRole($x); |
|
| 213 | + $a->setDomain(null); |
|
| 214 | + $a->setDatabase($database); |
|
| 215 | + $a->save(); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ((count($add) + count($delete)) > 0) { |
|
| 219 | + Logger::userRolesEdited($database, $user, $reason, $add, $removed, $domain->getId()); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if ((count($globalAdd) + count($globalDelete)) > 0) { |
|
| 223 | + Logger::userGlobalRolesEdited($database, $user, $reason, $globalAdd, $globalRemoved); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
| 227 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 228 | + $user->save(); |
|
| 229 | + |
|
| 230 | + $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
| 231 | + SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 232 | + |
|
| 233 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 234 | + } |
|
| 235 | + else { |
|
| 236 | + $this->assignCSRFToken(); |
|
| 237 | + $this->setTemplate('usermanagement/roleedit.tpl'); |
|
| 238 | + $this->assign('user', $user); |
|
| 239 | + $this->assign('roleData', $roleData); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Action target for deactivating users |
|
| 245 | + * |
|
| 246 | + * @throws ApplicationLogicException |
|
| 247 | + */ |
|
| 248 | + protected function deactivate() |
|
| 249 | + { |
|
| 250 | + $this->setHtmlTitle('User Management'); |
|
| 251 | + |
|
| 252 | + $database = $this->getDatabase(); |
|
| 253 | + |
|
| 254 | + $userId = WebRequest::getInt('user'); |
|
| 255 | + |
|
| 256 | + /** @var User $user */ |
|
| 257 | + $user = User::getById($userId, $database); |
|
| 258 | + |
|
| 259 | + if ($user === false || $user->isCommunityUser()) { |
|
| 260 | + throw new ApplicationLogicException('Sorry, the user you are trying to deactivate could not be found.'); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ($user->isDeactivated()) { |
|
| 264 | + throw new ApplicationLogicException('Sorry, the user you are trying to deactivate is already deactivated.'); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // Dual-mode action |
|
| 268 | + if (WebRequest::wasPosted()) { |
|
| 269 | + $this->validateCSRFToken(); |
|
| 270 | + $reason = WebRequest::postString('reason'); |
|
| 271 | + |
|
| 272 | + if ($reason === null || trim($reason) === '') { |
|
| 273 | + throw new ApplicationLogicException('No reason provided'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $user->setStatus(User::STATUS_DEACTIVATED); |
|
| 277 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 278 | + $user->save(); |
|
| 279 | + Logger::deactivatedUser($database, $user, $reason); |
|
| 280 | + |
|
| 281 | + $this->getNotificationHelper()->userDeactivated($user); |
|
| 282 | + SessionAlert::quick('Deactivated user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 283 | + |
|
| 284 | + // send email |
|
| 285 | + $this->sendStatusChangeEmail( |
|
| 286 | + 'Your WP:ACC account has been deactivated', |
|
| 287 | + 'usermanagement/emails/deactivated.tpl', |
|
| 288 | + $reason, |
|
| 289 | + $user, |
|
| 290 | + User::getCurrent($database)->getUsername() |
|
| 291 | + ); |
|
| 292 | + |
|
| 293 | + $this->redirect('userManagement'); |
|
| 294 | + |
|
| 295 | + return; |
|
| 296 | + } |
|
| 297 | + else { |
|
| 298 | + $this->assignCSRFToken(); |
|
| 299 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
| 300 | + $this->assign('user', $user); |
|
| 301 | + $this->assign('status', User::STATUS_DEACTIVATED); |
|
| 302 | + $this->assign("showReason", true); |
|
| 303 | + |
|
| 304 | + if (WebRequest::getString('preload')) { |
|
| 305 | + $this->assign('preload', WebRequest::getString('preload')); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Entry point for the approve action |
|
| 312 | + * |
|
| 313 | + * @throws ApplicationLogicException |
|
| 314 | + */ |
|
| 315 | + protected function approve() |
|
| 316 | + { |
|
| 317 | + $this->setHtmlTitle('User Management'); |
|
| 318 | + |
|
| 319 | + $database = $this->getDatabase(); |
|
| 320 | + |
|
| 321 | + $userId = WebRequest::getInt('user'); |
|
| 322 | + $user = User::getById($userId, $database); |
|
| 323 | + |
|
| 324 | + if ($user === false || $user->isCommunityUser()) { |
|
| 325 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + if ($user->isActive()) { |
|
| 329 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // Dual-mode action |
|
| 333 | + if (WebRequest::wasPosted()) { |
|
| 334 | + $this->validateCSRFToken(); |
|
| 335 | + $user->setStatus(User::STATUS_ACTIVE); |
|
| 336 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 337 | + $user->save(); |
|
| 338 | + Logger::approvedUser($database, $user); |
|
| 339 | + |
|
| 340 | + $this->getNotificationHelper()->userApproved($user); |
|
| 341 | + SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 342 | + |
|
| 343 | + // send email |
|
| 344 | + $this->sendStatusChangeEmail( |
|
| 345 | + 'Your WP:ACC account has been approved', |
|
| 346 | + 'usermanagement/emails/approved.tpl', |
|
| 347 | + null, |
|
| 348 | + $user, |
|
| 349 | + User::getCurrent($database)->getUsername() |
|
| 350 | + ); |
|
| 351 | + |
|
| 352 | + $this->redirect("userManagement"); |
|
| 353 | + |
|
| 354 | + return; |
|
| 355 | + } |
|
| 356 | + else { |
|
| 357 | + $this->assignCSRFToken(); |
|
| 358 | + $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
| 359 | + $this->assign("user", $user); |
|
| 360 | + $this->assign("status", "Active"); |
|
| 361 | + $this->assign("showReason", false); |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + #endregion |
|
| 366 | + |
|
| 367 | + #region Renaming / Editing |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Entry point for the rename action |
|
| 371 | + * |
|
| 372 | + * @throws ApplicationLogicException |
|
| 373 | + */ |
|
| 374 | + protected function rename() |
|
| 375 | + { |
|
| 376 | + $this->setHtmlTitle('User Management'); |
|
| 377 | + |
|
| 378 | + $database = $this->getDatabase(); |
|
| 379 | + |
|
| 380 | + $userId = WebRequest::getInt('user'); |
|
| 381 | + $user = User::getById($userId, $database); |
|
| 382 | + |
|
| 383 | + if ($user === false || $user->isCommunityUser()) { |
|
| 384 | + throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + // Dual-mode action |
|
| 388 | + if (WebRequest::wasPosted()) { |
|
| 389 | + $this->validateCSRFToken(); |
|
| 390 | + $newUsername = WebRequest::postString('newname'); |
|
| 391 | + |
|
| 392 | + if ($newUsername === null || trim($newUsername) === "") { |
|
| 393 | + throw new ApplicationLogicException('The new username cannot be empty'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if (User::getByUsername($newUsername, $database) != false) { |
|
| 397 | + throw new ApplicationLogicException('The new username already exists'); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + $oldUsername = $user->getUsername(); |
|
| 401 | + $user->setUsername($newUsername); |
|
| 402 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 403 | + |
|
| 404 | + $user->save(); |
|
| 405 | + |
|
| 406 | + $logEntryData = serialize(array( |
|
| 407 | + 'old' => $oldUsername, |
|
| 408 | + 'new' => $newUsername, |
|
| 409 | + )); |
|
| 410 | + |
|
| 411 | + Logger::renamedUser($database, $user, $logEntryData); |
|
| 412 | + |
|
| 413 | + SessionAlert::quick("Changed User " |
|
| 414 | + . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
| 415 | + . " name to " |
|
| 416 | + . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
| 417 | + |
|
| 418 | + $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
| 419 | + |
|
| 420 | + // send an email to the user. |
|
| 421 | + $this->assign('targetUsername', $user->getUsername()); |
|
| 422 | + $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
| 423 | + $this->assign('oldUsername', $oldUsername); |
|
| 424 | + $this->assign('mailingList', $this->adminMailingList); |
|
| 425 | + |
|
| 426 | + // FIXME: domains! |
|
| 427 | + /** @var Domain $domain */ |
|
| 428 | + $domain = Domain::getById(1, $database); |
|
| 429 | + $this->getEmailHelper()->sendMail( |
|
| 430 | + $this->adminMailingList, |
|
| 431 | + $user->getEmail(), |
|
| 432 | + 'Your username on WP:ACC has been changed', |
|
| 433 | + $this->fetchTemplate('usermanagement/emails/renamed.tpl') |
|
| 434 | + ); |
|
| 435 | + |
|
| 436 | + $this->redirect("userManagement"); |
|
| 437 | + |
|
| 438 | + return; |
|
| 439 | + } |
|
| 440 | + else { |
|
| 441 | + $this->assignCSRFToken(); |
|
| 442 | + $this->setTemplate('usermanagement/renameuser.tpl'); |
|
| 443 | + $this->assign('user', $user); |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Entry point for the edit action |
|
| 449 | + * |
|
| 450 | + * @throws ApplicationLogicException |
|
| 451 | + */ |
|
| 452 | + protected function editUser() |
|
| 453 | + { |
|
| 454 | + $this->setHtmlTitle('User Management'); |
|
| 455 | + |
|
| 456 | + $database = $this->getDatabase(); |
|
| 457 | + |
|
| 458 | + $userId = WebRequest::getInt('user'); |
|
| 459 | + $user = User::getById($userId, $database); |
|
| 460 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 461 | + |
|
| 462 | + if ($user === false || $user->isCommunityUser()) { |
|
| 463 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + // FIXME: domains |
|
| 467 | + $prefs = new PreferenceManager($database, $user->getId(), 1); |
|
| 468 | + |
|
| 469 | + // Dual-mode action |
|
| 470 | + if (WebRequest::wasPosted()) { |
|
| 471 | + $this->validateCSRFToken(); |
|
| 472 | + $newEmail = WebRequest::postEmail('user_email'); |
|
| 473 | + $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
| 474 | + |
|
| 475 | + if ($newEmail === null) { |
|
| 476 | + throw new ApplicationLogicException('Invalid email address'); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if ($this->validateUnusedEmail($newEmail, $userId)) { |
|
| 480 | + throw new ApplicationLogicException('The specified email address is already in use.'); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) { |
|
| 484 | + if (trim($newOnWikiName) == "") { |
|
| 485 | + throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + $user->setOnWikiName($newOnWikiName); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + $user->setEmail($newEmail); |
|
| 492 | + |
|
| 493 | + $prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode')); |
|
| 494 | + |
|
| 495 | + $prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation')); |
|
| 496 | + |
|
| 497 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 498 | + |
|
| 499 | + $user->save(); |
|
| 500 | + |
|
| 501 | + Logger::userPreferencesChange($database, $user); |
|
| 502 | + $this->getNotificationHelper()->userPrefChange($user); |
|
| 503 | + SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
| 504 | + |
|
| 505 | + $this->redirect("userManagement"); |
|
| 506 | + |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + else { |
|
| 510 | + $this->assignCSRFToken(); |
|
| 511 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 512 | + $this->getSiteConfiguration()); |
|
| 513 | + $this->setTemplate('usermanagement/edituser.tpl'); |
|
| 514 | + $this->assign('user', $user); |
|
| 515 | + $this->assign('oauth', $oauth); |
|
| 516 | + |
|
| 517 | + $this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE)); |
|
| 518 | + $this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE)); |
|
| 519 | + |
|
| 520 | + $this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false); |
|
| 521 | + |
|
| 522 | + $this->assign('canManualCreate', |
|
| 523 | + $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 524 | + $this->assign('canOauthCreate', |
|
| 525 | + $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 526 | + $this->assign('canBotCreate', |
|
| 527 | + $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation')); |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + #endregion |
|
| 532 | + |
|
| 533 | + private function validateUnusedEmail(string $email, int $userId) : bool { |
|
| 534 | + $query = 'SELECT COUNT(id) FROM user WHERE email = :email AND id <> :uid'; |
|
| 535 | + $statement = $this->getDatabase()->prepare($query); |
|
| 536 | + $statement->execute(array(':email' => $email, ':uid' => $userId)); |
|
| 537 | + $inUse = $statement->fetchColumn() > 0; |
|
| 538 | + $statement->closeCursor(); |
|
| 539 | + |
|
| 540 | + return $inUse; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Sends a status change email to the user. |
|
| 545 | + * |
|
| 546 | + * @param string $subject The subject of the email |
|
| 547 | + * @param string $template The smarty template to use |
|
| 548 | + * @param string|null $reason The reason for performing the status change |
|
| 549 | + * @param User $user The user affected |
|
| 550 | + * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
| 551 | + */ |
|
| 552 | + private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
| 553 | + { |
|
| 554 | + $this->assign('targetUsername', $user->getUsername()); |
|
| 555 | + $this->assign('toolAdmin', $toolAdminUsername); |
|
| 556 | + $this->assign('actionReason', $reason); |
|
| 557 | + $this->assign('mailingList', $this->adminMailingList); |
|
| 558 | + |
|
| 559 | + // FIXME: domains! |
|
| 560 | + /** @var Domain $domain */ |
|
| 561 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 562 | + $this->getEmailHelper()->sendMail( |
|
| 563 | + $this->adminMailingList, |
|
| 564 | + $user->getEmail(), |
|
| 565 | + $subject, |
|
| 566 | + $this->fetchTemplate($template) |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * @param UserRole[] $activeRoles |
|
| 572 | + * |
|
| 573 | + * @return array |
|
| 574 | + */ |
|
| 575 | + private function getRoleData($activeRoles) |
|
| 576 | + { |
|
| 577 | + $availableRoles = $this->getSecurityManager()->getAvailableRoles(); |
|
| 578 | + |
|
| 579 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 580 | + $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
| 581 | + |
|
| 582 | + $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
| 583 | + |
|
| 584 | + $roleData = array(); |
|
| 585 | + foreach ($availableRoles as $role => $data) { |
|
| 586 | + $intersection = array_intersect($data['editableBy'], $userRoles); |
|
| 587 | + |
|
| 588 | + $roleData[$role] = $initialValue; |
|
| 589 | + $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
| 590 | + $roleData[$role]['description'] = $data['description']; |
|
| 591 | + $roleData[$role]['globalOnly'] = $data['globalOnly']; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + foreach ($activeRoles as $role) { |
|
| 595 | + if (!isset($roleData[$role->getRole()])) { |
|
| 596 | + // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
| 597 | + $roleData[$role->getRole()] = $initialValue; |
|
| 598 | + $roleData[$role->getRole()]['allowEdit'] = 1; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + $roleData[$role->getRole()]['object'] = $role; |
|
| 602 | + $roleData[$role->getRole()]['active'] = 1; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + return $roleData; |
|
| 606 | + } |
|
| 607 | 607 | } |
@@ -33,369 +33,369 @@ |
||
| 33 | 33 | |
| 34 | 34 | class PageViewRequest extends InternalPageBase |
| 35 | 35 | { |
| 36 | - use RequestData; |
|
| 37 | - |
|
| 38 | - const STATUS_SYMBOL_OPEN = 'Ο'; |
|
| 39 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 40 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Main function for this page, when no specific actions are called. |
|
| 44 | - * @throws ApplicationLogicException |
|
| 45 | - */ |
|
| 46 | - protected function main() |
|
| 47 | - { |
|
| 48 | - // set up csrf protection |
|
| 49 | - $this->assignCSRFToken(); |
|
| 50 | - |
|
| 51 | - // get some useful objects |
|
| 52 | - $database = $this->getDatabase(); |
|
| 53 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 54 | - $config = $this->getSiteConfiguration(); |
|
| 55 | - $currentUser = User::getCurrent($database); |
|
| 56 | - |
|
| 57 | - // FIXME: domains! |
|
| 58 | - /** @var Domain $domain */ |
|
| 59 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 60 | - $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
| 61 | - |
|
| 62 | - // Shows a page if the email is not confirmed. |
|
| 63 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 64 | - // Show a banner if the user can manually confirm the request |
|
| 65 | - $viewConfirm = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageManuallyConfirm::class); |
|
| 66 | - |
|
| 67 | - // If the request is purged, there's nothing to confirm! |
|
| 68 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 69 | - $viewConfirm = false; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // Render |
|
| 73 | - $this->setTemplate("view-request/not-confirmed.tpl"); |
|
| 74 | - $this->assign("requestId", $request->getId()); |
|
| 75 | - $this->assign("requestVersion", $request->getUpdateVersion()); |
|
| 76 | - $this->assign('canViewConfirmButton', $viewConfirm); |
|
| 77 | - |
|
| 78 | - // Make sure to return, to prevent the leaking of other information. |
|
| 79 | - return; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $this->setupBasicData($request, $config); |
|
| 83 | - |
|
| 84 | - $this->setupUsernameData($request); |
|
| 85 | - |
|
| 86 | - $this->setupTitle($request); |
|
| 87 | - |
|
| 88 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 89 | - $this->setupGeneralData($database); |
|
| 90 | - |
|
| 91 | - $this->assign('requestDataCleared', false); |
|
| 92 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 93 | - $this->assign('requestDataCleared', true); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 97 | - |
|
| 98 | - $this->setupCreationTypes($currentUser); |
|
| 99 | - |
|
| 100 | - $this->setupLogData($request, $database, $allowedPrivateData); |
|
| 101 | - |
|
| 102 | - $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 103 | - |
|
| 104 | - $this->assign('showRevealLink', false); |
|
| 105 | - if ($request->getReserved() === $currentUser->getId() || |
|
| 106 | - $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 107 | - ) { |
|
| 108 | - $this->assign('showRevealLink', true); |
|
| 109 | - $this->assign('revealHash', $request->getRevealHash()); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $this->assign('canSeeRelatedRequests', false); |
|
| 113 | - if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) { |
|
| 114 | - $this->setupRelatedRequests($request, $config, $database); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $this->assign('canCreateLocalAccount', $this->barrierTest('createLocalAccount', $currentUser, 'RequestData')); |
|
| 118 | - |
|
| 119 | - $closureDate = $request->getClosureDate(); |
|
| 120 | - $date = new DateTime(); |
|
| 121 | - $date->modify("-7 days"); |
|
| 122 | - if ($request->getStatus() == "Closed" && $closureDate < $date) { |
|
| 123 | - $this->assign('isOldRequest', true); |
|
| 124 | - } |
|
| 125 | - $this->assign('canResetOldRequest', $this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')); |
|
| 126 | - $this->assign('canResetPurgedRequest', $this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData')); |
|
| 127 | - |
|
| 128 | - $this->assign('requestEmailSent', $request->getEmailSent()); |
|
| 129 | - |
|
| 130 | - if ($allowedPrivateData) { |
|
| 131 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 132 | - $this->setupPrivateData($request, $config); |
|
| 133 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 134 | - $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 135 | - |
|
| 136 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 137 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 138 | - $this->setupCheckUserData($request); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - else { |
|
| 142 | - $this->setTemplate('view-request/main.tpl'); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param Request $request |
|
| 148 | - */ |
|
| 149 | - protected function setupTitle(Request $request) |
|
| 150 | - { |
|
| 151 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 152 | - if ($request->getStatus() === RequestStatus::CLOSED) { |
|
| 153 | - if ($request->getWasCreated()) { |
|
| 154 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 155 | - } |
|
| 156 | - else { |
|
| 157 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Sets up data unrelated to the request, such as the email template information |
|
| 166 | - * |
|
| 167 | - * @param PdoDatabase $database |
|
| 168 | - */ |
|
| 169 | - protected function setupGeneralData(PdoDatabase $database) |
|
| 170 | - { |
|
| 171 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 172 | - |
|
| 173 | - // FIXME: domains |
|
| 174 | - /** @var Domain $domain */ |
|
| 175 | - $domain = Domain::getById(1, $database); |
|
| 176 | - $this->assign('defaultRequestState', RequestQueue::getDefaultQueue($database, 1)->getApiName()); |
|
| 177 | - $this->assign('activeRequestQueues', RequestQueue::getEnabledQueues($database)); |
|
| 178 | - |
|
| 179 | - /** @var EmailTemplate $createdTemplate */ |
|
| 180 | - $createdTemplate = EmailTemplate::getById($domain->getDefaultClose(), $database); |
|
| 181 | - |
|
| 182 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 183 | - $this->assign('createdId', $createdTemplate->getId()); |
|
| 184 | - $this->assign('createdName', $createdTemplate->getName()); |
|
| 185 | - |
|
| 186 | - $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 187 | - $skipJsAborts = $preferenceManager->getPreference(PreferenceManager::PREF_SKIP_JS_ABORT); |
|
| 188 | - $preferredCreationMode = (int)$preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE); |
|
| 189 | - $this->assign('skipJsAborts', $skipJsAborts); |
|
| 190 | - $this->assign('preferredCreationMode', $preferredCreationMode); |
|
| 191 | - |
|
| 192 | - $createReasons = EmailTemplate::getActiveNonpreloadTemplates( |
|
| 193 | - EmailTemplate::ACTION_CREATED, |
|
| 194 | - $database, |
|
| 195 | - $domain->getId(), |
|
| 196 | - $domain->getDefaultClose()); |
|
| 197 | - $this->assign("createReasons", $createReasons); |
|
| 198 | - |
|
| 199 | - $declineReasons = EmailTemplate::getActiveNonpreloadTemplates( |
|
| 200 | - EmailTemplate::ACTION_NOT_CREATED, |
|
| 201 | - $database, |
|
| 202 | - $domain->getId()); |
|
| 203 | - $this->assign("declineReasons", $declineReasons); |
|
| 204 | - |
|
| 205 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates( |
|
| 206 | - EmailTemplate::ACTION_CREATED, |
|
| 207 | - $database, |
|
| 208 | - $domain->getId()); |
|
| 209 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
| 210 | - |
|
| 211 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates( |
|
| 212 | - EmailTemplate::ACTION_NOT_CREATED, |
|
| 213 | - $database, |
|
| 214 | - $domain->getId()); |
|
| 215 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 216 | - |
|
| 217 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates( |
|
| 218 | - false, |
|
| 219 | - $database, |
|
| 220 | - $domain->getId()); |
|
| 221 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - private function setupLogData(Request $request, PdoDatabase $database, bool $allowedPrivateData) |
|
| 225 | - { |
|
| 226 | - $currentUser = User::getCurrent($database); |
|
| 227 | - |
|
| 228 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 229 | - $requestLogs = array(); |
|
| 230 | - |
|
| 231 | - /** @var User[] $nameCache */ |
|
| 232 | - $nameCache = array(); |
|
| 233 | - |
|
| 234 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 235 | - |
|
| 236 | - $canFlag = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageFlagComment::class); |
|
| 237 | - $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
| 238 | - |
|
| 239 | - /** @var Log|Comment $entry */ |
|
| 240 | - foreach ($logs as $entry) { |
|
| 241 | - // both log and comment have a 'user' field |
|
| 242 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 243 | - $entryUser = User::getById($entry->getUser(), $database); |
|
| 244 | - $nameCache[$entry->getUser()] = $entryUser; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($entry instanceof Comment) { |
|
| 248 | - // Determine if the comment contains private information. |
|
| 249 | - // Private defined as flagged or restricted visibility, but only when the user isn't allowed |
|
| 250 | - // to see private data |
|
| 251 | - $commentIsRestricted = |
|
| 252 | - ($entry->getFlagged() |
|
| 253 | - || $entry->getVisibility() == 'admin' || $entry->getVisibility() == 'checkuser') |
|
| 254 | - && !$allowedPrivateData; |
|
| 255 | - |
|
| 256 | - // Only allow comment editing if the user is able to edit comments or this is the user's own comment, |
|
| 257 | - // but only when they're allowed to see the comment itself. |
|
| 258 | - $commentIsEditable = ($editableComments || $entry->getUser() == $currentUser->getId()) |
|
| 259 | - && !$commentIsRestricted; |
|
| 260 | - |
|
| 261 | - // Flagging/unflagging can only be done if you can see the comment |
|
| 262 | - $canFlagThisComment = $canFlag |
|
| 263 | - && ( |
|
| 264 | - (!$entry->getFlagged() && !$commentIsRestricted) |
|
| 265 | - || ($entry->getFlagged() && $canUnflag && $commentIsEditable) |
|
| 266 | - ); |
|
| 267 | - |
|
| 268 | - $requestLogs[] = array( |
|
| 269 | - 'type' => 'comment', |
|
| 270 | - 'security' => $entry->getVisibility(), |
|
| 271 | - 'user' => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(), |
|
| 272 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 273 | - 'entry' => null, |
|
| 274 | - 'time' => $entry->getTime(), |
|
| 275 | - 'canedit' => $commentIsEditable, |
|
| 276 | - 'id' => $entry->getId(), |
|
| 277 | - 'comment' => $entry->getComment(), |
|
| 278 | - 'flagged' => $entry->getFlagged(), |
|
| 279 | - 'canflag' => $canFlagThisComment, |
|
| 280 | - 'updateversion' => $entry->getUpdateVersion(), |
|
| 281 | - 'edited' => $entry->getEdited(), |
|
| 282 | - 'hidden' => $commentIsRestricted |
|
| 283 | - ); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - if ($entry instanceof Log) { |
|
| 287 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 288 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 289 | - |
|
| 290 | - $entryComment = $entry->getComment(); |
|
| 291 | - |
|
| 292 | - if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') { |
|
| 293 | - $data = unserialize($entry->getComment()); |
|
| 294 | - /** @var JobQueue $job */ |
|
| 295 | - $job = JobQueue::getById($data['job'], $database); |
|
| 296 | - $requestLogs[] = array( |
|
| 297 | - 'type' => 'joblog', |
|
| 298 | - 'security' => 'user', |
|
| 299 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 300 | - 'user' => $entryUser->getUsername(), |
|
| 301 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 302 | - 'time' => $entry->getTimestamp(), |
|
| 303 | - 'canedit' => false, |
|
| 304 | - 'id' => $entry->getId(), |
|
| 305 | - 'jobId' => $job->getId(), |
|
| 306 | - 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - $requestLogs[] = array( |
|
| 311 | - 'type' => 'log', |
|
| 312 | - 'security' => 'user', |
|
| 313 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 314 | - 'user' => $entryUser->getUsername(), |
|
| 315 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 316 | - 'time' => $entry->getTimestamp(), |
|
| 317 | - 'canedit' => false, |
|
| 318 | - 'id' => $entry->getId(), |
|
| 319 | - 'comment' => $entryComment, |
|
| 320 | - ); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 326 | - |
|
| 327 | - $this->assign("requestLogs", $requestLogs); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @param Request $request |
|
| 332 | - */ |
|
| 333 | - protected function setupUsernameData(Request $request) |
|
| 334 | - { |
|
| 335 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 336 | - |
|
| 337 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 338 | - $this->assign('requestBlacklist', $blacklistData); |
|
| 339 | - |
|
| 340 | - try { |
|
| 341 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 342 | - } |
|
| 343 | - catch (Exception $ex) { |
|
| 344 | - $spoofs = $ex->getMessage(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $this->assign("spoofs", $spoofs); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - private function setupCreationTypes(User $user) |
|
| 351 | - { |
|
| 352 | - $this->assign('allowWelcomeSkip', false); |
|
| 353 | - $this->assign('forceWelcomeSkip', false); |
|
| 354 | - |
|
| 355 | - $database = $this->getDatabase(); |
|
| 356 | - $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 357 | - |
|
| 358 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 359 | - |
|
| 360 | - $welcomeTemplate = $preferenceManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE); |
|
| 361 | - |
|
| 362 | - if ($welcomeTemplate != null) { |
|
| 363 | - $this->assign('allowWelcomeSkip', true); |
|
| 364 | - |
|
| 365 | - if (!$oauth->canWelcome()) { |
|
| 366 | - $this->assign('forceWelcomeSkip', true); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // test credentials |
|
| 371 | - $canManualCreate = $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 372 | - $canOauthCreate = $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 373 | - $canBotCreate = $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'); |
|
| 374 | - |
|
| 375 | - $this->assign('canManualCreate', $canManualCreate); |
|
| 376 | - $this->assign('canOauthCreate', $canOauthCreate); |
|
| 377 | - $this->assign('canBotCreate', $canBotCreate); |
|
| 378 | - |
|
| 379 | - // show/hide the type radio buttons |
|
| 380 | - $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 381 | - |
|
| 382 | - $creationModePreference = $preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE); |
|
| 383 | - if (!$this->barrierTest($creationModePreference, $user, 'RequestCreation')) { |
|
| 384 | - // user is not allowed to use their default. Force a choice. |
|
| 385 | - $creationHasChoice = true; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $this->assign('creationHasChoice', $creationHasChoice); |
|
| 389 | - |
|
| 390 | - // determine problems in creation types |
|
| 391 | - $this->assign('botProblem', false); |
|
| 392 | - if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 393 | - $this->assign('botProblem', true); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - $this->assign('oauthProblem', false); |
|
| 397 | - if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 398 | - $this->assign('oauthProblem', true); |
|
| 399 | - } |
|
| 400 | - } |
|
| 36 | + use RequestData; |
|
| 37 | + |
|
| 38 | + const STATUS_SYMBOL_OPEN = 'Ο'; |
|
| 39 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 40 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Main function for this page, when no specific actions are called. |
|
| 44 | + * @throws ApplicationLogicException |
|
| 45 | + */ |
|
| 46 | + protected function main() |
|
| 47 | + { |
|
| 48 | + // set up csrf protection |
|
| 49 | + $this->assignCSRFToken(); |
|
| 50 | + |
|
| 51 | + // get some useful objects |
|
| 52 | + $database = $this->getDatabase(); |
|
| 53 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 54 | + $config = $this->getSiteConfiguration(); |
|
| 55 | + $currentUser = User::getCurrent($database); |
|
| 56 | + |
|
| 57 | + // FIXME: domains! |
|
| 58 | + /** @var Domain $domain */ |
|
| 59 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 60 | + $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
| 61 | + |
|
| 62 | + // Shows a page if the email is not confirmed. |
|
| 63 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 64 | + // Show a banner if the user can manually confirm the request |
|
| 65 | + $viewConfirm = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageManuallyConfirm::class); |
|
| 66 | + |
|
| 67 | + // If the request is purged, there's nothing to confirm! |
|
| 68 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 69 | + $viewConfirm = false; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // Render |
|
| 73 | + $this->setTemplate("view-request/not-confirmed.tpl"); |
|
| 74 | + $this->assign("requestId", $request->getId()); |
|
| 75 | + $this->assign("requestVersion", $request->getUpdateVersion()); |
|
| 76 | + $this->assign('canViewConfirmButton', $viewConfirm); |
|
| 77 | + |
|
| 78 | + // Make sure to return, to prevent the leaking of other information. |
|
| 79 | + return; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $this->setupBasicData($request, $config); |
|
| 83 | + |
|
| 84 | + $this->setupUsernameData($request); |
|
| 85 | + |
|
| 86 | + $this->setupTitle($request); |
|
| 87 | + |
|
| 88 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 89 | + $this->setupGeneralData($database); |
|
| 90 | + |
|
| 91 | + $this->assign('requestDataCleared', false); |
|
| 92 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 93 | + $this->assign('requestDataCleared', true); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 97 | + |
|
| 98 | + $this->setupCreationTypes($currentUser); |
|
| 99 | + |
|
| 100 | + $this->setupLogData($request, $database, $allowedPrivateData); |
|
| 101 | + |
|
| 102 | + $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 103 | + |
|
| 104 | + $this->assign('showRevealLink', false); |
|
| 105 | + if ($request->getReserved() === $currentUser->getId() || |
|
| 106 | + $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 107 | + ) { |
|
| 108 | + $this->assign('showRevealLink', true); |
|
| 109 | + $this->assign('revealHash', $request->getRevealHash()); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $this->assign('canSeeRelatedRequests', false); |
|
| 113 | + if ($allowedPrivateData || $this->barrierTest('seeRelatedRequests', $currentUser, 'RequestData')) { |
|
| 114 | + $this->setupRelatedRequests($request, $config, $database); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $this->assign('canCreateLocalAccount', $this->barrierTest('createLocalAccount', $currentUser, 'RequestData')); |
|
| 118 | + |
|
| 119 | + $closureDate = $request->getClosureDate(); |
|
| 120 | + $date = new DateTime(); |
|
| 121 | + $date->modify("-7 days"); |
|
| 122 | + if ($request->getStatus() == "Closed" && $closureDate < $date) { |
|
| 123 | + $this->assign('isOldRequest', true); |
|
| 124 | + } |
|
| 125 | + $this->assign('canResetOldRequest', $this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')); |
|
| 126 | + $this->assign('canResetPurgedRequest', $this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData')); |
|
| 127 | + |
|
| 128 | + $this->assign('requestEmailSent', $request->getEmailSent()); |
|
| 129 | + |
|
| 130 | + if ($allowedPrivateData) { |
|
| 131 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 132 | + $this->setupPrivateData($request, $config); |
|
| 133 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 134 | + $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 135 | + |
|
| 136 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 137 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 138 | + $this->setupCheckUserData($request); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + else { |
|
| 142 | + $this->setTemplate('view-request/main.tpl'); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param Request $request |
|
| 148 | + */ |
|
| 149 | + protected function setupTitle(Request $request) |
|
| 150 | + { |
|
| 151 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 152 | + if ($request->getStatus() === RequestStatus::CLOSED) { |
|
| 153 | + if ($request->getWasCreated()) { |
|
| 154 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 155 | + } |
|
| 156 | + else { |
|
| 157 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Sets up data unrelated to the request, such as the email template information |
|
| 166 | + * |
|
| 167 | + * @param PdoDatabase $database |
|
| 168 | + */ |
|
| 169 | + protected function setupGeneralData(PdoDatabase $database) |
|
| 170 | + { |
|
| 171 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 172 | + |
|
| 173 | + // FIXME: domains |
|
| 174 | + /** @var Domain $domain */ |
|
| 175 | + $domain = Domain::getById(1, $database); |
|
| 176 | + $this->assign('defaultRequestState', RequestQueue::getDefaultQueue($database, 1)->getApiName()); |
|
| 177 | + $this->assign('activeRequestQueues', RequestQueue::getEnabledQueues($database)); |
|
| 178 | + |
|
| 179 | + /** @var EmailTemplate $createdTemplate */ |
|
| 180 | + $createdTemplate = EmailTemplate::getById($domain->getDefaultClose(), $database); |
|
| 181 | + |
|
| 182 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 183 | + $this->assign('createdId', $createdTemplate->getId()); |
|
| 184 | + $this->assign('createdName', $createdTemplate->getName()); |
|
| 185 | + |
|
| 186 | + $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 187 | + $skipJsAborts = $preferenceManager->getPreference(PreferenceManager::PREF_SKIP_JS_ABORT); |
|
| 188 | + $preferredCreationMode = (int)$preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE); |
|
| 189 | + $this->assign('skipJsAborts', $skipJsAborts); |
|
| 190 | + $this->assign('preferredCreationMode', $preferredCreationMode); |
|
| 191 | + |
|
| 192 | + $createReasons = EmailTemplate::getActiveNonpreloadTemplates( |
|
| 193 | + EmailTemplate::ACTION_CREATED, |
|
| 194 | + $database, |
|
| 195 | + $domain->getId(), |
|
| 196 | + $domain->getDefaultClose()); |
|
| 197 | + $this->assign("createReasons", $createReasons); |
|
| 198 | + |
|
| 199 | + $declineReasons = EmailTemplate::getActiveNonpreloadTemplates( |
|
| 200 | + EmailTemplate::ACTION_NOT_CREATED, |
|
| 201 | + $database, |
|
| 202 | + $domain->getId()); |
|
| 203 | + $this->assign("declineReasons", $declineReasons); |
|
| 204 | + |
|
| 205 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates( |
|
| 206 | + EmailTemplate::ACTION_CREATED, |
|
| 207 | + $database, |
|
| 208 | + $domain->getId()); |
|
| 209 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
| 210 | + |
|
| 211 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates( |
|
| 212 | + EmailTemplate::ACTION_NOT_CREATED, |
|
| 213 | + $database, |
|
| 214 | + $domain->getId()); |
|
| 215 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 216 | + |
|
| 217 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates( |
|
| 218 | + false, |
|
| 219 | + $database, |
|
| 220 | + $domain->getId()); |
|
| 221 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + private function setupLogData(Request $request, PdoDatabase $database, bool $allowedPrivateData) |
|
| 225 | + { |
|
| 226 | + $currentUser = User::getCurrent($database); |
|
| 227 | + |
|
| 228 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 229 | + $requestLogs = array(); |
|
| 230 | + |
|
| 231 | + /** @var User[] $nameCache */ |
|
| 232 | + $nameCache = array(); |
|
| 233 | + |
|
| 234 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 235 | + |
|
| 236 | + $canFlag = $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageFlagComment::class); |
|
| 237 | + $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
| 238 | + |
|
| 239 | + /** @var Log|Comment $entry */ |
|
| 240 | + foreach ($logs as $entry) { |
|
| 241 | + // both log and comment have a 'user' field |
|
| 242 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 243 | + $entryUser = User::getById($entry->getUser(), $database); |
|
| 244 | + $nameCache[$entry->getUser()] = $entryUser; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($entry instanceof Comment) { |
|
| 248 | + // Determine if the comment contains private information. |
|
| 249 | + // Private defined as flagged or restricted visibility, but only when the user isn't allowed |
|
| 250 | + // to see private data |
|
| 251 | + $commentIsRestricted = |
|
| 252 | + ($entry->getFlagged() |
|
| 253 | + || $entry->getVisibility() == 'admin' || $entry->getVisibility() == 'checkuser') |
|
| 254 | + && !$allowedPrivateData; |
|
| 255 | + |
|
| 256 | + // Only allow comment editing if the user is able to edit comments or this is the user's own comment, |
|
| 257 | + // but only when they're allowed to see the comment itself. |
|
| 258 | + $commentIsEditable = ($editableComments || $entry->getUser() == $currentUser->getId()) |
|
| 259 | + && !$commentIsRestricted; |
|
| 260 | + |
|
| 261 | + // Flagging/unflagging can only be done if you can see the comment |
|
| 262 | + $canFlagThisComment = $canFlag |
|
| 263 | + && ( |
|
| 264 | + (!$entry->getFlagged() && !$commentIsRestricted) |
|
| 265 | + || ($entry->getFlagged() && $canUnflag && $commentIsEditable) |
|
| 266 | + ); |
|
| 267 | + |
|
| 268 | + $requestLogs[] = array( |
|
| 269 | + 'type' => 'comment', |
|
| 270 | + 'security' => $entry->getVisibility(), |
|
| 271 | + 'user' => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(), |
|
| 272 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 273 | + 'entry' => null, |
|
| 274 | + 'time' => $entry->getTime(), |
|
| 275 | + 'canedit' => $commentIsEditable, |
|
| 276 | + 'id' => $entry->getId(), |
|
| 277 | + 'comment' => $entry->getComment(), |
|
| 278 | + 'flagged' => $entry->getFlagged(), |
|
| 279 | + 'canflag' => $canFlagThisComment, |
|
| 280 | + 'updateversion' => $entry->getUpdateVersion(), |
|
| 281 | + 'edited' => $entry->getEdited(), |
|
| 282 | + 'hidden' => $commentIsRestricted |
|
| 283 | + ); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + if ($entry instanceof Log) { |
|
| 287 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 288 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 289 | + |
|
| 290 | + $entryComment = $entry->getComment(); |
|
| 291 | + |
|
| 292 | + if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') { |
|
| 293 | + $data = unserialize($entry->getComment()); |
|
| 294 | + /** @var JobQueue $job */ |
|
| 295 | + $job = JobQueue::getById($data['job'], $database); |
|
| 296 | + $requestLogs[] = array( |
|
| 297 | + 'type' => 'joblog', |
|
| 298 | + 'security' => 'user', |
|
| 299 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 300 | + 'user' => $entryUser->getUsername(), |
|
| 301 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 302 | + 'time' => $entry->getTimestamp(), |
|
| 303 | + 'canedit' => false, |
|
| 304 | + 'id' => $entry->getId(), |
|
| 305 | + 'jobId' => $job->getId(), |
|
| 306 | + 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + $requestLogs[] = array( |
|
| 311 | + 'type' => 'log', |
|
| 312 | + 'security' => 'user', |
|
| 313 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 314 | + 'user' => $entryUser->getUsername(), |
|
| 315 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 316 | + 'time' => $entry->getTimestamp(), |
|
| 317 | + 'canedit' => false, |
|
| 318 | + 'id' => $entry->getId(), |
|
| 319 | + 'comment' => $entryComment, |
|
| 320 | + ); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 326 | + |
|
| 327 | + $this->assign("requestLogs", $requestLogs); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @param Request $request |
|
| 332 | + */ |
|
| 333 | + protected function setupUsernameData(Request $request) |
|
| 334 | + { |
|
| 335 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 336 | + |
|
| 337 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 338 | + $this->assign('requestBlacklist', $blacklistData); |
|
| 339 | + |
|
| 340 | + try { |
|
| 341 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 342 | + } |
|
| 343 | + catch (Exception $ex) { |
|
| 344 | + $spoofs = $ex->getMessage(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $this->assign("spoofs", $spoofs); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + private function setupCreationTypes(User $user) |
|
| 351 | + { |
|
| 352 | + $this->assign('allowWelcomeSkip', false); |
|
| 353 | + $this->assign('forceWelcomeSkip', false); |
|
| 354 | + |
|
| 355 | + $database = $this->getDatabase(); |
|
| 356 | + $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 357 | + |
|
| 358 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 359 | + |
|
| 360 | + $welcomeTemplate = $preferenceManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE); |
|
| 361 | + |
|
| 362 | + if ($welcomeTemplate != null) { |
|
| 363 | + $this->assign('allowWelcomeSkip', true); |
|
| 364 | + |
|
| 365 | + if (!$oauth->canWelcome()) { |
|
| 366 | + $this->assign('forceWelcomeSkip', true); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // test credentials |
|
| 371 | + $canManualCreate = $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 372 | + $canOauthCreate = $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 373 | + $canBotCreate = $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation'); |
|
| 374 | + |
|
| 375 | + $this->assign('canManualCreate', $canManualCreate); |
|
| 376 | + $this->assign('canOauthCreate', $canOauthCreate); |
|
| 377 | + $this->assign('canBotCreate', $canBotCreate); |
|
| 378 | + |
|
| 379 | + // show/hide the type radio buttons |
|
| 380 | + $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 381 | + |
|
| 382 | + $creationModePreference = $preferenceManager->getPreference(PreferenceManager::PREF_CREATION_MODE); |
|
| 383 | + if (!$this->barrierTest($creationModePreference, $user, 'RequestCreation')) { |
|
| 384 | + // user is not allowed to use their default. Force a choice. |
|
| 385 | + $creationHasChoice = true; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $this->assign('creationHasChoice', $creationHasChoice); |
|
| 389 | + |
|
| 390 | + // determine problems in creation types |
|
| 391 | + $this->assign('botProblem', false); |
|
| 392 | + if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 393 | + $this->assign('botProblem', true); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + $this->assign('oauthProblem', false); |
|
| 397 | + if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 398 | + $this->assign('oauthProblem', true); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | 401 | } |
@@ -19,48 +19,48 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageDomainSwitch extends InternalPageBase |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @inheritDoc |
|
| 24 | - */ |
|
| 25 | - protected function main() |
|
| 26 | - { |
|
| 27 | - if (!WebRequest::wasPosted()) { |
|
| 28 | - $this->redirect('/'); |
|
| 22 | + /** |
|
| 23 | + * @inheritDoc |
|
| 24 | + */ |
|
| 25 | + protected function main() |
|
| 26 | + { |
|
| 27 | + if (!WebRequest::wasPosted()) { |
|
| 28 | + $this->redirect('/'); |
|
| 29 | 29 | |
| 30 | - return; |
|
| 31 | - } |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - $database = $this->getDatabase(); |
|
| 34 | - $currentUser = User::getCurrent($database); |
|
| 33 | + $database = $this->getDatabase(); |
|
| 34 | + $currentUser = User::getCurrent($database); |
|
| 35 | 35 | |
| 36 | - /** @var Domain|false $newDomain */ |
|
| 37 | - $newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database); |
|
| 36 | + /** @var Domain|false $newDomain */ |
|
| 37 | + $newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database); |
|
| 38 | 38 | |
| 39 | - if ($newDomain === false) { |
|
| 40 | - $this->redirect('/'); |
|
| 39 | + if ($newDomain === false) { |
|
| 40 | + $this->redirect('/'); |
|
| 41 | 41 | |
| 42 | - return; |
|
| 43 | - } |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - try { |
|
| 46 | - $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain); |
|
| 47 | - } |
|
| 48 | - catch(DomainSwitchNotAllowedException $ex){ |
|
| 49 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 50 | - } |
|
| 45 | + try { |
|
| 46 | + $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain); |
|
| 47 | + } |
|
| 48 | + catch(DomainSwitchNotAllowedException $ex){ |
|
| 49 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // try to stay on the same page if possible. |
|
| 53 | - // This only checks basic ACLs and not domain privileges, so this may still result in a 403. |
|
| 52 | + // try to stay on the same page if possible. |
|
| 53 | + // This only checks basic ACLs and not domain privileges, so this may still result in a 403. |
|
| 54 | 54 | |
| 55 | - $referrer = WebRequest::postString('referrer'); |
|
| 56 | - $priorPath = explode('/', $referrer); |
|
| 57 | - $router = new RequestRouter(); |
|
| 58 | - $route = $router->getRouteFromPath($priorPath); |
|
| 55 | + $referrer = WebRequest::postString('referrer'); |
|
| 56 | + $priorPath = explode('/', $referrer); |
|
| 57 | + $router = new RequestRouter(); |
|
| 58 | + $route = $router->getRouteFromPath($priorPath); |
|
| 59 | 59 | |
| 60 | - if ($this->barrierTest($route[1], $currentUser, $route[0])) { |
|
| 61 | - $this->redirect('/' . $referrer); |
|
| 62 | - } else { |
|
| 63 | - $this->redirect('/'); |
|
| 64 | - } |
|
| 65 | - } |
|
| 60 | + if ($this->barrierTest($route[1], $currentUser, $route[0])) { |
|
| 61 | + $this->redirect('/' . $referrer); |
|
| 62 | + } else { |
|
| 63 | + $this->redirect('/'); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |
@@ -22,58 +22,58 @@ |
||
| 22 | 22 | |
| 23 | 23 | class PageUserReactivate extends InternalPageBase |
| 24 | 24 | { |
| 25 | - use LogEntryLookup; |
|
| 25 | + use LogEntryLookup; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @throws ApplicationLogicException |
|
| 29 | - * @throws Exception |
|
| 30 | - */ |
|
| 31 | - protected function main() |
|
| 32 | - { |
|
| 33 | - $db = $this->getDatabase(); |
|
| 34 | - $currentUser = User::getCurrent($db); |
|
| 27 | + /** |
|
| 28 | + * @throws ApplicationLogicException |
|
| 29 | + * @throws Exception |
|
| 30 | + */ |
|
| 31 | + protected function main() |
|
| 32 | + { |
|
| 33 | + $db = $this->getDatabase(); |
|
| 34 | + $currentUser = User::getCurrent($db); |
|
| 35 | 35 | |
| 36 | - // *Only* deactivated users should be able to access this. |
|
| 37 | - // Redirect anyone else away. |
|
| 38 | - if (!$currentUser->isDeactivated()) { |
|
| 39 | - $this->redirect(); |
|
| 40 | - return; |
|
| 41 | - } |
|
| 36 | + // *Only* deactivated users should be able to access this. |
|
| 37 | + // Redirect anyone else away. |
|
| 38 | + if (!$currentUser->isDeactivated()) { |
|
| 39 | + $this->redirect(); |
|
| 40 | + return; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $ableToAppeal = true; |
|
| 44 | - $prefs = new PreferenceManager($db, $currentUser->getId(), Domain::getCurrent($db)->getId()); |
|
| 45 | - if ($prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false) { |
|
| 46 | - $ableToAppeal = false; |
|
| 47 | - } |
|
| 43 | + $ableToAppeal = true; |
|
| 44 | + $prefs = new PreferenceManager($db, $currentUser->getId(), Domain::getCurrent($db)->getId()); |
|
| 45 | + if ($prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false) { |
|
| 46 | + $ableToAppeal = false; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - if (WebRequest::wasPosted()) { |
|
| 50 | - $this->validateCSRFToken(); |
|
| 49 | + if (WebRequest::wasPosted()) { |
|
| 50 | + $this->validateCSRFToken(); |
|
| 51 | 51 | |
| 52 | - $reason = WebRequest::postString('reason'); |
|
| 53 | - $updateVersion = WebRequest::postInt('updateVersion'); |
|
| 52 | + $reason = WebRequest::postString('reason'); |
|
| 53 | + $updateVersion = WebRequest::postInt('updateVersion'); |
|
| 54 | 54 | |
| 55 | - if (!$ableToAppeal) { |
|
| 56 | - throw new ApplicationLogicException('Appeal is disabled'); |
|
| 57 | - } |
|
| 55 | + if (!$ableToAppeal) { |
|
| 56 | + throw new ApplicationLogicException('Appeal is disabled'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - if ($reason === null || trim($reason) === '') { |
|
| 60 | - throw new ApplicationLogicException('The reason field cannot be empty.'); |
|
| 61 | - } |
|
| 59 | + if ($reason === null || trim($reason) === '') { |
|
| 60 | + throw new ApplicationLogicException('The reason field cannot be empty.'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - Logger::requestedReactivation($db, $currentUser, $reason); |
|
| 64 | - $currentUser->setStatus(User::STATUS_NEW); |
|
| 65 | - $currentUser->setUpdateVersion($updateVersion); |
|
| 66 | - $currentUser->save(); |
|
| 63 | + Logger::requestedReactivation($db, $currentUser, $reason); |
|
| 64 | + $currentUser->setStatus(User::STATUS_NEW); |
|
| 65 | + $currentUser->setUpdateVersion($updateVersion); |
|
| 66 | + $currentUser->save(); |
|
| 67 | 67 | |
| 68 | - SessionAlert::success('Reactivation request has been saved. Please wait for a response from the tool admin team.'); |
|
| 69 | - $this->redirect(); |
|
| 70 | - } |
|
| 71 | - else { |
|
| 72 | - $this->assignCSRFToken(); |
|
| 73 | - $this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $db)); |
|
| 74 | - $this->assign('updateVersion', $currentUser->getUpdateVersion()); |
|
| 75 | - $this->assign('ableToAppeal', $ableToAppeal); |
|
| 76 | - $this->setTemplate('reactivate.tpl'); |
|
| 77 | - } |
|
| 78 | - } |
|
| 68 | + SessionAlert::success('Reactivation request has been saved. Please wait for a response from the tool admin team.'); |
|
| 69 | + $this->redirect(); |
|
| 70 | + } |
|
| 71 | + else { |
|
| 72 | + $this->assignCSRFToken(); |
|
| 73 | + $this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $db)); |
|
| 74 | + $this->assign('updateVersion', $currentUser->getUpdateVersion()); |
|
| 75 | + $this->assign('ableToAppeal', $ableToAppeal); |
|
| 76 | + $this->setTemplate('reactivate.tpl'); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |
@@ -21,170 +21,170 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PagePreferences extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - protected function main() |
|
| 29 | - { |
|
| 30 | - $this->setHtmlTitle('Preferences'); |
|
| 31 | - |
|
| 32 | - $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
| 33 | - $database = $this->getDatabase(); |
|
| 34 | - $user = User::getCurrent($database); |
|
| 35 | - $preferencesManager = PreferenceManager::getForCurrent($database); |
|
| 36 | - |
|
| 37 | - // Dual mode |
|
| 38 | - if (WebRequest::wasPosted()) { |
|
| 39 | - $this->validateCSRFToken(); |
|
| 40 | - |
|
| 41 | - $this->setPreference($preferencesManager,PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature'); |
|
| 42 | - $this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', WebRequest::postBoolean('skipJsAbort') ? 1 : 0); |
|
| 43 | - $this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', WebRequest::postBoolean('showQueueHelp') ? 1 : 0); |
|
| 44 | - $this->setCreationMode($user, $preferencesManager); |
|
| 45 | - $this->setSkin($preferencesManager); |
|
| 46 | - $preferencesManager->setGlobalPreference(PreferenceManager::PREF_DEFAULT_DOMAIN, WebRequest::postInt('defaultDomain')); |
|
| 47 | - |
|
| 48 | - $email = WebRequest::postEmail('email'); |
|
| 49 | - if ($email !== null) { |
|
| 50 | - $user->setEmail($email); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $user->save(); |
|
| 54 | - SessionAlert::success("Preferences updated!"); |
|
| 55 | - |
|
| 56 | - if ($this->barrierTest(RoleConfigurationBase::MAIN, $user, PageMain::class)) { |
|
| 57 | - $this->redirect(''); |
|
| 58 | - } |
|
| 59 | - else { |
|
| 60 | - $this->redirect('preferences'); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - else { |
|
| 64 | - $this->assignCSRFToken(); |
|
| 65 | - $this->setTemplate('preferences/prefs.tpl'); |
|
| 66 | - |
|
| 67 | - // FIXME: domains! |
|
| 68 | - /** @var Domain $domain */ |
|
| 69 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 70 | - $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
| 71 | - |
|
| 72 | - $this->assign("enforceOAuth", $enforceOAuth); |
|
| 73 | - |
|
| 74 | - $this->assignPreference($preferencesManager, PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature', false); |
|
| 75 | - $this->assignPreference($preferencesManager, PreferenceManager::PREF_CREATION_MODE, 'creationMode', false); |
|
| 76 | - $this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin', true); |
|
| 77 | - $this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', false); |
|
| 78 | - $this->assignPreference($preferencesManager, PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', false, true); |
|
| 79 | - $this->assignPreference($preferencesManager, PreferenceManager::PREF_DEFAULT_DOMAIN, 'defaultDomain', true); |
|
| 80 | - |
|
| 81 | - $this->assign('canManualCreate', |
|
| 82 | - $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 83 | - $this->assign('canOauthCreate', |
|
| 84 | - $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 85 | - $this->assign('canBotCreate', |
|
| 86 | - $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation')); |
|
| 87 | - |
|
| 88 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 89 | - $this->getSiteConfiguration()); |
|
| 90 | - $this->assign('oauth', $oauth); |
|
| 91 | - |
|
| 92 | - $identity = null; |
|
| 93 | - if ($oauth->isFullyLinked()) { |
|
| 94 | - $identity = $oauth->getIdentity(true); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $this->assign('identity', $identity); |
|
| 98 | - $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - private function assignPreference( |
|
| 103 | - PreferenceManager $preferencesManager, |
|
| 104 | - string $preference, |
|
| 105 | - string $fieldName, |
|
| 106 | - bool $defaultGlobal, |
|
| 107 | - $defaultValue = null |
|
| 108 | - ): void { |
|
| 109 | - $this->assign($fieldName, $preferencesManager->getPreference($preference) ?? $defaultValue); |
|
| 110 | - $this->assign($fieldName . 'Global', $preferencesManager->isGlobalPreference($preference) ?? $defaultGlobal); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - private function setPreferenceWithValue( |
|
| 114 | - PreferenceManager $preferencesManager, |
|
| 115 | - string $preferenceName, |
|
| 116 | - string $fieldName, |
|
| 117 | - $value |
|
| 118 | - ): void { |
|
| 119 | - $globalDefinition = WebRequest::postBoolean($fieldName . 'Global'); |
|
| 120 | - if ($globalDefinition) { |
|
| 121 | - $preferencesManager->setGlobalPreference($preferenceName, $value); |
|
| 122 | - } |
|
| 123 | - else { |
|
| 124 | - $preferencesManager->setLocalPreference($preferenceName, $value); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - private function setPreference( |
|
| 129 | - PreferenceManager $preferencesManager, |
|
| 130 | - string $preferenceName, |
|
| 131 | - string $fieldName |
|
| 132 | - ): void { |
|
| 133 | - $this->setPreferenceWithValue($preferencesManager, $preferenceName, $fieldName, WebRequest::postString($fieldName)); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - protected function refreshOAuth() |
|
| 137 | - { |
|
| 138 | - if (!WebRequest::wasPosted()) { |
|
| 139 | - $this->redirect('preferences'); |
|
| 140 | - |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $database = $this->getDatabase(); |
|
| 145 | - $oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(), |
|
| 146 | - $this->getSiteConfiguration()); |
|
| 147 | - |
|
| 148 | - // token is for old consumer, run through the approval workflow again |
|
| 149 | - if ($oauth->getIdentity(true)->getAudience() !== $this->getSiteConfiguration()->getOAuthConsumerToken()) { |
|
| 150 | - $authoriseUrl = $oauth->getRequestToken(); |
|
| 151 | - $this->redirectUrl($authoriseUrl); |
|
| 152 | - |
|
| 153 | - return; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if ($oauth->isFullyLinked()) { |
|
| 157 | - $oauth->refreshIdentity(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $this->redirect('preferences'); |
|
| 161 | - |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - private function setCreationMode(User $user, PreferenceManager $preferenceManager) |
|
| 166 | - { |
|
| 167 | - // if the user is selecting a creation mode that they are not allowed, do nothing. |
|
| 168 | - // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
|
| 169 | - // or that they have kept from when they previously had certain access. |
|
| 170 | - // This setting is only settable locally, as ACLs may change between domains. |
|
| 171 | - $creationMode = WebRequest::postInt('creationMode'); |
|
| 172 | - |
|
| 173 | - if ($creationMode === null) { |
|
| 174 | - return; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if ($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
|
| 178 | - $preferenceManager->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postString('creationMode')); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - private function setSkin(PreferenceManager $preferencesManager): void |
|
| 183 | - { |
|
| 184 | - $newSkin = WebRequest::postString('skin'); |
|
| 185 | - $allowedSkins = ['main', 'alt', 'auto']; |
|
| 186 | - if (in_array($newSkin, $allowedSkins)) { |
|
| 187 | - $this->setPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin'); |
|
| 188 | - } |
|
| 189 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + protected function main() |
|
| 29 | + { |
|
| 30 | + $this->setHtmlTitle('Preferences'); |
|
| 31 | + |
|
| 32 | + $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
| 33 | + $database = $this->getDatabase(); |
|
| 34 | + $user = User::getCurrent($database); |
|
| 35 | + $preferencesManager = PreferenceManager::getForCurrent($database); |
|
| 36 | + |
|
| 37 | + // Dual mode |
|
| 38 | + if (WebRequest::wasPosted()) { |
|
| 39 | + $this->validateCSRFToken(); |
|
| 40 | + |
|
| 41 | + $this->setPreference($preferencesManager,PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature'); |
|
| 42 | + $this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', WebRequest::postBoolean('skipJsAbort') ? 1 : 0); |
|
| 43 | + $this->setPreferenceWithValue($preferencesManager,PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', WebRequest::postBoolean('showQueueHelp') ? 1 : 0); |
|
| 44 | + $this->setCreationMode($user, $preferencesManager); |
|
| 45 | + $this->setSkin($preferencesManager); |
|
| 46 | + $preferencesManager->setGlobalPreference(PreferenceManager::PREF_DEFAULT_DOMAIN, WebRequest::postInt('defaultDomain')); |
|
| 47 | + |
|
| 48 | + $email = WebRequest::postEmail('email'); |
|
| 49 | + if ($email !== null) { |
|
| 50 | + $user->setEmail($email); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $user->save(); |
|
| 54 | + SessionAlert::success("Preferences updated!"); |
|
| 55 | + |
|
| 56 | + if ($this->barrierTest(RoleConfigurationBase::MAIN, $user, PageMain::class)) { |
|
| 57 | + $this->redirect(''); |
|
| 58 | + } |
|
| 59 | + else { |
|
| 60 | + $this->redirect('preferences'); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + else { |
|
| 64 | + $this->assignCSRFToken(); |
|
| 65 | + $this->setTemplate('preferences/prefs.tpl'); |
|
| 66 | + |
|
| 67 | + // FIXME: domains! |
|
| 68 | + /** @var Domain $domain */ |
|
| 69 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 70 | + $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
| 71 | + |
|
| 72 | + $this->assign("enforceOAuth", $enforceOAuth); |
|
| 73 | + |
|
| 74 | + $this->assignPreference($preferencesManager, PreferenceManager::PREF_EMAIL_SIGNATURE, 'emailSignature', false); |
|
| 75 | + $this->assignPreference($preferencesManager, PreferenceManager::PREF_CREATION_MODE, 'creationMode', false); |
|
| 76 | + $this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin', true); |
|
| 77 | + $this->assignPreference($preferencesManager, PreferenceManager::PREF_SKIP_JS_ABORT, 'skipJsAbort', false); |
|
| 78 | + $this->assignPreference($preferencesManager, PreferenceManager::PREF_QUEUE_HELP, 'showQueueHelp', false, true); |
|
| 79 | + $this->assignPreference($preferencesManager, PreferenceManager::PREF_DEFAULT_DOMAIN, 'defaultDomain', true); |
|
| 80 | + |
|
| 81 | + $this->assign('canManualCreate', |
|
| 82 | + $this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 83 | + $this->assign('canOauthCreate', |
|
| 84 | + $this->barrierTest(PreferenceManager::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 85 | + $this->assign('canBotCreate', |
|
| 86 | + $this->barrierTest(PreferenceManager::CREATION_BOT, $user, 'RequestCreation')); |
|
| 87 | + |
|
| 88 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 89 | + $this->getSiteConfiguration()); |
|
| 90 | + $this->assign('oauth', $oauth); |
|
| 91 | + |
|
| 92 | + $identity = null; |
|
| 93 | + if ($oauth->isFullyLinked()) { |
|
| 94 | + $identity = $oauth->getIdentity(true); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $this->assign('identity', $identity); |
|
| 98 | + $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + private function assignPreference( |
|
| 103 | + PreferenceManager $preferencesManager, |
|
| 104 | + string $preference, |
|
| 105 | + string $fieldName, |
|
| 106 | + bool $defaultGlobal, |
|
| 107 | + $defaultValue = null |
|
| 108 | + ): void { |
|
| 109 | + $this->assign($fieldName, $preferencesManager->getPreference($preference) ?? $defaultValue); |
|
| 110 | + $this->assign($fieldName . 'Global', $preferencesManager->isGlobalPreference($preference) ?? $defaultGlobal); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + private function setPreferenceWithValue( |
|
| 114 | + PreferenceManager $preferencesManager, |
|
| 115 | + string $preferenceName, |
|
| 116 | + string $fieldName, |
|
| 117 | + $value |
|
| 118 | + ): void { |
|
| 119 | + $globalDefinition = WebRequest::postBoolean($fieldName . 'Global'); |
|
| 120 | + if ($globalDefinition) { |
|
| 121 | + $preferencesManager->setGlobalPreference($preferenceName, $value); |
|
| 122 | + } |
|
| 123 | + else { |
|
| 124 | + $preferencesManager->setLocalPreference($preferenceName, $value); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + private function setPreference( |
|
| 129 | + PreferenceManager $preferencesManager, |
|
| 130 | + string $preferenceName, |
|
| 131 | + string $fieldName |
|
| 132 | + ): void { |
|
| 133 | + $this->setPreferenceWithValue($preferencesManager, $preferenceName, $fieldName, WebRequest::postString($fieldName)); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + protected function refreshOAuth() |
|
| 137 | + { |
|
| 138 | + if (!WebRequest::wasPosted()) { |
|
| 139 | + $this->redirect('preferences'); |
|
| 140 | + |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $database = $this->getDatabase(); |
|
| 145 | + $oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(), |
|
| 146 | + $this->getSiteConfiguration()); |
|
| 147 | + |
|
| 148 | + // token is for old consumer, run through the approval workflow again |
|
| 149 | + if ($oauth->getIdentity(true)->getAudience() !== $this->getSiteConfiguration()->getOAuthConsumerToken()) { |
|
| 150 | + $authoriseUrl = $oauth->getRequestToken(); |
|
| 151 | + $this->redirectUrl($authoriseUrl); |
|
| 152 | + |
|
| 153 | + return; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if ($oauth->isFullyLinked()) { |
|
| 157 | + $oauth->refreshIdentity(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $this->redirect('preferences'); |
|
| 161 | + |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + private function setCreationMode(User $user, PreferenceManager $preferenceManager) |
|
| 166 | + { |
|
| 167 | + // if the user is selecting a creation mode that they are not allowed, do nothing. |
|
| 168 | + // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
|
| 169 | + // or that they have kept from when they previously had certain access. |
|
| 170 | + // This setting is only settable locally, as ACLs may change between domains. |
|
| 171 | + $creationMode = WebRequest::postInt('creationMode'); |
|
| 172 | + |
|
| 173 | + if ($creationMode === null) { |
|
| 174 | + return; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if ($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
|
| 178 | + $preferenceManager->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postString('creationMode')); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + private function setSkin(PreferenceManager $preferencesManager): void |
|
| 183 | + { |
|
| 184 | + $newSkin = WebRequest::postString('skin'); |
|
| 185 | + $allowedSkins = ['main', 'alt', 'auto']; |
|
| 186 | + if (in_array($newSkin, $allowedSkins)) { |
|
| 187 | + $this->setPreference($preferencesManager, PreferenceManager::PREF_SKIN, 'skin'); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -15,102 +15,102 @@ |
||
| 15 | 15 | |
| 16 | 16 | class StatsMain extends InternalPageBase |
| 17 | 17 | { |
| 18 | - public function main() |
|
| 19 | - { |
|
| 20 | - $this->setHtmlTitle('Statistics'); |
|
| 21 | - |
|
| 22 | - $this->assign('statsPageTitle', 'Account Creation Statistics'); |
|
| 23 | - |
|
| 24 | - $statsPages = array( |
|
| 25 | - 'fastCloses' => 'Requests closed less than 30 seconds after reservation in the past 3 months', |
|
| 26 | - 'inactiveUsers' => 'Inactive tool users', |
|
| 27 | - 'monthlyStats' => 'Monthly Statistics', |
|
| 28 | - 'reservedRequests' => 'All currently reserved requests', |
|
| 29 | - 'templateStats' => 'Template Stats', |
|
| 30 | - 'topCreators' => 'Top Account Creators', |
|
| 31 | - 'users' => 'Account Creation Tool users', |
|
| 32 | - ); |
|
| 33 | - |
|
| 34 | - $this->generateSmallStatsTable(); |
|
| 35 | - |
|
| 36 | - $this->assign('statsPages', $statsPages); |
|
| 37 | - |
|
| 38 | - $graphList = array('day', '2day', '4day', 'week', '2week', 'month', '3month'); |
|
| 39 | - $this->assign('graphList', $graphList); |
|
| 40 | - |
|
| 41 | - $this->setTemplate('statistics/main.tpl'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Gets the relevant statistics from the database for the small statistics table |
|
| 46 | - */ |
|
| 47 | - private function generateSmallStatsTable() |
|
| 48 | - { |
|
| 49 | - $database = $this->getDatabase(); |
|
| 50 | - $requestsQuery = <<<'SQL' |
|
| 18 | + public function main() |
|
| 19 | + { |
|
| 20 | + $this->setHtmlTitle('Statistics'); |
|
| 21 | + |
|
| 22 | + $this->assign('statsPageTitle', 'Account Creation Statistics'); |
|
| 23 | + |
|
| 24 | + $statsPages = array( |
|
| 25 | + 'fastCloses' => 'Requests closed less than 30 seconds after reservation in the past 3 months', |
|
| 26 | + 'inactiveUsers' => 'Inactive tool users', |
|
| 27 | + 'monthlyStats' => 'Monthly Statistics', |
|
| 28 | + 'reservedRequests' => 'All currently reserved requests', |
|
| 29 | + 'templateStats' => 'Template Stats', |
|
| 30 | + 'topCreators' => 'Top Account Creators', |
|
| 31 | + 'users' => 'Account Creation Tool users', |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + $this->generateSmallStatsTable(); |
|
| 35 | + |
|
| 36 | + $this->assign('statsPages', $statsPages); |
|
| 37 | + |
|
| 38 | + $graphList = array('day', '2day', '4day', 'week', '2week', 'month', '3month'); |
|
| 39 | + $this->assign('graphList', $graphList); |
|
| 40 | + |
|
| 41 | + $this->setTemplate('statistics/main.tpl'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Gets the relevant statistics from the database for the small statistics table |
|
| 46 | + */ |
|
| 47 | + private function generateSmallStatsTable() |
|
| 48 | + { |
|
| 49 | + $database = $this->getDatabase(); |
|
| 50 | + $requestsQuery = <<<'SQL' |
|
| 51 | 51 | SELECT COUNT(*) FROM request WHERE status = :status AND queue = :queue AND emailconfirm = 'Confirmed'; |
| 52 | 52 | SQL; |
| 53 | - $requestsStatement = $database->prepare($requestsQuery); |
|
| 53 | + $requestsStatement = $database->prepare($requestsQuery); |
|
| 54 | 54 | |
| 55 | - $requestStateData = array(); |
|
| 55 | + $requestStateData = array(); |
|
| 56 | 56 | |
| 57 | - foreach (RequestQueue::getEnabledQueues($database) as $queue) { |
|
| 58 | - $requestsStatement->execute(array( |
|
| 59 | - ':status' => RequestStatus::OPEN, |
|
| 60 | - ':queue' => $queue->getId(), |
|
| 61 | - )); |
|
| 62 | - $requestCount = $requestsStatement->fetchColumn(); |
|
| 63 | - $requestsStatement->closeCursor(); |
|
| 64 | - $headerText = $queue->getHeader(); |
|
| 65 | - $requestStateData[$headerText] = $requestCount; |
|
| 66 | - } |
|
| 57 | + foreach (RequestQueue::getEnabledQueues($database) as $queue) { |
|
| 58 | + $requestsStatement->execute(array( |
|
| 59 | + ':status' => RequestStatus::OPEN, |
|
| 60 | + ':queue' => $queue->getId(), |
|
| 61 | + )); |
|
| 62 | + $requestCount = $requestsStatement->fetchColumn(); |
|
| 63 | + $requestsStatement->closeCursor(); |
|
| 64 | + $headerText = $queue->getHeader(); |
|
| 65 | + $requestStateData[$headerText] = $requestCount; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $this->assign('requestCountData', $requestStateData); |
|
| 68 | + $this->assign('requestCountData', $requestStateData); |
|
| 69 | 69 | |
| 70 | - // Unconfirmed requests |
|
| 71 | - $unconfirmedStatement = $database->query(<<<SQL |
|
| 70 | + // Unconfirmed requests |
|
| 71 | + $unconfirmedStatement = $database->query(<<<SQL |
|
| 72 | 72 | SELECT COUNT(*) FROM request WHERE emailconfirm != 'Confirmed' AND emailconfirm != ''; |
| 73 | 73 | SQL |
| 74 | - ); |
|
| 75 | - $unconfirmed = $unconfirmedStatement->fetchColumn(); |
|
| 76 | - $unconfirmedStatement->closeCursor(); |
|
| 77 | - $this->assign('statsUnconfirmed', $unconfirmed); |
|
| 78 | - |
|
| 79 | - $userRoleStatement = $database->prepare('SELECT COUNT(*) FROM user INNER JOIN userrole ON user.id = userrole.user WHERE userrole.role = :role AND user.status = \'Active\';'); |
|
| 80 | - |
|
| 81 | - // Admin users |
|
| 82 | - $userRoleStatement->execute(array(':role' => 'admin')); |
|
| 83 | - $adminUsers = $userRoleStatement->fetchColumn(); |
|
| 84 | - $userRoleStatement->closeCursor(); |
|
| 85 | - $this->assign('statsAdminUsers', $adminUsers); |
|
| 86 | - |
|
| 87 | - // Users |
|
| 88 | - $userRoleStatement->execute(array(':role' => 'user')); |
|
| 89 | - $users = $userRoleStatement->fetchColumn(); |
|
| 90 | - $userRoleStatement->closeCursor(); |
|
| 91 | - $this->assign('statsUsers', $users); |
|
| 92 | - |
|
| 93 | - $userStatusStatement = $database->prepare('SELECT COUNT(*) FROM user WHERE status = :status;'); |
|
| 74 | + ); |
|
| 75 | + $unconfirmed = $unconfirmedStatement->fetchColumn(); |
|
| 76 | + $unconfirmedStatement->closeCursor(); |
|
| 77 | + $this->assign('statsUnconfirmed', $unconfirmed); |
|
| 78 | + |
|
| 79 | + $userRoleStatement = $database->prepare('SELECT COUNT(*) FROM user INNER JOIN userrole ON user.id = userrole.user WHERE userrole.role = :role AND user.status = \'Active\';'); |
|
| 80 | + |
|
| 81 | + // Admin users |
|
| 82 | + $userRoleStatement->execute(array(':role' => 'admin')); |
|
| 83 | + $adminUsers = $userRoleStatement->fetchColumn(); |
|
| 84 | + $userRoleStatement->closeCursor(); |
|
| 85 | + $this->assign('statsAdminUsers', $adminUsers); |
|
| 86 | + |
|
| 87 | + // Users |
|
| 88 | + $userRoleStatement->execute(array(':role' => 'user')); |
|
| 89 | + $users = $userRoleStatement->fetchColumn(); |
|
| 90 | + $userRoleStatement->closeCursor(); |
|
| 91 | + $this->assign('statsUsers', $users); |
|
| 92 | + |
|
| 93 | + $userStatusStatement = $database->prepare('SELECT COUNT(*) FROM user WHERE status = :status;'); |
|
| 94 | 94 | |
| 95 | - // Deactivated users |
|
| 96 | - $userStatusStatement->execute(array(':status' => 'Deactivated')); |
|
| 97 | - $deactivatedUsers = $userStatusStatement->fetchColumn(); |
|
| 98 | - $userStatusStatement->closeCursor(); |
|
| 99 | - $this->assign('statsDeactivatedUsers', $deactivatedUsers); |
|
| 100 | - |
|
| 101 | - // New users |
|
| 102 | - $userStatusStatement->execute(array(':status' => 'New')); |
|
| 103 | - $newUsers = $userStatusStatement->fetchColumn(); |
|
| 104 | - $userStatusStatement->closeCursor(); |
|
| 105 | - $this->assign('statsNewUsers', $newUsers); |
|
| 106 | - |
|
| 107 | - // Most comments on a request |
|
| 108 | - $mostCommentsStatement = $database->query(<<<SQL |
|
| 95 | + // Deactivated users |
|
| 96 | + $userStatusStatement->execute(array(':status' => 'Deactivated')); |
|
| 97 | + $deactivatedUsers = $userStatusStatement->fetchColumn(); |
|
| 98 | + $userStatusStatement->closeCursor(); |
|
| 99 | + $this->assign('statsDeactivatedUsers', $deactivatedUsers); |
|
| 100 | + |
|
| 101 | + // New users |
|
| 102 | + $userStatusStatement->execute(array(':status' => 'New')); |
|
| 103 | + $newUsers = $userStatusStatement->fetchColumn(); |
|
| 104 | + $userStatusStatement->closeCursor(); |
|
| 105 | + $this->assign('statsNewUsers', $newUsers); |
|
| 106 | + |
|
| 107 | + // Most comments on a request |
|
| 108 | + $mostCommentsStatement = $database->query(<<<SQL |
|
| 109 | 109 | SELECT request FROM comment GROUP BY request ORDER BY COUNT(*) DESC LIMIT 1; |
| 110 | 110 | SQL |
| 111 | - ); |
|
| 112 | - $mostComments = $mostCommentsStatement->fetchColumn(); |
|
| 113 | - $mostCommentsStatement->closeCursor(); |
|
| 114 | - $this->assign('mostComments', $mostComments); |
|
| 115 | - } |
|
| 111 | + ); |
|
| 112 | + $mostComments = $mostCommentsStatement->fetchColumn(); |
|
| 113 | + $mostCommentsStatement->closeCursor(); |
|
| 114 | + $this->assign('mostComments', $mostComments); |
|
| 115 | + } |
|
| 116 | 116 | } |