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
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
99
|
|
|
return $this->render('editCounter/result.html.twig', [ |
100
|
|
|
'xtTitle' => $username, |
101
|
|
|
'xtPage' => 'ec', |
102
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'), |
103
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
104
|
|
|
'is_sub_request' => $isSubRequest, |
105
|
|
|
'user' => $this->user, |
106
|
|
|
'project' => $this->project, |
107
|
|
|
'ec' => $this->editCounter, |
108
|
|
|
|
109
|
|
|
// Automated edits. |
110
|
|
|
//'auto_edits' => $automatedEditsSummary, |
|
|
|
|
111
|
|
|
]); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Route("/ec-generalstats/{project}/{username}", name="EditCounterGeneralStats") |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
public function generalStatsAction($project, $username) |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
$this->setUpEditCounter($project, $username); |
120
|
|
|
|
121
|
|
|
// $revisionCounts = $this->editCounterHelper->getRevisionCounts($user->getId($project)); |
|
|
|
|
122
|
|
|
// $pageCounts = $this->editCounterHelper->getPageCounts($username, $revisionCounts['total']); |
123
|
|
|
// $logCounts = $this->editCounterHelper->getLogCounts($user->getId($project)); |
124
|
|
|
// $automatedEditsSummary = $automatedEditsHelper->getEditsSummary($user->getId($project)); |
125
|
|
|
// $topProjectsEditCounts = $this->editCounterHelper->getTopProjectsEditCounts($project->getUrl(), |
126
|
|
|
// $user->getUsername()); |
127
|
|
|
|
128
|
|
|
// Render view. |
129
|
|
|
$isSubRequest = $this->get('request_stack')->getParentRequest() !== null; |
130
|
|
|
return $this->render('editCounter/general_stats.html.twig', [ |
131
|
|
|
'xtPage' => 'ec', |
132
|
|
|
'is_sub_request' => $isSubRequest, |
133
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
134
|
|
|
'user' => $this->user, |
135
|
|
|
'project' => $this->project, |
136
|
|
|
'ec' => $this->editCounter, |
137
|
|
|
|
138
|
|
|
// Revision counts. |
|
|
|
|
139
|
|
|
// 'deleted_edits' => $revisionCounts['deleted'], |
140
|
|
|
// 'total_edits' => $revisionCounts['total'], |
141
|
|
|
// 'live_edits' => $revisionCounts['live'], |
142
|
|
|
// 'first_rev' => $revisionCounts['first'], |
143
|
|
|
// 'latest_rev' => $revisionCounts['last'], |
144
|
|
|
// 'days' => $revisionCounts['days'], |
145
|
|
|
// 'avg_per_day' => $revisionCounts['avg_per_day'], |
146
|
|
|
// 'rev_24h' => $revisionCounts['24h'], |
147
|
|
|
// 'rev_7d' => $revisionCounts['7d'], |
148
|
|
|
// 'rev_30d' => $revisionCounts['30d'], |
149
|
|
|
// 'rev_365d' => $revisionCounts['365d'], |
150
|
|
|
// 'rev_small' => $revisionCounts['small'], |
151
|
|
|
// 'rev_large' => $revisionCounts['large'], |
152
|
|
|
// 'with_comments' => $revisionCounts['with_comments'], |
153
|
|
|
// 'without_comments' => $revisionCounts['live'] - $revisionCounts['with_comments'], |
154
|
|
|
// 'minor_edits' => $revisionCounts['minor_edits'], |
155
|
|
|
// 'nonminor_edits' => $revisionCounts['live'] - $revisionCounts['minor_edits'], |
156
|
|
|
// 'auto_edits_total' => array_sum($automatedEditsSummary), |
157
|
|
|
// |
158
|
|
|
// // Page counts. |
159
|
|
|
// 'uniquePages' => $pageCounts['unique'], |
160
|
|
|
// 'pagesCreated' => $pageCounts['created'], |
161
|
|
|
// 'pagesMoved' => $pageCounts['moved'], |
162
|
|
|
// 'editsPerPage' => $pageCounts['edits_per_page'], |
163
|
|
|
// |
164
|
|
|
// // Log counts (keys are 'log name'-'action'). |
165
|
|
|
// 'pagesThanked' => $logCounts['thanks-thank'], |
166
|
|
|
// 'pagesApproved' => $logCounts['review-approve'], // Merged -a, -i, and -ia approvals. |
167
|
|
|
// 'pagesPatrolled' => $logCounts['patrol-patrol'], |
168
|
|
|
// 'usersBlocked' => $logCounts['block-block'], |
169
|
|
|
// 'usersUnblocked' => $logCounts['block-unblock'], |
170
|
|
|
// 'pagesProtected' => $logCounts['protect-protect'], |
171
|
|
|
// 'pagesUnprotected' => $logCounts['protect-unprotect'], |
172
|
|
|
// 'pagesDeleted' => $logCounts['delete-delete'], |
173
|
|
|
// 'pagesDeletedRevision' => $logCounts['delete-revision'], |
174
|
|
|
// 'pagesRestored' => $logCounts['delete-restore'], |
175
|
|
|
// 'pagesImported' => $logCounts['import-import'], |
176
|
|
|
// 'files_uploaded' => $logCounts['upload-upload'], |
177
|
|
|
// 'files_modified' => $logCounts['upload-overwrite'], |
178
|
|
|
// 'files_uploaded_commons' => $logCounts['files_uploaded_commons'], |
179
|
|
|
// |
180
|
|
|
// // Other projects. |
181
|
|
|
// 'top_projects_edit_counts' => $topProjectsEditCounts, |
182
|
|
|
]); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @Route("/ec-namespacetotals/{project}/{username}", name="EditCounterNamespaceTotals") |
187
|
|
|
*/ |
188
|
|
View Code Duplication |
public function namespaceTotalsAction($project, $username) |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
$this->setUpEditCounter($project, $username); |
191
|
|
|
$isSubRequest = $this->get('request_stack')->getParentRequest() !== null; |
192
|
|
|
return $this->render('editCounter/namespace_totals.html.twig', [ |
193
|
|
|
'xtTitle' => 'namespacetotals', |
194
|
|
|
'xtPage' => 'ec', |
195
|
|
|
'is_sub_request' => $isSubRequest, |
196
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
197
|
|
|
'user' => $this->user, |
198
|
|
|
'project' => $this->project, |
199
|
|
|
'ec' => $this->editCounter, |
200
|
|
|
]); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @Route("/ec-timecard/{project}/{username}", name="EditCounterTimeCard") |
205
|
|
|
*/ |
206
|
|
View Code Duplication |
public function timecardAction($project, $username) |
|
|
|
|
207
|
|
|
{ |
208
|
|
|
$this->setUpEditCounter($project, $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
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
217
|
|
|
'user' => $this->user, |
218
|
|
|
'project' => $this->project, |
219
|
|
|
'ec' => $this->editCounter, |
220
|
|
|
]); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @Route("/ec-yearcounts/{project}/{username}", name="EditCounterYearCounts") |
225
|
|
|
*/ |
226
|
|
View Code Duplication |
public function yearcountsAction($project, $username) |
|
|
|
|
227
|
|
|
{ |
228
|
|
|
$this->setUpEditCounter($project, $username); |
229
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
230
|
|
|
//$yearcounts = $this->editCounterHelper->getYearCounts($username); |
|
|
|
|
231
|
|
|
return $this->render('editCounter/yearcounts.html.twig', [ |
232
|
|
|
'xtTitle' => 'tool-ec', |
233
|
|
|
'xtPage' => 'ec', |
234
|
|
|
'is_sub_request' => $isSubRequest, |
235
|
|
|
//'namespaces' => $this->apiHelper->namespaces($project), |
|
|
|
|
236
|
|
|
//'yearcounts' => $yearcounts, |
|
|
|
|
237
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
238
|
|
|
'user' => $this->user, |
239
|
|
|
'project' => $this->project, |
240
|
|
|
'ec' => $this->editCounter, |
241
|
|
|
]); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @Route("/ec-monthcounts/{project}/{username}", name="EditCounterMonthCounts") |
246
|
|
|
*/ |
247
|
|
View Code Duplication |
public function monthcountsAction($project, $username) |
|
|
|
|
248
|
|
|
{ |
249
|
|
|
$this->setUpEditCounter($project, $username); |
250
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
251
|
|
|
return $this->render('editCounter/monthcounts.html.twig', [ |
252
|
|
|
'xtTitle' => 'tool-ec', |
253
|
|
|
'xtPage' => 'ec', |
254
|
|
|
'is_sub_request' => $isSubRequest, |
255
|
|
|
'is_labs' => $this->project->getRepository()->isLabs(), |
256
|
|
|
'user' => $this->user, |
257
|
|
|
'project' => $this->project, |
258
|
|
|
'ec' => $this->editCounter, |
259
|
|
|
]); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @Route("/ec-latestglobal/{project}/{username}", name="EditCounterLatestGlobal") |
264
|
|
|
*/ |
265
|
|
View Code Duplication |
public function latestglobalAction($project, $username) |
|
|
|
|
266
|
|
|
{ |
267
|
|
|
$this->setUpEditCounter($project, $username); |
268
|
|
|
$isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null; |
269
|
|
|
return $this->render('editCounter/latest_global.html.twig', [ |
270
|
|
|
'xtTitle' => 'tool_ec', |
271
|
|
|
'xtPage' => 'ec', |
272
|
|
|
'is_sub_request' => $isSubRequest, |
273
|
|
|
'user' => $this->user, |
274
|
|
|
'project' => $this->project, |
275
|
|
|
'ec' => $this->editCounter, |
276
|
|
|
]); |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|
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.