Skip to content

Commit 306da61

Browse files
authored
PagesCreated: add countsOnly option (x-tools#550)
Bug: T229581
1 parent b601ccb commit 306da61

File tree

7 files changed

+50
-8
lines changed

7 files changed

+50
-8
lines changed

i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"contributions": "Contributions",
8686
"count": "Count",
8787
"created-by": "Created by",
88+
"counts-only": "Counts only",
8889
"csv": "CSV",
8990
"current-admins": "Current admins",
9091
"current-patrollers": "Current patrollers",

i18n/qqq.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"A2093064",
55
"Ajeje Brazorf",
66
"Albe Albe460",
7+
"Alien333",
78
"Amire80",
89
"BaRaN6161 TURK",
910
"BuddhikaW88",
@@ -103,6 +104,7 @@
103104
"contentmodel": "The term used to describe the type of page on a wiki. See [[mw:Manual:ContentHandler]] for more info. This is used to indicate how many times a user has changed the content model of a page.",
104105
"contributions": "Term for edits that a users has made.\n\n{{Identical|Contribution}}",
105106
"count": "General term for 'count'.\n{{Identical|Count}}",
107+
"counts-only": "Option in form to only show counts of results in certain categories, rather than all those results.",
106108
"created-by": "Label for the creator of a page.",
107109
"csv": "{{Optional}}\nLink for CSV file. See https://en.wikipedia.org/wiki/Comma-separated_values for information on what a CSV file is.\nCSV is the name of a file format; should not be translated.",
108110
"current-admins": "Label for the current number of admins for a project.",

src/Controller/PagesController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ public function indexAction(): Response {
8181
* @return Pages
8282
* @codeCoverageIgnore
8383
*/
84-
protected function setUpPages( PagesRepository $pagesRepo, string $redirects, string $deleted ): Pages {
84+
protected function setUpPages(
85+
PagesRepository $pagesRepo,
86+
string $redirects,
87+
string $deleted,
88+
bool $countsOnly = false
89+
): Pages {
8590
if ( $this->user->isIpRange() ) {
8691
$this->params['username'] = $this->user->getUsername();
8792
$this->throwXtoolsException( $this->getIndexRoute(), 'error-ip-range-unsupported' );
@@ -96,7 +101,8 @@ protected function setUpPages( PagesRepository $pagesRepo, string $redirects, st
96101
$deleted,
97102
$this->start,
98103
$this->end,
99-
$this->offset
104+
$this->offset,
105+
$countsOnly
100106
);
101107
}
102108

@@ -128,6 +134,12 @@ public function resultAction(
128134
string $redirects = Pages::REDIR_NONE,
129135
string $deleted = Pages::DEL_ALL
130136
): RedirectResponse|Response {
137+
$countsOnly = filter_var(
138+
$this->request->query->get( 'countsOnly', 'false' ),
139+
FILTER_VALIDATE_BOOLEAN,
140+
) && (
141+
$this->request->query->get( 'format', 'html' ) === 'html'
142+
);
131143
// Check for legacy values for 'redirects', and redirect
132144
// back with correct values if need be. This could be refactored
133145
// out to XtoolsController, but this is the only tool in the suite
@@ -138,10 +150,11 @@ public function resultAction(
138150
'redirects' => Pages::REDIR_NONE,
139151
'deleted' => $deleted,
140152
'offset' => $this->offset,
153+
'countsOnly' => $countsOnly,
141154
] ) );
142155
}
143156

144-
$pages = $this->setUpPages( $pagesRepo, $redirects, $deleted );
157+
$pages = $this->setUpPages( $pagesRepo, $redirects, $deleted, $countsOnly );
145158
$pages->prepareData();
146159

147160
$ret = [

src/Controller/XtoolsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ public function getParams(): array {
638638
'include_pattern',
639639
'exclude_pattern',
640640
'classonly',
641+
'countsOnly',
641642

642643
// Legacy parameters.
643644
'user',

src/Model/Pages.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class Pages extends Model {
3434
/** @var array Number of redirects/pages that were created/deleted, broken down by namespace. */
3535
protected array $countsByNamespace;
3636

37+
/** @var bool Whether to only get the counts */
38+
protected bool $countsOnly;
39+
3740
/**
3841
* Pages constructor.
3942
* @param Repository|PagesRepository $repository
@@ -45,6 +48,7 @@ class Pages extends Model {
4548
* @param int|false $start Start date as Unix timestamp.
4649
* @param int|false $end End date as Unix timestamp.
4750
* @param int|false $offset Unix timestamp. Used for pagination.
51+
* @param bool $countsOnly Whether to only get the counts
4852
*/
4953
public function __construct(
5054
protected Repository|PagesRepository $repository,
@@ -55,11 +59,13 @@ public function __construct(
5559
string $deleted = self::DEL_ALL,
5660
protected int|false $start = false,
5761
protected int|false $end = false,
58-
protected int|false $offset = false
62+
protected int|false $offset = false,
63+
bool $countsOnly = false,
5964
) {
6065
$this->namespace = $namespace === 'all' ? 'all' : (int)$namespace;
6166
$this->redirects = $redirects ?: self::REDIR_NONE;
6267
$this->deleted = $deleted ?: self::DEL_ALL;
68+
$this->countsOnly = $countsOnly;
6369
}
6470

6571
/**
@@ -78,6 +84,14 @@ public function getDeleted(): string {
7884
return $this->deleted;
7985
}
8086

87+
/**
88+
* Whether to only calculate counts.
89+
* @return bool
90+
*/
91+
public function isCountsOnly(): bool {
92+
return $this->countsOnly;
93+
}
94+
8195
/**
8296
* Fetch and prepare the pages created by the user.
8397
* @param bool $all Whether to get *all* results. This should only be used for
@@ -88,6 +102,10 @@ public function getDeleted(): string {
88102
public function prepareData( bool $all = false ): array {
89103
$this->pages = [];
90104

105+
if ( $this->countsOnly ) {
106+
return [];
107+
}
108+
91109
foreach ( $this->getNamespaces() as $ns ) {
92110
$data = $this->fetchPagesCreated( $ns, $all );
93111
$this->pages[$ns] = count( $data ) > 0

templates/pages/index.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
{{ msg('view-wikitext') }}
2020
</label>
2121
</div>
22+
<div class="checkbox">
23+
<label>
24+
<input type="checkbox" name="countsOnly" value="true">
25+
{{ msg('counts-only') }}
26+
</label>
27+
</div>
2228
</fieldset>
2329
{{ forms.submit_btn() }}
2430
</form>

templates/pages/result.html.twig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,12 @@
238238
{{ layout.content_block('summary', content, downloadLink) }}
239239

240240
{################## LIST OF PAGES ###################}
241+
{% if not pages.countsOnly %}
242+
{% include 'pages/_pages_list.html.twig' with {'pages': pages} %}
241243

242-
{% include 'pages/_pages_list.html.twig' with {'pages': pages} %}
243-
244-
<div class="text-muted times-in-utc" style="clear:both">
245-
{{ msg('times-in-utc') }}
244+
<div class="text-muted times-in-utc" style="clear:both">
245+
{{ msg('times-in-utc') }}
246+
{% endif %}
246247
</div>
247248
</div>
248249

0 commit comments

Comments
 (0)