Merge "media: Mark public MediaHandler/ImageHandler methods as such"
[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 $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 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
241 $lag = $lb->safeGetLag( $pager->getDatabase() );
242 if ( $lag > 0 ) {
243 $out->showLagWarning( $lag );
244 }
245
246 $output = $pager->getBody();
247 if ( !$this->including() ) {
248 $output = '<p>' . $pager->getNavigationBar() . '</p>' .
249 $output .
250 '<p>' . $pager->getNavigationBar() . '</p>';
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 ) {
272 if ( !$this->including() ) {
273 if ( !$this->msg( $message, $target )->isDisabled() ) {
274 $out->wrapWikiMsg(
275 "<div class='mw-contributions-footer'>\n$1\n</div>",
276 [ $message, $target ] );
277 }
278 }
279 }
280 }
281 }
282
283 /**
284 * Generates the subheading with links
285 * @param User $userObj User object for the target
286 * @return string Appropriately-escaped HTML to be output literally
287 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
288 * Could be combined.
289 */
290 protected function contributionsSub( $userObj ) {
291 if ( $userObj->isAnon() ) {
292 // Show a warning message that the user being searched for doesn't exists.
293 // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
294 // but returns false for IP ranges. We don't want to suggest either of these are
295 // valid usernames which we would with the 'contributions-userdoesnotexist' message.
296 if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
297 $this->getOutput()->wrapWikiMsg(
298 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
299 [
300 'contributions-userdoesnotexist',
301 wfEscapeWikiText( $userObj->getName() ),
302 ]
303 );
304 if ( !$this->including() ) {
305 $this->getOutput()->setStatusCode( 404 );
306 }
307 }
308 $user = htmlspecialchars( $userObj->getName() );
309 } else {
310 $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
311 }
312 $nt = $userObj->getUserPage();
313 $talk = $userObj->getTalkPage();
314 $links = '';
315 if ( $talk ) {
316 $tools = self::getUserLinks( $this, $userObj );
317 $links = $this->getLanguage()->pipeList( $tools );
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 = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget();
333 }
334
335 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
336 LogEventsList::showLogExtract(
337 $out,
338 'block',
339 $nt,
340 '',
341 [
342 'lim' => 1,
343 'showIfEmpty' => false,
344 'msgKey' => [
345 $userObj->isAnon() ?
346 'sp-contributions-blocked-notice-anon' :
347 'sp-contributions-blocked-notice',
348 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
349 ],
350 'offset' => '' # don't use WebRequest parameter offset
351 ]
352 );
353 }
354 }
355 }
356
357 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
358 }
359
360 /**
361 * Links to different places.
362 *
363 * @note This function is also called in DeletedContributionsPage
364 * @param SpecialPage $sp SpecialPage instance, for context
365 * @param User $target Target user object
366 * @return array
367 */
368 public static function getUserLinks( SpecialPage $sp, User $target ) {
369 $id = $target->getId();
370 $username = $target->getName();
371 $userpage = $target->getUserPage();
372 $talkpage = $target->getTalkPage();
373
374 $linkRenderer = $sp->getLinkRenderer();
375
376 # No talk pages for IP ranges.
377 if ( !IP::isValidRange( $username ) ) {
378 $tools['user-talk'] = $linkRenderer->makeLink(
379 $talkpage,
380 $sp->msg( 'sp-contributions-talk' )->text()
381 );
382 }
383
384 if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) {
385 if ( $sp->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
386 if ( $target->isBlocked() && $target->getBlock()->getType() != Block::TYPE_AUTO ) {
387 $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
388 SpecialPage::getTitleFor( 'Block', $username ),
389 $sp->msg( 'change-blocklink' )->text()
390 );
391 $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
392 SpecialPage::getTitleFor( 'Unblock', $username ),
393 $sp->msg( 'unblocklink' )->text()
394 );
395 } else { # User is not blocked
396 $tools['block'] = $linkRenderer->makeKnownLink( # Block link
397 SpecialPage::getTitleFor( 'Block', $username ),
398 $sp->msg( 'blocklink' )->text()
399 );
400 }
401 }
402
403 # Block log link
404 $tools['log-block'] = $linkRenderer->makeKnownLink(
405 SpecialPage::getTitleFor( 'Log', 'block' ),
406 $sp->msg( 'sp-contributions-blocklog' )->text(),
407 [],
408 [ 'page' => $userpage->getPrefixedText() ]
409 );
410
411 # Suppression log link (T61120)
412 if ( $sp->getUser()->isAllowed( 'suppressionlog' ) ) {
413 $tools['log-suppression'] = $linkRenderer->makeKnownLink(
414 SpecialPage::getTitleFor( 'Log', 'suppress' ),
415 $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
416 [],
417 [ 'offender' => $username ]
418 );
419 }
420 }
421
422 # Don't show some links for IP ranges
423 if ( !IP::isValidRange( $username ) ) {
424 # Uploads
425 $tools['uploads'] = $linkRenderer->makeKnownLink(
426 SpecialPage::getTitleFor( 'Listfiles', $username ),
427 $sp->msg( 'sp-contributions-uploads' )->text()
428 );
429
430 # Other logs link
431 $tools['logs'] = $linkRenderer->makeKnownLink(
432 SpecialPage::getTitleFor( 'Log', $username ),
433 $sp->msg( 'sp-contributions-logs' )->text()
434 );
435
436 # Add link to deleted user contributions for priviledged users
437 if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) {
438 $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
439 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
440 $sp->msg( 'sp-contributions-deleted', $username )->text()
441 );
442 }
443 }
444
445 # Add a link to change user rights for privileged users
446 $userrightsPage = new UserrightsPage();
447 $userrightsPage->setContext( $sp->getContext() );
448 if ( $userrightsPage->userCanChangeRights( $target ) ) {
449 $tools['userrights'] = $linkRenderer->makeKnownLink(
450 SpecialPage::getTitleFor( 'Userrights', $username ),
451 $sp->msg( 'sp-contributions-userrights', $username )->text()
452 );
453 }
454
455 Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
456
457 return $tools;
458 }
459
460 /**
461 * Generates the namespace selector form with hidden attributes.
462 * @return string HTML fragment
463 */
464 protected function getForm() {
465 $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
466 if ( !isset( $this->opts['target'] ) ) {
467 $this->opts['target'] = '';
468 } else {
469 $this->opts['target'] = str_replace( '_', ' ', $this->opts['target'] );
470 }
471
472 if ( !isset( $this->opts['namespace'] ) ) {
473 $this->opts['namespace'] = '';
474 }
475
476 if ( !isset( $this->opts['nsInvert'] ) ) {
477 $this->opts['nsInvert'] = '';
478 }
479
480 if ( !isset( $this->opts['associated'] ) ) {
481 $this->opts['associated'] = false;
482 }
483
484 if ( !isset( $this->opts['contribs'] ) ) {
485 $this->opts['contribs'] = 'user';
486 }
487
488 if ( !isset( $this->opts['start'] ) ) {
489 $this->opts['start'] = '';
490 }
491
492 if ( !isset( $this->opts['end'] ) ) {
493 $this->opts['end'] = '';
494 }
495
496 if ( $this->opts['contribs'] == 'newbie' ) {
497 $this->opts['target'] = '';
498 }
499
500 if ( !isset( $this->opts['tagfilter'] ) ) {
501 $this->opts['tagfilter'] = '';
502 }
503
504 if ( !isset( $this->opts['topOnly'] ) ) {
505 $this->opts['topOnly'] = false;
506 }
507
508 if ( !isset( $this->opts['newOnly'] ) ) {
509 $this->opts['newOnly'] = false;
510 }
511
512 if ( !isset( $this->opts['hideMinor'] ) ) {
513 $this->opts['hideMinor'] = false;
514 }
515
516 // Modules required only for the form
517 $this->getOutput()->addModules( [
518 'mediawiki.userSuggest',
519 'mediawiki.special.contributions',
520 ] );
521 $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
522 $this->getOutput()->enableOOUI();
523
524 $form = Html::openElement(
525 'form',
526 [
527 'method' => 'get',
528 'action' => wfScript(),
529 'class' => 'mw-contributions-form'
530 ]
531 );
532
533 # Add hidden params for tracking except for parameters in $skipParameters
534 $skipParameters = [
535 'namespace',
536 'nsInvert',
537 'deletedOnly',
538 'target',
539 'contribs',
540 'year',
541 'month',
542 'start',
543 'end',
544 'topOnly',
545 'newOnly',
546 'hideMinor',
547 'associated',
548 'tagfilter'
549 ];
550
551 foreach ( $this->opts as $name => $value ) {
552 if ( in_array( $name, $skipParameters ) ) {
553 continue;
554 }
555 $form .= "\t" . Html::hidden( $name, $value ) . "\n";
556 }
557
558 $tagFilter = ChangeTags::buildTagFilterSelector(
559 $this->opts['tagfilter'], false, $this->getContext() );
560
561 if ( $tagFilter ) {
562 $filterSelection = Html::rawElement(
563 'div',
564 [],
565 implode( "\u{00A0}", $tagFilter )
566 );
567 } else {
568 $filterSelection = Html::rawElement( 'div', [], '' );
569 }
570
571 $labelNewbies = Xml::radioLabel(
572 $this->msg( 'sp-contributions-newbies' )->text(),
573 'contribs',
574 'newbie',
575 'newbie',
576 $this->opts['contribs'] == 'newbie',
577 [ 'class' => 'mw-input' ]
578 );
579 $labelUsername = Xml::radioLabel(
580 $this->msg( 'sp-contributions-username' )->text(),
581 'contribs',
582 'user',
583 'user',
584 $this->opts['contribs'] == 'user',
585 [ 'class' => 'mw-input' ]
586 );
587 $input = Html::input(
588 'target',
589 $this->opts['target'],
590 'text',
591 [
592 'size' => '40',
593 'class' => [
594 'mw-input',
595 'mw-ui-input-inline',
596 'mw-autocomplete-user', // used by mediawiki.userSuggest
597 ],
598 ] + (
599 // Only autofocus if target hasn't been specified or in non-newbies mode
600 ( $this->opts['contribs'] === 'newbie' || $this->opts['target'] )
601 ? [] : [ 'autofocus' => true ]
602 )
603 );
604
605 $targetSelection = Html::rawElement(
606 'div',
607 [],
608 $labelNewbies . '<br>' . $labelUsername . ' ' . $input . ' '
609 );
610
611 $namespaceSelection = Xml::tags(
612 'div',
613 [],
614 Xml::label(
615 $this->msg( 'namespace' )->text(),
616 'namespace',
617 ''
618 ) . "\u{00A0}" .
619 Html::namespaceSelector(
620 [ 'selected' => $this->opts['namespace'], 'all' => '', 'in-user-lang' => true ],
621 [
622 'name' => 'namespace',
623 'id' => 'namespace',
624 'class' => 'namespaceselector',
625 ]
626 ) . "\u{00A0}" .
627 Html::rawElement(
628 'span',
629 [ 'class' => 'mw-input-with-label' ],
630 Xml::checkLabel(
631 $this->msg( 'invert' )->text(),
632 'nsInvert',
633 'nsInvert',
634 $this->opts['nsInvert'],
635 [
636 'title' => $this->msg( 'tooltip-invert' )->text(),
637 'class' => 'mw-input'
638 ]
639 ) . "\u{00A0}"
640 ) .
641 Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' ],
642 Xml::checkLabel(
643 $this->msg( 'namespace_association' )->text(),
644 'associated',
645 'associated',
646 $this->opts['associated'],
647 [
648 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
649 'class' => 'mw-input'
650 ]
651 ) . "\u{00A0}"
652 )
653 );
654
655 $filters = [];
656
657 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
658 $filters[] = Html::rawElement(
659 'span',
660 [ 'class' => 'mw-input-with-label' ],
661 Xml::checkLabel(
662 $this->msg( 'history-show-deleted' )->text(),
663 'deletedOnly',
664 'mw-show-deleted-only',
665 $this->opts['deletedOnly'],
666 [ 'class' => 'mw-input' ]
667 )
668 );
669 }
670
671 $filters[] = Html::rawElement(
672 'span',
673 [ 'class' => 'mw-input-with-label' ],
674 Xml::checkLabel(
675 $this->msg( 'sp-contributions-toponly' )->text(),
676 'topOnly',
677 'mw-show-top-only',
678 $this->opts['topOnly'],
679 [ 'class' => 'mw-input' ]
680 )
681 );
682 $filters[] = Html::rawElement(
683 'span',
684 [ 'class' => 'mw-input-with-label' ],
685 Xml::checkLabel(
686 $this->msg( 'sp-contributions-newonly' )->text(),
687 'newOnly',
688 'mw-show-new-only',
689 $this->opts['newOnly'],
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-hideminor' )->text(),
698 'hideMinor',
699 'mw-hide-minor-edits',
700 $this->opts['hideMinor'],
701 [ 'class' => 'mw-input' ]
702 )
703 );
704
705 Hooks::run(
706 'SpecialContributions::getForm::filters',
707 [ $this, &$filters ]
708 );
709
710 $extraOptions = Html::rawElement(
711 'div',
712 [],
713 implode( '', $filters )
714 );
715
716 $dateRangeSelection = Html::rawElement(
717 'div',
718 [],
719 Xml::label( $this->msg( 'date-range-from' )->text(), 'mw-date-start' ) . ' ' .
720 new DateInputWidget( [
721 'infusable' => true,
722 'id' => 'mw-date-start',
723 'name' => 'start',
724 'value' => $this->opts['start'],
725 'longDisplayFormat' => true,
726 ] ) . '<br>' .
727 Xml::label( $this->msg( 'date-range-to' )->text(), 'mw-date-end' ) . ' ' .
728 new DateInputWidget( [
729 'infusable' => true,
730 'id' => 'mw-date-end',
731 'name' => 'end',
732 'value' => $this->opts['end'],
733 'longDisplayFormat' => true,
734 ] )
735 );
736
737 $submit = Xml::tags( 'div', [],
738 Html::submitButton(
739 $this->msg( 'sp-contributions-submit' )->text(),
740 [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ]
741 )
742 );
743
744 $form .= Xml::fieldset(
745 $this->msg( 'sp-contributions-search' )->text(),
746 $targetSelection .
747 $namespaceSelection .
748 $filterSelection .
749 $extraOptions .
750 $dateRangeSelection .
751 $submit,
752 [ 'class' => 'mw-contributions-table' ]
753 );
754
755 $explain = $this->msg( 'sp-contributions-explain' );
756 if ( !$explain->isBlank() ) {
757 $form .= Html::rawElement(
758 'p', [ 'id' => 'mw-sp-contributions-explain' ], $explain->parse()
759 );
760 }
761
762 $form .= Xml::closeElement( 'form' );
763
764 return $form;
765 }
766
767 /**
768 * Return an array of subpages beginning with $search that this special page will accept.
769 *
770 * @param string $search Prefix to search for
771 * @param int $limit Maximum number of results to return (usually 10)
772 * @param int $offset Number of results to skip (usually 0)
773 * @return string[] Matching subpages
774 */
775 public function prefixSearchSubpages( $search, $limit, $offset ) {
776 $user = User::newFromName( $search );
777 if ( !$user ) {
778 // No prefix suggestion for invalid user
779 return [];
780 }
781 // Autocomplete subpage as user list - public to allow caching
782 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
783 }
784
785 protected function getGroupName() {
786 return 'users';
787 }
788 }