|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use App\Model\EditSummary; |
|
8
|
|
|
use App\Repository\EditSummaryRepository; |
|
9
|
|
|
use OpenApi\Annotations as OA; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* This controller handles the Simple Edit Counter tool. |
|
16
|
|
|
*/ |
|
17
|
|
|
class EditSummaryController extends XtoolsController |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @inheritDoc |
|
21
|
|
|
* @codeCoverageIgnore |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getIndexRoute(): string |
|
24
|
|
|
{ |
|
25
|
|
|
return 'EditSummary'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The Edit Summary search form. |
|
30
|
|
|
* @Route("/editsummary", name="EditSummary") |
|
31
|
|
|
* @Route("/editsummary/index.php", name="EditSummaryIndexPhp") |
|
32
|
|
|
* @Route("/editsummary/{project}", name="EditSummaryProject") |
|
33
|
|
|
* @return Response |
|
34
|
|
|
*/ |
|
35
|
|
|
public function indexAction(): Response |
|
36
|
|
|
{ |
|
37
|
|
|
// If we've got a project, user, and namespace, redirect to results. |
|
38
|
|
|
if (isset($this->params['project']) && isset($this->params['username'])) { |
|
39
|
|
|
return $this->redirectToRoute('EditSummaryResult', $this->params); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// Show the form. |
|
43
|
|
|
return $this->render('editSummary/index.html.twig', array_merge([ |
|
44
|
|
|
'xtPageTitle' => 'tool-editsummary', |
|
45
|
|
|
'xtSubtitle' => 'tool-editsummary-desc', |
|
46
|
|
|
'xtPage' => 'EditSummary', |
|
47
|
|
|
|
|
48
|
|
|
// Defaults that will get overridden if in $params. |
|
49
|
|
|
'username' => '', |
|
50
|
|
|
'namespace' => 0, |
|
51
|
|
|
'start' => '', |
|
52
|
|
|
'end' => '', |
|
53
|
|
|
], $this->params, ['project' => $this->project])); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Display the Edit Summary results |
|
58
|
|
|
* @Route( |
|
59
|
|
|
* "/editsummary/{project}/{username}/{namespace}/{start}/{end}", name="EditSummaryResult", |
|
60
|
|
|
* requirements={ |
|
61
|
|
|
* "username" = "(ipr-.+\/\d+[^\/])|([^\/]+)", |
|
62
|
|
|
* "namespace"="|all|\d+", |
|
63
|
|
|
* "start"="|\d{4}-\d{2}-\d{2}", |
|
64
|
|
|
* "end"="|\d{4}-\d{2}-\d{2}", |
|
65
|
|
|
* }, |
|
66
|
|
|
* defaults={"namespace"="all", "start"=false, "end"=false} |
|
67
|
|
|
* ) |
|
68
|
|
|
* @param EditSummaryRepository $editSummaryRepo |
|
69
|
|
|
* @return Response |
|
70
|
|
|
* @codeCoverageIgnore |
|
71
|
|
|
*/ |
|
72
|
|
|
public function resultAction(EditSummaryRepository $editSummaryRepo): Response |
|
73
|
|
|
{ |
|
74
|
|
|
// Instantiate an EditSummary, treating the past 150 edits as 'recent'. |
|
75
|
|
|
$editSummary = new EditSummary( |
|
76
|
|
|
$editSummaryRepo, |
|
77
|
|
|
$this->project, |
|
78
|
|
|
$this->user, |
|
|
|
|
|
|
79
|
|
|
$this->namespace, |
|
80
|
|
|
$this->start, |
|
81
|
|
|
$this->end, |
|
82
|
|
|
150 |
|
83
|
|
|
); |
|
84
|
|
|
$editSummary->prepareData(); |
|
85
|
|
|
|
|
86
|
|
|
return $this->getFormattedResponse('editSummary/result', [ |
|
87
|
|
|
'xtPage' => 'EditSummary', |
|
88
|
|
|
'xtTitle' => $this->user->getUsername(), |
|
|
|
|
|
|
89
|
|
|
'es' => $editSummary, |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/************************ API endpoints ************************/ |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get statistics on how many times a user has used edit summaries. |
|
97
|
|
|
* @Route( |
|
98
|
|
|
* "/api/user/edit_summaries/{project}/{username}/{namespace}/{start}/{end}", name="UserApiEditSummaries", |
|
99
|
|
|
* requirements={ |
|
100
|
|
|
* "username" = "(ipr-.+\/\d+[^\/])|([^\/]+)", |
|
101
|
|
|
* "namespace"="|all|\d+", |
|
102
|
|
|
* "start"="|\d{4}-\d{2}-\d{2}", |
|
103
|
|
|
* "end"="|\d{4}-\d{2}-\d{2}", |
|
104
|
|
|
* }, |
|
105
|
|
|
* defaults={"namespace"="all", "start"=false, "end"=false}, |
|
106
|
|
|
* methods={"GET"} |
|
107
|
|
|
* ) |
|
108
|
|
|
* @OA\Tag(name="User API") |
|
109
|
|
|
* @OA\Get(description="Get edit summage usage statistics for the user, with a month-by-month breakdown.") |
|
110
|
|
|
* @OA\Parameter(ref="#/components/parameters/Project") |
|
111
|
|
|
* @OA\Parameter(ref="#/components/parameters/UsernameOrIp") |
|
112
|
|
|
* @OA\Parameter(ref="#/components/parameters/Namespace") |
|
113
|
|
|
* @OA\Parameter(ref="#/components/parameters/Start") |
|
114
|
|
|
* @OA\Parameter(ref="#/components/parameters/End") |
|
115
|
|
|
* @OA\Response( |
|
116
|
|
|
* response=200, |
|
117
|
|
|
* description="Edit summary usage statistics", |
|
118
|
|
|
* @OA\JsonContent( |
|
119
|
|
|
* @OA\Property(property="project", ref="#/components/parameters/Project/schema"), |
|
120
|
|
|
* @OA\Property(property="username", ref="#/components/parameters/UsernameOrIp/schema"), |
|
121
|
|
|
* @OA\Property(property="namespace", ref="#/components/schemas/Namespace"), |
|
122
|
|
|
* @OA\Property(property="start", ref="#/components/parameters/Start/schema"), |
|
123
|
|
|
* @OA\Property(property="end", ref="#/components/parameters/End/schema"), |
|
124
|
|
|
* @OA\Property(property="recent_edits_minor", type="integer", |
|
125
|
|
|
* description="Number of minor edits within the last 150 edits"), |
|
126
|
|
|
* @OA\Property(property="recent_edits_major", type="integer", |
|
127
|
|
|
* description="Number of non-minor edits within the last 150 edits"), |
|
128
|
|
|
* @OA\Property(property="total_edits_minor", type="integer", |
|
129
|
|
|
* description="Total number of minor edits"), |
|
130
|
|
|
* @OA\Property(property="total_edits_major", type="integer", |
|
131
|
|
|
* description="Total number of non-minor edits"), |
|
132
|
|
|
* @OA\Property(property="total_edits", type="integer", description="Total number of edits"), |
|
133
|
|
|
* @OA\Property(property="recent_summaries_minor", type="integer", |
|
134
|
|
|
* description="Number of minor edits with summaries within the last 150 edits"), |
|
135
|
|
|
* @OA\Property(property="recent_summaries_major", type="integer", |
|
136
|
|
|
* description="Number of non-minor edits with summaries within the last 150 edits"), |
|
137
|
|
|
* ) |
|
138
|
|
|
* ) |
|
139
|
|
|
* @OA\Response(response=404, ref="#/components/responses/404") |
|
140
|
|
|
* @OA\Response(response=501, ref="#/components/responses/501") |
|
141
|
|
|
* @OA\Response(response=503, ref="#/components/responses/503") |
|
142
|
|
|
* @OA\Response(response=504, ref="#/components/responses/504") |
|
143
|
|
|
* @param EditSummaryRepository $editSummaryRepo |
|
144
|
|
|
* @return JsonResponse |
|
145
|
|
|
* @codeCoverageIgnore |
|
146
|
|
|
*/ |
|
147
|
|
|
public function editSummariesApiAction(EditSummaryRepository $editSummaryRepo): JsonResponse |
|
148
|
|
|
{ |
|
149
|
|
|
$this->recordApiUsage('user/edit_summaries'); |
|
150
|
|
|
|
|
151
|
|
|
// Instantiate an EditSummary, treating the past 150 edits as 'recent'. |
|
152
|
|
|
$editSummary = new EditSummary( |
|
153
|
|
|
$editSummaryRepo, |
|
154
|
|
|
$this->project, |
|
155
|
|
|
$this->user, |
|
|
|
|
|
|
156
|
|
|
$this->namespace, |
|
157
|
|
|
$this->start, |
|
158
|
|
|
$this->end, |
|
159
|
|
|
150 |
|
160
|
|
|
); |
|
161
|
|
|
$editSummary->prepareData(); |
|
162
|
|
|
|
|
163
|
|
|
return $this->getFormattedApiResponse($editSummary->getData()); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|