@@ -248,7 +248,6 @@ discard block |
||
| 248 | 248 | * Get a user's total edit count on one or more project. |
| 249 | 249 | * Requires the CentralAuth extension to be installed on the project. |
| 250 | 250 | * |
| 251 | - * @param string $username The username. |
|
| 252 | 251 | * @param Project $project The project to start from. |
| 253 | 252 | * @return mixed[]|boolean Array of total edit counts, or false if none could be found. |
| 254 | 253 | */ |
@@ -295,7 +294,7 @@ discard block |
||
| 295 | 294 | |
| 296 | 295 | /** |
| 297 | 296 | * Get total edit counts for the top 10 projects for this user. |
| 298 | - * @param string $username The username. |
|
| 297 | + * @param string $stopwatchName |
|
| 299 | 298 | * @return string[] Elements are arrays with 'dbName', 'url', 'name', and 'total'. |
| 300 | 299 | */ |
| 301 | 300 | protected function getRevisionCountsAllProjectsNoCentralAuth( |
@@ -16,7 +16,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | ); |
@@ -331,16 +331,16 @@ discard block |
||
| 331 | 331 | { |
| 332 | 332 | $userId = $this->getUserId($username); |
| 333 | 333 | $sql = "SELECT page_namespace, count(rev_id) AS total |
| 334 | - FROM " . $this->labsHelper->getTable('revision') . " r |
|
| 335 | - JOIN " . $this->labsHelper->getTable('page') . " p on r.rev_page = p.page_id |
|
| 334 | + FROM " . $this->labsHelper->getTable('revision')." r |
|
| 335 | + JOIN " . $this->labsHelper->getTable('page')." p on r.rev_page = p.page_id |
|
| 336 | 336 | WHERE r.rev_user = :id GROUP BY page_namespace"; |
| 337 | 337 | $resultQuery = $this->replicas->prepare($sql); |
| 338 | 338 | $resultQuery->bindParam(":id", $userId); |
| 339 | 339 | $resultQuery->execute(); |
| 340 | 340 | $results = $resultQuery->fetchAll(); |
| 341 | - $namespaceTotals = array_combine(array_map(function ($e) { |
|
| 341 | + $namespaceTotals = array_combine(array_map(function($e) { |
|
| 342 | 342 | return $e['page_namespace']; |
| 343 | - }, $results), array_map(function ($e) { |
|
| 343 | + }, $results), array_map(function($e) { |
|
| 344 | 344 | return $e['total']; |
| 345 | 345 | }, $results)); |
| 346 | 346 | |
@@ -363,14 +363,14 @@ discard block |
||
| 363 | 363 | $revisions = $this->cacheGet($cacheKey); |
| 364 | 364 | } else { |
| 365 | 365 | $sql = |
| 366 | - "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " . |
|
| 367 | - " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " . |
|
| 368 | - " page_title, page_namespace " . " FROM " . |
|
| 369 | - $this->labsHelper->getTable('revision', $project['dbName']) . " JOIN " . |
|
| 370 | - $this->labsHelper->getTable('page', $project['dbName']) . |
|
| 371 | - " ON (rev_page = page_id)" . |
|
| 372 | - " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" . |
|
| 373 | - " ORDER BY rev_timestamp DESC" . " LIMIT 10"; |
|
| 366 | + "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, ". |
|
| 367 | + " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, ". |
|
| 368 | + " page_title, page_namespace "." FROM ". |
|
| 369 | + $this->labsHelper->getTable('revision', $project['dbName'])." JOIN ". |
|
| 370 | + $this->labsHelper->getTable('page', $project['dbName']). |
|
| 371 | + " ON (rev_page = page_id)". |
|
| 372 | + " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username". |
|
| 373 | + " ORDER BY rev_timestamp DESC"." LIMIT 10"; |
|
| 374 | 374 | $resultQuery = $this->replicas->prepare($sql); |
| 375 | 375 | $resultQuery->bindParam(":username", $username); |
| 376 | 376 | $resultQuery->execute(); |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | if (count($revisions) === 0) { |
| 381 | 381 | continue; |
| 382 | 382 | } |
| 383 | - $revsWithProject = array_map(function (&$item) use ($project) { |
|
| 383 | + $revsWithProject = array_map(function(&$item) use ($project) { |
|
| 384 | 384 | $item['project_name'] = $project['wikiName']; |
| 385 | 385 | $item['project_url'] = $project['url']; |
| 386 | 386 | $item['project_db_name'] = $project['dbName']; |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | }, $revisions); |
| 391 | 391 | $allRevisions = array_merge($allRevisions, $revsWithProject); |
| 392 | 392 | } |
| 393 | - usort($allRevisions, function ($a, $b) { |
|
| 394 | - return $b['rev_timestamp'] - $a['rev_timestamp']; |
|
| 393 | + usort($allRevisions, function($a, $b) { |
|
| 394 | + return $b['rev_timestamp']-$a['rev_timestamp']; |
|
| 395 | 395 | }); |
| 396 | 396 | |
| 397 | 397 | return array_slice($allRevisions, 0, $topN); |
@@ -410,12 +410,12 @@ discard block |
||
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $sql = |
| 413 | - "SELECT " . " YEAR(rev_timestamp) AS `year`," . |
|
| 414 | - " MONTH(rev_timestamp) AS `month`," . " page_namespace," . |
|
| 415 | - " COUNT(rev_id) AS `count` " . " FROM " . $this->labsHelper->getTable('revision') . |
|
| 416 | - " JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
| 417 | - " WHERE rev_user_text = :username" . |
|
| 418 | - " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " . |
|
| 413 | + "SELECT "." YEAR(rev_timestamp) AS `year`,". |
|
| 414 | + " MONTH(rev_timestamp) AS `month`,"." page_namespace,". |
|
| 415 | + " COUNT(rev_id) AS `count` "." FROM ".$this->labsHelper->getTable('revision'). |
|
| 416 | + " JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
| 417 | + " WHERE rev_user_text = :username". |
|
| 418 | + " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace ". |
|
| 419 | 419 | " ORDER BY rev_timestamp DESC"; |
| 420 | 420 | $resultQuery = $this->replicas->prepare($sql); |
| 421 | 421 | $resultQuery->bindParam(":username", $username); |
@@ -437,14 +437,14 @@ discard block |
||
| 437 | 437 | if (!isset($out['totals'][$ns])) { |
| 438 | 438 | $out['totals'][$ns] = []; |
| 439 | 439 | } |
| 440 | - $out['totals'][$ns][$total['year'] . $total['month']] = $total['count']; |
|
| 440 | + $out['totals'][$ns][$total['year'].$total['month']] = $total['count']; |
|
| 441 | 441 | } |
| 442 | 442 | // Fill in the blanks (where no edits were made in a given month for a namespace). |
| 443 | 443 | for ($y = $out['min_year']; $y <= $out['max_year']; $y++) { |
| 444 | 444 | for ($m = 1; $m <= 12; $m++) { |
| 445 | 445 | foreach ($out['totals'] as $nsId => &$total) { |
| 446 | - if (!isset($total[$y . $m])) { |
|
| 447 | - $total[$y . $m] = 0; |
|
| 446 | + if (!isset($total[$y.$m])) { |
|
| 447 | + $total[$y.$m] = 0; |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | } |
@@ -467,12 +467,12 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | $sql = |
| 470 | - "SELECT " . " SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," . |
|
| 471 | - " page_namespace," . " COUNT(rev_id) AS `count` " . " FROM " . |
|
| 472 | - $this->labsHelper->getTable('revision') . " JOIN " . |
|
| 473 | - $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" . |
|
| 474 | - " WHERE rev_user_text = :username" . |
|
| 475 | - " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " . |
|
| 470 | + "SELECT "." SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`,". |
|
| 471 | + " page_namespace,"." COUNT(rev_id) AS `count` "." FROM ". |
|
| 472 | + $this->labsHelper->getTable('revision')." JOIN ". |
|
| 473 | + $this->labsHelper->getTable('page')." ON (rev_page = page_id)". |
|
| 474 | + " WHERE rev_user_text = :username". |
|
| 475 | + " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ". |
|
| 476 | 476 | " ORDER BY rev_timestamp DESC "; |
| 477 | 477 | $resultQuery = $this->replicas->prepare($sql); |
| 478 | 478 | $resultQuery->bindParam(":username", $username); |
@@ -511,9 +511,9 @@ discard block |
||
| 511 | 511 | $hourInterval = 2; |
| 512 | 512 | $xCalc = "ROUND(HOUR(rev_timestamp)/$hourInterval)*$hourInterval"; |
| 513 | 513 | $sql = |
| 514 | - "SELECT " . " DAYOFWEEK(rev_timestamp) AS `y`, " . " $xCalc AS `x`, " . |
|
| 515 | - " COUNT(rev_id) AS `r` " . " FROM " . $this->labsHelper->getTable('revision') . |
|
| 516 | - " WHERE rev_user_text = :username" . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " . |
|
| 514 | + "SELECT "." DAYOFWEEK(rev_timestamp) AS `y`, "." $xCalc AS `x`, ". |
|
| 515 | + " COUNT(rev_id) AS `r` "." FROM ".$this->labsHelper->getTable('revision'). |
|
| 516 | + " WHERE rev_user_text = :username"." GROUP BY DAYOFWEEK(rev_timestamp), $xCalc ". |
|
| 517 | 517 | " "; |
| 518 | 518 | $resultQuery = $this->replicas->prepare($sql); |
| 519 | 519 | $resultQuery->bindParam(":username", $username); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | protected function getRevisionCounts() |
| 43 | 43 | { |
| 44 | - if (! is_array($this->revisionCounts)) { |
|
| 44 | + if (!is_array($this->revisionCounts)) { |
|
| 45 | 45 | $this->revisionCounts = $this->getRepository() |
| 46 | 46 | ->getRevisionCounts($this->project, $this->user); |
| 47 | 47 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | protected function getRevisionDates() |
| 56 | 56 | { |
| 57 | - if (! is_array($this->revisionDates)) { |
|
| 57 | + if (!is_array($this->revisionDates)) { |
|
| 58 | 58 | $this->revisionDates = $this->getRepository() |
| 59 | 59 | ->getRevisionDates($this->project, $this->user); |
| 60 | 60 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | protected function getPageCounts() |
| 69 | 69 | { |
| 70 | - if (! is_array($this->pageCounts)) { |
|
| 70 | + if (!is_array($this->pageCounts)) { |
|
| 71 | 71 | $this->pageCounts = $this->getRepository() |
| 72 | 72 | ->getPageCounts($this->project, $this->user); |
| 73 | 73 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | protected function getLogCounts() |
| 82 | 82 | { |
| 83 | - if (! is_array($this->logCounts)) { |
|
| 83 | + if (!is_array($this->logCounts)) { |
|
| 84 | 84 | $this->logCounts = $this->getRepository() |
| 85 | 85 | ->getLogCounts($this->project, $this->user); |
| 86 | 86 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function countAllRevisions() |
| 111 | 111 | { |
| 112 | - return $this->countLiveRevisions() + $this->countDeletedRevisions(); |
|
| 112 | + return $this->countLiveRevisions()+$this->countDeletedRevisions(); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function countRevisionsWithoutComments() |
| 130 | 130 | { |
| 131 | - return $this->countAllRevisions() - $this->countRevisionsWithComments(); |
|
| 131 | + return $this->countAllRevisions()-$this->countRevisionsWithComments(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public function countAllPagesEdited() |
| 197 | 197 | { |
| 198 | - return $this->countLivePagesEdited() + $this->countDeletedPagesEdited(); |
|
| 198 | + return $this->countLivePagesEdited()+$this->countDeletedPagesEdited(); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | public function countPagesCreated() |
| 215 | 215 | { |
| 216 | - return $this->countCreatedPagesLive() + $this->countPagesCreatedDeleted(); |
|
| 216 | + return $this->countCreatedPagesLive()+$this->countPagesCreatedDeleted(); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | public function approvals() |
| 360 | 360 | { |
| 361 | 361 | $logCounts = $this->getLogCounts(); |
| 362 | - $total = $logCounts['review-approve'] + |
|
| 363 | - (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) + |
|
| 364 | - (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) + |
|
| 362 | + $total = $logCounts['review-approve']+ |
|
| 363 | + (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+ |
|
| 364 | + (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+ |
|
| 365 | 365 | (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0); |
| 366 | 366 | return $total; |
| 367 | 367 | } |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | // Get counts. |
| 388 | 388 | $editCounts = $this->getRepository()->getRevisionCountsAllProjects($user, $project); |
| 389 | 389 | // Sort. |
| 390 | - uasort($editCounts, function ($a, $b) { |
|
| 391 | - return $b['total'] - $a['total']; |
|
| 390 | + uasort($editCounts, function($a, $b) { |
|
| 391 | + return $b['total']-$a['total']; |
|
| 392 | 392 | }); |
| 393 | 393 | // Truncate, and return. |
| 394 | 394 | return array_slice($editCounts, 0, $numProjects); |