@@ -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,12 +2,10 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace AppBundle\Helper; |
| 4 | 4 | |
| 5 | -use AppBundle\Twig\AppExtension; |
|
| 6 | 5 | use DateInterval; |
| 7 | 6 | use Doctrine\DBAL\Connection; |
| 8 | 7 | use Exception; |
| 9 | 8 | use Symfony\Component\DependencyInjection\Container; |
| 10 | -use Symfony\Component\VarDumper\VarDumper; |
|
| 11 | 9 | |
| 12 | 10 | class EditCounterHelper extends HelperBase |
| 13 | 11 | { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | $topEditCounts = []; |
| 61 | 61 | foreach ($this->labsHelper->allProjects() as $project) { |
| 62 | - $cacheKey = 'topprojects.' . $project['dbName'] . '.' . $username; |
|
| 62 | + $cacheKey = 'topprojects.'.$project['dbName'].'.'.$username; |
|
| 63 | 63 | if ($this->cacheHas($cacheKey)) { |
| 64 | 64 | $total = $this->cacheGet($cacheKey); |
| 65 | 65 | } else { |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | $topEditCounts[$project['dbName']] = array_merge($project, ['total' => $total]); |
| 77 | 77 | } |
| 78 | - uasort($topEditCounts, function ($a, $b) { |
|
| 79 | - return $b['total'] - $a['total']; |
|
| 78 | + uasort($topEditCounts, function($a, $b) { |
|
| 79 | + return $b['total']-$a['total']; |
|
| 80 | 80 | }); |
| 81 | 81 | return array_slice($topEditCounts, 0, $numProjects); |
| 82 | 82 | } |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $revisionCounts = array_combine( |
| 149 | - array_map(function ($e) { |
|
| 149 | + array_map(function($e) { |
|
| 150 | 150 | return $e['source']; |
| 151 | 151 | }, $results), |
| 152 | - array_map(function ($e) { |
|
| 152 | + array_map(function($e) { |
|
| 153 | 153 | return $e['value']; |
| 154 | 154 | }, $results) |
| 155 | 155 | ); |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | // Count the number of days, accounting for when there's zero or one edit. |
| 158 | 158 | $revisionCounts['days'] = 0; |
| 159 | 159 | if (isset($revisionCounts['first']) && isset($revisionCounts['last'])) { |
| 160 | - $editingTimeInSeconds = ceil($revisionCounts['last'] - $revisionCounts['first']); |
|
| 161 | - $revisionCounts['days'] = $editingTimeInSeconds ? $editingTimeInSeconds/(60*60*24) : 1; |
|
| 160 | + $editingTimeInSeconds = ceil($revisionCounts['last']-$revisionCounts['first']); |
|
| 161 | + $revisionCounts['days'] = $editingTimeInSeconds ? $editingTimeInSeconds / (60 * 60 * 24) : 1; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Format the first and last dates. |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | : 0; |
| 171 | 171 | |
| 172 | 172 | // Sum deleted and live to make the total. |
| 173 | - $revisionCounts['total'] = $revisionCounts['deleted'] + $revisionCounts['live']; |
|
| 173 | + $revisionCounts['total'] = $revisionCounts['deleted']+$revisionCounts['live']; |
|
| 174 | 174 | |
| 175 | 175 | // Calculate the average number of live edits per day. |
| 176 | 176 | $revisionCounts['avg_per_day'] = round( |
@@ -214,16 +214,16 @@ discard block |
||
| 214 | 214 | $results = $resultQuery->fetchAll(); |
| 215 | 215 | |
| 216 | 216 | $pageCounts = array_combine( |
| 217 | - array_map(function ($e) { |
|
| 217 | + array_map(function($e) { |
|
| 218 | 218 | return $e['source']; |
| 219 | 219 | }, $results), |
| 220 | - array_map(function ($e) { |
|
| 220 | + array_map(function($e) { |
|
| 221 | 221 | return $e['value']; |
| 222 | 222 | }, $results) |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | // Total created. |
| 226 | - $pageCounts['created'] = $pageCounts['created-live'] + $pageCounts['created-deleted']; |
|
| 226 | + $pageCounts['created'] = $pageCounts['created-live']+$pageCounts['created-deleted']; |
|
| 227 | 227 | |
| 228 | 228 | // Calculate the average number of edits per page. |
| 229 | 229 | $pageCounts['edits_per_page'] = 0; |
@@ -252,17 +252,17 @@ discard block |
||
| 252 | 252 | $resultQuery->execute(); |
| 253 | 253 | $results = $resultQuery->fetchAll(); |
| 254 | 254 | $logCounts = array_combine( |
| 255 | - array_map(function ($e) { |
|
| 255 | + array_map(function($e) { |
|
| 256 | 256 | return $e['source']; |
| 257 | 257 | }, $results), |
| 258 | - array_map(function ($e) { |
|
| 258 | + array_map(function($e) { |
|
| 259 | 259 | return $e['value']; |
| 260 | 260 | }, $results) |
| 261 | 261 | ); |
| 262 | 262 | |
| 263 | 263 | // Make sure there is some value for each of the wanted counts. |
| 264 | 264 | $requiredCounts = [ |
| 265 | - 'thanks-thank', 'review-approve', 'patrol-patrol','block-block', 'block-unblock', |
|
| 265 | + 'thanks-thank', 'review-approve', 'patrol-patrol', 'block-block', 'block-unblock', |
|
| 266 | 266 | 'protect-protect', 'protect-unprotect', 'delete-delete', 'delete-revision', |
| 267 | 267 | 'delete-restore', 'import-import', 'upload-upload', 'upload-overwrite', |
| 268 | 268 | ]; |
@@ -273,9 +273,9 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Merge approvals together. |
| 276 | - $logCounts['review-approve'] = $logCounts['review-approve'] + |
|
| 277 | - (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) + |
|
| 278 | - (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) + |
|
| 276 | + $logCounts['review-approve'] = $logCounts['review-approve']+ |
|
| 277 | + (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+ |
|
| 278 | + (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+ |
|
| 279 | 279 | (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0); |
| 280 | 280 | |
| 281 | 281 | // Add Commons upload count, if applicable. |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | { |
| 302 | 302 | $userId = $this->getUserId($username); |
| 303 | 303 | $sql = "SELECT page_namespace, count(rev_id) AS total |
| 304 | - FROM ".$this->labsHelper->getTable('revision') ." r |
|
| 304 | + FROM ".$this->labsHelper->getTable('revision')." r |
|
| 305 | 305 | JOIN ".$this->labsHelper->getTable('page')." p on r.rev_page = p.page_id |
| 306 | 306 | WHERE r.rev_user = :id GROUP BY page_namespace"; |
| 307 | 307 | $resultQuery = $this->replicas->prepare($sql); |
@@ -309,10 +309,10 @@ discard block |
||
| 309 | 309 | $resultQuery->execute(); |
| 310 | 310 | $results = $resultQuery->fetchAll(); |
| 311 | 311 | $namespaceTotals = array_combine( |
| 312 | - array_map(function ($e) { |
|
| 312 | + array_map(function($e) { |
|
| 313 | 313 | return $e['page_namespace']; |
| 314 | 314 | }, $results), |
| 315 | - array_map(function ($e) { |
|
| 315 | + array_map(function($e) { |
|
| 316 | 316 | return $e['total']; |
| 317 | 317 | }, $results) |
| 318 | 318 | ); |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | $sql = |
| 338 | 338 | "SELECT rev_id, rev_comment, rev_timestamp, rev_minor_edit, rev_deleted, " |
| 339 | 339 | . " rev_len, rev_parent_id, page_title " |
| 340 | - . " FROM " . $this->labsHelper->getTable('revision', $project['dbName']) |
|
| 341 | - . " JOIN " . $this->labsHelper->getTable('page', $project['dbName']) |
|
| 340 | + . " FROM ".$this->labsHelper->getTable('revision', $project['dbName']) |
|
| 341 | + . " JOIN ".$this->labsHelper->getTable('page', $project['dbName']) |
|
| 342 | 342 | . " ON (rev_page = page_id)" |
| 343 | 343 | . " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" |
| 344 | 344 | . " ORDER BY rev_timestamp DESC" |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | continue; |
| 354 | 354 | } |
| 355 | 355 | $revsWithProject = array_map( |
| 356 | - function (&$item) use ($project) { |
|
| 356 | + function(&$item) use ($project) { |
|
| 357 | 357 | $item['project_name'] = $project['name']; |
| 358 | 358 | $item['project_url'] = $project['url']; |
| 359 | 359 | $item['project_db_name'] = $project['dbName']; |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | ); |
| 364 | 364 | $allRevisions = array_merge($allRevisions, $revsWithProject); |
| 365 | 365 | } |
| 366 | - usort($allRevisions, function ($a, $b) { |
|
| 367 | - return $b['rev_timestamp'] - $a['rev_timestamp']; |
|
| 366 | + usort($allRevisions, function($a, $b) { |
|
| 367 | + return $b['rev_timestamp']-$a['rev_timestamp']; |
|
| 368 | 368 | }); |
| 369 | 369 | return array_slice($allRevisions, 0, $contribCount); |
| 370 | 370 | } |
@@ -386,8 +386,8 @@ discard block |
||
| 386 | 386 | . " MONTH(rev_timestamp) AS `month`," |
| 387 | 387 | . " page_namespace," |
| 388 | 388 | . " COUNT(rev_id) AS `count` " |
| 389 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
| 390 | - . " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" |
|
| 389 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
| 390 | + . " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)" |
|
| 391 | 391 | . " WHERE rev_user_text = :username" |
| 392 | 392 | . " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " |
| 393 | 393 | . " ORDER BY rev_timestamp DESC"; |
@@ -443,10 +443,10 @@ discard block |
||
| 443 | 443 | . " SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," |
| 444 | 444 | . " page_namespace," |
| 445 | 445 | . " COUNT(rev_id) AS `count` " |
| 446 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
| 447 | - . " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
| 448 | - " WHERE rev_user_text = :username" . |
|
| 449 | - " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " . |
|
| 446 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
| 447 | + . " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
| 448 | + " WHERE rev_user_text = :username". |
|
| 449 | + " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ". |
|
| 450 | 450 | " ORDER BY rev_timestamp DESC "; |
| 451 | 451 | $resultQuery = $this->replicas->prepare($sql); |
| 452 | 452 | $resultQuery->bindParam(":username", $username); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | . " DAYOFWEEK(rev_timestamp) AS `y`, " |
| 488 | 488 | . " $xCalc AS `x`, " |
| 489 | 489 | . " COUNT(rev_id) AS `r` " |
| 490 | - . " FROM " . $this->labsHelper->getTable('revision') |
|
| 490 | + . " FROM ".$this->labsHelper->getTable('revision') |
|
| 491 | 491 | . " WHERE rev_user_text = :username" |
| 492 | 492 | . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " |
| 493 | 493 | . " "; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | // Create the query we're going to run against the meta database |
| 62 | 62 | $wikiQuery = $this->client->createQueryBuilder(); |
| 63 | 63 | $wikiQuery |
| 64 | - ->select([ 'dbName', 'name', 'url', 'lang' ]) |
|
| 64 | + ->select(['dbName', 'name', 'url', 'lang']) |
|
| 65 | 65 | ->from('wiki') |
| 66 | 66 | ->where($wikiQuery->expr()->eq('dbname', ':project')) |
| 67 | 67 | // The meta database will have the project's URL stored as https://en.wikipedia.org |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $this->dbName = $dbName; |
| 98 | 98 | $this->url = $url; |
| 99 | 99 | |
| 100 | - return [ 'dbName' => $dbName, 'wikiName' => $wikiName, 'url' => $url, 'lang' => $lang ]; |
|
| 100 | + return ['dbName' => $dbName, 'wikiName' => $wikiName, 'url' => $url, 'lang' => $lang]; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | public function allProjects() |
| 107 | 107 | { |
| 108 | 108 | $wikiQuery = $this->client->createQueryBuilder(); |
| 109 | - $wikiQuery->select([ 'dbName', 'name', 'url' ])->from('wiki'); |
|
| 109 | + $wikiQuery->select(['dbName', 'name', 'url'])->from('wiki'); |
|
| 110 | 110 | $stmt = $wikiQuery->execute(); |
| 111 | 111 | $out = $stmt->fetchAll(); |
| 112 | 112 | return $out; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function allProjects() |
| 119 | 119 | { |
| 120 | 120 | $wikiQuery = $this->client->createQueryBuilder(); |
| 121 | - $wikiQuery->select([ 'dbName', 'name', 'url' ])->from('wiki'); |
|
| 121 | + $wikiQuery->select(['dbName', 'name', 'url'])->from('wiki'); |
|
| 122 | 122 | $stmt = $wikiQuery->execute(); |
| 123 | 123 | $out = $stmt->fetchAll(); |
| 124 | 124 | return $out; |