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
30 class SpecialContributions
extends SpecialPage
{
33 public function __construct() {
34 parent
::__construct( 'Contributions' );
37 public function execute( $par ) {
39 $this->outputHeader();
40 $out = $this->getOutput();
41 $out->addModuleStyles( 'mediawiki.special' );
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 $out->addHTML( $this->getForm() );
71 $user = $this->getUser();
73 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
74 $this->opts
['target'] = $target;
75 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
77 $nt = Title
::makeTitleSafe( NS_USER
, $target );
79 $out->addHTML( $this->getForm() );
83 $userObj = User
::newFromName( $nt->getText(), false );
85 $out->addHTML( $this->getForm() );
89 $id = $userObj->getID();
91 if ( $this->opts
['contribs'] != 'newbie' ) {
92 $target = $nt->getText();
93 $out->addSubtitle( $this->contributionsSub( $userObj ) );
94 $out->setHTMLTitle( $this->msg(
96 $this->msg( 'contributions-title', $target )->plain()
98 $this->getSkin()->setRelevantUser( $userObj );
100 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
101 $out->setHTMLTitle( $this->msg(
103 $this->msg( 'sp-contributions-newbies-title' )->plain()
107 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
108 $this->opts
['namespace'] = intval( $ns );
110 $this->opts
['namespace'] = '';
113 $this->opts
['associated'] = $request->getBool( 'associated' );
114 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
115 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
117 // Allows reverts to have the bot flag in recent changes. It is just here to
118 // be passed in the form at the top of the page
119 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
120 $this->opts
['bot'] = '1';
123 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
124 # Offset overrides year/month selection
126 $this->opts
['year'] = '';
127 $this->opts
['month'] = '';
129 $this->opts
['year'] = $request->getIntOrNull( 'year' );
130 $this->opts
['month'] = $request->getIntOrNull( 'month' );
133 $feedType = $request->getVal( 'feed' );
135 // Maintain some level of backwards compatability
136 // If people request feeds using the old parameters, redirect to API
138 'action' => 'feedcontributions',
139 'feedformat' => $feedType,
142 if ( $this->opts
['topOnly'] ) {
143 $apiParams['toponly'] = true;
145 if ( $this->opts
['deletedOnly'] ) {
146 $apiParams['deletedonly'] = true;
148 if ( $this->opts
['tagfilter'] !== '' ) {
149 $apiParams['tagfilter'] = $this->opts
['tagfilter'];
151 if ( $this->opts
['namespace'] !== '' ) {
152 $apiParams['namespace'] = $this->opts
['namespace'];
154 if ( $this->opts
['year'] !== null ) {
155 $apiParams['year'] = $this->opts
['year'];
157 if ( $this->opts
['month'] !== null ) {
158 $apiParams['month'] = $this->opts
['month'];
161 $url = wfAppendQuery( wfScript( 'api' ), $apiParams );
163 $out->redirect( $url, '301' );
168 // Add RSS/atom links
169 $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) );
171 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
172 $out->addHTML( $this->getForm() );
174 $pager = new ContribsPager( $this->getContext(), array(
176 'contribs' => $this->opts
['contribs'],
177 'namespace' => $this->opts
['namespace'],
178 'tagfilter' => $this->opts
['tagfilter'],
179 'year' => $this->opts
['year'],
180 'month' => $this->opts
['month'],
181 'deletedOnly' => $this->opts
['deletedOnly'],
182 'topOnly' => $this->opts
['topOnly'],
183 'nsInvert' => $this->opts
['nsInvert'],
184 'associated' => $this->opts
['associated'],
187 if ( !$pager->getNumRows() ) {
188 $out->addWikiMsg( 'nocontribs', $target );
190 # Show a message about slave lag, if applicable
191 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
193 $out->showLagWarning( $lag );
197 '<p>' . $pager->getNavigationBar() . '</p>' .
199 '<p>' . $pager->getNavigationBar() . '</p>'
202 $out->preventClickjacking( $pager->getPreventClickjacking() );
204 # Show the appropriate "footer" message - WHOIS tools, etc.
205 if ( $this->opts
['contribs'] == 'newbie' ) {
206 $message = 'sp-contributions-footer-newbies';
207 } elseif ( IP
::isIPAddress( $target ) ) {
208 $message = 'sp-contributions-footer-anon';
209 } elseif ( $userObj->isAnon() ) {
210 // No message for non-existing users
213 $message = 'sp-contributions-footer';
217 if ( !$this->msg( $message, $target )->isDisabled() ) {
219 "<div class='mw-contributions-footer'>\n$1\n</div>",
220 array( $message, $target ) );
227 * Generates the subheading with links
228 * @param $userObj User object for the target
229 * @return String: appropriately-escaped HTML to be output literally
230 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
232 protected function contributionsSub( $userObj ) {
233 if ( $userObj->isAnon() ) {
234 $user = htmlspecialchars( $userObj->getName() );
236 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
238 $nt = $userObj->getUserPage();
239 $talk = $userObj->getTalkPage();
242 $tools = $this->getUserLinks( $nt, $talk, $userObj );
243 $links = $this->getLanguage()->pipeList( $tools );
245 // Show a note if the user is blocked and display the last block log entry.
246 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
247 // and also this will display a totally irrelevant log entry as a current block.
248 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
249 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
250 LogEventsList
::showLogExtract(
257 'showIfEmpty' => false,
260 'sp-contributions-blocked-notice-anon' :
261 'sp-contributions-blocked-notice',
262 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
264 'offset' => '' # don't use WebRequest parameter offset
270 // Old message 'contribsub' had one parameter, but that doesn't work for
271 // languages that want to put the "for" bit right after $user but before
272 // $links. If 'contribsub' is around, use it for reverse compatibility,
273 // otherwise use 'contribsub2'.
274 // @todo Should this be removed at some point?
275 $oldMsg = $this->msg( 'contribsub' );
276 if ( $oldMsg->exists() ) {
277 $linksWithParentheses = $this->msg( 'parentheses' )->rawParams( $links )->escaped();
279 return $oldMsg->rawParams( "$user $linksWithParentheses" );
282 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
286 * Links to different places.
287 * @param $userpage Title: Target user page
288 * @param $talkpage Title: Talk page
289 * @param $target User: Target user object
292 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
294 $id = $target->getId();
295 $username = $target->getName();
297 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
299 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
300 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
301 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
302 $tools[] = Linker
::linkKnown( # Change block link
303 SpecialPage
::getTitleFor( 'Block', $username ),
304 $this->msg( 'change-blocklink' )->escaped()
306 $tools[] = Linker
::linkKnown( # Unblock link
307 SpecialPage
::getTitleFor( 'Unblock', $username ),
308 $this->msg( 'unblocklink' )->escaped()
310 } else { # User is not blocked
311 $tools[] = Linker
::linkKnown( # Block link
312 SpecialPage
::getTitleFor( 'Block', $username ),
313 $this->msg( 'blocklink' )->escaped()
319 $tools[] = Linker
::linkKnown(
320 SpecialPage
::getTitleFor( 'Log', 'block' ),
321 $this->msg( 'sp-contributions-blocklog' )->escaped(),
323 array( 'page' => $userpage->getPrefixedText() )
327 $tools[] = Linker
::linkKnown(
328 SpecialPage
::getTitleFor( 'Listfiles', $username ),
329 $this->msg( 'sp-contributions-uploads' )->escaped()
333 $tools[] = Linker
::linkKnown(
334 SpecialPage
::getTitleFor( 'Log', $username ),
335 $this->msg( 'sp-contributions-logs' )->escaped()
338 # Add link to deleted user contributions for priviledged users
339 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
340 $tools[] = Linker
::linkKnown(
341 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
342 $this->msg( 'sp-contributions-deleted' )->escaped()
346 # Add a link to change user rights for privileged users
347 $userrightsPage = new UserrightsPage();
348 $userrightsPage->setContext( $this->getContext() );
349 if ( $userrightsPage->userCanChangeRights( $target ) ) {
350 $tools[] = Linker
::linkKnown(
351 SpecialPage
::getTitleFor( 'Userrights', $username ),
352 $this->msg( 'sp-contributions-userrights' )->escaped()
356 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
362 * Generates the namespace selector form with hidden attributes.
363 * @return String: HTML fragment
365 protected function getForm() {
368 $this->opts
['title'] = $this->getTitle()->getPrefixedText();
369 if ( !isset( $this->opts
['target'] ) ) {
370 $this->opts
['target'] = '';
372 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
375 if ( !isset( $this->opts
['namespace'] ) ) {
376 $this->opts
['namespace'] = '';
379 if ( !isset( $this->opts
['nsInvert'] ) ) {
380 $this->opts
['nsInvert'] = '';
383 if ( !isset( $this->opts
['associated'] ) ) {
384 $this->opts
['associated'] = false;
387 if ( !isset( $this->opts
['contribs'] ) ) {
388 $this->opts
['contribs'] = 'user';
391 if ( !isset( $this->opts
['year'] ) ) {
392 $this->opts
['year'] = '';
395 if ( !isset( $this->opts
['month'] ) ) {
396 $this->opts
['month'] = '';
399 if ( $this->opts
['contribs'] == 'newbie' ) {
400 $this->opts
['target'] = '';
403 if ( !isset( $this->opts
['tagfilter'] ) ) {
404 $this->opts
['tagfilter'] = '';
407 if ( !isset( $this->opts
['topOnly'] ) ) {
408 $this->opts
['topOnly'] = false;
411 $form = Html
::openElement(
415 'action' => $wgScript,
416 'class' => 'mw-contributions-form'
420 # Add hidden params for tracking except for parameters in $skipParameters
421 $skipParameters = array(
433 foreach ( $this->opts
as $name => $value ) {
434 if ( in_array( $name, $skipParameters ) ) {
437 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
440 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
443 $filterSelection = Html
::rawElement(
445 array( 'class' => 'mw-label' ),
446 array_shift( $tagFilter )
448 $filterSelection .= Html
::rawElement(
450 array( 'class' => 'mw-input' ),
451 implode( ' ', $tagFilter )
454 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
457 $labelNewbies = Xml
::radioLabel(
458 $this->msg( 'sp-contributions-newbies' )->text(),
462 $this->opts
['contribs'] == 'newbie',
463 array( 'class' => 'mw-input' )
465 $labelUsername = Xml
::radioLabel(
466 $this->msg( 'sp-contributions-username' )->text(),
470 $this->opts
['contribs'] == 'user',
471 array( 'class' => 'mw-input' )
473 $input = Html
::input(
475 $this->opts
['target'],
477 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
478 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
481 $targetSelection = Html
::rawElement(
483 array( 'colspan' => 2 ),
484 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
487 $namespaceSelection = Xml
::tags(
489 array( 'class' => 'mw-label' ),
491 $this->msg( 'namespace' )->text(),
496 $namespaceSelection .= Html
::rawElement(
499 Html
::namespaceSelector(
500 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
502 'name' => 'namespace',
504 'class' => 'namespaceselector',
509 array( 'style' => 'white-space: nowrap' ),
511 $this->msg( 'invert' )->text(),
514 $this->opts
['nsInvert'],
516 'title' => $this->msg( 'tooltip-invert' )->text(),
517 'class' => 'mw-input'
521 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
523 $this->msg( 'namespace_association' )->text(),
526 $this->opts
['associated'],
528 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
529 'class' => 'mw-input'
535 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
536 $deletedOnlyCheck = Html
::rawElement(
538 array( 'style' => 'white-space: nowrap' ),
540 $this->msg( 'history-show-deleted' )->text(),
542 'mw-show-deleted-only',
543 $this->opts
['deletedOnly'],
544 array( 'class' => 'mw-input' )
548 $deletedOnlyCheck = '';
551 $checkLabelTopOnly = Html
::rawElement(
553 array( 'style' => 'white-space: nowrap' ),
555 $this->msg( 'sp-contributions-toponly' )->text(),
558 $this->opts
['topOnly'],
559 array( 'class' => 'mw-input' )
562 $extraOptions = Html
::rawElement(
564 array( 'colspan' => 2 ),
565 $deletedOnlyCheck . $checkLabelTopOnly
568 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
570 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
574 $this->msg( 'sp-contributions-submit' )->text(),
575 array( 'class' => 'mw-submit' )
579 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
580 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
581 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
582 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
583 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
584 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
585 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
588 $explain = $this->msg( 'sp-contributions-explain' );
589 if ( !$explain->isBlank() ) {
590 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
593 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
598 protected function getGroupName() {
604 * Pager for Special:Contributions
605 * @ingroup SpecialPage Pager
607 class ContribsPager
extends ReverseChronologicalPager
{
608 public $mDefaultDirection = true;
609 var $messages, $target;
610 var $namespace = '', $mDb;
611 var $preventClickjacking = false;
616 protected $mParentLens;
618 function __construct( IContextSource
$context, array $options ) {
619 parent
::__construct( $context );
631 foreach ( $msgs as $msg ) {
632 $this->messages
[$msg] = $this->msg( $msg )->escaped();
635 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
636 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
637 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
638 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
639 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
640 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
642 $this->deletedOnly
= !empty( $options['deletedOnly'] );
643 $this->topOnly
= !empty( $options['topOnly'] );
645 $year = isset( $options['year'] ) ?
$options['year'] : false;
646 $month = isset( $options['month'] ) ?
$options['month'] : false;
647 $this->getDateCond( $year, $month );
649 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
652 function getDefaultQuery() {
653 $query = parent
::getDefaultQuery();
654 $query['target'] = $this->target
;
660 * This method basically executes the exact same code as the parent class, though with
661 * a hook added, to allow extentions to add additional queries.
663 * @param string $offset index offset, inclusive
664 * @param $limit Integer: exact query limit
665 * @param $descending Boolean: query direction, false for ascending, true for descending
666 * @return ResultWrapper
668 function reallyDoQuery( $offset, $limit, $descending ) {
669 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
677 * This hook will allow extensions to add in additional queries, so they can get their data
678 * in My Contributions as well. Extensions should append their results to the $data array.
680 * Extension queries have to implement the navbar requirement as well. They should
681 * - have a column aliased as $pager->getIndexField()
683 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
684 * - have the ORDER BY specified based upon the details provided by the navbar
686 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
688 * &$data: an array of results of all contribs queries
689 * $pager: the ContribsPager object hooked into
690 * $offset: see phpdoc above
691 * $limit: see phpdoc above
692 * $descending: see phpdoc above
694 $data = array( $this->mDb
->select( $tables, $fields, $conds, $fname, $options, $join_conds ) );
695 wfRunHooks( 'ContribsPager::reallyDoQuery', array( &$data, $pager, $offset, $limit, $descending ) );
699 // loop all results and collect them in an array
700 foreach ( $data as $query ) {
701 foreach ( $query as $i => $row ) {
702 // use index column as key, allowing us to easily sort in PHP
703 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
715 $result = array_slice( $result, 0, $limit );
717 // get rid of array keys
718 $result = array_values( $result );
720 return new FakeResultWrapper( $result );
723 function getQueryInfo() {
724 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
726 $user = $this->getUser();
727 $conds = array_merge( $userCond, $this->getNamespaceCond() );
729 // Paranoia: avoid brute force searches (bug 17342)
730 if ( !$user->isAllowed( 'deletedhistory' ) ) {
731 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
732 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
733 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
734 ' != ' . Revision
::SUPPRESSED_USER
;
737 # Don't include orphaned revisions
738 $join_cond['page'] = Revision
::pageJoinCond();
739 # Get the current user name for accounts
740 $join_cond['user'] = Revision
::userJoinCond();
744 'fields' => array_merge(
745 Revision
::selectFields(),
746 Revision
::selectUserFields(),
747 array( 'page_namespace', 'page_title', 'page_is_new',
748 'page_latest', 'page_is_redirect', 'page_len' )
751 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
752 'join_conds' => $join_cond
755 ChangeTags
::modifyDisplayQuery(
756 $queryInfo['tables'],
757 $queryInfo['fields'],
759 $queryInfo['join_conds'],
760 $queryInfo['options'],
764 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
769 function getUserCond() {
770 $condition = array();
771 $join_conds = array();
772 $tables = array( 'revision', 'page', 'user' );
773 if ( $this->contribs
== 'newbie' ) {
774 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
775 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
776 $index = 'user_timestamp';
777 # ignore local groups with the bot right
778 # @todo FIXME: Global groups may have 'bot' rights
779 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
780 if ( count( $groupsWithBotPermission ) ) {
781 $tables[] = 'user_groups';
782 $condition[] = 'ug_group IS NULL';
783 $join_conds['user_groups'] = array(
785 'ug_user = rev_user',
786 'ug_group' => $groupsWithBotPermission
791 $uid = User
::idFromName( $this->target
);
793 $condition['rev_user'] = $uid;
794 $index = 'user_timestamp';
796 $condition['rev_user_text'] = $this->target
;
797 $index = 'usertext_timestamp';
801 if ( $this->deletedOnly
) {
802 $condition[] = 'rev_deleted != 0';
805 if ( $this->topOnly
) {
806 $condition[] = 'rev_id = page_latest';
809 return array( $tables, $index, $condition, $join_conds );
812 function getNamespaceCond() {
813 if ( $this->namespace !== '' ) {
814 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
815 $eq_op = $this->nsInvert ?
'!=' : '=';
816 $bool_op = $this->nsInvert ?
'AND' : 'OR';
818 if ( !$this->associated
) {
819 return array( "page_namespace $eq_op $selectedNS" );
822 $associatedNS = $this->mDb
->addQuotes(
823 MWNamespace
::getAssociated( $this->namespace )
827 "page_namespace $eq_op $selectedNS " .
829 " page_namespace $eq_op $associatedNS"
836 function getIndexField() {
837 return 'rev_timestamp';
840 function doBatchLookups() {
841 # Do a link batch query
842 $this->mResult
->seek( 0 );
844 $batch = new LinkBatch();
845 # Give some pointers to make (last) links
846 foreach ( $this->mResult
as $row ) {
847 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
848 $revIds[] = $row->rev_parent_id
;
850 if ( isset( $row->rev_id
) ) {
851 if ( $this->contribs
=== 'newbie' ) { // multiple users
852 $batch->add( NS_USER
, $row->user_name
);
853 $batch->add( NS_USER_TALK
, $row->user_name
);
855 $batch->add( $row->page_namespace
, $row->page_title
);
858 $this->mParentLens
= Revision
::getParentLengths( $this->getDatabase(), $revIds );
860 $this->mResult
->seek( 0 );
866 function getStartBody() {
873 function getEndBody() {
878 * Generates each row in the contributions list.
880 * Contributions which are marked "top" are currently on top of the history.
881 * For these contributions, a [rollback] link is shown for users with roll-
882 * back privileges. The rollback link restores the most recent version that
883 * was not written by the target user.
885 * @todo This would probably look a lot nicer in a table.
889 function formatRow( $row ) {
890 wfProfileIn( __METHOD__
);
896 * There may be more than just revision rows. To make sure that we'll only be processing
897 * revisions here, let's _try_ to build a revision out of our row (without displaying
898 * notices though) and then trying to grab data from the built object. If we succeed,
899 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
900 * to extensions to subscribe to the hook to parse the row.
902 wfSuppressWarnings();
903 $rev = new Revision( $row );
904 $validRevision = (bool)$rev->getId();
907 if ( $validRevision ) {
910 $page = Title
::newFromRow( $row );
911 $link = Linker
::link(
913 htmlspecialchars( $page->getPrefixedText() ),
914 array( 'class' => 'mw-contributions-title' ),
915 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
917 # Mark current revisions
919 $user = $this->getUser();
920 if ( $row->rev_id
== $row->page_latest
) {
921 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
923 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
924 && $page->quickUserCan( 'edit', $user )
926 $this->preventClickjacking();
927 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
930 # Is there a visible previous revision?
931 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
932 $difftext = Linker
::linkKnown(
934 $this->messages
['diff'],
938 'oldid' => $row->rev_id
942 $difftext = $this->messages
['diff'];
944 $histlink = Linker
::linkKnown(
946 $this->messages
['hist'],
948 array( 'action' => 'history' )
951 if ( $row->rev_parent_id
=== null ) {
952 // For some reason rev_parent_id isn't populated for this row.
953 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
954 // Next best thing is to have the total number of bytes.
955 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
956 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
957 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
959 $parentLen = isset( $this->mParentLens
[$row->rev_parent_id
] ) ?
$this->mParentLens
[$row->rev_parent_id
] : 0;
960 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
961 $chardiff .= ChangesList
::showCharacterDifference(
966 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
969 $lang = $this->getLanguage();
970 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
971 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
972 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
973 $d = Linker
::linkKnown(
975 htmlspecialchars( $date ),
976 array( 'class' => 'mw-changeslist-date' ),
977 array( 'oldid' => intval( $row->rev_id
) )
980 $d = htmlspecialchars( $date );
982 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
983 $d = '<span class="history-deleted">' . $d . '</span>';
986 # Show user names for /newbies as there may be different users.
987 # Note that we already excluded rows with hidden user names.
988 if ( $this->contribs
== 'newbie' ) {
989 $userlink = ' . . ' . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
990 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
991 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
996 if ( $rev->getParentId() === 0 ) {
997 $nflag = ChangesList
::flag( 'newpage' );
1002 if ( $rev->isMinor() ) {
1003 $mflag = ChangesList
::flag( 'minor' );
1008 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1009 if ( $del !== '' ) {
1013 $diffHistLinks = $this->msg( 'parentheses' )
1014 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1016 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
1018 # Denote if username is redacted for this edit
1019 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1020 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
1024 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1028 $classes = array_merge( $classes, $newClasses );
1029 $ret .= " $tagSummary";
1032 // Let extensions add data
1033 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1035 if ( $classes === array() && $ret === '' ) {
1036 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1037 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1039 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1042 wfProfileOut( __METHOD__
);
1048 * Overwrite Pager function and return a helpful comment
1051 function getSqlComment() {
1052 if ( $this->namespace ||
$this->deletedOnly
) {
1053 // potentially slow, see CR r58153
1054 return 'contributions page filtered for namespace or RevisionDeleted edits';
1056 return 'contributions page unfiltered';
1060 protected function preventClickjacking() {
1061 $this->preventClickjacking
= true;
1067 public function getPreventClickjacking() {
1068 return $this->preventClickjacking
;