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