|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains only the SimpleEditCounterController class. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
declare(strict_types=1); |
|
7
|
|
|
|
|
8
|
|
|
namespace AppBundle\Controller; |
|
9
|
|
|
|
|
10
|
|
|
use AppBundle\Model\SimpleEditCounter; |
|
11
|
|
|
use AppBundle\Repository\SimpleEditCounterRepository; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* This controller handles the Simple Edit Counter tool. |
|
17
|
|
|
*/ |
|
18
|
|
|
class SimpleEditCounterController extends XtoolsController |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get the name of the tool's index route. |
|
23
|
|
|
* This is also the name of the associated model. |
|
24
|
|
|
* @return string |
|
25
|
|
|
* @codeCoverageIgnore |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getIndexRoute(): string |
|
28
|
|
|
{ |
|
29
|
|
|
return 'SimpleEditCounter'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The Simple Edit Counter search form. |
|
34
|
|
|
* @Route("/sc", name="SimpleEditCounter") |
|
35
|
|
|
* @Route("/sc/index.php", name="SimpleEditCounterIndexPhp") |
|
36
|
|
|
* @Route("/sc/{project}", name="SimpleEditCounterProject") |
|
37
|
|
|
* @return Response |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function indexAction(): Response |
|
40
|
|
|
{ |
|
41
|
|
|
// Redirect if project and username are given. |
|
42
|
1 |
|
if (isset($this->params['project']) && isset($this->params['username'])) { |
|
43
|
|
|
return $this->redirectToRoute('SimpleEditCounterResult', $this->params); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Show the form. |
|
47
|
1 |
|
return $this->render('simpleEditCounter/index.html.twig', array_merge([ |
|
48
|
1 |
|
'xtPageTitle' => 'tool-simpleeditcounter', |
|
49
|
1 |
|
'xtSubtitle' => 'tool-simpleeditcounter-desc', |
|
50
|
1 |
|
'xtPage' => 'SimpleEditCounter', |
|
51
|
1 |
|
'project' => $this->project, |
|
52
|
|
|
|
|
53
|
|
|
// Defaults that will get overridden if in $params. |
|
54
|
1 |
|
'namespace' => 'all', |
|
55
|
1 |
|
'start' => '', |
|
56
|
1 |
|
'end' => '', |
|
57
|
1 |
|
], $this->params, ['project' => $this->project])); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function prepareSimpleEditCounter(): SimpleEditCounter |
|
61
|
|
|
{ |
|
62
|
|
|
$sec = new SimpleEditCounter( |
|
63
|
|
|
$this->project, |
|
64
|
|
|
$this->user, |
|
65
|
|
|
$this->namespace, |
|
66
|
|
|
$this->start, |
|
67
|
|
|
$this->end |
|
68
|
|
|
); |
|
69
|
|
|
$secRepo = new SimpleEditCounterRepository(); |
|
70
|
|
|
$secRepo->setContainer($this->container); |
|
71
|
|
|
$sec->setRepository($secRepo); |
|
72
|
|
|
$sec->prepareData(); |
|
73
|
|
|
|
|
74
|
|
|
if ($sec->isLimited()) { |
|
75
|
|
|
$this->addFlash('warning', $this->i18n->msg('simple-counter-limited-results')); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $sec; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Display the results. |
|
83
|
|
|
* @Route( |
|
84
|
|
|
* "/sc/{project}/{username}/{namespace}/{start}/{end}", |
|
85
|
|
|
* name="SimpleEditCounterResult", |
|
86
|
|
|
* requirements={ |
|
87
|
|
|
* "start" = "|\d{4}-\d{2}-\d{2}", |
|
88
|
|
|
* "end" = "|\d{4}-\d{2}-\d{2}", |
|
89
|
|
|
* "namespace" = "|all|\d+", |
|
90
|
|
|
* }, |
|
91
|
|
|
* defaults={ |
|
92
|
|
|
* "start"=false, |
|
93
|
|
|
* "end"=false, |
|
94
|
|
|
* "namespace"="all", |
|
95
|
|
|
* } |
|
96
|
|
|
* ) |
|
97
|
|
|
* @return Response |
|
98
|
|
|
* @codeCoverageIgnore |
|
99
|
|
|
*/ |
|
100
|
|
|
public function resultAction(): Response |
|
101
|
|
|
{ |
|
102
|
|
|
$sec = $this->prepareSimpleEditCounter(); |
|
103
|
|
|
|
|
104
|
|
|
return $this->getFormattedResponse('simpleEditCounter/result', [ |
|
105
|
|
|
'xtPage' => 'SimpleEditCounter', |
|
106
|
|
|
'xtTitle' => $this->user->getUsername(), |
|
107
|
|
|
'sec' => $sec, |
|
108
|
|
|
]); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/************************ API endpoints ************************/ |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* API endpoint for the Simple Edit Counter. |
|
115
|
|
|
* @Route( |
|
116
|
|
|
* "/api/user/simple_editcount/{project}/{username}/{namespace}/{start}/{end}", |
|
117
|
|
|
* name="SimpleEditCounterApi", |
|
118
|
|
|
* requirements={ |
|
119
|
|
|
* "username" = "(.+?)(?!(?:\/(\d+))?\/(?:\d{4}-\d{2}-\d{2})(?:\/(\d{4}-\d{2}-\d{2}))?)?$", |
|
120
|
|
|
* "start" = "|\d{4}-\d{2}-\d{2}", |
|
121
|
|
|
* "end" = "|\d{4}-\d{2}-\d{2}", |
|
122
|
|
|
* "namespace" = "|all|\d+" |
|
123
|
|
|
* }, |
|
124
|
|
|
* defaults={ |
|
125
|
|
|
* "start"=false, |
|
126
|
|
|
* "end"=false, |
|
127
|
|
|
* "namespace"="all", |
|
128
|
|
|
* } |
|
129
|
|
|
* ) |
|
130
|
|
|
* @return Response |
|
131
|
|
|
* @codeCoverageIgnore |
|
132
|
|
|
*/ |
|
133
|
|
|
public function simpleEditCounterApiAction(): Response |
|
134
|
|
|
{ |
|
135
|
|
|
$sec = $this->prepareSimpleEditCounter(); |
|
136
|
|
|
return $this->getFormattedApiResponse($sec->getData()); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|