@@ -5,21 +5,15 @@ |
||
| 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; |
| 17 | 14 | use Xtools\ProjectRepository; |
| 18 | 15 | use Xtools\UserRepository; |
| 19 | -use Xtools\Page; |
|
| 20 | -use Xtools\PagesRepository; |
|
| 21 | 16 | use Xtools\Edit; |
| 22 | -use DateTime; |
|
| 23 | 17 | |
| 24 | 18 | /** |
| 25 | 19 | * Serves the external API of XTools. |
@@ -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']; |
@@ -187,7 +187,7 @@ |
||
| 187 | 187 | * @param Request $request The HTTP request. |
| 188 | 188 | * @param string $project |
| 189 | 189 | * @param string $article |
| 190 | - * @return View |
|
| 190 | + * @return Response |
|
| 191 | 191 | */ |
| 192 | 192 | public function articleInfo(Request $request, $project, $article) |
| 193 | 193 | { |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | $rendered = str_replace('"', '\"', trim($rendered)); |
| 86 | 86 | |
| 87 | 87 | // Uglify temporary file. |
| 88 | - $tmpFile = sys_get_temp_dir() . '/xtools_articleinfo_gadget.js'; |
|
| 88 | + $tmpFile = sys_get_temp_dir().'/xtools_articleinfo_gadget.js'; |
|
| 89 | 89 | $script = "echo \"$rendered\" | tee $tmpFile >/dev/null && "; |
| 90 | - $script .= $this->get('kernel')->getRootDir() . |
|
| 91 | - "/Resources/node_modules/uglify-es/bin/uglifyjs $tmpFile --mangle " . |
|
| 90 | + $script .= $this->get('kernel')->getRootDir(). |
|
| 91 | + "/Resources/node_modules/uglify-es/bin/uglifyjs $tmpFile --mangle ". |
|
| 92 | 92 | "&& rm $tmpFile >/dev/null"; |
| 93 | 93 | $process = new Process($script); |
| 94 | 94 | $process->run(); |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | $rendered = str_replace('\"', '"', trim($rendered)); |
| 108 | 108 | |
| 109 | 109 | // Add comment after uglifying since it removes comments. |
| 110 | - $rendered = "/**\n * This code was automatically generated and should not " . |
|
| 111 | - "be manually edited.\n * For updates, please copy and paste from " . |
|
| 112 | - $this->generateUrl('ArticleInfoGadget', ['uglify' => 1], UrlGeneratorInterface::ABSOLUTE_URL) . |
|
| 113 | - "\n * Released under GPL v3 license.\n */\n" . $rendered; |
|
| 110 | + $rendered = "/**\n * This code was automatically generated and should not ". |
|
| 111 | + "be manually edited.\n * For updates, please copy and paste from ". |
|
| 112 | + $this->generateUrl('ArticleInfoGadget', ['uglify' => 1], UrlGeneratorInterface::ABSOLUTE_URL). |
|
| 113 | + "\n * Released under GPL v3 license.\n */\n".$rendered; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | $response = new \Symfony\Component\HttpFoundation\Response($rendered); |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | $info = $page->getBasicEditingInfo(); |
| 214 | 214 | $creationDateTime = DateTime::createFromFormat('YmdHis', $info['created_at']); |
| 215 | 215 | $modifiedDateTime = DateTime::createFromFormat('YmdHis', $info['modified_at']); |
| 216 | - $secsSinceLastEdit = (new DateTime)->getTimestamp() - $modifiedDateTime->getTimestamp(); |
|
| 216 | + $secsSinceLastEdit = (new DateTime)->getTimestamp()-$modifiedDateTime->getTimestamp(); |
|
| 217 | 217 | |
| 218 | 218 | $data = [ |
| 219 | - 'revisions' => (int) $info['num_edits'], |
|
| 220 | - 'editors' => (int) $info['num_editors'], |
|
| 219 | + 'revisions' => (int)$info['num_edits'], |
|
| 220 | + 'editors' => (int)$info['num_editors'], |
|
| 221 | 221 | 'author' => $info['author'], |
| 222 | - 'author_editcount' => (int) $info['author_editcount'], |
|
| 222 | + 'author_editcount' => (int)$info['author_editcount'], |
|
| 223 | 223 | 'created_at' => $creationDateTime->format('Y-m-d'), |
| 224 | 224 | 'created_rev_id' => $info['created_rev_id'], |
| 225 | 225 | 'modified_at' => $modifiedDateTime->format('Y-m-d H:i'), |
| 226 | 226 | 'secs_since_last_edit' => $secsSinceLastEdit, |
| 227 | - 'last_edit_id' => (int) $info['modified_rev_id'], |
|
| 228 | - 'watchers' => (int) $page->getWatchers(), |
|
| 227 | + 'last_edit_id' => (int)$info['modified_rev_id'], |
|
| 228 | + 'watchers' => (int)$page->getWatchers(), |
|
| 229 | 229 | 'pageviews' => $page->getLastPageviews($pageviewsOffset), |
| 230 | 230 | 'pageviews_offset' => $pageviewsOffset, |
| 231 | 231 | ]; |
@@ -8,15 +8,12 @@ |
||
| 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\DependencyInjection\ContainerInterface; |
|
| 12 | 11 | use Symfony\Component\HttpFoundation\Response; |
| 13 | 12 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 14 | 13 | use Symfony\Component\HttpFoundation\RedirectResponse; |
| 15 | 14 | use Symfony\Component\Process\Process; |
| 16 | 15 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
| 17 | 16 | use Xtools\ProjectRepository; |
| 18 | -use Xtools\Page; |
|
| 19 | -use Xtools\PagesRepository; |
|
| 20 | 17 | use Xtools\ArticleInfo; |
| 21 | 18 | use DateTime; |
| 22 | 19 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | // supply as the OFFSET. |
| 149 | 149 | $limitClause = ''; |
| 150 | 150 | if (intval($limit) > 0 && isset($numRevisions)) { |
| 151 | - $offset = $numRevisions - $limit; |
|
| 151 | + $offset = $numRevisions-$limit; |
|
| 152 | 152 | $limitClause = "LIMIT $offset, $limit"; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $time2 = time(); |
| 265 | 265 | |
| 266 | 266 | // If it took over 5 seconds, cache the result for 20 minutes. |
| 267 | - if ($time2 - $time1 > 5) { |
|
| 267 | + if ($time2-$time1 > 5) { |
|
| 268 | 268 | $cacheItem = $this->cache->getItem($cacheKey) |
| 269 | 269 | ->set($result) |
| 270 | 270 | ->expiresAfter(new DateInterval('PT20M')); |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | |
| 400 | 400 | $wikidataId = ltrim($page->getWikidataId(), 'Q'); |
| 401 | 401 | |
| 402 | - $sql = "SELECT " . ($count ? 'COUNT(*) AS count' : '*') . " |
|
| 402 | + $sql = "SELECT ".($count ? 'COUNT(*) AS count' : '*')." |
|
| 403 | 403 | FROM wikidatawiki_p.wb_items_per_site |
| 404 | 404 | WHERE ips_item_id = :wikidataId"; |
| 405 | 405 | |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | |
| 410 | 410 | $result = $resultQuery->fetchAll(); |
| 411 | 411 | |
| 412 | - return $count ? (int) $result[0]['count'] : $result; |
|
| 412 | + return $count ? (int)$result[0]['count'] : $result; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | // Transform to associative array by 'type' |
| 451 | 451 | foreach ($res as $row) { |
| 452 | - $data[$row['type'] . '_count'] = $row['value']; |
|
| 452 | + $data[$row['type'].'_count'] = $row['value']; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | return $data; |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | $project = $page->getProject()->getDomain(); |
| 489 | 489 | |
| 490 | - $url = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/' . |
|
| 490 | + $url = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/'. |
|
| 491 | 491 | "$project/all-access/user/$title/daily/$start/$end"; |
| 492 | 492 | |
| 493 | 493 | $res = $client->request('GET', $url); |