|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Helper\ApiHelper; |
|
6
|
|
|
use AppBundle\Helper\AutomatedEditsHelper; |
|
7
|
|
|
use AppBundle\Helper\EditCounterHelper; |
|
8
|
|
|
use AppBundle\Helper\LabsHelper; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
13
|
|
|
use Symfony\Component\VarDumper\VarDumper; |
|
14
|
|
|
|
|
15
|
|
|
class EditCounterController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/ec", name="ec") |
|
19
|
|
|
* @Route("/ec", name="EditCounter") |
|
20
|
|
|
* @Route("/ec/", name="EditCounterSlash") |
|
21
|
|
|
* @Route("/ec/index.php", name="EditCounterIndexPhp") |
|
22
|
|
|
* @Route("/ec/{project}", name="EditCounterProject") |
|
23
|
|
|
*/ |
|
24
|
|
|
public function indexAction(Request $request, $project = null) |
|
25
|
|
|
{ |
|
26
|
|
|
$lh = $this->get("app.labs_helper"); |
|
27
|
|
|
$lh->checkEnabled("ec"); |
|
28
|
|
|
|
|
29
|
|
|
$queryProject = $request->query->get('project'); |
|
30
|
|
|
$username = $request->query->get('user'); |
|
31
|
|
|
|
|
32
|
|
|
if (($project || $queryProject) && $username) { |
|
33
|
|
|
$routeParams = [ 'project'=>($project ?: $queryProject), 'username' => $username ]; |
|
34
|
|
|
return $this->redirectToRoute("EditCounterResult", $routeParams); |
|
35
|
|
|
} elseif (!$project && $queryProject) { |
|
36
|
|
|
return $this->redirectToRoute("EditCounterProject", [ 'project'=>$queryProject ]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// Otherwise fall through. |
|
40
|
|
|
return $this->render('editCounter/index.html.twig', [ |
|
41
|
|
|
"xtPageTitle" => "tool_ec", |
|
42
|
|
|
"xtSubtitle" => "tool_ec_desc", |
|
43
|
|
|
'xtPage' => "ec", |
|
44
|
|
|
'xtTitle' => "tool_ec", |
|
45
|
|
|
'project' => $project, |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @Route("/ec/{project}/{username}", name="EditCounterResult") |
|
51
|
|
|
*/ |
|
52
|
|
|
public function resultAction($project, $username) |
|
53
|
|
|
{ |
|
54
|
|
|
/** @var LabsHelper $lh */ |
|
55
|
|
|
$lh = $this->get('app.labs_helper'); |
|
56
|
|
|
/** @var EditCounterHelper $ec */ |
|
57
|
|
|
$ec = $this->get('app.editcounter_helper'); |
|
58
|
|
|
/** @var ApiHelper $api */ |
|
59
|
|
|
$api = $this->get('app.api_helper'); |
|
60
|
|
|
/** @var AutomatedEditsHelper $automatedEditsHelper */ |
|
61
|
|
|
$automatedEditsHelper = $this->get('app.automated_edits_helper'); |
|
62
|
|
|
|
|
63
|
|
|
// Check, clean, and get inputs. |
|
64
|
|
|
$lh->checkEnabled("ec"); |
|
65
|
|
|
$username = ucfirst($username); |
|
66
|
|
|
$dbValues = $lh->databasePrepare($project); |
|
67
|
|
|
$dbName = $dbValues["dbName"]; |
|
68
|
|
|
$wikiName = $dbValues["wikiName"]; |
|
69
|
|
|
$url = $dbValues["url"]; |
|
70
|
|
|
|
|
71
|
|
|
// Get statistics. |
|
72
|
|
|
$userId = $ec->getUserId($username); |
|
73
|
|
|
$revisionCounts = $ec->getRevisionCounts($userId); |
|
74
|
|
|
$pageCounts = $ec->getPageCounts($username, $revisionCounts['total']); |
|
75
|
|
|
$logCounts = $ec->getLogCounts($userId); |
|
76
|
|
|
$namespaceTotals = $ec->getNamespaceTotals($userId); |
|
77
|
|
|
$automatedEditsSummary = $automatedEditsHelper->getEditsSummary($userId); |
|
78
|
|
|
$topProjectsEditCounts = $ec->getTopProjectsEditCounts($username); |
|
79
|
|
|
$recentGlobalContribs = $ec->getRecentGlobalContribs($username); |
|
80
|
|
|
$yearlyTotalsByNamespace = $ec->getYearlyTotalsByNamespace($username); |
|
81
|
|
|
|
|
82
|
|
|
// Give it all to the template. |
|
83
|
|
|
return $this->render('editCounter/result.html.twig', [ |
|
84
|
|
|
'xtTitle' => 'tool_ec', |
|
85
|
|
|
'xtPage' => 'ec', |
|
86
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'), |
|
87
|
|
|
'is_labs' => $lh->isLabs(), |
|
88
|
|
|
|
|
89
|
|
|
// Project. |
|
90
|
|
|
'project' => $project, |
|
91
|
|
|
'wiki' => $dbName, |
|
92
|
|
|
'name' => $wikiName, |
|
93
|
|
|
'url' => $url, |
|
94
|
|
|
'namespaces' => $api->namespaces($project), |
|
95
|
|
|
|
|
96
|
|
|
// User and groups. |
|
97
|
|
|
'username' => $username, |
|
98
|
|
|
'user_id' => $userId, |
|
99
|
|
|
'user_groups' => $api->groups($project, $username), |
|
100
|
|
|
'global_groups' => $api->globalGroups($project, $username), |
|
101
|
|
|
|
|
102
|
|
|
// Revision counts. |
|
103
|
|
|
'deleted_edits' => $revisionCounts['deleted'], |
|
104
|
|
|
'total_edits' => $revisionCounts['total'], |
|
105
|
|
|
'live_edits' => $revisionCounts['live'], |
|
106
|
|
|
'first_rev' => $revisionCounts['first'], |
|
107
|
|
|
'latest_rev' => $revisionCounts['last'], |
|
108
|
|
|
'days' => $revisionCounts['days'], |
|
109
|
|
|
'avg_per_day' => $revisionCounts['avg_per_day'], |
|
110
|
|
|
'rev_24h' => $revisionCounts['24h'], |
|
111
|
|
|
'rev_7d' => $revisionCounts['7d'], |
|
112
|
|
|
'rev_30d' => $revisionCounts['30d'], |
|
113
|
|
|
'rev_365d' => $revisionCounts['365d'], |
|
114
|
|
|
'rev_small' => $revisionCounts['small'], |
|
115
|
|
|
'rev_large' => $revisionCounts['large'], |
|
116
|
|
|
'with_comments' => $revisionCounts['with_comments'], |
|
117
|
|
|
'without_comments' => $revisionCounts['live'] - $revisionCounts['with_comments'], |
|
118
|
|
|
'minor_edits' => $revisionCounts['minor_edits'], |
|
119
|
|
|
'nonminor_edits' => $revisionCounts['live'] - $revisionCounts['minor_edits'], |
|
120
|
|
|
|
|
121
|
|
|
// Page counts. |
|
122
|
|
|
'uniquePages' => $pageCounts['unique'], |
|
123
|
|
|
'pagesCreated' => $pageCounts['created'], |
|
124
|
|
|
'pagesMoved' => $pageCounts['moved'], |
|
125
|
|
|
'editsPerPage' => $pageCounts['edits_per_page'], |
|
126
|
|
|
|
|
127
|
|
|
// Log counts (keys are 'log name'-'action'). |
|
128
|
|
|
'pagesThanked' => $logCounts['thanks-thank'], |
|
129
|
|
|
'pagesApproved' => $logCounts['review-approve'], // Merged -a, -i, and -ia approvals. |
|
130
|
|
|
'pagesPatrolled' => $logCounts['patrol-patrol'], |
|
131
|
|
|
'usersBlocked' => $logCounts['block-block'], |
|
132
|
|
|
'usersUnblocked' => $logCounts['block-unblock'], |
|
133
|
|
|
'pagesProtected' => $logCounts['protect-protect'], |
|
134
|
|
|
'pagesUnprotected' => $logCounts['protect-unprotect'], |
|
135
|
|
|
'pagesDeleted' => $logCounts['delete-delete'], |
|
136
|
|
|
'pagesDeletedRevision' => $logCounts['delete-revision'], |
|
137
|
|
|
'pagesRestored' => $logCounts['delete-restore'], |
|
138
|
|
|
'pagesImported' => $logCounts['import-import'], |
|
139
|
|
|
'files_uploaded' => $logCounts['upload-upload'], |
|
140
|
|
|
'files_modified' => $logCounts['upload-overwrite'], |
|
141
|
|
|
'files_uploaded_commons' => $logCounts['files_uploaded_commons'], |
|
142
|
|
|
|
|
143
|
|
|
// Namespace Totals |
|
144
|
|
|
'namespaceArray' => $namespaceTotals, |
|
145
|
|
|
'namespaceTotal' => array_sum($namespaceTotals), |
|
146
|
|
|
'yearcounts' => $yearlyTotalsByNamespace, |
|
147
|
|
|
|
|
148
|
|
|
// Semi-automated edits. |
|
149
|
|
|
'auto_edits' => $automatedEditsSummary, |
|
150
|
|
|
'auto_edits_total' => array_sum($automatedEditsSummary), |
|
151
|
|
|
|
|
152
|
|
|
// Other projects. |
|
153
|
|
|
'top_projects_edit_counts' => $topProjectsEditCounts, |
|
154
|
|
|
'recent_global_contribs' => $recentGlobalContribs, |
|
155
|
|
|
|
|
156
|
|
|
]); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @Route("/ec-timecard/{project}/{username}", name="EditCounterTimeCard") |
|
161
|
|
|
*/ |
|
162
|
|
|
public function timecardAction($project, $username) |
|
163
|
|
|
{ |
|
164
|
|
|
/** @var LabsHelper $lh */ |
|
165
|
|
|
$lh = $this->get('app.labs_helper'); |
|
166
|
|
|
/** @var EditCounterHelper $ec */ |
|
167
|
|
|
$ec = $this->get('app.editcounter_helper'); |
|
168
|
|
|
|
|
169
|
|
|
$lh->databasePrepare($project); |
|
170
|
|
|
$username = ucfirst($username); |
|
171
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
|
172
|
|
|
$datasets = $ec->getTimeCard($username); |
|
173
|
|
|
return $this->render('editCounter/timecard.html.twig', [ |
|
174
|
|
|
'xtTitle' => 'tool_ec', |
|
175
|
|
|
'xtPage' => 'ec', |
|
176
|
|
|
'is_sub_request' => $isSubRequest, |
|
177
|
|
|
'datasets' => $datasets, |
|
178
|
|
|
]); |
|
179
|
|
|
} |
|
180
|
|
|
/** |
|
181
|
|
|
* @Route("/ec-monthcounts/{project}/{username}", name="EditCounterMonthCounts") |
|
182
|
|
|
*/ |
|
183
|
|
|
public function monthcountsAction($project, $username) |
|
184
|
|
|
{ |
|
185
|
|
|
/** @var LabsHelper $lh */ |
|
186
|
|
|
$lh = $this->get('app.labs_helper'); |
|
187
|
|
|
$lh->databasePrepare($project); |
|
188
|
|
|
|
|
189
|
|
|
/** @var EditCounterHelper $ec */ |
|
190
|
|
|
$ec = $this->get('app.editcounter_helper'); |
|
191
|
|
|
$username = ucfirst($username); |
|
192
|
|
|
$monthlyTotalsByNamespace = $ec->getMonthCounts($username); |
|
193
|
|
|
|
|
194
|
|
|
/** @var ApiHelper $api */ |
|
195
|
|
|
$api = $this->get('app.api_helper'); |
|
196
|
|
|
|
|
197
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
|
198
|
|
|
return $this->render('editCounter/monthcounts.html.twig', [ |
|
199
|
|
|
'xtTitle' => 'tool_ec', |
|
200
|
|
|
'xtPage' => 'ec', |
|
201
|
|
|
'is_sub_request' => $isSubRequest, |
|
202
|
|
|
'month_counts' => $monthlyTotalsByNamespace, |
|
203
|
|
|
'namespaces' => $api->namespaces($project), |
|
204
|
|
|
]); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|