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