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
29 class SpecialContributions
extends IncludableSpecialPage
{
32 public function __construct() {
33 parent
::__construct( 'Contributions' );
36 public function execute( $par ) {
38 $this->outputHeader();
39 $out = $this->getOutput();
40 $out->addModuleStyles( 'mediawiki.special' );
41 $this->addHelpLink( 'Help:User contributions' );
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() );
73 $user = $this->getUser();
75 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
76 $this->opts
['target'] = $target;
77 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
78 $this->opts
['newOnly'] = $request->getBool( 'newOnly' );
80 $nt = Title
::makeTitleSafe( NS_USER
, $target );
82 $out->addHTML( $this->getForm() );
86 $userObj = User
::newFromName( $nt->getText(), false );
88 $out->addHTML( $this->getForm() );
92 $id = $userObj->getID();
94 if ( $this->opts
['contribs'] != 'newbie' ) {
95 $target = $nt->getText();
96 $out->addSubtitle( $this->contributionsSub( $userObj ) );
97 $out->setHTMLTitle( $this->msg(
99 $this->msg( 'contributions-title', $target )->plain()
100 )->inContentLanguage() );
101 $this->getSkin()->setRelevantUser( $userObj );
103 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
104 $out->setHTMLTitle( $this->msg(
106 $this->msg( 'sp-contributions-newbies-title' )->plain()
107 )->inContentLanguage() );
110 $ns = $request->getVal( 'namespace', null );
111 if ( $ns !== null && $ns !== '' ) {
112 $this->opts
['namespace'] = intval( $ns );
114 $this->opts
['namespace'] = '';
117 $this->opts
['associated'] = $request->getBool( 'associated' );
118 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
119 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
121 // Allows reverts to have the bot flag in recent changes. It is just here to
122 // be passed in the form at the top of the page
123 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
124 $this->opts
['bot'] = '1';
127 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
128 # Offset overrides year/month selection
130 $this->opts
['year'] = '';
131 $this->opts
['month'] = '';
133 $this->opts
['year'] = $request->getIntOrNull( 'year' );
134 $this->opts
['month'] = $request->getIntOrNull( 'month' );
137 $feedType = $request->getVal( 'feed' );
140 'action' => 'feedcontributions',
143 if ( $this->opts
['topOnly'] ) {
144 $feedParams['toponly'] = true;
146 if ( $this->opts
['newOnly'] ) {
147 $feedParams['newonly'] = true;
149 if ( $this->opts
['deletedOnly'] ) {
150 $feedParams['deletedonly'] = true;
152 if ( $this->opts
['tagfilter'] !== '' ) {
153 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
155 if ( $this->opts
['namespace'] !== '' ) {
156 $feedParams['namespace'] = $this->opts
['namespace'];
158 // Don't use year and month for the feed URL, but pass them on if
159 // we redirect to API (if $feedType is specified)
160 if ( $feedType && $this->opts
['year'] !== null ) {
161 $feedParams['year'] = $this->opts
['year'];
163 if ( $feedType && $this->opts
['month'] !== null ) {
164 $feedParams['month'] = $this->opts
['month'];
168 // Maintain some level of backwards compatibility
169 // If people request feeds using the old parameters, redirect to API
170 $feedParams['feedformat'] = $feedType;
171 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
173 $out->redirect( $url, '301' );
178 // Add RSS/atom links
179 $this->addFeedLinks( $feedParams );
181 if ( Hooks
::run( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) {
182 if ( !$this->including() ) {
183 $out->addHTML( $this->getForm() );
185 $pager = new ContribsPager( $this->getContext(), array(
187 'contribs' => $this->opts
['contribs'],
188 'namespace' => $this->opts
['namespace'],
189 'tagfilter' => $this->opts
['tagfilter'],
190 'year' => $this->opts
['year'],
191 'month' => $this->opts
['month'],
192 'deletedOnly' => $this->opts
['deletedOnly'],
193 'topOnly' => $this->opts
['topOnly'],
194 'newOnly' => $this->opts
['newOnly'],
195 'nsInvert' => $this->opts
['nsInvert'],
196 'associated' => $this->opts
['associated'],
199 if ( !$pager->getNumRows() ) {
200 $out->addWikiMsg( 'nocontribs', $target );
202 # Show a message about slave lag, if applicable
203 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
205 $out->showLagWarning( $lag );
208 $output = $pager->getBody();
209 if ( !$this->including() ) {
210 $output = '<p>' . $pager->getNavigationBar() . '</p>' .
212 '<p>' . $pager->getNavigationBar() . '</p>';
214 $out->addHTML( $output );
216 $out->preventClickjacking( $pager->getPreventClickjacking() );
218 # Show the appropriate "footer" message - WHOIS tools, etc.
219 if ( $this->opts
['contribs'] == 'newbie' ) {
220 $message = 'sp-contributions-footer-newbies';
221 } elseif ( IP
::isIPAddress( $target ) ) {
222 $message = 'sp-contributions-footer-anon';
223 } elseif ( $userObj->isAnon() ) {
224 // No message for non-existing users
227 $message = 'sp-contributions-footer';
231 if ( !$this->including() ) {
232 if ( !$this->msg( $message, $target )->isDisabled() ) {
234 "<div class='mw-contributions-footer'>\n$1\n</div>",
235 array( $message, $target ) );
243 * Generates the subheading with links
244 * @param User $userObj User object for the target
245 * @return string Appropriately-escaped HTML to be output literally
246 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
249 protected function contributionsSub( $userObj ) {
250 if ( $userObj->isAnon() ) {
251 // Show a warning message that the user being searched for doesn't exists
252 if ( !User
::isIP( $userObj->getName() ) ) {
253 $this->getOutput()->wrapWikiMsg(
254 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
256 'contributions-userdoesnotexist',
257 wfEscapeWikiText( $userObj->getName() ),
260 if ( !$this->including() ) {
261 $this->getOutput()->setStatusCode( 404 );
264 $user = htmlspecialchars( $userObj->getName() );
266 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
268 $nt = $userObj->getUserPage();
269 $talk = $userObj->getTalkPage();
272 $tools = $this->getUserLinks( $nt, $talk, $userObj );
273 $links = $this->getLanguage()->pipeList( $tools );
275 // Show a note if the user is blocked and display the last block log entry.
276 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
277 // and also this will display a totally irrelevant log entry as a current block.
278 if ( !$this->including() ) {
279 $block = Block
::newFromTarget( $userObj, $userObj );
280 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
281 if ( $block->getType() == Block
::TYPE_RANGE
) {
282 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
285 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
286 LogEventsList
::showLogExtract(
293 'showIfEmpty' => false,
296 'sp-contributions-blocked-notice-anon' :
297 'sp-contributions-blocked-notice',
298 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
300 'offset' => '' # don't use WebRequest parameter offset
307 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
311 * Links to different places.
312 * @param Title $userpage Target user page
313 * @param Title $talkpage Talk page
314 * @param User $target Target user object
317 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
319 $id = $target->getId();
320 $username = $target->getName();
322 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
324 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
325 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
326 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
327 $tools[] = Linker
::linkKnown( # Change block link
328 SpecialPage
::getTitleFor( 'Block', $username ),
329 $this->msg( 'change-blocklink' )->escaped()
331 $tools[] = Linker
::linkKnown( # Unblock link
332 SpecialPage
::getTitleFor( 'Unblock', $username ),
333 $this->msg( 'unblocklink' )->escaped()
335 } else { # User is not blocked
336 $tools[] = Linker
::linkKnown( # Block link
337 SpecialPage
::getTitleFor( 'Block', $username ),
338 $this->msg( 'blocklink' )->escaped()
344 $tools[] = Linker
::linkKnown(
345 SpecialPage
::getTitleFor( 'Log', 'block' ),
346 $this->msg( 'sp-contributions-blocklog' )->escaped(),
348 array( 'page' => $userpage->getPrefixedText() )
351 # Suppression log link (bug 59120)
352 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
353 $tools[] = Linker
::linkKnown(
354 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
355 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
357 array( 'offender' => $username )
362 $tools[] = Linker
::linkKnown(
363 SpecialPage
::getTitleFor( 'Listfiles', $username ),
364 $this->msg( 'sp-contributions-uploads' )->escaped()
368 $tools[] = Linker
::linkKnown(
369 SpecialPage
::getTitleFor( 'Log', $username ),
370 $this->msg( 'sp-contributions-logs' )->escaped()
373 # Add link to deleted user contributions for priviledged users
374 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
375 $tools[] = Linker
::linkKnown(
376 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
377 $this->msg( 'sp-contributions-deleted' )->escaped()
381 # Add a link to change user rights for privileged users
382 $userrightsPage = new UserrightsPage();
383 $userrightsPage->setContext( $this->getContext() );
384 if ( $userrightsPage->userCanChangeRights( $target ) ) {
385 $tools[] = Linker
::linkKnown(
386 SpecialPage
::getTitleFor( 'Userrights', $username ),
387 $this->msg( 'sp-contributions-userrights' )->escaped()
391 Hooks
::run( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
397 * Generates the namespace selector form with hidden attributes.
398 * @return string HTML fragment
400 protected function getForm() {
401 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
402 if ( !isset( $this->opts
['target'] ) ) {
403 $this->opts
['target'] = '';
405 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
408 if ( !isset( $this->opts
['namespace'] ) ) {
409 $this->opts
['namespace'] = '';
412 if ( !isset( $this->opts
['nsInvert'] ) ) {
413 $this->opts
['nsInvert'] = '';
416 if ( !isset( $this->opts
['associated'] ) ) {
417 $this->opts
['associated'] = false;
420 if ( !isset( $this->opts
['contribs'] ) ) {
421 $this->opts
['contribs'] = 'user';
424 if ( !isset( $this->opts
['year'] ) ) {
425 $this->opts
['year'] = '';
428 if ( !isset( $this->opts
['month'] ) ) {
429 $this->opts
['month'] = '';
432 if ( $this->opts
['contribs'] == 'newbie' ) {
433 $this->opts
['target'] = '';
436 if ( !isset( $this->opts
['tagfilter'] ) ) {
437 $this->opts
['tagfilter'] = '';
440 if ( !isset( $this->opts
['topOnly'] ) ) {
441 $this->opts
['topOnly'] = false;
444 if ( !isset( $this->opts
['newOnly'] ) ) {
445 $this->opts
['newOnly'] = false;
448 $form = Html
::openElement(
452 'action' => wfScript(),
453 'class' => 'mw-contributions-form'
457 # Add hidden params for tracking except for parameters in $skipParameters
458 $skipParameters = array(
471 foreach ( $this->opts
as $name => $value ) {
472 if ( in_array( $name, $skipParameters ) ) {
475 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
478 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
481 $filterSelection = Html
::rawElement(
484 array_shift( $tagFilter ) . implode( ' ', $tagFilter )
487 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
490 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
492 $labelNewbies = Xml
::radioLabel(
493 $this->msg( 'sp-contributions-newbies' )->text(),
497 $this->opts
['contribs'] == 'newbie',
498 array( 'class' => 'mw-input' )
500 $labelUsername = Xml
::radioLabel(
501 $this->msg( 'sp-contributions-username' )->text(),
505 $this->opts
['contribs'] == 'user',
506 array( 'class' => 'mw-input' )
508 $input = Html
::input(
510 $this->opts
['target'],
517 'mw-ui-input-inline',
518 'mw-autocomplete-user', // used by mediawiki.userSuggest
520 ) +
( $this->opts
['target'] ?
array() : array( 'autofocus' ) )
522 $targetSelection = Html
::rawElement(
524 array( 'colspan' => 2 ),
525 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
528 $namespaceSelection = Xml
::tags(
532 $this->msg( 'namespace' )->text(),
536 Html
::namespaceSelector(
537 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
539 'name' => 'namespace',
541 'class' => 'namespaceselector',
546 array( 'style' => 'white-space: nowrap' ),
548 $this->msg( 'invert' )->text(),
551 $this->opts
['nsInvert'],
553 'title' => $this->msg( 'tooltip-invert' )->text(),
554 'class' => 'mw-input'
558 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
560 $this->msg( 'namespace_association' )->text(),
563 $this->opts
['associated'],
565 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
566 'class' => 'mw-input'
572 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
573 $deletedOnlyCheck = Html
::rawElement(
575 array( 'style' => 'white-space: nowrap' ),
577 $this->msg( 'history-show-deleted' )->text(),
579 'mw-show-deleted-only',
580 $this->opts
['deletedOnly'],
581 array( 'class' => 'mw-input' )
585 $deletedOnlyCheck = '';
588 $checkLabelTopOnly = Html
::rawElement(
590 array( 'style' => 'white-space: nowrap' ),
592 $this->msg( 'sp-contributions-toponly' )->text(),
595 $this->opts
['topOnly'],
596 array( 'class' => 'mw-input' )
599 $checkLabelNewOnly = Html
::rawElement(
601 array( 'style' => 'white-space: nowrap' ),
603 $this->msg( 'sp-contributions-newonly' )->text(),
606 $this->opts
['newOnly'],
607 array( 'class' => 'mw-input' )
610 $extraOptions = Html
::rawElement(
612 array( 'colspan' => 2 ),
613 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
616 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
618 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
622 $this->msg( 'sp-contributions-submit' )->text(),
623 array( 'class' => 'mw-submit' ), array( 'mw-ui-progressive' )
627 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
628 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
629 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
630 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
631 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
632 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
633 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
636 $explain = $this->msg( 'sp-contributions-explain' );
637 if ( !$explain->isBlank() ) {
638 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
641 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
646 protected function getGroupName() {
652 * Pager for Special:Contributions
653 * @ingroup SpecialPage Pager
655 class ContribsPager
extends ReverseChronologicalPager
{
656 public $mDefaultDirection = IndexPager
::DIR_DESCENDING
;
659 public $namespace = '';
661 public $preventClickjacking = false;
663 /** @var IDatabase */
664 public $mDbSecondary;
669 protected $mParentLens;
671 function __construct( IContextSource
$context, array $options ) {
672 parent
::__construct( $context );
681 foreach ( $msgs as $msg ) {
682 $this->messages
[$msg] = $this->msg( $msg )->escaped();
685 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
686 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
687 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
688 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
689 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
690 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
692 $this->deletedOnly
= !empty( $options['deletedOnly'] );
693 $this->topOnly
= !empty( $options['topOnly'] );
694 $this->newOnly
= !empty( $options['newOnly'] );
696 $year = isset( $options['year'] ) ?
$options['year'] : false;
697 $month = isset( $options['month'] ) ?
$options['month'] : false;
698 $this->getDateCond( $year, $month );
700 // Most of this code will use the 'contributions' group DB, which can map to slaves
701 // with extra user based indexes or partioning by user. The additional metadata
702 // queries should use a regular slave since the lookup pattern is not all by user.
703 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
704 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
707 function getDefaultQuery() {
708 $query = parent
::getDefaultQuery();
709 $query['target'] = $this->target
;
715 * This method basically executes the exact same code as the parent class, though with
716 * a hook added, to allow extensions to add additional queries.
718 * @param string $offset Index offset, inclusive
719 * @param int $limit Exact query limit
720 * @param bool $descending Query direction, false for ascending, true for descending
721 * @return ResultWrapper
723 function reallyDoQuery( $offset, $limit, $descending ) {
724 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
731 * This hook will allow extensions to add in additional queries, so they can get their data
732 * in My Contributions as well. Extensions should append their results to the $data array.
734 * Extension queries have to implement the navbar requirement as well. They should
735 * - have a column aliased as $pager->getIndexField()
737 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
738 * - have the ORDER BY specified based upon the details provided by the navbar
740 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
742 * &$data: an array of results of all contribs queries
743 * $pager: the ContribsPager object hooked into
744 * $offset: see phpdoc above
745 * $limit: see phpdoc above
746 * $descending: see phpdoc above
748 $data = array( $this->mDb
->select(
749 $tables, $fields, $conds, $fname, $options, $join_conds
752 'ContribsPager::reallyDoQuery',
753 array( &$data, $this, $offset, $limit, $descending )
758 // loop all results and collect them in an array
759 foreach ( $data as $query ) {
760 foreach ( $query as $i => $row ) {
761 // use index column as key, allowing us to easily sort in PHP
762 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
774 $result = array_slice( $result, 0, $limit );
776 // get rid of array keys
777 $result = array_values( $result );
779 return new FakeResultWrapper( $result );
782 function getQueryInfo() {
783 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
785 $user = $this->getUser();
786 $conds = array_merge( $userCond, $this->getNamespaceCond() );
788 // Paranoia: avoid brute force searches (bug 17342)
789 if ( !$user->isAllowed( 'deletedhistory' ) ) {
790 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
791 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
792 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
793 ' != ' . Revision
::SUPPRESSED_USER
;
796 # Don't include orphaned revisions
797 $join_cond['page'] = Revision
::pageJoinCond();
798 # Get the current user name for accounts
799 $join_cond['user'] = Revision
::userJoinCond();
803 $options['USE INDEX'] = array( 'revision' => $index );
808 'fields' => array_merge(
809 Revision
::selectFields(),
810 Revision
::selectUserFields(),
811 array( 'page_namespace', 'page_title', 'page_is_new',
812 'page_latest', 'page_is_redirect', 'page_len' )
815 'options' => $options,
816 'join_conds' => $join_cond
819 ChangeTags
::modifyDisplayQuery(
820 $queryInfo['tables'],
821 $queryInfo['fields'],
823 $queryInfo['join_conds'],
824 $queryInfo['options'],
828 Hooks
::run( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
833 function getUserCond() {
834 $condition = array();
835 $join_conds = array();
836 $tables = array( 'revision', 'page', 'user' );
838 if ( $this->contribs
== 'newbie' ) {
839 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
840 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
841 # ignore local groups with the bot right
842 # @todo FIXME: Global groups may have 'bot' rights
843 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
844 if ( count( $groupsWithBotPermission ) ) {
845 $tables[] = 'user_groups';
846 $condition[] = 'ug_group IS NULL';
847 $join_conds['user_groups'] = array(
849 'ug_user = rev_user',
850 'ug_group' => $groupsWithBotPermission
855 $uid = User
::idFromName( $this->target
);
857 $condition['rev_user'] = $uid;
858 $index = 'user_timestamp';
860 $condition['rev_user_text'] = $this->target
;
861 $index = 'usertext_timestamp';
865 if ( $this->deletedOnly
) {
866 $condition[] = 'rev_deleted != 0';
869 if ( $this->topOnly
) {
870 $condition[] = 'rev_id = page_latest';
873 if ( $this->newOnly
) {
874 $condition[] = 'rev_parent_id = 0';
877 return array( $tables, $index, $condition, $join_conds );
880 function getNamespaceCond() {
881 if ( $this->namespace !== '' ) {
882 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
883 $eq_op = $this->nsInvert ?
'!=' : '=';
884 $bool_op = $this->nsInvert ?
'AND' : 'OR';
886 if ( !$this->associated
) {
887 return array( "page_namespace $eq_op $selectedNS" );
890 $associatedNS = $this->mDb
->addQuotes(
891 MWNamespace
::getAssociated( $this->namespace )
895 "page_namespace $eq_op $selectedNS " .
897 " page_namespace $eq_op $associatedNS"
904 function getIndexField() {
905 return 'rev_timestamp';
908 function doBatchLookups() {
909 # Do a link batch query
910 $this->mResult
->seek( 0 );
912 $batch = new LinkBatch();
913 # Give some pointers to make (last) links
914 foreach ( $this->mResult
as $row ) {
915 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
916 $revIds[] = $row->rev_parent_id
;
918 if ( isset( $row->rev_id
) ) {
919 if ( $this->contribs
=== 'newbie' ) { // multiple users
920 $batch->add( NS_USER
, $row->user_name
);
921 $batch->add( NS_USER_TALK
, $row->user_name
);
923 $batch->add( $row->page_namespace
, $row->page_title
);
926 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
928 $this->mResult
->seek( 0 );
934 function getStartBody() {
935 return "<ul class=\"mw-contributions-list\">\n";
941 function getEndBody() {
946 * Generates each row in the contributions list.
948 * Contributions which are marked "top" are currently on top of the history.
949 * For these contributions, a [rollback] link is shown for users with roll-
950 * back privileges. The rollback link restores the most recent version that
951 * was not written by the target user.
953 * @todo This would probably look a lot nicer in a table.
957 function formatRow( $row ) {
963 * There may be more than just revision rows. To make sure that we'll only be processing
964 * revisions here, let's _try_ to build a revision out of our row (without displaying
965 * notices though) and then trying to grab data from the built object. If we succeed,
966 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
967 * to extensions to subscribe to the hook to parse the row.
969 MediaWiki\
suppressWarnings();
971 $rev = new Revision( $row );
972 $validRevision = (bool)$rev->getId();
973 } catch ( Exception
$e ) {
974 $validRevision = false;
976 MediaWiki\restoreWarnings
();
978 if ( $validRevision ) {
981 $page = Title
::newFromRow( $row );
982 $link = Linker
::link(
984 htmlspecialchars( $page->getPrefixedText() ),
985 array( 'class' => 'mw-contributions-title' ),
986 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
988 # Mark current revisions
990 $user = $this->getUser();
991 if ( $row->rev_id
== $row->page_latest
) {
992 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
994 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
995 && $page->quickUserCan( 'edit', $user )
997 $this->preventClickjacking();
998 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
1001 # Is there a visible previous revision?
1002 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
1003 $difftext = Linker
::linkKnown(
1005 $this->messages
['diff'],
1009 'oldid' => $row->rev_id
1013 $difftext = $this->messages
['diff'];
1015 $histlink = Linker
::linkKnown(
1017 $this->messages
['hist'],
1019 array( 'action' => 'history' )
1022 if ( $row->rev_parent_id
=== null ) {
1023 // For some reason rev_parent_id isn't populated for this row.
1024 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
1025 // Next best thing is to have the total number of bytes.
1026 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1027 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
1028 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1031 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1032 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1035 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1036 $chardiff .= ChangesList
::showCharacterDifference(
1041 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1044 $lang = $this->getLanguage();
1045 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1046 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1047 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1048 $d = Linker
::linkKnown(
1050 htmlspecialchars( $date ),
1051 array( 'class' => 'mw-changeslist-date' ),
1052 array( 'oldid' => intval( $row->rev_id
) )
1055 $d = htmlspecialchars( $date );
1057 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1058 $d = '<span class="history-deleted">' . $d . '</span>';
1061 # Show user names for /newbies as there may be different users.
1062 # Note that we already excluded rows with hidden user names.
1063 if ( $this->contribs
== 'newbie' ) {
1064 $userlink = ' . . ' . $lang->getDirMark()
1065 . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1066 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1067 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1072 if ( $rev->getParentId() === 0 ) {
1073 $nflag = ChangesList
::flag( 'newpage' );
1078 if ( $rev->isMinor() ) {
1079 $mflag = ChangesList
::flag( 'minor' );
1084 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1085 if ( $del !== '' ) {
1089 $diffHistLinks = $this->msg( 'parentheses' )
1090 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1092 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1093 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1095 # Denote if username is redacted for this edit
1096 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1097 $ret .= " <strong>" .
1098 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1103 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1107 $classes = array_merge( $classes, $newClasses );
1108 $ret .= " $tagSummary";
1111 // Let extensions add data
1112 Hooks
::run( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1114 if ( $classes === array() && $ret === '' ) {
1115 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
1116 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1118 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1125 * Overwrite Pager function and return a helpful comment
1128 function getSqlComment() {
1129 if ( $this->namespace ||
$this->deletedOnly
) {
1130 // potentially slow, see CR r58153
1131 return 'contributions page filtered for namespace or RevisionDeleted edits';
1133 return 'contributions page unfiltered';
1137 protected function preventClickjacking() {
1138 $this->preventClickjacking
= true;
1144 public function getPreventClickjacking() {
1145 return $this->preventClickjacking
;