|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use App\Model\Authorship; |
|
8
|
|
|
use App\Model\Blame; |
|
9
|
|
|
use App\Repository\BlameRepository; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This controller provides the search form and results page for the Blame tool. |
|
15
|
|
|
* @codeCoverageIgnore |
|
16
|
|
|
*/ |
|
17
|
|
|
class BlameController extends XtoolsController |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Get the name of the tool's index route. This is also the name of the associated model. |
|
21
|
|
|
* @return string |
|
22
|
|
|
* @codeCoverageIgnore |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getIndexRoute(): string |
|
25
|
|
|
{ |
|
26
|
|
|
return 'Blame'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @inheritDoc |
|
31
|
|
|
*/ |
|
32
|
|
|
public function supportedProjects(): array |
|
33
|
|
|
{ |
|
34
|
|
|
return Authorship::SUPPORTED_PROJECTS; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The search form. |
|
39
|
|
|
* @Route("/blame", name="Blame") |
|
40
|
|
|
* @Route("/blame/{project}", name="BlameProject") |
|
41
|
|
|
* @return Response |
|
42
|
|
|
*/ |
|
43
|
|
|
public function indexAction(): Response |
|
44
|
|
|
{ |
|
45
|
|
|
$this->params['target'] = $this->request->query->get('target', ''); |
|
46
|
|
|
|
|
47
|
|
|
if (isset($this->params['project']) && isset($this->params['page']) && isset($this->params['q'])) { |
|
48
|
|
|
return $this->redirectToRoute('BlameResult', $this->params); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (preg_match('/\d{4}-\d{2}-\d{2}/', $this->params['target'])) { |
|
52
|
|
|
$show = 'date'; |
|
53
|
|
|
} elseif (is_numeric($this->params['target'])) { |
|
54
|
|
|
$show = 'id'; |
|
55
|
|
|
} else { |
|
56
|
|
|
$show = 'latest'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $this->render('blame/index.html.twig', array_merge([ |
|
60
|
|
|
'xtPage' => 'Blame', |
|
61
|
|
|
'xtPageTitle' => 'tool-blame', |
|
62
|
|
|
'xtSubtitle' => 'tool-blame-desc', |
|
63
|
|
|
|
|
64
|
|
|
// Defaults that will get overridden if in $params. |
|
65
|
|
|
'page' => '', |
|
66
|
|
|
'supportedProjects' => Authorship::SUPPORTED_PROJECTS, |
|
67
|
|
|
], $this->params, [ |
|
68
|
|
|
'project' => $this->project, |
|
69
|
|
|
'show' => $show, |
|
70
|
|
|
'target' => '', |
|
71
|
|
|
])); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @Route( |
|
76
|
|
|
* "/blame/{project}/{page}/{target}", |
|
77
|
|
|
* name="BlameResult", |
|
78
|
|
|
* requirements={ |
|
79
|
|
|
* "page"="(.+?)", |
|
80
|
|
|
* "target"="|latest|\d+|\d{4}-\d{2}-\d{2}", |
|
81
|
|
|
* }, |
|
82
|
|
|
* defaults={"target"="latest"} |
|
83
|
|
|
* ) |
|
84
|
|
|
* @param string $target |
|
85
|
|
|
* @param BlameRepository $blameRepo |
|
86
|
|
|
* @return Response |
|
87
|
|
|
*/ |
|
88
|
|
|
public function resultAction(string $target, BlameRepository $blameRepo): Response |
|
89
|
|
|
{ |
|
90
|
|
|
if (!isset($this->params['q'])) { |
|
91
|
|
|
return $this->redirectToRoute('BlameProject', [ |
|
92
|
|
|
'project' => $this->project->getDomain(), |
|
93
|
|
|
]); |
|
94
|
|
|
} |
|
95
|
|
|
if (0 !== $this->page->getNamespace()) { |
|
|
|
|
|
|
96
|
|
|
$this->addFlashMessage('danger', 'error-authorship-non-mainspace'); |
|
97
|
|
|
return $this->redirectToRoute('BlameProject', [ |
|
98
|
|
|
'project' => $this->project->getDomain(), |
|
99
|
|
|
]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// This action sometimes requires more memory. 256M should be safe. |
|
103
|
|
|
ini_set('memory_limit', '256M'); |
|
104
|
|
|
|
|
105
|
|
|
$blame = new Blame($blameRepo, $this->page, $this->params['q'], $target); |
|
|
|
|
|
|
106
|
|
|
$blame->setRepository($blameRepo); |
|
107
|
|
|
$blame->prepareData(); |
|
108
|
|
|
|
|
109
|
|
|
return $this->getFormattedResponse('blame/blame', [ |
|
110
|
|
|
'xtPage' => 'Blame', |
|
111
|
|
|
'xtTitle' => $this->page->getTitle(), |
|
112
|
|
|
'blame' => $blame, |
|
113
|
|
|
]); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.