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