|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Helper\ApiHelper; |
|
6
|
|
|
use AppBundle\Helper\AutomatedEditsHelper; |
|
7
|
|
|
use AppBundle\Helper\LabsHelper; |
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\VarDumper\VarDumper; |
|
12
|
|
|
use Xtools\EditCounter; |
|
13
|
|
|
use Xtools\EditCounterRepository; |
|
14
|
|
|
use Xtools\Project; |
|
15
|
|
|
use Xtools\ProjectRepository; |
|
16
|
|
|
use Xtools\User; |
|
17
|
|
|
use Xtools\UserRepository; |
|
18
|
|
|
|
|
19
|
|
|
class EditCounterController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** @var User */ |
|
23
|
|
|
protected $user; |
|
24
|
|
|
|
|
25
|
|
|
/** @var Project */ |
|
26
|
|
|
protected $project; |
|
27
|
|
|
|
|
28
|
|
|
/** @var EditCounter */ |
|
29
|
|
|
protected $editCounter; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Every action in this controller (other than 'index') calls this first. |
|
33
|
|
|
* @param string|boolean $project |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function setUpEditCounter($project = false, $username = false) |
|
36
|
|
|
{ |
|
37
|
|
|
// Make sure EditCounter is enabled. |
|
38
|
|
|
$this->get('app.labs_helper')->checkEnabled("ec"); |
|
39
|
|
|
|
|
40
|
|
|
$this->project = ProjectRepository::getProject($project, $this->container); |
|
|
|
|
|
|
41
|
|
|
$this->user = UserRepository::getUser($username, $this->container); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
// Get an edit-counter. |
|
44
|
|
|
$editCounterRepo = new EditCounterRepository(); |
|
45
|
|
|
$editCounterRepo->setContainer($this->container); |
|
|
|
|
|
|
46
|
|
|
$this->editCounter = new EditCounter($this->project, $this->user); |
|
47
|
|
|
$this->editCounter->setRepository($editCounterRepo); |
|
48
|
|
|
|
|
49
|
|
|
// Don't continue if the user doesn't exist. |
|
50
|
|
|
if (!$this->user->existsOnProject($this->project)) { |
|
51
|
|
|
$this->container->getSession()->getFlashBag()->set('notice', 'user-not-found'); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @Route("/ec", name="ec") |
|
57
|
|
|
* @Route("/ec", name="EditCounter") |
|
58
|
|
|
* @Route("/ec/", name="EditCounterSlash") |
|
59
|
|
|
* @Route("/ec/index.php", name="EditCounterIndexPhp") |
|
60
|
|
|
* @Route("/ec/{project}", name="EditCounterProject") |
|
61
|
|
|
*/ |
|
62
|
|
|
public function indexAction(Request $request, $project = null) |
|
63
|
|
|
{ |
|
64
|
|
|
$queryProject = $request->query->get('project'); |
|
65
|
|
|
$username = $request->query->get('username'); |
|
66
|
|
|
|
|
67
|
|
|
if (($project || $queryProject) && $username) { |
|
68
|
|
|
$routeParams = [ 'project'=>($project ?: $queryProject), 'username' => $username ]; |
|
69
|
|
|
return $this->redirectToRoute("EditCounterResult", $routeParams); |
|
70
|
|
|
} elseif (!$project && $queryProject) { |
|
71
|
|
|
return $this->redirectToRoute("EditCounterProject", [ 'project'=>$queryProject ]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$project = ProjectRepository::getProject($queryProject, $this->container); |
|
|
|
|
|
|
75
|
|
|
if (!$project->exists()) { |
|
76
|
|
|
$project = ProjectRepository::getDefaultProject($this->container); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// Otherwise fall through. |
|
80
|
|
|
return $this->render('editCounter/index.html.twig', [ |
|
81
|
|
|
"xtPageTitle" => "tool-ec", |
|
82
|
|
|
"xtSubtitle" => "tool-ec-desc", |
|
83
|
|
|
'xtPage' => "ec", |
|
84
|
|
|
'project' => $project, |
|
85
|
|
|
]); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @Route("/ec/{project}/{username}", name="EditCounterResult") |
|
90
|
|
|
*/ |
|
91
|
|
|
public function resultAction(Request $request, $project, $username) |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$this->setUpEditCounter($project, $username); |
|
94
|
|
|
|
|
95
|
|
|
//$automatedEditsSummary = $automatedEditsHelper->getEditsSummary($user->getId()); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
// Give it all to the template. |
|
98
|
|
|
return $this->render('editCounter/result.html.twig', [ |
|
99
|
|
|
'xtTitle' => $username, |
|
100
|
|
|
'xtPage' => 'ec', |
|
101
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'), |
|
102
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
|
103
|
|
|
'user' => $this->user, |
|
104
|
|
|
'project' => $this->project, |
|
105
|
|
|
'ec' => $this->editCounter, |
|
106
|
|
|
|
|
107
|
|
|
// Automated edits. |
|
108
|
|
|
//'auto_edits' => $automatedEditsSummary, |
|
|
|
|
|
|
109
|
|
|
]); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @Route("/ec-generalstats/{project}/{username}", name="EditCounterGeneralStats") |
|
114
|
|
|
*/ |
|
115
|
|
View Code Duplication |
public function generalStatsAction($project, $username) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$this->setUpEditCounter($project, $username); |
|
118
|
|
|
|
|
119
|
|
|
// $revisionCounts = $this->editCounterHelper->getRevisionCounts($user->getId($project)); |
|
|
|
|
|
|
120
|
|
|
// $pageCounts = $this->editCounterHelper->getPageCounts($username, $revisionCounts['total']); |
|
121
|
|
|
// $logCounts = $this->editCounterHelper->getLogCounts($user->getId($project)); |
|
122
|
|
|
// $automatedEditsSummary = $automatedEditsHelper->getEditsSummary($user->getId($project)); |
|
123
|
|
|
// $topProjectsEditCounts = $this->editCounterHelper->getTopProjectsEditCounts($project->getUrl(), |
|
124
|
|
|
// $user->getUsername()); |
|
125
|
|
|
|
|
126
|
|
|
// Render view. |
|
127
|
|
|
$isSubRequest = $this->get('request_stack')->getParentRequest() !== null; |
|
128
|
|
|
return $this->render('editCounter/general_stats.html.twig', [ |
|
129
|
|
|
'xtPage' => 'ec', |
|
130
|
|
|
'is_sub_request' => $isSubRequest, |
|
131
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
|
132
|
|
|
'user' => $this->user, |
|
133
|
|
|
'project' => $this->project, |
|
134
|
|
|
'ec' => $this->editCounter, |
|
135
|
|
|
|
|
136
|
|
|
// Revision counts. |
|
|
|
|
|
|
137
|
|
|
// 'deleted_edits' => $revisionCounts['deleted'], |
|
138
|
|
|
// 'total_edits' => $revisionCounts['total'], |
|
139
|
|
|
// 'live_edits' => $revisionCounts['live'], |
|
140
|
|
|
// 'first_rev' => $revisionCounts['first'], |
|
141
|
|
|
// 'latest_rev' => $revisionCounts['last'], |
|
142
|
|
|
// 'days' => $revisionCounts['days'], |
|
143
|
|
|
// 'avg_per_day' => $revisionCounts['avg_per_day'], |
|
144
|
|
|
// 'rev_24h' => $revisionCounts['24h'], |
|
145
|
|
|
// 'rev_7d' => $revisionCounts['7d'], |
|
146
|
|
|
// 'rev_30d' => $revisionCounts['30d'], |
|
147
|
|
|
// 'rev_365d' => $revisionCounts['365d'], |
|
148
|
|
|
// 'rev_small' => $revisionCounts['small'], |
|
149
|
|
|
// 'rev_large' => $revisionCounts['large'], |
|
150
|
|
|
// 'with_comments' => $revisionCounts['with_comments'], |
|
151
|
|
|
// 'without_comments' => $revisionCounts['live'] - $revisionCounts['with_comments'], |
|
152
|
|
|
// 'minor_edits' => $revisionCounts['minor_edits'], |
|
153
|
|
|
// 'nonminor_edits' => $revisionCounts['live'] - $revisionCounts['minor_edits'], |
|
154
|
|
|
// 'auto_edits_total' => array_sum($automatedEditsSummary), |
|
155
|
|
|
// |
|
156
|
|
|
// // Page counts. |
|
157
|
|
|
// 'uniquePages' => $pageCounts['unique'], |
|
158
|
|
|
// 'pagesCreated' => $pageCounts['created'], |
|
159
|
|
|
// 'pagesMoved' => $pageCounts['moved'], |
|
160
|
|
|
// 'editsPerPage' => $pageCounts['edits_per_page'], |
|
161
|
|
|
// |
|
162
|
|
|
// // Log counts (keys are 'log name'-'action'). |
|
163
|
|
|
// 'pagesThanked' => $logCounts['thanks-thank'], |
|
164
|
|
|
// 'pagesApproved' => $logCounts['review-approve'], // Merged -a, -i, and -ia approvals. |
|
165
|
|
|
// 'pagesPatrolled' => $logCounts['patrol-patrol'], |
|
166
|
|
|
// 'usersBlocked' => $logCounts['block-block'], |
|
167
|
|
|
// 'usersUnblocked' => $logCounts['block-unblock'], |
|
168
|
|
|
// 'pagesProtected' => $logCounts['protect-protect'], |
|
169
|
|
|
// 'pagesUnprotected' => $logCounts['protect-unprotect'], |
|
170
|
|
|
// 'pagesDeleted' => $logCounts['delete-delete'], |
|
171
|
|
|
// 'pagesDeletedRevision' => $logCounts['delete-revision'], |
|
172
|
|
|
// 'pagesRestored' => $logCounts['delete-restore'], |
|
173
|
|
|
// 'pagesImported' => $logCounts['import-import'], |
|
174
|
|
|
// 'files_uploaded' => $logCounts['upload-upload'], |
|
175
|
|
|
// 'files_modified' => $logCounts['upload-overwrite'], |
|
176
|
|
|
// 'files_uploaded_commons' => $logCounts['files_uploaded_commons'], |
|
177
|
|
|
// |
|
178
|
|
|
// // Other projects. |
|
179
|
|
|
// 'top_projects_edit_counts' => $topProjectsEditCounts, |
|
180
|
|
|
]); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @Route("/ec-namespacetotals/{project}/{username}", name="EditCounterNamespaceTotals") |
|
185
|
|
|
*/ |
|
186
|
|
View Code Duplication |
public function namespaceTotalsAction($project, $username) |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
$this->setUpEditCounter($project, $username); |
|
189
|
|
|
$isSubRequest = $this->get('request_stack')->getParentRequest() !== null; |
|
190
|
|
|
return $this->render('editCounter/namespace_totals.html.twig', [ |
|
191
|
|
|
'xtTitle' => 'namespacetotals', |
|
192
|
|
|
'xtPage' => 'ec', |
|
193
|
|
|
'is_sub_request' => $isSubRequest, |
|
194
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
|
195
|
|
|
'user' => $this->user, |
|
196
|
|
|
'project' => $this->project, |
|
197
|
|
|
'ec' => $this->editCounter, |
|
198
|
|
|
]); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @Route("/ec-timecard/{project}/{username}", name="EditCounterTimeCard") |
|
203
|
|
|
*/ |
|
204
|
|
View Code Duplication |
public function timecardAction($project, $username) |
|
|
|
|
|
|
205
|
|
|
{ |
|
206
|
|
|
$this->setUpEditCounter($project); |
|
207
|
|
|
$this->labsHelper->databasePrepare($project); |
|
|
|
|
|
|
208
|
|
|
$username = ucfirst($username); |
|
209
|
|
|
$isSubRequest = $this->get('request_stack')->getParentRequest() !== null; |
|
210
|
|
|
$datasets = $this->editCounterHelper->getTimeCard($username); |
|
|
|
|
|
|
211
|
|
|
return $this->render('editCounter/timecard.html.twig', [ |
|
212
|
|
|
'xtTitle' => 'tool-ec', |
|
213
|
|
|
'xtPage' => 'ec', |
|
214
|
|
|
'is_sub_request' => $isSubRequest, |
|
215
|
|
|
'datasets' => $datasets, |
|
216
|
|
|
]); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @Route("/ec-yearcounts/{project}/{username}", name="EditCounterYearCounts") |
|
221
|
|
|
*/ |
|
222
|
|
View Code Duplication |
public function yearcountsAction($project, $username) |
|
|
|
|
|
|
223
|
|
|
{ |
|
224
|
|
|
$this->setUpEditCounter($project); |
|
225
|
|
|
$this->labsHelper->databasePrepare($project); |
|
226
|
|
|
$username = ucfirst($username); |
|
227
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
|
228
|
|
|
$yearcounts = $this->editCounterHelper->getYearCounts($username); |
|
|
|
|
|
|
229
|
|
|
return $this->render('editCounter/yearcounts.html.twig', [ |
|
230
|
|
|
'xtTitle' => 'tool_ec', |
|
231
|
|
|
'xtPage' => 'ec', |
|
232
|
|
|
'is_sub_request' => $isSubRequest, |
|
233
|
|
|
'namespaces' => $this->apiHelper->namespaces($project), |
|
|
|
|
|
|
234
|
|
|
'yearcounts' => $yearcounts, |
|
235
|
|
|
]); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @Route("/ec-monthcounts/{project}/{username}", name="EditCounterMonthCounts") |
|
240
|
|
|
*/ |
|
241
|
|
View Code Duplication |
public function monthcountsAction($project, $username) |
|
|
|
|
|
|
242
|
|
|
{ |
|
243
|
|
|
$this->setUpEditCounter($project); |
|
244
|
|
|
$this->labsHelper->databasePrepare($project); |
|
245
|
|
|
$username = ucfirst($username); |
|
246
|
|
|
$monthlyTotalsByNamespace = $this->editCounterHelper->getMonthCounts($username); |
|
|
|
|
|
|
247
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
|
248
|
|
|
return $this->render('editCounter/monthcounts.html.twig', [ |
|
249
|
|
|
'xtTitle' => 'tool_ec', |
|
250
|
|
|
'xtPage' => 'ec', |
|
251
|
|
|
'is_sub_request' => $isSubRequest, |
|
252
|
|
|
'month_counts' => $monthlyTotalsByNamespace, |
|
253
|
|
|
'namespaces' => $this->apiHelper->namespaces($project), |
|
254
|
|
|
]); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* @Route("/ec-latestglobal/{project}/{username}", name="EditCounterLatestGlobal") |
|
259
|
|
|
*/ |
|
260
|
|
|
public function latestglobalAction($project, $username) |
|
261
|
|
|
{ |
|
262
|
|
|
$this->setUpEditCounter($project); |
|
263
|
|
|
$info = $this->labsHelper->databasePrepare($project); |
|
264
|
|
|
$username = ucfirst($username); |
|
265
|
|
|
|
|
266
|
|
|
$topProjectsEditCounts = $this->editCounterHelper->getTopProjectsEditCounts( |
|
|
|
|
|
|
267
|
|
|
$info['url'], |
|
268
|
|
|
$username |
|
269
|
|
|
); |
|
270
|
|
|
$recentGlobalContribs = $this->editCounterHelper->getRecentGlobalContribs( |
|
|
|
|
|
|
271
|
|
|
$username, |
|
272
|
|
|
array_keys($topProjectsEditCounts) |
|
273
|
|
|
); |
|
274
|
|
|
|
|
275
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
|
276
|
|
|
return $this->render('editCounter/latest_global.html.twig', [ |
|
277
|
|
|
'xtTitle' => 'tool_ec', |
|
278
|
|
|
'xtPage' => 'ec', |
|
279
|
|
|
'is_sub_request' => $isSubRequest, |
|
280
|
|
|
'latest_global_contribs' => $recentGlobalContribs, |
|
281
|
|
|
'username' => $username, |
|
282
|
|
|
'project' => $project, |
|
283
|
|
|
'namespaces' => $this->apiHelper->namespaces($project), |
|
284
|
|
|
]); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.