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