Merge "Integration tests for FileBackendGroup"
[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 use MediaWiki\Widget\DateInputWidget;
27
28 /**
29 * Special:Contributions, show user contributions in a paged list
30 *
31 * @ingroup SpecialPage
32 */
33 class SpecialContributions extends IncludableSpecialPage {
34 protected $opts;
35
36 public function __construct() {
37 parent::__construct( 'Contributions' );
38 }
39
40 public function execute( $par ) {
41 $this->setHeaders();
42 $this->outputHeader();
43 $out = $this->getOutput();
44 // Modules required for viewing the list of contributions (also when included on other pages)
45 $out->addModuleStyles( [
46 'mediawiki.interface.helpers.styles',
47 'mediawiki.special',
48 'mediawiki.special.changeslist',
49 ] );
50 $out->addModules( 'mediawiki.special.recentchanges' );
51 $this->addHelpLink( 'Help:User contributions' );
52
53 $this->opts = [];
54 $request = $this->getRequest();
55
56 $target = $par ?? $request->getVal( 'target' );
57
58 $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
59
60 if ( !strlen( $target ) ) {
61 if ( !$this->including() ) {
62 $out->addHTML( $this->getForm() );
63 }
64
65 return;
66 }
67
68 $user = $this->getUser();
69
70 $this->opts['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
71 $this->opts['target'] = $target;
72 $this->opts['topOnly'] = $request->getBool( 'topOnly' );
73 $this->opts['newOnly'] = $request->getBool( 'newOnly' );
74 $this->opts['hideMinor'] = $request->getBool( 'hideMinor' );
75
76 $id = 0;
77 if ( ExternalUserNames::isExternal( $target ) ) {
78 $userObj = User::newFromName( $target, false );
79 if ( !$userObj ) {
80 $out->addHTML( $this->getForm() );
81 return;
82 }
83
84 $out->addSubtitle( $this->contributionsSub( $userObj ) );
85 $out->setHTMLTitle( $this->msg(
86 'pagetitle',
87 $this->msg( 'contributions-title', $target )->plain()
88 )->inContentLanguage() );
89 } else {
90 $nt = Title::makeTitleSafe( NS_USER, $target );
91 if ( !$nt ) {
92 $out->addHTML( $this->getForm() );
93 return;
94 }
95 $userObj = User::newFromName( $nt->getText(), false );
96 if ( !$userObj ) {
97 $out->addHTML( $this->getForm() );
98 return;
99 }
100 $id = $userObj->getId();
101
102 $target = $nt->getText();
103 $out->addSubtitle( $this->contributionsSub( $userObj ) );
104 $out->setHTMLTitle( $this->msg(
105 'pagetitle',
106 $this->msg( 'contributions-title', $target )->plain()
107 )->inContentLanguage() );
108
109 # For IP ranges, we want the contributionsSub, but not the skin-dependent
110 # links under 'Tools', which may include irrelevant links like 'Logs'.
111 if ( !IP::isValidRange( $target ) ) {
112 $this->getSkin()->setRelevantUser( $userObj );
113 }
114 }
115
116 $ns = $request->getVal( 'namespace', null );
117 if ( $ns !== null && $ns !== '' ) {
118 $this->opts['namespace'] = intval( $ns );
119 } else {
120 $this->opts['namespace'] = '';
121 }
122
123 $this->opts['associated'] = $request->getBool( 'associated' );
124 $this->opts['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
125 $this->opts['tagfilter'] = (string)$request->getVal( 'tagfilter' );
126
127 // Allows reverts to have the bot flag in recent changes. It is just here to
128 // be passed in the form at the top of the page
129 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
130 $this->opts['bot'] = '1';
131 }
132
133 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
134 # Offset overrides year/month selection
135 if ( !$skip ) {
136 $this->opts['year'] = $request->getVal( 'year' );
137 $this->opts['month'] = $request->getVal( 'month' );
138
139 $this->opts['start'] = $request->getVal( 'start' );
140 $this->opts['end'] = $request->getVal( 'end' );
141 }
142 $this->opts = ContribsPager::processDateFilter( $this->opts );
143
144 if ( $this->opts['namespace'] < NS_MAIN ) {
145 $this->getOutput()->wrapWikiMsg(
146 "<div class=\"mw-negative-namespace-not-supported error\">\n\$1\n</div>",
147 [ 'negative-namespace-not-supported' ]
148 );
149 $out->addHTML( $this->getForm() );
150 return;
151 }
152
153 $feedType = $request->getVal( 'feed' );
154
155 $feedParams = [
156 'action' => 'feedcontributions',
157 'user' => $target,
158 ];
159 if ( $this->opts['topOnly'] ) {
160 $feedParams['toponly'] = true;
161 }
162 if ( $this->opts['newOnly'] ) {
163 $feedParams['newonly'] = true;
164 }
165 if ( $this->opts['hideMinor'] ) {
166 $feedParams['hideminor'] = true;
167 }
168 if ( $this->opts['deletedOnly'] ) {
169 $feedParams['deletedonly'] = true;
170 }
171 if ( $this->opts['tagfilter'] !== '' ) {
172 $feedParams['tagfilter'] = $this->opts['tagfilter'];
173 }
174 if ( $this->opts['namespace'] !== '' ) {
175 $feedParams['namespace'] = $this->opts['namespace'];
176 }
177 // Don't use year and month for the feed URL, but pass them on if
178 // we redirect to API (if $feedType is specified)
179 if ( $feedType && $this->opts['year'] !== null ) {
180 $feedParams['year'] = $this->opts['year'];
181 }
182 if ( $feedType && $this->opts['month'] !== null ) {
183 $feedParams['month'] = $this->opts['month'];
184 }
185
186 if ( $feedType ) {
187 // Maintain some level of backwards compatibility
188 // If people request feeds using the old parameters, redirect to API
189 $feedParams['feedformat'] = $feedType;
190 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
191
192 $out->redirect( $url, '301' );
193
194 return;
195 }
196
197 // Add RSS/atom links
198 $this->addFeedLinks( $feedParams );
199
200 if ( Hooks::run( 'SpecialContributionsBeforeMainOutput', [ $id, $userObj, $this ] ) ) {
201 if ( !$this->including() ) {
202 $out->addHTML( $this->getForm() );
203 }
204 $pager = new ContribsPager( $this->getContext(), [
205 'target' => $target,
206 // Temporary, until newbie feature is fully removed from ContribsPager
207 'contribs' => 'user',
208 'namespace' => $this->opts['namespace'],
209 'tagfilter' => $this->opts['tagfilter'],
210 'start' => $this->opts['start'],
211 'end' => $this->opts['end'],
212 'deletedOnly' => $this->opts['deletedOnly'],
213 'topOnly' => $this->opts['topOnly'],
214 'newOnly' => $this->opts['newOnly'],
215 'hideMinor' => $this->opts['hideMinor'],
216 'nsInvert' => $this->opts['nsInvert'],
217 'associated' => $this->opts['associated'],
218 ] );
219
220 if ( IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
221 // Valid range, but outside CIDR limit.
222 $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
223 $limit = $limits[ IP::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
224 $out->addWikiMsg( 'sp-contributions-outofrange', $limit );
225 } elseif ( !$pager->getNumRows() ) {
226 $out->addWikiMsg( 'nocontribs', $target );
227 } else {
228 # Show a message about replica DB lag, if applicable
229 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
230 if ( $lag > 0 ) {
231 $out->showLagWarning( $lag );
232 }
233
234 $output = $pager->getBody();
235 if ( !$this->including() ) {
236 $output = $pager->getNavigationBar() .
237 $output .
238 $pager->getNavigationBar();
239 }
240 $out->addHTML( $output );
241 }
242
243 $out->preventClickjacking( $pager->getPreventClickjacking() );
244
245 # Show the appropriate "footer" message - WHOIS tools, etc.
246 if ( IP::isValidRange( $target ) ) {
247 $message = 'sp-contributions-footer-anon-range';
248 } elseif ( IP::isIPAddress( $target ) ) {
249 $message = 'sp-contributions-footer-anon';
250 } elseif ( $userObj->isAnon() ) {
251 // No message for non-existing users
252 $message = '';
253 } else {
254 $message = 'sp-contributions-footer';
255 }
256
257 if ( $message && !$this->including() && !$this->msg( $message, $target )->isDisabled() ) {
258 $out->wrapWikiMsg(
259 "<div class='mw-contributions-footer'>\n$1\n</div>",
260 [ $message, $target ] );
261 }
262 }
263 }
264
265 /**
266 * Generates the subheading with links
267 * @param User $userObj User object for the target
268 * @return string Appropriately-escaped HTML to be output literally
269 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
270 * Could be combined.
271 */
272 protected function contributionsSub( $userObj ) {
273 if ( $userObj->isAnon() ) {
274 // Show a warning message that the user being searched for doesn't exist.
275 // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
276 // but returns false for IP ranges. We don't want to suggest either of these are
277 // valid usernames which we would with the 'contributions-userdoesnotexist' message.
278 if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
279 $this->getOutput()->wrapWikiMsg(
280 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
281 [
282 'contributions-userdoesnotexist',
283 wfEscapeWikiText( $userObj->getName() ),
284 ]
285 );
286 if ( !$this->including() ) {
287 $this->getOutput()->setStatusCode( 404 );
288 }
289 }
290 $user = htmlspecialchars( $userObj->getName() );
291 } else {
292 $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
293 }
294 $nt = $userObj->getUserPage();
295 $talk = $userObj->getTalkPage();
296 $links = '';
297 if ( $talk ) {
298 $tools = self::getUserLinks( $this, $userObj );
299 $links = Html::openElement( 'span', [ 'class' => 'mw-changeslist-links' ] );
300 foreach ( $tools as $tool ) {
301 $links .= Html::rawElement( 'span', [], $tool ) . ' ';
302 }
303 $links = trim( $links ) . Html::closeElement( 'span' );
304
305 // Show a note if the user is blocked and display the last block log entry.
306 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
307 // and also this will display a totally irrelevant log entry as a current block.
308 if ( !$this->including() ) {
309 // For IP ranges you must give DatabaseBlock::newFromTarget the CIDR string
310 // and not a user object.
311 if ( $userObj->isIPRange() ) {
312 $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
313 } else {
314 $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
315 }
316
317 if ( !is_null( $block ) && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
318 if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
319 $nt = MediaWikiServices::getInstance()->getNamespaceInfo()->
320 getCanonicalName( NS_USER ) . ':' . $block->getTarget();
321 }
322
323 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
324 LogEventsList::showLogExtract(
325 $out,
326 'block',
327 $nt,
328 '',
329 [
330 'lim' => 1,
331 'showIfEmpty' => false,
332 'msgKey' => [
333 $userObj->isAnon() ?
334 'sp-contributions-blocked-notice-anon' :
335 'sp-contributions-blocked-notice',
336 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
337 ],
338 'offset' => '' # don't use WebRequest parameter offset
339 ]
340 );
341 }
342 }
343 }
344
345 return Html::rawElement( 'div', [ 'class' => 'mw-contributions-user-tools' ],
346 $this->msg( 'contributions-subtitle' )->rawParams( $user )->params( $userObj->getName() )
347 . ' ' . $links
348 );
349 }
350
351 /**
352 * Links to different places.
353 *
354 * @note This function is also called in DeletedContributionsPage
355 * @param SpecialPage $sp SpecialPage instance, for context
356 * @param User $target Target user object
357 * @return array
358 */
359 public static function getUserLinks( SpecialPage $sp, User $target ) {
360 $id = $target->getId();
361 $username = $target->getName();
362 $userpage = $target->getUserPage();
363 $talkpage = $target->getTalkPage();
364 $isIP = IP::isValid( $username );
365 $isRange = IP::isValidRange( $username );
366
367 $linkRenderer = $sp->getLinkRenderer();
368
369 # No talk pages for IP ranges.
370 if ( !$isRange ) {
371 $tools['user-talk'] = $linkRenderer->makeLink(
372 $talkpage,
373 $sp->msg( 'sp-contributions-talk' )->text()
374 );
375 }
376
377 if ( $sp->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
378 if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
379 $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
380 SpecialPage::getTitleFor( 'Block', $username ),
381 $sp->msg( 'change-blocklink' )->text()
382 );
383 $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
384 SpecialPage::getTitleFor( 'Unblock', $username ),
385 $sp->msg( 'unblocklink' )->text()
386 );
387 } else { # User is not blocked
388 $tools['block'] = $linkRenderer->makeKnownLink( # Block link
389 SpecialPage::getTitleFor( 'Block', $username ),
390 $sp->msg( 'blocklink' )->text()
391 );
392 }
393 }
394
395 # Block log link
396 $tools['log-block'] = $linkRenderer->makeKnownLink(
397 SpecialPage::getTitleFor( 'Log', 'block' ),
398 $sp->msg( 'sp-contributions-blocklog' )->text(),
399 [],
400 [ 'page' => $userpage->getPrefixedText() ]
401 );
402
403 # Suppression log link (T61120)
404 if ( $sp->getUser()->isAllowed( 'suppressionlog' ) ) {
405 $tools['log-suppression'] = $linkRenderer->makeKnownLink(
406 SpecialPage::getTitleFor( 'Log', 'suppress' ),
407 $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
408 [],
409 [ 'offender' => $username ]
410 );
411 }
412
413 # Don't show some links for IP ranges
414 if ( !$isRange ) {
415 # Uploads: hide if IPs cannot upload (T220674)
416 if ( !$isIP || $target->isAllowed( 'upload' ) ) {
417 $tools['uploads'] = $linkRenderer->makeKnownLink(
418 SpecialPage::getTitleFor( 'Listfiles', $username ),
419 $sp->msg( 'sp-contributions-uploads' )->text()
420 );
421 }
422
423 # Other logs link
424 # Todo: T146628
425 $tools['logs'] = $linkRenderer->makeKnownLink(
426 SpecialPage::getTitleFor( 'Log', $username ),
427 $sp->msg( 'sp-contributions-logs' )->text()
428 );
429
430 # Add link to deleted user contributions for priviledged users
431 # Todo: T183457
432 if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) {
433 $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
434 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
435 $sp->msg( 'sp-contributions-deleted', $username )->text()
436 );
437 }
438 }
439
440 # Add a link to change user rights for privileged users
441 $userrightsPage = new UserrightsPage();
442 $userrightsPage->setContext( $sp->getContext() );
443 if ( $userrightsPage->userCanChangeRights( $target ) ) {
444 $tools['userrights'] = $linkRenderer->makeKnownLink(
445 SpecialPage::getTitleFor( 'Userrights', $username ),
446 $sp->msg( 'sp-contributions-userrights', $username )->text()
447 );
448 }
449
450 Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
451
452 return $tools;
453 }
454
455 /**
456 * Generates the namespace selector form with hidden attributes.
457 * @return string HTML fragment
458 */
459 protected function getForm() {
460 $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
461 if ( !isset( $this->opts['target'] ) ) {
462 $this->opts['target'] = '';
463 } else {
464 $this->opts['target'] = str_replace( '_', ' ', $this->opts['target'] );
465 }
466
467 if ( !isset( $this->opts['namespace'] ) ) {
468 $this->opts['namespace'] = '';
469 }
470
471 if ( !isset( $this->opts['nsInvert'] ) ) {
472 $this->opts['nsInvert'] = '';
473 }
474
475 if ( !isset( $this->opts['associated'] ) ) {
476 $this->opts['associated'] = false;
477 }
478
479 if ( !isset( $this->opts['start'] ) ) {
480 $this->opts['start'] = '';
481 }
482
483 if ( !isset( $this->opts['end'] ) ) {
484 $this->opts['end'] = '';
485 }
486
487 if ( !isset( $this->opts['tagfilter'] ) ) {
488 $this->opts['tagfilter'] = '';
489 }
490
491 if ( !isset( $this->opts['topOnly'] ) ) {
492 $this->opts['topOnly'] = false;
493 }
494
495 if ( !isset( $this->opts['newOnly'] ) ) {
496 $this->opts['newOnly'] = false;
497 }
498
499 if ( !isset( $this->opts['hideMinor'] ) ) {
500 $this->opts['hideMinor'] = false;
501 }
502
503 // Modules required only for the form
504 $this->getOutput()->addModules( [
505 'mediawiki.userSuggest',
506 'mediawiki.special.contributions',
507 ] );
508 $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
509 $this->getOutput()->enableOOUI();
510
511 $form = Html::openElement(
512 'form',
513 [
514 'method' => 'get',
515 'action' => wfScript(),
516 'class' => 'mw-contributions-form'
517 ]
518 );
519
520 # Add hidden params for tracking except for parameters in $skipParameters
521 $skipParameters = [
522 'namespace',
523 'nsInvert',
524 'deletedOnly',
525 'target',
526 'contribs',
527 'year',
528 'month',
529 'start',
530 'end',
531 'topOnly',
532 'newOnly',
533 'hideMinor',
534 'associated',
535 'tagfilter'
536 ];
537
538 foreach ( $this->opts as $name => $value ) {
539 if ( in_array( $name, $skipParameters ) ) {
540 continue;
541 }
542 $form .= "\t" . Html::hidden( $name, $value ) . "\n";
543 }
544
545 $tagFilter = ChangeTags::buildTagFilterSelector(
546 $this->opts['tagfilter'], false, $this->getContext() );
547
548 if ( $tagFilter ) {
549 $filterSelection = Html::rawElement(
550 'div',
551 [],
552 implode( "\u{00A0}", $tagFilter )
553 );
554 } else {
555 $filterSelection = Html::rawElement( 'div', [], '' );
556 }
557
558 $labelUsername = Xml::radioLabel(
559 $this->msg( 'sp-contributions-username' )->text(),
560 'contribs',
561 'user',
562 'user',
563 true,
564 [ 'class' => 'mw-input' ]
565 );
566 $input = Html::input(
567 'target',
568 $this->opts['target'],
569 'text',
570 [
571 'id' => 'mw-target-user-or-ip',
572 'size' => '40',
573 'class' => [
574 'mw-input',
575 'mw-ui-input-inline',
576 'mw-autocomplete-user', // used by mediawiki.userSuggest
577 ],
578 ] + (
579 // Only autofocus if target hasn't been specified
580 $this->opts['target'] ? [] : [ 'autofocus' => true ]
581 )
582 );
583
584 $targetSelection = Html::rawElement(
585 'div',
586 [],
587 $labelUsername . ' ' . $input . ' '
588 );
589
590 $hidden = $this->opts['namespace'] === '' ? ' mw-input-hidden' : '';
591 $namespaceSelection = Xml::tags(
592 'div',
593 [],
594 Xml::label(
595 $this->msg( 'namespace' )->text(),
596 'namespace'
597 ) . "\u{00A0}" .
598 Html::namespaceSelector(
599 [ 'selected' => $this->opts['namespace'], 'all' => '', 'in-user-lang' => true ],
600 [
601 'name' => 'namespace',
602 'id' => 'namespace',
603 'class' => 'namespaceselector',
604 ]
605 ) . "\u{00A0}" .
606 Html::rawElement(
607 'span',
608 [ 'class' => 'mw-input-with-label' . $hidden ],
609 Xml::checkLabel(
610 $this->msg( 'invert' )->text(),
611 'nsInvert',
612 'nsinvert',
613 $this->opts['nsInvert'],
614 [
615 'title' => $this->msg( 'tooltip-invert' )->text(),
616 'class' => 'mw-input'
617 ]
618 ) . "\u{00A0}"
619 ) .
620 Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' . $hidden ],
621 Xml::checkLabel(
622 $this->msg( 'namespace_association' )->text(),
623 'associated',
624 'nsassociated',
625 $this->opts['associated'],
626 [
627 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
628 'class' => 'mw-input'
629 ]
630 ) . "\u{00A0}"
631 )
632 );
633
634 $filters = [];
635
636 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
637 $filters[] = Html::rawElement(
638 'span',
639 [ 'class' => 'mw-input-with-label' ],
640 Xml::checkLabel(
641 $this->msg( 'history-show-deleted' )->text(),
642 'deletedOnly',
643 'mw-show-deleted-only',
644 $this->opts['deletedOnly'],
645 [ 'class' => 'mw-input' ]
646 )
647 );
648 }
649
650 $filters[] = Html::rawElement(
651 'span',
652 [ 'class' => 'mw-input-with-label' ],
653 Xml::checkLabel(
654 $this->msg( 'sp-contributions-toponly' )->text(),
655 'topOnly',
656 'mw-show-top-only',
657 $this->opts['topOnly'],
658 [ 'class' => 'mw-input' ]
659 )
660 );
661 $filters[] = Html::rawElement(
662 'span',
663 [ 'class' => 'mw-input-with-label' ],
664 Xml::checkLabel(
665 $this->msg( 'sp-contributions-newonly' )->text(),
666 'newOnly',
667 'mw-show-new-only',
668 $this->opts['newOnly'],
669 [ 'class' => 'mw-input' ]
670 )
671 );
672 $filters[] = Html::rawElement(
673 'span',
674 [ 'class' => 'mw-input-with-label' ],
675 Xml::checkLabel(
676 $this->msg( 'sp-contributions-hideminor' )->text(),
677 'hideMinor',
678 'mw-hide-minor-edits',
679 $this->opts['hideMinor'],
680 [ 'class' => 'mw-input' ]
681 )
682 );
683
684 Hooks::run(
685 'SpecialContributions::getForm::filters',
686 [ $this, &$filters ]
687 );
688
689 $extraOptions = Html::rawElement(
690 'div',
691 [],
692 implode( '', $filters )
693 );
694
695 $dateRangeSelection = Html::rawElement(
696 'div',
697 [],
698 Xml::label( $this->msg( 'date-range-from' )->text(), 'mw-date-start' ) . ' ' .
699 new DateInputWidget( [
700 'infusable' => true,
701 'id' => 'mw-date-start',
702 'name' => 'start',
703 'value' => $this->opts['start'],
704 'longDisplayFormat' => true,
705 ] ) . '<br>' .
706 Xml::label( $this->msg( 'date-range-to' )->text(), 'mw-date-end' ) . ' ' .
707 new DateInputWidget( [
708 'infusable' => true,
709 'id' => 'mw-date-end',
710 'name' => 'end',
711 'value' => $this->opts['end'],
712 'longDisplayFormat' => true,
713 ] )
714 );
715
716 $submit = Xml::tags( 'div', [],
717 Html::submitButton(
718 $this->msg( 'sp-contributions-submit' )->text(),
719 [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ]
720 )
721 );
722
723 $form .= Xml::fieldset(
724 $this->msg( 'sp-contributions-search' )->text(),
725 $targetSelection .
726 $namespaceSelection .
727 $filterSelection .
728 $extraOptions .
729 $dateRangeSelection .
730 $submit,
731 [ 'class' => 'mw-contributions-table' ]
732 );
733
734 $explain = $this->msg( 'sp-contributions-explain' );
735 if ( !$explain->isBlank() ) {
736 $form .= Html::rawElement(
737 'p', [ 'id' => 'mw-sp-contributions-explain' ], $explain->parse()
738 );
739 }
740
741 $form .= Xml::closeElement( 'form' );
742
743 return $form;
744 }
745
746 /**
747 * Return an array of subpages beginning with $search that this special page will accept.
748 *
749 * @param string $search Prefix to search for
750 * @param int $limit Maximum number of results to return (usually 10)
751 * @param int $offset Number of results to skip (usually 0)
752 * @return string[] Matching subpages
753 */
754 public function prefixSearchSubpages( $search, $limit, $offset ) {
755 $user = User::newFromName( $search );
756 if ( !$user ) {
757 // No prefix suggestion for invalid user
758 return [];
759 }
760 // Autocomplete subpage as user list - public to allow caching
761 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
762 }
763
764 protected function getGroupName() {
765 return 'users';
766 }
767 }