Pagers: Drop 'newbie' feature
[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 ] );
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 # No talk pages for IP ranges.
368 if ( !$isRange ) {
369 $tools['user-talk'] = $linkRenderer->makeLink(
370 $talkpage,
371 $sp->msg( 'sp-contributions-talk' )->text()
372 );
373 }
374
375 if ( $sp->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
376 if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
377 $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
378 SpecialPage::getTitleFor( 'Block', $username ),
379 $sp->msg( 'change-blocklink' )->text()
380 );
381 $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
382 SpecialPage::getTitleFor( 'Unblock', $username ),
383 $sp->msg( 'unblocklink' )->text()
384 );
385 } else { # User is not blocked
386 $tools['block'] = $linkRenderer->makeKnownLink( # Block link
387 SpecialPage::getTitleFor( 'Block', $username ),
388 $sp->msg( 'blocklink' )->text()
389 );
390 }
391 }
392
393 # Block log link
394 $tools['log-block'] = $linkRenderer->makeKnownLink(
395 SpecialPage::getTitleFor( 'Log', 'block' ),
396 $sp->msg( 'sp-contributions-blocklog' )->text(),
397 [],
398 [ 'page' => $userpage->getPrefixedText() ]
399 );
400
401 # Suppression log link (T61120)
402 if ( $sp->getUser()->isAllowed( 'suppressionlog' ) ) {
403 $tools['log-suppression'] = $linkRenderer->makeKnownLink(
404 SpecialPage::getTitleFor( 'Log', 'suppress' ),
405 $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
406 [],
407 [ 'offender' => $username ]
408 );
409 }
410
411 # Don't show some links for IP ranges
412 if ( !$isRange ) {
413 # Uploads: hide if IPs cannot upload (T220674)
414 if ( !$isIP || $target->isAllowed( 'upload' ) ) {
415 $tools['uploads'] = $linkRenderer->makeKnownLink(
416 SpecialPage::getTitleFor( 'Listfiles', $username ),
417 $sp->msg( 'sp-contributions-uploads' )->text()
418 );
419 }
420
421 # Other logs link
422 # Todo: T146628
423 $tools['logs'] = $linkRenderer->makeKnownLink(
424 SpecialPage::getTitleFor( 'Log', $username ),
425 $sp->msg( 'sp-contributions-logs' )->text()
426 );
427
428 # Add link to deleted user contributions for priviledged users
429 # Todo: T183457
430 if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) {
431 $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
432 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
433 $sp->msg( 'sp-contributions-deleted', $username )->text()
434 );
435 }
436 }
437
438 # Add a link to change user rights for privileged users
439 $userrightsPage = new UserrightsPage();
440 $userrightsPage->setContext( $sp->getContext() );
441 if ( $userrightsPage->userCanChangeRights( $target ) ) {
442 $tools['userrights'] = $linkRenderer->makeKnownLink(
443 SpecialPage::getTitleFor( 'Userrights', $username ),
444 $sp->msg( 'sp-contributions-userrights', $username )->text()
445 );
446 }
447
448 Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
449
450 return $tools;
451 }
452
453 /**
454 * Generates the namespace selector form with hidden attributes.
455 * @return string HTML fragment
456 */
457 protected function getForm() {
458 $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
459 if ( !isset( $this->opts['target'] ) ) {
460 $this->opts['target'] = '';
461 } else {
462 $this->opts['target'] = str_replace( '_', ' ', $this->opts['target'] );
463 }
464
465 if ( !isset( $this->opts['namespace'] ) ) {
466 $this->opts['namespace'] = '';
467 }
468
469 if ( !isset( $this->opts['nsInvert'] ) ) {
470 $this->opts['nsInvert'] = '';
471 }
472
473 if ( !isset( $this->opts['associated'] ) ) {
474 $this->opts['associated'] = false;
475 }
476
477 if ( !isset( $this->opts['start'] ) ) {
478 $this->opts['start'] = '';
479 }
480
481 if ( !isset( $this->opts['end'] ) ) {
482 $this->opts['end'] = '';
483 }
484
485 if ( !isset( $this->opts['tagfilter'] ) ) {
486 $this->opts['tagfilter'] = '';
487 }
488
489 if ( !isset( $this->opts['topOnly'] ) ) {
490 $this->opts['topOnly'] = false;
491 }
492
493 if ( !isset( $this->opts['newOnly'] ) ) {
494 $this->opts['newOnly'] = false;
495 }
496
497 if ( !isset( $this->opts['hideMinor'] ) ) {
498 $this->opts['hideMinor'] = false;
499 }
500
501 // Modules required only for the form
502 $this->getOutput()->addModules( [
503 'mediawiki.userSuggest',
504 'mediawiki.special.contributions',
505 ] );
506 $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
507 $this->getOutput()->enableOOUI();
508
509 $form = Html::openElement(
510 'form',
511 [
512 'method' => 'get',
513 'action' => wfScript(),
514 'class' => 'mw-contributions-form'
515 ]
516 );
517
518 # Add hidden params for tracking except for parameters in $skipParameters
519 $skipParameters = [
520 'namespace',
521 'nsInvert',
522 'deletedOnly',
523 'target',
524 'contribs',
525 'year',
526 'month',
527 'start',
528 'end',
529 'topOnly',
530 'newOnly',
531 'hideMinor',
532 'associated',
533 'tagfilter'
534 ];
535
536 foreach ( $this->opts as $name => $value ) {
537 if ( in_array( $name, $skipParameters ) ) {
538 continue;
539 }
540 $form .= "\t" . Html::hidden( $name, $value ) . "\n";
541 }
542
543 $tagFilter = ChangeTags::buildTagFilterSelector(
544 $this->opts['tagfilter'], false, $this->getContext() );
545
546 if ( $tagFilter ) {
547 $filterSelection = Html::rawElement(
548 'div',
549 [],
550 implode( "\u{00A0}", $tagFilter )
551 );
552 } else {
553 $filterSelection = Html::rawElement( 'div', [], '' );
554 }
555
556 $labelUsername = Xml::radioLabel(
557 $this->msg( 'sp-contributions-username' )->text(),
558 'contribs',
559 'user',
560 'user',
561 true,
562 [ 'class' => 'mw-input' ]
563 );
564 $input = Html::input(
565 'target',
566 $this->opts['target'],
567 'text',
568 [
569 'id' => 'mw-target-user-or-ip',
570 'size' => '40',
571 'class' => [
572 'mw-input',
573 'mw-ui-input-inline',
574 'mw-autocomplete-user', // used by mediawiki.userSuggest
575 ],
576 ] + (
577 // Only autofocus if target hasn't been specified
578 $this->opts['target'] ? [] : [ 'autofocus' => true ]
579 )
580 );
581
582 $targetSelection = Html::rawElement(
583 'div',
584 [],
585 $labelUsername . ' ' . $input . ' '
586 );
587
588 $hidden = $this->opts['namespace'] === '' ? ' mw-input-hidden' : '';
589 $namespaceSelection = Xml::tags(
590 'div',
591 [],
592 Xml::label(
593 $this->msg( 'namespace' )->text(),
594 'namespace'
595 ) . "\u{00A0}" .
596 Html::namespaceSelector(
597 [ 'selected' => $this->opts['namespace'], 'all' => '', 'in-user-lang' => true ],
598 [
599 'name' => 'namespace',
600 'id' => 'namespace',
601 'class' => 'namespaceselector',
602 ]
603 ) . "\u{00A0}" .
604 Html::rawElement(
605 'span',
606 [ 'class' => 'mw-input-with-label' . $hidden ],
607 Xml::checkLabel(
608 $this->msg( 'invert' )->text(),
609 'nsInvert',
610 'nsinvert',
611 $this->opts['nsInvert'],
612 [
613 'title' => $this->msg( 'tooltip-invert' )->text(),
614 'class' => 'mw-input'
615 ]
616 ) . "\u{00A0}"
617 ) .
618 Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' . $hidden ],
619 Xml::checkLabel(
620 $this->msg( 'namespace_association' )->text(),
621 'associated',
622 'nsassociated',
623 $this->opts['associated'],
624 [
625 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
626 'class' => 'mw-input'
627 ]
628 ) . "\u{00A0}"
629 )
630 );
631
632 $filters = [];
633
634 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
635 $filters[] = Html::rawElement(
636 'span',
637 [ 'class' => 'mw-input-with-label' ],
638 Xml::checkLabel(
639 $this->msg( 'history-show-deleted' )->text(),
640 'deletedOnly',
641 'mw-show-deleted-only',
642 $this->opts['deletedOnly'],
643 [ 'class' => 'mw-input' ]
644 )
645 );
646 }
647
648 $filters[] = Html::rawElement(
649 'span',
650 [ 'class' => 'mw-input-with-label' ],
651 Xml::checkLabel(
652 $this->msg( 'sp-contributions-toponly' )->text(),
653 'topOnly',
654 'mw-show-top-only',
655 $this->opts['topOnly'],
656 [ 'class' => 'mw-input' ]
657 )
658 );
659 $filters[] = Html::rawElement(
660 'span',
661 [ 'class' => 'mw-input-with-label' ],
662 Xml::checkLabel(
663 $this->msg( 'sp-contributions-newonly' )->text(),
664 'newOnly',
665 'mw-show-new-only',
666 $this->opts['newOnly'],
667 [ 'class' => 'mw-input' ]
668 )
669 );
670 $filters[] = Html::rawElement(
671 'span',
672 [ 'class' => 'mw-input-with-label' ],
673 Xml::checkLabel(
674 $this->msg( 'sp-contributions-hideminor' )->text(),
675 'hideMinor',
676 'mw-hide-minor-edits',
677 $this->opts['hideMinor'],
678 [ 'class' => 'mw-input' ]
679 )
680 );
681
682 Hooks::run(
683 'SpecialContributions::getForm::filters',
684 [ $this, &$filters ]
685 );
686
687 $extraOptions = Html::rawElement(
688 'div',
689 [],
690 implode( '', $filters )
691 );
692
693 $dateRangeSelection = Html::rawElement(
694 'div',
695 [],
696 Xml::label( $this->msg( 'date-range-from' )->text(), 'mw-date-start' ) . ' ' .
697 new DateInputWidget( [
698 'infusable' => true,
699 'id' => 'mw-date-start',
700 'name' => 'start',
701 'value' => $this->opts['start'],
702 'longDisplayFormat' => true,
703 ] ) . '<br>' .
704 Xml::label( $this->msg( 'date-range-to' )->text(), 'mw-date-end' ) . ' ' .
705 new DateInputWidget( [
706 'infusable' => true,
707 'id' => 'mw-date-end',
708 'name' => 'end',
709 'value' => $this->opts['end'],
710 'longDisplayFormat' => true,
711 ] )
712 );
713
714 $submit = Xml::tags( 'div', [],
715 Html::submitButton(
716 $this->msg( 'sp-contributions-submit' )->text(),
717 [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ]
718 )
719 );
720
721 $form .= Xml::fieldset(
722 $this->msg( 'sp-contributions-search' )->text(),
723 $targetSelection .
724 $namespaceSelection .
725 $filterSelection .
726 $extraOptions .
727 $dateRangeSelection .
728 $submit,
729 [ 'class' => 'mw-contributions-table' ]
730 );
731
732 $explain = $this->msg( 'sp-contributions-explain' );
733 if ( !$explain->isBlank() ) {
734 $form .= Html::rawElement(
735 'p', [ 'id' => 'mw-sp-contributions-explain' ], $explain->parse()
736 );
737 }
738
739 $form .= Xml::closeElement( 'form' );
740
741 return $form;
742 }
743
744 /**
745 * Return an array of subpages beginning with $search that this special page will accept.
746 *
747 * @param string $search Prefix to search for
748 * @param int $limit Maximum number of results to return (usually 10)
749 * @param int $offset Number of results to skip (usually 0)
750 * @return string[] Matching subpages
751 */
752 public function prefixSearchSubpages( $search, $limit, $offset ) {
753 $user = User::newFromName( $search );
754 if ( !$user ) {
755 // No prefix suggestion for invalid user
756 return [];
757 }
758 // Autocomplete subpage as user list - public to allow caching
759 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
760 }
761
762 protected function getGroupName() {
763 return 'users';
764 }
765 }