Completed
Push — master ( 458768...717411 )
by Sam
03:06
created
src/Xtools/EditCounterRepository.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     public function getRevisionCounts(Project $project, User $user)
17 17
     {
18 18
         // Set up cache.
19
-        $cacheKey = 'revisioncounts.' . $project->getDatabaseName() . '.' . $user->getUsername();
19
+        $cacheKey = 'revisioncounts.'.$project->getDatabaseName().'.'.$user->getUsername();
20 20
         if ($this->cache->hasItem($cacheKey)) {
21 21
             return $this->cache->getItem($cacheKey)->get();
22 22
         }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     public function getRevisionDates(Project $project, User $user)
78 78
     {
79 79
         // Set up cache.
80
-        $cacheKey = 'revisiondates.' . $project->getDatabaseName() . '.' . $user->getUsername();
80
+        $cacheKey = 'revisiondates.'.$project->getDatabaseName().'.'.$user->getUsername();
81 81
         if ($this->cache->hasItem($cacheKey)) {
82 82
             return $this->cache->getItem($cacheKey)->get();
83 83
         }
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
         $results = $resultQuery->fetchAll();
150 150
 
151 151
         $pageCounts = array_combine(
152
-            array_map(function ($e) {
152
+            array_map(function($e) {
153 153
                 return $e['source'];
154 154
             }, $results),
155
-            array_map(function ($e) {
155
+            array_map(function($e) {
156 156
                 return $e['value'];
157 157
             }, $results)
158 158
         );
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
         // Query.
185 185
         $sql = "SELECT CONCAT(log_type, '-', log_action) AS source, COUNT(log_id) AS value
186
-            FROM " . $this->getTableName($project->getDatabaseName(), 'logging') . "
186
+            FROM " . $this->getTableName($project->getDatabaseName(), 'logging')."
187 187
             WHERE log_user = :userId
188 188
             GROUP BY log_type, log_action";
189 189
         $resultQuery = $this->getProjectsConnection()->prepare($sql);
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
         $resultQuery->execute();
193 193
         $results = $resultQuery->fetchAll();
194 194
         $logCounts = array_combine(
195
-            array_map(function ($e) {
195
+            array_map(function($e) {
196 196
                 return $e['source'];
197 197
             }, $results),
198
-            array_map(function ($e) {
198
+            array_map(function($e) {
199 199
                 return $e['value'];
200 200
             }, $results)
201 201
         );
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
     public function getTopProjectsEditCounts($projectUrl, $username, $numProjects = 10)
286 286
     {
287 287
         $this->debug("Getting top project edit counts for $username");
288
-        $cacheKey = 'topprojectseditcounts.' . $username;
288
+        $cacheKey = 'topprojectseditcounts.'.$username;
289 289
         if ($this->cacheHas($cacheKey)) {
290 290
             return $this->cacheGet($cacheKey);
291 291
         }
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
         if (false === $topEditCounts) {
298 298
             // If no CentralAuth, fall back to querying each database in turn.
299 299
             foreach ($this->labsHelper->getProjectsInfo() as $project) {
300
-                $this->container->get('logger')->debug('Getting edit count for ' . $project['url']);
300
+                $this->container->get('logger')->debug('Getting edit count for '.$project['url']);
301 301
                 $revisionTableName = $this->labsHelper->getTable('revision', $project['dbName']);
302 302
                 $sql = "SELECT COUNT(rev_id) FROM $revisionTableName WHERE rev_user_text=:username";
303 303
                 $stmt = $this->replicas->prepare($sql);
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
                 $topEditCounts[$project['dbName']] = array_merge($project, ['total' => $total]);
308 308
             }
309 309
         }
310
-        uasort($topEditCounts, function ($a, $b) {
311
-            return $b['total'] - $a['total'];
310
+        uasort($topEditCounts, function($a, $b) {
311
+            return $b['total']-$a['total'];
312 312
         });
313 313
         $out = array_slice($topEditCounts, 0, $numProjects);
314 314
 
@@ -327,16 +327,16 @@  discard block
 block discarded – undo
327 327
     {
328 328
         $userId = $this->getUserId($username);
329 329
         $sql = "SELECT page_namespace, count(rev_id) AS total
330
-            FROM " . $this->labsHelper->getTable('revision') . " r
331
-                JOIN " . $this->labsHelper->getTable('page') . " p on r.rev_page = p.page_id
330
+            FROM " . $this->labsHelper->getTable('revision')." r
331
+                JOIN " . $this->labsHelper->getTable('page')." p on r.rev_page = p.page_id
332 332
             WHERE r.rev_user = :id GROUP BY page_namespace";
333 333
         $resultQuery = $this->replicas->prepare($sql);
334 334
         $resultQuery->bindParam(":id", $userId);
335 335
         $resultQuery->execute();
336 336
         $results = $resultQuery->fetchAll();
337
-        $namespaceTotals = array_combine(array_map(function ($e) {
337
+        $namespaceTotals = array_combine(array_map(function($e) {
338 338
             return $e['page_namespace'];
339
-        }, $results), array_map(function ($e) {
339
+        }, $results), array_map(function($e) {
340 340
             return $e['total'];
341 341
         }, $results));
342 342
 
@@ -359,14 +359,14 @@  discard block
 block discarded – undo
359 359
                 $revisions = $this->cacheGet($cacheKey);
360 360
             } else {
361 361
                 $sql =
362
-                    "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " .
363
-                    " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " .
364
-                    " page_title, page_namespace " . " FROM " .
365
-                    $this->labsHelper->getTable('revision', $project['dbName']) . "    JOIN " .
366
-                    $this->labsHelper->getTable('page', $project['dbName']) .
367
-                    "    ON (rev_page = page_id)" .
368
-                    " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" .
369
-                    " ORDER BY rev_timestamp DESC" . " LIMIT 10";
362
+                    "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, ".
363
+                    " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, ".
364
+                    " page_title, page_namespace "." FROM ".
365
+                    $this->labsHelper->getTable('revision', $project['dbName'])."    JOIN ".
366
+                    $this->labsHelper->getTable('page', $project['dbName']).
367
+                    "    ON (rev_page = page_id)".
368
+                    " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username".
369
+                    " ORDER BY rev_timestamp DESC"." LIMIT 10";
370 370
                 $resultQuery = $this->replicas->prepare($sql);
371 371
                 $resultQuery->bindParam(":username", $username);
372 372
                 $resultQuery->execute();
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
             if (count($revisions) === 0) {
377 377
                 continue;
378 378
             }
379
-            $revsWithProject = array_map(function (&$item) use ($project) {
379
+            $revsWithProject = array_map(function(&$item) use ($project) {
380 380
                 $item['project_name'] = $project['wikiName'];
381 381
                 $item['project_url'] = $project['url'];
382 382
                 $item['project_db_name'] = $project['dbName'];
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
             }, $revisions);
387 387
             $allRevisions = array_merge($allRevisions, $revsWithProject);
388 388
         }
389
-        usort($allRevisions, function ($a, $b) {
390
-            return $b['rev_timestamp'] - $a['rev_timestamp'];
389
+        usort($allRevisions, function($a, $b) {
390
+            return $b['rev_timestamp']-$a['rev_timestamp'];
391 391
         });
392 392
 
393 393
         return array_slice($allRevisions, 0, $topN);
@@ -406,12 +406,12 @@  discard block
 block discarded – undo
406 406
         }
407 407
 
408 408
         $sql =
409
-            "SELECT " . "     YEAR(rev_timestamp) AS `year`," .
410
-            "     MONTH(rev_timestamp) AS `month`," . "     page_namespace," .
411
-            "     COUNT(rev_id) AS `count` " . " FROM " . $this->labsHelper->getTable('revision') .
412
-            "    JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" .
413
-            " WHERE rev_user_text = :username" .
414
-            " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " .
409
+            "SELECT "."     YEAR(rev_timestamp) AS `year`,".
410
+            "     MONTH(rev_timestamp) AS `month`,"."     page_namespace,".
411
+            "     COUNT(rev_id) AS `count` "." FROM ".$this->labsHelper->getTable('revision').
412
+            "    JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)".
413
+            " WHERE rev_user_text = :username".
414
+            " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace ".
415 415
             " ORDER BY rev_timestamp DESC";
416 416
         $resultQuery = $this->replicas->prepare($sql);
417 417
         $resultQuery->bindParam(":username", $username);
@@ -433,14 +433,14 @@  discard block
 block discarded – undo
433 433
             if (!isset($out['totals'][$ns])) {
434 434
                 $out['totals'][$ns] = [];
435 435
             }
436
-            $out['totals'][$ns][$total['year'] . $total['month']] = $total['count'];
436
+            $out['totals'][$ns][$total['year'].$total['month']] = $total['count'];
437 437
         }
438 438
         // Fill in the blanks (where no edits were made in a given month for a namespace).
439 439
         for ($y = $out['min_year']; $y <= $out['max_year']; $y++) {
440 440
             for ($m = 1; $m <= 12; $m++) {
441 441
                 foreach ($out['totals'] as $nsId => &$total) {
442
-                    if (!isset($total[$y . $m])) {
443
-                        $total[$y . $m] = 0;
442
+                    if (!isset($total[$y.$m])) {
443
+                        $total[$y.$m] = 0;
444 444
                     }
445 445
                 }
446 446
             }
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
         }
464 464
 
465 465
         $sql =
466
-            "SELECT " . "     SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," .
467
-            "     page_namespace," . "     COUNT(rev_id) AS `count` " . " FROM " .
468
-            $this->labsHelper->getTable('revision') . "    JOIN " .
469
-            $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" .
470
-            " WHERE rev_user_text = :username" .
471
-            " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " .
466
+            "SELECT "."     SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`,".
467
+            "     page_namespace,"."     COUNT(rev_id) AS `count` "." FROM ".
468
+            $this->labsHelper->getTable('revision')."    JOIN ".
469
+            $this->labsHelper->getTable('page')." ON (rev_page = page_id)".
470
+            " WHERE rev_user_text = :username".
471
+            " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ".
472 472
             " ORDER BY rev_timestamp DESC ";
473 473
         $resultQuery = $this->replicas->prepare($sql);
474 474
         $resultQuery->bindParam(":username", $username);
@@ -507,9 +507,9 @@  discard block
 block discarded – undo
507 507
         $hourInterval = 2;
508 508
         $xCalc = "ROUND(HOUR(rev_timestamp)/$hourInterval)*$hourInterval";
509 509
         $sql =
510
-            "SELECT " . "     DAYOFWEEK(rev_timestamp) AS `y`, " . "     $xCalc AS `x`, " .
511
-            "     COUNT(rev_id) AS `r` " . " FROM " . $this->labsHelper->getTable('revision') .
512
-            " WHERE rev_user_text = :username" . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " .
510
+            "SELECT "."     DAYOFWEEK(rev_timestamp) AS `y`, "."     $xCalc AS `x`, ".
511
+            "     COUNT(rev_id) AS `r` "." FROM ".$this->labsHelper->getTable('revision').
512
+            " WHERE rev_user_text = :username"." GROUP BY DAYOFWEEK(rev_timestamp), $xCalc ".
513 513
             " ";
514 514
         $resultQuery = $this->replicas->prepare($sql);
515 515
         $resultQuery->bindParam(":username", $username);
Please login to merge, or discard this patch.