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 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
274 * Links to different places.
275 * @param $userpage Title: Target user page
276 * @param $talkpage Title: Talk page
277 * @param $target User: Target user object
280 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
282 $id = $target->getId();
283 $username = $target->getName();
285 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
287 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
288 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
289 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
290 $tools[] = Linker
::linkKnown( # Change block link
291 SpecialPage
::getTitleFor( 'Block', $username ),
292 $this->msg( 'change-blocklink' )->escaped()
294 $tools[] = Linker
::linkKnown( # Unblock link
295 SpecialPage
::getTitleFor( 'Unblock', $username ),
296 $this->msg( 'unblocklink' )->escaped()
298 } else { # User is not blocked
299 $tools[] = Linker
::linkKnown( # Block link
300 SpecialPage
::getTitleFor( 'Block', $username ),
301 $this->msg( 'blocklink' )->escaped()
307 $tools[] = Linker
::linkKnown(
308 SpecialPage
::getTitleFor( 'Log', 'block' ),
309 $this->msg( 'sp-contributions-blocklog' )->escaped(),
311 array( 'page' => $userpage->getPrefixedText() )
315 $tools[] = Linker
::linkKnown(
316 SpecialPage
::getTitleFor( 'Listfiles', $username ),
317 $this->msg( 'sp-contributions-uploads' )->escaped()
321 $tools[] = Linker
::linkKnown(
322 SpecialPage
::getTitleFor( 'Log', $username ),
323 $this->msg( 'sp-contributions-logs' )->escaped()
326 # Add link to deleted user contributions for priviledged users
327 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
328 $tools[] = Linker
::linkKnown(
329 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
330 $this->msg( 'sp-contributions-deleted' )->escaped()
334 # Add a link to change user rights for privileged users
335 $userrightsPage = new UserrightsPage();
336 $userrightsPage->setContext( $this->getContext() );
337 if ( $userrightsPage->userCanChangeRights( $target ) ) {
338 $tools[] = Linker
::linkKnown(
339 SpecialPage
::getTitleFor( 'Userrights', $username ),
340 $this->msg( 'sp-contributions-userrights' )->escaped()
344 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
350 * Generates the namespace selector form with hidden attributes.
351 * @return String: HTML fragment
353 protected function getForm() {
356 $this->opts
['title'] = $this->getTitle()->getPrefixedText();
357 if ( !isset( $this->opts
['target'] ) ) {
358 $this->opts
['target'] = '';
360 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
363 if ( !isset( $this->opts
['namespace'] ) ) {
364 $this->opts
['namespace'] = '';
367 if ( !isset( $this->opts
['nsInvert'] ) ) {
368 $this->opts
['nsInvert'] = '';
371 if ( !isset( $this->opts
['associated'] ) ) {
372 $this->opts
['associated'] = false;
375 if ( !isset( $this->opts
['contribs'] ) ) {
376 $this->opts
['contribs'] = 'user';
379 if ( !isset( $this->opts
['year'] ) ) {
380 $this->opts
['year'] = '';
383 if ( !isset( $this->opts
['month'] ) ) {
384 $this->opts
['month'] = '';
387 if ( $this->opts
['contribs'] == 'newbie' ) {
388 $this->opts
['target'] = '';
391 if ( !isset( $this->opts
['tagfilter'] ) ) {
392 $this->opts
['tagfilter'] = '';
395 if ( !isset( $this->opts
['topOnly'] ) ) {
396 $this->opts
['topOnly'] = false;
399 $form = Html
::openElement(
403 'action' => $wgScript,
404 'class' => 'mw-contributions-form'
408 # Add hidden params for tracking except for parameters in $skipParameters
409 $skipParameters = array(
421 foreach ( $this->opts
as $name => $value ) {
422 if ( in_array( $name, $skipParameters ) ) {
425 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
428 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
431 $filterSelection = Html
::rawElement(
433 array( 'class' => 'mw-label' ),
434 array_shift( $tagFilter )
436 $filterSelection .= Html
::rawElement(
438 array( 'class' => 'mw-input' ),
439 implode( ' ', $tagFilter )
442 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
445 $labelNewbies = Xml
::radioLabel(
446 $this->msg( 'sp-contributions-newbies' )->text(),
450 $this->opts
['contribs'] == 'newbie',
451 array( 'class' => 'mw-input' )
453 $labelUsername = Xml
::radioLabel(
454 $this->msg( 'sp-contributions-username' )->text(),
458 $this->opts
['contribs'] == 'user',
459 array( 'class' => 'mw-input' )
461 $input = Html
::input(
463 $this->opts
['target'],
465 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
466 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
469 $targetSelection = Html
::rawElement(
471 array( 'colspan' => 2 ),
472 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
475 $namespaceSelection = Xml
::tags(
477 array( 'class' => 'mw-label' ),
479 $this->msg( 'namespace' )->text(),
484 $namespaceSelection .= Html
::rawElement(
487 Html
::namespaceSelector(
488 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
490 'name' => 'namespace',
492 'class' => 'namespaceselector',
497 array( 'style' => 'white-space: nowrap' ),
499 $this->msg( 'invert' )->text(),
502 $this->opts
['nsInvert'],
504 'title' => $this->msg( 'tooltip-invert' )->text(),
505 'class' => 'mw-input'
509 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
511 $this->msg( 'namespace_association' )->text(),
514 $this->opts
['associated'],
516 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
517 'class' => 'mw-input'
523 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
524 $deletedOnlyCheck = Html
::rawElement(
526 array( 'style' => 'white-space: nowrap' ),
528 $this->msg( 'history-show-deleted' )->text(),
530 'mw-show-deleted-only',
531 $this->opts
['deletedOnly'],
532 array( 'class' => 'mw-input' )
536 $deletedOnlyCheck = '';
539 $checkLabelTopOnly = Html
::rawElement(
541 array( 'style' => 'white-space: nowrap' ),
543 $this->msg( 'sp-contributions-toponly' )->text(),
546 $this->opts
['topOnly'],
547 array( 'class' => 'mw-input' )
550 $extraOptions = Html
::rawElement(
552 array( 'colspan' => 2 ),
553 $deletedOnlyCheck . $checkLabelTopOnly
556 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
558 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
562 $this->msg( 'sp-contributions-submit' )->text(),
563 array( 'class' => 'mw-submit' )
567 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
568 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
569 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
570 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
571 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
572 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
573 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
576 $explain = $this->msg( 'sp-contributions-explain' );
577 if ( !$explain->isBlank() ) {
578 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
581 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
586 protected function getGroupName() {
592 * Pager for Special:Contributions
593 * @ingroup SpecialPage Pager
595 class ContribsPager
extends ReverseChronologicalPager
{
596 public $mDefaultDirection = true;
597 var $messages, $target;
598 var $namespace = '', $mDb;
599 var $preventClickjacking = false;
604 protected $mParentLens;
606 function __construct( IContextSource
$context, array $options ) {
607 parent
::__construct( $context );
619 foreach ( $msgs as $msg ) {
620 $this->messages
[$msg] = $this->msg( $msg )->escaped();
623 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
624 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
625 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
626 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
627 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
628 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
630 $this->deletedOnly
= !empty( $options['deletedOnly'] );
631 $this->topOnly
= !empty( $options['topOnly'] );
633 $year = isset( $options['year'] ) ?
$options['year'] : false;
634 $month = isset( $options['month'] ) ?
$options['month'] : false;
635 $this->getDateCond( $year, $month );
637 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
640 function getDefaultQuery() {
641 $query = parent
::getDefaultQuery();
642 $query['target'] = $this->target
;
648 * This method basically executes the exact same code as the parent class, though with
649 * a hook added, to allow extentions to add additional queries.
651 * @param string $offset index offset, inclusive
652 * @param $limit Integer: exact query limit
653 * @param $descending Boolean: query direction, false for ascending, true for descending
654 * @return ResultWrapper
656 function reallyDoQuery( $offset, $limit, $descending ) {
657 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
665 * This hook will allow extensions to add in additional queries, so they can get their data
666 * in My Contributions as well. Extensions should append their results to the $data array.
668 * Extension queries have to implement the navbar requirement as well. They should
669 * - have a column aliased as $pager->getIndexField()
671 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
672 * - have the ORDER BY specified based upon the details provided by the navbar
674 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
676 * &$data: an array of results of all contribs queries
677 * $pager: the ContribsPager object hooked into
678 * $offset: see phpdoc above
679 * $limit: see phpdoc above
680 * $descending: see phpdoc above
682 $data = array( $this->mDb
->select( $tables, $fields, $conds, $fname, $options, $join_conds ) );
683 wfRunHooks( 'ContribsPager::reallyDoQuery', array( &$data, $pager, $offset, $limit, $descending ) );
687 // loop all results and collect them in an array
688 foreach ( $data as $query ) {
689 foreach ( $query as $i => $row ) {
690 // use index column as key, allowing us to easily sort in PHP
691 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
703 $result = array_slice( $result, 0, $limit );
705 // get rid of array keys
706 $result = array_values( $result );
708 return new FakeResultWrapper( $result );
711 function getQueryInfo() {
712 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
714 $user = $this->getUser();
715 $conds = array_merge( $userCond, $this->getNamespaceCond() );
717 // Paranoia: avoid brute force searches (bug 17342)
718 if ( !$user->isAllowed( 'deletedhistory' ) ) {
719 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
720 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
721 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
722 ' != ' . Revision
::SUPPRESSED_USER
;
725 # Don't include orphaned revisions
726 $join_cond['page'] = Revision
::pageJoinCond();
727 # Get the current user name for accounts
728 $join_cond['user'] = Revision
::userJoinCond();
732 'fields' => array_merge(
733 Revision
::selectFields(),
734 Revision
::selectUserFields(),
735 array( 'page_namespace', 'page_title', 'page_is_new',
736 'page_latest', 'page_is_redirect', 'page_len' )
739 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
740 'join_conds' => $join_cond
743 ChangeTags
::modifyDisplayQuery(
744 $queryInfo['tables'],
745 $queryInfo['fields'],
747 $queryInfo['join_conds'],
748 $queryInfo['options'],
752 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
757 function getUserCond() {
758 $condition = array();
759 $join_conds = array();
760 $tables = array( 'revision', 'page', 'user' );
761 if ( $this->contribs
== 'newbie' ) {
762 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
763 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
764 $index = 'user_timestamp';
765 # ignore local groups with the bot right
766 # @todo FIXME: Global groups may have 'bot' rights
767 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
768 if ( count( $groupsWithBotPermission ) ) {
769 $tables[] = 'user_groups';
770 $condition[] = 'ug_group IS NULL';
771 $join_conds['user_groups'] = array(
773 'ug_user = rev_user',
774 'ug_group' => $groupsWithBotPermission
779 $uid = User
::idFromName( $this->target
);
781 $condition['rev_user'] = $uid;
782 $index = 'user_timestamp';
784 $condition['rev_user_text'] = $this->target
;
785 $index = 'usertext_timestamp';
789 if ( $this->deletedOnly
) {
790 $condition[] = 'rev_deleted != 0';
793 if ( $this->topOnly
) {
794 $condition[] = 'rev_id = page_latest';
797 return array( $tables, $index, $condition, $join_conds );
800 function getNamespaceCond() {
801 if ( $this->namespace !== '' ) {
802 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
803 $eq_op = $this->nsInvert ?
'!=' : '=';
804 $bool_op = $this->nsInvert ?
'AND' : 'OR';
806 if ( !$this->associated
) {
807 return array( "page_namespace $eq_op $selectedNS" );
810 $associatedNS = $this->mDb
->addQuotes(
811 MWNamespace
::getAssociated( $this->namespace )
815 "page_namespace $eq_op $selectedNS " .
817 " page_namespace $eq_op $associatedNS"
824 function getIndexField() {
825 return 'rev_timestamp';
828 function doBatchLookups() {
829 # Do a link batch query
830 $this->mResult
->seek( 0 );
832 $batch = new LinkBatch();
833 # Give some pointers to make (last) links
834 foreach ( $this->mResult
as $row ) {
835 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
836 $revIds[] = $row->rev_parent_id
;
838 if ( isset( $row->rev_id
) ) {
839 if ( $this->contribs
=== 'newbie' ) { // multiple users
840 $batch->add( NS_USER
, $row->user_name
);
841 $batch->add( NS_USER_TALK
, $row->user_name
);
843 $batch->add( $row->page_namespace
, $row->page_title
);
846 $this->mParentLens
= Revision
::getParentLengths( $this->getDatabase(), $revIds );
848 $this->mResult
->seek( 0 );
854 function getStartBody() {
861 function getEndBody() {
866 * Generates each row in the contributions list.
868 * Contributions which are marked "top" are currently on top of the history.
869 * For these contributions, a [rollback] link is shown for users with roll-
870 * back privileges. The rollback link restores the most recent version that
871 * was not written by the target user.
873 * @todo This would probably look a lot nicer in a table.
877 function formatRow( $row ) {
878 wfProfileIn( __METHOD__
);
884 * There may be more than just revision rows. To make sure that we'll only be processing
885 * revisions here, let's _try_ to build a revision out of our row (without displaying
886 * notices though) and then trying to grab data from the built object. If we succeed,
887 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
888 * to extensions to subscribe to the hook to parse the row.
890 wfSuppressWarnings();
891 $rev = new Revision( $row );
892 $validRevision = (bool)$rev->getId();
895 if ( $validRevision ) {
898 $page = Title
::newFromRow( $row );
899 $link = Linker
::link(
901 htmlspecialchars( $page->getPrefixedText() ),
902 array( 'class' => 'mw-contributions-title' ),
903 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
905 # Mark current revisions
907 $user = $this->getUser();
908 if ( $row->rev_id
== $row->page_latest
) {
909 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
911 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
912 && $page->quickUserCan( 'edit', $user )
914 $this->preventClickjacking();
915 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
918 # Is there a visible previous revision?
919 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
920 $difftext = Linker
::linkKnown(
922 $this->messages
['diff'],
926 'oldid' => $row->rev_id
930 $difftext = $this->messages
['diff'];
932 $histlink = Linker
::linkKnown(
934 $this->messages
['hist'],
936 array( 'action' => 'history' )
939 if ( $row->rev_parent_id
=== null ) {
940 // For some reason rev_parent_id isn't populated for this row.
941 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
942 // Next best thing is to have the total number of bytes.
943 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
944 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
945 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
947 $parentLen = isset( $this->mParentLens
[$row->rev_parent_id
] ) ?
$this->mParentLens
[$row->rev_parent_id
] : 0;
948 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
949 $chardiff .= ChangesList
::showCharacterDifference(
954 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
957 $lang = $this->getLanguage();
958 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
959 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
960 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
961 $d = Linker
::linkKnown(
963 htmlspecialchars( $date ),
964 array( 'class' => 'mw-changeslist-date' ),
965 array( 'oldid' => intval( $row->rev_id
) )
968 $d = htmlspecialchars( $date );
970 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
971 $d = '<span class="history-deleted">' . $d . '</span>';
974 # Show user names for /newbies as there may be different users.
975 # Note that we already excluded rows with hidden user names.
976 if ( $this->contribs
== 'newbie' ) {
977 $userlink = ' . . ' . $lang->getDirMark() . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
978 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
979 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
984 if ( $rev->getParentId() === 0 ) {
985 $nflag = ChangesList
::flag( 'newpage' );
990 if ( $rev->isMinor() ) {
991 $mflag = ChangesList
::flag( 'minor' );
996 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1001 $diffHistLinks = $this->msg( 'parentheses' )
1002 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1004 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
1006 # Denote if username is redacted for this edit
1007 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1008 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
1012 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1016 $classes = array_merge( $classes, $newClasses );
1017 $ret .= " $tagSummary";
1020 // Let extensions add data
1021 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1023 if ( $classes === array() && $ret === '' ) {
1024 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1025 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1027 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1030 wfProfileOut( __METHOD__
);
1036 * Overwrite Pager function and return a helpful comment
1039 function getSqlComment() {
1040 if ( $this->namespace ||
$this->deletedOnly
) {
1041 // potentially slow, see CR r58153
1042 return 'contributions page filtered for namespace or RevisionDeleted edits';
1044 return 'contributions page unfiltered';
1048 protected function preventClickjacking() {
1049 $this->preventClickjacking
= true;
1055 public function getPreventClickjacking() {
1056 return $this->preventClickjacking
;