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( 'mediawiki.special' );
41 $this->addHelpLink( 'Help:User contributions' );
43 $this->opts
= array();
44 $request = $this->getRequest();
46 if ( $par !== null ) {
49 $target = $request->getVal( 'target' );
53 if ( $request->getVal( 'contribs' ) == 'newbie' ) {
55 $this->opts
['contribs'] = 'newbie';
56 } elseif ( $par === 'newbies' ) { // b/c for WMF
58 $this->opts
['contribs'] = 'newbie';
60 $this->opts
['contribs'] = 'user';
63 $this->opts
['deletedOnly'] = $request->getBool( 'deletedOnly' );
65 if ( !strlen( $target ) ) {
66 if ( !$this->including() ) {
67 $out->addHTML( $this->getForm() );
73 $user = $this->getUser();
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' );
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
['deletedOnly'] ) {
150 $feedParams['deletedonly'] = true;
152 if ( $this->opts
['tagfilter'] !== '' ) {
153 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
155 if ( $this->opts
['namespace'] !== '' ) {
156 $feedParams['namespace'] = $this->opts
['namespace'];
158 // Don't use year and month for the feed URL, but pass them on if
159 // we redirect to API (if $feedType is specified)
160 if ( $feedType && $this->opts
['year'] !== null ) {
161 $feedParams['year'] = $this->opts
['year'];
163 if ( $feedType && $this->opts
['month'] !== null ) {
164 $feedParams['month'] = $this->opts
['month'];
168 // Maintain some level of backwards compatibility
169 // If people request feeds using the old parameters, redirect to API
170 $feedParams['feedformat'] = $feedType;
171 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
173 $out->redirect( $url, '301' );
178 // Add RSS/atom links
179 $this->addFeedLinks( $feedParams );
181 if ( Hooks
::run( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) {
182 if ( !$this->including() ) {
183 $out->addHTML( $this->getForm() );
185 $pager = new ContribsPager( $this->getContext(), array(
187 'contribs' => $this->opts
['contribs'],
188 'namespace' => $this->opts
['namespace'],
189 'tagfilter' => $this->opts
['tagfilter'],
190 'year' => $this->opts
['year'],
191 'month' => $this->opts
['month'],
192 'deletedOnly' => $this->opts
['deletedOnly'],
193 'topOnly' => $this->opts
['topOnly'],
194 'newOnly' => $this->opts
['newOnly'],
195 'nsInvert' => $this->opts
['nsInvert'],
196 'associated' => $this->opts
['associated'],
199 if ( !$pager->getNumRows() ) {
200 $out->addWikiMsg( 'nocontribs', $target );
202 # Show a message about slave lag, if applicable
203 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
205 $out->showLagWarning( $lag );
208 $output = $pager->getBody();
209 if ( !$this->including() ) {
210 $output = '<p>' . $pager->getNavigationBar() . '</p>' .
212 '<p>' . $pager->getNavigationBar() . '</p>';
214 $out->addHTML( $output );
216 $out->preventClickjacking( $pager->getPreventClickjacking() );
218 # Show the appropriate "footer" message - WHOIS tools, etc.
219 if ( $this->opts
['contribs'] == 'newbie' ) {
220 $message = 'sp-contributions-footer-newbies';
221 } elseif ( IP
::isIPAddress( $target ) ) {
222 $message = 'sp-contributions-footer-anon';
223 } elseif ( $userObj->isAnon() ) {
224 // No message for non-existing users
227 $message = 'sp-contributions-footer';
231 if ( !$this->including() ) {
232 if ( !$this->msg( $message, $target )->isDisabled() ) {
234 "<div class='mw-contributions-footer'>\n$1\n</div>",
235 array( $message, $target ) );
243 * Generates the subheading with links
244 * @param User $userObj User object for the target
245 * @return string Appropriately-escaped HTML to be output literally
246 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
249 protected function contributionsSub( $userObj ) {
250 if ( $userObj->isAnon() ) {
251 // Show a warning message that the user being searched for doesn't exists
252 if ( !User
::isIP( $userObj->getName() ) ) {
253 $this->getOutput()->wrapWikiMsg(
254 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
256 'contributions-userdoesnotexist',
257 wfEscapeWikiText( $userObj->getName() ),
260 if ( !$this->including() ) {
261 $this->getOutput()->setStatusCode( 404 );
264 $user = htmlspecialchars( $userObj->getName() );
266 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
268 $nt = $userObj->getUserPage();
269 $talk = $userObj->getTalkPage();
272 $tools = $this->getUserLinks( $nt, $talk, $userObj );
273 $links = $this->getLanguage()->pipeList( $tools );
275 // Show a note if the user is blocked and display the last block log entry.
276 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
277 // and also this will display a totally irrelevant log entry as a current block.
278 if ( !$this->including() ) {
279 $block = Block
::newFromTarget( $userObj, $userObj );
280 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
281 if ( $block->getType() == Block
::TYPE_RANGE
) {
282 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
285 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
286 LogEventsList
::showLogExtract(
293 'showIfEmpty' => false,
296 'sp-contributions-blocked-notice-anon' :
297 'sp-contributions-blocked-notice',
298 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
300 'offset' => '' # don't use WebRequest parameter offset
307 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
311 * Links to different places.
312 * @param Title $userpage Target user page
313 * @param Title $talkpage Talk page
314 * @param User $target Target user object
317 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
319 $id = $target->getId();
320 $username = $target->getName();
322 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
324 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
325 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
326 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
327 $tools[] = Linker
::linkKnown( # Change block link
328 SpecialPage
::getTitleFor( 'Block', $username ),
329 $this->msg( 'change-blocklink' )->escaped()
331 $tools[] = Linker
::linkKnown( # Unblock link
332 SpecialPage
::getTitleFor( 'Unblock', $username ),
333 $this->msg( 'unblocklink' )->escaped()
335 } else { # User is not blocked
336 $tools[] = Linker
::linkKnown( # Block link
337 SpecialPage
::getTitleFor( 'Block', $username ),
338 $this->msg( 'blocklink' )->escaped()
344 $tools[] = Linker
::linkKnown(
345 SpecialPage
::getTitleFor( 'Log', 'block' ),
346 $this->msg( 'sp-contributions-blocklog' )->escaped(),
348 array( 'page' => $userpage->getPrefixedText() )
351 # Suppression log link (bug 59120)
352 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
353 $tools[] = Linker
::linkKnown(
354 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
355 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
357 array( 'offender' => $username )
362 $tools[] = Linker
::linkKnown(
363 SpecialPage
::getTitleFor( 'Listfiles', $username ),
364 $this->msg( 'sp-contributions-uploads' )->escaped()
368 $tools[] = Linker
::linkKnown(
369 SpecialPage
::getTitleFor( 'Log', $username ),
370 $this->msg( 'sp-contributions-logs' )->escaped()
373 # Add link to deleted user contributions for priviledged users
374 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
375 $tools[] = Linker
::linkKnown(
376 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
377 $this->msg( 'sp-contributions-deleted' )->escaped()
381 # Add a link to change user rights for privileged users
382 $userrightsPage = new UserrightsPage();
383 $userrightsPage->setContext( $this->getContext() );
384 if ( $userrightsPage->userCanChangeRights( $target ) ) {
385 $tools[] = Linker
::linkKnown(
386 SpecialPage
::getTitleFor( 'Userrights', $username ),
387 $this->msg( 'sp-contributions-userrights' )->escaped()
391 Hooks
::run( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
397 * Generates the namespace selector form with hidden attributes.
398 * @return string HTML fragment
400 protected function getForm() {
401 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
402 if ( !isset( $this->opts
['target'] ) ) {
403 $this->opts
['target'] = '';
405 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
408 if ( !isset( $this->opts
['namespace'] ) ) {
409 $this->opts
['namespace'] = '';
412 if ( !isset( $this->opts
['nsInvert'] ) ) {
413 $this->opts
['nsInvert'] = '';
416 if ( !isset( $this->opts
['associated'] ) ) {
417 $this->opts
['associated'] = false;
420 if ( !isset( $this->opts
['contribs'] ) ) {
421 $this->opts
['contribs'] = 'user';
424 if ( !isset( $this->opts
['year'] ) ) {
425 $this->opts
['year'] = '';
428 if ( !isset( $this->opts
['month'] ) ) {
429 $this->opts
['month'] = '';
432 if ( $this->opts
['contribs'] == 'newbie' ) {
433 $this->opts
['target'] = '';
436 if ( !isset( $this->opts
['tagfilter'] ) ) {
437 $this->opts
['tagfilter'] = '';
440 if ( !isset( $this->opts
['topOnly'] ) ) {
441 $this->opts
['topOnly'] = false;
444 if ( !isset( $this->opts
['newOnly'] ) ) {
445 $this->opts
['newOnly'] = false;
448 $form = Html
::openElement(
452 'action' => wfScript(),
453 'class' => 'mw-contributions-form'
457 # Add hidden params for tracking except for parameters in $skipParameters
458 $skipParameters = array(
472 foreach ( $this->opts
as $name => $value ) {
473 if ( in_array( $name, $skipParameters ) ) {
476 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
479 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
482 $filterSelection = Html
::rawElement(
485 implode( ' ', $tagFilter )
488 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
491 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
493 $labelNewbies = Xml
::radioLabel(
494 $this->msg( 'sp-contributions-newbies' )->text(),
498 $this->opts
['contribs'] == 'newbie',
499 array( 'class' => 'mw-input' )
501 $labelUsername = Xml
::radioLabel(
502 $this->msg( 'sp-contributions-username' )->text(),
506 $this->opts
['contribs'] == 'user',
507 array( 'class' => 'mw-input' )
509 $input = Html
::input(
511 $this->opts
['target'],
518 'mw-ui-input-inline',
519 'mw-autocomplete-user', // used by mediawiki.userSuggest
522 // Only autofocus if target hasn't been specified or in non-newbies mode
523 ( $this->opts
['contribs'] === 'newbie' ||
$this->opts
['target'] )
524 ?
array() : array( 'autofocus' => true )
528 $targetSelection = Html
::rawElement(
530 array( 'colspan' => 2 ),
531 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
534 $namespaceSelection = Xml
::tags(
538 $this->msg( 'namespace' )->text(),
542 Html
::namespaceSelector(
543 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
545 'name' => 'namespace',
547 'class' => 'namespaceselector',
552 array( 'class' => 'mw-input-with-label' ),
554 $this->msg( 'invert' )->text(),
557 $this->opts
['nsInvert'],
559 'title' => $this->msg( 'tooltip-invert' )->text(),
560 'class' => 'mw-input'
564 Html
::rawElement( 'span', array( 'class' => 'mw-input-with-label' ),
566 $this->msg( 'namespace_association' )->text(),
569 $this->opts
['associated'],
571 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
572 'class' => 'mw-input'
578 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
579 $deletedOnlyCheck = Html
::rawElement(
581 array( 'class' => 'mw-input-with-label' ),
583 $this->msg( 'history-show-deleted' )->text(),
585 'mw-show-deleted-only',
586 $this->opts
['deletedOnly'],
587 array( 'class' => 'mw-input' )
591 $deletedOnlyCheck = '';
594 $checkLabelTopOnly = Html
::rawElement(
596 array( 'class' => 'mw-input-with-label' ),
598 $this->msg( 'sp-contributions-toponly' )->text(),
601 $this->opts
['topOnly'],
602 array( 'class' => 'mw-input' )
605 $checkLabelNewOnly = Html
::rawElement(
607 array( 'class' => 'mw-input-with-label' ),
609 $this->msg( 'sp-contributions-newonly' )->text(),
612 $this->opts
['newOnly'],
613 array( 'class' => 'mw-input' )
616 $extraOptions = Html
::rawElement(
618 array( 'colspan' => 2 ),
619 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
622 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
624 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
628 $this->msg( 'sp-contributions-submit' )->text(),
629 array( 'class' => 'mw-submit' ), array( 'mw-ui-progressive' )
633 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
634 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
635 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
636 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
637 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
638 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
639 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
642 $explain = $this->msg( 'sp-contributions-explain' );
643 if ( !$explain->isBlank() ) {
644 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
647 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
652 protected function getGroupName() {
658 * Pager for Special:Contributions
659 * @ingroup SpecialPage Pager
661 class ContribsPager
extends ReverseChronologicalPager
{
662 public $mDefaultDirection = IndexPager
::DIR_DESCENDING
;
665 public $namespace = '';
667 public $preventClickjacking = false;
669 /** @var IDatabase */
670 public $mDbSecondary;
675 protected $mParentLens;
677 function __construct( IContextSource
$context, array $options ) {
678 parent
::__construct( $context );
687 foreach ( $msgs as $msg ) {
688 $this->messages
[$msg] = $this->msg( $msg )->escaped();
691 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
692 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
693 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
694 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
695 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
696 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
698 $this->deletedOnly
= !empty( $options['deletedOnly'] );
699 $this->topOnly
= !empty( $options['topOnly'] );
700 $this->newOnly
= !empty( $options['newOnly'] );
702 $year = isset( $options['year'] ) ?
$options['year'] : false;
703 $month = isset( $options['month'] ) ?
$options['month'] : false;
704 $this->getDateCond( $year, $month );
706 // Most of this code will use the 'contributions' group DB, which can map to slaves
707 // with extra user based indexes or partioning by user. The additional metadata
708 // queries should use a regular slave since the lookup pattern is not all by user.
709 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
710 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
713 function getDefaultQuery() {
714 $query = parent
::getDefaultQuery();
715 $query['target'] = $this->target
;
721 * This method basically executes the exact same code as the parent class, though with
722 * a hook added, to allow extensions to add additional queries.
724 * @param string $offset Index offset, inclusive
725 * @param int $limit Exact query limit
726 * @param bool $descending Query direction, false for ascending, true for descending
727 * @return ResultWrapper
729 function reallyDoQuery( $offset, $limit, $descending ) {
730 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
737 * This hook will allow extensions to add in additional queries, so they can get their data
738 * in My Contributions as well. Extensions should append their results to the $data array.
740 * Extension queries have to implement the navbar requirement as well. They should
741 * - have a column aliased as $pager->getIndexField()
743 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
744 * - have the ORDER BY specified based upon the details provided by the navbar
746 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
748 * &$data: an array of results of all contribs queries
749 * $pager: the ContribsPager object hooked into
750 * $offset: see phpdoc above
751 * $limit: see phpdoc above
752 * $descending: see phpdoc above
754 $data = array( $this->mDb
->select(
755 $tables, $fields, $conds, $fname, $options, $join_conds
758 'ContribsPager::reallyDoQuery',
759 array( &$data, $this, $offset, $limit, $descending )
764 // loop all results and collect them in an array
765 foreach ( $data as $query ) {
766 foreach ( $query as $i => $row ) {
767 // use index column as key, allowing us to easily sort in PHP
768 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
780 $result = array_slice( $result, 0, $limit );
782 // get rid of array keys
783 $result = array_values( $result );
785 return new FakeResultWrapper( $result );
788 function getQueryInfo() {
789 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
791 $user = $this->getUser();
792 $conds = array_merge( $userCond, $this->getNamespaceCond() );
794 // Paranoia: avoid brute force searches (bug 17342)
795 if ( !$user->isAllowed( 'deletedhistory' ) ) {
796 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
797 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
798 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
799 ' != ' . Revision
::SUPPRESSED_USER
;
802 # Don't include orphaned revisions
803 $join_cond['page'] = Revision
::pageJoinCond();
804 # Get the current user name for accounts
805 $join_cond['user'] = Revision
::userJoinCond();
809 $options['USE INDEX'] = array( 'revision' => $index );
814 'fields' => array_merge(
815 Revision
::selectFields(),
816 Revision
::selectUserFields(),
817 array( 'page_namespace', 'page_title', 'page_is_new',
818 'page_latest', 'page_is_redirect', 'page_len' )
821 'options' => $options,
822 'join_conds' => $join_cond
825 ChangeTags
::modifyDisplayQuery(
826 $queryInfo['tables'],
827 $queryInfo['fields'],
829 $queryInfo['join_conds'],
830 $queryInfo['options'],
834 Hooks
::run( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
839 function getUserCond() {
840 $condition = array();
841 $join_conds = array();
842 $tables = array( 'revision', 'page', 'user' );
844 if ( $this->contribs
== 'newbie' ) {
845 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
846 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
847 # ignore local groups with the bot right
848 # @todo FIXME: Global groups may have 'bot' rights
849 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
850 if ( count( $groupsWithBotPermission ) ) {
851 $tables[] = 'user_groups';
852 $condition[] = 'ug_group IS NULL';
853 $join_conds['user_groups'] = array(
855 'ug_user = rev_user',
856 'ug_group' => $groupsWithBotPermission
861 $uid = User
::idFromName( $this->target
);
863 $condition['rev_user'] = $uid;
864 $index = 'user_timestamp';
866 $condition['rev_user_text'] = $this->target
;
867 $index = 'usertext_timestamp';
871 if ( $this->deletedOnly
) {
872 $condition[] = 'rev_deleted != 0';
875 if ( $this->topOnly
) {
876 $condition[] = 'rev_id = page_latest';
879 if ( $this->newOnly
) {
880 $condition[] = 'rev_parent_id = 0';
883 return array( $tables, $index, $condition, $join_conds );
886 function getNamespaceCond() {
887 if ( $this->namespace !== '' ) {
888 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
889 $eq_op = $this->nsInvert ?
'!=' : '=';
890 $bool_op = $this->nsInvert ?
'AND' : 'OR';
892 if ( !$this->associated
) {
893 return array( "page_namespace $eq_op $selectedNS" );
896 $associatedNS = $this->mDb
->addQuotes(
897 MWNamespace
::getAssociated( $this->namespace )
901 "page_namespace $eq_op $selectedNS " .
903 " page_namespace $eq_op $associatedNS"
910 function getIndexField() {
911 return 'rev_timestamp';
914 function doBatchLookups() {
915 # Do a link batch query
916 $this->mResult
->seek( 0 );
918 $batch = new LinkBatch();
919 # Give some pointers to make (last) links
920 foreach ( $this->mResult
as $row ) {
921 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
922 $revIds[] = $row->rev_parent_id
;
924 if ( isset( $row->rev_id
) ) {
925 if ( $this->contribs
=== 'newbie' ) { // multiple users
926 $batch->add( NS_USER
, $row->user_name
);
927 $batch->add( NS_USER_TALK
, $row->user_name
);
929 $batch->add( $row->page_namespace
, $row->page_title
);
932 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
934 $this->mResult
->seek( 0 );
940 function getStartBody() {
941 return "<ul class=\"mw-contributions-list\">\n";
947 function getEndBody() {
952 * Generates each row in the contributions list.
954 * Contributions which are marked "top" are currently on top of the history.
955 * For these contributions, a [rollback] link is shown for users with roll-
956 * back privileges. The rollback link restores the most recent version that
957 * was not written by the target user.
959 * @todo This would probably look a lot nicer in a table.
963 function formatRow( $row ) {
969 * There may be more than just revision rows. To make sure that we'll only be processing
970 * revisions here, let's _try_ to build a revision out of our row (without displaying
971 * notices though) and then trying to grab data from the built object. If we succeed,
972 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
973 * to extensions to subscribe to the hook to parse the row.
975 MediaWiki\
suppressWarnings();
977 $rev = new Revision( $row );
978 $validRevision = (bool)$rev->getId();
979 } catch ( Exception
$e ) {
980 $validRevision = false;
982 MediaWiki\restoreWarnings
();
984 if ( $validRevision ) {
987 $page = Title
::newFromRow( $row );
988 $link = Linker
::link(
990 htmlspecialchars( $page->getPrefixedText() ),
991 array( 'class' => 'mw-contributions-title' ),
992 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
994 # Mark current revisions
996 $user = $this->getUser();
997 if ( $row->rev_id
== $row->page_latest
) {
998 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
1000 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
1001 && $page->quickUserCan( 'edit', $user )
1003 $this->preventClickjacking();
1004 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
1007 # Is there a visible previous revision?
1008 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
1009 $difftext = Linker
::linkKnown(
1011 $this->messages
['diff'],
1015 'oldid' => $row->rev_id
1019 $difftext = $this->messages
['diff'];
1021 $histlink = Linker
::linkKnown(
1023 $this->messages
['hist'],
1025 array( 'action' => 'history' )
1028 if ( $row->rev_parent_id
=== null ) {
1029 // For some reason rev_parent_id isn't populated for this row.
1030 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
1031 // Next best thing is to have the total number of bytes.
1032 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1033 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
1034 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1037 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1038 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1041 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1042 $chardiff .= ChangesList
::showCharacterDifference(
1047 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1050 $lang = $this->getLanguage();
1051 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1052 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1053 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1054 $d = Linker
::linkKnown(
1056 htmlspecialchars( $date ),
1057 array( 'class' => 'mw-changeslist-date' ),
1058 array( 'oldid' => intval( $row->rev_id
) )
1061 $d = htmlspecialchars( $date );
1063 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1064 $d = '<span class="history-deleted">' . $d . '</span>';
1067 # Show user names for /newbies as there may be different users.
1068 # Note that we already excluded rows with hidden user names.
1069 if ( $this->contribs
== 'newbie' ) {
1070 $userlink = ' . . ' . $lang->getDirMark()
1071 . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1072 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1073 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1078 if ( $rev->getParentId() === 0 ) {
1079 $nflag = ChangesList
::flag( 'newpage' );
1084 if ( $rev->isMinor() ) {
1085 $mflag = ChangesList
::flag( 'minor' );
1090 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1091 if ( $del !== '' ) {
1095 $diffHistLinks = $this->msg( 'parentheses' )
1096 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1098 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1099 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1101 # Denote if username is redacted for this edit
1102 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1103 $ret .= " <strong>" .
1104 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1109 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1113 $classes = array_merge( $classes, $newClasses );
1114 $ret .= " $tagSummary";
1117 // Let extensions add data
1118 Hooks
::run( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1120 if ( $classes === array() && $ret === '' ) {
1121 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
1122 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1124 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1131 * Overwrite Pager function and return a helpful comment
1134 function getSqlComment() {
1135 if ( $this->namespace ||
$this->deletedOnly
) {
1136 // potentially slow, see CR r58153
1137 return 'contributions page filtered for namespace or RevisionDeleted edits';
1139 return 'contributions page unfiltered';
1143 protected function preventClickjacking() {
1144 $this->preventClickjacking
= true;
1150 public function getPreventClickjacking() {
1151 return $this->preventClickjacking
;