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