Declare dynamic properties
[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 'namespace' => $this->opts['namespace'],
207 'tagfilter' => $this->opts['tagfilter'],
208 'start' => $this->opts['start'],
209 'end' => $this->opts['end'],
210 'deletedOnly' => $this->opts['deletedOnly'],
211 'topOnly' => $this->opts['topOnly'],
212 'newOnly' => $this->opts['newOnly'],
213 'hideMinor' => $this->opts['hideMinor'],
214 'nsInvert' => $this->opts['nsInvert'],
215 'associated' => $this->opts['associated'],
216 ], $this->getLinkRenderer() );
217
218 if ( IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
219 // Valid range, but outside CIDR limit.
220 $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
221 $limit = $limits[ IP::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
222 $out->addWikiMsg( 'sp-contributions-outofrange', $limit );
223 } elseif ( !$pager->getNumRows() ) {
224 $out->addWikiMsg( 'nocontribs', $target );
225 } else {
226 # Show a message about replica DB lag, if applicable
227 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
228 if ( $lag > 0 ) {
229 $out->showLagWarning( $lag );
230 }
231
232 $output = $pager->getBody();
233 if ( !$this->including() ) {
234 $output = $pager->getNavigationBar() .
235 $output .
236 $pager->getNavigationBar();
237 }
238 $out->addHTML( $output );
239 }
240
241 $out->preventClickjacking( $pager->getPreventClickjacking() );
242
243 # Show the appropriate "footer" message - WHOIS tools, etc.
244 if ( IP::isValidRange( $target ) ) {
245 $message = 'sp-contributions-footer-anon-range';
246 } elseif ( IP::isIPAddress( $target ) ) {
247 $message = 'sp-contributions-footer-anon';
248 } elseif ( $userObj->isAnon() ) {
249 // No message for non-existing users
250 $message = '';
251 } else {
252 $message = 'sp-contributions-footer';
253 }
254
255 if ( $message && !$this->including() && !$this->msg( $message, $target )->isDisabled() ) {
256 $out->wrapWikiMsg(
257 "<div class='mw-contributions-footer'>\n$1\n</div>",
258 [ $message, $target ] );
259 }
260 }
261 }
262
263 /**
264 * Generates the subheading with links
265 * @param User $userObj User object for the target
266 * @return string Appropriately-escaped HTML to be output literally
267 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
268 * Could be combined.
269 */
270 protected function contributionsSub( $userObj ) {
271 if ( $userObj->isAnon() ) {
272 // Show a warning message that the user being searched for doesn't exist.
273 // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
274 // but returns false for IP ranges. We don't want to suggest either of these are
275 // valid usernames which we would with the 'contributions-userdoesnotexist' message.
276 if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
277 $this->getOutput()->wrapWikiMsg(
278 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
279 [
280 'contributions-userdoesnotexist',
281 wfEscapeWikiText( $userObj->getName() ),
282 ]
283 );
284 if ( !$this->including() ) {
285 $this->getOutput()->setStatusCode( 404 );
286 }
287 }
288 $user = htmlspecialchars( $userObj->getName() );
289 } else {
290 $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
291 }
292 $nt = $userObj->getUserPage();
293 $talk = $userObj->getTalkPage();
294 $links = '';
295 if ( $talk ) {
296 $tools = self::getUserLinks( $this, $userObj );
297 $links = Html::openElement( 'span', [ 'class' => 'mw-changeslist-links' ] );
298 foreach ( $tools as $tool ) {
299 $links .= Html::rawElement( 'span', [], $tool ) . ' ';
300 }
301 $links = trim( $links ) . Html::closeElement( 'span' );
302
303 // Show a note if the user is blocked and display the last block log entry.
304 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
305 // and also this will display a totally irrelevant log entry as a current block.
306 if ( !$this->including() ) {
307 // For IP ranges you must give DatabaseBlock::newFromTarget the CIDR string
308 // and not a user object.
309 if ( $userObj->isIPRange() ) {
310 $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
311 } else {
312 $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
313 }
314
315 if ( !is_null( $block ) && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
316 if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
317 $nt = MediaWikiServices::getInstance()->getNamespaceInfo()->
318 getCanonicalName( NS_USER ) . ':' . $block->getTarget();
319 }
320
321 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
322 LogEventsList::showLogExtract(
323 $out,
324 'block',
325 $nt,
326 '',
327 [
328 'lim' => 1,
329 'showIfEmpty' => false,
330 'msgKey' => [
331 $userObj->isAnon() ?
332 'sp-contributions-blocked-notice-anon' :
333 'sp-contributions-blocked-notice',
334 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
335 ],
336 'offset' => '' # don't use WebRequest parameter offset
337 ]
338 );
339 }
340 }
341 }
342
343 return Html::rawElement( 'div', [ 'class' => 'mw-contributions-user-tools' ],
344 $this->msg( 'contributions-subtitle' )->rawParams( $user )->params( $userObj->getName() )
345 . ' ' . $links
346 );
347 }
348
349 /**
350 * Links to different places.
351 *
352 * @note This function is also called in DeletedContributionsPage
353 * @param SpecialPage $sp SpecialPage instance, for context
354 * @param User $target Target user object
355 * @return array
356 */
357 public static function getUserLinks( SpecialPage $sp, User $target ) {
358 $id = $target->getId();
359 $username = $target->getName();
360 $userpage = $target->getUserPage();
361 $talkpage = $target->getTalkPage();
362 $isIP = IP::isValid( $username );
363 $isRange = IP::isValidRange( $username );
364
365 $linkRenderer = $sp->getLinkRenderer();
366
367 $tools = [];
368 # No talk pages for IP ranges.
369 if ( !$isRange ) {
370 $tools['user-talk'] = $linkRenderer->makeLink(
371 $talkpage,
372 $sp->msg( 'sp-contributions-talk' )->text()
373 );
374 }
375
376 if ( $sp->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
377 if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
378 $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
379 SpecialPage::getTitleFor( 'Block', $username ),
380 $sp->msg( 'change-blocklink' )->text()
381 );
382 $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
383 SpecialPage::getTitleFor( 'Unblock', $username ),
384 $sp->msg( 'unblocklink' )->text()
385 );
386 } else { # User is not blocked
387 $tools['block'] = $linkRenderer->makeKnownLink( # Block link
388 SpecialPage::getTitleFor( 'Block', $username ),
389 $sp->msg( 'blocklink' )->text()
390 );
391 }
392 }
393
394 # Block log link
395 $tools['log-block'] = $linkRenderer->makeKnownLink(
396 SpecialPage::getTitleFor( 'Log', 'block' ),
397 $sp->msg( 'sp-contributions-blocklog' )->text(),
398 [],
399 [ 'page' => $userpage->getPrefixedText() ]
400 );
401
402 # Suppression log link (T61120)
403 if ( $sp->getUser()->isAllowed( 'suppressionlog' ) ) {
404 $tools['log-suppression'] = $linkRenderer->makeKnownLink(
405 SpecialPage::getTitleFor( 'Log', 'suppress' ),
406 $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
407 [],
408 [ 'offender' => $username ]
409 );
410 }
411
412 # Don't show some links for IP ranges
413 if ( !$isRange ) {
414 # Uploads: hide if IPs cannot upload (T220674)
415 if ( !$isIP || $target->isAllowed( 'upload' ) ) {
416 $tools['uploads'] = $linkRenderer->makeKnownLink(
417 SpecialPage::getTitleFor( 'Listfiles', $username ),
418 $sp->msg( 'sp-contributions-uploads' )->text()
419 );
420 }
421
422 # Other logs link
423 # Todo: T146628
424 $tools['logs'] = $linkRenderer->makeKnownLink(
425 SpecialPage::getTitleFor( 'Log', $username ),
426 $sp->msg( 'sp-contributions-logs' )->text()
427 );
428
429 # Add link to deleted user contributions for priviledged users
430 # Todo: T183457
431 if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) {
432 $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
433 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
434 $sp->msg( 'sp-contributions-deleted', $username )->text()
435 );
436 }
437 }
438
439 # Add a link to change user rights for privileged users
440 $userrightsPage = new UserrightsPage();
441 $userrightsPage->setContext( $sp->getContext() );
442 if ( $userrightsPage->userCanChangeRights( $target ) ) {
443 $tools['userrights'] = $linkRenderer->makeKnownLink(
444 SpecialPage::getTitleFor( 'Userrights', $username ),
445 $sp->msg( 'sp-contributions-userrights', $username )->text()
446 );
447 }
448
449 Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
450
451 return $tools;
452 }
453
454 /**
455 * Generates the namespace selector form with hidden attributes.
456 * @return string HTML fragment
457 */
458 protected function getForm() {
459 $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
460 if ( !isset( $this->opts['target'] ) ) {
461 $this->opts['target'] = '';
462 } else {
463 $this->opts['target'] = str_replace( '_', ' ', $this->opts['target'] );
464 }
465
466 if ( !isset( $this->opts['namespace'] ) ) {
467 $this->opts['namespace'] = '';
468 }
469
470 if ( !isset( $this->opts['nsInvert'] ) ) {
471 $this->opts['nsInvert'] = '';
472 }
473
474 if ( !isset( $this->opts['associated'] ) ) {
475 $this->opts['associated'] = false;
476 }
477
478 if ( !isset( $this->opts['start'] ) ) {
479 $this->opts['start'] = '';
480 }
481
482 if ( !isset( $this->opts['end'] ) ) {
483 $this->opts['end'] = '';
484 }
485
486 if ( !isset( $this->opts['tagfilter'] ) ) {
487 $this->opts['tagfilter'] = '';
488 }
489
490 if ( !isset( $this->opts['topOnly'] ) ) {
491 $this->opts['topOnly'] = false;
492 }
493
494 if ( !isset( $this->opts['newOnly'] ) ) {
495 $this->opts['newOnly'] = false;
496 }
497
498 if ( !isset( $this->opts['hideMinor'] ) ) {
499 $this->opts['hideMinor'] = false;
500 }
501
502 // Modules required only for the form
503 $this->getOutput()->addModules( [
504 'mediawiki.userSuggest',
505 'mediawiki.special.contributions',
506 ] );
507 $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
508 $this->getOutput()->enableOOUI();
509
510 $form = Html::openElement(
511 'form',
512 [
513 'method' => 'get',
514 'action' => wfScript(),
515 'class' => 'mw-contributions-form'
516 ]
517 );
518
519 # Add hidden params for tracking except for parameters in $skipParameters
520 $skipParameters = [
521 'namespace',
522 'nsInvert',
523 'deletedOnly',
524 'target',
525 'contribs',
526 'year',
527 'month',
528 'start',
529 'end',
530 'topOnly',
531 'newOnly',
532 'hideMinor',
533 'associated',
534 'tagfilter'
535 ];
536
537 foreach ( $this->opts as $name => $value ) {
538 if ( in_array( $name, $skipParameters ) ) {
539 continue;
540 }
541 $form .= "\t" . Html::hidden( $name, $value ) . "\n";
542 }
543
544 $tagFilter = ChangeTags::buildTagFilterSelector(
545 $this->opts['tagfilter'], false, $this->getContext() );
546
547 if ( $tagFilter ) {
548 $filterSelection = Html::rawElement(
549 'div',
550 [],
551 implode( "\u{00A0}", $tagFilter )
552 );
553 } else {
554 $filterSelection = Html::rawElement( 'div', [], '' );
555 }
556
557 $labelUsername = Xml::label(
558 $this->msg( 'sp-contributions-username' )->text(),
559 'mw-target-user-or-ip'
560 );
561 $input = Html::input(
562 'target',
563 $this->opts['target'],
564 'text',
565 [
566 'id' => 'mw-target-user-or-ip',
567 'size' => '40',
568 'class' => [
569 'mw-input',
570 'mw-ui-input-inline',
571 'mw-autocomplete-user', // used by mediawiki.userSuggest
572 ],
573 ] + (
574 // Only autofocus if target hasn't been specified
575 $this->opts['target'] ? [] : [ 'autofocus' => true ]
576 )
577 );
578
579 $targetSelection = Html::rawElement(
580 'div',
581 [],
582 $labelUsername . ' ' . $input . ' '
583 );
584
585 $hidden = $this->opts['namespace'] === '' ? ' mw-input-hidden' : '';
586 $namespaceSelection = Xml::tags(
587 'div',
588 [],
589 Xml::label(
590 $this->msg( 'namespace' )->text(),
591 'namespace'
592 ) . "\u{00A0}" .
593 Html::namespaceSelector(
594 [ 'selected' => $this->opts['namespace'], 'all' => '', 'in-user-lang' => true ],
595 [
596 'name' => 'namespace',
597 'id' => 'namespace',
598 'class' => 'namespaceselector',
599 ]
600 ) . "\u{00A0}" .
601 Html::rawElement(
602 'span',
603 [ 'class' => 'mw-input-with-label' . $hidden ],
604 Xml::checkLabel(
605 $this->msg( 'invert' )->text(),
606 'nsInvert',
607 'nsinvert',
608 $this->opts['nsInvert'],
609 [
610 'title' => $this->msg( 'tooltip-invert' )->text(),
611 'class' => 'mw-input'
612 ]
613 ) . "\u{00A0}"
614 ) .
615 Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' . $hidden ],
616 Xml::checkLabel(
617 $this->msg( 'namespace_association' )->text(),
618 'associated',
619 'nsassociated',
620 $this->opts['associated'],
621 [
622 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
623 'class' => 'mw-input'
624 ]
625 ) . "\u{00A0}"
626 )
627 );
628
629 $filters = [];
630
631 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
632 $filters[] = Html::rawElement(
633 'span',
634 [ 'class' => 'mw-input-with-label' ],
635 Xml::checkLabel(
636 $this->msg( 'history-show-deleted' )->text(),
637 'deletedOnly',
638 'mw-show-deleted-only',
639 $this->opts['deletedOnly'],
640 [ 'class' => 'mw-input' ]
641 )
642 );
643 }
644
645 $filters[] = Html::rawElement(
646 'span',
647 [ 'class' => 'mw-input-with-label' ],
648 Xml::checkLabel(
649 $this->msg( 'sp-contributions-toponly' )->text(),
650 'topOnly',
651 'mw-show-top-only',
652 $this->opts['topOnly'],
653 [ 'class' => 'mw-input' ]
654 )
655 );
656 $filters[] = Html::rawElement(
657 'span',
658 [ 'class' => 'mw-input-with-label' ],
659 Xml::checkLabel(
660 $this->msg( 'sp-contributions-newonly' )->text(),
661 'newOnly',
662 'mw-show-new-only',
663 $this->opts['newOnly'],
664 [ 'class' => 'mw-input' ]
665 )
666 );
667 $filters[] = Html::rawElement(
668 'span',
669 [ 'class' => 'mw-input-with-label' ],
670 Xml::checkLabel(
671 $this->msg( 'sp-contributions-hideminor' )->text(),
672 'hideMinor',
673 'mw-hide-minor-edits',
674 $this->opts['hideMinor'],
675 [ 'class' => 'mw-input' ]
676 )
677 );
678
679 Hooks::run(
680 'SpecialContributions::getForm::filters',
681 [ $this, &$filters ]
682 );
683
684 $extraOptions = Html::rawElement(
685 'div',
686 [],
687 implode( '', $filters )
688 );
689
690 $dateRangeSelection = Html::rawElement(
691 'div',
692 [],
693 Xml::label( $this->msg( 'date-range-from' )->text(), 'mw-date-start' ) . ' ' .
694 new DateInputWidget( [
695 'infusable' => true,
696 'id' => 'mw-date-start',
697 'name' => 'start',
698 'value' => $this->opts['start'],
699 'longDisplayFormat' => true,
700 ] ) . '<br>' .
701 Xml::label( $this->msg( 'date-range-to' )->text(), 'mw-date-end' ) . ' ' .
702 new DateInputWidget( [
703 'infusable' => true,
704 'id' => 'mw-date-end',
705 'name' => 'end',
706 'value' => $this->opts['end'],
707 'longDisplayFormat' => true,
708 ] )
709 );
710
711 $submit = Xml::tags( 'div', [],
712 Html::submitButton(
713 $this->msg( 'sp-contributions-submit' )->text(),
714 [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ]
715 )
716 );
717
718 $form .= Xml::fieldset(
719 $this->msg( 'sp-contributions-search' )->text(),
720 $targetSelection .
721 $namespaceSelection .
722 $filterSelection .
723 $extraOptions .
724 $dateRangeSelection .
725 $submit,
726 [ 'class' => 'mw-contributions-table' ]
727 );
728
729 $explain = $this->msg( 'sp-contributions-explain' );
730 if ( !$explain->isBlank() ) {
731 $form .= Html::rawElement(
732 'p', [ 'id' => 'mw-sp-contributions-explain' ], $explain->parse()
733 );
734 }
735
736 $form .= Xml::closeElement( 'form' );
737
738 return $form;
739 }
740
741 /**
742 * Return an array of subpages beginning with $search that this special page will accept.
743 *
744 * @param string $search Prefix to search for
745 * @param int $limit Maximum number of results to return (usually 10)
746 * @param int $offset Number of results to skip (usually 0)
747 * @return string[] Matching subpages
748 */
749 public function prefixSearchSubpages( $search, $limit, $offset ) {
750 $user = User::newFromName( $search );
751 if ( !$user ) {
752 // No prefix suggestion for invalid user
753 return [];
754 }
755 // Autocomplete subpage as user list - public to allow caching
756 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
757 }
758
759 protected function getGroupName() {
760 return 'users';
761 }
762 }