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 IncludableSpecialPage
{
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 if ( !$this->including() ) {
67 $out->addHTML( $this->getForm() );
72 $user = $this->getUser();
74 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
75 $this->opts
['target'] = $target;
76 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
78 $nt = Title
::makeTitleSafe( NS_USER
, $target );
80 $out->addHTML( $this->getForm() );
84 $userObj = User
::newFromName( $nt->getText(), false );
86 $out->addHTML( $this->getForm() );
90 $id = $userObj->getID();
92 if ( $this->opts
['contribs'] != 'newbie' ) {
93 $target = $nt->getText();
94 $out->addSubtitle( $this->contributionsSub( $userObj ) );
95 $out->setHTMLTitle( $this->msg(
97 $this->msg( 'contributions-title', $target )->plain()
98 )->inContentLanguage() );
99 $this->getSkin()->setRelevantUser( $userObj );
101 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
102 $out->setHTMLTitle( $this->msg(
104 $this->msg( 'sp-contributions-newbies-title' )->plain()
105 )->inContentLanguage() );
108 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
109 $this->opts
['namespace'] = intval( $ns );
111 $this->opts
['namespace'] = '';
114 $this->opts
['associated'] = $request->getBool( 'associated' );
115 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
116 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
118 // Allows reverts to have the bot flag in recent changes. It is just here to
119 // be passed in the form at the top of the page
120 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
121 $this->opts
['bot'] = '1';
124 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
125 # Offset overrides year/month selection
127 $this->opts
['year'] = '';
128 $this->opts
['month'] = '';
130 $this->opts
['year'] = $request->getIntOrNull( 'year' );
131 $this->opts
['month'] = $request->getIntOrNull( 'month' );
134 $feedType = $request->getVal( 'feed' );
137 'action' => 'feedcontributions',
140 if ( $this->opts
['topOnly'] ) {
141 $feedParams['toponly'] = true;
143 if ( $this->opts
['deletedOnly'] ) {
144 $feedParams['deletedonly'] = true;
146 if ( $this->opts
['tagfilter'] !== '' ) {
147 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
149 if ( $this->opts
['namespace'] !== '' ) {
150 $feedParams['namespace'] = $this->opts
['namespace'];
152 // Don't use year and month for the feed URL, but pass them on if
153 // we redirect to API (if $feedType is specified)
154 if ( $feedType && $this->opts
['year'] !== null ) {
155 $feedParams['year'] = $this->opts
['year'];
157 if ( $feedType && $this->opts
['month'] !== null ) {
158 $feedParams['month'] = $this->opts
['month'];
162 // Maintain some level of backwards compatability
163 // If people request feeds using the old parameters, redirect to API
164 $feedParams['feedformat'] = $feedType;
165 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
167 $out->redirect( $url, '301' );
172 // Add RSS/atom links
173 $this->addFeedLinks( $feedParams );
175 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) {
176 if ( !$this->including() ) {
177 $out->addHTML( $this->getForm() );
179 $pager = new ContribsPager( $this->getContext(), array(
181 'contribs' => $this->opts
['contribs'],
182 'namespace' => $this->opts
['namespace'],
183 'tagfilter' => $this->opts
['tagfilter'],
184 'year' => $this->opts
['year'],
185 'month' => $this->opts
['month'],
186 'deletedOnly' => $this->opts
['deletedOnly'],
187 'topOnly' => $this->opts
['topOnly'],
188 'nsInvert' => $this->opts
['nsInvert'],
189 'associated' => $this->opts
['associated'],
192 if ( !$pager->getNumRows() ) {
193 $out->addWikiMsg( 'nocontribs', $target );
195 # Show a message about slave lag, if applicable
196 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
198 $out->showLagWarning( $lag );
202 '<p>' . $pager->getNavigationBar() . '</p>' .
204 '<p>' . $pager->getNavigationBar() . '</p>'
207 $out->preventClickjacking( $pager->getPreventClickjacking() );
209 # Show the appropriate "footer" message - WHOIS tools, etc.
210 if ( $this->opts
['contribs'] == 'newbie' ) {
211 $message = 'sp-contributions-footer-newbies';
212 } elseif ( IP
::isIPAddress( $target ) ) {
213 $message = 'sp-contributions-footer-anon';
214 } elseif ( $userObj->isAnon() ) {
215 // No message for non-existing users
218 $message = 'sp-contributions-footer';
222 if ( !$this->including() ) {
223 if ( !$this->msg( $message, $target )->isDisabled() ) {
225 "<div class='mw-contributions-footer'>\n$1\n</div>",
226 array( $message, $target ) );
234 * Generates the subheading with links
235 * @param $userObj User object for the target
236 * @return String: appropriately-escaped HTML to be output literally
237 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
240 protected function contributionsSub( $userObj ) {
241 if ( $userObj->isAnon() ) {
242 $user = htmlspecialchars( $userObj->getName() );
244 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
246 $nt = $userObj->getUserPage();
247 $talk = $userObj->getTalkPage();
250 $tools = $this->getUserLinks( $nt, $talk, $userObj );
251 $links = $this->getLanguage()->pipeList( $tools );
253 // Show a note if the user is blocked and display the last block log entry.
254 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
255 // and also this will display a totally irrelevant log entry as a current block.
256 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
257 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
258 LogEventsList
::showLogExtract(
265 'showIfEmpty' => false,
268 'sp-contributions-blocked-notice-anon' :
269 'sp-contributions-blocked-notice',
270 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
272 'offset' => '' # don't use WebRequest parameter offset
278 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
282 * Links to different places.
283 * @param $userpage Title: Target user page
284 * @param $talkpage Title: Talk page
285 * @param $target User: Target user object
288 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
290 $id = $target->getId();
291 $username = $target->getName();
293 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
295 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
296 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
297 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
298 $tools[] = Linker
::linkKnown( # Change block link
299 SpecialPage
::getTitleFor( 'Block', $username ),
300 $this->msg( 'change-blocklink' )->escaped()
302 $tools[] = Linker
::linkKnown( # Unblock link
303 SpecialPage
::getTitleFor( 'Unblock', $username ),
304 $this->msg( 'unblocklink' )->escaped()
306 } else { # User is not blocked
307 $tools[] = Linker
::linkKnown( # Block link
308 SpecialPage
::getTitleFor( 'Block', $username ),
309 $this->msg( 'blocklink' )->escaped()
315 $tools[] = Linker
::linkKnown(
316 SpecialPage
::getTitleFor( 'Log', 'block' ),
317 $this->msg( 'sp-contributions-blocklog' )->escaped(),
319 array( 'page' => $userpage->getPrefixedText() )
323 $tools[] = Linker
::linkKnown(
324 SpecialPage
::getTitleFor( 'Listfiles', $username ),
325 $this->msg( 'sp-contributions-uploads' )->escaped()
329 $tools[] = Linker
::linkKnown(
330 SpecialPage
::getTitleFor( 'Log', $username ),
331 $this->msg( 'sp-contributions-logs' )->escaped()
334 # Add link to deleted user contributions for priviledged users
335 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
336 $tools[] = Linker
::linkKnown(
337 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
338 $this->msg( 'sp-contributions-deleted' )->escaped()
342 # Add a link to change user rights for privileged users
343 $userrightsPage = new UserrightsPage();
344 $userrightsPage->setContext( $this->getContext() );
345 if ( $userrightsPage->userCanChangeRights( $target ) ) {
346 $tools[] = Linker
::linkKnown(
347 SpecialPage
::getTitleFor( 'Userrights', $username ),
348 $this->msg( 'sp-contributions-userrights' )->escaped()
352 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
358 * Generates the namespace selector form with hidden attributes.
359 * @return String: HTML fragment
361 protected function getForm() {
364 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
365 if ( !isset( $this->opts
['target'] ) ) {
366 $this->opts
['target'] = '';
368 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
371 if ( !isset( $this->opts
['namespace'] ) ) {
372 $this->opts
['namespace'] = '';
375 if ( !isset( $this->opts
['nsInvert'] ) ) {
376 $this->opts
['nsInvert'] = '';
379 if ( !isset( $this->opts
['associated'] ) ) {
380 $this->opts
['associated'] = false;
383 if ( !isset( $this->opts
['contribs'] ) ) {
384 $this->opts
['contribs'] = 'user';
387 if ( !isset( $this->opts
['year'] ) ) {
388 $this->opts
['year'] = '';
391 if ( !isset( $this->opts
['month'] ) ) {
392 $this->opts
['month'] = '';
395 if ( $this->opts
['contribs'] == 'newbie' ) {
396 $this->opts
['target'] = '';
399 if ( !isset( $this->opts
['tagfilter'] ) ) {
400 $this->opts
['tagfilter'] = '';
403 if ( !isset( $this->opts
['topOnly'] ) ) {
404 $this->opts
['topOnly'] = false;
407 $form = Html
::openElement(
411 'action' => $wgScript,
412 'class' => 'mw-contributions-form'
416 # Add hidden params for tracking except for parameters in $skipParameters
417 $skipParameters = array(
429 foreach ( $this->opts
as $name => $value ) {
430 if ( in_array( $name, $skipParameters ) ) {
433 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
436 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
439 $filterSelection = Html
::rawElement(
441 array( 'class' => 'mw-label' ),
442 array_shift( $tagFilter )
444 $filterSelection .= Html
::rawElement(
446 array( 'class' => 'mw-input' ),
447 implode( ' ', $tagFilter )
450 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
453 $labelNewbies = Xml
::radioLabel(
454 $this->msg( 'sp-contributions-newbies' )->text(),
458 $this->opts
['contribs'] == 'newbie',
459 array( 'class' => 'mw-input' )
461 $labelUsername = Xml
::radioLabel(
462 $this->msg( 'sp-contributions-username' )->text(),
466 $this->opts
['contribs'] == 'user',
467 array( 'class' => 'mw-input' )
469 $input = Html
::input(
471 $this->opts
['target'],
473 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
474 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
477 $targetSelection = Html
::rawElement(
479 array( 'colspan' => 2 ),
480 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
483 $namespaceSelection = Xml
::tags(
485 array( 'class' => 'mw-label' ),
487 $this->msg( 'namespace' )->text(),
492 $namespaceSelection .= Html
::rawElement(
495 Html
::namespaceSelector(
496 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
498 'name' => 'namespace',
500 'class' => 'namespaceselector',
505 array( 'style' => 'white-space: nowrap' ),
507 $this->msg( 'invert' )->text(),
510 $this->opts
['nsInvert'],
512 'title' => $this->msg( 'tooltip-invert' )->text(),
513 'class' => 'mw-input'
517 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
519 $this->msg( 'namespace_association' )->text(),
522 $this->opts
['associated'],
524 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
525 'class' => 'mw-input'
531 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
532 $deletedOnlyCheck = Html
::rawElement(
534 array( 'style' => 'white-space: nowrap' ),
536 $this->msg( 'history-show-deleted' )->text(),
538 'mw-show-deleted-only',
539 $this->opts
['deletedOnly'],
540 array( 'class' => 'mw-input' )
544 $deletedOnlyCheck = '';
547 $checkLabelTopOnly = Html
::rawElement(
549 array( 'style' => 'white-space: nowrap' ),
551 $this->msg( 'sp-contributions-toponly' )->text(),
554 $this->opts
['topOnly'],
555 array( 'class' => 'mw-input' )
558 $extraOptions = Html
::rawElement(
560 array( 'colspan' => 2 ),
561 $deletedOnlyCheck . $checkLabelTopOnly
564 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
566 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
570 $this->msg( 'sp-contributions-submit' )->text(),
571 array( 'class' => 'mw-submit' )
575 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
576 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
577 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
578 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
579 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
580 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
581 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
584 $explain = $this->msg( 'sp-contributions-explain' );
585 if ( !$explain->isBlank() ) {
586 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
589 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
594 protected function getGroupName() {
600 * Pager for Special:Contributions
601 * @ingroup SpecialPage Pager
603 class ContribsPager
extends ReverseChronologicalPager
{
604 public $mDefaultDirection = true;
607 public $namespace = '';
609 public $preventClickjacking = false;
611 /** @var DatabaseBase */
612 public $mDbSecondary;
617 protected $mParentLens;
619 function __construct( IContextSource
$context, array $options ) {
620 parent
::__construct( $context );
632 foreach ( $msgs as $msg ) {
633 $this->messages
[$msg] = $this->msg( $msg )->escaped();
636 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
637 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
638 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
639 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
640 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
641 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
643 $this->deletedOnly
= !empty( $options['deletedOnly'] );
644 $this->topOnly
= !empty( $options['topOnly'] );
646 $year = isset( $options['year'] ) ?
$options['year'] : false;
647 $month = isset( $options['month'] ) ?
$options['month'] : false;
648 $this->getDateCond( $year, $month );
650 // Most of this code will use the 'contributions' group DB, which can map to slaves
651 // with extra user based indexes or partioning by user. The additional metadata
652 // queries should use a regular slave since the lookup pattern is not all by user.
653 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
654 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
657 function getDefaultQuery() {
658 $query = parent
::getDefaultQuery();
659 $query['target'] = $this->target
;
665 * This method basically executes the exact same code as the parent class, though with
666 * a hook added, to allow extentions to add additional queries.
668 * @param string $offset index offset, inclusive
669 * @param $limit Integer: exact query limit
670 * @param $descending Boolean: query direction, false for ascending, true for descending
671 * @return ResultWrapper
673 function reallyDoQuery( $offset, $limit, $descending ) {
674 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
682 * This hook will allow extensions to add in additional queries, so they can get their data
683 * in My Contributions as well. Extensions should append their results to the $data array.
685 * Extension queries have to implement the navbar requirement as well. They should
686 * - have a column aliased as $pager->getIndexField()
688 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
689 * - have the ORDER BY specified based upon the details provided by the navbar
691 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
693 * &$data: an array of results of all contribs queries
694 * $pager: the ContribsPager object hooked into
695 * $offset: see phpdoc above
696 * $limit: see phpdoc above
697 * $descending: see phpdoc above
699 $data = array( $this->mDb
->select(
700 $tables, $fields, $conds, $fname, $options, $join_conds
703 'ContribsPager::reallyDoQuery',
704 array( &$data, $pager, $offset, $limit, $descending )
709 // loop all results and collect them in an array
710 foreach ( $data as $query ) {
711 foreach ( $query as $i => $row ) {
712 // use index column as key, allowing us to easily sort in PHP
713 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
725 $result = array_slice( $result, 0, $limit );
727 // get rid of array keys
728 $result = array_values( $result );
730 return new FakeResultWrapper( $result );
733 function getQueryInfo() {
734 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
736 $user = $this->getUser();
737 $conds = array_merge( $userCond, $this->getNamespaceCond() );
739 // Paranoia: avoid brute force searches (bug 17342)
740 if ( !$user->isAllowed( 'deletedhistory' ) ) {
741 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
742 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
743 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
744 ' != ' . Revision
::SUPPRESSED_USER
;
747 # Don't include orphaned revisions
748 $join_cond['page'] = Revision
::pageJoinCond();
749 # Get the current user name for accounts
750 $join_cond['user'] = Revision
::userJoinCond();
754 $options['USE INDEX'] = array( 'revision' => $index );
759 'fields' => array_merge(
760 Revision
::selectFields(),
761 Revision
::selectUserFields(),
762 array( 'page_namespace', 'page_title', 'page_is_new',
763 'page_latest', 'page_is_redirect', 'page_len' )
766 'options' => $options,
767 'join_conds' => $join_cond
770 ChangeTags
::modifyDisplayQuery(
771 $queryInfo['tables'],
772 $queryInfo['fields'],
774 $queryInfo['join_conds'],
775 $queryInfo['options'],
779 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
784 function getUserCond() {
785 $condition = array();
786 $join_conds = array();
787 $tables = array( 'revision', 'page', 'user' );
789 if ( $this->contribs
== 'newbie' ) {
790 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
791 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
792 # ignore local groups with the bot right
793 # @todo FIXME: Global groups may have 'bot' rights
794 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
795 if ( count( $groupsWithBotPermission ) ) {
796 $tables[] = 'user_groups';
797 $condition[] = 'ug_group IS NULL';
798 $join_conds['user_groups'] = array(
800 'ug_user = rev_user',
801 'ug_group' => $groupsWithBotPermission
806 $uid = User
::idFromName( $this->target
);
808 $condition['rev_user'] = $uid;
809 $index = 'user_timestamp';
811 $condition['rev_user_text'] = $this->target
;
812 $index = 'usertext_timestamp';
816 if ( $this->deletedOnly
) {
817 $condition[] = 'rev_deleted != 0';
820 if ( $this->topOnly
) {
821 $condition[] = 'rev_id = page_latest';
824 return array( $tables, $index, $condition, $join_conds );
827 function getNamespaceCond() {
828 if ( $this->namespace !== '' ) {
829 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
830 $eq_op = $this->nsInvert ?
'!=' : '=';
831 $bool_op = $this->nsInvert ?
'AND' : 'OR';
833 if ( !$this->associated
) {
834 return array( "page_namespace $eq_op $selectedNS" );
837 $associatedNS = $this->mDb
->addQuotes(
838 MWNamespace
::getAssociated( $this->namespace )
842 "page_namespace $eq_op $selectedNS " .
844 " page_namespace $eq_op $associatedNS"
851 function getIndexField() {
852 return 'rev_timestamp';
855 function doBatchLookups() {
856 # Do a link batch query
857 $this->mResult
->seek( 0 );
859 $batch = new LinkBatch();
860 # Give some pointers to make (last) links
861 foreach ( $this->mResult
as $row ) {
862 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
863 $revIds[] = $row->rev_parent_id
;
865 if ( isset( $row->rev_id
) ) {
866 if ( $this->contribs
=== 'newbie' ) { // multiple users
867 $batch->add( NS_USER
, $row->user_name
);
868 $batch->add( NS_USER_TALK
, $row->user_name
);
870 $batch->add( $row->page_namespace
, $row->page_title
);
873 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
875 $this->mResult
->seek( 0 );
881 function getStartBody() {
888 function getEndBody() {
893 * Generates each row in the contributions list.
895 * Contributions which are marked "top" are currently on top of the history.
896 * For these contributions, a [rollback] link is shown for users with roll-
897 * back privileges. The rollback link restores the most recent version that
898 * was not written by the target user.
900 * @todo This would probably look a lot nicer in a table.
904 function formatRow( $row ) {
905 wfProfileIn( __METHOD__
);
911 * There may be more than just revision rows. To make sure that we'll only be processing
912 * revisions here, let's _try_ to build a revision out of our row (without displaying
913 * notices though) and then trying to grab data from the built object. If we succeed,
914 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
915 * to extensions to subscribe to the hook to parse the row.
917 wfSuppressWarnings();
918 $rev = new Revision( $row );
919 $validRevision = (bool)$rev->getId();
922 if ( $validRevision ) {
925 $page = Title
::newFromRow( $row );
926 $link = Linker
::link(
928 htmlspecialchars( $page->getPrefixedText() ),
929 array( 'class' => 'mw-contributions-title' ),
930 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
932 # Mark current revisions
934 $user = $this->getUser();
935 if ( $row->rev_id
== $row->page_latest
) {
936 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
938 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
939 && $page->quickUserCan( 'edit', $user )
941 $this->preventClickjacking();
942 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
945 # Is there a visible previous revision?
946 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
947 $difftext = Linker
::linkKnown(
949 $this->messages
['diff'],
953 'oldid' => $row->rev_id
957 $difftext = $this->messages
['diff'];
959 $histlink = Linker
::linkKnown(
961 $this->messages
['hist'],
963 array( 'action' => 'history' )
966 if ( $row->rev_parent_id
=== null ) {
967 // For some reason rev_parent_id isn't populated for this row.
968 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
969 // Next best thing is to have the total number of bytes.
970 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
971 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
972 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
975 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
976 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
979 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
980 $chardiff .= ChangesList
::showCharacterDifference(
985 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
988 $lang = $this->getLanguage();
989 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
990 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
991 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
992 $d = Linker
::linkKnown(
994 htmlspecialchars( $date ),
995 array( 'class' => 'mw-changeslist-date' ),
996 array( 'oldid' => intval( $row->rev_id
) )
999 $d = htmlspecialchars( $date );
1001 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1002 $d = '<span class="history-deleted">' . $d . '</span>';
1005 # Show user names for /newbies as there may be different users.
1006 # Note that we already excluded rows with hidden user names.
1007 if ( $this->contribs
== 'newbie' ) {
1008 $userlink = ' . . ' . $lang->getDirMark() . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1009 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1010 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1015 if ( $rev->getParentId() === 0 ) {
1016 $nflag = ChangesList
::flag( 'newpage' );
1021 if ( $rev->isMinor() ) {
1022 $mflag = ChangesList
::flag( 'minor' );
1027 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1028 if ( $del !== '' ) {
1032 $diffHistLinks = $this->msg( 'parentheses' )
1033 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1035 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1036 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1038 # Denote if username is redacted for this edit
1039 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1040 $ret .= " <strong>" .
1041 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1046 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1050 $classes = array_merge( $classes, $newClasses );
1051 $ret .= " $tagSummary";
1054 // Let extensions add data
1055 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1057 if ( $classes === array() && $ret === '' ) {
1058 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1059 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1061 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1064 wfProfileOut( __METHOD__
);
1070 * Overwrite Pager function and return a helpful comment
1073 function getSqlComment() {
1074 if ( $this->namespace ||
$this->deletedOnly
) {
1075 // potentially slow, see CR r58153
1076 return 'contributions page filtered for namespace or RevisionDeleted edits';
1078 return 'contributions page unfiltered';
1082 protected function preventClickjacking() {
1083 $this->preventClickjacking
= true;
1089 public function getPreventClickjacking() {
1090 return $this->preventClickjacking
;