@@ -3,8 +3,6 @@ |
||
3 | 3 | namespace AppBundle\Controller; |
4 | 4 | |
5 | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6 | -use Symfony\Component\CssSelector\Exception\InternalErrorException; |
|
7 | -use Symfony\Component\Debug\Exception\ContextErrorException; |
|
8 | 6 | use Symfony\Component\HttpFoundation\Request; |
9 | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
10 | 8 | use Xtools\ProjectRepository; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $username = $request->query->get('username'); |
49 | 49 | |
50 | 50 | if ($projectQuery != '' && $username != '') { |
51 | - $routeParams = [ 'project' => $projectQuery, 'username' => $username ]; |
|
51 | + $routeParams = ['project' => $projectQuery, 'username' => $username]; |
|
52 | 52 | return $this->redirectToRoute( |
53 | 53 | 'rfxvoteResult', |
54 | 54 | $routeParams |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | $titles = []; |
168 | 168 | |
169 | 169 | while ($row = $sth->fetch()) { |
170 | - $titles[] = $namespaces[$row['page_namespace']] . |
|
171 | - ':' .$row['page_title']; |
|
170 | + $titles[] = $namespaces[$row['page_namespace']]. |
|
171 | + ':'.$row['page_title']; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Chunking... it's possible to make a URI too long |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @Route("/rfxvote/index.php", name="rfxvoteIndexPhp") |
40 | 40 | * @Route("/rfxvote", name="RfXVoteCalculator") |
41 | 41 | * |
42 | - * @return Response |
|
42 | + * @return \Symfony\Component\HttpFoundation\Response |
|
43 | 43 | */ |
44 | 44 | public function indexAction() |
45 | 45 | { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @Route("/rfxvote/{project}/{username}", name="rfxvoteResult") |
90 | 90 | * |
91 | - * @return Response |
|
91 | + * @return \Symfony\Component\HttpFoundation\Response |
|
92 | 92 | * @codeCoverageIgnore |
93 | 93 | */ |
94 | 94 | public function resultAction($project, $username) |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | |
474 | 474 | /** |
475 | 475 | * Get the date and time of the user's first edit. |
476 | - * @return DateTime|bool The time of the first revision, or false. |
|
476 | + * @return DateInterval The time of the first revision, or false. |
|
477 | 477 | */ |
478 | 478 | public function datetimeFirstRevision() |
479 | 479 | { |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | |
484 | 484 | /** |
485 | 485 | * Get the date and time of the user's first edit. |
486 | - * @return DateTime|bool The time of the last revision, or false. |
|
486 | + * @return DateInterval The time of the last revision, or false. |
|
487 | 487 | */ |
488 | 488 | public function datetimeLastRevision() |
489 | 489 | { |
@@ -6,7 +6,6 @@ |
||
6 | 6 | namespace Xtools; |
7 | 7 | |
8 | 8 | use DateTime; |
9 | -use Exception; |
|
10 | 9 | use DatePeriod; |
11 | 10 | use DateInterval; |
12 | 11 | use GuzzleHttp; |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | $promises[] = $promise; |
118 | 118 | |
119 | 119 | // Handle response of $promise asynchronously. |
120 | - $promise->then(function ($response) use ($key, $endpoint) { |
|
121 | - $result = (array) json_decode($response->getBody()->getContents()); |
|
120 | + $promise->then(function($response) use ($key, $endpoint) { |
|
121 | + $result = (array)json_decode($response->getBody()->getContents()); |
|
122 | 122 | |
123 | 123 | $this->getRepository() |
124 | 124 | ->getLog() |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | // We'll log this to see how often it happens. |
136 | 136 | $this->getRepository() |
137 | 137 | ->getLog() |
138 | - ->error("Failed to fetch data for $endpoint via async, " . |
|
138 | + ->error("Failed to fetch data for $endpoint via async, ". |
|
139 | 139 | "re-attempting synchoronously."); |
140 | 140 | } |
141 | 141 | }); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | // Filter out unblocks unless requested. |
193 | 193 | if ($blocksOnly) { |
194 | - $blocks = array_filter($blocks, function ($block) { |
|
194 | + $blocks = array_filter($blocks, function($block) { |
|
195 | 195 | return $block['log_action'] === 'block'; |
196 | 196 | }); |
197 | 197 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function countAllRevisions() |
227 | 227 | { |
228 | - return $this->countLiveRevisions() + $this->countDeletedRevisions(); |
|
228 | + return $this->countLiveRevisions()+$this->countDeletedRevisions(); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function countRevisionsWithoutComments() |
246 | 246 | { |
247 | - return $this->countLiveRevisions() - $this->countRevisionsWithComments(); |
|
247 | + return $this->countLiveRevisions()-$this->countRevisionsWithComments(); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function countAllPagesEdited() |
285 | 285 | { |
286 | - return $this->countLivePagesEdited() + $this->countDeletedPagesEdited(); |
|
286 | + return $this->countLivePagesEdited()+$this->countDeletedPagesEdited(); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public function countPagesCreated() |
295 | 295 | { |
296 | - return $this->countCreatedPagesLive() + $this->countPagesCreatedDeleted(); |
|
296 | + return $this->countCreatedPagesLive()+$this->countPagesCreatedDeleted(); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | } elseif ($block['log_action'] === 'unblock') { |
434 | 434 | // The last block was lifted. So the duration will be the time from when the |
435 | 435 | // last block was set to the time of the unblock. |
436 | - $timeSinceLastBlock = $timestamp - $lastBlock[0]; |
|
436 | + $timeSinceLastBlock = $timestamp-$lastBlock[0]; |
|
437 | 437 | if ($timeSinceLastBlock > $this->longestBlockSeconds) { |
438 | 438 | $this->longestBlockSeconds = $timeSinceLastBlock; |
439 | 439 | |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | // The last block was modified. So we will adjust $lastBlock to include |
445 | 445 | // the difference of the duration of the new reblock, and time since the last block. |
446 | 446 | // $lastBlock is left unchanged if its duration was indefinite. |
447 | - $timeSinceLastBlock = $timestamp - $lastBlock[0]; |
|
448 | - $lastBlock[1] = $timeSinceLastBlock + $duration; |
|
447 | + $timeSinceLastBlock = $timestamp-$lastBlock[0]; |
|
448 | + $lastBlock[1] = $timeSinceLastBlock+$duration; |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | } |
456 | 456 | |
457 | 457 | // Test if the last block is still active, and if so use the expiry as the duration. |
458 | - $lastBlockExpiry = $lastBlock[0] + $lastBlock[1]; |
|
458 | + $lastBlockExpiry = $lastBlock[0]+$lastBlock[1]; |
|
459 | 459 | if ($lastBlockExpiry > time() && $lastBlockExpiry > $this->longestBlockSeconds) { |
460 | 460 | $this->longestBlockSeconds = $lastBlock[1]; |
461 | 461 | // Otherwise, test if the duration of the last block is now the longest overall. |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | // If invalid, $duration is left as null. |
497 | 497 | if (strtotime($durationStr)) { |
498 | 498 | $expiry = strtotime($durationStr, $timestamp); |
499 | - $duration = $expiry - $timestamp; |
|
499 | + $duration = $expiry-$timestamp; |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | return [$timestamp, $duration]; |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | $import = isset($logCounts['import-import']) ? (int)$logCounts['import-import'] : 0; |
574 | 574 | $interwiki = isset($logCounts['import-interwiki']) ? (int)$logCounts['import-interwiki'] : 0; |
575 | 575 | $upload = isset($logCounts['import-upload']) ? (int)$logCounts['import-upload'] : 0; |
576 | - return $import + $interwiki + $upload; |
|
576 | + return $import+$interwiki+$upload; |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | public function approvals() |
698 | 698 | { |
699 | 699 | $logCounts = $this->getLogCounts(); |
700 | - $total = $logCounts['review-approve'] + |
|
701 | - (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) + |
|
702 | - (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) + |
|
700 | + $total = $logCounts['review-approve']+ |
|
701 | + (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+ |
|
702 | + (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+ |
|
703 | 703 | (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0); |
704 | 704 | return $total; |
705 | 705 | } |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | $logCounts = $this->getLogCounts(); |
724 | 724 | $create2 = $logCounts['newusers-create2'] ?: 0; |
725 | 725 | $byemail = $logCounts['newusers-byemail'] ?: 0; |
726 | - return $create2 + $byemail; |
|
726 | + return $create2+$byemail; |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | |
776 | 776 | $totals = $this->getRepository()->getMonthCounts($this->project, $this->user); |
777 | 777 | $out = [ |
778 | - 'yearLabels' => [], // labels for years |
|
778 | + 'yearLabels' => [], // labels for years |
|
779 | 779 | 'monthLabels' => [], // labels for months |
780 | 780 | 'totals' => [], // actual totals, grouped by namespace, year and then month |
781 | 781 | ]; |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | $out['totals'][$ns][$total['year']] = []; |
804 | 804 | } |
805 | 805 | |
806 | - $out['totals'][$ns][$total['year']][$total['month']] = (int) $total['count']; |
|
806 | + $out['totals'][$ns][$total['year']][$total['month']] = (int)$total['count']; |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | $dateRange = new DatePeriod( |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | ); |
814 | 814 | |
815 | 815 | foreach ($dateRange as $monthObj) { |
816 | - $year = (int) $monthObj->format('Y'); |
|
817 | - $month = (int) $monthObj->format('n'); |
|
816 | + $year = (int)$monthObj->format('Y'); |
|
817 | + $month = (int)$monthObj->format('n'); |
|
818 | 818 | |
819 | 819 | // Fill in labels |
820 | 820 | $out['monthLabels'][] = $monthObj->format('Y-m'); |
@@ -930,8 +930,8 @@ discard block |
||
930 | 930 | |
931 | 931 | if ($sorted) { |
932 | 932 | // Sort. |
933 | - uasort($this->globalEditCounts, function ($a, $b) { |
|
934 | - return $b['total'] - $a['total']; |
|
933 | + uasort($this->globalEditCounts, function($a, $b) { |
|
934 | + return $b['total']-$a['total']; |
|
935 | 935 | }); |
936 | 936 | } |
937 | 937 | |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | $nsName = $project->getNamespaces()[$revision['page_namespace']]; |
968 | 968 | } |
969 | 969 | $page = $project->getRepository() |
970 | - ->getPage($project, $nsName . ':' . $revision['page_title']); |
|
970 | + ->getPage($project, $nsName.':'.$revision['page_title']); |
|
971 | 971 | $edit = new Edit($page, $revision); |
972 | 972 | $globalEdits[$edit->getTimestamp()->getTimestamp().'-'.$edit->getId()] = $edit; |
973 | 973 | } |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | public function countSmallEdits() |
1009 | 1009 | { |
1010 | 1010 | $editSizeData = $this->getEditSizeData(); |
1011 | - return isset($editSizeData['small_edits']) ? (int) $editSizeData['small_edits'] : 0; |
|
1011 | + return isset($editSizeData['small_edits']) ? (int)$editSizeData['small_edits'] : 0; |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
@@ -1018,7 +1018,7 @@ discard block |
||
1018 | 1018 | public function countLargeEdits() |
1019 | 1019 | { |
1020 | 1020 | $editSizeData = $this->getEditSizeData(); |
1021 | - return isset($editSizeData['large_edits']) ? (int) $editSizeData['large_edits'] : 0; |
|
1021 | + return isset($editSizeData['large_edits']) ? (int)$editSizeData['large_edits'] : 0; |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | /** |
@@ -5,12 +5,9 @@ |
||
5 | 5 | |
6 | 6 | namespace AppBundle\Controller; |
7 | 7 | |
8 | -use Exception; |
|
9 | -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10 | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
11 | 9 | use Symfony\Component\HttpFoundation\Request; |
12 | 10 | use Symfony\Component\HttpFoundation\Response; |
13 | -use Symfony\Component\Debug\Exception\FatalErrorException; |
|
14 | 11 | use FOS\RestBundle\Controller\Annotations as Rest; |
15 | 12 | use FOS\RestBundle\Controller\FOSRestController; |
16 | 13 | use FOS\RestBundle\View\View; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $res['automated_editcount'] = $user->countAutomatedEdits($project, $namespace, $start, $end); |
132 | 132 | } |
133 | 133 | |
134 | - $res['nonautomated_editcount'] = $res['total_editcount'] - $res['automated_editcount']; |
|
134 | + $res['nonautomated_editcount'] = $res['total_editcount']-$res['automated_editcount']; |
|
135 | 135 | |
136 | 136 | $view = View::create()->setStatusCode(Response::HTTP_OK); |
137 | 137 | $view->setData($res); |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | if ($request->query->get('format') !== 'html') { |
177 | 177 | return new View( |
178 | 178 | [ |
179 | - 'error' => 'Unable to show any data. User has made over ' . |
|
180 | - $user->maxEdits() . ' edits.', |
|
179 | + 'error' => 'Unable to show any data. User has made over '. |
|
180 | + $user->maxEdits().' edits.', |
|
181 | 181 | ], |
182 | 182 | Response::HTTP_FORBIDDEN |
183 | 183 | ); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | if ($request->query->get('format') === 'html') { |
194 | 194 | if ($edits) { |
195 | - $edits = array_map(function ($attrs) use ($project, $username) { |
|
195 | + $edits = array_map(function($attrs) use ($project, $username) { |
|
196 | 196 | $page = $project->getRepository() |
197 | 197 | ->getPage($project, $attrs['full_page_title']); |
198 | 198 | $pageTitles[] = $attrs['full_page_title']; |
@@ -270,19 +270,19 @@ discard block |
||
270 | 270 | $info = $page->getBasicEditingInfo(); |
271 | 271 | $creationDateTime = DateTime::createFromFormat('YmdHis', $info['created_at']); |
272 | 272 | $modifiedDateTime = DateTime::createFromFormat('YmdHis', $info['modified_at']); |
273 | - $secsSinceLastEdit = (new DateTime)->getTimestamp() - $modifiedDateTime->getTimestamp(); |
|
273 | + $secsSinceLastEdit = (new DateTime)->getTimestamp()-$modifiedDateTime->getTimestamp(); |
|
274 | 274 | |
275 | 275 | $data = [ |
276 | - 'revisions' => (int) $info['num_edits'], |
|
277 | - 'editors' => (int) $info['num_editors'], |
|
276 | + 'revisions' => (int)$info['num_edits'], |
|
277 | + 'editors' => (int)$info['num_editors'], |
|
278 | 278 | 'author' => $info['author'], |
279 | - 'author_editcount' => (int) $info['author_editcount'], |
|
279 | + 'author_editcount' => (int)$info['author_editcount'], |
|
280 | 280 | 'created_at' => $creationDateTime->format('Y-m-d'), |
281 | 281 | 'created_rev_id' => $info['created_rev_id'], |
282 | 282 | 'modified_at' => $modifiedDateTime->format('Y-m-d H:i'), |
283 | 283 | 'secs_since_last_edit' => $secsSinceLastEdit, |
284 | - 'last_edit_id' => (int) $info['modified_rev_id'], |
|
285 | - 'watchers' => (int) $page->getWatchers(), |
|
284 | + 'last_edit_id' => (int)$info['modified_rev_id'], |
|
285 | + 'watchers' => (int)$page->getWatchers(), |
|
286 | 286 | 'pageviews' => $page->getLastPageviews($pageviewsOffset), |
287 | 287 | 'pageviews_offset' => $pageviewsOffset, |
288 | 288 | ]; |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Get this page's database ID. |
62 | - * @return int |
|
62 | + * @return \string|null |
|
63 | 63 | */ |
64 | 64 | public function getId() |
65 | 65 | { |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Get this page's length in bytes. |
72 | - * @return int |
|
72 | + * @return \string|null |
|
73 | 73 | */ |
74 | 74 | public function getLength() |
75 | 75 | { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | /** |
95 | 95 | * Get the full URL of this page. |
96 | - * @return string |
|
96 | + * @return \string|null |
|
97 | 97 | */ |
98 | 98 | public function getUrl() |
99 | 99 | { |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Get the numerical ID of the namespace of this page. |
106 | - * @return int |
|
106 | + * @return \string|null |
|
107 | 107 | */ |
108 | 108 | public function getNamespace() |
109 | 109 | { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Get the number of page watchers. |
116 | - * @return int |
|
116 | + * @return \string|null |
|
117 | 117 | */ |
118 | 118 | public function getWatchers() |
119 | 119 | { |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | |
421 | 421 | /** |
422 | 422 | * Get the sum of pageviews for the given page and timeframe. |
423 | - * @param string|DateTime $start In the format YYYYMMDD |
|
424 | - * @param string|DateTime $end In the format YYYYMMDD |
|
423 | + * @param string $start In the format YYYYMMDD |
|
424 | + * @param string $end In the format YYYYMMDD |
|
425 | 425 | * @return string[] |
426 | 426 | */ |
427 | 427 | public function getPageviews($start, $end) |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $info = $this->getPageInfo(); |
82 | 82 | $title = isset($info['title']) ? $info['title'] : $this->unnormalizedPageName; |
83 | 83 | $nsName = $this->getNamespaceName(); |
84 | - return str_replace($nsName . ':', '', $title); |
|
84 | + return str_replace($nsName.':', '', $title); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | { |
218 | 218 | // If a user is given, we will not cache the result via instance variable. |
219 | 219 | if ($user !== null) { |
220 | - return (int) $this->getRepository()->getNumRevisions($this, $user); |
|
220 | + return (int)$this->getRepository()->getNumRevisions($this, $user); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | // Return cached value, if present. |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $this->numRevisions = count($this->revisions); |
231 | 231 | } else { |
232 | 232 | // Otherwise do a COUNT in the event fetching all revisions is not desired. |
233 | - $this->numRevisions = (int) $this->getRepository()->getNumRevisions($this); |
|
233 | + $this->numRevisions = (int)$this->getRepository()->getNumRevisions($this); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return $this->numRevisions; |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | { |
261 | 261 | $content = $this->getRepository()->getPagesWikitext( |
262 | 262 | $this->getProject(), |
263 | - [ $this->getTitle() ] |
|
263 | + [$this->getTitle()] |
|
264 | 264 | ); |
265 | 265 | |
266 | 266 | return isset($content[$this->getTitle()]) |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | |
418 | 418 | $wikidataInfo = $this->getRepository()->getWikidataInfo($this); |
419 | 419 | |
420 | - $terms = array_map(function ($entry) { |
|
420 | + $terms = array_map(function($entry) { |
|
421 | 421 | return $entry['term']; |
422 | 422 | }, $wikidataInfo); |
423 | 423 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | 'prio' => 2, |
429 | 429 | 'name' => 'Wikidata', |
430 | 430 | 'notice' => "Label for language <em>$lang</em> is missing", // FIXME: i18n |
431 | - 'explanation' => "See: <a target='_blank' " . |
|
431 | + 'explanation' => "See: <a target='_blank' ". |
|
432 | 432 | "href='//www.wikidata.org/wiki/Help:Label'>Help:Label</a>", |
433 | 433 | ]; |
434 | 434 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | 'prio' => 3, |
439 | 439 | 'name' => 'Wikidata', |
440 | 440 | 'notice' => "Description for language <em>$lang</em> is missing", // FIXME: i18n |
441 | - 'explanation' => "See: <a target='_blank' " . |
|
441 | + 'explanation' => "See: <a target='_blank' ". |
|
442 | 442 | "href='//www.wikidata.org/wiki/Help:Description'>Help:Description</a>", |
443 | 443 | ]; |
444 | 444 | } |
@@ -517,8 +517,8 @@ discard block |
||
517 | 517 | return 0; |
518 | 518 | } |
519 | 519 | |
520 | - return array_sum(array_map(function ($item) { |
|
521 | - return (int) $item['views']; |
|
520 | + return array_sum(array_map(function($item) { |
|
521 | + return (int)$item['views']; |
|
522 | 522 | }, $pageviews['items'])); |
523 | 523 | } |
524 | 524 |
@@ -151,8 +151,8 @@ |
||
151 | 151 | // Get individual counts of how many times each tool was used. |
152 | 152 | // This also includes a wikilink to the tool. |
153 | 153 | $toolCounts = $user->getAutomatedCounts($projectData, $namespace, $start, $end); |
154 | - $toolsTotal = array_reduce($toolCounts, function ($a, $b) { |
|
155 | - return $a + $b['count']; |
|
154 | + $toolsTotal = array_reduce($toolCounts, function($a, $b) { |
|
155 | + return $a+$b['count']; |
|
156 | 156 | }); |
157 | 157 | |
158 | 158 | // Query to get combined (semi)automated using for all edits |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function onKernelController(FilterControllerEvent $event) |
58 | 58 | { |
59 | - $this->rateLimit = (int) $this->container->getParameter('app.rate_limit_count'); |
|
60 | - $this->rateDuration = (int) $this->container->getParameter('app.rate_limit_time'); |
|
59 | + $this->rateLimit = (int)$this->container->getParameter('app.rate_limit_count'); |
|
60 | + $this->rateDuration = (int)$this->container->getParameter('app.rate_limit_time'); |
|
61 | 61 | |
62 | 62 | // Zero values indicate the rate limiting feature should be disabled. |
63 | 63 | if ($this->rateLimit === 0 || $this->rateDuration === 0) { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | $controller = $event->getController(); |
68 | - $loggedIn = (bool) $this->container->get('session')->get('logged_in_user'); |
|
68 | + $loggedIn = (bool)$this->container->get('session')->get('logged_in_user'); |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Rate limiting will not apply to these actions |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $cacheItem = $cache->getItem($cacheKey); |
92 | 92 | |
93 | 93 | // If increment value already in cache, or start with 1. |
94 | - $count = $cacheItem->isHit() ? (int) $cacheItem->get() + 1 : 1; |
|
94 | + $count = $cacheItem->isHit() ? (int)$cacheItem->get()+1 : 1; |
|
95 | 95 | |
96 | 96 | // Check if limit has been exceeded, and if so, throw an error. |
97 | 97 | if ($count > $this->rateLimit) { |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | // Log the denied request |
144 | 144 | $logger = $this->container->get('monolog.logger.rate_limit'); |
145 | 145 | $logger->info( |
146 | - "<URI>: " . $request->getRequestUri() . |
|
147 | - ($logComment != '' ? "\t<Reason>: $logComment" : '') . |
|
148 | - "\t<User agent>: " . $request->headers->get('User-Agent') |
|
146 | + "<URI>: ".$request->getRequestUri(). |
|
147 | + ($logComment != '' ? "\t<Reason>: $logComment" : ''). |
|
148 | + "\t<User agent>: ".$request->headers->get('User-Agent') |
|
149 | 149 | ); |
150 | 150 | |
151 | - throw new AccessDeniedHttpException("Possible spider crawl detected. " . |
|
152 | - 'If you are human, you are making too many requests during a short period of time. ' . |
|
153 | - "Please wait $this->rateDuration minutes before reloading this tool. You can then " . |
|
151 | + throw new AccessDeniedHttpException("Possible spider crawl detected. ". |
|
152 | + 'If you are human, you are making too many requests during a short period of time. '. |
|
153 | + "Please wait $this->rateDuration minutes before reloading this tool. You can then ". |
|
154 | 154 | 'login to prevent this from happening again.'); |
155 | 155 | } |
156 | 156 | } |
@@ -8,7 +8,6 @@ |
||
8 | 8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9 | 9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | 10 | use Symfony\Component\HttpFoundation\Request; |
11 | -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
12 | 11 | use Xtools\ProjectRepository; |
13 | 12 | use Xtools\Page; |
14 | 13 | use Xtools\PagesRepository; |
@@ -166,7 +166,7 @@ |
||
166 | 166 | $neutral = $rfx->getSection('neutral'); |
167 | 167 | $dup = $rfx->getDuplicates(); |
168 | 168 | |
169 | - $total = count($support) + count($oppose) + count($neutral); |
|
169 | + $total = count($support)+count($oppose)+count($neutral); |
|
170 | 170 | |
171 | 171 | if ($total === 0) { |
172 | 172 | $this->addFlash('notice', ['no-result', $pagename]); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @Route("/rfx/{project}", name="rfxAnalysisProject") |
46 | 46 | * @Route("/rfx/{project}/{type}", name="rfxAnalysisProjectType") |
47 | 47 | * |
48 | - * @return Response|RedirectResponse |
|
48 | + * @return \Symfony\Component\HttpFoundation\Response |
|
49 | 49 | */ |
50 | 50 | public function indexAction(Request $request, $project = null, $type = null) |
51 | 51 | { |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @Route("/rfx/{project}/{type}/{username}", name="rfxAnalysisResult") |
113 | 113 | * |
114 | - * @return Response|RedirectResponse |
|
114 | + * @return \Symfony\Component\HttpFoundation\Response |
|
115 | 115 | * @codeCoverageIgnore |
116 | 116 | */ |
117 | 117 | public function resultAction($project, $type, $username) |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * Returns matches. |
36 | 36 | * |
37 | 37 | * @param string $input The line we're looking for |
38 | - * @param array $matches Pointer to an array where we stash results |
|
38 | + * @param string[] $matches Pointer to an array where we stash results |
|
39 | 39 | * |
40 | 40 | * @TODO: Make this cleaner |
41 | 41 | * |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - $final = []; // initialize the final array |
|
122 | + $final = []; // initialize the final array |
|
123 | 123 | $finalRaw = []; // Initialize the raw data array |
124 | 124 | |
125 | 125 | foreach ($this->data as $key => $value) { |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $final = array_count_values($final); // find repetition and its count |
134 | 134 | |
135 | - $final = array_diff($final, [1]); // remove single occurrences |
|
135 | + $final = array_diff($final, [1]); // remove single occurrences |
|
136 | 136 | |
137 | 137 | $this->duplicates = array_keys($final); |
138 | 138 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * Get the user's (system) edit count. |
97 | 97 | * @param string $databaseName The database to query. |
98 | 98 | * @param string $username The username to find. |
99 | - * @return int|null As returned by the database. |
|
99 | + * @return string|boolean As returned by the database. |
|
100 | 100 | */ |
101 | 101 | public function getEditCount($databaseName, $username) |
102 | 102 | { |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | * Get the combined regex and tags for all semi-automated tools, |
742 | 742 | * ready to be used in a query. |
743 | 743 | * @param string $projectDomain Such as en.wikipedia.org |
744 | - * @param $conn Doctrine\DBAL\Connection Used for proper escaping |
|
744 | + * @param \Doctrine\DBAL\Connection $conn Doctrine\DBAL\Connection Used for proper escaping |
|
745 | 745 | * @return string[] In the format: |
746 | 746 | * ['combined|regex', 'combined,tags'] |
747 | 747 | */ |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | $this->stopwatch->start($cacheKey, 'XTools'); |
126 | 126 | $api = $this->getMediawikiApi($project); |
127 | - $params = [ "list"=>"users", "ususers"=>$username, "usprop"=>"groups" ]; |
|
127 | + $params = ["list"=>"users", "ususers"=>$username, "usprop"=>"groups"]; |
|
128 | 128 | $query = new SimpleRequest('query', $params); |
129 | 129 | $result = []; |
130 | 130 | $res = $api->getRequest($query); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | |
160 | 160 | // Create the API query. |
161 | 161 | $api = $this->getMediawikiApi($project); |
162 | - $params = [ "meta"=>"globaluserinfo", "guiuser"=>$username, "guiprop"=>"groups" ]; |
|
162 | + $params = ["meta"=>"globaluserinfo", "guiuser"=>$username, "guiprop"=>"groups"]; |
|
163 | 163 | $query = new SimpleRequest('query', $params); |
164 | 164 | |
165 | 165 | // Get the result. |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | { |
204 | 204 | $username = $user->getUsername(); |
205 | 205 | |
206 | - $cacheKey = 'pages.' . $project->getDatabaseName() . '.' |
|
207 | - . $user->getCacheKey() . '.' . $namespace . '.' . $redirects; |
|
206 | + $cacheKey = 'pages.'.$project->getDatabaseName().'.' |
|
207 | + . $user->getCacheKey().'.'.$namespace.'.'.$redirects; |
|
208 | 208 | if ($this->cache->hasItem($cacheKey)) { |
209 | 209 | return $this->cache->getItem($cacheKey)->get(); |
210 | 210 | } |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | FROM $pageTable |
263 | 263 | JOIN $revisionTable ON page_id = rev_page |
264 | 264 | $paJoin |
265 | - WHERE $whereRev AND rev_parent_id = '0' $namespaceConditionRev $redirectCondition" . |
|
266 | - ($hasPageAssessments ? 'GROUP BY rev_page' : '') . " |
|
265 | + WHERE $whereRev AND rev_parent_id = '0' $namespaceConditionRev $redirectCondition". |
|
266 | + ($hasPageAssessments ? 'GROUP BY rev_page' : '')." |
|
267 | 267 | ) |
268 | 268 | |
269 | 269 | UNION |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | */ |
306 | 306 | public function countEdits(Project $project, User $user, $namespace = 'all', $start = '', $end = '') |
307 | 307 | { |
308 | - $cacheKey = 'editcount.' . $project->getDatabaseName() . '.' |
|
309 | - . $user->getCacheKey() . '.' . $namespace; |
|
308 | + $cacheKey = 'editcount.'.$project->getDatabaseName().'.' |
|
309 | + . $user->getCacheKey().'.'.$namespace; |
|
310 | 310 | |
311 | 311 | $condBegin = ''; |
312 | 312 | $condEnd = ''; |
313 | 313 | |
314 | 314 | if (!empty($start)) { |
315 | - $cacheKey .= '.' . $start; |
|
315 | + $cacheKey .= '.'.$start; |
|
316 | 316 | |
317 | 317 | // For the query |
318 | 318 | $start = date('Ymd000000', strtotime($start)); |
319 | 319 | $condBegin = 'AND rev_timestamp >= :start '; |
320 | 320 | } |
321 | 321 | if (!empty($end)) { |
322 | - $cacheKey .= '.' . $end; |
|
322 | + $cacheKey .= '.'.$end; |
|
323 | 323 | |
324 | 324 | // For the query |
325 | 325 | $end = date('Ymd235959', strtotime($end)); |
@@ -379,21 +379,21 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function countAutomatedEdits(Project $project, User $user, $namespace = 'all', $start = '', $end = '') |
381 | 381 | { |
382 | - $cacheKey = 'autoeditcount.' . $project->getDatabaseName() . '.' |
|
383 | - . $user->getCacheKey() . '.' . $namespace; |
|
382 | + $cacheKey = 'autoeditcount.'.$project->getDatabaseName().'.' |
|
383 | + . $user->getCacheKey().'.'.$namespace; |
|
384 | 384 | |
385 | 385 | $condBegin = ''; |
386 | 386 | $condEnd = ''; |
387 | 387 | |
388 | 388 | if (!empty($start)) { |
389 | - $cacheKey .= '.' . $start; |
|
389 | + $cacheKey .= '.'.$start; |
|
390 | 390 | |
391 | 391 | // For the query |
392 | 392 | $start = date('Ymd000000', strtotime($start)); |
393 | 393 | $condBegin = 'AND rev_timestamp >= :start '; |
394 | 394 | } |
395 | 395 | if (!empty($end)) { |
396 | - $cacheKey .= '.' . $end; |
|
396 | + $cacheKey .= '.'.$end; |
|
397 | 397 | |
398 | 398 | // For the query |
399 | 399 | $end = date('Ymd235959', strtotime($end)); |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | $tagJoin = $tags != '' ? "LEFT OUTER JOIN $tagTable ON ct_rev_id = rev_id" : ''; |
426 | 426 | $condTools[] = "ct_tag IN ($tags)"; |
427 | 427 | } |
428 | - $condTool = 'AND (' . implode(' OR ', $condTools) . ')'; |
|
428 | + $condTool = 'AND ('.implode(' OR ', $condTools).')'; |
|
429 | 429 | |
430 | 430 | $sql = "SELECT COUNT(DISTINCT(rev_id)) |
431 | 431 | FROM $revisionTable |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | $resultQuery->bindParam('namespace', $namespace); |
451 | 451 | } |
452 | 452 | $resultQuery->execute(); |
453 | - $result = (int) $resultQuery->fetchColumn(); |
|
453 | + $result = (int)$resultQuery->fetchColumn(); |
|
454 | 454 | |
455 | 455 | // Cache for 10 minutes, and return. |
456 | 456 | $cacheItem = $this->cache->getItem($cacheKey) |
@@ -482,21 +482,21 @@ discard block |
||
482 | 482 | $end = '', |
483 | 483 | $offset = 0 |
484 | 484 | ) { |
485 | - $cacheKey = 'nonautoedits.' . $project->getDatabaseName() . '.' |
|
486 | - . $user->getCacheKey() . '.' . $namespace . '.' . $offset; |
|
485 | + $cacheKey = 'nonautoedits.'.$project->getDatabaseName().'.' |
|
486 | + . $user->getCacheKey().'.'.$namespace.'.'.$offset; |
|
487 | 487 | |
488 | 488 | $condBegin = ''; |
489 | 489 | $condEnd = ''; |
490 | 490 | |
491 | 491 | if (!empty($start)) { |
492 | - $cacheKey .= '.' . $start; |
|
492 | + $cacheKey .= '.'.$start; |
|
493 | 493 | |
494 | 494 | // For the query |
495 | 495 | $start = date('Ymd000000', strtotime($start)); |
496 | 496 | $condBegin = 'AND revs.rev_timestamp >= :start '; |
497 | 497 | } |
498 | 498 | if (!empty($end)) { |
499 | - $cacheKey .= '.' . $end; |
|
499 | + $cacheKey .= '.'.$end; |
|
500 | 500 | |
501 | 501 | // For the query |
502 | 502 | $end = date('Ymd235959', strtotime($end)); |
@@ -589,21 +589,21 @@ discard block |
||
589 | 589 | $start = '', |
590 | 590 | $end = '' |
591 | 591 | ) { |
592 | - $cacheKey = 'autotoolcounts.' . $project->getDatabaseName() . '.' |
|
593 | - . $user->getCacheKey() . '.' . $namespace; |
|
592 | + $cacheKey = 'autotoolcounts.'.$project->getDatabaseName().'.' |
|
593 | + . $user->getCacheKey().'.'.$namespace; |
|
594 | 594 | |
595 | 595 | $condBegin = ''; |
596 | 596 | $condEnd = ''; |
597 | 597 | |
598 | 598 | if (!empty($start)) { |
599 | - $cacheKey .= '.' . $start; |
|
599 | + $cacheKey .= '.'.$start; |
|
600 | 600 | |
601 | 601 | // For the query |
602 | 602 | $start = date('Ymd000000', strtotime($start)); |
603 | 603 | $condBegin = 'AND rev_timestamp >= :start '; |
604 | 604 | } |
605 | 605 | if (!empty($end)) { |
606 | - $cacheKey .= '.' . $end; |
|
606 | + $cacheKey .= '.'.$end; |
|
607 | 607 | |
608 | 608 | // For the query |
609 | 609 | $end = date('Ymd235959', strtotime($end)); |
@@ -650,13 +650,13 @@ discard block |
||
650 | 650 | if ($condTool === '') { |
651 | 651 | $condTool = "ct_tag = $tag"; |
652 | 652 | } else { |
653 | - $condTool = '(' . $condTool . " OR ct_tag = $tag)"; |
|
653 | + $condTool = '('.$condTool." OR ct_tag = $tag)"; |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | 657 | // Developer error, no regex or tag provided for this tool. |
658 | 658 | if ($condTool === '') { |
659 | - throw new Exception("No regex or tag found for the tool $toolname. " . |
|
659 | + throw new Exception("No regex or tag found for the tool $toolname. ". |
|
660 | 660 | "Please verify this entry in semi_automated.yml"); |
661 | 661 | } |
662 | 662 | |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | } |
709 | 709 | |
710 | 710 | // Sort the array by count |
711 | - uasort($results, function ($a, $b) { |
|
712 | - return $b['count'] - $a['count']; |
|
711 | + uasort($results, function($a, $b) { |
|
712 | + return $b['count']-$a['count']; |
|
713 | 713 | }); |
714 | 714 | |
715 | 715 | // Cache for 10 minutes, and return. |