|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains only the SimpleEditCounterController class. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace AppBundle\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
13
|
|
|
use Xtools\SimpleEditCounter; |
|
14
|
|
|
use Xtools\SimpleEditCounterRepository; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This controller handles the Simple Edit Counter tool. |
|
18
|
|
|
*/ |
|
19
|
|
|
class SimpleEditCounterController extends XtoolsController |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Get the name of the tool's index route. |
|
24
|
|
|
* This is also the name of the associated model. |
|
25
|
|
|
* @return string |
|
26
|
|
|
* @codeCoverageIgnore |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getIndexRoute() |
|
29
|
|
|
{ |
|
30
|
|
|
return 'SimpleEditCounter'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* SimpleEditCounterController constructor. |
|
35
|
|
|
* @param RequestStack $requestStack |
|
36
|
|
|
* @param ContainerInterface $container |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function __construct(RequestStack $requestStack, ContainerInterface $container) |
|
39
|
|
|
{ |
|
40
|
2 |
|
$this->tooHighEditCountAction = $this->getIndexRoute(); |
|
41
|
2 |
|
$this->tooHighEditCountActionBlacklist = ['index', 'result']; |
|
42
|
|
|
|
|
43
|
2 |
|
parent::__construct($requestStack, $container); |
|
44
|
2 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The Simple Edit Counter search form. |
|
48
|
|
|
* @Route("/sc", name="SimpleEditCounter") |
|
49
|
|
|
* @Route("/sc/", name="SimpleEditCounterSlash") |
|
50
|
|
|
* @Route("/sc/index.php", name="SimpleEditCounterIndexPhp") |
|
51
|
|
|
* @Route("/sc/{project}", name="SimpleEditCounterProject") |
|
52
|
|
|
* @return Response |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function indexAction() |
|
55
|
|
|
{ |
|
56
|
|
|
// Redirect if project and username are given. |
|
57
|
1 |
|
if (isset($this->params['project']) && isset($this->params['username'])) { |
|
58
|
|
|
return $this->redirectToRoute('SimpleEditCounterResult', $this->params); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// Show the form. |
|
62
|
1 |
|
return $this->render('simpleEditCounter/index.html.twig', array_merge([ |
|
63
|
1 |
|
'xtPageTitle' => 'tool-simpleeditcounter', |
|
64
|
1 |
|
'xtSubtitle' => 'tool-simpleeditcounter-desc', |
|
65
|
1 |
|
'xtPage' => 'simpleeditcounter', |
|
66
|
1 |
|
'project' => $this->project, |
|
67
|
|
|
|
|
68
|
|
|
// Defaults that will get overriden if in $params. |
|
69
|
1 |
|
'namespace' => 'all', |
|
70
|
1 |
|
'start' => '', |
|
71
|
1 |
|
'end' => '', |
|
72
|
1 |
|
], $this->params)); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Display the |
|
77
|
|
|
* @Route( |
|
78
|
|
|
* "/sc/{project}/{username}/{namespace}/{start}/{end}", |
|
79
|
|
|
* name="SimpleEditCounterResult", |
|
80
|
|
|
* requirements={ |
|
81
|
|
|
* "start" = "|\d{4}-\d{2}-\d{2}", |
|
82
|
|
|
* "end" = "|\d{4}-\d{2}-\d{2}", |
|
83
|
|
|
* "namespace" = "|all|\d+", |
|
84
|
|
|
* }, |
|
85
|
|
|
* defaults={ |
|
86
|
|
|
* "start"=false, |
|
87
|
|
|
* "end"=false, |
|
88
|
|
|
* } |
|
89
|
|
|
* ) |
|
90
|
|
|
* @param int|string $namespace Namespace ID or 'all' for all namespaces. |
|
91
|
|
|
* @return Response |
|
92
|
|
|
* @codeCoverageIgnore |
|
93
|
|
|
*/ |
|
94
|
|
|
public function resultAction($namespace = 'all') |
|
95
|
|
|
{ |
|
96
|
|
|
$sec = new SimpleEditCounter( |
|
97
|
|
|
$this->container, |
|
98
|
|
|
$this->project, |
|
99
|
|
|
$this->user, |
|
100
|
|
|
$namespace, |
|
101
|
|
|
$this->start, |
|
102
|
|
|
$this->end |
|
103
|
|
|
); |
|
104
|
|
|
$secRepo = new SimpleEditCounterRepository(); |
|
105
|
|
|
$secRepo->setContainer($this->container); |
|
106
|
|
|
$sec->setRepository($secRepo); |
|
107
|
|
|
$sec->prepareData(); |
|
108
|
|
|
|
|
109
|
|
|
// Assign the values and display the template |
|
110
|
|
|
return $this->render('simpleEditCounter/result.html.twig', [ |
|
111
|
|
|
'xtPage' => 'simpleeditcounter', |
|
112
|
|
|
'xtTitle' => $this->user->getUsername(), |
|
113
|
|
|
'user' => $this->user, |
|
114
|
|
|
'project' => $this->project, |
|
115
|
|
|
'sec' => $sec, |
|
116
|
|
|
]); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/************************ API endpoints ************************/ |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* API endpoint for the Simple Edit Counter. |
|
123
|
|
|
* @Route( |
|
124
|
|
|
* "/api/user/simple_editcount/{project}/{username}/{namespace}/{start}/{end}", |
|
125
|
|
|
* name="SimpleEditCounterApi", |
|
126
|
|
|
* requirements={ |
|
127
|
|
|
* "username" = "(.+?)(?!(?:\/(\d+))?\/(?:\d{4}-\d{2}-\d{2})(?:\/(\d{4}-\d{2}-\d{2}))?)?$", |
|
128
|
|
|
* "start" = "|\d{4}-\d{2}-\d{2}", |
|
129
|
|
|
* "end" = "|\d{4}-\d{2}-\d{2}", |
|
130
|
|
|
* "namespace" = "|all|\d+" |
|
131
|
|
|
* }, |
|
132
|
|
|
* defaults={ |
|
133
|
|
|
* "start"=false, |
|
134
|
|
|
* "end"=false, |
|
135
|
|
|
* } |
|
136
|
|
|
* ) |
|
137
|
|
|
* @param int|string $namespace Namespace ID or 'all' for all namespaces. |
|
138
|
|
|
* @return Response |
|
139
|
|
|
* @codeCoverageIgnore |
|
140
|
|
|
*/ |
|
141
|
|
|
public function simpleEditCounterApiAction($namespace = 'all') |
|
142
|
|
|
{ |
|
143
|
|
|
$this->recordApiUsage('user/simple_editcount'); |
|
144
|
|
|
|
|
145
|
|
|
$sec = new SimpleEditCounter( |
|
146
|
|
|
$this->container, |
|
147
|
|
|
$this->project, |
|
148
|
|
|
$this->user, |
|
149
|
|
|
$namespace, |
|
150
|
|
|
$this->start, |
|
151
|
|
|
$this->end |
|
152
|
|
|
); |
|
153
|
|
|
$secRepo = new SimpleEditCounterRepository(); |
|
154
|
|
|
$secRepo->setContainer($this->container); |
|
155
|
|
|
$sec->setRepository($secRepo); |
|
156
|
|
|
$sec->prepareData(); |
|
157
|
|
|
|
|
158
|
|
|
$ret = [ |
|
159
|
|
|
'username' => $this->user->getUsername(), |
|
160
|
|
|
]; |
|
161
|
|
|
|
|
162
|
|
|
if ($namespace !== 'all') { |
|
163
|
|
|
$ret['namespace'] = $namespace; |
|
164
|
|
|
} |
|
165
|
|
|
if ($this->start !== false) { |
|
166
|
|
|
$ret['start'] = date('Y-m-d', $this->start); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
if ($this->end !== false) { |
|
169
|
|
|
$ret['end'] = date('Y-m-d', $this->end); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$ret = array_merge($ret, $sec->getData()); |
|
173
|
|
|
|
|
174
|
|
|
$response = new JsonResponse(); |
|
175
|
|
|
$response->setEncodingOptions(JSON_NUMERIC_CHECK); |
|
176
|
|
|
$response->setData($ret); |
|
177
|
|
|
return $response; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|