From 056fa18d87202483d99e1a118a7e1c7443513e47 Mon Sep 17 00:00:00 2001 From: agoujot Date: Thu, 26 Jun 2025 16:42:16 +0200 Subject: [PATCH 1/5] add countsonly to pagescreated --- i18n/en.json | 1 + i18n/qqq.json | 2 ++ src/Controller/PagesController.php | 15 ++++++++++++--- src/Controller/XtoolsController.php | 1 + src/Model/Pages.php | 12 +++++++++++- templates/pages/index.html.twig | 6 ++++++ templates/pages/result.html.twig | 12 +++++++----- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index eca7cd4d7..9cf2bc713 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -88,6 +88,7 @@ "contributions": "Contributions", "count": "Count", "created-by": "Created by", + "counts-only": "Counts only", "csv": "CSV", "current-admins": "Current admins", "current-patrollers": "Current patrollers", diff --git a/i18n/qqq.json b/i18n/qqq.json index d78373d1d..4c952825e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -4,6 +4,7 @@ "A2093064", "Ajeje Brazorf", "Albe Albe460", + "Alien333", "Amire80", "BaRaN6161 TURK", "BuddhikaW88", @@ -106,6 +107,7 @@ "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.", "contributions": "Term for edits that a users has made.\n\n{{Identical|Contribution}}", "count": "General term for 'count'.\n{{Identical|Count}}", + "counts-only": "Option in form to only show counts of results in certain categories, rather than all those results.", "created-by": "Label for the creator of a page.", "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.", "current-admins": "Label for the current number of admins for a project.", diff --git a/src/Controller/PagesController.php b/src/Controller/PagesController.php index c5bb5bde6..dc73d37de 100644 --- a/src/Controller/PagesController.php +++ b/src/Controller/PagesController.php @@ -87,7 +87,7 @@ public function indexAction(): Response * @return Pages * @codeCoverageIgnore */ - protected function setUpPages(PagesRepository $pagesRepo, string $redirects, string $deleted): Pages + protected function setUpPages(PagesRepository $pagesRepo, string $redirects, string $deleted, bool $countsOnly = false): Pages { if ($this->user->isIpRange()) { $this->params['username'] = $this->user->getUsername(); @@ -103,7 +103,8 @@ protected function setUpPages(PagesRepository $pagesRepo, string $redirects, str $deleted, $this->start, $this->end, - $this->offset + $this->offset, + $countsOnly, ); } @@ -139,6 +140,12 @@ public function resultAction( string $redirects = Pages::REDIR_NONE, string $deleted = Pages::DEL_ALL ) { + $countsOnly = filter_var( + $this->request->query->get('countsOnly', 'false'), + FILTER_VALIDATE_BOOLEAN, + ) && ( + $this->request->query->get('format', 'html') === 'html' + ); // Check for legacy values for 'redirects', and redirect // back with correct values if need be. This could be refactored // out to XtoolsController, but this is the only tool in the suite @@ -149,10 +156,11 @@ public function resultAction( 'redirects' => Pages::REDIR_NONE, 'deleted' => $deleted, 'offset' => $this->offset, + 'countsOnly' => $countsOnly, ])); } - $pages = $this->setUpPages($pagesRepo, $redirects, $deleted); + $pages = $this->setUpPages($pagesRepo, $redirects, $deleted, $countsOnly); $pages->prepareData(); $ret = [ @@ -160,6 +168,7 @@ public function resultAction( 'xtTitle' => $this->user->getUsername(), 'summaryColumns' => $pages->getSummaryColumns(), 'pages' => $pages, + 'countsOnly' => $countsOnly, ]; if ('PagePile' === $this->request->query->get('format')) { diff --git a/src/Controller/XtoolsController.php b/src/Controller/XtoolsController.php index 7f6702ddc..a95ff273f 100644 --- a/src/Controller/XtoolsController.php +++ b/src/Controller/XtoolsController.php @@ -687,6 +687,7 @@ public function getParams(): array 'include_pattern', 'exclude_pattern', 'classonly', + 'countsOnly', // Legacy parameters. 'user', diff --git a/src/Model/Pages.php b/src/Model/Pages.php index e47f33582..adb04187d 100644 --- a/src/Model/Pages.php +++ b/src/Model/Pages.php @@ -34,6 +34,9 @@ class Pages extends Model /** @var array Number of redirects/pages that were created/deleted, broken down by namespace. */ protected array $countsByNamespace; + /** @var bool Whether to only get the counts */ + protected bool $countsOnly; + /** * Pages constructor. * @param PagesRepository $repository @@ -45,6 +48,7 @@ class Pages extends Model * @param int|false $start Start date as Unix timestamp. * @param int|false $end End date as Unix timestamp. * @param int|false $offset Unix timestamp. Used for pagination. + * @param bool $countsOnly Whether to only get the counts */ public function __construct( PagesRepository $repository, @@ -55,7 +59,8 @@ public function __construct( string $deleted = self::DEL_ALL, $start = false, $end = false, - $offset = false + $offset = false, + $countsOnly = false, ) { $this->repository = $repository; $this->project = $project; @@ -66,6 +71,7 @@ public function __construct( $this->redirects = $redirects ?: self::REDIR_NONE; $this->deleted = $deleted ?: self::DEL_ALL; $this->offset = $offset; + $this->countsOnly = $countsOnly; } /** @@ -97,6 +103,10 @@ public function prepareData(bool $all = false): array { $this->pages = []; + if ($this->countsOnly) { + return []; + } + foreach ($this->getNamespaces() as $ns) { $data = $this->fetchPagesCreated($ns, $all); $this->pages[$ns] = count($data) > 0 diff --git a/templates/pages/index.html.twig b/templates/pages/index.html.twig index eb4ec7897..0ed184c5b 100644 --- a/templates/pages/index.html.twig +++ b/templates/pages/index.html.twig @@ -19,6 +19,12 @@ {{ msg('view-wikitext') }} +
+ +
{{ forms.submit_btn() }} diff --git a/templates/pages/result.html.twig b/templates/pages/result.html.twig index 037ea26e3..3899642f9 100644 --- a/templates/pages/result.html.twig +++ b/templates/pages/result.html.twig @@ -205,11 +205,13 @@ {{ layout.content_block('summary', content, downloadLink) }} {################## LIST OF PAGES ###################} - - {% include 'pages/_pages_list.html.twig' with {'pages': pages} %} - -
- {{ msg('times-in-utc') }} + {# not if countsOnly is true #} + {% if not countsOnly %} + {% include 'pages/_pages_list.html.twig' with {'pages': pages} %} + +
+ {{ msg('times-in-utc') }} + {% endif %}
From a642c3ecc5bbe833624f398a32fafc79642afe67 Mon Sep 17 00:00:00 2001 From: agoujot Date: Thu, 26 Jun 2025 16:48:52 +0200 Subject: [PATCH 2/5] lints --- src/Controller/PagesController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Controller/PagesController.php b/src/Controller/PagesController.php index dc73d37de..6dcbd356a 100644 --- a/src/Controller/PagesController.php +++ b/src/Controller/PagesController.php @@ -87,8 +87,12 @@ public function indexAction(): Response * @return Pages * @codeCoverageIgnore */ - protected function setUpPages(PagesRepository $pagesRepo, string $redirects, string $deleted, bool $countsOnly = false): Pages - { + protected function setUpPages( + PagesRepository $pagesRepo, + string $redirects, + string $deleted, + bool $countsOnly = false + ): Pages { if ($this->user->isIpRange()) { $this->params['username'] = $this->user->getUsername(); $this->throwXtoolsException($this->getIndexRoute(), 'error-ip-range-unsupported'); @@ -144,7 +148,7 @@ public function resultAction( $this->request->query->get('countsOnly', 'false'), FILTER_VALIDATE_BOOLEAN, ) && ( - $this->request->query->get('format', 'html') === 'html' + 'html' === $this->request->query->get('format', 'html') ); // Check for legacy values for 'redirects', and redirect // back with correct values if need be. This could be refactored From 543dd2b68a846538c0b3bacb94e6fa451d67ce74 Mon Sep 17 00:00:00 2001 From: agoujot Date: Mon, 14 Jul 2025 20:58:22 +0200 Subject: [PATCH 3/5] rm problematic comma --- src/Model/Pages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Pages.php b/src/Model/Pages.php index adb04187d..bc5c3b41f 100644 --- a/src/Model/Pages.php +++ b/src/Model/Pages.php @@ -50,7 +50,7 @@ class Pages extends Model * @param int|false $offset Unix timestamp. Used for pagination. * @param bool $countsOnly Whether to only get the counts */ - public function __construct( + public function __construct ( PagesRepository $repository, Project $project, User $user, @@ -60,7 +60,7 @@ public function __construct( $start = false, $end = false, $offset = false, - $countsOnly = false, + $countsOnly = false ) { $this->repository = $repository; $this->project = $project; From d8e3eba40894421861776d75bbe83ee77fe66be0 Mon Sep 17 00:00:00 2001 From: agoujot Date: Mon, 14 Jul 2025 20:59:42 +0200 Subject: [PATCH 4/5] *grumble* remove space (lint) --- src/Model/Pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Pages.php b/src/Model/Pages.php index bc5c3b41f..22b99a836 100644 --- a/src/Model/Pages.php +++ b/src/Model/Pages.php @@ -50,7 +50,7 @@ class Pages extends Model * @param int|false $offset Unix timestamp. Used for pagination. * @param bool $countsOnly Whether to only get the counts */ - public function __construct ( + public function __construct( PagesRepository $repository, Project $project, User $user, From eabd1111796ff2fc2c0aba93e83bfc5fd9296c34 Mon Sep 17 00:00:00 2001 From: alien4444 Date: Sat, 3 Jan 2026 23:22:24 +0100 Subject: [PATCH 5/5] fix after merge --- src/Controller/PagesController.php | 20 ++++++++++---------- src/Controller/XtoolsController.php | 2 +- src/Model/Pages.php | 19 ++++++++++++++----- templates/pages/result.html.twig | 5 ++--- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Controller/PagesController.php b/src/Controller/PagesController.php index 098f673e3..3f035f2ae 100644 --- a/src/Controller/PagesController.php +++ b/src/Controller/PagesController.php @@ -82,11 +82,11 @@ public function indexAction(): Response { * @codeCoverageIgnore */ protected function setUpPages( - PagesRepository $pagesRepo, - string $redirects, - string $deleted, - bool $countsOnly = false - ): Pages { + PagesRepository $pagesRepo, + string $redirects, + string $deleted, + bool $countsOnly = false + ): Pages { if ( $this->user->isIpRange() ) { $this->params['username'] = $this->user->getUsername(); $this->throwXtoolsException( $this->getIndexRoute(), 'error-ip-range-unsupported' ); @@ -102,7 +102,7 @@ protected function setUpPages( $this->start, $this->end, $this->offset, - $countsOnly + $countsOnly ); } @@ -134,11 +134,11 @@ public function resultAction( string $redirects = Pages::REDIR_NONE, string $deleted = Pages::DEL_ALL ): RedirectResponse|Response { - $countsOnly = filter_var( - $this->request->query->get('countsOnly', 'false'), + $countsOnly = filter_var( + $this->request->query->get( 'countsOnly', 'false' ), FILTER_VALIDATE_BOOLEAN, ) && ( - $this->request->query->get('format', 'html') === 'html' + $this->request->query->get( 'format', 'html' ) === 'html' ); // Check for legacy values for 'redirects', and redirect // back with correct values if need be. This could be refactored @@ -150,7 +150,7 @@ public function resultAction( 'redirects' => Pages::REDIR_NONE, 'deleted' => $deleted, 'offset' => $this->offset, - 'countsOnly' => $countsOnly, + 'countsOnly' => $countsOnly, ] ) ); } diff --git a/src/Controller/XtoolsController.php b/src/Controller/XtoolsController.php index c6258b0ab..6b8da3140 100644 --- a/src/Controller/XtoolsController.php +++ b/src/Controller/XtoolsController.php @@ -638,7 +638,7 @@ public function getParams(): array { 'include_pattern', 'exclude_pattern', 'classonly', - 'countsOnly', + 'countsOnly', // Legacy parameters. 'user', diff --git a/src/Model/Pages.php b/src/Model/Pages.php index 867239a39..e70452b2d 100644 --- a/src/Model/Pages.php +++ b/src/Model/Pages.php @@ -33,8 +33,8 @@ class Pages extends Model { /** @var array Number of redirects/pages that were created/deleted, broken down by namespace. */ protected array $countsByNamespace; - - /** @var bool Whether to only get the counts */ + + /** @var bool Whether to only get the counts */ protected bool $countsOnly; /** @@ -48,7 +48,7 @@ class Pages extends Model { * @param int|false $start Start date as Unix timestamp. * @param int|false $end End date as Unix timestamp. * @param int|false $offset Unix timestamp. Used for pagination. - * @param bool $countsOnly Whether to only get the counts + * @param bool $countsOnly Whether to only get the counts */ public function __construct( protected Repository|PagesRepository $repository, @@ -60,11 +60,12 @@ public function __construct( protected int|false $start = false, protected int|false $end = false, protected int|false $offset = false, - protected bool $countsOnly = false, + bool $countsOnly = false, ) { $this->namespace = $namespace === 'all' ? 'all' : (int)$namespace; $this->redirects = $redirects ?: self::REDIR_NONE; $this->deleted = $deleted ?: self::DEL_ALL; + $this->countsOnly = $countsOnly; } /** @@ -83,6 +84,14 @@ public function getDeleted(): string { return $this->deleted; } + /** + * Whether to only calculate counts. + * @return bool + */ + public function isCountsOnly(): bool { + return $this->countsOnly; + } + /** * Fetch and prepare the pages created by the user. * @param bool $all Whether to get *all* results. This should only be used for @@ -93,7 +102,7 @@ public function getDeleted(): string { public function prepareData( bool $all = false ): array { $this->pages = []; - if ($this->countsOnly) { + if ( $this->countsOnly ) { return []; } diff --git a/templates/pages/result.html.twig b/templates/pages/result.html.twig index 340477c51..d2d65463d 100644 --- a/templates/pages/result.html.twig +++ b/templates/pages/result.html.twig @@ -238,10 +238,9 @@ {{ layout.content_block('summary', content, downloadLink) }} {################## LIST OF PAGES ###################} - {# not if countsOnly is true #} - {% if not countsOnly %} + {% if not pages.countsOnly %} {% include 'pages/_pages_list.html.twig' with {'pages': pages} %} - +
{{ msg('times-in-utc') }} {% endif %}