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 'year' => $this->opts
['year'],
179 'month' => $this->opts
['month'],
180 'deletedOnly' => $this->opts
['deletedOnly'],
181 'topOnly' => $this->opts
['topOnly'],
182 'nsInvert' => $this->opts
['nsInvert'],
183 'associated' => $this->opts
['associated'],
186 if ( !$pager->getNumRows() ) {
187 $out->addWikiMsg( 'nocontribs', $target );
189 # Show a message about slave lag, if applicable
190 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
192 $out->showLagWarning( $lag );
196 '<p>' . $pager->getNavigationBar() . '</p>' .
198 '<p>' . $pager->getNavigationBar() . '</p>'
201 $out->preventClickjacking( $pager->getPreventClickjacking() );
203 # Show the appropriate "footer" message - WHOIS tools, etc.
204 if ( $this->opts
['contribs'] == 'newbie' ) {
205 $message = 'sp-contributions-footer-newbies';
206 } elseif ( IP
::isIPAddress( $target ) ) {
207 $message = 'sp-contributions-footer-anon';
208 } elseif ( $userObj->isAnon() ) {
209 // No message for non-existing users
212 $message = 'sp-contributions-footer';
216 if ( !$this->msg( $message, $target )->isDisabled() ) {
218 "<div class='mw-contributions-footer'>\n$1\n</div>",
219 array( $message, $target ) );
226 * Generates the subheading with links
227 * @param $userObj User object for the target
228 * @return String: appropriately-escaped HTML to be output literally
229 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
231 protected function contributionsSub( $userObj ) {
232 if ( $userObj->isAnon() ) {
233 $user = htmlspecialchars( $userObj->getName() );
235 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
237 $nt = $userObj->getUserPage();
238 $talk = $userObj->getTalkPage();
241 $tools = $this->getUserLinks( $nt, $talk, $userObj );
242 $links = $this->getLanguage()->pipeList( $tools );
244 // Show a note if the user is blocked and display the last block log entry.
245 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
246 // and also this will display a totally irrelevant log entry as a current block.
247 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
248 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
249 LogEventsList
::showLogExtract(
256 'showIfEmpty' => false,
259 'sp-contributions-blocked-notice-anon' :
260 'sp-contributions-blocked-notice',
261 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
263 'offset' => '' # don't use WebRequest parameter offset
269 // Old message 'contribsub' had one parameter, but that doesn't work for
270 // languages that want to put the "for" bit right after $user but before
271 // $links. If 'contribsub' is around, use it for reverse compatibility,
272 // otherwise use 'contribsub2'.
273 // @todo Should this be removed at some point?
274 $oldMsg = $this->msg( 'contribsub' );
275 if ( $oldMsg->exists() ) {
276 $linksWithParentheses = $this->msg( 'parentheses' )->rawParams( $links )->escaped();
278 return $oldMsg->rawParams( "$user $linksWithParentheses" );
281 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
285 * Links to different places.
286 * @param $userpage Title: Target user page
287 * @param $talkpage Title: Talk page
288 * @param $target User: Target user object
291 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
293 $id = $target->getId();
294 $username = $target->getName();
296 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
298 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
299 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
300 if ( $target->isBlocked() ) {
301 $tools[] = Linker
::linkKnown( # Change block link
302 SpecialPage
::getTitleFor( 'Block', $username ),
303 $this->msg( 'change-blocklink' )->escaped()
305 $tools[] = Linker
::linkKnown( # Unblock link
306 SpecialPage
::getTitleFor( 'Unblock', $username ),
307 $this->msg( 'unblocklink' )->escaped()
309 } else { # User is not blocked
310 $tools[] = Linker
::linkKnown( # Block link
311 SpecialPage
::getTitleFor( 'Block', $username ),
312 $this->msg( 'blocklink' )->escaped()
318 $tools[] = Linker
::linkKnown(
319 SpecialPage
::getTitleFor( 'Log', 'block' ),
320 $this->msg( 'sp-contributions-blocklog' )->escaped(),
322 array( 'page' => $userpage->getPrefixedText() )
326 $tools[] = Linker
::linkKnown(
327 SpecialPage
::getTitleFor( 'Listfiles', $username ),
328 $this->msg( 'sp-contributions-uploads' )->escaped()
332 $tools[] = Linker
::linkKnown(
333 SpecialPage
::getTitleFor( 'Log', $username ),
334 $this->msg( 'sp-contributions-logs' )->escaped()
337 # Add link to deleted user contributions for priviledged users
338 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
339 $tools[] = Linker
::linkKnown(
340 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
341 $this->msg( 'sp-contributions-deleted' )->escaped()
345 # Add a link to change user rights for privileged users
346 $userrightsPage = new UserrightsPage();
347 $userrightsPage->setContext( $this->getContext() );
348 if ( $userrightsPage->userCanChangeRights( $target ) ) {
349 $tools[] = Linker
::linkKnown(
350 SpecialPage
::getTitleFor( 'Userrights', $username ),
351 $this->msg( 'sp-contributions-userrights' )->escaped()
355 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
361 * Generates the namespace selector form with hidden attributes.
362 * @return String: HTML fragment
364 protected function getForm() {
367 $this->opts
['title'] = $this->getTitle()->getPrefixedText();
368 if ( !isset( $this->opts
['target'] ) ) {
369 $this->opts
['target'] = '';
371 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
374 if ( !isset( $this->opts
['namespace'] ) ) {
375 $this->opts
['namespace'] = '';
378 if ( !isset( $this->opts
['nsInvert'] ) ) {
379 $this->opts
['nsInvert'] = '';
382 if ( !isset( $this->opts
['associated'] ) ) {
383 $this->opts
['associated'] = false;
386 if ( !isset( $this->opts
['contribs'] ) ) {
387 $this->opts
['contribs'] = 'user';
390 if ( !isset( $this->opts
['year'] ) ) {
391 $this->opts
['year'] = '';
394 if ( !isset( $this->opts
['month'] ) ) {
395 $this->opts
['month'] = '';
398 if ( $this->opts
['contribs'] == 'newbie' ) {
399 $this->opts
['target'] = '';
402 if ( !isset( $this->opts
['tagfilter'] ) ) {
403 $this->opts
['tagfilter'] = '';
406 if ( !isset( $this->opts
['topOnly'] ) ) {
407 $this->opts
['topOnly'] = false;
410 $form = Html
::openElement(
414 'action' => $wgScript,
415 'class' => 'mw-contributions-form'
419 # Add hidden params for tracking except for parameters in $skipParameters
420 $skipParameters = array(
432 foreach ( $this->opts
as $name => $value ) {
433 if ( in_array( $name, $skipParameters ) ) {
436 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
439 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
442 $filterSelection = Html
::rawElement(
444 array( 'class' => 'mw-label' ),
445 array_shift( $tagFilter )
447 $filterSelection .= Html
::rawElement(
449 array( 'class' => 'mw-input' ),
450 implode( ' ', $tagFilter )
453 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
456 $labelNewbies = Xml
::radioLabel(
457 $this->msg( 'sp-contributions-newbies' )->text(),
461 $this->opts
['contribs'] == 'newbie',
462 array( 'class' => 'mw-input' )
464 $labelUsername = Xml
::radioLabel(
465 $this->msg( 'sp-contributions-username' )->text(),
469 $this->opts
['contribs'] == 'user',
470 array( 'class' => 'mw-input' )
472 $input = Html
::input(
474 $this->opts
['target'],
476 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
477 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
480 $targetSelection = Html
::rawElement(
482 array( 'colspan' => 2 ),
483 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
486 $namespaceSelection = Xml
::tags(
488 array( 'class' => 'mw-label' ),
490 $this->msg( 'namespace' )->text(),
495 $namespaceSelection .= Html
::rawElement(
498 Html
::namespaceSelector(
499 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
501 'name' => 'namespace',
503 'class' => 'namespaceselector',
508 array( 'style' => 'white-space: nowrap' ),
510 $this->msg( 'invert' )->text(),
513 $this->opts
['nsInvert'],
515 'title' => $this->msg( 'tooltip-invert' )->text(),
516 'class' => 'mw-input'
520 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
522 $this->msg( 'namespace_association' )->text(),
525 $this->opts
['associated'],
527 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
528 'class' => 'mw-input'
534 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
535 $deletedOnlyCheck = Html
::rawElement(
537 array( 'style' => 'white-space: nowrap' ),
539 $this->msg( 'history-show-deleted' )->text(),
541 'mw-show-deleted-only',
542 $this->opts
['deletedOnly'],
543 array( 'class' => 'mw-input' )
547 $deletedOnlyCheck = '';
550 $checkLabelTopOnly = Html
::rawElement(
552 array( 'style' => 'white-space: nowrap' ),
554 $this->msg( 'sp-contributions-toponly' )->text(),
557 $this->opts
['topOnly'],
558 array( 'class' => 'mw-input' )
561 $extraOptions = Html
::rawElement(
563 array( 'colspan' => 2 ),
564 $deletedOnlyCheck . $checkLabelTopOnly
567 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
569 $this->opts
['year'] === '' ?
gmdate( 'Y' ) : $this->opts
['year'],
573 $this->msg( 'sp-contributions-submit' )->text(),
574 array( 'class' => 'mw-submit' )
578 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
579 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
580 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
581 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
582 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
583 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
584 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
587 $explain = $this->msg( 'sp-contributions-explain' );
588 if ( !$explain->isBlank() ) {
589 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
592 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
597 protected function getGroupName() {
603 * Pager for Special:Contributions
604 * @ingroup SpecialPage Pager
606 class ContribsPager
extends ReverseChronologicalPager
{
607 public $mDefaultDirection = true;
608 var $messages, $target;
609 var $namespace = '', $mDb;
610 var $preventClickjacking = false;
615 protected $mParentLens;
617 function __construct( IContextSource
$context, array $options ) {
618 parent
::__construct( $context );
630 foreach ( $msgs as $msg ) {
631 $this->messages
[$msg] = $this->msg( $msg )->escaped();
634 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
635 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
636 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
637 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
638 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
639 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
641 $this->deletedOnly
= !empty( $options['deletedOnly'] );
642 $this->topOnly
= !empty( $options['topOnly'] );
644 $year = isset( $options['year'] ) ?
$options['year'] : false;
645 $month = isset( $options['month'] ) ?
$options['month'] : false;
646 $this->getDateCond( $year, $month );
648 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
651 function getDefaultQuery() {
652 $query = parent
::getDefaultQuery();
653 $query['target'] = $this->target
;
659 * This method basically executes the exact same code as the parent class, though with
660 * a hook added, to allow extentions to add additional queries.
662 * @param string $offset index offset, inclusive
663 * @param $limit Integer: exact query limit
664 * @param $descending Boolean: query direction, false for ascending, true for descending
665 * @return ResultWrapper
667 function reallyDoQuery( $offset, $limit, $descending ) {
668 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
676 * This hook will allow extensions to add in additional queries, so they can get their data
677 * in My Contributions as well. Extensions should append their results to the $data array.
679 * Extension queries have to implement the navbar requirement as well. They should
680 * - have a column aliased as $pager->getIndexField()
682 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
683 * - have the ORDER BY specified based upon the details provided by the navbar
685 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
687 * &$data: an array of results of all contribs queries
688 * $pager: the ContribsPager object hooked into
689 * $offset: see phpdoc above
690 * $limit: see phpdoc above
691 * $descending: see phpdoc above
693 $data = array( $this->mDb
->select( $tables, $fields, $conds, $fname, $options, $join_conds ) );
694 wfRunHooks( 'ContribsPager::reallyDoQuery', array( &$data, $pager, $offset, $limit, $descending ) );
698 // loop all results and collect them in an array
699 foreach ( $data as $query ) {
700 foreach ( $query as $i => $row ) {
701 // use index column as key, allowing us to easily sort in PHP
702 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
714 $result = array_slice( $result, 0, $limit );
716 // get rid of array keys
717 $result = array_values( $result );
719 return new FakeResultWrapper( $result );
722 function getQueryInfo() {
723 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
725 $user = $this->getUser();
726 $conds = array_merge( $userCond, $this->getNamespaceCond() );
728 // Paranoia: avoid brute force searches (bug 17342)
729 if ( !$user->isAllowed( 'deletedhistory' ) ) {
730 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
731 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
732 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
733 ' != ' . Revision
::SUPPRESSED_USER
;
736 # Don't include orphaned revisions
737 $join_cond['page'] = Revision
::pageJoinCond();
738 # Get the current user name for accounts
739 $join_cond['user'] = Revision
::userJoinCond();
743 'fields' => array_merge(
744 Revision
::selectFields(),
745 Revision
::selectUserFields(),
746 array( 'page_namespace', 'page_title', 'page_is_new',
747 'page_latest', 'page_is_redirect', 'page_len' )
750 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
751 'join_conds' => $join_cond
754 ChangeTags
::modifyDisplayQuery(
755 $queryInfo['tables'],
756 $queryInfo['fields'],
758 $queryInfo['join_conds'],
759 $queryInfo['options'],
763 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
768 function getUserCond() {
769 $condition = array();
770 $join_conds = array();
771 $tables = array( 'revision', 'page', 'user' );
772 if ( $this->contribs
== 'newbie' ) {
773 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
774 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
775 $index = 'user_timestamp';
776 # ignore local groups with the bot right
777 # @todo FIXME: Global groups may have 'bot' rights
778 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
779 if ( count( $groupsWithBotPermission ) ) {
780 $tables[] = 'user_groups';
781 $condition[] = 'ug_group IS NULL';
782 $join_conds['user_groups'] = array(
784 'ug_user = rev_user',
785 'ug_group' => $groupsWithBotPermission
790 $uid = User
::idFromName( $this->target
);
792 $condition['rev_user'] = $uid;
793 $index = 'user_timestamp';
795 $condition['rev_user_text'] = $this->target
;
796 $index = 'usertext_timestamp';
800 if ( $this->deletedOnly
) {
801 $condition[] = 'rev_deleted != 0';
804 if ( $this->topOnly
) {
805 $condition[] = 'rev_id = page_latest';
808 return array( $tables, $index, $condition, $join_conds );
811 function getNamespaceCond() {
812 if ( $this->namespace !== '' ) {
813 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
814 $eq_op = $this->nsInvert ?
'!=' : '=';
815 $bool_op = $this->nsInvert ?
'AND' : 'OR';
817 if ( !$this->associated
) {
818 return array( "page_namespace $eq_op $selectedNS" );
821 $associatedNS = $this->mDb
->addQuotes(
822 MWNamespace
::getAssociated( $this->namespace )
826 "page_namespace $eq_op $selectedNS " .
828 " page_namespace $eq_op $associatedNS"
835 function getIndexField() {
836 return 'rev_timestamp';
839 function doBatchLookups() {
840 # Do a link batch query
841 $this->mResult
->seek( 0 );
843 $batch = new LinkBatch();
844 # Give some pointers to make (last) links
845 foreach ( $this->mResult
as $row ) {
846 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
847 $revIds[] = $row->rev_parent_id
;
849 if ( isset( $row->rev_id
) ) {
850 if ( $this->contribs
=== 'newbie' ) { // multiple users
851 $batch->add( NS_USER
, $row->user_name
);
852 $batch->add( NS_USER_TALK
, $row->user_name
);
854 $batch->add( $row->page_namespace
, $row->page_title
);
857 $this->mParentLens
= Revision
::getParentLengths( $this->getDatabase(), $revIds );
859 $this->mResult
->seek( 0 );
865 function getStartBody() {
872 function getEndBody() {
877 * Generates each row in the contributions list.
879 * Contributions which are marked "top" are currently on top of the history.
880 * For these contributions, a [rollback] link is shown for users with roll-
881 * back privileges. The rollback link restores the most recent version that
882 * was not written by the target user.
884 * @todo This would probably look a lot nicer in a table.
888 function formatRow( $row ) {
889 wfProfileIn( __METHOD__
);
895 * There may be more than just revision rows. To make sure that we'll only be processing
896 * revisions here, let's _try_ to build a revision out of our row (without displaying
897 * notices though) and then trying to grab data from the built object. If we succeed,
898 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
899 * to extensions to subscribe to the hook to parse the row.
901 wfSuppressWarnings();
902 $rev = new Revision( $row );
903 $validRevision = (bool)$rev->getId();
906 if ( $validRevision ) {
909 $page = Title
::newFromRow( $row );
910 $link = Linker
::link(
912 htmlspecialchars( $page->getPrefixedText() ),
913 array( 'class' => 'mw-contributions-title' ),
914 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
916 # Mark current revisions
918 $user = $this->getUser();
919 if ( $row->rev_id
== $row->page_latest
) {
920 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
922 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
923 && $page->quickUserCan( 'edit', $user )
925 $this->preventClickjacking();
926 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
929 # Is there a visible previous revision?
930 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
931 $difftext = Linker
::linkKnown(
933 $this->messages
['diff'],
937 'oldid' => $row->rev_id
941 $difftext = $this->messages
['diff'];
943 $histlink = Linker
::linkKnown(
945 $this->messages
['hist'],
947 array( 'action' => 'history' )
950 if ( $row->rev_parent_id
=== null ) {
951 // For some reason rev_parent_id isn't populated for this row.
952 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
953 // Next best thing is to have the total number of bytes.
954 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
955 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
956 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
958 $parentLen = isset( $this->mParentLens
[$row->rev_parent_id
] ) ?
$this->mParentLens
[$row->rev_parent_id
] : 0;
959 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
960 $chardiff .= ChangesList
::showCharacterDifference(
965 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
968 $lang = $this->getLanguage();
969 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
970 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
971 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
972 $d = Linker
::linkKnown(
974 htmlspecialchars( $date ),
975 array( 'class' => 'mw-changeslist-date' ),
976 array( 'oldid' => intval( $row->rev_id
) )
979 $d = htmlspecialchars( $date );
981 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
982 $d = '<span class="history-deleted">' . $d . '</span>';
985 # Show user names for /newbies as there may be different users.
986 # Note that we already excluded rows with hidden user names.
987 if ( $this->contribs
== 'newbie' ) {
988 $userlink = ' . . ' . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
989 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
990 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
995 if ( $rev->getParentId() === 0 ) {
996 $nflag = ChangesList
::flag( 'newpage' );
1001 if ( $rev->isMinor() ) {
1002 $mflag = ChangesList
::flag( 'minor' );
1007 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1008 if ( $del !== '' ) {
1012 $diffHistLinks = $this->msg( 'parentheses' )
1013 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1015 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
1017 # Denote if username is redacted for this edit
1018 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1019 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
1023 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1027 $classes = array_merge( $classes, $newClasses );
1028 $ret .= " $tagSummary";
1031 // Let extensions add data
1032 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1034 if ( $classes === array() && $ret === '' ) {
1035 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1036 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1038 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1041 wfProfileOut( __METHOD__
);
1047 * Overwrite Pager function and return a helpful comment
1050 function getSqlComment() {
1051 if ( $this->namespace ||
$this->deletedOnly
) {
1052 // potentially slow, see CR r58153
1053 return 'contributions page filtered for namespace or RevisionDeleted edits';
1055 return 'contributions page unfiltered';
1059 protected function preventClickjacking() {
1060 $this->preventClickjacking
= true;
1066 public function getPreventClickjacking() {
1067 return $this->preventClickjacking
;