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 compatibility
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() ),
258 if ( !$this->including() ) {
259 $this->getOutput()->setStatusCode( 404 );
262 $user = htmlspecialchars( $userObj->getName() );
264 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
266 $nt = $userObj->getUserPage();
267 $talk = $userObj->getTalkPage();
270 $tools = $this->getUserLinks( $nt, $talk, $userObj );
271 $links = $this->getLanguage()->pipeList( $tools );
273 // Show a note if the user is blocked and display the last block log entry.
274 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
275 // and also this will display a totally irrelevant log entry as a current block.
276 if ( !$this->including() ) {
277 $block = Block
::newFromTarget( $userObj, $userObj );
278 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
279 if ( $block->getType() == Block
::TYPE_RANGE
) {
280 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
283 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
284 LogEventsList
::showLogExtract(
291 'showIfEmpty' => false,
294 'sp-contributions-blocked-notice-anon' :
295 'sp-contributions-blocked-notice',
296 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
298 'offset' => '' # don't use WebRequest parameter offset
305 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
309 * Links to different places.
310 * @param Title $userpage Target user page
311 * @param Title $talkpage Talk page
312 * @param User $target Target user object
315 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
317 $id = $target->getId();
318 $username = $target->getName();
320 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
322 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
323 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
324 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
325 $tools[] = Linker
::linkKnown( # Change block link
326 SpecialPage
::getTitleFor( 'Block', $username ),
327 $this->msg( 'change-blocklink' )->escaped()
329 $tools[] = Linker
::linkKnown( # Unblock link
330 SpecialPage
::getTitleFor( 'Unblock', $username ),
331 $this->msg( 'unblocklink' )->escaped()
333 } else { # User is not blocked
334 $tools[] = Linker
::linkKnown( # Block link
335 SpecialPage
::getTitleFor( 'Block', $username ),
336 $this->msg( 'blocklink' )->escaped()
342 $tools[] = Linker
::linkKnown(
343 SpecialPage
::getTitleFor( 'Log', 'block' ),
344 $this->msg( 'sp-contributions-blocklog' )->escaped(),
346 array( 'page' => $userpage->getPrefixedText() )
349 # Suppression log link (bug 59120)
350 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
351 $tools[] = Linker
::linkKnown(
352 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
353 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
355 array( 'offender' => $username )
360 $tools[] = Linker
::linkKnown(
361 SpecialPage
::getTitleFor( 'Listfiles', $username ),
362 $this->msg( 'sp-contributions-uploads' )->escaped()
366 $tools[] = Linker
::linkKnown(
367 SpecialPage
::getTitleFor( 'Log', $username ),
368 $this->msg( 'sp-contributions-logs' )->escaped()
371 # Add link to deleted user contributions for priviledged users
372 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
373 $tools[] = Linker
::linkKnown(
374 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
375 $this->msg( 'sp-contributions-deleted' )->escaped()
379 # Add a link to change user rights for privileged users
380 $userrightsPage = new UserrightsPage();
381 $userrightsPage->setContext( $this->getContext() );
382 if ( $userrightsPage->userCanChangeRights( $target ) ) {
383 $tools[] = Linker
::linkKnown(
384 SpecialPage
::getTitleFor( 'Userrights', $username ),
385 $this->msg( 'sp-contributions-userrights' )->escaped()
389 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
395 * Generates the namespace selector form with hidden attributes.
396 * @return string HTML fragment
398 protected function getForm() {
399 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
400 if ( !isset( $this->opts
['target'] ) ) {
401 $this->opts
['target'] = '';
403 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
406 if ( !isset( $this->opts
['namespace'] ) ) {
407 $this->opts
['namespace'] = '';
410 if ( !isset( $this->opts
['nsInvert'] ) ) {
411 $this->opts
['nsInvert'] = '';
414 if ( !isset( $this->opts
['associated'] ) ) {
415 $this->opts
['associated'] = false;
418 if ( !isset( $this->opts
['contribs'] ) ) {
419 $this->opts
['contribs'] = 'user';
422 if ( !isset( $this->opts
['year'] ) ) {
423 $this->opts
['year'] = '';
426 if ( !isset( $this->opts
['month'] ) ) {
427 $this->opts
['month'] = '';
430 if ( $this->opts
['contribs'] == 'newbie' ) {
431 $this->opts
['target'] = '';
434 if ( !isset( $this->opts
['tagfilter'] ) ) {
435 $this->opts
['tagfilter'] = '';
438 if ( !isset( $this->opts
['topOnly'] ) ) {
439 $this->opts
['topOnly'] = false;
442 if ( !isset( $this->opts
['newOnly'] ) ) {
443 $this->opts
['newOnly'] = false;
446 $form = Html
::openElement(
450 'action' => wfScript(),
451 'class' => 'mw-contributions-form'
455 # Add hidden params for tracking except for parameters in $skipParameters
456 $skipParameters = array(
469 foreach ( $this->opts
as $name => $value ) {
470 if ( in_array( $name, $skipParameters ) ) {
473 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
476 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
479 $filterSelection = Html
::rawElement(
482 array_shift( $tagFilter ) . implode( ' ', $tagFilter )
485 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
488 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
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'],
515 'mw-ui-input-inline',
516 'mw-autocomplete-user', // used by mediawiki.userSuggest
518 ) +
( $this->opts
['target'] ?
array() : array( 'autofocus' ) )
520 $targetSelection = Html
::rawElement(
522 array( 'colspan' => 2 ),
523 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
526 $namespaceSelection = Xml
::tags(
530 $this->msg( 'namespace' )->text(),
534 Html
::namespaceSelector(
535 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
537 'name' => 'namespace',
539 'class' => 'namespaceselector',
544 array( 'style' => 'white-space: nowrap' ),
546 $this->msg( 'invert' )->text(),
549 $this->opts
['nsInvert'],
551 'title' => $this->msg( 'tooltip-invert' )->text(),
552 'class' => 'mw-input'
556 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
558 $this->msg( 'namespace_association' )->text(),
561 $this->opts
['associated'],
563 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
564 'class' => 'mw-input'
570 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
571 $deletedOnlyCheck = Html
::rawElement(
573 array( 'style' => 'white-space: nowrap' ),
575 $this->msg( 'history-show-deleted' )->text(),
577 'mw-show-deleted-only',
578 $this->opts
['deletedOnly'],
579 array( 'class' => 'mw-input' )
583 $deletedOnlyCheck = '';
586 $checkLabelTopOnly = Html
::rawElement(
588 array( 'style' => 'white-space: nowrap' ),
590 $this->msg( 'sp-contributions-toponly' )->text(),
593 $this->opts
['topOnly'],
594 array( 'class' => 'mw-input' )
597 $checkLabelNewOnly = Html
::rawElement(
599 array( 'style' => 'white-space: nowrap' ),
601 $this->msg( 'sp-contributions-newonly' )->text(),
604 $this->opts
['newOnly'],
605 array( 'class' => 'mw-input' )
608 $extraOptions = Html
::rawElement(
610 array( 'colspan' => 2 ),
611 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
614 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
616 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
620 $this->msg( 'sp-contributions-submit' )->text(),
621 array( 'class' => 'mw-submit' ), array( 'mw-ui-progressive' )
625 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
626 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
627 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
628 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
629 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
630 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
631 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
634 $explain = $this->msg( 'sp-contributions-explain' );
635 if ( !$explain->isBlank() ) {
636 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
639 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
644 protected function getGroupName() {
650 * Pager for Special:Contributions
651 * @ingroup SpecialPage Pager
653 class ContribsPager
extends ReverseChronologicalPager
{
654 public $mDefaultDirection = IndexPager
::DIR_DESCENDING
;
657 public $namespace = '';
659 public $preventClickjacking = false;
661 /** @var DatabaseBase */
662 public $mDbSecondary;
667 protected $mParentLens;
669 function __construct( IContextSource
$context, array $options ) {
670 parent
::__construct( $context );
682 foreach ( $msgs as $msg ) {
683 $this->messages
[$msg] = $this->msg( $msg )->escaped();
686 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
687 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
688 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
689 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
690 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
691 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
693 $this->deletedOnly
= !empty( $options['deletedOnly'] );
694 $this->topOnly
= !empty( $options['topOnly'] );
695 $this->newOnly
= !empty( $options['newOnly'] );
697 $year = isset( $options['year'] ) ?
$options['year'] : false;
698 $month = isset( $options['month'] ) ?
$options['month'] : false;
699 $this->getDateCond( $year, $month );
701 // Most of this code will use the 'contributions' group DB, which can map to slaves
702 // with extra user based indexes or partioning by user. The additional metadata
703 // queries should use a regular slave since the lookup pattern is not all by user.
704 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
705 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
708 function getDefaultQuery() {
709 $query = parent
::getDefaultQuery();
710 $query['target'] = $this->target
;
716 * This method basically executes the exact same code as the parent class, though with
717 * a hook added, to allow extentions to add additional queries.
719 * @param string $offset Index offset, inclusive
720 * @param int $limit Exact query limit
721 * @param bool $descending Query direction, false for ascending, true for descending
722 * @return ResultWrapper
724 function reallyDoQuery( $offset, $limit, $descending ) {
725 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
733 * This hook will allow extensions to add in additional queries, so they can get their data
734 * in My Contributions as well. Extensions should append their results to the $data array.
736 * Extension queries have to implement the navbar requirement as well. They should
737 * - have a column aliased as $pager->getIndexField()
739 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
740 * - have the ORDER BY specified based upon the details provided by the navbar
742 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
744 * &$data: an array of results of all contribs queries
745 * $pager: the ContribsPager object hooked into
746 * $offset: see phpdoc above
747 * $limit: see phpdoc above
748 * $descending: see phpdoc above
750 $data = array( $this->mDb
->select(
751 $tables, $fields, $conds, $fname, $options, $join_conds
754 'ContribsPager::reallyDoQuery',
755 array( &$data, $pager, $offset, $limit, $descending )
760 // loop all results and collect them in an array
761 foreach ( $data as $query ) {
762 foreach ( $query as $i => $row ) {
763 // use index column as key, allowing us to easily sort in PHP
764 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
776 $result = array_slice( $result, 0, $limit );
778 // get rid of array keys
779 $result = array_values( $result );
781 return new FakeResultWrapper( $result );
784 function getQueryInfo() {
785 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
787 $user = $this->getUser();
788 $conds = array_merge( $userCond, $this->getNamespaceCond() );
790 // Paranoia: avoid brute force searches (bug 17342)
791 if ( !$user->isAllowed( 'deletedhistory' ) ) {
792 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
793 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
794 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
795 ' != ' . Revision
::SUPPRESSED_USER
;
798 # Don't include orphaned revisions
799 $join_cond['page'] = Revision
::pageJoinCond();
800 # Get the current user name for accounts
801 $join_cond['user'] = Revision
::userJoinCond();
805 $options['USE INDEX'] = array( 'revision' => $index );
810 'fields' => array_merge(
811 Revision
::selectFields(),
812 Revision
::selectUserFields(),
813 array( 'page_namespace', 'page_title', 'page_is_new',
814 'page_latest', 'page_is_redirect', 'page_len' )
817 'options' => $options,
818 'join_conds' => $join_cond
821 ChangeTags
::modifyDisplayQuery(
822 $queryInfo['tables'],
823 $queryInfo['fields'],
825 $queryInfo['join_conds'],
826 $queryInfo['options'],
830 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
835 function getUserCond() {
836 $condition = array();
837 $join_conds = array();
838 $tables = array( 'revision', 'page', 'user' );
840 if ( $this->contribs
== 'newbie' ) {
841 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
842 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
843 # ignore local groups with the bot right
844 # @todo FIXME: Global groups may have 'bot' rights
845 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
846 if ( count( $groupsWithBotPermission ) ) {
847 $tables[] = 'user_groups';
848 $condition[] = 'ug_group IS NULL';
849 $join_conds['user_groups'] = array(
851 'ug_user = rev_user',
852 'ug_group' => $groupsWithBotPermission
857 $uid = User
::idFromName( $this->target
);
859 $condition['rev_user'] = $uid;
860 $index = 'user_timestamp';
862 $condition['rev_user_text'] = $this->target
;
863 $index = 'usertext_timestamp';
867 if ( $this->deletedOnly
) {
868 $condition[] = 'rev_deleted != 0';
871 if ( $this->topOnly
) {
872 $condition[] = 'rev_id = page_latest';
875 if ( $this->newOnly
) {
876 $condition[] = 'rev_parent_id = 0';
879 return array( $tables, $index, $condition, $join_conds );
882 function getNamespaceCond() {
883 if ( $this->namespace !== '' ) {
884 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
885 $eq_op = $this->nsInvert ?
'!=' : '=';
886 $bool_op = $this->nsInvert ?
'AND' : 'OR';
888 if ( !$this->associated
) {
889 return array( "page_namespace $eq_op $selectedNS" );
892 $associatedNS = $this->mDb
->addQuotes(
893 MWNamespace
::getAssociated( $this->namespace )
897 "page_namespace $eq_op $selectedNS " .
899 " page_namespace $eq_op $associatedNS"
906 function getIndexField() {
907 return 'rev_timestamp';
910 function doBatchLookups() {
911 # Do a link batch query
912 $this->mResult
->seek( 0 );
914 $batch = new LinkBatch();
915 # Give some pointers to make (last) links
916 foreach ( $this->mResult
as $row ) {
917 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
918 $revIds[] = $row->rev_parent_id
;
920 if ( isset( $row->rev_id
) ) {
921 if ( $this->contribs
=== 'newbie' ) { // multiple users
922 $batch->add( NS_USER
, $row->user_name
);
923 $batch->add( NS_USER_TALK
, $row->user_name
);
925 $batch->add( $row->page_namespace
, $row->page_title
);
928 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
930 $this->mResult
->seek( 0 );
936 function getStartBody() {
937 return "<ul class=\"mw-contributions-list\">\n";
943 function getEndBody() {
948 * Generates each row in the contributions list.
950 * Contributions which are marked "top" are currently on top of the history.
951 * For these contributions, a [rollback] link is shown for users with roll-
952 * back privileges. The rollback link restores the most recent version that
953 * was not written by the target user.
955 * @todo This would probably look a lot nicer in a table.
959 function formatRow( $row ) {
960 wfProfileIn( __METHOD__
);
966 * There may be more than just revision rows. To make sure that we'll only be processing
967 * revisions here, let's _try_ to build a revision out of our row (without displaying
968 * notices though) and then trying to grab data from the built object. If we succeed,
969 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
970 * to extensions to subscribe to the hook to parse the row.
972 wfSuppressWarnings();
974 $rev = new Revision( $row );
975 $validRevision = (bool)$rev->getId();
976 } catch ( MWException
$e ) {
977 $validRevision = false;
981 if ( $validRevision ) {
984 $page = Title
::newFromRow( $row );
985 $link = Linker
::link(
987 htmlspecialchars( $page->getPrefixedText() ),
988 array( 'class' => 'mw-contributions-title' ),
989 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
991 # Mark current revisions
993 $user = $this->getUser();
994 if ( $row->rev_id
== $row->page_latest
) {
995 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
997 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
998 && $page->quickUserCan( 'edit', $user )
1000 $this->preventClickjacking();
1001 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
1004 # Is there a visible previous revision?
1005 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
1006 $difftext = Linker
::linkKnown(
1008 $this->messages
['diff'],
1012 'oldid' => $row->rev_id
1016 $difftext = $this->messages
['diff'];
1018 $histlink = Linker
::linkKnown(
1020 $this->messages
['hist'],
1022 array( 'action' => 'history' )
1025 if ( $row->rev_parent_id
=== null ) {
1026 // For some reason rev_parent_id isn't populated for this row.
1027 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
1028 // Next best thing is to have the total number of bytes.
1029 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1030 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
1031 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1034 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1035 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1038 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1039 $chardiff .= ChangesList
::showCharacterDifference(
1044 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1047 $lang = $this->getLanguage();
1048 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1049 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1050 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1051 $d = Linker
::linkKnown(
1053 htmlspecialchars( $date ),
1054 array( 'class' => 'mw-changeslist-date' ),
1055 array( 'oldid' => intval( $row->rev_id
) )
1058 $d = htmlspecialchars( $date );
1060 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1061 $d = '<span class="history-deleted">' . $d . '</span>';
1064 # Show user names for /newbies as there may be different users.
1065 # Note that we already excluded rows with hidden user names.
1066 if ( $this->contribs
== 'newbie' ) {
1067 $userlink = ' . . ' . $lang->getDirMark()
1068 . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1069 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1070 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1075 if ( $rev->getParentId() === 0 ) {
1076 $nflag = ChangesList
::flag( 'newpage' );
1081 if ( $rev->isMinor() ) {
1082 $mflag = ChangesList
::flag( 'minor' );
1087 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1088 if ( $del !== '' ) {
1092 $diffHistLinks = $this->msg( 'parentheses' )
1093 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1095 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1096 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1098 # Denote if username is redacted for this edit
1099 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1100 $ret .= " <strong>" .
1101 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1106 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1110 $classes = array_merge( $classes, $newClasses );
1111 $ret .= " $tagSummary";
1114 // Let extensions add data
1115 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1117 if ( $classes === array() && $ret === '' ) {
1118 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
1119 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1121 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1124 wfProfileOut( __METHOD__
);
1130 * Overwrite Pager function and return a helpful comment
1133 function getSqlComment() {
1134 if ( $this->namespace ||
$this->deletedOnly
) {
1135 // potentially slow, see CR r58153
1136 return 'contributions page filtered for namespace or RevisionDeleted edits';
1138 return 'contributions page unfiltered';
1142 protected function preventClickjacking() {
1143 $this->preventClickjacking
= true;
1149 public function getPreventClickjacking() {
1150 return $this->preventClickjacking
;