@@ -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 | { |
@@ -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. |
@@ -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 $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 | } |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | $revisionCounts = array_combine( |
157 | - array_map(function ($e) { |
|
157 | + array_map(function($e) { |
|
158 | 158 | return $e['source']; |
159 | 159 | }, $results), |
160 | - array_map(function ($e) { |
|
160 | + array_map(function($e) { |
|
161 | 161 | return $e['value']; |
162 | 162 | }, $results) |
163 | 163 | ); |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | // Count the number of days, accounting for when there's zero or one edit. |
166 | 166 | $revisionCounts['days'] = 0; |
167 | 167 | if (isset($revisionCounts['first']) && isset($revisionCounts['last'])) { |
168 | - $editingTimeInSeconds = ceil($revisionCounts['last'] - $revisionCounts['first']); |
|
169 | - $revisionCounts['days'] = $editingTimeInSeconds ? $editingTimeInSeconds/(60*60*24) : 1; |
|
168 | + $editingTimeInSeconds = ceil($revisionCounts['last']-$revisionCounts['first']); |
|
169 | + $revisionCounts['days'] = $editingTimeInSeconds ? $editingTimeInSeconds / (60 * 60 * 24) : 1; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Format the first and last dates. |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | : 0; |
179 | 179 | |
180 | 180 | // Sum deleted and live to make the total. |
181 | - $revisionCounts['total'] = $revisionCounts['deleted'] + $revisionCounts['live']; |
|
181 | + $revisionCounts['total'] = $revisionCounts['deleted']+$revisionCounts['live']; |
|
182 | 182 | |
183 | 183 | // Calculate the average number of live edits per day. |
184 | 184 | $revisionCounts['avg_per_day'] = round( |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | $results = $resultQuery->fetchAll(); |
223 | 223 | |
224 | 224 | $pageCounts = array_combine( |
225 | - array_map(function ($e) { |
|
225 | + array_map(function($e) { |
|
226 | 226 | return $e['source']; |
227 | 227 | }, $results), |
228 | - array_map(function ($e) { |
|
228 | + array_map(function($e) { |
|
229 | 229 | return $e['value']; |
230 | 230 | }, $results) |
231 | 231 | ); |
232 | 232 | |
233 | 233 | // Total created. |
234 | - $pageCounts['created'] = $pageCounts['created-live'] + $pageCounts['created-deleted']; |
|
234 | + $pageCounts['created'] = $pageCounts['created-live']+$pageCounts['created-deleted']; |
|
235 | 235 | |
236 | 236 | // Calculate the average number of edits per page. |
237 | 237 | $pageCounts['edits_per_page'] = 0; |
@@ -260,17 +260,17 @@ discard block |
||
260 | 260 | $resultQuery->execute(); |
261 | 261 | $results = $resultQuery->fetchAll(); |
262 | 262 | $logCounts = array_combine( |
263 | - array_map(function ($e) { |
|
263 | + array_map(function($e) { |
|
264 | 264 | return $e['source']; |
265 | 265 | }, $results), |
266 | - array_map(function ($e) { |
|
266 | + array_map(function($e) { |
|
267 | 267 | return $e['value']; |
268 | 268 | }, $results) |
269 | 269 | ); |
270 | 270 | |
271 | 271 | // Make sure there is some value for each of the wanted counts. |
272 | 272 | $requiredCounts = [ |
273 | - 'thanks-thank', 'review-approve', 'patrol-patrol','block-block', 'block-unblock', |
|
273 | + 'thanks-thank', 'review-approve', 'patrol-patrol', 'block-block', 'block-unblock', |
|
274 | 274 | 'protect-protect', 'protect-unprotect', 'delete-delete', 'delete-revision', |
275 | 275 | 'delete-restore', 'import-import', 'upload-upload', 'upload-overwrite', |
276 | 276 | ]; |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // Merge approvals together. |
284 | - $logCounts['review-approve'] = $logCounts['review-approve'] + |
|
285 | - (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) + |
|
286 | - (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) + |
|
284 | + $logCounts['review-approve'] = $logCounts['review-approve']+ |
|
285 | + (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+ |
|
286 | + (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+ |
|
287 | 287 | (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0); |
288 | 288 | |
289 | 289 | // Add Commons upload count, if applicable. |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | { |
310 | 310 | $userId = $this->getUserId($username); |
311 | 311 | $sql = "SELECT page_namespace, count(rev_id) AS total |
312 | - FROM ".$this->labsHelper->getTable('revision') ." r |
|
312 | + FROM ".$this->labsHelper->getTable('revision')." r |
|
313 | 313 | JOIN ".$this->labsHelper->getTable('page')." p on r.rev_page = p.page_id |
314 | 314 | WHERE r.rev_user = :id GROUP BY page_namespace"; |
315 | 315 | $resultQuery = $this->replicas->prepare($sql); |
@@ -317,10 +317,10 @@ discard block |
||
317 | 317 | $resultQuery->execute(); |
318 | 318 | $results = $resultQuery->fetchAll(); |
319 | 319 | $namespaceTotals = array_combine( |
320 | - array_map(function ($e) { |
|
320 | + array_map(function($e) { |
|
321 | 321 | return $e['page_namespace']; |
322 | 322 | }, $results), |
323 | - array_map(function ($e) { |
|
323 | + array_map(function($e) { |
|
324 | 324 | return $e['total']; |
325 | 325 | }, $results) |
326 | 326 | ); |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " |
347 | 347 | . " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " |
348 | 348 | . " page_title, page_namespace " |
349 | - . " FROM " . $this->labsHelper->getTable('revision', $project['dbName']) |
|
350 | - . " JOIN " . $this->labsHelper->getTable('page', $project['dbName']) |
|
349 | + . " FROM ".$this->labsHelper->getTable('revision', $project['dbName']) |
|
350 | + . " JOIN ".$this->labsHelper->getTable('page', $project['dbName']) |
|
351 | 351 | . " ON (rev_page = page_id)" |
352 | 352 | . " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" |
353 | 353 | . " ORDER BY rev_timestamp DESC" |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | continue; |
363 | 363 | } |
364 | 364 | $revsWithProject = array_map( |
365 | - function (&$item) use ($project) { |
|
365 | + function(&$item) use ($project) { |
|
366 | 366 | $item['project_name'] = $project['name']; |
367 | 367 | $item['project_url'] = $project['url']; |
368 | 368 | $item['project_db_name'] = $project['dbName']; |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | ); |
374 | 374 | $allRevisions = array_merge($allRevisions, $revsWithProject); |
375 | 375 | } |
376 | - usort($allRevisions, function ($a, $b) { |
|
377 | - return $b['rev_timestamp'] - $a['rev_timestamp']; |
|
376 | + usort($allRevisions, function($a, $b) { |
|
377 | + return $b['rev_timestamp']-$a['rev_timestamp']; |
|
378 | 378 | }); |
379 | 379 | return array_slice($allRevisions, 0, $contribCount); |
380 | 380 | } |
@@ -396,8 +396,8 @@ discard block |
||
396 | 396 | . " MONTH(rev_timestamp) AS `month`," |
397 | 397 | . " page_namespace," |
398 | 398 | . " COUNT(rev_id) AS `count` " |
399 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
400 | - . " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" |
|
399 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
400 | + . " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)" |
|
401 | 401 | . " WHERE rev_user_text = :username" |
402 | 402 | . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " |
403 | 403 | . " ORDER BY rev_timestamp DESC"; |
@@ -453,10 +453,10 @@ discard block |
||
453 | 453 | . " SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," |
454 | 454 | . " page_namespace," |
455 | 455 | . " COUNT(rev_id) AS `count` " |
456 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
457 | - . " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
458 | - " WHERE rev_user_text = :username" . |
|
459 | - " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " . |
|
456 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
457 | + . " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
458 | + " WHERE rev_user_text = :username". |
|
459 | + " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ". |
|
460 | 460 | " ORDER BY rev_timestamp DESC "; |
461 | 461 | $resultQuery = $this->replicas->prepare($sql); |
462 | 462 | $resultQuery->bindParam(":username", $username); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | . " DAYOFWEEK(rev_timestamp) AS `y`, " |
498 | 498 | . " $xCalc AS `x`, " |
499 | 499 | . " COUNT(rev_id) AS `r` " |
500 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
500 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
501 | 501 | . " WHERE rev_user_text = :username" |
502 | 502 | . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " |
503 | 503 | . " "; |
@@ -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; |