@@ -6,13 +6,9 @@ |
||
6 | 6 | use AppBundle\Helper\AutomatedEditsHelper; |
7 | 7 | use AppBundle\Helper\EditCounterHelper; |
8 | 8 | use AppBundle\Helper\LabsHelper; |
9 | -use Mediawiki\Api\ApiUser; |
|
10 | 9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
11 | 10 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
12 | -use Symfony\Component\DependencyInjection\ContainerInterface; |
|
13 | 11 | use Symfony\Component\HttpFoundation\Request; |
14 | -use Symfony\Component\HttpFoundation\RequestStack; |
|
15 | -use Symfony\Component\VarDumper\VarDumper; |
|
16 | 12 | |
17 | 13 | class EditCounterController extends Controller |
18 | 14 | { |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | $username = $request->query->get('username'); |
64 | 64 | |
65 | 65 | if (($project || $queryProject) && $username) { |
66 | - $routeParams = [ 'project'=>($project ?: $queryProject), 'username' => $username ]; |
|
66 | + $routeParams = ['project'=>($project ?: $queryProject), 'username' => $username]; |
|
67 | 67 | return $this->redirectToRoute("EditCounterResult", $routeParams); |
68 | 68 | } elseif (!$project && $queryProject) { |
69 | - return $this->redirectToRoute("EditCounterProject", [ 'project'=>$queryProject ]); |
|
69 | + return $this->redirectToRoute("EditCounterProject", ['project'=>$queryProject]); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $this->init($project); |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | 'rev_small' => $revisionCounts['small'], |
172 | 172 | 'rev_large' => $revisionCounts['large'], |
173 | 173 | 'with_comments' => $revisionCounts['with_comments'], |
174 | - 'without_comments' => $revisionCounts['live'] - $revisionCounts['with_comments'], |
|
174 | + 'without_comments' => $revisionCounts['live']-$revisionCounts['with_comments'], |
|
175 | 175 | 'minor_edits' => $revisionCounts['minor_edits'], |
176 | - 'nonminor_edits' => $revisionCounts['live'] - $revisionCounts['minor_edits'], |
|
176 | + 'nonminor_edits' => $revisionCounts['live']-$revisionCounts['minor_edits'], |
|
177 | 177 | 'auto_edits_total' => array_sum($automatedEditsSummary), |
178 | 178 | |
179 | 179 | // Page counts. |
@@ -3,11 +3,7 @@ |
||
3 | 3 | namespace AppBundle\Helper; |
4 | 4 | |
5 | 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 | 6 | use Symfony\Component\DependencyInjection\ContainerInterface; |
10 | -use Symfony\Component\VarDumper\VarDumper; |
|
11 | 7 | |
12 | 8 | class AutomatedEditsHelper extends HelperBase |
13 | 9 | { |
@@ -2,13 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace AppBundle\Helper; |
4 | 4 | |
5 | -use AppBundle\Twig\AppExtension; |
|
6 | -use DateInterval; |
|
7 | 5 | use Doctrine\DBAL\Connection; |
8 | 6 | use Exception; |
9 | -use Mediawiki\Api\SimpleRequest; |
|
10 | 7 | use Symfony\Component\DependencyInjection\Container; |
11 | -use Symfony\Component\VarDumper\VarDumper; |
|
12 | 8 | |
13 | 9 | class EditCounterHelper extends HelperBase |
14 | 10 | { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function getUserId($usernameOrIp) |
38 | 38 | { |
39 | - $cacheKey = 'userid.' . $usernameOrIp; |
|
39 | + $cacheKey = 'userid.'.$usernameOrIp; |
|
40 | 40 | if ($this->cacheHas($cacheKey)) { |
41 | 41 | return $this->cacheGet($cacheKey); |
42 | 42 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** @var ApiHelper */ |
64 | 64 | $api = $this->container->get('app.api_helper'); |
65 | 65 | foreach ($this->labsHelper->allProjects() as $project) { |
66 | - $cacheKey = 'topprojects.' . $project['dbName'] . '.' . $username; |
|
66 | + $cacheKey = 'topprojects.'.$project['dbName'].'.'.$username; |
|
67 | 67 | if ($this->cacheHas($cacheKey)) { |
68 | 68 | $total = $this->cacheGet($cacheKey); |
69 | 69 | } else { |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | } |
84 | 84 | $topEditCounts[$project['dbName']] = array_merge($project, ['total' => $total]); |
85 | 85 | } |
86 | - uasort($topEditCounts, function ($a, $b) { |
|
87 | - return $b['total'] - $a['total']; |
|
86 | + uasort($topEditCounts, function($a, $b) { |
|
87 | + return $b['total']-$a['total']; |
|
88 | 88 | }); |
89 | 89 | return array_slice($topEditCounts, 0, $numProjects); |
90 | 90 | } |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | // Count the number of days, accounting for when there's zero or one edit. |
146 | 146 | $revisionCounts['days'] = 0; |
147 | 147 | if ($revisionCounts['first'] && $revisionCounts['last']) { |
148 | - $editingTimeInSeconds = ceil($revisionCounts['last'] - $revisionCounts['first']); |
|
149 | - $revisionCounts['days'] = $editingTimeInSeconds ? $editingTimeInSeconds/(60*60*24) : 1; |
|
148 | + $editingTimeInSeconds = ceil($revisionCounts['last']-$revisionCounts['first']); |
|
149 | + $revisionCounts['days'] = $editingTimeInSeconds ? $editingTimeInSeconds / (60 * 60 * 24) : 1; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // Format the first and last dates. |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | : 0; |
159 | 159 | |
160 | 160 | // Sum deleted and live to make the total. |
161 | - $revisionCounts['total'] = $revisionCounts['deleted'] + $revisionCounts['live']; |
|
161 | + $revisionCounts['total'] = $revisionCounts['deleted']+$revisionCounts['live']; |
|
162 | 162 | |
163 | 163 | // Calculate the average number of live edits per day. |
164 | 164 | $revisionCounts['avg_per_day'] = 0; |
@@ -205,16 +205,16 @@ discard block |
||
205 | 205 | $results = $resultQuery->fetchAll(); |
206 | 206 | |
207 | 207 | $pageCounts = array_combine( |
208 | - array_map(function ($e) { |
|
208 | + array_map(function($e) { |
|
209 | 209 | return $e['source']; |
210 | 210 | }, $results), |
211 | - array_map(function ($e) { |
|
211 | + array_map(function($e) { |
|
212 | 212 | return $e['value']; |
213 | 213 | }, $results) |
214 | 214 | ); |
215 | 215 | |
216 | 216 | // Total created. |
217 | - $pageCounts['created'] = $pageCounts['created-live'] + $pageCounts['created-deleted']; |
|
217 | + $pageCounts['created'] = $pageCounts['created-live']+$pageCounts['created-deleted']; |
|
218 | 218 | |
219 | 219 | // Calculate the average number of edits per page. |
220 | 220 | $pageCounts['edits_per_page'] = 0; |
@@ -243,17 +243,17 @@ discard block |
||
243 | 243 | $resultQuery->execute(); |
244 | 244 | $results = $resultQuery->fetchAll(); |
245 | 245 | $logCounts = array_combine( |
246 | - array_map(function ($e) { |
|
246 | + array_map(function($e) { |
|
247 | 247 | return $e['source']; |
248 | 248 | }, $results), |
249 | - array_map(function ($e) { |
|
249 | + array_map(function($e) { |
|
250 | 250 | return $e['value']; |
251 | 251 | }, $results) |
252 | 252 | ); |
253 | 253 | |
254 | 254 | // Make sure there is some value for each of the wanted counts. |
255 | 255 | $requiredCounts = [ |
256 | - 'thanks-thank', 'review-approve', 'patrol-patrol','block-block', 'block-unblock', |
|
256 | + 'thanks-thank', 'review-approve', 'patrol-patrol', 'block-block', 'block-unblock', |
|
257 | 257 | 'protect-protect', 'protect-unprotect', 'delete-delete', 'delete-revision', |
258 | 258 | 'delete-restore', 'import-import', 'upload-upload', 'upload-overwrite', |
259 | 259 | ]; |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | // Merge approvals together. |
267 | - $logCounts['review-approve'] = $logCounts['review-approve'] + |
|
268 | - (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) + |
|
269 | - (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) + |
|
267 | + $logCounts['review-approve'] = $logCounts['review-approve']+ |
|
268 | + (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+ |
|
269 | + (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+ |
|
270 | 270 | (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0); |
271 | 271 | |
272 | 272 | // Add Commons upload count, if applicable. |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | { |
293 | 293 | $userId = $this->getUserId($username); |
294 | 294 | $sql = "SELECT page_namespace, count(rev_id) AS total |
295 | - FROM ".$this->labsHelper->getTable('revision') ." r |
|
295 | + FROM ".$this->labsHelper->getTable('revision')." r |
|
296 | 296 | JOIN ".$this->labsHelper->getTable('page')." p on r.rev_page = p.page_id |
297 | 297 | WHERE r.rev_user = :id GROUP BY page_namespace"; |
298 | 298 | $resultQuery = $this->replicas->prepare($sql); |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | $resultQuery->execute(); |
301 | 301 | $results = $resultQuery->fetchAll(); |
302 | 302 | $namespaceTotals = array_combine( |
303 | - array_map(function ($e) { |
|
303 | + array_map(function($e) { |
|
304 | 304 | return $e['page_namespace']; |
305 | 305 | }, $results), |
306 | - array_map(function ($e) { |
|
306 | + array_map(function($e) { |
|
307 | 307 | return $e['total']; |
308 | 308 | }, $results) |
309 | 309 | ); |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " |
330 | 330 | . " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " |
331 | 331 | . " page_title, page_namespace " |
332 | - . " FROM " . $this->labsHelper->getTable('revision', $project['dbName']) |
|
333 | - . " JOIN " . $this->labsHelper->getTable('page', $project['dbName']) |
|
332 | + . " FROM ".$this->labsHelper->getTable('revision', $project['dbName']) |
|
333 | + . " JOIN ".$this->labsHelper->getTable('page', $project['dbName']) |
|
334 | 334 | . " ON (rev_page = page_id)" |
335 | 335 | . " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" |
336 | 336 | . " ORDER BY rev_timestamp DESC" |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | continue; |
346 | 346 | } |
347 | 347 | $revsWithProject = array_map( |
348 | - function (&$item) use ($project) { |
|
348 | + function(&$item) use ($project) { |
|
349 | 349 | $item['project_name'] = $project['name']; |
350 | 350 | $item['project_url'] = $project['url']; |
351 | 351 | $item['project_db_name'] = $project['dbName']; |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | ); |
357 | 357 | $allRevisions = array_merge($allRevisions, $revsWithProject); |
358 | 358 | } |
359 | - usort($allRevisions, function ($a, $b) { |
|
360 | - return $b['rev_timestamp'] - $a['rev_timestamp']; |
|
359 | + usort($allRevisions, function($a, $b) { |
|
360 | + return $b['rev_timestamp']-$a['rev_timestamp']; |
|
361 | 361 | }); |
362 | 362 | return array_slice($allRevisions, 0, $contribCount); |
363 | 363 | } |
@@ -379,8 +379,8 @@ discard block |
||
379 | 379 | . " MONTH(rev_timestamp) AS `month`," |
380 | 380 | . " page_namespace," |
381 | 381 | . " COUNT(rev_id) AS `count` " |
382 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
383 | - . " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" |
|
382 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
383 | + . " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)" |
|
384 | 384 | . " WHERE rev_user_text = :username" |
385 | 385 | . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " |
386 | 386 | . " ORDER BY rev_timestamp DESC"; |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | . " SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," |
437 | 437 | . " page_namespace," |
438 | 438 | . " COUNT(rev_id) AS `count` " |
439 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
440 | - . " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
441 | - " WHERE rev_user_text = :username" . |
|
442 | - " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " . |
|
439 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
440 | + . " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
441 | + " WHERE rev_user_text = :username". |
|
442 | + " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ". |
|
443 | 443 | " ORDER BY rev_timestamp DESC "; |
444 | 444 | $resultQuery = $this->replicas->prepare($sql); |
445 | 445 | $resultQuery->bindParam(":username", $username); |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | . " DAYOFWEEK(rev_timestamp) AS `y`, " |
481 | 481 | . " $xCalc AS `x`, " |
482 | 482 | . " COUNT(rev_id) AS `r` " |
483 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
483 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
484 | 484 | . " WHERE rev_user_text = :username" |
485 | 485 | . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " |
486 | 486 | . " "; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | // Create the query we're going to run against the meta database |
78 | 78 | $wikiQuery = $this->client->createQueryBuilder(); |
79 | 79 | $wikiQuery |
80 | - ->select([ 'dbName', 'name', 'url', 'lang' ]) |
|
80 | + ->select(['dbName', 'name', 'url', 'lang']) |
|
81 | 81 | ->from('wiki') |
82 | 82 | ->where($wikiQuery->expr()->eq('dbname', ':project')) |
83 | 83 | // The meta database will have the project's URL stored as https://en.wikipedia.org |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $this->dbName = $dbName; |
114 | 114 | $this->url = $url; |
115 | 115 | |
116 | - $dbInfo = [ 'dbName' => $dbName, 'wikiName' => $wikiName, 'url' => $url, 'lang' => $lang ]; |
|
116 | + $dbInfo = ['dbName' => $dbName, 'wikiName' => $wikiName, 'url' => $url, 'lang' => $lang]; |
|
117 | 117 | $this->dbInfo[$project] = $dbInfo; |
118 | 118 | return $dbInfo; |
119 | 119 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | public function allProjects() |
125 | 125 | { |
126 | 126 | $wikiQuery = $this->client->createQueryBuilder(); |
127 | - $wikiQuery->select([ 'dbName', 'name', 'url' ])->from('wiki'); |
|
127 | + $wikiQuery->select(['dbName', 'name', 'url'])->from('wiki'); |
|
128 | 128 | $stmt = $wikiQuery->execute(); |
129 | 129 | $out = $stmt->fetchAll(); |
130 | 130 | return $out; |