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' );
52 if ( $request->getVal( 'contribs' ) == 'newbie' ||
$par === 'newbies' ) {
54 $this->opts
['contribs'] = 'newbie';
56 $this->opts
['contribs'] = 'user';
59 $this->opts
['deletedOnly'] = $request->getBool( 'deletedOnly' );
61 if ( !strlen( $target ) ) {
62 if ( !$this->including() ) {
63 $out->addHTML( $this->getForm() );
69 $user = $this->getUser();
71 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
72 $this->opts
['target'] = $target;
73 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
74 $this->opts
['newOnly'] = $request->getBool( 'newOnly' );
76 $nt = Title
::makeTitleSafe( NS_USER
, $target );
78 $out->addHTML( $this->getForm() );
82 $userObj = User
::newFromName( $nt->getText(), false );
84 $out->addHTML( $this->getForm() );
88 $id = $userObj->getID();
90 if ( $this->opts
['contribs'] != 'newbie' ) {
91 $target = $nt->getText();
92 $out->addSubtitle( $this->contributionsSub( $userObj ) );
93 $out->setHTMLTitle( $this->msg(
95 $this->msg( 'contributions-title', $target )->plain()
96 )->inContentLanguage() );
97 $this->getSkin()->setRelevantUser( $userObj );
99 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
100 $out->setHTMLTitle( $this->msg(
102 $this->msg( 'sp-contributions-newbies-title' )->plain()
103 )->inContentLanguage() );
106 $ns = $request->getVal( 'namespace', null );
107 if ( $ns !== 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' );
136 'action' => 'feedcontributions',
139 if ( $this->opts
['topOnly'] ) {
140 $feedParams['toponly'] = true;
142 if ( $this->opts
['newOnly'] ) {
143 $feedParams['newonly'] = true;
145 if ( $this->opts
['deletedOnly'] ) {
146 $feedParams['deletedonly'] = true;
148 if ( $this->opts
['tagfilter'] !== '' ) {
149 $feedParams['tagfilter'] = $this->opts
['tagfilter'];
151 if ( $this->opts
['namespace'] !== '' ) {
152 $feedParams['namespace'] = $this->opts
['namespace'];
154 // Don't use year and month for the feed URL, but pass them on if
155 // we redirect to API (if $feedType is specified)
156 if ( $feedType && $this->opts
['year'] !== null ) {
157 $feedParams['year'] = $this->opts
['year'];
159 if ( $feedType && $this->opts
['month'] !== null ) {
160 $feedParams['month'] = $this->opts
['month'];
164 // Maintain some level of backwards compatibility
165 // If people request feeds using the old parameters, redirect to API
166 $feedParams['feedformat'] = $feedType;
167 $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
169 $out->redirect( $url, '301' );
174 // Add RSS/atom links
175 $this->addFeedLinks( $feedParams );
177 if ( Hooks
::run( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) {
178 if ( !$this->including() ) {
179 $out->addHTML( $this->getForm() );
181 $pager = new ContribsPager( $this->getContext(), array(
183 'contribs' => $this->opts
['contribs'],
184 'namespace' => $this->opts
['namespace'],
185 'tagfilter' => $this->opts
['tagfilter'],
186 'year' => $this->opts
['year'],
187 'month' => $this->opts
['month'],
188 'deletedOnly' => $this->opts
['deletedOnly'],
189 'topOnly' => $this->opts
['topOnly'],
190 'newOnly' => $this->opts
['newOnly'],
191 'nsInvert' => $this->opts
['nsInvert'],
192 'associated' => $this->opts
['associated'],
195 if ( !$pager->getNumRows() ) {
196 $out->addWikiMsg( 'nocontribs', $target );
198 # Show a message about slave lag, if applicable
199 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
201 $out->showLagWarning( $lag );
204 $output = $pager->getBody();
205 if ( !$this->including() ) {
206 $output = '<p>' . $pager->getNavigationBar() . '</p>' .
208 '<p>' . $pager->getNavigationBar() . '</p>';
210 $out->addHTML( $output );
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 User $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 // Show a warning message that the user being searched for doesn't exists
248 if ( !User
::isIP( $userObj->getName() ) ) {
249 $this->getOutput()->wrapWikiMsg(
250 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
252 'contributions-userdoesnotexist',
253 wfEscapeWikiText( $userObj->getName() ),
256 if ( !$this->including() ) {
257 $this->getOutput()->setStatusCode( 404 );
260 $user = htmlspecialchars( $userObj->getName() );
262 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
264 $nt = $userObj->getUserPage();
265 $talk = $userObj->getTalkPage();
268 $tools = $this->getUserLinks( $nt, $talk, $userObj );
269 $links = $this->getLanguage()->pipeList( $tools );
271 // Show a note if the user is blocked and display the last block log entry.
272 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
273 // and also this will display a totally irrelevant log entry as a current block.
274 if ( !$this->including() ) {
275 $block = Block
::newFromTarget( $userObj, $userObj );
276 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
277 if ( $block->getType() == Block
::TYPE_RANGE
) {
278 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
281 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
282 LogEventsList
::showLogExtract(
289 'showIfEmpty' => false,
292 'sp-contributions-blocked-notice-anon' :
293 'sp-contributions-blocked-notice',
294 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
296 'offset' => '' # don't use WebRequest parameter offset
303 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
307 * Links to different places.
308 * @param Title $userpage Target user page
309 * @param Title $talkpage Talk page
310 * @param User $target Target user object
313 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
315 $id = $target->getId();
316 $username = $target->getName();
318 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
320 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
321 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
322 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
323 $tools[] = Linker
::linkKnown( # Change block link
324 SpecialPage
::getTitleFor( 'Block', $username ),
325 $this->msg( 'change-blocklink' )->escaped()
327 $tools[] = Linker
::linkKnown( # Unblock link
328 SpecialPage
::getTitleFor( 'Unblock', $username ),
329 $this->msg( 'unblocklink' )->escaped()
331 } else { # User is not blocked
332 $tools[] = Linker
::linkKnown( # Block link
333 SpecialPage
::getTitleFor( 'Block', $username ),
334 $this->msg( 'blocklink' )->escaped()
340 $tools[] = Linker
::linkKnown(
341 SpecialPage
::getTitleFor( 'Log', 'block' ),
342 $this->msg( 'sp-contributions-blocklog' )->escaped(),
344 array( 'page' => $userpage->getPrefixedText() )
347 # Suppression log link (bug 59120)
348 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
349 $tools[] = Linker
::linkKnown(
350 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
351 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
353 array( 'offender' => $username )
358 $tools[] = Linker
::linkKnown(
359 SpecialPage
::getTitleFor( 'Listfiles', $username ),
360 $this->msg( 'sp-contributions-uploads' )->escaped()
364 $tools[] = Linker
::linkKnown(
365 SpecialPage
::getTitleFor( 'Log', $username ),
366 $this->msg( 'sp-contributions-logs' )->escaped()
369 # Add link to deleted user contributions for priviledged users
370 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
371 $tools[] = Linker
::linkKnown(
372 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
373 $this->msg( 'sp-contributions-deleted' )->escaped()
377 # Add a link to change user rights for privileged users
378 $userrightsPage = new UserrightsPage();
379 $userrightsPage->setContext( $this->getContext() );
380 if ( $userrightsPage->userCanChangeRights( $target ) ) {
381 $tools[] = Linker
::linkKnown(
382 SpecialPage
::getTitleFor( 'Userrights', $username ),
383 $this->msg( 'sp-contributions-userrights' )->escaped()
387 Hooks
::run( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
393 * Generates the namespace selector form with hidden attributes.
394 * @return string HTML fragment
396 protected function getForm() {
397 $this->opts
['title'] = $this->getPageTitle()->getPrefixedText();
398 if ( !isset( $this->opts
['target'] ) ) {
399 $this->opts
['target'] = '';
401 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
404 if ( !isset( $this->opts
['namespace'] ) ) {
405 $this->opts
['namespace'] = '';
408 if ( !isset( $this->opts
['nsInvert'] ) ) {
409 $this->opts
['nsInvert'] = '';
412 if ( !isset( $this->opts
['associated'] ) ) {
413 $this->opts
['associated'] = false;
416 if ( !isset( $this->opts
['contribs'] ) ) {
417 $this->opts
['contribs'] = 'user';
420 if ( !isset( $this->opts
['year'] ) ) {
421 $this->opts
['year'] = '';
424 if ( !isset( $this->opts
['month'] ) ) {
425 $this->opts
['month'] = '';
428 if ( $this->opts
['contribs'] == 'newbie' ) {
429 $this->opts
['target'] = '';
432 if ( !isset( $this->opts
['tagfilter'] ) ) {
433 $this->opts
['tagfilter'] = '';
436 if ( !isset( $this->opts
['topOnly'] ) ) {
437 $this->opts
['topOnly'] = false;
440 if ( !isset( $this->opts
['newOnly'] ) ) {
441 $this->opts
['newOnly'] = false;
444 $form = Html
::openElement(
448 'action' => wfScript(),
449 'class' => 'mw-contributions-form'
453 # Add hidden params for tracking except for parameters in $skipParameters
454 $skipParameters = array(
468 foreach ( $this->opts
as $name => $value ) {
469 if ( in_array( $name, $skipParameters ) ) {
472 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
475 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
478 $filterSelection = Html
::rawElement(
481 implode( ' ', $tagFilter )
484 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
487 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
489 $labelNewbies = Xml
::radioLabel(
490 $this->msg( 'sp-contributions-newbies' )->text(),
494 $this->opts
['contribs'] == 'newbie',
495 array( 'class' => 'mw-input' )
497 $labelUsername = Xml
::radioLabel(
498 $this->msg( 'sp-contributions-username' )->text(),
502 $this->opts
['contribs'] == 'user',
503 array( 'class' => 'mw-input' )
505 $input = Html
::input(
507 $this->opts
['target'],
514 'mw-ui-input-inline',
515 'mw-autocomplete-user', // used by mediawiki.userSuggest
518 // Only autofocus if target hasn't been specified or in non-newbies mode
519 ( $this->opts
['contribs'] === 'newbie' ||
$this->opts
['target'] )
520 ?
array() : array( 'autofocus' => true )
524 $targetSelection = Html
::rawElement(
526 array( 'colspan' => 2 ),
527 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
530 $namespaceSelection = Xml
::tags(
534 $this->msg( 'namespace' )->text(),
538 Html
::namespaceSelector(
539 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
541 'name' => 'namespace',
543 'class' => 'namespaceselector',
548 array( 'class' => 'mw-input-with-label' ),
550 $this->msg( 'invert' )->text(),
553 $this->opts
['nsInvert'],
555 'title' => $this->msg( 'tooltip-invert' )->text(),
556 'class' => 'mw-input'
560 Html
::rawElement( 'span', array( 'class' => 'mw-input-with-label' ),
562 $this->msg( 'namespace_association' )->text(),
565 $this->opts
['associated'],
567 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
568 'class' => 'mw-input'
574 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
575 $deletedOnlyCheck = Html
::rawElement(
577 array( 'class' => 'mw-input-with-label' ),
579 $this->msg( 'history-show-deleted' )->text(),
581 'mw-show-deleted-only',
582 $this->opts
['deletedOnly'],
583 array( 'class' => 'mw-input' )
587 $deletedOnlyCheck = '';
590 $checkLabelTopOnly = Html
::rawElement(
592 array( 'class' => 'mw-input-with-label' ),
594 $this->msg( 'sp-contributions-toponly' )->text(),
597 $this->opts
['topOnly'],
598 array( 'class' => 'mw-input' )
601 $checkLabelNewOnly = Html
::rawElement(
603 array( 'class' => 'mw-input-with-label' ),
605 $this->msg( 'sp-contributions-newonly' )->text(),
608 $this->opts
['newOnly'],
609 array( 'class' => 'mw-input' )
612 $extraOptions = Html
::rawElement(
614 array( 'colspan' => 2 ),
615 $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly
618 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
620 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
624 $this->msg( 'sp-contributions-submit' )->text(),
625 array( 'class' => 'mw-submit' ), array( 'mw-ui-progressive' )
629 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
630 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
631 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
632 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
633 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
634 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
635 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
638 $explain = $this->msg( 'sp-contributions-explain' );
639 if ( !$explain->isBlank() ) {
640 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
643 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
649 * Return an array of subpages beginning with $search that this special page will accept.
651 * @param string $search Prefix to search for
652 * @param int $limit Maximum number of results to return (usually 10)
653 * @param int $offset Number of results to skip (usually 0)
654 * @return string[] Matching subpages
656 public function prefixSearchSubpages( $search, $limit, $offset ) {
657 $user = User
::newFromName( $search );
659 // No prefix suggestion for invalid user
662 // Autocomplete subpage as user list - public to allow caching
663 return UserNamePrefixSearch
::search( 'public', $search, $limit, $offset );
666 protected function getGroupName() {
672 * Pager for Special:Contributions
673 * @ingroup SpecialPage Pager
675 class ContribsPager
extends ReverseChronologicalPager
{
676 public $mDefaultDirection = IndexPager
::DIR_DESCENDING
;
679 public $namespace = '';
681 public $preventClickjacking = false;
683 /** @var IDatabase */
684 public $mDbSecondary;
689 protected $mParentLens;
691 function __construct( IContextSource
$context, array $options ) {
692 parent
::__construct( $context );
701 foreach ( $msgs as $msg ) {
702 $this->messages
[$msg] = $this->msg( $msg )->escaped();
705 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
706 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
707 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
708 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
709 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
710 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
712 $this->deletedOnly
= !empty( $options['deletedOnly'] );
713 $this->topOnly
= !empty( $options['topOnly'] );
714 $this->newOnly
= !empty( $options['newOnly'] );
716 $year = isset( $options['year'] ) ?
$options['year'] : false;
717 $month = isset( $options['month'] ) ?
$options['month'] : false;
718 $this->getDateCond( $year, $month );
720 // Most of this code will use the 'contributions' group DB, which can map to slaves
721 // with extra user based indexes or partioning by user. The additional metadata
722 // queries should use a regular slave since the lookup pattern is not all by user.
723 $this->mDbSecondary
= wfGetDB( DB_SLAVE
); // any random slave
724 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
727 function getDefaultQuery() {
728 $query = parent
::getDefaultQuery();
729 $query['target'] = $this->target
;
735 * This method basically executes the exact same code as the parent class, though with
736 * a hook added, to allow extensions to add additional queries.
738 * @param string $offset Index offset, inclusive
739 * @param int $limit Exact query limit
740 * @param bool $descending Query direction, false for ascending, true for descending
741 * @return ResultWrapper
743 function reallyDoQuery( $offset, $limit, $descending ) {
744 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
751 * This hook will allow extensions to add in additional queries, so they can get their data
752 * in My Contributions as well. Extensions should append their results to the $data array.
754 * Extension queries have to implement the navbar requirement as well. They should
755 * - have a column aliased as $pager->getIndexField()
757 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
758 * - have the ORDER BY specified based upon the details provided by the navbar
760 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
762 * &$data: an array of results of all contribs queries
763 * $pager: the ContribsPager object hooked into
764 * $offset: see phpdoc above
765 * $limit: see phpdoc above
766 * $descending: see phpdoc above
768 $data = array( $this->mDb
->select(
769 $tables, $fields, $conds, $fname, $options, $join_conds
772 'ContribsPager::reallyDoQuery',
773 array( &$data, $this, $offset, $limit, $descending )
778 // loop all results and collect them in an array
779 foreach ( $data as $query ) {
780 foreach ( $query as $i => $row ) {
781 // use index column as key, allowing us to easily sort in PHP
782 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
794 $result = array_slice( $result, 0, $limit );
796 // get rid of array keys
797 $result = array_values( $result );
799 return new FakeResultWrapper( $result );
802 function getQueryInfo() {
803 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
805 $user = $this->getUser();
806 $conds = array_merge( $userCond, $this->getNamespaceCond() );
808 // Paranoia: avoid brute force searches (bug 17342)
809 if ( !$user->isAllowed( 'deletedhistory' ) ) {
810 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
811 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
812 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
813 ' != ' . Revision
::SUPPRESSED_USER
;
816 # Don't include orphaned revisions
817 $join_cond['page'] = Revision
::pageJoinCond();
818 # Get the current user name for accounts
819 $join_cond['user'] = Revision
::userJoinCond();
823 $options['USE INDEX'] = array( 'revision' => $index );
828 'fields' => array_merge(
829 Revision
::selectFields(),
830 Revision
::selectUserFields(),
831 array( 'page_namespace', 'page_title', 'page_is_new',
832 'page_latest', 'page_is_redirect', 'page_len' )
835 'options' => $options,
836 'join_conds' => $join_cond
839 ChangeTags
::modifyDisplayQuery(
840 $queryInfo['tables'],
841 $queryInfo['fields'],
843 $queryInfo['join_conds'],
844 $queryInfo['options'],
848 Hooks
::run( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
853 function getUserCond() {
854 $condition = array();
855 $join_conds = array();
856 $tables = array( 'revision', 'page', 'user' );
858 if ( $this->contribs
== 'newbie' ) {
859 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
860 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
861 # ignore local groups with the bot right
862 # @todo FIXME: Global groups may have 'bot' rights
863 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
864 if ( count( $groupsWithBotPermission ) ) {
865 $tables[] = 'user_groups';
866 $condition[] = 'ug_group IS NULL';
867 $join_conds['user_groups'] = array(
869 'ug_user = rev_user',
870 'ug_group' => $groupsWithBotPermission
875 $uid = User
::idFromName( $this->target
);
877 $condition['rev_user'] = $uid;
878 $index = 'user_timestamp';
880 $condition['rev_user_text'] = $this->target
;
881 $index = 'usertext_timestamp';
885 if ( $this->deletedOnly
) {
886 $condition[] = 'rev_deleted != 0';
889 if ( $this->topOnly
) {
890 $condition[] = 'rev_id = page_latest';
893 if ( $this->newOnly
) {
894 $condition[] = 'rev_parent_id = 0';
897 return array( $tables, $index, $condition, $join_conds );
900 function getNamespaceCond() {
901 if ( $this->namespace !== '' ) {
902 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
903 $eq_op = $this->nsInvert ?
'!=' : '=';
904 $bool_op = $this->nsInvert ?
'AND' : 'OR';
906 if ( !$this->associated
) {
907 return array( "page_namespace $eq_op $selectedNS" );
910 $associatedNS = $this->mDb
->addQuotes(
911 MWNamespace
::getAssociated( $this->namespace )
915 "page_namespace $eq_op $selectedNS " .
917 " page_namespace $eq_op $associatedNS"
924 function getIndexField() {
925 return 'rev_timestamp';
928 function doBatchLookups() {
929 # Do a link batch query
930 $this->mResult
->seek( 0 );
932 $batch = new LinkBatch();
933 # Give some pointers to make (last) links
934 foreach ( $this->mResult
as $row ) {
935 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
936 $revIds[] = $row->rev_parent_id
;
938 if ( isset( $row->rev_id
) ) {
939 if ( $this->contribs
=== 'newbie' ) { // multiple users
940 $batch->add( NS_USER
, $row->user_name
);
941 $batch->add( NS_USER_TALK
, $row->user_name
);
943 $batch->add( $row->page_namespace
, $row->page_title
);
946 $this->mParentLens
= Revision
::getParentLengths( $this->mDbSecondary
, $revIds );
948 $this->mResult
->seek( 0 );
954 function getStartBody() {
955 return "<ul class=\"mw-contributions-list\">\n";
961 function getEndBody() {
966 * Generates each row in the contributions list.
968 * Contributions which are marked "top" are currently on top of the history.
969 * For these contributions, a [rollback] link is shown for users with roll-
970 * back privileges. The rollback link restores the most recent version that
971 * was not written by the target user.
973 * @todo This would probably look a lot nicer in a table.
977 function formatRow( $row ) {
983 * There may be more than just revision rows. To make sure that we'll only be processing
984 * revisions here, let's _try_ to build a revision out of our row (without displaying
985 * notices though) and then trying to grab data from the built object. If we succeed,
986 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
987 * to extensions to subscribe to the hook to parse the row.
989 MediaWiki\
suppressWarnings();
991 $rev = new Revision( $row );
992 $validRevision = (bool)$rev->getId();
993 } catch ( Exception
$e ) {
994 $validRevision = false;
996 MediaWiki\restoreWarnings
();
998 if ( $validRevision ) {
1001 $page = Title
::newFromRow( $row );
1002 $link = Linker
::link(
1004 htmlspecialchars( $page->getPrefixedText() ),
1005 array( 'class' => 'mw-contributions-title' ),
1006 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
1008 # Mark current revisions
1010 $user = $this->getUser();
1011 if ( $row->rev_id
== $row->page_latest
) {
1012 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
1014 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
1015 && $page->quickUserCan( 'edit', $user )
1017 $this->preventClickjacking();
1018 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
1021 # Is there a visible previous revision?
1022 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
1023 $difftext = Linker
::linkKnown(
1025 $this->messages
['diff'],
1029 'oldid' => $row->rev_id
1033 $difftext = $this->messages
['diff'];
1035 $histlink = Linker
::linkKnown(
1037 $this->messages
['hist'],
1039 array( 'action' => 'history' )
1042 if ( $row->rev_parent_id
=== null ) {
1043 // For some reason rev_parent_id isn't populated for this row.
1044 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
1045 // Next best thing is to have the total number of bytes.
1046 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1047 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
1048 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1051 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
1052 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
1055 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
1056 $chardiff .= ChangesList
::showCharacterDifference(
1061 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
1064 $lang = $this->getLanguage();
1065 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
1066 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
1067 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1068 $d = Linker
::linkKnown(
1070 htmlspecialchars( $date ),
1071 array( 'class' => 'mw-changeslist-date' ),
1072 array( 'oldid' => intval( $row->rev_id
) )
1075 $d = htmlspecialchars( $date );
1077 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
1078 $d = '<span class="history-deleted">' . $d . '</span>';
1081 # Show user names for /newbies as there may be different users.
1082 # Note that we already excluded rows with hidden user names.
1083 if ( $this->contribs
== 'newbie' ) {
1084 $userlink = ' . . ' . $lang->getDirMark()
1085 . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
1086 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
1087 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
1092 if ( $rev->getParentId() === 0 ) {
1093 $nflag = ChangesList
::flag( 'newpage' );
1098 if ( $rev->isMinor() ) {
1099 $mflag = ChangesList
::flag( 'minor' );
1104 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1105 if ( $del !== '' ) {
1109 $diffHistLinks = $this->msg( 'parentheses' )
1110 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1112 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1113 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1115 # Denote if username is redacted for this edit
1116 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1117 $ret .= " <strong>" .
1118 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1123 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1127 $classes = array_merge( $classes, $newClasses );
1128 $ret .= " $tagSummary";
1131 // Let extensions add data
1132 Hooks
::run( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1134 if ( $classes === array() && $ret === '' ) {
1135 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
1136 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1138 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1145 * Overwrite Pager function and return a helpful comment
1148 function getSqlComment() {
1149 if ( $this->namespace ||
$this->deletedOnly
) {
1150 // potentially slow, see CR r58153
1151 return 'contributions page filtered for namespace or RevisionDeleted edits';
1153 return 'contributions page unfiltered';
1157 protected function preventClickjacking() {
1158 $this->preventClickjacking
= true;
1164 public function getPreventClickjacking() {
1165 return $this->preventClickjacking
;