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 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
274 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
275 LogEventsList
::showLogExtract(
282 'showIfEmpty' => false,
285 'sp-contributions-blocked-notice-anon' :
286 'sp-contributions-blocked-notice',
287 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
289 'offset' => '' # don't use WebRequest parameter offset
295 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
299 * Links to different places.
300 * @param Title $userpage Target user page
301 * @param Title $talkpage Talk page
302 * @param User $target Target user object
305 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
307 $id = $target->getId();
308 $username = $target->getName();
310 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
312 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
313 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
314 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
315 $tools[] = Linker
::linkKnown( # Change block link
316 SpecialPage
::getTitleFor( 'Block', $username ),
317 $this->msg( 'change-blocklink' )->escaped()
319 $tools[] = Linker
::linkKnown( # Unblock link
320 SpecialPage
::getTitleFor( 'Unblock', $username ),
321 $this->msg( 'unblocklink' )->escaped()
323 } else { # User is not blocked
324 $tools[] = Linker
::linkKnown( # Block link
325 SpecialPage
::getTitleFor( 'Block', $username ),
326 $this->msg( 'blocklink' )->escaped()
332 $tools[] = Linker
::linkKnown(
333 SpecialPage
::getTitleFor( 'Log', 'block' ),
334 $this->msg( 'sp-contributions-blocklog' )->escaped(),
336 array( 'page' => $userpage->getPrefixedText() )
339 # Suppression log link (bug 59120)
340 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
341 $tools[] = Linker
::linkKnown(
342 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
343 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
345 array( 'offender' => $username )
350 $tools[] = Linker
::linkKnown(
351 SpecialPage
::getTitleFor( 'Listfiles', $username ),
352 $this->msg( 'sp-contributions-uploads' )->escaped()
356 $tools[] = Linker
::linkKnown(
357 SpecialPage
::getTitleFor( 'Log', $username ),
358 $this->msg( 'sp-contributions-logs' )->escaped()
361 # Add link to deleted user contributions for priviledged users
362 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
363 $tools[] = Linker
::linkKnown(
364 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
365 $this->msg( 'sp-contributions-deleted' )->escaped()
369 # Add a link to change user rights for privileged users
370 $userrightsPage = new UserrightsPage();
371 $userrightsPage->setContext( $this->getContext() );
372 if ( $userrightsPage->userCanChangeRights( $target ) ) {
373 $tools[] = Linker
::linkKnown(
374 SpecialPage
::getTitleFor( 'Userrights', $username ),
375 $this->msg( 'sp-contributions-userrights' )->escaped()
379 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
385 * Generates the namespace selector form with hidden attributes.
386 * @return string HTML fragment
388 protected function getForm() {
391 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
392 if ( !isset( $this->opts
['target'] ) ) {
393 $this->opts
['target'] = '';
395 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
398 if ( !isset( $this->opts
['namespace'] ) ) {
399 $this->opts
['namespace'] = '';
402 if ( !isset( $this->opts
['nsInvert'] ) ) {
403 $this->opts
['nsInvert'] = '';
406 if ( !isset( $this->opts
['associated'] ) ) {
407 $this->opts
['associated'] = false;
410 if ( !isset( $this->opts
['contribs'] ) ) {
411 $this->opts
['contribs'] = 'user';
414 if ( !isset( $this->opts
['year'] ) ) {
415 $this->opts
['year'] = '';
418 if ( !isset( $this->opts
['month'] ) ) {
419 $this->opts
['month'] = '';
422 if ( $this->opts
['contribs'] == 'newbie' ) {
423 $this->opts
['target'] = '';
426 if ( !isset( $this->opts
['tagfilter'] ) ) {
427 $this->opts
['tagfilter'] = '';
430 if ( !isset( $this->opts
['topOnly'] ) ) {
431 $this->opts
['topOnly'] = false;
434 if ( !isset( $this->opts
['newOnly'] ) ) {
435 $this->opts
['newOnly'] = false;
438 $form = Html
::openElement(
442 'action' => $wgScript,
443 'class' => 'mw-contributions-form'
447 # Add hidden params for tracking except for parameters in $skipParameters
448 $skipParameters = array(
461 foreach ( $this->opts
as $name => $value ) {
462 if ( in_array( $name, $skipParameters ) ) {
465 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
468 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
471 $filterSelection = Html
::rawElement(
473 array( 'class' => 'mw-label' ),
474 array_shift( $tagFilter )
476 $filterSelection .= Html
::rawElement(
478 array( 'class' => 'mw-input' ),
479 implode( ' ', $tagFilter )
482 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
485 $labelNewbies = Xml
::radioLabel(
486 $this->msg( 'sp-contributions-newbies' )->text(),
490 $this->opts
['contribs'] == 'newbie',
491 array( 'class' => 'mw-input' )
493 $labelUsername = Xml
::radioLabel(
494 $this->msg( 'sp-contributions-username' )->text(),
498 $this->opts
['contribs'] == 'user',
499 array( 'class' => 'mw-input' )
501 $input = Html
::input(
503 $this->opts
['target'],
505 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
506 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
509 $targetSelection = Html
::rawElement(
511 array( 'colspan' => 2 ),
512 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
515 $namespaceSelection = Xml
::tags(
517 array( 'class' => 'mw-label' ),
519 $this->msg( 'namespace' )->text(),
524 $namespaceSelection .= Html
::rawElement(
527 Html
::namespaceSelector(
528 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
530 'name' => 'namespace',
532 'class' => 'namespaceselector',
537 array( 'style' => 'white-space: nowrap' ),
539 $this->msg( 'invert' )->text(),
542 $this->opts
['nsInvert'],
544 'title' => $this->msg( 'tooltip-invert' )->text(),
545 'class' => 'mw-input'
549 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
551 $this->msg( 'namespace_association' )->text(),
554 $this->opts
['associated'],
556 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
557 'class' => 'mw-input'
563 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
564 $deletedOnlyCheck = Html
::rawElement(
566 array( 'style' => 'white-space: nowrap' ),
568 $this->msg( 'history-show-deleted' )->text(),
570 'mw-show-deleted-only',
571 $this->opts
['deletedOnly'],
572 array( 'class' => 'mw-input' )
576 $deletedOnlyCheck = '';
579 $checkLabelTopOnly = Html
::rawElement(
581 array( 'style' => 'white-space: nowrap' ),
583 $this->msg( 'sp-contributions-toponly' )->text(),
586 $this->opts
['topOnly'],
587 array( 'class' => 'mw-input' )
590 $checkLabelNewOnly = Html
::rawElement(
592 array( 'style' => 'white-space: nowrap' ),
594 $this->msg( 'sp-contributions-newonly' )->text(),
597 $this->opts
['newOnly'],
598 array( 'class' => 'mw-input' )
601 $extraOptions = Html
::rawElement(
603 array( 'colspan' => 2 ),
604 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
607 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
609 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
613 $this->msg( 'sp-contributions-submit' )->text(),
614 array( 'class' => 'mw-submit' )
618 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
619 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
620 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
621 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
622 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
623 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
624 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
627 $explain = $this->msg( 'sp-contributions-explain' );
628 if ( !$explain->isBlank() ) {
629 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
632 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
637 protected function getGroupName() {
643 * Pager for Special:Contributions
644 * @ingroup SpecialPage Pager
646 class ContribsPager
extends ReverseChronologicalPager
{
647 public $mDefaultDirection = true;
650 public $namespace = '';
652 public $preventClickjacking = false;
654 /** @var DatabaseBase */
655 public $mDbSecondary;
660 protected $mParentLens;
662 function __construct( IContextSource
$context, array $options ) {
663 parent
::__construct( $context );
675 foreach ( $msgs as $msg ) {
676 $this->messages
[$msg] = $this->msg( $msg )->escaped();
679 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
680 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
681 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
682 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
683 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
684 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
686 $this->deletedOnly
= !empty( $options['deletedOnly'] );
687 $this->topOnly
= !empty( $options['topOnly'] );
688 $this->newOnly
= !empty( $options['newOnly'] );
690 $year = isset( $options['year'] ) ?
$options['year'] : false;
691 $month = isset( $options['month'] ) ?
$options['month'] : false;
692 $this->getDateCond( $year, $month );
694 // Most of this code will use the 'contributions' group DB, which can map to slaves
695 // with extra user based indexes or partioning by user. The additional metadata
696 // queries should use a regular slave since the lookup pattern is not all by user.
697 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
698 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
701 function getDefaultQuery() {
702 $query = parent
::getDefaultQuery();
703 $query['target'] = $this->target
;
709 * This method basically executes the exact same code as the parent class, though with
710 * a hook added, to allow extentions to add additional queries.
712 * @param string $offset Index offset, inclusive
713 * @param int $limit Exact query limit
714 * @param bool $descending Query direction, false for ascending, true for descending
715 * @return ResultWrapper
717 function reallyDoQuery( $offset, $limit, $descending ) {
718 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
726 * This hook will allow extensions to add in additional queries, so they can get their data
727 * in My Contributions as well. Extensions should append their results to the $data array.
729 * Extension queries have to implement the navbar requirement as well. They should
730 * - have a column aliased as $pager->getIndexField()
732 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
733 * - have the ORDER BY specified based upon the details provided by the navbar
735 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
737 * &$data: an array of results of all contribs queries
738 * $pager: the ContribsPager object hooked into
739 * $offset: see phpdoc above
740 * $limit: see phpdoc above
741 * $descending: see phpdoc above
743 $data = array( $this->mDb
->select(
744 $tables, $fields, $conds, $fname, $options, $join_conds
747 'ContribsPager::reallyDoQuery',
748 array( &$data, $pager, $offset, $limit, $descending )
753 // loop all results and collect them in an array
754 foreach ( $data as $query ) {
755 foreach ( $query as $i => $row ) {
756 // use index column as key, allowing us to easily sort in PHP
757 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
769 $result = array_slice( $result, 0, $limit );
771 // get rid of array keys
772 $result = array_values( $result );
774 return new FakeResultWrapper( $result );
777 function getQueryInfo() {
778 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
780 $user = $this->getUser();
781 $conds = array_merge( $userCond, $this->getNamespaceCond() );
783 // Paranoia: avoid brute force searches (bug 17342)
784 if ( !$user->isAllowed( 'deletedhistory' ) ) {
785 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
786 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
787 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
788 ' != ' . Revision
::SUPPRESSED_USER
;
791 # Don't include orphaned revisions
792 $join_cond['page'] = Revision
::pageJoinCond();
793 # Get the current user name for accounts
794 $join_cond['user'] = Revision
::userJoinCond();
798 $options['USE INDEX'] = array( 'revision' => $index );
803 'fields' => array_merge(
804 Revision
::selectFields(),
805 Revision
::selectUserFields(),
806 array( 'page_namespace', 'page_title', 'page_is_new',
807 'page_latest', 'page_is_redirect', 'page_len' )
810 'options' => $options,
811 'join_conds' => $join_cond
814 ChangeTags
::modifyDisplayQuery(
815 $queryInfo['tables'],
816 $queryInfo['fields'],
818 $queryInfo['join_conds'],
819 $queryInfo['options'],
823 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
828 function getUserCond() {
829 $condition = array();
830 $join_conds = array();
831 $tables = array( 'revision', 'page', 'user' );
833 if ( $this->contribs
== 'newbie' ) {
834 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
835 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
836 # ignore local groups with the bot right
837 # @todo FIXME: Global groups may have 'bot' rights
838 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
839 if ( count( $groupsWithBotPermission ) ) {
840 $tables[] = 'user_groups';
841 $condition[] = 'ug_group IS NULL';
842 $join_conds['user_groups'] = array(
844 'ug_user = rev_user',
845 'ug_group' => $groupsWithBotPermission
850 $uid = User
::idFromName( $this->target
);
852 $condition['rev_user'] = $uid;
853 $index = 'user_timestamp';
855 $condition['rev_user_text'] = $this->target
;
856 $index = 'usertext_timestamp';
860 if ( $this->deletedOnly
) {
861 $condition[] = 'rev_deleted != 0';
864 if ( $this->topOnly
) {
865 $condition[] = 'rev_id = page_latest';
868 if ( $this->newOnly
) {
869 $condition[] = 'rev_parent_id = 0';
872 return array( $tables, $index, $condition, $join_conds );
875 function getNamespaceCond() {
876 if ( $this->namespace !== '' ) {
877 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
878 $eq_op = $this->nsInvert ?
'!=' : '=';
879 $bool_op = $this->nsInvert ?
'AND' : 'OR';
881 if ( !$this->associated
) {
882 return array( "page_namespace $eq_op $selectedNS" );
885 $associatedNS = $this->mDb
->addQuotes(
886 MWNamespace
::getAssociated( $this->namespace )
890 "page_namespace $eq_op $selectedNS " .
892 " page_namespace $eq_op $associatedNS"
899 function getIndexField() {
900 return 'rev_timestamp';
903 function doBatchLookups() {
904 # Do a link batch query
905 $this->mResult
->seek( 0 );
907 $batch = new LinkBatch();
908 # Give some pointers to make (last) links
909 foreach ( $this->mResult
as $row ) {
910 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
911 $revIds[] = $row->rev_parent_id
;
913 if ( isset( $row->rev_id
) ) {
914 if ( $this->contribs
=== 'newbie' ) { // multiple users
915 $batch->add( NS_USER
, $row->user_name
);
916 $batch->add( NS_USER_TALK
, $row->user_name
);
918 $batch->add( $row->page_namespace
, $row->page_title
);
921 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
923 $this->mResult
->seek( 0 );
929 function getStartBody() {
936 function getEndBody() {
941 * Generates each row in the contributions list.
943 * Contributions which are marked "top" are currently on top of the history.
944 * For these contributions, a [rollback] link is shown for users with roll-
945 * back privileges. The rollback link restores the most recent version that
946 * was not written by the target user.
948 * @todo This would probably look a lot nicer in a table.
952 function formatRow( $row ) {
953 wfProfileIn( __METHOD__
);
959 * There may be more than just revision rows. To make sure that we'll only be processing
960 * revisions here, let's _try_ to build a revision out of our row (without displaying
961 * notices though) and then trying to grab data from the built object. If we succeed,
962 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
963 * to extensions to subscribe to the hook to parse the row.
965 wfSuppressWarnings();
967 $rev = new Revision( $row );
968 $validRevision = (bool)$rev->getId();
969 } catch ( MWException
$e ) {
970 $validRevision = false;
974 if ( $validRevision ) {
977 $page = Title
::newFromRow( $row );
978 $link = Linker
::link(
980 htmlspecialchars( $page->getPrefixedText() ),
981 array( 'class' => 'mw-contributions-title' ),
982 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
984 # Mark current revisions
986 $user = $this->getUser();
987 if ( $row->rev_id
== $row->page_latest
) {
988 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
990 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
991 && $page->quickUserCan( 'edit', $user )
993 $this->preventClickjacking();
994 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
997 # Is there a visible previous revision?
998 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
999 $difftext = Linker
::linkKnown(
1001 $this->messages
['diff'],
1005 'oldid' => $row->rev_id
1009 $difftext = $this->messages
['diff'];
1011 $histlink = Linker
::linkKnown(
1013 $this->messages
['hist'],
1015 array( 'action' => 'history' )
1018 if ( $row->rev_parent_id
=== null ) {
1019 // For some reason rev_parent_id isn't populated for this row.
1020 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
1021 // Next best thing is to have the total number of bytes.
1022 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1023 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
1024 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1027 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1028 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1031 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1032 $chardiff .= ChangesList
::showCharacterDifference(
1037 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1040 $lang = $this->getLanguage();
1041 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1042 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1043 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1044 $d = Linker
::linkKnown(
1046 htmlspecialchars( $date ),
1047 array( 'class' => 'mw-changeslist-date' ),
1048 array( 'oldid' => intval( $row->rev_id
) )
1051 $d = htmlspecialchars( $date );
1053 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1054 $d = '<span class="history-deleted">' . $d . '</span>';
1057 # Show user names for /newbies as there may be different users.
1058 # Note that we already excluded rows with hidden user names.
1059 if ( $this->contribs
== 'newbie' ) {
1060 $userlink = ' . . ' . $lang->getDirMark()
1061 . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1062 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1063 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1068 if ( $rev->getParentId() === 0 ) {
1069 $nflag = ChangesList
::flag( 'newpage' );
1074 if ( $rev->isMinor() ) {
1075 $mflag = ChangesList
::flag( 'minor' );
1080 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1081 if ( $del !== '' ) {
1085 $diffHistLinks = $this->msg( 'parentheses' )
1086 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1088 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1089 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1091 # Denote if username is redacted for this edit
1092 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1093 $ret .= " <strong>" .
1094 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1099 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1103 $classes = array_merge( $classes, $newClasses );
1104 $ret .= " $tagSummary";
1107 // Let extensions add data
1108 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1110 if ( $classes === array() && $ret === '' ) {
1111 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
1112 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1114 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1117 wfProfileOut( __METHOD__
);
1123 * Overwrite Pager function and return a helpful comment
1126 function getSqlComment() {
1127 if ( $this->namespace ||
$this->deletedOnly
) {
1128 // potentially slow, see CR r58153
1129 return 'contributions page filtered for namespace or RevisionDeleted edits';
1131 return 'contributions page unfiltered';
1135 protected function preventClickjacking() {
1136 $this->preventClickjacking
= true;
1142 public function getPreventClickjacking() {
1143 return $this->preventClickjacking
;