@@ -10,7 +10,6 @@ |
||
10 | 10 | use Xtools\Page; |
11 | 11 | use Xtools\PagesRepository; |
12 | 12 | use Xtools\Project; |
13 | -use Xtools\ProjectRepository; |
|
14 | 13 | use Xtools\User; |
15 | 14 | |
16 | 15 | class TopEditsController extends ControllerBase |
@@ -2,12 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace AppBundle\Helper; |
4 | 4 | |
5 | -use Doctrine\DBAL\Connection; |
|
6 | -use Psr\Cache\CacheItemPoolInterface; |
|
7 | -use Symfony\Component\Config\Definition\Exception\Exception; |
|
8 | -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
9 | 5 | use Symfony\Component\DependencyInjection\ContainerInterface; |
10 | -use Symfony\Component\VarDumper\VarDumper; |
|
11 | 6 | |
12 | 7 | class AutomatedEditsHelper extends HelperBase |
13 | 8 | { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function getRevisionCounts(Project $project, User $user) |
42 | 42 | { |
43 | 43 | // Set up cache. |
44 | - $cacheKey = 'revisioncounts.' . $user->getId($project); |
|
44 | + $cacheKey = 'revisioncounts.'.$user->getId($project); |
|
45 | 45 | if ($this->cache->hasItem($cacheKey)) { |
46 | 46 | return $this->cache->getItem($cacheKey)->get(); |
47 | 47 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | public function getTopProjectsEditCounts($projectUrl, $username, $numProjects = 10) |
133 | 133 | { |
134 | 134 | $this->debug("Getting top project edit counts for $username"); |
135 | - $cacheKey = 'topprojectseditcounts.' . $username; |
|
135 | + $cacheKey = 'topprojectseditcounts.'.$username; |
|
136 | 136 | if ($this->cacheHas($cacheKey)) { |
137 | 137 | return $this->cacheGet($cacheKey); |
138 | 138 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | if (false === $topEditCounts) { |
145 | 145 | // If no CentralAuth, fall back to querying each database in turn. |
146 | 146 | foreach ($this->labsHelper->getProjectsInfo() as $project) { |
147 | - $this->container->get('logger')->debug('Getting edit count for ' . $project['url']); |
|
147 | + $this->container->get('logger')->debug('Getting edit count for '.$project['url']); |
|
148 | 148 | $revisionTableName = $this->labsHelper->getTable('revision', $project['dbName']); |
149 | 149 | $sql = "SELECT COUNT(rev_id) FROM $revisionTableName WHERE rev_user_text=:username"; |
150 | 150 | $stmt = $this->replicas->prepare($sql); |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | $topEditCounts[$project['dbName']] = array_merge($project, ['total' => $total]); |
155 | 155 | } |
156 | 156 | } |
157 | - uasort($topEditCounts, function ($a, $b) { |
|
158 | - return $b['total'] - $a['total']; |
|
157 | + uasort($topEditCounts, function($a, $b) { |
|
158 | + return $b['total']-$a['total']; |
|
159 | 159 | }); |
160 | 160 | $out = array_slice($topEditCounts, 0, $numProjects); |
161 | 161 | |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | $results = $resultQuery->fetchAll(); |
198 | 198 | |
199 | 199 | $pageCounts = array_combine( |
200 | - array_map(function ($e) { |
|
200 | + array_map(function($e) { |
|
201 | 201 | return $e['source']; |
202 | 202 | }, $results), |
203 | - array_map(function ($e) { |
|
203 | + array_map(function($e) { |
|
204 | 204 | return $e['value']; |
205 | 205 | }, $results) |
206 | 206 | ); |
@@ -216,16 +216,16 @@ discard block |
||
216 | 216 | public function getLogCounts($userId) |
217 | 217 | { |
218 | 218 | $sql = "SELECT CONCAT(log_type, '-', log_action) AS source, COUNT(log_id) AS value |
219 | - FROM " . $this->labsHelper->getTable('logging') . " |
|
219 | + FROM " . $this->labsHelper->getTable('logging')." |
|
220 | 220 | WHERE log_user = :userId |
221 | 221 | GROUP BY log_type, log_action"; |
222 | 222 | $resultQuery = $this->replicas->prepare($sql); |
223 | 223 | $resultQuery->bindParam('userId', $userId); |
224 | 224 | $resultQuery->execute(); |
225 | 225 | $results = $resultQuery->fetchAll(); |
226 | - $logCounts = array_combine(array_map(function ($e) { |
|
226 | + $logCounts = array_combine(array_map(function($e) { |
|
227 | 227 | return $e['source']; |
228 | - }, $results), array_map(function ($e) { |
|
228 | + }, $results), array_map(function($e) { |
|
229 | 229 | return $e['value']; |
230 | 230 | }, $results)); |
231 | 231 | |
@@ -253,9 +253,9 @@ discard block |
||
253 | 253 | |
254 | 254 | // Merge approvals together. |
255 | 255 | $logCounts['review-approve'] = |
256 | - $logCounts['review-approve'] + |
|
257 | - (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) + |
|
258 | - (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) + |
|
256 | + $logCounts['review-approve']+ |
|
257 | + (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+ |
|
258 | + (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+ |
|
259 | 259 | (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0); |
260 | 260 | |
261 | 261 | // Add Commons upload count, if applicable. |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | { |
282 | 282 | $userId = $this->getUserId($username); |
283 | 283 | $sql = "SELECT page_namespace, count(rev_id) AS total |
284 | - FROM " . $this->labsHelper->getTable('revision') . " r |
|
285 | - JOIN " . $this->labsHelper->getTable('page') . " p on r.rev_page = p.page_id |
|
284 | + FROM " . $this->labsHelper->getTable('revision')." r |
|
285 | + JOIN " . $this->labsHelper->getTable('page')." p on r.rev_page = p.page_id |
|
286 | 286 | WHERE r.rev_user = :id GROUP BY page_namespace"; |
287 | 287 | $resultQuery = $this->replicas->prepare($sql); |
288 | 288 | $resultQuery->bindParam(":id", $userId); |
289 | 289 | $resultQuery->execute(); |
290 | 290 | $results = $resultQuery->fetchAll(); |
291 | - $namespaceTotals = array_combine(array_map(function ($e) { |
|
291 | + $namespaceTotals = array_combine(array_map(function($e) { |
|
292 | 292 | return $e['page_namespace']; |
293 | - }, $results), array_map(function ($e) { |
|
293 | + }, $results), array_map(function($e) { |
|
294 | 294 | return $e['total']; |
295 | 295 | }, $results)); |
296 | 296 | |
@@ -313,14 +313,14 @@ discard block |
||
313 | 313 | $revisions = $this->cacheGet($cacheKey); |
314 | 314 | } else { |
315 | 315 | $sql = |
316 | - "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " . |
|
317 | - " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " . |
|
318 | - " page_title, page_namespace " . " FROM " . |
|
319 | - $this->labsHelper->getTable('revision', $project['dbName']) . " JOIN " . |
|
320 | - $this->labsHelper->getTable('page', $project['dbName']) . |
|
321 | - " ON (rev_page = page_id)" . |
|
322 | - " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" . |
|
323 | - " ORDER BY rev_timestamp DESC" . " LIMIT 10"; |
|
316 | + "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, ". |
|
317 | + " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, ". |
|
318 | + " page_title, page_namespace "." FROM ". |
|
319 | + $this->labsHelper->getTable('revision', $project['dbName'])." JOIN ". |
|
320 | + $this->labsHelper->getTable('page', $project['dbName']). |
|
321 | + " ON (rev_page = page_id)". |
|
322 | + " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username". |
|
323 | + " ORDER BY rev_timestamp DESC"." LIMIT 10"; |
|
324 | 324 | $resultQuery = $this->replicas->prepare($sql); |
325 | 325 | $resultQuery->bindParam(":username", $username); |
326 | 326 | $resultQuery->execute(); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | if (count($revisions) === 0) { |
331 | 331 | continue; |
332 | 332 | } |
333 | - $revsWithProject = array_map(function (&$item) use ($project) { |
|
333 | + $revsWithProject = array_map(function(&$item) use ($project) { |
|
334 | 334 | $item['project_name'] = $project['wikiName']; |
335 | 335 | $item['project_url'] = $project['url']; |
336 | 336 | $item['project_db_name'] = $project['dbName']; |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | }, $revisions); |
341 | 341 | $allRevisions = array_merge($allRevisions, $revsWithProject); |
342 | 342 | } |
343 | - usort($allRevisions, function ($a, $b) { |
|
344 | - return $b['rev_timestamp'] - $a['rev_timestamp']; |
|
343 | + usort($allRevisions, function($a, $b) { |
|
344 | + return $b['rev_timestamp']-$a['rev_timestamp']; |
|
345 | 345 | }); |
346 | 346 | |
347 | 347 | return array_slice($allRevisions, 0, $topN); |
@@ -360,12 +360,12 @@ discard block |
||
360 | 360 | } |
361 | 361 | |
362 | 362 | $sql = |
363 | - "SELECT " . " YEAR(rev_timestamp) AS `year`," . |
|
364 | - " MONTH(rev_timestamp) AS `month`," . " page_namespace," . |
|
365 | - " COUNT(rev_id) AS `count` " . " FROM " . $this->labsHelper->getTable('revision') . |
|
366 | - " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
367 | - " WHERE rev_user_text = :username" . |
|
368 | - " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " . |
|
363 | + "SELECT "." YEAR(rev_timestamp) AS `year`,". |
|
364 | + " MONTH(rev_timestamp) AS `month`,"." page_namespace,". |
|
365 | + " COUNT(rev_id) AS `count` "." FROM ".$this->labsHelper->getTable('revision'). |
|
366 | + " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
367 | + " WHERE rev_user_text = :username". |
|
368 | + " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace ". |
|
369 | 369 | " ORDER BY rev_timestamp DESC"; |
370 | 370 | $resultQuery = $this->replicas->prepare($sql); |
371 | 371 | $resultQuery->bindParam(":username", $username); |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | if (!isset($out['totals'][$ns])) { |
388 | 388 | $out['totals'][$ns] = []; |
389 | 389 | } |
390 | - $out['totals'][$ns][$total['year'] . $total['month']] = $total['count']; |
|
390 | + $out['totals'][$ns][$total['year'].$total['month']] = $total['count']; |
|
391 | 391 | } |
392 | 392 | // Fill in the blanks (where no edits were made in a given month for a namespace). |
393 | 393 | for ($y = $out['min_year']; $y <= $out['max_year']; $y++) { |
394 | 394 | for ($m = 1; $m <= 12; $m++) { |
395 | 395 | foreach ($out['totals'] as $nsId => &$total) { |
396 | - if (!isset($total[$y . $m])) { |
|
397 | - $total[$y . $m] = 0; |
|
396 | + if (!isset($total[$y.$m])) { |
|
397 | + $total[$y.$m] = 0; |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | } |
@@ -417,12 +417,12 @@ discard block |
||
417 | 417 | } |
418 | 418 | |
419 | 419 | $sql = |
420 | - "SELECT " . " SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," . |
|
421 | - " page_namespace," . " COUNT(rev_id) AS `count` " . " FROM " . |
|
422 | - $this->labsHelper->getTable('revision') . " JOIN " . |
|
423 | - $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
424 | - " WHERE rev_user_text = :username" . |
|
425 | - " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " . |
|
420 | + "SELECT "." SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`,". |
|
421 | + " page_namespace,"." COUNT(rev_id) AS `count` "." FROM ". |
|
422 | + $this->labsHelper->getTable('revision')." JOIN ". |
|
423 | + $this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
424 | + " WHERE rev_user_text = :username". |
|
425 | + " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ". |
|
426 | 426 | " ORDER BY rev_timestamp DESC "; |
427 | 427 | $resultQuery = $this->replicas->prepare($sql); |
428 | 428 | $resultQuery->bindParam(":username", $username); |
@@ -461,9 +461,9 @@ discard block |
||
461 | 461 | $hourInterval = 2; |
462 | 462 | $xCalc = "ROUND(HOUR(rev_timestamp)/$hourInterval)*$hourInterval"; |
463 | 463 | $sql = |
464 | - "SELECT " . " DAYOFWEEK(rev_timestamp) AS `y`, " . " $xCalc AS `x`, " . |
|
465 | - " COUNT(rev_id) AS `r` " . " FROM " . $this->labsHelper->getTable('revision') . |
|
466 | - " WHERE rev_user_text = :username" . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " . |
|
464 | + "SELECT "." DAYOFWEEK(rev_timestamp) AS `y`, "." $xCalc AS `x`, ". |
|
465 | + " COUNT(rev_id) AS `r` "." FROM ".$this->labsHelper->getTable('revision'). |
|
466 | + " WHERE rev_user_text = :username"." GROUP BY DAYOFWEEK(rev_timestamp), $xCalc ". |
|
467 | 467 | " "; |
468 | 468 | $resultQuery = $this->replicas->prepare($sql); |
469 | 469 | $resultQuery->bindParam(":username", $username); |
@@ -66,7 +66,7 @@ |
||
66 | 66 | public function userRightsUrl(Project $project) |
67 | 67 | { |
68 | 68 | return $project->getUrl() . $project->getScriptPath() . "?title=Special:UserRights&user=" . |
69 | - $this->getUsername(); |
|
69 | + $this->getUsername(); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -65,7 +65,7 @@ |
||
65 | 65 | */ |
66 | 66 | public function userRightsUrl(Project $project) |
67 | 67 | { |
68 | - return $project->getUrl() . $project->getScriptPath() . "?title=Special:UserRights&user=" . |
|
68 | + return $project->getUrl().$project->getScriptPath()."?title=Special:UserRights&user=". |
|
69 | 69 | $this->getUsername(); |
70 | 70 | } |
71 | 71 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function getGroups(Project $project, $username) |
33 | 33 | { |
34 | 34 | $api = $this->getMediawikiApi($project); |
35 | - $params = [ "list"=>"users", "ususers"=>$username, "usprop"=>"groups" ]; |
|
35 | + $params = ["list"=>"users", "ususers"=>$username, "usprop"=>"groups"]; |
|
36 | 36 | $query = new SimpleRequest('query', $params); |
37 | 37 | $result = []; |
38 | 38 | $res = $api->getRequest($query); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | // Create the API query. |
59 | 59 | $api = $this->getMediawikiApi($project); |
60 | - $params = [ "meta"=>"globaluserinfo", "guiuser"=>$username, "guiprop"=>"groups" ]; |
|
60 | + $params = ["meta"=>"globaluserinfo", "guiuser"=>$username, "guiprop"=>"groups"]; |
|
61 | 61 | $query = new SimpleRequest('query', $params); |
62 | 62 | |
63 | 63 | // Get the result. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function getRevisionCounts() |
39 | 39 | { |
40 | - if (! is_array($this->revisionCounts)) { |
|
40 | + if (!is_array($this->revisionCounts)) { |
|
41 | 41 | $this->revisionCounts = $this->getRepository() |
42 | 42 | ->getRevisionCounts($this->project, $this->user); |
43 | 43 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | protected function getPageCounts() |
52 | 52 | { |
53 | - if (! is_array($this->pageCounts)) { |
|
53 | + if (!is_array($this->pageCounts)) { |
|
54 | 54 | $this->pageCounts = $this->getRepository() |
55 | 55 | ->getPageCounts($this->project, $this->user); |
56 | 56 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function getRevisionDates() |
65 | 65 | { |
66 | - if (! is_array($this->revisionDates)) { |
|
66 | + if (!is_array($this->revisionDates)) { |
|
67 | 67 | $this->revisionDates = $this->getRepository() |
68 | 68 | ->getRevisionDates($this->project, $this->user); |
69 | 69 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getTotalEditCount() |
90 | 90 | { |
91 | - return $this->getLiveEditCount() + $this->getDeletedEditCount(); |
|
91 | + return $this->getLiveEditCount()+$this->getDeletedEditCount(); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getTotalPagesEdited() |
115 | 115 | { |
116 | - return $this->getTotalLivePagesEdited() + $this->getTotalDeletedPagesEdited(); |
|
116 | + return $this->getTotalLivePagesEdited()+$this->getTotalDeletedPagesEdited(); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function getCreatedPagesTotal() |
134 | 134 | { |
135 | - return $this->getCreatedPagesLive() + $this->getCreatedPagesDeleted(); |
|
135 | + return $this->getCreatedPagesLive()+$this->getCreatedPagesDeleted(); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -53,10 +53,10 @@ |
||
53 | 53 | $username = $request->query->get('username'); |
54 | 54 | |
55 | 55 | if (($project || $queryProject) && $username) { |
56 | - $routeParams = [ 'project'=>($project ?: $queryProject), 'username' => $username ]; |
|
56 | + $routeParams = ['project'=>($project ?: $queryProject), 'username' => $username]; |
|
57 | 57 | return $this->redirectToRoute("EditCounterResult", $routeParams); |
58 | 58 | } elseif (!$project && $queryProject) { |
59 | - return $this->redirectToRoute("EditCounterProject", [ 'project'=>$queryProject ]); |
|
59 | + return $this->redirectToRoute("EditCounterProject", ['project'=>$queryProject]); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $this->init($project); |