1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
4
|
|
|
* * |
5
|
|
|
* All code in this file is released into the public domain by the ACC * |
6
|
|
|
* Development Team. Please see team.json for a list of contributors. * |
7
|
|
|
******************************************************************************/ |
8
|
|
|
|
9
|
|
|
namespace Waca\Pages\Statistics; |
10
|
|
|
|
11
|
|
|
use PDO; |
12
|
|
|
use Waca\DataObjects\Log; |
13
|
|
|
use Waca\DataObjects\User; |
14
|
|
|
use Waca\Exceptions\ApplicationLogicException; |
15
|
|
|
use Waca\Helpers\LogHelper; |
16
|
|
|
use Waca\Helpers\SearchHelpers\LogSearchHelper; |
17
|
|
|
use Waca\Helpers\SearchHelpers\UserSearchHelper; |
18
|
|
|
use Waca\Pages\PageUserManagement; |
19
|
|
|
use Waca\Tasks\InternalPageBase; |
20
|
|
|
use Waca\WebRequest; |
21
|
|
|
|
22
|
|
|
class StatsUsers extends InternalPageBase |
23
|
|
|
{ |
24
|
|
View Code Duplication |
public function main() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$this->setHtmlTitle('Users :: Statistics'); |
27
|
|
|
|
28
|
|
|
$database = $this->getDatabase(); |
29
|
|
|
|
30
|
|
|
$query = <<<SQL |
31
|
|
|
select |
32
|
|
|
u.id |
33
|
|
|
, u.username |
34
|
|
|
, case when ru.role is not null then 'Yes' else 'No' end tooluser |
35
|
|
|
, case when ra.role is not null then 'Yes' else 'No' end tooladmin |
36
|
|
|
, case when rc.role is not null then 'Yes' else 'No' end checkuser |
37
|
|
|
, case when rr.role is not null then 'Yes' else 'No' end toolroot |
38
|
|
|
from user u |
39
|
|
|
left join userrole ru on ru.user = u.id and ru.role = 'user' |
40
|
|
|
left join userrole ra on ra.user = u.id and ra.role = 'admin' |
41
|
|
|
left join userrole rc on rc.user = u.id and rc.role = 'checkuser' |
42
|
|
|
left join userrole rr on rr.user = u.id and rr.role = 'toolRoot' |
43
|
|
|
where u.status = 'Active' |
44
|
|
|
SQL; |
45
|
|
|
|
46
|
|
|
$users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC); |
47
|
|
|
$this->assign('users', $users); |
48
|
|
|
|
49
|
|
|
$this->assign('statsPageTitle', 'Account Creation Tool users'); |
50
|
|
|
$this->setTemplate("statistics/users.tpl"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Entry point for the detail action. |
55
|
|
|
* |
56
|
|
|
* @throws ApplicationLogicException |
57
|
|
|
*/ |
58
|
|
|
protected function detail() |
59
|
|
|
{ |
60
|
|
|
$userId = WebRequest::getInt('user'); |
61
|
|
|
if ($userId === null) { |
62
|
|
|
throw new ApplicationLogicException("User not found"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$database = $this->getDatabase(); |
66
|
|
|
|
67
|
|
|
$user = User::getById($userId, $database); |
68
|
|
|
if ($user == false) { |
69
|
|
|
throw new ApplicationLogicException('User not found'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$safeUsername = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'); |
73
|
|
|
$this->setHtmlTitle($safeUsername . ' :: Users :: Statistics'); |
74
|
|
|
|
75
|
|
|
$activitySummary = $database->prepare(<<<SQL |
76
|
|
|
SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count |
77
|
|
|
FROM log |
78
|
|
|
INNER JOIN user ON log.user = user.id |
79
|
|
|
LEFT JOIN closes ON log.action = closes.closes |
80
|
|
|
WHERE user.username = :username |
81
|
|
|
GROUP BY action; |
82
|
|
|
SQL |
83
|
|
|
); |
84
|
|
|
$activitySummary->execute(array(":username" => $user->getUsername())); |
85
|
|
|
$activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
86
|
|
|
|
87
|
|
|
$this->assign("user", $user); |
88
|
|
|
$this->assign("activity", $activitySummaryData); |
89
|
|
|
|
90
|
|
|
$usersCreatedQuery = $database->prepare(<<<SQL |
91
|
|
|
SELECT log.timestamp time, request.name name, request.id id |
92
|
|
|
FROM log |
93
|
|
|
INNER JOIN request ON (request.id = log.objectid AND log.objecttype = 'Request') |
94
|
|
|
INNER JOIN user ON log.user = user.id |
95
|
|
|
LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
96
|
|
|
WHERE user.username = :username |
97
|
|
|
AND log.action LIKE 'Closed %' |
98
|
|
|
AND (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
99
|
|
|
ORDER BY log.timestamp; |
100
|
|
|
SQL |
101
|
|
|
); |
102
|
|
|
$usersCreatedQuery->execute(array(":username" => $user->getUsername())); |
103
|
|
|
$usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
104
|
|
|
$this->assign("created", $usersCreated); |
105
|
|
|
|
106
|
|
|
$usersNotCreatedQuery = $database->prepare(<<<SQL |
107
|
|
|
SELECT log.timestamp time, request.name name, request.id id |
108
|
|
|
FROM log |
109
|
|
|
JOIN request ON request.id = log.objectid AND log.objecttype = 'Request' |
110
|
|
|
JOIN user ON log.user = user.id |
111
|
|
|
LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
112
|
|
|
WHERE user.username = :username |
113
|
|
|
AND log.action LIKE 'Closed %' |
114
|
|
|
AND (emailtemplate.oncreated = '0' OR log.action = 'Closed custom-n' OR log.action = 'Closed 0') |
115
|
|
|
ORDER BY log.timestamp; |
116
|
|
|
SQL |
117
|
|
|
); |
118
|
|
|
$usersNotCreatedQuery->execute(array(":username" => $user->getUsername())); |
119
|
|
|
$usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
120
|
|
|
$this->assign("notcreated", $usersNotCreated); |
121
|
|
|
|
122
|
|
|
/** @var Log[] $logs */ |
123
|
|
|
$logs = LogSearchHelper::get($database) |
124
|
|
|
->byObjectType('User') |
125
|
|
|
->byObjectId($user->getId()) |
126
|
|
|
->getRecordCount($logCount) |
127
|
|
|
->fetch(); |
128
|
|
|
|
129
|
|
|
if ($logCount === 0) { |
130
|
|
|
$this->assign('accountlog', array()); |
131
|
|
|
} |
132
|
|
|
else { |
133
|
|
|
list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
134
|
|
|
|
135
|
|
|
$this->assign("accountlog", $logData); |
136
|
|
|
$this->assign("users", $users); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$currentUser = User::getCurrent($database); |
140
|
|
|
$this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
141
|
|
|
$this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class)); |
142
|
|
|
$this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
143
|
|
|
$this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class)); |
144
|
|
|
$this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class)); |
145
|
|
|
$this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class)); |
146
|
|
|
|
147
|
|
|
$this->assign('statsPageTitle', 'Account Creation Tool users'); |
148
|
|
|
$this->setTemplate("statistics/userdetail.tpl"); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.