Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"A2093064",
"Ajeje Brazorf",
"Albe Albe460",
"Alien333",
"Amire80",
"BaRaN6161 TURK",
"BuddhikaW88",
Expand Down Expand Up @@ -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.",
Expand Down
19 changes: 16 additions & 3 deletions src/Controller/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -96,7 +101,8 @@ protected function setUpPages( PagesRepository $pagesRepo, string $redirects, st
$deleted,
$this->start,
$this->end,
$this->offset
$this->offset,
$countsOnly
);
}

Expand Down Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions src/Controller/XtoolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ public function getParams(): array {
'include_pattern',
'exclude_pattern',
'classonly',
'countsOnly',

// Legacy parameters.
'user',
Expand Down
20 changes: 19 additions & 1 deletion src/Model/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
}

/**
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions templates/pages/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
{{ msg('view-wikitext') }}
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="countsOnly" value="true">
{{ msg('counts-only') }}
</label>
</div>
</fieldset>
{{ forms.submit_btn() }}
</form>
Expand Down
9 changes: 5 additions & 4 deletions templates/pages/result.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,12 @@
{{ layout.content_block('summary', content, downloadLink) }}

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

{% include 'pages/_pages_list.html.twig' with {'pages': pages} %}

<div class="text-muted times-in-utc" style="clear:both">
{{ msg('times-in-utc') }}
<div class="text-muted times-in-utc" style="clear:both">
{{ msg('times-in-utc') }}
{% endif %}
</div>
</div>

Expand Down
Loading