diff --git a/i18n/en.json b/i18n/en.json index 6e3642569..ed9ad522c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -85,6 +85,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 d7dc2f60b..9a3a256c2 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -4,6 +4,7 @@ "A2093064", "Ajeje Brazorf", "Albe Albe460", + "Alien333", "Amire80", "BaRaN6161 TURK", "BuddhikaW88", @@ -103,6 +104,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 5cca32dad..3f035f2ae 100644 --- a/src/Controller/PagesController.php +++ b/src/Controller/PagesController.php @@ -81,7 +81,12 @@ 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(); $this->throwXtoolsException( $this->getIndexRoute(), 'error-ip-range-unsupported' ); @@ -96,7 +101,8 @@ protected function setUpPages( PagesRepository $pagesRepo, string $redirects, st $deleted, $this->start, $this->end, - $this->offset + $this->offset, + $countsOnly ); } @@ -128,6 +134,12 @@ public function resultAction( string $redirects = Pages::REDIR_NONE, string $deleted = Pages::DEL_ALL ): RedirectResponse|Response { + $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 @@ -138,10 +150,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 = [ diff --git a/src/Controller/XtoolsController.php b/src/Controller/XtoolsController.php index f5ff3e2d9..6b8da3140 100644 --- a/src/Controller/XtoolsController.php +++ b/src/Controller/XtoolsController.php @@ -638,6 +638,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 942e28076..e70452b2d 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 Repository|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( protected Repository|PagesRepository $repository, @@ -55,11 +59,13 @@ public function __construct( string $deleted = self::DEL_ALL, protected int|false $start = false, protected int|false $end = false, - protected int|false $offset = false + protected int|false $offset = 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; } /** @@ -78,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 @@ -88,6 +102,10 @@ public function getDeleted(): string { 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') }} +