DeletedContribsPager: Use the UserIdentity object instead of the raw target string

Fixed the query for imported actors and some other potential edge cases.

Unsetting the 'target' field in SpecialDeletedContributions alone should
be sufficient, but I would rather like to keep the behaviour the same
with ContribsPager, which is used by more users and using
`$this->targetUser->getName()` is known to be ok so far.

Also, renamed some variables to match the parent class method signature
to avoid confusion.

Bug: T372444
Bug: T404230
Change-Id: I318ec7f30174087f988536f5196ff81e99241c9b
(cherry picked from commit dda0d4dfcd712b976e542cd688a3ab1c45051e7d)
This commit is contained in:
Func 2025-09-11 02:01:28 +08:00
parent 600f5a4010
commit 6677a9ce4b
3 changed files with 18 additions and 18 deletions

View file

@ -146,17 +146,12 @@ class ContributionsSpecialPage extends IncludableSpecialPage {
$target = $par ?? $request->getVal( 'target', '' );
'@phan-var string $target'; // getVal does not return null here
// Normalize underscores that may be present in the target parameter
// if it was passed in as a path param, rather than a query param
// where HTMLForm may have already performed preprocessing (T372444).
$target = $this->userNameUtils->getCanonical( $target, UserNameUtils::RIGOR_NONE );
$this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
// Explicitly check for false or empty string as this needs to account
// for the rare case where the target parameter is '0' which is a valid
// Explicitly check for empty string as this needs to account for
// the rare case where the target parameter is '0' which is a valid
// target but resolves to false in boolean context (T379515).
if ( $target === false || $target === '' ) {
if ( $target === '' ) {
$out->addHTML( $this->getForm( $this->opts ) );
return;
@ -743,7 +738,7 @@ class ContributionsSpecialPage extends IncludableSpecialPage {
'title',
];
foreach ( $this->opts as $name => $value ) {
foreach ( $pagerOptions as $name => $value ) {
if ( in_array( $name, $skipParameters ) ) {
continue;
}
@ -755,10 +750,10 @@ class ContributionsSpecialPage extends IncludableSpecialPage {
];
}
$target = $this->opts['target'] ?? '';
$target = $pagerOptions['target'] ?? '';
$fields['target'] = $this->getTargetField( $target );
$ns = $this->opts['namespace'] ?? null;
$ns = $pagerOptions['namespace'] ?? null;
$fields['namespace'] = [
'type' => 'namespaceselect',
'label' => $this->msg( 'namespace' )->text(),

View file

@ -105,8 +105,13 @@ class SpecialDeletedContributions extends ContributionsSpecialPage {
/**
* @inheritDoc
*/
protected function getPager( $target ) {
protected function getPager( $targetUser ) {
if ( $this->pager === null ) {
// Fields in the opts property are usually not normalised, mainly
// for validations in HTMLForm, especially the 'target' field.
$options = $this->opts;
unset( $options['target'] );
$this->pager = new DeletedContribsPager(
$this->getHookContainer(),
$this->getLinkRenderer(),
@ -117,8 +122,8 @@ class SpecialDeletedContributions extends ContributionsSpecialPage {
$this->linkBatchFactory,
$this->userFactory,
$this->getContext(),
$this->opts,
$target
$options,
$targetUser
);
}

View file

@ -47,7 +47,7 @@ class DeletedContribsPager extends ContributionsPager {
* @param UserFactory $userFactory
* @param IContextSource $context
* @param array $options
* @param UserIdentity $target
* @param UserIdentity $targetUser
*/
public function __construct(
HookContainer $hookContainer,
@ -60,7 +60,7 @@ class DeletedContribsPager extends ContributionsPager {
UserFactory $userFactory,
IContextSource $context,
array $options,
$target
UserIdentity $targetUser
) {
$options['isArchive'] = true;
@ -74,7 +74,7 @@ class DeletedContribsPager extends ContributionsPager {
$userFactory,
$context,
$options,
$target
$targetUser
);
$this->revisionIdField = 'ar_rev_id';
@ -94,7 +94,7 @@ class DeletedContribsPager extends ContributionsPager {
protected function getRevisionQuery() {
$queryBuilder = $this->revisionStore->newArchiveSelectQueryBuilder( $this->getDatabase() )
->joinComment()
->where( [ 'actor_name' => $this->target ] );
->where( [ 'actor_name' => $this->targetUser->getName() ] );
return $queryBuilder->getQueryInfo();
}