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() );
70 $user = $this->getUser();
72 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
73 $this->opts
['target'] = $target;
74 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
76 $nt = Title
::makeTitleSafe( NS_USER
, $target );
78 $out->addHTML( $this->getForm() );
81 $userObj = User
::newFromName( $nt->getText(), false );
83 $out->addHTML( $this->getForm() );
86 $id = $userObj->getID();
88 if ( $this->opts
['contribs'] != 'newbie' ) {
89 $target = $nt->getText();
90 $out->addSubtitle( $this->contributionsSub( $userObj ) );
91 $out->setHTMLTitle( $this->msg(
93 $this->msg( 'contributions-title', $target )->plain()
95 $this->getSkin()->setRelevantUser( $userObj );
97 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
98 $out->setHTMLTitle( $this->msg(
100 $this->msg( 'sp-contributions-newbies-title' )->plain()
104 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
105 $this->opts
['namespace'] = intval( $ns );
107 $this->opts
['namespace'] = '';
110 $this->opts
['associated'] = $request->getBool( 'associated' );
111 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
112 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
114 // Allows reverts to have the bot flag in recent changes. It is just here to
115 // be passed in the form at the top of the page
116 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
117 $this->opts
['bot'] = '1';
120 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
121 # Offset overrides year/month selection
123 $this->opts
['year'] = '';
124 $this->opts
['month'] = '';
126 $this->opts
['year'] = $request->getIntOrNull( 'year' );
127 $this->opts
['month'] = $request->getIntOrNull( 'month' );
130 $feedType = $request->getVal( 'feed' );
132 // Maintain some level of backwards compatability
133 // If people request feeds using the old parameters, redirect to API
135 'action' => 'feedcontributions',
136 'feedformat' => $feedType,
139 if ( $this->opts
['topOnly'] ) {
140 $apiParams['toponly'] = true;
142 if ( $this->opts
['deletedOnly'] ) {
143 $apiParams['deletedonly'] = true;
145 if ( $this->opts
['tagfilter'] !== '' ) {
146 $apiParams['tagfilter'] = $this->opts
['tagfilter'];
148 if ( $this->opts
['namespace'] !== '' ) {
149 $apiParams['namespace'] = $this->opts
['namespace'];
151 if ( $this->opts
['year'] !== null ) {
152 $apiParams['year'] = $this->opts
['year'];
154 if ( $this->opts
['month'] !== null ) {
155 $apiParams['month'] = $this->opts
['month'];
158 $url = wfScript( 'api' ) . '?' . wfArrayToCgi( $apiParams );
160 $out->redirect( $url, '301' );
164 // Add RSS/atom links
165 $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) );
167 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
168 $out->addHTML( $this->getForm() );
170 $pager = new ContribsPager( $this->getContext(), array(
172 'contribs' => $this->opts
['contribs'],
173 'namespace' => $this->opts
['namespace'],
174 'year' => $this->opts
['year'],
175 'month' => $this->opts
['month'],
176 'deletedOnly' => $this->opts
['deletedOnly'],
177 'topOnly' => $this->opts
['topOnly'],
178 'nsInvert' => $this->opts
['nsInvert'],
179 'associated' => $this->opts
['associated'],
182 if ( !$pager->getNumRows() ) {
183 $out->addWikiMsg( 'nocontribs', $target );
185 # Show a message about slave lag, if applicable
186 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
188 $out->showLagWarning( $lag );
192 '<p>' . $pager->getNavigationBar() . '</p>' .
194 '<p>' . $pager->getNavigationBar() . '</p>'
197 $out->preventClickjacking( $pager->getPreventClickjacking() );
199 # Show the appropriate "footer" message - WHOIS tools, etc.
200 if ( $this->opts
['contribs'] == 'newbie' ) {
201 $message = 'sp-contributions-footer-newbies';
202 } elseif ( IP
::isIPAddress( $target ) ) {
203 $message = 'sp-contributions-footer-anon';
204 } elseif ( $userObj->isAnon() ) {
205 // No message for non-existing users
208 $message = 'sp-contributions-footer';
212 if ( !$this->msg( $message, $target )->isDisabled() ) {
214 "<div class='mw-contributions-footer'>\n$1\n</div>",
215 array( $message, $target ) );
222 * Generates the subheading with links
223 * @param $userObj User object for the target
224 * @return String: appropriately-escaped HTML to be output literally
225 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
227 protected function contributionsSub( $userObj ) {
228 if ( $userObj->isAnon() ) {
229 $user = htmlspecialchars( $userObj->getName() );
231 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
233 $nt = $userObj->getUserPage();
234 $talk = $userObj->getTalkPage();
237 $tools = $this->getUserLinks( $nt, $talk, $userObj );
238 $links = $this->getLanguage()->pipeList( $tools );
240 // Show a note if the user is blocked and display the last block log entry.
241 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
242 // and also this will display a totally irrelevant log entry as a current block.
243 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
244 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
245 LogEventsList
::showLogExtract(
252 'showIfEmpty' => false,
255 'sp-contributions-blocked-notice-anon' :
256 'sp-contributions-blocked-notice',
257 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
259 'offset' => '' # don't use WebRequest parameter offset
265 // Old message 'contribsub' had one parameter, but that doesn't work for
266 // languages that want to put the "for" bit right after $user but before
267 // $links. If 'contribsub' is around, use it for reverse compatibility,
268 // otherwise use 'contribsub2'.
269 // @todo Should this be removed at some point?
270 $oldMsg = $this->msg( 'contribsub' );
271 if ( $oldMsg->exists() ) {
272 $linksWithParentheses = $this->msg( 'parentheses' )->rawParams( $links )->escaped();
273 return $oldMsg->rawParams( "$user $linksWithParentheses" );
276 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
280 * Links to different places.
281 * @param $userpage Title: Target user page
282 * @param $talkpage Title: Talk page
283 * @param $target User: Target user object
286 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
288 $id = $target->getId();
289 $username = $target->getName();
291 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
293 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
294 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
295 if ( $target->isBlocked() ) {
296 $tools[] = Linker
::linkKnown( # Change block link
297 SpecialPage
::getTitleFor( 'Block', $username ),
298 $this->msg( 'change-blocklink' )->escaped()
300 $tools[] = Linker
::linkKnown( # Unblock link
301 SpecialPage
::getTitleFor( 'Unblock', $username ),
302 $this->msg( 'unblocklink' )->escaped()
304 } else { # User is not blocked
305 $tools[] = Linker
::linkKnown( # Block link
306 SpecialPage
::getTitleFor( 'Block', $username ),
307 $this->msg( 'blocklink' )->escaped()
312 $tools[] = Linker
::linkKnown(
313 SpecialPage
::getTitleFor( 'Log', 'block' ),
314 $this->msg( 'sp-contributions-blocklog' )->escaped(),
316 array( 'page' => $userpage->getPrefixedText() )
320 $tools[] = Linker
::linkKnown(
321 SpecialPage
::getTitleFor( 'Listfiles', $username ),
322 $this->msg( 'sp-contributions-uploads' )->escaped()
326 $tools[] = Linker
::linkKnown(
327 SpecialPage
::getTitleFor( 'Log', $username ),
328 $this->msg( 'sp-contributions-logs' )->escaped()
331 # Add link to deleted user contributions for priviledged users
332 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
333 $tools[] = Linker
::linkKnown(
334 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
335 $this->msg( 'sp-contributions-deleted' )->escaped()
339 # Add a link to change user rights for privileged users
340 $userrightsPage = new UserrightsPage();
341 $userrightsPage->setContext( $this->getContext() );
342 if ( $userrightsPage->userCanChangeRights( $target ) ) {
343 $tools[] = Linker
::linkKnown(
344 SpecialPage
::getTitleFor( 'Userrights', $username ),
345 $this->msg( 'sp-contributions-userrights' )->escaped()
349 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
354 * Generates the namespace selector form with hidden attributes.
355 * @return String: HTML fragment
357 protected function getForm() {
360 $this->opts
['title'] = $this->getTitle()->getPrefixedText();
361 if ( !isset( $this->opts
['target'] ) ) {
362 $this->opts
['target'] = '';
364 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
367 if ( !isset( $this->opts
['namespace'] ) ) {
368 $this->opts
['namespace'] = '';
371 if ( !isset( $this->opts
['nsInvert'] ) ) {
372 $this->opts
['nsInvert'] = '';
375 if ( !isset( $this->opts
['associated'] ) ) {
376 $this->opts
['associated'] = false;
379 if ( !isset( $this->opts
['contribs'] ) ) {
380 $this->opts
['contribs'] = 'user';
383 if ( !isset( $this->opts
['year'] ) ) {
384 $this->opts
['year'] = '';
387 if ( !isset( $this->opts
['month'] ) ) {
388 $this->opts
['month'] = '';
391 if ( $this->opts
['contribs'] == 'newbie' ) {
392 $this->opts
['target'] = '';
395 if ( !isset( $this->opts
['tagfilter'] ) ) {
396 $this->opts
['tagfilter'] = '';
399 if ( !isset( $this->opts
['topOnly'] ) ) {
400 $this->opts
['topOnly'] = false;
403 $form = Html
::openElement(
407 'action' => $wgScript,
408 'class' => 'mw-contributions-form'
412 # Add hidden params for tracking except for parameters in $skipParameters
413 $skipParameters = array(
425 foreach ( $this->opts
as $name => $value ) {
426 if ( in_array( $name, $skipParameters ) ) {
429 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
432 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
435 $filterSelection = Html
::rawElement(
437 array( 'class' => 'mw-label' ),
438 array_shift( $tagFilter )
440 $filterSelection .= Html
::rawElement(
442 array( 'class' => 'mw-input' ),
443 implode( ' ', $tagFilter )
446 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
449 $labelNewbies = Xml
::radioLabel(
450 $this->msg( 'sp-contributions-newbies' )->text(),
454 $this->opts
['contribs'] == 'newbie',
455 array( 'class' => 'mw-input' )
457 $labelUsername = Xml
::radioLabel(
458 $this->msg( 'sp-contributions-username' )->text(),
462 $this->opts
['contribs'] == 'user',
463 array( 'class' => 'mw-input' )
465 $input = Html
::input(
467 $this->opts
['target'],
469 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
470 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
473 $targetSelection = Html
::rawElement(
475 array( 'colspan' => 2 ),
476 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
479 $namespaceSelection = Xml
::tags(
481 array( 'class' => 'mw-label' ),
483 $this->msg( 'namespace' )->text(),
488 $namespaceSelection .= Html
::rawElement(
491 Html
::namespaceSelector(
492 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
494 'name' => 'namespace',
496 'class' => 'namespaceselector',
501 array( 'style' => 'white-space: nowrap' ),
503 $this->msg( 'invert' )->text(),
506 $this->opts
['nsInvert'],
508 'title' => $this->msg( 'tooltip-invert' )->text(),
509 'class' => 'mw-input'
513 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
515 $this->msg( 'namespace_association' )->text(),
518 $this->opts
['associated'],
520 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
521 'class' => 'mw-input'
527 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
528 $deletedOnlyCheck = Html
::rawElement(
530 array( 'style' => 'white-space: nowrap' ),
532 $this->msg( 'history-show-deleted' )->text(),
534 'mw-show-deleted-only',
535 $this->opts
['deletedOnly'],
536 array( 'class' => 'mw-input' )
540 $deletedOnlyCheck = '';
543 $checkLabelTopOnly = Html
::rawElement(
545 array( 'style' => 'white-space: nowrap' ),
547 $this->msg( 'sp-contributions-toponly' )->text(),
550 $this->opts
['topOnly'],
551 array( 'class' => 'mw-input' )
554 $extraOptions = Html
::rawElement(
556 array( 'colspan' => 2 ),
557 $deletedOnlyCheck . $checkLabelTopOnly
560 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
566 $this->msg( 'sp-contributions-submit' )->text(),
567 array( 'class' => 'mw-submit' )
571 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
572 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
573 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
574 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
575 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
576 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
577 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
580 $explain = $this->msg( 'sp-contributions-explain' );
581 if ( !$explain->isBlank() ) {
582 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
585 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
590 protected function getGroupName() {
596 * Pager for Special:Contributions
597 * @ingroup SpecialPage Pager
599 class ContribsPager
extends ReverseChronologicalPager
{
600 public $mDefaultDirection = true;
601 var $messages, $target;
602 var $namespace = '', $mDb;
603 var $preventClickjacking = false;
608 protected $mParentLens;
610 function __construct( IContextSource
$context, array $options ) {
611 parent
::__construct( $context );
623 foreach ( $msgs as $msg ) {
624 $this->messages
[$msg] = $this->msg( $msg )->escaped();
627 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
628 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
629 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
630 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
631 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
632 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
634 $this->deletedOnly
= !empty( $options['deletedOnly'] );
635 $this->topOnly
= !empty( $options['topOnly'] );
637 $year = isset( $options['year'] ) ?
$options['year'] : false;
638 $month = isset( $options['month'] ) ?
$options['month'] : false;
639 $this->getDateCond( $year, $month );
641 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
644 function getDefaultQuery() {
645 $query = parent
::getDefaultQuery();
646 $query['target'] = $this->target
;
651 * This method basically executes the exact same code as the parent class, though with
652 * a hook added, to allow extentions to add additional queries.
654 * @param string $offset index offset, inclusive
655 * @param $limit Integer: exact query limit
656 * @param $descending Boolean: query direction, false for ascending, true for descending
657 * @return ResultWrapper
659 function reallyDoQuery( $offset, $limit, $descending ) {
660 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
668 * This hook will allow extensions to add in additional queries, so they can get their data
669 * in My Contributions as well. Extensions should append their results to the $data array.
671 * Extension queries have to implement the navbar requirement as well. They should
672 * - have a column aliased as $pager->getIndexField()
674 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
675 * - have the ORDER BY specified based upon the details provided by the navbar
677 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
679 * &$data: an array of results of all contribs queries
680 * $pager: the ContribsPager object hooked into
681 * $offset: see phpdoc above
682 * $limit: see phpdoc above
683 * $descending: see phpdoc above
685 $data = array( $this->mDb
->select( $tables, $fields, $conds, $fname, $options, $join_conds ) );
686 wfRunHooks( 'ContribsPager::reallyDoQuery', array( &$data, $pager, $offset, $limit, $descending ) );
690 // loop all results and collect them in an array
691 foreach ( $data as $query ) {
692 foreach ( $query as $i => $row ) {
693 // use index column as key, allowing us to easily sort in PHP
694 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
706 $result = array_slice( $result, 0, $limit );
708 // get rid of array keys
709 $result = array_values( $result );
711 return new FakeResultWrapper( $result );
714 function getQueryInfo() {
715 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
717 $user = $this->getUser();
718 $conds = array_merge( $userCond, $this->getNamespaceCond() );
720 // Paranoia: avoid brute force searches (bug 17342)
721 if ( !$user->isAllowed( 'deletedhistory' ) ) {
722 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
723 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
724 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
725 ' != ' . Revision
::SUPPRESSED_USER
;
728 # Don't include orphaned revisions
729 $join_cond['page'] = Revision
::pageJoinCond();
730 # Get the current user name for accounts
731 $join_cond['user'] = Revision
::userJoinCond();
735 'fields' => array_merge(
736 Revision
::selectFields(),
737 Revision
::selectUserFields(),
738 array( 'page_namespace', 'page_title', 'page_is_new',
739 'page_latest', 'page_is_redirect', 'page_len' )
742 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
743 'join_conds' => $join_cond
746 ChangeTags
::modifyDisplayQuery(
747 $queryInfo['tables'],
748 $queryInfo['fields'],
750 $queryInfo['join_conds'],
751 $queryInfo['options'],
755 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
759 function getUserCond() {
760 $condition = array();
761 $join_conds = array();
762 $tables = array( 'revision', 'page', 'user' );
763 if ( $this->contribs
== 'newbie' ) {
764 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
765 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
766 $index = 'user_timestamp';
767 # ignore local groups with the bot right
768 # @todo FIXME: Global groups may have 'bot' rights
769 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
770 if ( count( $groupsWithBotPermission ) ) {
771 $tables[] = 'user_groups';
772 $condition[] = 'ug_group IS NULL';
773 $join_conds['user_groups'] = array(
775 'ug_user = rev_user',
776 'ug_group' => $groupsWithBotPermission
781 $uid = User
::idFromName( $this->target
);
783 $condition['rev_user'] = $uid;
784 $index = 'user_timestamp';
786 $condition['rev_user_text'] = $this->target
;
787 $index = 'usertext_timestamp';
791 if ( $this->deletedOnly
) {
792 $condition[] = 'rev_deleted != 0';
795 if ( $this->topOnly
) {
796 $condition[] = 'rev_id = page_latest';
799 return array( $tables, $index, $condition, $join_conds );
802 function getNamespaceCond() {
803 if ( $this->namespace !== '' ) {
804 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
805 $eq_op = $this->nsInvert ?
'!=' : '=';
806 $bool_op = $this->nsInvert ?
'AND' : 'OR';
808 if ( !$this->associated
) {
809 return array( "page_namespace $eq_op $selectedNS" );
812 $associatedNS = $this->mDb
->addQuotes(
813 MWNamespace
::getAssociated( $this->namespace )
817 "page_namespace $eq_op $selectedNS " .
819 " page_namespace $eq_op $associatedNS"
826 function getIndexField() {
827 return 'rev_timestamp';
830 function doBatchLookups() {
831 # Do a link batch query
832 $this->mResult
->seek( 0 );
834 $batch = new LinkBatch();
835 # Give some pointers to make (last) links
836 foreach ( $this->mResult
as $row ) {
837 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
838 $revIds[] = $row->rev_parent_id
;
840 if ( isset( $row->rev_id
) ) {
841 if ( $this->contribs
=== 'newbie' ) { // multiple users
842 $batch->add( NS_USER
, $row->user_name
);
843 $batch->add( NS_USER_TALK
, $row->user_name
);
845 $batch->add( $row->page_namespace
, $row->page_title
);
848 $this->mParentLens
= Revision
::getParentLengths( $this->getDatabase(), $revIds );
850 $this->mResult
->seek( 0 );
856 function getStartBody() {
863 function getEndBody() {
868 * Generates each row in the contributions list.
870 * Contributions which are marked "top" are currently on top of the history.
871 * For these contributions, a [rollback] link is shown for users with roll-
872 * back privileges. The rollback link restores the most recent version that
873 * was not written by the target user.
875 * @todo This would probably look a lot nicer in a table.
879 function formatRow( $row ) {
880 wfProfileIn( __METHOD__
);
886 * There may be more than just revision rows. To make sure that we'll only be processing
887 * revisions here, let's _try_ to build a revision out of our row (without displaying
888 * notices though) and then trying to grab data from the built object. If we succeed,
889 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
890 * to extensions to subscribe to the hook to parse the row.
892 wfSuppressWarnings();
893 $rev = new Revision( $row );
894 $validRevision = (bool)$rev->getId();
897 if ( $validRevision ) {
900 $page = Title
::newFromRow( $row );
901 $link = Linker
::link(
903 htmlspecialchars( $page->getPrefixedText() ),
904 array( 'class' => 'mw-contributions-title' ),
905 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
907 # Mark current revisions
909 $user = $this->getUser();
910 if ( $row->rev_id
== $row->page_latest
) {
911 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
913 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
914 && $page->quickUserCan( 'edit', $user )
916 $this->preventClickjacking();
917 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
920 # Is there a visible previous revision?
921 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
922 $difftext = Linker
::linkKnown(
924 $this->messages
['diff'],
928 'oldid' => $row->rev_id
932 $difftext = $this->messages
['diff'];
934 $histlink = Linker
::linkKnown(
936 $this->messages
['hist'],
938 array( 'action' => 'history' )
941 if ( $row->rev_parent_id
=== null ) {
942 // For some reason rev_parent_id isn't populated for this row.
943 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
944 // Next best thing is to have the total number of bytes.
945 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
946 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
947 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
949 $parentLen = isset( $this->mParentLens
[$row->rev_parent_id
] ) ?
$this->mParentLens
[$row->rev_parent_id
] : 0;
950 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
951 $chardiff .= ChangesList
::showCharacterDifference(
956 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
959 $lang = $this->getLanguage();
960 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
961 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
962 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
963 $d = Linker
::linkKnown(
965 htmlspecialchars( $date ),
966 array( 'class' => 'mw-changeslist-date' ),
967 array( 'oldid' => intval( $row->rev_id
) )
970 $d = htmlspecialchars( $date );
972 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
973 $d = '<span class="history-deleted">' . $d . '</span>';
976 # Show user names for /newbies as there may be different users.
977 # Note that we already excluded rows with hidden user names.
978 if ( $this->contribs
== 'newbie' ) {
979 $userlink = ' . . ' . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
980 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
981 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
986 if ( $rev->getParentId() === 0 ) {
987 $nflag = ChangesList
::flag( 'newpage' );
992 if ( $rev->isMinor() ) {
993 $mflag = ChangesList
::flag( 'minor' );
998 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1003 $diffHistLinks = $this->msg( 'parentheses' )
1004 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1006 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
1008 # Denote if username is redacted for this edit
1009 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1010 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
1014 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1018 $classes = array_merge( $classes, $newClasses );
1019 $ret .= " $tagSummary";
1022 // Let extensions add data
1023 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1025 if ( $classes === array() && $ret === '' ) {
1026 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1027 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1029 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1032 wfProfileOut( __METHOD__
);
1037 * Overwrite Pager function and return a helpful comment
1040 function getSqlComment() {
1041 if ( $this->namespace ||
$this->deletedOnly
) {
1042 // potentially slow, see CR r58153
1043 return 'contributions page filtered for namespace or RevisionDeleted edits';
1045 return 'contributions page unfiltered';
1049 protected function preventClickjacking() {
1050 $this->preventClickjacking
= true;
1056 public function getPreventClickjacking() {
1057 return $this->preventClickjacking
;