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' );
42 $this->opts
= array();
43 $request = $this->getRequest();
45 if ( $par !== null ) {
48 $target = $request->getVal( 'target' );
52 if ( $request->getVal( 'contribs' ) == 'newbie' ) {
54 $this->opts
['contribs'] = 'newbie';
55 } elseif ( $par === 'newbies' ) { // b/c for WMF
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' );
79 $nt = Title
::makeTitleSafe( NS_USER
, $target );
81 $out->addHTML( $this->getForm() );
85 $userObj = User
::newFromName( $nt->getText(), false );
87 $out->addHTML( $this->getForm() );
91 $id = $userObj->getID();
93 if ( $this->opts
['contribs'] != 'newbie' ) {
94 $target = $nt->getText();
95 $out->addSubtitle( $this->contributionsSub( $userObj ) );
96 $out->setHTMLTitle( $this->msg(
98 $this->msg( 'contributions-title', $target )->plain()
99 )->inContentLanguage() );
100 $this->getSkin()->setRelevantUser( $userObj );
102 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
103 $out->setHTMLTitle( $this->msg(
105 $this->msg( 'sp-contributions-newbies-title' )->plain()
106 )->inContentLanguage() );
109 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
110 $this->opts
['namespace'] = intval( $ns );
112 $this->opts
['namespace'] = '';
115 $this->opts
['associated'] = $request->getBool( 'associated' );
116 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
117 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
119 // Allows reverts to have the bot flag in recent changes. It is just here to
120 // be passed in the form at the top of the page
121 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
122 $this->opts
['bot'] = '1';
125 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
126 # Offset overrides year/month selection
128 $this->opts
['year'] = '';
129 $this->opts
['month'] = '';
131 $this->opts
['year'] = $request->getIntOrNull( 'year' );
132 $this->opts
['month'] = $request->getIntOrNull( 'month' );
135 $feedType = $request->getVal( 'feed' );
138 'action' => 'feedcontributions',
141 if ( $this->opts
['topOnly'] ) {
142 $feedParams['toponly'] = true;
144 if ( $this->opts
['newOnly'] ) {
145 $feedParams['newonly'] = true;
147 if ( $this->opts
['deletedOnly'] ) {
148 $feedParams['deletedonly'] = true;
150 if ( $this->opts
['tagfilter'] !== '' ) {
151 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
153 if ( $this->opts
['namespace'] !== '' ) {
154 $feedParams['namespace'] = $this->opts
['namespace'];
156 // Don't use year and month for the feed URL, but pass them on if
157 // we redirect to API (if $feedType is specified)
158 if ( $feedType && $this->opts
['year'] !== null ) {
159 $feedParams['year'] = $this->opts
['year'];
161 if ( $feedType && $this->opts
['month'] !== null ) {
162 $feedParams['month'] = $this->opts
['month'];
166 // Maintain some level of backwards compatability
167 // If people request feeds using the old parameters, redirect to API
168 $feedParams['feedformat'] = $feedType;
169 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
171 $out->redirect( $url, '301' );
176 // Add RSS/atom links
177 $this->addFeedLinks( $feedParams );
179 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) {
180 if ( !$this->including() ) {
181 $out->addHTML( $this->getForm() );
183 $pager = new ContribsPager( $this->getContext(), array(
185 'contribs' => $this->opts
['contribs'],
186 'namespace' => $this->opts
['namespace'],
187 'tagfilter' => $this->opts
['tagfilter'],
188 'year' => $this->opts
['year'],
189 'month' => $this->opts
['month'],
190 'deletedOnly' => $this->opts
['deletedOnly'],
191 'topOnly' => $this->opts
['topOnly'],
192 'newOnly' => $this->opts
['newOnly'],
193 'nsInvert' => $this->opts
['nsInvert'],
194 'associated' => $this->opts
['associated'],
197 if ( !$pager->getNumRows() ) {
198 $out->addWikiMsg( 'nocontribs', $target );
200 # Show a message about slave lag, if applicable
201 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
203 $out->showLagWarning( $lag );
206 $output = $pager->getBody();
207 if ( !$this->including() ) {
208 $output = '<p>' . $pager->getNavigationBar() . '</p>' .
210 '<p>' . $pager->getNavigationBar() . '</p>';
212 $out->addHTML( $output );
214 $out->preventClickjacking( $pager->getPreventClickjacking() );
216 # Show the appropriate "footer" message - WHOIS tools, etc.
217 if ( $this->opts
['contribs'] == 'newbie' ) {
218 $message = 'sp-contributions-footer-newbies';
219 } elseif ( IP
::isIPAddress( $target ) ) {
220 $message = 'sp-contributions-footer-anon';
221 } elseif ( $userObj->isAnon() ) {
222 // No message for non-existing users
225 $message = 'sp-contributions-footer';
229 if ( !$this->including() ) {
230 if ( !$this->msg( $message, $target )->isDisabled() ) {
232 "<div class='mw-contributions-footer'>\n$1\n</div>",
233 array( $message, $target ) );
241 * Generates the subheading with links
242 * @param User $userObj User object for the target
243 * @return string Appropriately-escaped HTML to be output literally
244 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
247 protected function contributionsSub( $userObj ) {
248 if ( $userObj->isAnon() ) {
249 // Show a warning message that the user being searched for doesn't exists
250 if ( !User
::isIP( $userObj->getName() ) ) {
251 $this->getOutput()->wrapWikiMsg(
252 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
254 'contributions-userdoesnotexist',
255 wfEscapeWikiText( $userObj->getName() ),
259 $user = htmlspecialchars( $userObj->getName() );
261 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
263 $nt = $userObj->getUserPage();
264 $talk = $userObj->getTalkPage();
267 $tools = $this->getUserLinks( $nt, $talk, $userObj );
268 $links = $this->getLanguage()->pipeList( $tools );
270 // Show a note if the user is blocked and display the last block log entry.
271 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
272 // and also this will display a totally irrelevant log entry as a current block.
273 $block = Block
::newFromTarget( $userObj, $userObj );
274 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
275 if ( $block->getType() == Block
::TYPE_RANGE
) {
276 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
279 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
280 LogEventsList
::showLogExtract(
287 'showIfEmpty' => false,
290 'sp-contributions-blocked-notice-anon' :
291 'sp-contributions-blocked-notice',
292 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
294 'offset' => '' # don't use WebRequest parameter offset
300 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
304 * Links to different places.
305 * @param Title $userpage Target user page
306 * @param Title $talkpage Talk page
307 * @param User $target Target user object
310 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
312 $id = $target->getId();
313 $username = $target->getName();
315 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
317 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
318 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
319 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
320 $tools[] = Linker
::linkKnown( # Change block link
321 SpecialPage
::getTitleFor( 'Block', $username ),
322 $this->msg( 'change-blocklink' )->escaped()
324 $tools[] = Linker
::linkKnown( # Unblock link
325 SpecialPage
::getTitleFor( 'Unblock', $username ),
326 $this->msg( 'unblocklink' )->escaped()
328 } else { # User is not blocked
329 $tools[] = Linker
::linkKnown( # Block link
330 SpecialPage
::getTitleFor( 'Block', $username ),
331 $this->msg( 'blocklink' )->escaped()
337 $tools[] = Linker
::linkKnown(
338 SpecialPage
::getTitleFor( 'Log', 'block' ),
339 $this->msg( 'sp-contributions-blocklog' )->escaped(),
341 array( 'page' => $userpage->getPrefixedText() )
344 # Suppression log link (bug 59120)
345 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
346 $tools[] = Linker
::linkKnown(
347 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
348 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
350 array( 'offender' => $username )
355 $tools[] = Linker
::linkKnown(
356 SpecialPage
::getTitleFor( 'Listfiles', $username ),
357 $this->msg( 'sp-contributions-uploads' )->escaped()
361 $tools[] = Linker
::linkKnown(
362 SpecialPage
::getTitleFor( 'Log', $username ),
363 $this->msg( 'sp-contributions-logs' )->escaped()
366 # Add link to deleted user contributions for priviledged users
367 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
368 $tools[] = Linker
::linkKnown(
369 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
370 $this->msg( 'sp-contributions-deleted' )->escaped()
374 # Add a link to change user rights for privileged users
375 $userrightsPage = new UserrightsPage();
376 $userrightsPage->setContext( $this->getContext() );
377 if ( $userrightsPage->userCanChangeRights( $target ) ) {
378 $tools[] = Linker
::linkKnown(
379 SpecialPage
::getTitleFor( 'Userrights', $username ),
380 $this->msg( 'sp-contributions-userrights' )->escaped()
384 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
390 * Generates the namespace selector form with hidden attributes.
391 * @return string HTML fragment
393 protected function getForm() {
396 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
397 if ( !isset( $this->opts
['target'] ) ) {
398 $this->opts
['target'] = '';
400 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
403 if ( !isset( $this->opts
['namespace'] ) ) {
404 $this->opts
['namespace'] = '';
407 if ( !isset( $this->opts
['nsInvert'] ) ) {
408 $this->opts
['nsInvert'] = '';
411 if ( !isset( $this->opts
['associated'] ) ) {
412 $this->opts
['associated'] = false;
415 if ( !isset( $this->opts
['contribs'] ) ) {
416 $this->opts
['contribs'] = 'user';
419 if ( !isset( $this->opts
['year'] ) ) {
420 $this->opts
['year'] = '';
423 if ( !isset( $this->opts
['month'] ) ) {
424 $this->opts
['month'] = '';
427 if ( $this->opts
['contribs'] == 'newbie' ) {
428 $this->opts
['target'] = '';
431 if ( !isset( $this->opts
['tagfilter'] ) ) {
432 $this->opts
['tagfilter'] = '';
435 if ( !isset( $this->opts
['topOnly'] ) ) {
436 $this->opts
['topOnly'] = false;
439 if ( !isset( $this->opts
['newOnly'] ) ) {
440 $this->opts
['newOnly'] = false;
443 $form = Html
::openElement(
447 'action' => $wgScript,
448 'class' => 'mw-contributions-form'
452 # Add hidden params for tracking except for parameters in $skipParameters
453 $skipParameters = array(
466 foreach ( $this->opts
as $name => $value ) {
467 if ( in_array( $name, $skipParameters ) ) {
470 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
473 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
476 $filterSelection = Html
::rawElement(
478 array( 'class' => 'mw-label' ),
479 array_shift( $tagFilter )
481 $filterSelection .= Html
::rawElement(
483 array( 'class' => 'mw-input' ),
484 implode( ' ', $tagFilter )
487 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
490 $labelNewbies = Xml
::radioLabel(
491 $this->msg( 'sp-contributions-newbies' )->text(),
495 $this->opts
['contribs'] == 'newbie',
496 array( 'class' => 'mw-input' )
498 $labelUsername = Xml
::radioLabel(
499 $this->msg( 'sp-contributions-username' )->text(),
503 $this->opts
['contribs'] == 'user',
504 array( 'class' => 'mw-input' )
506 $input = Html
::input(
508 $this->opts
['target'],
510 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
511 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
514 $targetSelection = Html
::rawElement(
516 array( 'colspan' => 2 ),
517 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
520 $namespaceSelection = Xml
::tags(
522 array( 'class' => 'mw-label' ),
524 $this->msg( 'namespace' )->text(),
529 $namespaceSelection .= Html
::rawElement(
532 Html
::namespaceSelector(
533 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
535 'name' => 'namespace',
537 'class' => 'namespaceselector',
542 array( 'style' => 'white-space: nowrap' ),
544 $this->msg( 'invert' )->text(),
547 $this->opts
['nsInvert'],
549 'title' => $this->msg( 'tooltip-invert' )->text(),
550 'class' => 'mw-input'
554 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
556 $this->msg( 'namespace_association' )->text(),
559 $this->opts
['associated'],
561 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
562 'class' => 'mw-input'
568 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
569 $deletedOnlyCheck = Html
::rawElement(
571 array( 'style' => 'white-space: nowrap' ),
573 $this->msg( 'history-show-deleted' )->text(),
575 'mw-show-deleted-only',
576 $this->opts
['deletedOnly'],
577 array( 'class' => 'mw-input' )
581 $deletedOnlyCheck = '';
584 $checkLabelTopOnly = Html
::rawElement(
586 array( 'style' => 'white-space: nowrap' ),
588 $this->msg( 'sp-contributions-toponly' )->text(),
591 $this->opts
['topOnly'],
592 array( 'class' => 'mw-input' )
595 $checkLabelNewOnly = Html
::rawElement(
597 array( 'style' => 'white-space: nowrap' ),
599 $this->msg( 'sp-contributions-newonly' )->text(),
602 $this->opts
['newOnly'],
603 array( 'class' => 'mw-input' )
606 $extraOptions = Html
::rawElement(
608 array( 'colspan' => 2 ),
609 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
612 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
614 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
618 $this->msg( 'sp-contributions-submit' )->text(),
619 array( 'class' => 'mw-submit' )
623 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
624 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
625 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
626 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
627 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
628 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
629 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
632 $explain = $this->msg( 'sp-contributions-explain' );
633 if ( !$explain->isBlank() ) {
634 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
637 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
642 protected function getGroupName() {
648 * Pager for Special:Contributions
649 * @ingroup SpecialPage Pager
651 class ContribsPager
extends ReverseChronologicalPager
{
652 public $mDefaultDirection = true;
655 public $namespace = '';
657 public $preventClickjacking = false;
659 /** @var DatabaseBase */
660 public $mDbSecondary;
665 protected $mParentLens;
667 function __construct( IContextSource
$context, array $options ) {
668 parent
::__construct( $context );
680 foreach ( $msgs as $msg ) {
681 $this->messages
[$msg] = $this->msg( $msg )->escaped();
684 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
685 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
686 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
687 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
688 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
689 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
691 $this->deletedOnly
= !empty( $options['deletedOnly'] );
692 $this->topOnly
= !empty( $options['topOnly'] );
693 $this->newOnly
= !empty( $options['newOnly'] );
695 $year = isset( $options['year'] ) ?
$options['year'] : false;
696 $month = isset( $options['month'] ) ?
$options['month'] : false;
697 $this->getDateCond( $year, $month );
699 // Most of this code will use the 'contributions' group DB, which can map to slaves
700 // with extra user based indexes or partioning by user. The additional metadata
701 // queries should use a regular slave since the lookup pattern is not all by user.
702 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
703 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
706 function getDefaultQuery() {
707 $query = parent
::getDefaultQuery();
708 $query['target'] = $this->target
;
714 * This method basically executes the exact same code as the parent class, though with
715 * a hook added, to allow extentions to add additional queries.
717 * @param string $offset Index offset, inclusive
718 * @param int $limit Exact query limit
719 * @param bool $descending Query direction, false for ascending, true for descending
720 * @return ResultWrapper
722 function reallyDoQuery( $offset, $limit, $descending ) {
723 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
731 * This hook will allow extensions to add in additional queries, so they can get their data
732 * in My Contributions as well. Extensions should append their results to the $data array.
734 * Extension queries have to implement the navbar requirement as well. They should
735 * - have a column aliased as $pager->getIndexField()
737 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
738 * - have the ORDER BY specified based upon the details provided by the navbar
740 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
742 * &$data: an array of results of all contribs queries
743 * $pager: the ContribsPager object hooked into
744 * $offset: see phpdoc above
745 * $limit: see phpdoc above
746 * $descending: see phpdoc above
748 $data = array( $this->mDb
->select(
749 $tables, $fields, $conds, $fname, $options, $join_conds
752 'ContribsPager::reallyDoQuery',
753 array( &$data, $pager, $offset, $limit, $descending )
758 // loop all results and collect them in an array
759 foreach ( $data as $query ) {
760 foreach ( $query as $i => $row ) {
761 // use index column as key, allowing us to easily sort in PHP
762 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
774 $result = array_slice( $result, 0, $limit );
776 // get rid of array keys
777 $result = array_values( $result );
779 return new FakeResultWrapper( $result );
782 function getQueryInfo() {
783 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
785 $user = $this->getUser();
786 $conds = array_merge( $userCond, $this->getNamespaceCond() );
788 // Paranoia: avoid brute force searches (bug 17342)
789 if ( !$user->isAllowed( 'deletedhistory' ) ) {
790 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
791 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
792 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
793 ' != ' . Revision
::SUPPRESSED_USER
;
796 # Don't include orphaned revisions
797 $join_cond['page'] = Revision
::pageJoinCond();
798 # Get the current user name for accounts
799 $join_cond['user'] = Revision
::userJoinCond();
803 $options['USE INDEX'] = array( 'revision' => $index );
808 'fields' => array_merge(
809 Revision
::selectFields(),
810 Revision
::selectUserFields(),
811 array( 'page_namespace', 'page_title', 'page_is_new',
812 'page_latest', 'page_is_redirect', 'page_len' )
815 'options' => $options,
816 'join_conds' => $join_cond
819 ChangeTags
::modifyDisplayQuery(
820 $queryInfo['tables'],
821 $queryInfo['fields'],
823 $queryInfo['join_conds'],
824 $queryInfo['options'],
828 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
833 function getUserCond() {
834 $condition = array();
835 $join_conds = array();
836 $tables = array( 'revision', 'page', 'user' );
838 if ( $this->contribs
== 'newbie' ) {
839 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
840 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
841 # ignore local groups with the bot right
842 # @todo FIXME: Global groups may have 'bot' rights
843 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
844 if ( count( $groupsWithBotPermission ) ) {
845 $tables[] = 'user_groups';
846 $condition[] = 'ug_group IS NULL';
847 $join_conds['user_groups'] = array(
849 'ug_user = rev_user',
850 'ug_group' => $groupsWithBotPermission
855 $uid = User
::idFromName( $this->target
);
857 $condition['rev_user'] = $uid;
858 $index = 'user_timestamp';
860 $condition['rev_user_text'] = $this->target
;
861 $index = 'usertext_timestamp';
865 if ( $this->deletedOnly
) {
866 $condition[] = 'rev_deleted != 0';
869 if ( $this->topOnly
) {
870 $condition[] = 'rev_id = page_latest';
873 if ( $this->newOnly
) {
874 $condition[] = 'rev_parent_id = 0';
877 return array( $tables, $index, $condition, $join_conds );
880 function getNamespaceCond() {
881 if ( $this->namespace !== '' ) {
882 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
883 $eq_op = $this->nsInvert ?
'!=' : '=';
884 $bool_op = $this->nsInvert ?
'AND' : 'OR';
886 if ( !$this->associated
) {
887 return array( "page_namespace $eq_op $selectedNS" );
890 $associatedNS = $this->mDb
->addQuotes(
891 MWNamespace
::getAssociated( $this->namespace )
895 "page_namespace $eq_op $selectedNS " .
897 " page_namespace $eq_op $associatedNS"
904 function getIndexField() {
905 return 'rev_timestamp';
908 function doBatchLookups() {
909 # Do a link batch query
910 $this->mResult
->seek( 0 );
912 $batch = new LinkBatch();
913 # Give some pointers to make (last) links
914 foreach ( $this->mResult
as $row ) {
915 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
916 $revIds[] = $row->rev_parent_id
;
918 if ( isset( $row->rev_id
) ) {
919 if ( $this->contribs
=== 'newbie' ) { // multiple users
920 $batch->add( NS_USER
, $row->user_name
);
921 $batch->add( NS_USER_TALK
, $row->user_name
);
923 $batch->add( $row->page_namespace
, $row->page_title
);
926 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
928 $this->mResult
->seek( 0 );
934 function getStartBody() {
941 function getEndBody() {
946 * Generates each row in the contributions list.
948 * Contributions which are marked "top" are currently on top of the history.
949 * For these contributions, a [rollback] link is shown for users with roll-
950 * back privileges. The rollback link restores the most recent version that
951 * was not written by the target user.
953 * @todo This would probably look a lot nicer in a table.
957 function formatRow( $row ) {
958 wfProfileIn( __METHOD__
);
964 * There may be more than just revision rows. To make sure that we'll only be processing
965 * revisions here, let's _try_ to build a revision out of our row (without displaying
966 * notices though) and then trying to grab data from the built object. If we succeed,
967 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
968 * to extensions to subscribe to the hook to parse the row.
970 wfSuppressWarnings();
972 $rev = new Revision( $row );
973 $validRevision = (bool)$rev->getId();
974 } catch ( MWException
$e ) {
975 $validRevision = false;
979 if ( $validRevision ) {
982 $page = Title
::newFromRow( $row );
983 $link = Linker
::link(
985 htmlspecialchars( $page->getPrefixedText() ),
986 array( 'class' => 'mw-contributions-title' ),
987 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
989 # Mark current revisions
991 $user = $this->getUser();
992 if ( $row->rev_id
== $row->page_latest
) {
993 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
995 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
996 && $page->quickUserCan( 'edit', $user )
998 $this->preventClickjacking();
999 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
1002 # Is there a visible previous revision?
1003 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
1004 $difftext = Linker
::linkKnown(
1006 $this->messages
['diff'],
1010 'oldid' => $row->rev_id
1014 $difftext = $this->messages
['diff'];
1016 $histlink = Linker
::linkKnown(
1018 $this->messages
['hist'],
1020 array( 'action' => 'history' )
1023 if ( $row->rev_parent_id
=== null ) {
1024 // For some reason rev_parent_id isn't populated for this row.
1025 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
1026 // Next best thing is to have the total number of bytes.
1027 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1028 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
1029 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1032 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1033 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1036 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1037 $chardiff .= ChangesList
::showCharacterDifference(
1042 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1045 $lang = $this->getLanguage();
1046 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1047 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1048 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1049 $d = Linker
::linkKnown(
1051 htmlspecialchars( $date ),
1052 array( 'class' => 'mw-changeslist-date' ),
1053 array( 'oldid' => intval( $row->rev_id
) )
1056 $d = htmlspecialchars( $date );
1058 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1059 $d = '<span class="history-deleted">' . $d . '</span>';
1062 # Show user names for /newbies as there may be different users.
1063 # Note that we already excluded rows with hidden user names.
1064 if ( $this->contribs
== 'newbie' ) {
1065 $userlink = ' . . ' . $lang->getDirMark()
1066 . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1067 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1068 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1073 if ( $rev->getParentId() === 0 ) {
1074 $nflag = ChangesList
::flag( 'newpage' );
1079 if ( $rev->isMinor() ) {
1080 $mflag = ChangesList
::flag( 'minor' );
1085 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1086 if ( $del !== '' ) {
1090 $diffHistLinks = $this->msg( 'parentheses' )
1091 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1093 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1094 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1096 # Denote if username is redacted for this edit
1097 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1098 $ret .= " <strong>" .
1099 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1104 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1108 $classes = array_merge( $classes, $newClasses );
1109 $ret .= " $tagSummary";
1112 // Let extensions add data
1113 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1115 if ( $classes === array() && $ret === '' ) {
1116 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
1117 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1119 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1122 wfProfileOut( __METHOD__
);
1128 * Overwrite Pager function and return a helpful comment
1131 function getSqlComment() {
1132 if ( $this->namespace ||
$this->deletedOnly
) {
1133 // potentially slow, see CR r58153
1134 return 'contributions page filtered for namespace or RevisionDeleted edits';
1136 return 'contributions page unfiltered';
1140 protected function preventClickjacking() {
1141 $this->preventClickjacking
= true;
1147 public function getPreventClickjacking() {
1148 return $this->preventClickjacking
;