Do not insert page titles into querycache.qc_value
[lhc/web/wiklou.git] / includes / specials / SpecialContributions.php
1 <?php
2 /**
3 * Implements Special:Contributions
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 use MediaWiki\Block\DatabaseBlock;
25 use MediaWiki\MediaWikiServices;
26
27 /**
28 * Special:Contributions, show user contributions in a paged list
29 *
30 * @ingroup SpecialPage
31 */
32 class SpecialContributions extends IncludableSpecialPage {
33 protected $opts;
34
35 public function __construct() {
36 parent::__construct( 'Contributions' );
37 }
38
39 public function execute( $par ) {
40 $this->setHeaders();
41 $this->outputHeader();
42 $out = $this->getOutput();
43 // Modules required for viewing the list of contributions (also when included on other pages)
44 $out->addModuleStyles( [
45 'jquery.makeCollapsible.styles',
46 'mediawiki.interface.helpers.styles',
47 'mediawiki.special',
48 'mediawiki.special.changeslist',
49 ] );
50 $out->addModules( [
51 'mediawiki.special.recentchanges',
52 // Certain skins e.g. Minerva might have disabled this module.
53 'mediawiki.page.ready'
54 ] );
55 $this->addHelpLink( 'Help:User contributions' );
56
57 $this->opts = [];
58 $request = $this->getRequest();
59
60 $target = $par ?? $request->getVal( 'target' );
61
62 $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
63
64 if ( !strlen( $target ) ) {
65 if ( !$this->including() ) {
66 $out->addHTML( $this->getForm( $this->opts ) );
67 }
68
69 return;
70 }
71
72 $user = $this->getUser();
73
74 $this->opts['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
75 $this->opts['target'] = $target;
76 $this->opts['topOnly'] = $request->getBool( 'topOnly' );
77 $this->opts['newOnly'] = $request->getBool( 'newOnly' );
78 $this->opts['hideMinor'] = $request->getBool( 'hideMinor' );
79
80 $id = 0;
81 if ( ExternalUserNames::isExternal( $target ) ) {
82 $userObj = User::newFromName( $target, false );
83 if ( !$userObj ) {
84 $out->addHTML( $this->getForm( $this->opts ) );
85 return;
86 }
87
88 $out->addSubtitle( $this->contributionsSub( $userObj ) );
89 $out->setHTMLTitle( $this->msg(
90 'pagetitle',
91 $this->msg( 'contributions-title', $target )->plain()
92 )->inContentLanguage() );
93 } else {
94 $nt = Title::makeTitleSafe( NS_USER, $target );
95 if ( !$nt ) {
96 $out->addHTML( $this->getForm( $this->opts ) );
97 return;
98 }
99 $userObj = User::newFromName( $nt->getText(), false );
100 if ( !$userObj ) {
101 $out->addHTML( $this->getForm( $this->opts ) );
102 return;
103 }
104 $id = $userObj->getId();
105
106 $target = $nt->getText();
107 $out->addSubtitle( $this->contributionsSub( $userObj ) );
108 $out->setHTMLTitle( $this->msg(
109 'pagetitle',
110 $this->msg( 'contributions-title', $target )->plain()
111 )->inContentLanguage() );
112
113 # For IP ranges, we want the contributionsSub, but not the skin-dependent
114 # links under 'Tools', which may include irrelevant links like 'Logs'.
115 if ( !IP::isValidRange( $target ) ) {
116 $this->getSkin()->setRelevantUser( $userObj );
117 }
118 }
119
120 $ns = $request->getVal( 'namespace', null );
121 if ( $ns !== null && $ns !== '' && $ns !== 'all' ) {
122 $this->opts['namespace'] = intval( $ns );
123 } else {
124 $this->opts['namespace'] = '';
125 }
126
127 // Backwards compatibility: Before using OOUI form the old HTML form had
128 // fields for nsInvert and associated. These have now been replaced with the
129 // wpFilters query string parameters. These are retained to keep old URIs working.
130 $this->opts['associated'] = $request->getBool( 'associated' );
131 $this->opts['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
132 $nsFilters = $request->getArray( 'wpfilters', null );
133 if ( $nsFilters !== null ) {
134 $this->opts['associated'] = in_array( 'associated', $nsFilters );
135 $this->opts['nsInvert'] = in_array( 'nsInvert', $nsFilters );
136 }
137
138 $this->opts['tagfilter'] = (string)$request->getVal( 'tagfilter' );
139
140 // Allows reverts to have the bot flag in recent changes. It is just here to
141 // be passed in the form at the top of the page
142 if ( MediaWikiServices::getInstance()
143 ->getPermissionManager()
144 ->userHasRight( $user, 'markbotedits' ) && $request->getBool( 'bot' )
145 ) {
146 $this->opts['bot'] = '1';
147 }
148
149 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
150 # Offset overrides year/month selection
151 if ( !$skip ) {
152 $this->opts['year'] = $request->getVal( 'year' );
153 $this->opts['month'] = $request->getVal( 'month' );
154
155 $this->opts['start'] = $request->getVal( 'start' );
156 $this->opts['end'] = $request->getVal( 'end' );
157 }
158 $this->opts = ContribsPager::processDateFilter( $this->opts );
159
160 if ( $this->opts['namespace'] < NS_MAIN ) {
161 $this->getOutput()->wrapWikiMsg(
162 "<div class=\"mw-negative-namespace-not-supported error\">\n\$1\n</div>",
163 [ 'negative-namespace-not-supported' ]
164 );
165 $out->addHTML( $this->getForm( $this->opts ) );
166 return;
167 }
168
169 $feedType = $request->getVal( 'feed' );
170
171 $feedParams = [
172 'action' => 'feedcontributions',
173 'user' => $target,
174 ];
175 if ( $this->opts['topOnly'] ) {
176 $feedParams['toponly'] = true;
177 }
178 if ( $this->opts['newOnly'] ) {
179 $feedParams['newonly'] = true;
180 }
181 if ( $this->opts['hideMinor'] ) {
182 $feedParams['hideminor'] = true;
183 }
184 if ( $this->opts['deletedOnly'] ) {
185 $feedParams['deletedonly'] = true;
186 }
187 if ( $this->opts['tagfilter'] !== '' ) {
188 $feedParams['tagfilter'] = $this->opts['tagfilter'];
189 }
190 if ( $this->opts['namespace'] !== '' ) {
191 $feedParams['namespace'] = $this->opts['namespace'];
192 }
193 // Don't use year and month for the feed URL, but pass them on if
194 // we redirect to API (if $feedType is specified)
195 if ( $feedType && $this->opts['year'] !== null ) {
196 $feedParams['year'] = $this->opts['year'];
197 }
198 if ( $feedType && $this->opts['month'] !== null ) {
199 $feedParams['month'] = $this->opts['month'];
200 }
201
202 if ( $feedType ) {
203 // Maintain some level of backwards compatibility
204 // If people request feeds using the old parameters, redirect to API
205 $feedParams['feedformat'] = $feedType;
206 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
207
208 $out->redirect( $url, '301' );
209
210 return;
211 }
212
213 // Add RSS/atom links
214 $this->addFeedLinks( $feedParams );
215
216 if ( Hooks::run( 'SpecialContributionsBeforeMainOutput', [ $id, $userObj, $this ] ) ) {
217 $pager = new ContribsPager( $this->getContext(), [
218 'target' => $target,
219 'namespace' => $this->opts['namespace'],
220 'tagfilter' => $this->opts['tagfilter'],
221 'start' => $this->opts['start'],
222 'end' => $this->opts['end'],
223 'deletedOnly' => $this->opts['deletedOnly'],
224 'topOnly' => $this->opts['topOnly'],
225 'newOnly' => $this->opts['newOnly'],
226 'hideMinor' => $this->opts['hideMinor'],
227 'nsInvert' => $this->opts['nsInvert'],
228 'associated' => $this->opts['associated'],
229 ], $this->getLinkRenderer() );
230 if ( !$this->including() ) {
231 $out->addHTML( $this->getForm( $this->opts ) );
232 }
233
234 if ( IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
235 // Valid range, but outside CIDR limit.
236 $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
237 $limit = $limits[ IP::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
238 $out->addWikiMsg( 'sp-contributions-outofrange', $limit );
239 } elseif ( !$pager->getNumRows() ) {
240 $out->addWikiMsg( 'nocontribs', $target );
241 } else {
242 # Show a message about replica DB lag, if applicable
243 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
244 if ( $lag > 0 ) {
245 $out->showLagWarning( $lag );
246 }
247
248 $output = $pager->getBody();
249 if ( !$this->including() ) {
250 $output = $pager->getNavigationBar() .
251 $output .
252 $pager->getNavigationBar();
253 }
254 $out->addHTML( $output );
255 }
256
257 $out->preventClickjacking( $pager->getPreventClickjacking() );
258
259 # Show the appropriate "footer" message - WHOIS tools, etc.
260 if ( IP::isValidRange( $target ) ) {
261 $message = 'sp-contributions-footer-anon-range';
262 } elseif ( IP::isIPAddress( $target ) ) {
263 $message = 'sp-contributions-footer-anon';
264 } elseif ( $userObj->isAnon() ) {
265 // No message for non-existing users
266 $message = '';
267 } else {
268 $message = 'sp-contributions-footer';
269 }
270
271 if ( $message && !$this->including() && !$this->msg( $message, $target )->isDisabled() ) {
272 $out->wrapWikiMsg(
273 "<div class='mw-contributions-footer'>\n$1\n</div>",
274 [ $message, $target ] );
275 }
276 }
277 }
278
279 /**
280 * Generates the subheading with links
281 * @param User $userObj User object for the target
282 * @return string Appropriately-escaped HTML to be output literally
283 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
284 * Could be combined.
285 */
286 protected function contributionsSub( $userObj ) {
287 if ( $userObj->isAnon() ) {
288 // Show a warning message that the user being searched for doesn't exist.
289 // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
290 // but returns false for IP ranges. We don't want to suggest either of these are
291 // valid usernames which we would with the 'contributions-userdoesnotexist' message.
292 if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
293 $this->getOutput()->wrapWikiMsg(
294 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
295 [
296 'contributions-userdoesnotexist',
297 wfEscapeWikiText( $userObj->getName() ),
298 ]
299 );
300 if ( !$this->including() ) {
301 $this->getOutput()->setStatusCode( 404 );
302 }
303 }
304 $user = htmlspecialchars( $userObj->getName() );
305 } else {
306 $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
307 }
308 $nt = $userObj->getUserPage();
309 $talk = $userObj->getTalkPage();
310 $links = '';
311 if ( $talk ) {
312 $tools = self::getUserLinks( $this, $userObj );
313 $links = Html::openElement( 'span', [ 'class' => 'mw-changeslist-links' ] );
314 foreach ( $tools as $tool ) {
315 $links .= Html::rawElement( 'span', [], $tool ) . ' ';
316 }
317 $links = trim( $links ) . Html::closeElement( 'span' );
318
319 // Show a note if the user is blocked and display the last block log entry.
320 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
321 // and also this will display a totally irrelevant log entry as a current block.
322 if ( !$this->including() ) {
323 // For IP ranges you must give DatabaseBlock::newFromTarget the CIDR string
324 // and not a user object.
325 if ( $userObj->isIPRange() ) {
326 $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
327 } else {
328 $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
329 }
330
331 if ( !is_null( $block ) && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
332 if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
333 $nt = MediaWikiServices::getInstance()->getNamespaceInfo()->
334 getCanonicalName( NS_USER ) . ':' . $block->getTarget();
335 }
336
337 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
338 LogEventsList::showLogExtract(
339 $out,
340 'block',
341 $nt,
342 '',
343 [
344 'lim' => 1,
345 'showIfEmpty' => false,
346 'msgKey' => [
347 $userObj->isAnon() ?
348 'sp-contributions-blocked-notice-anon' :
349 'sp-contributions-blocked-notice',
350 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
351 ],
352 'offset' => '' # don't use WebRequest parameter offset
353 ]
354 );
355 }
356 }
357 }
358
359 return Html::rawElement( 'div', [ 'class' => 'mw-contributions-user-tools' ],
360 $this->msg( 'contributions-subtitle' )->rawParams( $user )->params( $userObj->getName() )
361 . ' ' . $links
362 );
363 }
364
365 /**
366 * Links to different places.
367 *
368 * @note This function is also called in DeletedContributionsPage
369 * @param SpecialPage $sp SpecialPage instance, for context
370 * @param User $target Target user object
371 * @return array
372 */
373 public static function getUserLinks( SpecialPage $sp, User $target ) {
374 $id = $target->getId();
375 $username = $target->getName();
376 $userpage = $target->getUserPage();
377 $talkpage = $target->getTalkPage();
378 $isIP = IP::isValid( $username );
379 $isRange = IP::isValidRange( $username );
380
381 $linkRenderer = $sp->getLinkRenderer();
382
383 $tools = [];
384 # No talk pages for IP ranges.
385 if ( !$isRange ) {
386 $tools['user-talk'] = $linkRenderer->makeLink(
387 $talkpage,
388 $sp->msg( 'sp-contributions-talk' )->text()
389 );
390 }
391
392 # Block / Change block / Unblock links
393 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
394 if ( $permissionManager->userHasRight( $sp->getUser(), 'block' ) ) {
395 if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
396 $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
397 SpecialPage::getTitleFor( 'Block', $username ),
398 $sp->msg( 'change-blocklink' )->text()
399 );
400 $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
401 SpecialPage::getTitleFor( 'Unblock', $username ),
402 $sp->msg( 'unblocklink' )->text()
403 );
404 } else { # User is not blocked
405 $tools['block'] = $linkRenderer->makeKnownLink( # Block link
406 SpecialPage::getTitleFor( 'Block', $username ),
407 $sp->msg( 'blocklink' )->text()
408 );
409 }
410 }
411
412 # Block log link
413 $tools['log-block'] = $linkRenderer->makeKnownLink(
414 SpecialPage::getTitleFor( 'Log', 'block' ),
415 $sp->msg( 'sp-contributions-blocklog' )->text(),
416 [],
417 [ 'page' => $userpage->getPrefixedText() ]
418 );
419
420 # Suppression log link (T61120)
421 if ( $permissionManager->userHasRight( $sp->getUser(), 'suppressionlog' ) ) {
422 $tools['log-suppression'] = $linkRenderer->makeKnownLink(
423 SpecialPage::getTitleFor( 'Log', 'suppress' ),
424 $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
425 [],
426 [ 'offender' => $username ]
427 );
428 }
429
430 # Don't show some links for IP ranges
431 if ( !$isRange ) {
432 # Uploads: hide if IPs cannot upload (T220674)
433 if ( !$isIP || $permissionManager->userHasRight( $target, 'upload' ) ) {
434 $tools['uploads'] = $linkRenderer->makeKnownLink(
435 SpecialPage::getTitleFor( 'Listfiles', $username ),
436 $sp->msg( 'sp-contributions-uploads' )->text()
437 );
438 }
439
440 # Other logs link
441 # Todo: T146628
442 $tools['logs'] = $linkRenderer->makeKnownLink(
443 SpecialPage::getTitleFor( 'Log', $username ),
444 $sp->msg( 'sp-contributions-logs' )->text()
445 );
446
447 # Add link to deleted user contributions for priviledged users
448 # Todo: T183457
449 if ( $permissionManager->userHasRight( $sp->getUser(), 'deletedhistory' ) ) {
450 $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
451 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
452 $sp->msg( 'sp-contributions-deleted', $username )->text()
453 );
454 }
455 }
456
457 # Add a link to change user rights for privileged users
458 $userrightsPage = new UserrightsPage();
459 $userrightsPage->setContext( $sp->getContext() );
460 if ( $userrightsPage->userCanChangeRights( $target ) ) {
461 $tools['userrights'] = $linkRenderer->makeKnownLink(
462 SpecialPage::getTitleFor( 'Userrights', $username ),
463 $sp->msg( 'sp-contributions-userrights', $username )->text()
464 );
465 }
466
467 Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
468
469 return $tools;
470 }
471
472 /**
473 * Generates the namespace selector form with hidden attributes.
474 * @param array $pagerOptions with keys contribs, user, deletedOnly, limit, target, topOnly,
475 * newOnly, hideMinor, namespace, associated, nsInvert, tagfilter, year, start, end
476 * @return string HTML fragment
477 */
478 protected function getForm( array $pagerOptions ) {
479 $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
480 // Modules required only for the form
481 $this->getOutput()->addModules( [
482 'mediawiki.userSuggest',
483 'mediawiki.special.contributions',
484 ] );
485 $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
486 $this->getOutput()->enableOOUI();
487 $fields = [];
488
489 # Add hidden params for tracking except for parameters in $skipParameters
490 $skipParameters = [
491 'namespace',
492 'nsInvert',
493 'deletedOnly',
494 'target',
495 'year',
496 'month',
497 'start',
498 'end',
499 'topOnly',
500 'newOnly',
501 'hideMinor',
502 'associated',
503 'tagfilter'
504 ];
505
506 foreach ( $this->opts as $name => $value ) {
507 if ( in_array( $name, $skipParameters ) ) {
508 continue;
509 }
510
511 $fields[$name] = [
512 'name' => $name,
513 'type' => 'hidden',
514 'default' => $value,
515 ];
516 }
517
518 $target = $this->opts['target'] ?? null;
519 $fields['target'] = [
520 'type' => 'text',
521 'cssclass' => 'mw-autocomplete-user mw-ui-input-inline mw-input',
522 'default' => $target ?
523 str_replace( '_', ' ', $target ) : '' ,
524 'label' => $this->msg( 'sp-contributions-username' )->text(),
525 'name' => 'target',
526 'id' => 'mw-target-user-or-ip',
527 'size' => 40,
528 'autofocus' => !$target,
529 'section' => 'contribs-top',
530 ];
531
532 $ns = $this->opts['namespace'] ?? null;
533 $fields['namespace'] = [
534 'type' => 'namespaceselect',
535 'label' => $this->msg( 'namespace' )->text(),
536 'name' => 'namespace',
537 'cssclass' => 'namespaceselector',
538 'default' => $ns,
539 'id' => 'namespace',
540 'section' => 'contribs-top',
541 ];
542 $request = $this->getRequest();
543 $nsFilters = $request->getArray( 'wpfilters' );
544 $fields['nsFilters'] = [
545 'class' => 'HTMLMultiSelectField',
546 'label' => '',
547 'name' => 'wpfilters',
548 'flatlist' => true,
549 // Only shown when namespaces are selected.
550 'cssclass' => $ns === '' ?
551 'contribs-ns-filters mw-input-with-label mw-input-hidden' :
552 'contribs-ns-filters mw-input-with-label',
553 // `contribs-ns-filters` class allows these fields to be toggled on/off by JavaScript.
554 // See resources/src/mediawiki.special.recentchanges.js
555 'infusable' => true,
556 'options' => [
557 $this->msg( 'invert' )->text() => 'nsInvert',
558 $this->msg( 'namespace_association' )->text() => 'associated',
559 ],
560 'default' => $nsFilters,
561 'section' => 'contribs-top',
562 ];
563 $fields['tagfilter'] = [
564 'type' => 'tagfilter',
565 'cssclass' => 'mw-tagfilter-input',
566 'id' => 'tagfilter',
567 'label-message' => [ 'tag-filter', 'parse' ],
568 'name' => 'tagfilter',
569 'size' => 20,
570 'section' => 'contribs-top',
571 ];
572
573 if ( MediaWikiServices::getInstance()
574 ->getPermissionManager()
575 ->userHasRight( $this->getUser(), 'deletedhistory' )
576 ) {
577 $fields['deletedOnly'] = [
578 'type' => 'check',
579 'id' => 'mw-show-deleted-only',
580 'label' => $this->msg( 'history-show-deleted' )->text(),
581 'name' => 'deletedOnly',
582 'section' => 'contribs-top',
583 ];
584 }
585
586 $fields['topOnly'] = [
587 'type' => 'check',
588 'id' => 'mw-show-top-only',
589 'label' => $this->msg( 'sp-contributions-toponly' )->text(),
590 'name' => 'topOnly',
591 'section' => 'contribs-top',
592 ];
593 $fields['newOnly'] = [
594 'type' => 'check',
595 'id' => 'mw-show-new-only',
596 'label' => $this->msg( 'sp-contributions-newonly' )->text(),
597 'name' => 'newOnly',
598 'section' => 'contribs-top',
599 ];
600 $fields['hideMinor'] = [
601 'type' => 'check',
602 'cssclass' => 'mw-hide-minor-edits',
603 'id' => 'mw-show-new-only',
604 'label' => $this->msg( 'sp-contributions-hideminor' )->text(),
605 'name' => 'hideMinor',
606 'section' => 'contribs-top',
607 ];
608
609 // Allow additions at this point to the filters.
610 $rawFilters = [];
611 Hooks::run(
612 'SpecialContributions::getForm::filters',
613 [ $this, &$rawFilters ]
614 );
615 foreach ( $rawFilters as $filter ) {
616 // Backwards compatibility support for previous hook function signature.
617 if ( is_string( $filter ) ) {
618 $fields[] = [
619 'type' => 'info',
620 'default' => $filter,
621 'raw' => true,
622 'section' => 'contribs-top',
623 ];
624 wfDeprecated(
625 __METHOD__ .
626 ' returning string[]',
627 '1.33'
628 );
629 } else {
630 // Preferred append method.
631 $fields[] = $filter;
632 }
633 }
634
635 $fields['start'] = [
636 'type' => 'date',
637 'default' => '',
638 'id' => 'mw-date-start',
639 'label' => $this->msg( 'date-range-from' )->text(),
640 'name' => 'start',
641 'section' => 'contribs-date',
642 ];
643 $fields['end'] = [
644 'type' => 'date',
645 'default' => '',
646 'id' => 'mw-date-end',
647 'label' => $this->msg( 'date-range-to' )->text(),
648 'name' => 'end',
649 'section' => 'contribs-date',
650 ];
651
652 $htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
653 $htmlForm
654 ->setMethod( 'get' )
655 // When offset is defined, the user is paging through results
656 // so we hide the form by default to allow users to focus on browsing
657 // rather than defining search parameters
658 ->setCollapsibleOptions(
659 ( $pagerOptions['target'] ?? null ) ||
660 ( $pagerOptions['start'] ?? null ) ||
661 ( $pagerOptions['end'] ?? null )
662 )
663 ->setAction( wfScript() )
664 ->setSubmitText( $this->msg( 'sp-contributions-submit' )->text() )
665 ->setWrapperLegend( $this->msg( 'sp-contributions-search' )->text() );
666
667 $explain = $this->msg( 'sp-contributions-explain' );
668 if ( !$explain->isBlank() ) {
669 $htmlForm->addFooterText( "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>" );
670 }
671
672 $htmlForm->loadData();
673
674 return $htmlForm->getHTML( false );
675 }
676
677 /**
678 * Return an array of subpages beginning with $search that this special page will accept.
679 *
680 * @param string $search Prefix to search for
681 * @param int $limit Maximum number of results to return (usually 10)
682 * @param int $offset Number of results to skip (usually 0)
683 * @return string[] Matching subpages
684 */
685 public function prefixSearchSubpages( $search, $limit, $offset ) {
686 $user = User::newFromName( $search );
687 if ( !$user ) {
688 // No prefix suggestion for invalid user
689 return [];
690 }
691 // Autocomplete subpage as user list - public to allow caching
692 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
693 }
694
695 protected function getGroupName() {
696 return 'users';
697 }
698 }