ab46ddae117986c6ab1c173b401b78a36e3a3f92
3 * Implements Special:Contributions
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.
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.
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
21 * @ingroup SpecialPage
25 * Special:Contributions, show user contributions in a paged list
27 * @ingroup SpecialPage
29 class SpecialContributions
extends IncludableSpecialPage
{
32 public function __construct() {
33 parent
::__construct( 'Contributions' );
36 public function execute( $par ) {
38 $this->outputHeader();
39 $out = $this->getOutput();
40 $out->addModuleStyles( [
42 'mediawiki.special.changeslist',
44 $this->addHelpLink( 'Help:User contributions' );
47 $request = $this->getRequest();
49 if ( $par !== null ) {
52 $target = $request->getVal( 'target' );
55 if ( $request->getVal( 'contribs' ) == 'newbie' ||
$par === 'newbies' ) {
57 $this->opts
['contribs'] = 'newbie';
59 $this->opts
['contribs'] = 'user';
62 $this->opts
['deletedOnly'] = $request->getBool( 'deletedOnly' );
64 if ( !strlen( $target ) ) {
65 if ( !$this->including() ) {
66 $out->addHTML( $this->getForm() );
72 $user = $this->getUser();
74 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
75 $this->opts
['target'] = $target;
76 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
77 $this->opts
['newOnly'] = $request->getBool( 'newOnly' );
78 $this->opts
['hideMinor'] = $request->getBool( 'hideMinor' );
80 $nt = Title
::makeTitleSafe( NS_USER
, $target );
82 $out->addHTML( $this->getForm() );
86 $userObj = User
::newFromName( $nt->getText(), false );
88 $out->addHTML( $this->getForm() );
92 $id = $userObj->getId();
94 if ( $this->opts
['contribs'] != 'newbie' ) {
95 $target = $nt->getText();
96 $out->addSubtitle( $this->contributionsSub( $userObj ) );
97 $out->setHTMLTitle( $this->msg(
99 $this->msg( 'contributions-title', $target )->plain()
100 )->inContentLanguage() );
101 $this->getSkin()->setRelevantUser( $userObj );
103 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
104 $out->setHTMLTitle( $this->msg(
106 $this->msg( 'sp-contributions-newbies-title' )->plain()
107 )->inContentLanguage() );
110 $ns = $request->getVal( 'namespace', null );
111 if ( $ns !== null && $ns !== '' ) {
112 $this->opts
['namespace'] = intval( $ns );
114 $this->opts
['namespace'] = '';
117 $this->opts
['associated'] = $request->getBool( 'associated' );
118 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
119 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
121 // Allows reverts to have the bot flag in recent changes. It is just here to
122 // be passed in the form at the top of the page
123 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
124 $this->opts
['bot'] = '1';
127 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
128 # Offset overrides year/month selection
130 $this->opts
['year'] = '';
131 $this->opts
['month'] = '';
133 $this->opts
['year'] = $request->getIntOrNull( 'year' );
134 $this->opts
['month'] = $request->getIntOrNull( 'month' );
137 $feedType = $request->getVal( 'feed' );
140 'action' => 'feedcontributions',
143 if ( $this->opts
['topOnly'] ) {
144 $feedParams['toponly'] = true;
146 if ( $this->opts
['newOnly'] ) {
147 $feedParams['newonly'] = true;
149 if ( $this->opts
['hideMinor'] ) {
150 $feedParams['hideminor'] = true;
152 if ( $this->opts
['deletedOnly'] ) {
153 $feedParams['deletedonly'] = true;
155 if ( $this->opts
['tagfilter'] !== '' ) {
156 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
158 if ( $this->opts
['namespace'] !== '' ) {
159 $feedParams['namespace'] = $this->opts
['namespace'];
161 // Don't use year and month for the feed URL, but pass them on if
162 // we redirect to API (if $feedType is specified)
163 if ( $feedType && $this->opts
['year'] !== null ) {
164 $feedParams['year'] = $this->opts
['year'];
166 if ( $feedType && $this->opts
['month'] !== null ) {
167 $feedParams['month'] = $this->opts
['month'];
171 // Maintain some level of backwards compatibility
172 // If people request feeds using the old parameters, redirect to API
173 $feedParams['feedformat'] = $feedType;
174 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
176 $out->redirect( $url, '301' );
181 // Add RSS/atom links
182 $this->addFeedLinks( $feedParams );
184 if ( Hooks
::run( 'SpecialContributionsBeforeMainOutput', [ $id, $userObj, $this ] ) ) {
185 if ( !$this->including() ) {
186 $out->addHTML( $this->getForm() );
188 $pager = new ContribsPager( $this->getContext(), [
190 'contribs' => $this->opts
['contribs'],
191 'namespace' => $this->opts
['namespace'],
192 'tagfilter' => $this->opts
['tagfilter'],
193 'year' => $this->opts
['year'],
194 'month' => $this->opts
['month'],
195 'deletedOnly' => $this->opts
['deletedOnly'],
196 'topOnly' => $this->opts
['topOnly'],
197 'newOnly' => $this->opts
['newOnly'],
198 'hideMinor' => $this->opts
['hideMinor'],
199 'nsInvert' => $this->opts
['nsInvert'],
200 'associated' => $this->opts
['associated'],
203 if ( !$pager->getNumRows() ) {
204 $out->addWikiMsg( 'nocontribs', $target );
206 # Show a message about slave lag, if applicable
207 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
209 $out->showLagWarning( $lag );
212 $output = $pager->getBody();
213 if ( !$this->including() ) {
214 $output = '<p>' . $pager->getNavigationBar() . '</p>' .
216 '<p>' . $pager->getNavigationBar() . '</p>';
218 $out->addHTML( $output );
220 $out->preventClickjacking( $pager->getPreventClickjacking() );
222 # Show the appropriate "footer" message - WHOIS tools, etc.
223 if ( $this->opts
['contribs'] == 'newbie' ) {
224 $message = 'sp-contributions-footer-newbies';
225 } elseif ( IP
::isIPAddress( $target ) ) {
226 $message = 'sp-contributions-footer-anon';
227 } elseif ( $userObj->isAnon() ) {
228 // No message for non-existing users
231 $message = 'sp-contributions-footer';
235 if ( !$this->including() ) {
236 if ( !$this->msg( $message, $target )->isDisabled() ) {
238 "<div class='mw-contributions-footer'>\n$1\n</div>",
239 [ $message, $target ] );
247 * Generates the subheading with links
248 * @param User $userObj User object for the target
249 * @return string Appropriately-escaped HTML to be output literally
250 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
253 protected function contributionsSub( $userObj ) {
254 if ( $userObj->isAnon() ) {
255 // Show a warning message that the user being searched for doesn't exists
256 if ( !User
::isIP( $userObj->getName() ) ) {
257 $this->getOutput()->wrapWikiMsg(
258 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
260 'contributions-userdoesnotexist',
261 wfEscapeWikiText( $userObj->getName() ),
264 if ( !$this->including() ) {
265 $this->getOutput()->setStatusCode( 404 );
268 $user = htmlspecialchars( $userObj->getName() );
270 $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
272 $nt = $userObj->getUserPage();
273 $talk = $userObj->getTalkPage();
276 $tools = $this->getUserLinks( $nt, $talk, $userObj );
277 $links = $this->getLanguage()->pipeList( $tools );
279 // Show a note if the user is blocked and display the last block log entry.
280 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
281 // and also this will display a totally irrelevant log entry as a current block.
282 if ( !$this->including() ) {
283 $block = Block
::newFromTarget( $userObj, $userObj );
284 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
285 if ( $block->getType() == Block
::TYPE_RANGE
) {
286 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
289 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
290 LogEventsList
::showLogExtract(
297 'showIfEmpty' => false,
300 'sp-contributions-blocked-notice-anon' :
301 'sp-contributions-blocked-notice',
302 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
304 'offset' => '' # don't use WebRequest parameter offset
311 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
315 * Links to different places.
316 * @param Title $userpage Target user page
317 * @param Title $talkpage Talk page
318 * @param User $target Target user object
321 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
323 $id = $target->getId();
324 $username = $target->getName();
326 $linkRenderer = $this->getLinkRenderer();
327 $tools[] = $linkRenderer->makeLink( $talkpage, $this->msg( 'sp-contributions-talk' )->text() );
329 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
330 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
331 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
332 $tools[] = $linkRenderer->makeKnownLink( # Change block link
333 SpecialPage
::getTitleFor( 'Block', $username ),
334 $this->msg( 'change-blocklink' )->text()
336 $tools[] = $linkRenderer->makeKnownLink( # Unblock link
337 SpecialPage
::getTitleFor( 'Unblock', $username ),
338 $this->msg( 'unblocklink' )->text()
340 } else { # User is not blocked
341 $tools[] = $linkRenderer->makeKnownLink( # Block link
342 SpecialPage
::getTitleFor( 'Block', $username ),
343 $this->msg( 'blocklink' )->text()
349 $tools[] = $linkRenderer->makeKnownLink(
350 SpecialPage
::getTitleFor( 'Log', 'block' ),
351 $this->msg( 'sp-contributions-blocklog' )->text(),
353 [ 'page' => $userpage->getPrefixedText() ]
356 # Suppression log link (bug 59120)
357 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
358 $tools[] = $linkRenderer->makeKnownLink(
359 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
360 $this->msg( 'sp-contributions-suppresslog' )->text(),
362 [ 'offender' => $username ]
367 $tools[] = $linkRenderer->makeKnownLink(
368 SpecialPage
::getTitleFor( 'Listfiles', $username ),
369 $this->msg( 'sp-contributions-uploads' )->text()
373 $tools[] = $linkRenderer->makeKnownLink(
374 SpecialPage
::getTitleFor( 'Log', $username ),
375 $this->msg( 'sp-contributions-logs' )->text()
378 # Add link to deleted user contributions for priviledged users
379 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
380 $tools[] = $linkRenderer->makeKnownLink(
381 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
382 $this->msg( 'sp-contributions-deleted' )->text()
386 # Add a link to change user rights for privileged users
387 $userrightsPage = new UserrightsPage();
388 $userrightsPage->setContext( $this->getContext() );
389 if ( $userrightsPage->userCanChangeRights( $target ) ) {
390 $tools[] = $linkRenderer->makeKnownLink(
391 SpecialPage
::getTitleFor( 'Userrights', $username ),
392 $this->msg( 'sp-contributions-userrights' )->text()
396 Hooks
::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $this ] );
402 * Generates the namespace selector form with hidden attributes.
403 * @return string HTML fragment
405 protected function getForm() {
406 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
407 if ( !isset( $this->opts
['target'] ) ) {
408 $this->opts
['target'] = '';
410 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
413 if ( !isset( $this->opts
['namespace'] ) ) {
414 $this->opts
['namespace'] = '';
417 if ( !isset( $this->opts
['nsInvert'] ) ) {
418 $this->opts
['nsInvert'] = '';
421 if ( !isset( $this->opts
['associated'] ) ) {
422 $this->opts
['associated'] = false;
425 if ( !isset( $this->opts
['contribs'] ) ) {
426 $this->opts
['contribs'] = 'user';
429 if ( !isset( $this->opts
['year'] ) ) {
430 $this->opts
['year'] = '';
433 if ( !isset( $this->opts
['month'] ) ) {
434 $this->opts
['month'] = '';
437 if ( $this->opts
['contribs'] == 'newbie' ) {
438 $this->opts
['target'] = '';
441 if ( !isset( $this->opts
['tagfilter'] ) ) {
442 $this->opts
['tagfilter'] = '';
445 if ( !isset( $this->opts
['topOnly'] ) ) {
446 $this->opts
['topOnly'] = false;
449 if ( !isset( $this->opts
['newOnly'] ) ) {
450 $this->opts
['newOnly'] = false;
453 if ( !isset( $this->opts
['hideMinor'] ) ) {
454 $this->opts
['hideMinor'] = false;
457 $form = Html
::openElement(
461 'action' => wfScript(),
462 'class' => 'mw-contributions-form'
466 # Add hidden params for tracking except for parameters in $skipParameters
482 foreach ( $this->opts
as $name => $value ) {
483 if ( in_array( $name, $skipParameters ) ) {
486 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
489 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
492 $filterSelection = Html
::rawElement(
495 implode( ' ', $tagFilter )
498 $filterSelection = Html
::rawElement( 'td', [ 'colspan' => 2 ], '' );
501 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
503 $labelNewbies = Xml
::radioLabel(
504 $this->msg( 'sp-contributions-newbies' )->text(),
508 $this->opts
['contribs'] == 'newbie',
509 [ 'class' => 'mw-input' ]
511 $labelUsername = Xml
::radioLabel(
512 $this->msg( 'sp-contributions-username' )->text(),
516 $this->opts
['contribs'] == 'user',
517 [ 'class' => 'mw-input' ]
519 $input = Html
::input(
521 $this->opts
['target'],
528 'mw-ui-input-inline',
529 'mw-autocomplete-user', // used by mediawiki.userSuggest
532 // Only autofocus if target hasn't been specified or in non-newbies mode
533 ( $this->opts
['contribs'] === 'newbie' ||
$this->opts
['target'] )
534 ?
[] : [ 'autofocus' => true ]
538 $targetSelection = Html
::rawElement(
541 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
544 $namespaceSelection = Xml
::tags(
548 $this->msg( 'namespace' )->text(),
552 Html
::namespaceSelector(
553 [ 'selected' => $this->opts
['namespace'], 'all' => '' ],
555 'name' => 'namespace',
557 'class' => 'namespaceselector',
562 [ 'class' => 'mw-input-with-label' ],
564 $this->msg( 'invert' )->text(),
567 $this->opts
['nsInvert'],
569 'title' => $this->msg( 'tooltip-invert' )->text(),
570 'class' => 'mw-input'
574 Html
::rawElement( 'span', [ 'class' => 'mw-input-with-label' ],
576 $this->msg( 'namespace_association' )->text(),
579 $this->opts
['associated'],
581 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
582 'class' => 'mw-input'
590 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
591 $filters[] = Html
::rawElement(
593 [ 'class' => 'mw-input-with-label' ],
595 $this->msg( 'history-show-deleted' )->text(),
597 'mw-show-deleted-only',
598 $this->opts
['deletedOnly'],
599 [ 'class' => 'mw-input' ]
604 $filters[] = Html
::rawElement(
606 [ 'class' => 'mw-input-with-label' ],
608 $this->msg( 'sp-contributions-toponly' )->text(),
611 $this->opts
['topOnly'],
612 [ 'class' => 'mw-input' ]
615 $filters[] = Html
::rawElement(
617 [ 'class' => 'mw-input-with-label' ],
619 $this->msg( 'sp-contributions-newonly' )->text(),
622 $this->opts
['newOnly'],
623 [ 'class' => 'mw-input' ]
626 $filters[] = Html
::rawElement(
628 [ 'class' => 'mw-input-with-label' ],
630 $this->msg( 'sp-contributions-hideminor' )->text(),
632 'mw-hide-minor-edits',
633 $this->opts
['hideMinor'],
634 [ 'class' => 'mw-input' ]
639 'SpecialContributions::getForm::filters',
643 $extraOptions = Html
::rawElement(
646 implode( '', $filters )
649 $dateSelectionAndSubmit = Xml
::tags( 'td', [ 'colspan' => 2 ],
651 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
655 $this->msg( 'sp-contributions-submit' )->text(),
656 [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ]
660 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
661 $form .= Html
::rawElement( 'table', [ 'class' => 'mw-contributions-table' ], "\n" .
662 Html
::rawElement( 'tr', [], $targetSelection ) . "\n" .
663 Html
::rawElement( 'tr', [], $namespaceSelection ) . "\n" .
664 Html
::rawElement( 'tr', [], $filterSelection ) . "\n" .
665 Html
::rawElement( 'tr', [], $extraOptions ) . "\n" .
666 Html
::rawElement( 'tr', [], $dateSelectionAndSubmit ) . "\n"
669 $explain = $this->msg( 'sp-contributions-explain' );
670 if ( !$explain->isBlank() ) {
671 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
674 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
680 * Return an array of subpages beginning with $search that this special page will accept.
682 * @param string $search Prefix to search for
683 * @param int $limit Maximum number of results to return (usually 10)
684 * @param int $offset Number of results to skip (usually 0)
685 * @return string[] Matching subpages
687 public function prefixSearchSubpages( $search, $limit, $offset ) {
688 $user = User
::newFromName( $search );
690 // No prefix suggestion for invalid user
693 // Autocomplete subpage as user list - public to allow caching
694 return UserNamePrefixSearch
::search( 'public', $search, $limit, $offset );
697 protected function getGroupName() {