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