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