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' );
77 $this->opts
['newOnly'] = $request->getBool( 'newOnly' );
79 $nt = Title
::makeTitleSafe( NS_USER
, $target );
81 $out->addHTML( $this->getForm() );
85 $userObj = User
::newFromName( $nt->getText(), false );
87 $out->addHTML( $this->getForm() );
91 $id = $userObj->getID();
93 if ( $this->opts
['contribs'] != 'newbie' ) {
94 $target = $nt->getText();
95 $out->addSubtitle( $this->contributionsSub( $userObj ) );
96 $out->setHTMLTitle( $this->msg(
98 $this->msg( 'contributions-title', $target )->plain()
99 )->inContentLanguage() );
100 $this->getSkin()->setRelevantUser( $userObj );
102 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
103 $out->setHTMLTitle( $this->msg(
105 $this->msg( 'sp-contributions-newbies-title' )->plain()
106 )->inContentLanguage() );
109 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
110 $this->opts
['namespace'] = intval( $ns );
112 $this->opts
['namespace'] = '';
115 $this->opts
['associated'] = $request->getBool( 'associated' );
116 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
117 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
119 // Allows reverts to have the bot flag in recent changes. It is just here to
120 // be passed in the form at the top of the page
121 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
122 $this->opts
['bot'] = '1';
125 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
126 # Offset overrides year/month selection
128 $this->opts
['year'] = '';
129 $this->opts
['month'] = '';
131 $this->opts
['year'] = $request->getIntOrNull( 'year' );
132 $this->opts
['month'] = $request->getIntOrNull( 'month' );
135 $feedType = $request->getVal( 'feed' );
138 'action' => 'feedcontributions',
141 if ( $this->opts
['topOnly'] ) {
142 $feedParams['toponly'] = true;
144 if ( $this->opts
['newOnly'] ) {
145 $feedParams['newonly'] = true;
147 if ( $this->opts
['deletedOnly'] ) {
148 $feedParams['deletedonly'] = true;
150 if ( $this->opts
['tagfilter'] !== '' ) {
151 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
153 if ( $this->opts
['namespace'] !== '' ) {
154 $feedParams['namespace'] = $this->opts
['namespace'];
156 // Don't use year and month for the feed URL, but pass them on if
157 // we redirect to API (if $feedType is specified)
158 if ( $feedType && $this->opts
['year'] !== null ) {
159 $feedParams['year'] = $this->opts
['year'];
161 if ( $feedType && $this->opts
['month'] !== null ) {
162 $feedParams['month'] = $this->opts
['month'];
166 // Maintain some level of backwards compatability
167 // If people request feeds using the old parameters, redirect to API
168 $feedParams['feedformat'] = $feedType;
169 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
171 $out->redirect( $url, '301' );
176 // Add RSS/atom links
177 $this->addFeedLinks( $feedParams );
179 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) {
180 if ( !$this->including() ) {
181 $out->addHTML( $this->getForm() );
183 $pager = new ContribsPager( $this->getContext(), array(
185 'contribs' => $this->opts
['contribs'],
186 'namespace' => $this->opts
['namespace'],
187 'tagfilter' => $this->opts
['tagfilter'],
188 'year' => $this->opts
['year'],
189 'month' => $this->opts
['month'],
190 'deletedOnly' => $this->opts
['deletedOnly'],
191 'topOnly' => $this->opts
['topOnly'],
192 'newOnly' => $this->opts
['newOnly'],
193 'nsInvert' => $this->opts
['nsInvert'],
194 'associated' => $this->opts
['associated'],
197 if ( !$pager->getNumRows() ) {
198 $out->addWikiMsg( 'nocontribs', $target );
200 # Show a message about slave lag, if applicable
201 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
203 $out->showLagWarning( $lag );
207 '<p>' . $pager->getNavigationBar() . '</p>' .
209 '<p>' . $pager->getNavigationBar() . '</p>'
212 $out->preventClickjacking( $pager->getPreventClickjacking() );
214 # Show the appropriate "footer" message - WHOIS tools, etc.
215 if ( $this->opts
['contribs'] == 'newbie' ) {
216 $message = 'sp-contributions-footer-newbies';
217 } elseif ( IP
::isIPAddress( $target ) ) {
218 $message = 'sp-contributions-footer-anon';
219 } elseif ( $userObj->isAnon() ) {
220 // No message for non-existing users
223 $message = 'sp-contributions-footer';
227 if ( !$this->including() ) {
228 if ( !$this->msg( $message, $target )->isDisabled() ) {
230 "<div class='mw-contributions-footer'>\n$1\n</div>",
231 array( $message, $target ) );
239 * Generates the subheading with links
240 * @param $userObj User object for the target
241 * @return String: appropriately-escaped HTML to be output literally
242 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
245 protected function contributionsSub( $userObj ) {
246 if ( $userObj->isAnon() ) {
247 $user = htmlspecialchars( $userObj->getName() );
249 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
251 $nt = $userObj->getUserPage();
252 $talk = $userObj->getTalkPage();
255 $tools = $this->getUserLinks( $nt, $talk, $userObj );
256 $links = $this->getLanguage()->pipeList( $tools );
258 // Show a note if the user is blocked and display the last block log entry.
259 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
260 // and also this will display a totally irrelevant log entry as a current block.
261 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
262 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
263 LogEventsList
::showLogExtract(
270 'showIfEmpty' => false,
273 'sp-contributions-blocked-notice-anon' :
274 'sp-contributions-blocked-notice',
275 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
277 'offset' => '' # don't use WebRequest parameter offset
283 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
287 * Links to different places.
288 * @param $userpage Title: Target user page
289 * @param $talkpage Title: Talk page
290 * @param $target User: Target user object
293 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
295 $id = $target->getId();
296 $username = $target->getName();
298 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
300 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
301 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
302 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
303 $tools[] = Linker
::linkKnown( # Change block link
304 SpecialPage
::getTitleFor( 'Block', $username ),
305 $this->msg( 'change-blocklink' )->escaped()
307 $tools[] = Linker
::linkKnown( # Unblock link
308 SpecialPage
::getTitleFor( 'Unblock', $username ),
309 $this->msg( 'unblocklink' )->escaped()
311 } else { # User is not blocked
312 $tools[] = Linker
::linkKnown( # Block link
313 SpecialPage
::getTitleFor( 'Block', $username ),
314 $this->msg( 'blocklink' )->escaped()
320 $tools[] = Linker
::linkKnown(
321 SpecialPage
::getTitleFor( 'Log', 'block' ),
322 $this->msg( 'sp-contributions-blocklog' )->escaped(),
324 array( 'page' => $userpage->getPrefixedText() )
328 $tools[] = Linker
::linkKnown(
329 SpecialPage
::getTitleFor( 'Listfiles', $username ),
330 $this->msg( 'sp-contributions-uploads' )->escaped()
334 $tools[] = Linker
::linkKnown(
335 SpecialPage
::getTitleFor( 'Log', $username ),
336 $this->msg( 'sp-contributions-logs' )->escaped()
339 # Add link to deleted user contributions for priviledged users
340 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
341 $tools[] = Linker
::linkKnown(
342 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
343 $this->msg( 'sp-contributions-deleted' )->escaped()
347 # Add a link to change user rights for privileged users
348 $userrightsPage = new UserrightsPage();
349 $userrightsPage->setContext( $this->getContext() );
350 if ( $userrightsPage->userCanChangeRights( $target ) ) {
351 $tools[] = Linker
::linkKnown(
352 SpecialPage
::getTitleFor( 'Userrights', $username ),
353 $this->msg( 'sp-contributions-userrights' )->escaped()
357 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
363 * Generates the namespace selector form with hidden attributes.
364 * @return String: HTML fragment
366 protected function getForm() {
369 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
370 if ( !isset( $this->opts
['target'] ) ) {
371 $this->opts
['target'] = '';
373 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
376 if ( !isset( $this->opts
['namespace'] ) ) {
377 $this->opts
['namespace'] = '';
380 if ( !isset( $this->opts
['nsInvert'] ) ) {
381 $this->opts
['nsInvert'] = '';
384 if ( !isset( $this->opts
['associated'] ) ) {
385 $this->opts
['associated'] = false;
388 if ( !isset( $this->opts
['contribs'] ) ) {
389 $this->opts
['contribs'] = 'user';
392 if ( !isset( $this->opts
['year'] ) ) {
393 $this->opts
['year'] = '';
396 if ( !isset( $this->opts
['month'] ) ) {
397 $this->opts
['month'] = '';
400 if ( $this->opts
['contribs'] == 'newbie' ) {
401 $this->opts
['target'] = '';
404 if ( !isset( $this->opts
['tagfilter'] ) ) {
405 $this->opts
['tagfilter'] = '';
408 if ( !isset( $this->opts
['topOnly'] ) ) {
409 $this->opts
['topOnly'] = false;
412 if ( !isset( $this->opts
['newOnly'] ) ) {
413 $this->opts
['newOnly'] = false;
416 $form = Html
::openElement(
420 'action' => $wgScript,
421 'class' => 'mw-contributions-form'
425 # Add hidden params for tracking except for parameters in $skipParameters
426 $skipParameters = array(
439 foreach ( $this->opts
as $name => $value ) {
440 if ( in_array( $name, $skipParameters ) ) {
443 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
446 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
449 $filterSelection = Html
::rawElement(
451 array( 'class' => 'mw-label' ),
452 array_shift( $tagFilter )
454 $filterSelection .= Html
::rawElement(
456 array( 'class' => 'mw-input' ),
457 implode( ' ', $tagFilter )
460 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
463 $labelNewbies = Xml
::radioLabel(
464 $this->msg( 'sp-contributions-newbies' )->text(),
468 $this->opts
['contribs'] == 'newbie',
469 array( 'class' => 'mw-input' )
471 $labelUsername = Xml
::radioLabel(
472 $this->msg( 'sp-contributions-username' )->text(),
476 $this->opts
['contribs'] == 'user',
477 array( 'class' => 'mw-input' )
479 $input = Html
::input(
481 $this->opts
['target'],
483 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
484 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
487 $targetSelection = Html
::rawElement(
489 array( 'colspan' => 2 ),
490 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
493 $namespaceSelection = Xml
::tags(
495 array( 'class' => 'mw-label' ),
497 $this->msg( 'namespace' )->text(),
502 $namespaceSelection .= Html
::rawElement(
505 Html
::namespaceSelector(
506 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
508 'name' => 'namespace',
510 'class' => 'namespaceselector',
515 array( 'style' => 'white-space: nowrap' ),
517 $this->msg( 'invert' )->text(),
520 $this->opts
['nsInvert'],
522 'title' => $this->msg( 'tooltip-invert' )->text(),
523 'class' => 'mw-input'
527 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
529 $this->msg( 'namespace_association' )->text(),
532 $this->opts
['associated'],
534 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
535 'class' => 'mw-input'
541 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
542 $deletedOnlyCheck = Html
::rawElement(
544 array( 'style' => 'white-space: nowrap' ),
546 $this->msg( 'history-show-deleted' )->text(),
548 'mw-show-deleted-only',
549 $this->opts
['deletedOnly'],
550 array( 'class' => 'mw-input' )
554 $deletedOnlyCheck = '';
557 $checkLabelTopOnly = Html
::rawElement(
559 array( 'style' => 'white-space: nowrap' ),
561 $this->msg( 'sp-contributions-toponly' )->text(),
564 $this->opts
['topOnly'],
565 array( 'class' => 'mw-input' )
568 $checkLabelNewOnly = Html
::rawElement(
570 array( 'style' => 'white-space: nowrap' ),
572 $this->msg( 'sp-contributions-newonly' )->text(),
575 $this->opts
['newOnly'],
576 array( 'class' => 'mw-input' )
579 $extraOptions = Html
::rawElement(
581 array( 'colspan' => 2 ),
582 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
585 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
587 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
591 $this->msg( 'sp-contributions-submit' )->text(),
592 array( 'class' => 'mw-submit' )
596 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
597 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
598 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
599 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
600 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
601 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
602 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
605 $explain = $this->msg( 'sp-contributions-explain' );
606 if ( !$explain->isBlank() ) {
607 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
610 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
615 protected function getGroupName() {
621 * Pager for Special:Contributions
622 * @ingroup SpecialPage Pager
624 class ContribsPager
extends ReverseChronologicalPager
{
625 public $mDefaultDirection = true;
628 public $namespace = '';
630 public $preventClickjacking = false;
632 /** @var DatabaseBase */
633 public $mDbSecondary;
638 protected $mParentLens;
640 function __construct( IContextSource
$context, array $options ) {
641 parent
::__construct( $context );
653 foreach ( $msgs as $msg ) {
654 $this->messages
[$msg] = $this->msg( $msg )->escaped();
657 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
658 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
659 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
660 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
661 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
662 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
664 $this->deletedOnly
= !empty( $options['deletedOnly'] );
665 $this->topOnly
= !empty( $options['topOnly'] );
666 $this->newOnly
= !empty( $options['newOnly'] );
668 $year = isset( $options['year'] ) ?
$options['year'] : false;
669 $month = isset( $options['month'] ) ?
$options['month'] : false;
670 $this->getDateCond( $year, $month );
672 // Most of this code will use the 'contributions' group DB, which can map to slaves
673 // with extra user based indexes or partioning by user. The additional metadata
674 // queries should use a regular slave since the lookup pattern is not all by user.
675 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
676 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
679 function getDefaultQuery() {
680 $query = parent
::getDefaultQuery();
681 $query['target'] = $this->target
;
687 * This method basically executes the exact same code as the parent class, though with
688 * a hook added, to allow extentions to add additional queries.
690 * @param string $offset index offset, inclusive
691 * @param $limit Integer: exact query limit
692 * @param $descending Boolean: query direction, false for ascending, true for descending
693 * @return ResultWrapper
695 function reallyDoQuery( $offset, $limit, $descending ) {
696 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
704 * This hook will allow extensions to add in additional queries, so they can get their data
705 * in My Contributions as well. Extensions should append their results to the $data array.
707 * Extension queries have to implement the navbar requirement as well. They should
708 * - have a column aliased as $pager->getIndexField()
710 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
711 * - have the ORDER BY specified based upon the details provided by the navbar
713 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
715 * &$data: an array of results of all contribs queries
716 * $pager: the ContribsPager object hooked into
717 * $offset: see phpdoc above
718 * $limit: see phpdoc above
719 * $descending: see phpdoc above
721 $data = array( $this->mDb
->select(
722 $tables, $fields, $conds, $fname, $options, $join_conds
725 'ContribsPager::reallyDoQuery',
726 array( &$data, $pager, $offset, $limit, $descending )
731 // loop all results and collect them in an array
732 foreach ( $data as $query ) {
733 foreach ( $query as $i => $row ) {
734 // use index column as key, allowing us to easily sort in PHP
735 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
747 $result = array_slice( $result, 0, $limit );
749 // get rid of array keys
750 $result = array_values( $result );
752 return new FakeResultWrapper( $result );
755 function getQueryInfo() {
756 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
758 $user = $this->getUser();
759 $conds = array_merge( $userCond, $this->getNamespaceCond() );
761 // Paranoia: avoid brute force searches (bug 17342)
762 if ( !$user->isAllowed( 'deletedhistory' ) ) {
763 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
764 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
765 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
766 ' != ' . Revision
::SUPPRESSED_USER
;
769 # Don't include orphaned revisions
770 $join_cond['page'] = Revision
::pageJoinCond();
771 # Get the current user name for accounts
772 $join_cond['user'] = Revision
::userJoinCond();
776 $options['USE INDEX'] = array( 'revision' => $index );
781 'fields' => array_merge(
782 Revision
::selectFields(),
783 Revision
::selectUserFields(),
784 array( 'page_namespace', 'page_title', 'page_is_new',
785 'page_latest', 'page_is_redirect', 'page_len' )
788 'options' => $options,
789 'join_conds' => $join_cond
792 ChangeTags
::modifyDisplayQuery(
793 $queryInfo['tables'],
794 $queryInfo['fields'],
796 $queryInfo['join_conds'],
797 $queryInfo['options'],
801 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
806 function getUserCond() {
807 $condition = array();
808 $join_conds = array();
809 $tables = array( 'revision', 'page', 'user' );
811 if ( $this->contribs
== 'newbie' ) {
812 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
813 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
814 # ignore local groups with the bot right
815 # @todo FIXME: Global groups may have 'bot' rights
816 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
817 if ( count( $groupsWithBotPermission ) ) {
818 $tables[] = 'user_groups';
819 $condition[] = 'ug_group IS NULL';
820 $join_conds['user_groups'] = array(
822 'ug_user = rev_user',
823 'ug_group' => $groupsWithBotPermission
828 $uid = User
::idFromName( $this->target
);
830 $condition['rev_user'] = $uid;
831 $index = 'user_timestamp';
833 $condition['rev_user_text'] = $this->target
;
834 $index = 'usertext_timestamp';
838 if ( $this->deletedOnly
) {
839 $condition[] = 'rev_deleted != 0';
842 if ( $this->topOnly
) {
843 $condition[] = 'rev_id = page_latest';
846 if ( $this->newOnly
) {
847 $condition[] = 'rev_parent_id = 0';
850 return array( $tables, $index, $condition, $join_conds );
853 function getNamespaceCond() {
854 if ( $this->namespace !== '' ) {
855 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
856 $eq_op = $this->nsInvert ?
'!=' : '=';
857 $bool_op = $this->nsInvert ?
'AND' : 'OR';
859 if ( !$this->associated
) {
860 return array( "page_namespace $eq_op $selectedNS" );
863 $associatedNS = $this->mDb
->addQuotes(
864 MWNamespace
::getAssociated( $this->namespace )
868 "page_namespace $eq_op $selectedNS " .
870 " page_namespace $eq_op $associatedNS"
877 function getIndexField() {
878 return 'rev_timestamp';
881 function doBatchLookups() {
882 # Do a link batch query
883 $this->mResult
->seek( 0 );
885 $batch = new LinkBatch();
886 # Give some pointers to make (last) links
887 foreach ( $this->mResult
as $row ) {
888 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
889 $revIds[] = $row->rev_parent_id
;
891 if ( isset( $row->rev_id
) ) {
892 if ( $this->contribs
=== 'newbie' ) { // multiple users
893 $batch->add( NS_USER
, $row->user_name
);
894 $batch->add( NS_USER_TALK
, $row->user_name
);
896 $batch->add( $row->page_namespace
, $row->page_title
);
899 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
901 $this->mResult
->seek( 0 );
907 function getStartBody() {
914 function getEndBody() {
919 * Generates each row in the contributions list.
921 * Contributions which are marked "top" are currently on top of the history.
922 * For these contributions, a [rollback] link is shown for users with roll-
923 * back privileges. The rollback link restores the most recent version that
924 * was not written by the target user.
926 * @todo This would probably look a lot nicer in a table.
930 function formatRow( $row ) {
931 wfProfileIn( __METHOD__
);
937 * There may be more than just revision rows. To make sure that we'll only be processing
938 * revisions here, let's _try_ to build a revision out of our row (without displaying
939 * notices though) and then trying to grab data from the built object. If we succeed,
940 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
941 * to extensions to subscribe to the hook to parse the row.
943 wfSuppressWarnings();
944 $rev = new Revision( $row );
945 $validRevision = (bool)$rev->getId();
948 if ( $validRevision ) {
951 $page = Title
::newFromRow( $row );
952 $link = Linker
::link(
954 htmlspecialchars( $page->getPrefixedText() ),
955 array( 'class' => 'mw-contributions-title' ),
956 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
958 # Mark current revisions
960 $user = $this->getUser();
961 if ( $row->rev_id
== $row->page_latest
) {
962 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
964 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
965 && $page->quickUserCan( 'edit', $user )
967 $this->preventClickjacking();
968 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
971 # Is there a visible previous revision?
972 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
973 $difftext = Linker
::linkKnown(
975 $this->messages
['diff'],
979 'oldid' => $row->rev_id
983 $difftext = $this->messages
['diff'];
985 $histlink = Linker
::linkKnown(
987 $this->messages
['hist'],
989 array( 'action' => 'history' )
992 if ( $row->rev_parent_id
=== null ) {
993 // For some reason rev_parent_id isn't populated for this row.
994 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
995 // Next best thing is to have the total number of bytes.
996 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
997 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
998 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1001 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1002 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1005 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1006 $chardiff .= ChangesList
::showCharacterDifference(
1011 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1014 $lang = $this->getLanguage();
1015 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1016 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1017 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1018 $d = Linker
::linkKnown(
1020 htmlspecialchars( $date ),
1021 array( 'class' => 'mw-changeslist-date' ),
1022 array( 'oldid' => intval( $row->rev_id
) )
1025 $d = htmlspecialchars( $date );
1027 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1028 $d = '<span class="history-deleted">' . $d . '</span>';
1031 # Show user names for /newbies as there may be different users.
1032 # Note that we already excluded rows with hidden user names.
1033 if ( $this->contribs
== 'newbie' ) {
1034 $userlink = ' . . ' . $lang->getDirMark() . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1035 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1036 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1041 if ( $rev->getParentId() === 0 ) {
1042 $nflag = ChangesList
::flag( 'newpage' );
1047 if ( $rev->isMinor() ) {
1048 $mflag = ChangesList
::flag( 'minor' );
1053 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1054 if ( $del !== '' ) {
1058 $diffHistLinks = $this->msg( 'parentheses' )
1059 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1061 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1062 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1064 # Denote if username is redacted for this edit
1065 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1066 $ret .= " <strong>" .
1067 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1072 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1076 $classes = array_merge( $classes, $newClasses );
1077 $ret .= " $tagSummary";
1080 // Let extensions add data
1081 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1083 if ( $classes === array() && $ret === '' ) {
1084 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1085 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1087 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1090 wfProfileOut( __METHOD__
);
1096 * Overwrite Pager function and return a helpful comment
1099 function getSqlComment() {
1100 if ( $this->namespace ||
$this->deletedOnly
) {
1101 // potentially slow, see CR r58153
1102 return 'contributions page filtered for namespace or RevisionDeleted edits';
1104 return 'contributions page unfiltered';
1108 protected function preventClickjacking() {
1109 $this->preventClickjacking
= true;
1115 public function getPreventClickjacking() {
1116 return $this->preventClickjacking
;