Debian Codegraph @

extensions/Nuke/includes/SpecialNuke.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Nuke;
4
5 use DeletePageJob;
6 use ErrorPageError;
7 use JobQueueGroup;
8 use MediaWiki\CheckUser\Services\CheckUserTemporaryAccountsByIPLookup;
9 use MediaWiki\CommentStore\CommentStore;
10 use MediaWiki\Extension\Nuke\Hooks\NukeHookRunner;
11 use MediaWiki\Html\Html;
12 use MediaWiki\Html\ListToggle;
13 use MediaWiki\HTMLForm\HTMLForm;
14 use MediaWiki\Language\Language;
15 use MediaWiki\Page\File\FileDeleteForm;
16 use MediaWiki\Permissions\PermissionManager;
17 use MediaWiki\Request\WebRequest;
18 use MediaWiki\SpecialPage\SpecialPage;
19 use MediaWiki\Title\NamespaceInfo;
20 use MediaWiki\Title\Title;
21 use MediaWiki\User\Options\UserOptionsLookup;
22 use MediaWiki\User\User;
23 use MediaWiki\User\UserFactory;
24 use MediaWiki\User\UserNamePrefixSearch;
25 use MediaWiki\User\UserNameUtils;
26 use MediaWiki\Xml\Xml;
27 use OOUI\DropdownInputWidget;
28 use OOUI\FieldLayout;
29 use OOUI\TextInputWidget;
30 use PermissionsError;
31 use RepoGroup;
32 use UserBlockedError;
33 use Wikimedia\IPUtils;
34 use Wikimedia\Rdbms\IConnectionProvider;
35 use Wikimedia\Rdbms\IExpression;
36 use Wikimedia\Rdbms\LikeMatch;
37 use Wikimedia\Rdbms\LikeValue;
38 use Wikimedia\Rdbms\SelectQueryBuilder;
39
40 class SpecialNuke extends SpecialPage {
41
42 /** @var NukeHookRunner|null */
43 private $hookRunner;
44
45 private JobQueueGroup $jobQueueGroup;
46 private IConnectionProvider $dbProvider;
47 private PermissionManager $permissionManager;
48 private RepoGroup $repoGroup;
49 private UserFactory $userFactory;
50 private UserOptionsLookup $userOptionsLookup;
51 private UserNamePrefixSearch $userNamePrefixSearch;
52 private UserNameUtils $userNameUtils;
53 private NamespaceInfo $namespaceInfo;
54 private Language $contentLanguage;
55 /** @var CheckUserTemporaryAccountsByIPLookup|null */
56 private $checkUserTemporaryAccountsByIPLookup = null;
57
58 /**
59 * @inheritDoc
60 */
61 public function __construct(
62 JobQueueGroup $jobQueueGroup,
63 IConnectionProvider $dbProvider,
64 PermissionManager $permissionManager,
65 RepoGroup $repoGroup,
66 UserFactory $userFactory,
67 UserOptionsLookup $userOptionsLookup,
68 UserNamePrefixSearch $userNamePrefixSearch,
69 UserNameUtils $userNameUtils,
70 NamespaceInfo $namespaceInfo,
71 Language $contentLanguage,
72 $checkUserTemporaryAccountsByIPLookup = null
73 ) {
74 parent::__construct( 'Nuke', 'nuke' );
75 $this->jobQueueGroup = $jobQueueGroup;
76 $this->dbProvider = $dbProvider;
77 $this->permissionManager = $permissionManager;
78 $this->repoGroup = $repoGroup;
79 $this->userFactory = $userFactory;
80 $this->userOptionsLookup = $userOptionsLookup;
81 $this->userNamePrefixSearch = $userNamePrefixSearch;
82 $this->userNameUtils = $userNameUtils;
83 $this->namespaceInfo = $namespaceInfo;
84 $this->contentLanguage = $contentLanguage;
85 $this->checkUserTemporaryAccountsByIPLookup = $checkUserTemporaryAccountsByIPLookup;
86 }
87
88 /**
89 * @inheritDoc
90 * @codeCoverageIgnore
91 */
92 public function doesWrites() {
93 return true;
94 }
95
96 /**
97 * @param null|string $par
98 */
99 public function execute( $par ) {
100 $this->setHeaders();
101 $this->checkPermissions();
102 $this->checkReadOnly();
103 $this->outputHeader();
104 $this->addHelpLink( 'Help:Extension:Nuke' );
105
106 $currentUser = $this->getUser();
107 $block = $currentUser->getBlock();
108
109 // appliesToRight is presently a no-op, since there is no handling for `delete`,
110 // and so will return `null`. `true` will be returned if the block actively
111 // applies to `delete`, and both `null` and `true` should result in an error
112 if ( $block && ( $block->isSitewide() ||
113 ( $block->appliesToRight( 'delete' ) !== false ) )
114 ) {
115 throw new UserBlockedError( $block );
116 }
117
118 $req = $this->getRequest();
119 $target = trim( $req->getText( 'target', $par ?? '' ) );
120
121 // Normalise name
122 if ( $target !== '' ) {
123 $user = $this->userFactory->newFromName( $target );
124 if ( $user ) {
125 $target = $user->getName();
126 }
127 }
128
129 $reason = $this->getDeleteReason( $this->getRequest(), $target );
130
131 $limit = $req->getInt( 'limit', 500 );
132 $namespace = $req->getIntOrNull( 'namespace' );
133
134 if ( $req->wasPosted()
135 && $currentUser->matchEditToken( $req->getVal( 'wpEditToken' ) )
136 ) {
137 if ( $req->getRawVal( 'action' ) === 'delete' ) {
138 $pages = $req->getArray( 'pages' );
139
140 if ( $pages ) {
141 $this->doDelete( $pages, $reason );
142 return;
143 }
144 } elseif ( $req->getRawVal( 'action' ) === 'submit' ) {
145 // if the target is an ip addresss and temp account lookup is available,
146 // list pages created by the ip user or by temp accounts associated with the ip address
147 if (
148 $this->checkUserTemporaryAccountsByIPLookup &&
149 IPUtils::isValid( $target )
150 ) {
151 $this->assertUserCanAccessTemporaryAccounts( $currentUser );
152 $tempnames = $this->getTempAccountData( $target );
153 $reason = $this->getDeleteReason( $this->getRequest(), $target, true );
154 $this->listForm( $target, $reason, $limit, $namespace, $tempnames );
155 } else {
156 // otherwise just list pages normally
157 $this->listForm( $target, $reason, $limit, $namespace );
158 }
159 } else {
160 $this->promptForm();
161 }
162 } elseif ( $target === '' ) {
163 $this->promptForm();
164 } else {
165 $this->listForm( $target, $reason, $limit, $namespace );
166 }
167 }
168
169 /**
170 * Does the user have the appropriate permissions and have they enabled in preferences?
171 * Adapted from MediaWiki\CheckUser\Api\Rest\Handler\AbstractTemporaryAccountHandler::checkPermissions
172 *
173 * @param User $currentUser
174 *
175 * @throws PermissionsError if the user does not have the 'checkuser-temporary-account' right
176 * @throws ErrorPageError if the user has not enabled the 'checkuser-temporary-account-enabled' preference
177 */
178 private function assertUserCanAccessTemporaryAccounts( User $currentUser ) {
179 if (
180 !$currentUser->isAllowed( 'checkuser-temporary-account-no-preference' )
181 ) {
182 if (
183 !$currentUser->isAllowed( 'checkuser-temporary-account' )
184 ) {
185 throw new PermissionsError( 'checkuser-temporary-account' );
186 }
187 if (
188 !$this->userOptionsLookup->getOption(
189 $currentUser,
190 'checkuser-temporary-account-enable'
191 )
192 ) {
193 throw new ErrorPageError(
194 $this->msg( 'checkuser-ip-contributions-permission-error-title' ),
195 $this->msg( 'checkuser-ip-contributions-permission-error-description' )
196 );
197 }
198 }
199 }
200
201 /**
202 * Given an IP address, return a list of temporary accounts that are known to have edited from the IP.
203 *
204 * Calls to this method result in a log entry being generated for the logged-in user account making the request.
205 * @param string $ip The IP address used for looking up temporary account names.
206 * The address will be normalized in the IP lookup service.
207 * @return string[] A list of temporary account usernames associated with the IP address
208 */
209 private function getTempAccountData( string $ip ): array {
210 // Requires CheckUserTemporaryAccountsByIPLookup service
211 if ( !$this->checkUserTemporaryAccountsByIPLookup ) {
212 return [];
213 }
214 $status = $this->checkUserTemporaryAccountsByIPLookup->get(
215 $ip,
216 $this->getAuthority(),
217 true
218 );
219 if ( $status->isGood() ) {
220 return $status->getValue();
221 }
222 return [];
223 }
224
225 /**
226 * Prompt for a username or IP address.
227 *
228 * @param string $userName
229 */
230 protected function promptForm( string $userName = '' ): void {
231 $out = $this->getOutput();
232
233 if ( $this->checkUserTemporaryAccountsByIPLookup ) {
234 $out->addWikiMsg( 'nuke-tools-tempaccount' );
235 } else {
236 $out->addWikiMsg( 'nuke-tools' );
237 }
238
239 $formDescriptor = [
240 'nuke-target' => [
241 'id' => 'nuke-target',
242 'default' => $userName,
243 'label' => $this->msg( 'nuke-userorip' )->text(),
244 'type' => 'user',
245 'name' => 'target',
246 'autofocus' => true
247 ],
248 'nuke-pattern' => [
249 'id' => 'nuke-pattern',
250 'label' => $this->msg( 'nuke-pattern' )->text(),
251 'maxLength' => 40,
252 'type' => 'text',
253 'name' => 'pattern'
254 ],
255 'namespace' => [
256 'id' => 'nuke-namespace',
257 'type' => 'namespaceselect',
258 'label' => $this->msg( 'nuke-namespace' )->text(),
259 'all' => 'all',
260 'name' => 'namespace'
261 ],
262 'limit' => [
263 'id' => 'nuke-limit',
264 'maxLength' => 7,
265 'default' => 500,
266 'label' => $this->msg( 'nuke-maxpages' )->text(),
267 'type' => 'int',
268 'name' => 'limit'
269 ]
270 ];
271
272 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
273 ->setName( 'massdelete' )
274 ->setFormIdentifier( 'massdelete' )
275 ->setWrapperLegendMsg( 'nuke' )
276 ->setSubmitTextMsg( 'nuke-submit-user' )
277 ->setSubmitName( 'nuke-submit-user' )
278 ->setAction( $this->getPageTitle()->getLocalURL( 'action=submit' ) )
279 ->prepareForm()
280 ->displayForm( false );
281 }
282
283 /**
284 * Display list of pages to delete.
285 *
286 * @param string $username
287 * @param string $reason
288 * @param int $limit
289 * @param int|null $namespace
290 * @param string[] $tempnames
291 */
292 protected function listForm( $username, $reason, $limit, $namespace = null, $tempnames = [] ): void {
293 $out = $this->getOutput();
294
295 $pages = $this->getNewPages( $username, $limit, $namespace, $tempnames );
296
297 if ( !$pages ) {
298 if ( $username === '' ) {
299 $out->addWikiMsg( 'nuke-nopages-global' );
300 } else {
301 $out->addWikiMsg( 'nuke-nopages', $username );
302 }
303
304 $this->promptForm( $username );
305 return;
306 }
307
308 $out->addModules( 'ext.nuke.confirm' );
309 $out->addModuleStyles( [ 'ext.nuke.styles', 'mediawiki.interface.helpers.styles' ] );
310
311 if ( $username === '' ) {
312 $out->addWikiMsg( 'nuke-list-multiple' );
313 } elseif ( $tempnames ) {
314 $out->addWikiMsg( 'nuke-list-tempaccount', $username );
315 } else {
316 $out->addWikiMsg( 'nuke-list', $username );
317 }
318
319 $nuke = $this->getPageTitle();
320
321 $options = Xml::listDropdownOptions(
322 $this->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
323 [ 'other' => $this->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
324 );
325
326 $dropdown = new FieldLayout(
327 new DropdownInputWidget( [
328 'name' => 'wpDeleteReasonList',
329 'inputId' => 'wpDeleteReasonList',
330 'tabIndex' => 1,
331 'infusable' => true,
332 'value' => '',
333 'options' => Xml::listDropdownOptionsOoui( $options ),
334 ] ),
335 [
336 'label' => $this->msg( 'deletecomment' )->text(),
337 'align' => 'top',
338 ]
339 );
340 $reasonField = new FieldLayout(
341 new TextInputWidget( [
342 'name' => 'wpReason',
343 'inputId' => 'wpReason',
344 'tabIndex' => 2,
345 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
346 'infusable' => true,
347 'value' => $reason,
348 'autofocus' => true,
349 ] ),
350 [
351 'label' => $this->msg( 'deleteotherreason' )->text(),
352 'align' => 'top',
353 ]
354 );
355
356 $out->enableOOUI();
357 $out->addHTML(
358 Html::openElement( 'form', [
359 'action' => $nuke->getLocalURL( 'action=delete' ),
360 'method' => 'post',
361 'name' => 'nukelist' ]
362 ) .
363 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) .
364 $dropdown .
365 $reasonField .
366 // Select: All, None, Invert
367 ( new ListToggle( $this->getOutput() ) )->getHTML() .
368 '<ul>'
369 );
370
371 $wordSeparator = $this->msg( 'word-separator' )->escaped();
372 $commaSeparator = $this->msg( 'comma-separator' )->escaped();
373 $pipeSeparator = $this->msg( 'pipe-separator' )->escaped();
374
375 $linkRenderer = $this->getLinkRenderer();
376 $localRepo = $this->repoGroup->getLocalRepo();
377 foreach ( $pages as [ $title, $userName ] ) {
378 /**
379 * @var $title Title
380 */
381
382 $image = $title->inNamespace( NS_FILE ) ? $localRepo->newFile( $title ) : false;
383 $thumb = $image && $image->exists() ?
384 $image->transform( [ 'width' => 120, 'height' => 120 ], 0 ) :
385 false;
386
387 $userNameText = $userName ?
388 ' <span class="mw-changeslist-separator"></span> ' . $this->msg( 'nuke-editby', $userName )->parse() :
389 '';
390 $changesLink = $linkRenderer->makeKnownLink(
391 $title,
392 $this->msg( 'nuke-viewchanges' )->text(),
393 [],
394 [ 'action' => 'history' ]
395 );
396
397 $talkPageText = $this->namespaceInfo->isTalk( $title->getNamespace() ) ?
398 '' :
399 $linkRenderer->makeLink(
400 $this->namespaceInfo->getTalkPage( $title ),
401 $this->msg( 'sp-contributions-talk' )->text(),
402 [],
403 [],
404 ) . $wordSeparator . $pipeSeparator;
405
406 $query = $title->isRedirect() ? [ 'redirect' => 'no' ] : [];
407 $attributes = $title->isRedirect() ? [ 'class' => 'ext-nuke-italicize' ] : [];
408 $out->addHTML( '<li>' .
409 Html::check(
410 'pages[]',
411 true,
412 [ 'value' => $title->getPrefixedDBkey() ]
413 ) . "\u{00A0}" .
414 ( $thumb ? $thumb->toHtml( [ 'desc-link' => true ] ) : '' ) .
415 $linkRenderer->makeKnownLink( $title, null, $attributes, $query ) . $wordSeparator .
416 $this->msg( 'parentheses' )->rawParams( $talkPageText . $changesLink )->escaped() . $wordSeparator .
417 "<span class='ext-nuke-italicize'>" . $userNameText . "</span>" .
418 "</li>\n" );
419 }
420
421 $out->addHTML(
422 "</ul>\n" .
423 Html::submitButton( $this->msg( 'nuke-submit-delete' )->text() ) .
424 '</form>'
425 );
426 }
427
428 /**
429 * Gets a list of new pages by the specified user or everyone when none is specified.
430 *
431 * @param string $username
432 * @param int $limit
433 * @param int|null $namespace
434 * @param string[] $tempnames
435 *
436 * @return array{0:Title,1:string|false}[]
437 */
438 protected function getNewPages( $username, $limit, $namespace = null, $tempnames = [] ): array {
439 $dbr = $this->dbProvider->getReplicaDatabase();
440 $queryBuilder = $dbr->newSelectQueryBuilder()
441 ->select( [ 'page_title', 'page_namespace' ] )
442 ->from( 'recentchanges' )
443 ->join( 'actor', null, 'actor_id=rc_actor' )
444 ->join( 'page', null, 'page_id=rc_cur_id' )
445 ->where(
446 $dbr->expr( 'rc_source', '=', 'mw.new' )->orExpr(
447 $dbr->expr( 'rc_log_type', '=', 'upload' )
448 ->and( 'rc_log_action', '=', 'upload' )
449 )
450 )
451 ->orderBy( 'rc_timestamp', SelectQueryBuilder::SORT_DESC )
452 ->limit( $limit );
453
454 if ( $username === '' ) {
455 $queryBuilder->field( 'actor_name', 'rc_user_text' );
456 } else {
457 $actornames = array_filter( [ $username, ...$tempnames ] );
458 if ( $actornames ) {
459 $queryBuilder->andWhere( [ 'actor_name' => $actornames ] );
460 }
461 }
462
463 if ( $namespace !== null ) {
464 $queryBuilder->andWhere( [ 'page_namespace' => $namespace ] );
465 }
466
467 $pattern = $this->getRequest()->getText( 'pattern' );
468 if ( $pattern !== null && trim( $pattern ) !== '' ) {
469 $addedWhere = false;
470
471 $pattern = trim( $pattern );
472 $pattern = preg_replace( '/ +/', '`_', $pattern );
473 $pattern = preg_replace( '/\\\\([%_])/', '`$1', $pattern );
474
475 if ( $namespace !== null ) {
476 // Custom namespace requested
477 // If that namespace capitalizes titles, capitalize the first character
478 // to match the DB title.
479 $pattern = $this->namespaceInfo->isCapitalized( $namespace ) ?
480 $this->contentLanguage->ucfirst( $pattern ) : $pattern;
481 } else {
482 // All namespaces requested
483
484 $overriddenNamespaces = [];
485 $capitalLinks = $this->getConfig()->get( 'CapitalLinks' );
486 $capitalLinkOverrides = $this->getConfig()->get( 'CapitalLinkOverrides' );
487 // If there are any capital-overridden namespaces, keep track of them. "overridden"
488 // here means the namespace-specific value is not equal to $wgCapitalLinks.
489 foreach ( $capitalLinkOverrides as $k => $v ) {
490 if ( $v !== $capitalLinks ) {
491 $overriddenNamespaces[] = $k;
492 }
493 }
494
495 if ( count( $overriddenNamespaces ) ) {
496 // If there are overridden namespaces, they have to be converted
497 // on a case-by-case basis.
498
499 $validNamespaces = $this->namespaceInfo->getValidNamespaces();
500 $nonOverriddenNamespaces = [];
501 foreach ( $validNamespaces as $ns ) {
502 if ( !in_array( $ns, $overriddenNamespaces ) ) {
503 // Put all namespaces that aren't overridden in $nonOverriddenNamespaces
504 $nonOverriddenNamespaces[] = $ns;
505 }
506 }
507
508 $patternSpecific = $this->namespaceInfo->isCapitalized( $overriddenNamespaces[0] ) ?
509 $this->contentLanguage->ucfirst( $pattern ) : $pattern;
510 $orConditions = [
511 $dbr->expr(
512 'page_title', IExpression::LIKE, new LikeValue(
513 new LikeMatch( $patternSpecific )
514 )
515 )->and(
516 // IN condition
517 'page_namespace', '=', $overriddenNamespaces
518 )
519 ];
520 if ( count( $nonOverriddenNamespaces ) ) {
521 $patternStandard = $this->namespaceInfo->isCapitalized( $nonOverriddenNamespaces[0] ) ?
522 $this->contentLanguage->ucfirst( $pattern ) : $pattern;
523 $orConditions[] = $dbr->expr(
524 'page_title', IExpression::LIKE, new LikeValue(
525 new LikeMatch( $patternStandard )
526 )
527 )->and(
528 // IN condition, with the non-overridden namespaces.
529 // If the default is case-sensitive namespaces, $pattern's first
530 // character is turned lowercase. Otherwise, it is turned uppercase.
531 'page_namespace', '=', $nonOverriddenNamespaces
532 );
533 }
534 $queryBuilder->andWhere( $dbr->orExpr( $orConditions ) );
535 $addedWhere = true;
536 } else {
537 // No overridden namespaces; just convert all titles.
538 $pattern = $this->namespaceInfo->isCapitalized( NS_MAIN ) ?
539 $this->contentLanguage->ucfirst( $pattern ) : $pattern;
540 }
541 }
542
543 if ( !$addedWhere ) {
544 $queryBuilder->andWhere(
545 $dbr->expr(
546 'page_title',
547 IExpression::LIKE,
548 new LikeValue(
549 new LikeMatch( $pattern )
550 )
551 )
552 );
553 }
554 }
555
556 $result = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
557 /** @var array{0:Title,1:string|false}[] $pages */
558 $pages = [];
559 foreach ( $result as $row ) {
560 $pages[] = [
561 Title::makeTitle( $row->page_namespace, $row->page_title ),
562 $username === '' ? $row->rc_user_text : false
563 ];
564 }
565
566 // Allows other extensions to provide pages to be nuked that don't use
567 // the recentchanges table the way mediawiki-core does
568 $this->getNukeHookRunner()->onNukeGetNewPages( $username, $pattern, $namespace, $limit, $pages );
569
570 // Re-enforcing the limit *after* the hook because other extensions
571 // may add and/or remove pages. We need to make sure we don't end up
572 // with more pages than $limit.
573 if ( count( $pages ) > $limit ) {
574 $pages = array_slice( $pages, 0, $limit );
575 }
576
577 return $pages;
578 }
579
580 /**
581 * Does the actual deletion of the pages.
582 *
583 * @param array $pages The pages to delete
584 * @param string $reason
585 * @throws PermissionsError
586 */
587 protected function doDelete( array $pages, $reason ): void {
588 $res = [];
589 $jobs = [];
590 $user = $this->getUser();
591
592 $localRepo = $this->repoGroup->getLocalRepo();
593 foreach ( $pages as $page ) {
594 $title = Title::newFromText( $page );
595
596 // Check the delete rate limit for each page
597 if ( $user->pingLimiter( 'delete' ) ) {
598 $statuses[$title->getPrefixedDBkey()] = Status::newFatal( 'actionthrottledtext' );
599 break;
600 }
601
602 $deletionResult = false;
603 if ( !$this->getNukeHookRunner()->onNukeDeletePage( $title, $reason, $deletionResult ) ) {
604 $res[] = $this->msg(
605 $deletionResult ? 'nuke-deleted' : 'nuke-not-deleted',
606 wfEscapeWikiText( $title->getPrefixedText() )
607 )->parse();
608 continue;
609 }
610
611 $permission_errors = $this->permissionManager->getPermissionErrors( 'delete', $user, $title );
612
613 if ( $permission_errors !== [] ) {
614 throw new PermissionsError( 'delete', $permission_errors );
615 }
616
617 $file = $title->getNamespace() === NS_FILE ? $localRepo->newFile( $title ) : false;
618 if ( $file ) {
619 // Must be passed by reference
620 $oldimage = null;
621 $status = FileDeleteForm::doDelete(
622 $title,
623 $file,
624 $oldimage,
625 $reason,
626 false,
627 $user
628 );
629 } else {
630 $job = new DeletePageJob( [
631 'namespace' => $title->getNamespace(),
632 'title' => $title->getDBKey(),
633 'reason' => $reason,
634 'userId' => $user->getId(),
635 'wikiPageId' => $title->getId(),
636 'suppress' => false,
637 'tags' => '["Nuke"]',
638 'logsubtype' => 'delete',
639 ] );
640 $jobs[] = $job;
641 $status = 'job';
642 }
643
644 if ( $status === 'job' ) {
645 $res[] = $this->msg(
646 'nuke-deletion-queued',
647 wfEscapeWikiText( $title->getPrefixedText() )
648 )->parse();
649 } else {
650 $res[] = $this->msg(
651 $status->isOK() ? 'nuke-deleted' : 'nuke-not-deleted',
652 wfEscapeWikiText( $title->getPrefixedText() )
653 )->parse();
654 }
655 }
656
657 if ( $jobs ) {
658 $this->jobQueueGroup->push( $jobs );
659 }
660
661 $this->getOutput()->addHTML(
662 "<ul>\n<li>" .
663 implode( "</li>\n<li>", $res ) .
664 "</li>\n</ul>\n"
665 );
666 $this->getOutput()->addWikiMsg( 'nuke-delete-more' );
667 }
668
669 /**
670 * Return an array of subpages beginning with $search that this special page will accept.
671 *
672 * @param string $search Prefix to search for
673 * @param int $limit Maximum number of results to return (usually 10)
674 * @param int $offset Number of results to skip (usually 0)
675 * @return string[] Matching subpages
676 */
677 public function prefixSearchSubpages( $search, $limit, $offset ) {
678 $search = $this->userNameUtils->getCanonical( $search );
679 if ( !$search ) {
680 // No prefix suggestion for invalid user
681 return [];
682 }
683
684 // Autocomplete subpage as user list - public to allow caching
685 return $this->userNamePrefixSearch
686 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
687 }
688
689 /**
690 * Group Special:Nuke with pagetools
691 *
692 * @codeCoverageIgnore
693 * @return string
694 */
695 protected function getGroupName() {
696 return 'pagetools';
697 }
698
699 private function getDeleteReason( WebRequest $request, string $target, bool $tempaccount = false ): string {
700 if ( $tempaccount ) {
701 $defaultReason = $this->msg( 'nuke-defaultreason-tempaccount' );
702 } else {
703 $defaultReason = $target === ''
704 ? $this->msg( 'nuke-multiplepeople' )->inContentLanguage()->text()
705 : $this->msg( 'nuke-defaultreason', $target )->inContentLanguage()->text();
706 }
707
708 $dropdownSelection = $request->getText( 'wpDeleteReasonList', 'other' );
709 $reasonInput = $request->getText( 'wpReason', $defaultReason );
710
711 if ( $dropdownSelection === 'other' ) {
712 return $reasonInput;
713 } elseif ( $reasonInput !== '' ) {
714 // Entry from drop down menu + additional comment
715 $separator = $this->msg( 'colon-separator' )->inContentLanguage()->text();
716 return $dropdownSelection . $separator . $reasonInput;
717 } else {
718 return $dropdownSelection;
719 }
720 }
721
722 private function getNukeHookRunner(): NukeHookRunner {
723 $this->hookRunner ??= new NukeHookRunner( $this->getHookContainer() );
724 return $this->hookRunner;
725 }
726 }