3 * Implements Special:Contributions
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Special:Contributions, show user contributions in a paged list
27 * @ingroup SpecialPage
30 class SpecialContributions
extends SpecialPage
{
33 public function __construct() {
34 parent
::__construct( 'Contributions' );
37 public function execute( $par ) {
39 $this->outputHeader();
40 $out = $this->getOutput();
41 $out->addModuleStyles( 'mediawiki.special' );
43 $this->opts
= array();
44 $request = $this->getRequest();
46 if ( $par !== null ) {
49 $target = $request->getVal( 'target' );
53 if ( $request->getVal( 'contribs' ) == 'newbie' ) {
55 $this->opts
['contribs'] = 'newbie';
56 } elseif ( $par === 'newbies' ) { // b/c for WMF
58 $this->opts
['contribs'] = 'newbie';
60 $this->opts
['contribs'] = 'user';
63 $this->opts
['deletedOnly'] = $request->getBool( 'deletedOnly' );
65 if ( !strlen( $target ) ) {
66 $out->addHTML( $this->getForm() );
71 $user = $this->getUser();
73 $this->opts
['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
74 $this->opts
['target'] = $target;
75 $this->opts
['topOnly'] = $request->getBool( 'topOnly' );
77 $nt = Title
::makeTitleSafe( NS_USER
, $target );
79 $out->addHTML( $this->getForm() );
83 $userObj = User
::newFromName( $nt->getText(), false );
85 $out->addHTML( $this->getForm() );
89 $id = $userObj->getID();
91 if ( $this->opts
['contribs'] != 'newbie' ) {
92 $target = $nt->getText();
93 $out->addSubtitle( $this->contributionsSub( $userObj ) );
94 $out->setHTMLTitle( $this->msg(
96 $this->msg( 'contributions-title', $target )->plain()
98 $this->getSkin()->setRelevantUser( $userObj );
100 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
101 $out->setHTMLTitle( $this->msg(
103 $this->msg( 'sp-contributions-newbies-title' )->plain()
107 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
108 $this->opts
['namespace'] = intval( $ns );
110 $this->opts
['namespace'] = '';
113 $this->opts
['associated'] = $request->getBool( 'associated' );
114 $this->opts
['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
115 $this->opts
['tagfilter'] = (string)$request->getVal( 'tagfilter' );
117 // Allows reverts to have the bot flag in recent changes. It is just here to
118 // be passed in the form at the top of the page
119 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
120 $this->opts
['bot'] = '1';
123 $skip = $request->getText( 'offset' ) ||
$request->getText( 'dir' ) == 'prev';
124 # Offset overrides year/month selection
126 $this->opts
['year'] = '';
127 $this->opts
['month'] = '';
129 $this->opts
['year'] = $request->getIntOrNull( 'year' );
130 $this->opts
['month'] = $request->getIntOrNull( 'month' );
133 $feedType = $request->getVal( 'feed' );
135 // Maintain some level of backwards compatability
136 // If people request feeds using the old parameters, redirect to API
138 'action' => 'feedcontributions',
139 'feedformat' => $feedType,
142 if ( $this->opts
['topOnly'] ) {
143 $apiParams['toponly'] = true;
145 if ( $this->opts
['deletedOnly'] ) {
146 $apiParams['deletedonly'] = true;
148 if ( $this->opts
['tagfilter'] !== '' ) {
149 $apiParams['tagfilter'] = $this->opts
['tagfilter'];
151 if ( $this->opts
['namespace'] !== '' ) {
152 $apiParams['namespace'] = $this->opts
['namespace'];
154 if ( $this->opts
['year'] !== null ) {
155 $apiParams['year'] = $this->opts
['year'];
157 if ( $this->opts
['month'] !== null ) {
158 $apiParams['month'] = $this->opts
['month'];
161 $url = wfAppendQuery( wfScript( 'api' ), $apiParams );
163 $out->redirect( $url, '301' );
168 // Add RSS/atom links
169 $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) );
171 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
172 $out->addHTML( $this->getForm() );
174 $pager = new ContribsPager( $this->getContext(), array(
176 'contribs' => $this->opts
['contribs'],
177 'namespace' => $this->opts
['namespace'],
178 'tagfilter' => $this->opts
['tagfilter'],
179 'year' => $this->opts
['year'],
180 'month' => $this->opts
['month'],
181 'deletedOnly' => $this->opts
['deletedOnly'],
182 'topOnly' => $this->opts
['topOnly'],
183 'nsInvert' => $this->opts
['nsInvert'],
184 'associated' => $this->opts
['associated'],
187 if ( !$pager->getNumRows() ) {
188 $out->addWikiMsg( 'nocontribs', $target );
190 # Show a message about slave lag, if applicable
191 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
193 $out->showLagWarning( $lag );
197 '<p>' . $pager->getNavigationBar() . '</p>' .
199 '<p>' . $pager->getNavigationBar() . '</p>'
202 $out->preventClickjacking( $pager->getPreventClickjacking() );
204 # Show the appropriate "footer" message - WHOIS tools, etc.
205 if ( $this->opts
['contribs'] == 'newbie' ) {
206 $message = 'sp-contributions-footer-newbies';
207 } elseif ( IP
::isIPAddress( $target ) ) {
208 $message = 'sp-contributions-footer-anon';
209 } elseif ( $userObj->isAnon() ) {
210 // No message for non-existing users
213 $message = 'sp-contributions-footer';
217 if ( !$this->msg( $message, $target )->isDisabled() ) {
219 "<div class='mw-contributions-footer'>\n$1\n</div>",
220 array( $message, $target ) );
227 * Generates the subheading with links
228 * @param $userObj User object for the target
229 * @return String: appropriately-escaped HTML to be output literally
230 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
233 protected function contributionsSub( $userObj ) {
234 if ( $userObj->isAnon() ) {
235 $user = htmlspecialchars( $userObj->getName() );
237 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
239 $nt = $userObj->getUserPage();
240 $talk = $userObj->getTalkPage();
243 $tools = $this->getUserLinks( $nt, $talk, $userObj );
244 $links = $this->getLanguage()->pipeList( $tools );
246 // Show a note if the user is blocked and display the last block log entry.
247 // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
248 // and also this will display a totally irrelevant log entry as a current block.
249 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() != Block
::TYPE_AUTO
) {
250 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
251 LogEventsList
::showLogExtract(
258 'showIfEmpty' => false,
261 'sp-contributions-blocked-notice-anon' :
262 'sp-contributions-blocked-notice',
263 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
265 'offset' => '' # don't use WebRequest parameter offset
271 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
275 * Links to different places.
276 * @param $userpage Title: Target user page
277 * @param $talkpage Title: Talk page
278 * @param $target User: Target user object
281 public function getUserLinks( Title
$userpage, Title
$talkpage, User
$target ) {
283 $id = $target->getId();
284 $username = $target->getName();
286 $tools[] = Linker
::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
288 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $username ) ) ) {
289 if ( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
290 if ( $target->isBlocked() && $target->getBlock()->getType() != Block
::TYPE_AUTO
) {
291 $tools[] = Linker
::linkKnown( # Change block link
292 SpecialPage
::getTitleFor( 'Block', $username ),
293 $this->msg( 'change-blocklink' )->escaped()
295 $tools[] = Linker
::linkKnown( # Unblock link
296 SpecialPage
::getTitleFor( 'Unblock', $username ),
297 $this->msg( 'unblocklink' )->escaped()
299 } else { # User is not blocked
300 $tools[] = Linker
::linkKnown( # Block link
301 SpecialPage
::getTitleFor( 'Block', $username ),
302 $this->msg( 'blocklink' )->escaped()
308 $tools[] = Linker
::linkKnown(
309 SpecialPage
::getTitleFor( 'Log', 'block' ),
310 $this->msg( 'sp-contributions-blocklog' )->escaped(),
312 array( 'page' => $userpage->getPrefixedText() )
316 $tools[] = Linker
::linkKnown(
317 SpecialPage
::getTitleFor( 'Listfiles', $username ),
318 $this->msg( 'sp-contributions-uploads' )->escaped()
322 $tools[] = Linker
::linkKnown(
323 SpecialPage
::getTitleFor( 'Log', $username ),
324 $this->msg( 'sp-contributions-logs' )->escaped()
327 # Add link to deleted user contributions for priviledged users
328 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
329 $tools[] = Linker
::linkKnown(
330 SpecialPage
::getTitleFor( 'DeletedContributions', $username ),
331 $this->msg( 'sp-contributions-deleted' )->escaped()
335 # Add a link to change user rights for privileged users
336 $userrightsPage = new UserrightsPage();
337 $userrightsPage->setContext( $this->getContext() );
338 if ( $userrightsPage->userCanChangeRights( $target ) ) {
339 $tools[] = Linker
::linkKnown(
340 SpecialPage
::getTitleFor( 'Userrights', $username ),
341 $this->msg( 'sp-contributions-userrights' )->escaped()
345 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
351 * Generates the namespace selector form with hidden attributes.
352 * @return String: HTML fragment
354 protected function getForm() {
357 $this->opts
['title'] = $this->getTitle()->getPrefixedText();
358 if ( !isset( $this->opts
['target'] ) ) {
359 $this->opts
['target'] = '';
361 $this->opts
['target'] = str_replace( '_', ' ', $this->opts
['target'] );
364 if ( !isset( $this->opts
['namespace'] ) ) {
365 $this->opts
['namespace'] = '';
368 if ( !isset( $this->opts
['nsInvert'] ) ) {
369 $this->opts
['nsInvert'] = '';
372 if ( !isset( $this->opts
['associated'] ) ) {
373 $this->opts
['associated'] = false;
376 if ( !isset( $this->opts
['contribs'] ) ) {
377 $this->opts
['contribs'] = 'user';
380 if ( !isset( $this->opts
['year'] ) ) {
381 $this->opts
['year'] = '';
384 if ( !isset( $this->opts
['month'] ) ) {
385 $this->opts
['month'] = '';
388 if ( $this->opts
['contribs'] == 'newbie' ) {
389 $this->opts
['target'] = '';
392 if ( !isset( $this->opts
['tagfilter'] ) ) {
393 $this->opts
['tagfilter'] = '';
396 if ( !isset( $this->opts
['topOnly'] ) ) {
397 $this->opts
['topOnly'] = false;
400 $form = Html
::openElement(
404 'action' => $wgScript,
405 'class' => 'mw-contributions-form'
409 # Add hidden params for tracking except for parameters in $skipParameters
410 $skipParameters = array(
422 foreach ( $this->opts
as $name => $value ) {
423 if ( in_array( $name, $skipParameters ) ) {
426 $form .= "\t" . Html
::hidden( $name, $value ) . "\n";
429 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
432 $filterSelection = Html
::rawElement(
434 array( 'class' => 'mw-label' ),
435 array_shift( $tagFilter )
437 $filterSelection .= Html
::rawElement(
439 array( 'class' => 'mw-input' ),
440 implode( ' ', $tagFilter )
443 $filterSelection = Html
::rawElement( 'td', array( 'colspan' => 2 ), '' );
446 $labelNewbies = Xml
::radioLabel(
447 $this->msg( 'sp-contributions-newbies' )->text(),
451 $this->opts
['contribs'] == 'newbie',
452 array( 'class' => 'mw-input' )
454 $labelUsername = Xml
::radioLabel(
455 $this->msg( 'sp-contributions-username' )->text(),
459 $this->opts
['contribs'] == 'user',
460 array( 'class' => 'mw-input' )
462 $input = Html
::input(
464 $this->opts
['target'],
466 array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) +
467 ( $this->opts
['target'] ?
array() : array( 'autofocus' )
470 $targetSelection = Html
::rawElement(
472 array( 'colspan' => 2 ),
473 $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '
476 $namespaceSelection = Xml
::tags(
478 array( 'class' => 'mw-label' ),
480 $this->msg( 'namespace' )->text(),
485 $namespaceSelection .= Html
::rawElement(
488 Html
::namespaceSelector(
489 array( 'selected' => $this->opts
['namespace'], 'all' => '' ),
491 'name' => 'namespace',
493 'class' => 'namespaceselector',
498 array( 'style' => 'white-space: nowrap' ),
500 $this->msg( 'invert' )->text(),
503 $this->opts
['nsInvert'],
505 'title' => $this->msg( 'tooltip-invert' )->text(),
506 'class' => 'mw-input'
510 Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
512 $this->msg( 'namespace_association' )->text(),
515 $this->opts
['associated'],
517 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
518 'class' => 'mw-input'
524 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
525 $deletedOnlyCheck = Html
::rawElement(
527 array( 'style' => 'white-space: nowrap' ),
529 $this->msg( 'history-show-deleted' )->text(),
531 'mw-show-deleted-only',
532 $this->opts
['deletedOnly'],
533 array( 'class' => 'mw-input' )
537 $deletedOnlyCheck = '';
540 $checkLabelTopOnly = Html
::rawElement(
542 array( 'style' => 'white-space: nowrap' ),
544 $this->msg( 'sp-contributions-toponly' )->text(),
547 $this->opts
['topOnly'],
548 array( 'class' => 'mw-input' )
551 $extraOptions = Html
::rawElement(
553 array( 'colspan' => 2 ),
554 $deletedOnlyCheck . $checkLabelTopOnly
557 $dateSelectionAndSubmit = Xml
::tags( 'td', array( 'colspan' => 2 ),
559 $this->opts
['year'] === '' ? MWTimestamp
::getInstance()->format( 'Y' ) : $this->opts
['year'],
563 $this->msg( 'sp-contributions-submit' )->text(),
564 array( 'class' => 'mw-submit' )
568 $form .= Xml
::fieldset( $this->msg( 'sp-contributions-search' )->text() );
569 $form .= Html
::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" .
570 Html
::rawElement( 'tr', array(), $targetSelection ) . "\n" .
571 Html
::rawElement( 'tr', array(), $namespaceSelection ) . "\n" .
572 Html
::rawElement( 'tr', array(), $filterSelection ) . "\n" .
573 Html
::rawElement( 'tr', array(), $extraOptions ) . "\n" .
574 Html
::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n"
577 $explain = $this->msg( 'sp-contributions-explain' );
578 if ( !$explain->isBlank() ) {
579 $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
582 $form .= Xml
::closeElement( 'fieldset' ) . Xml
::closeElement( 'form' );
587 protected function getGroupName() {
593 * Pager for Special:Contributions
594 * @ingroup SpecialPage Pager
596 class ContribsPager
extends ReverseChronologicalPager
{
597 public $mDefaultDirection = true;
600 public $namespace = '';
602 public $preventClickjacking = false;
607 protected $mParentLens;
609 function __construct( IContextSource
$context, array $options ) {
610 parent
::__construct( $context );
622 foreach ( $msgs as $msg ) {
623 $this->messages
[$msg] = $this->msg( $msg )->escaped();
626 $this->target
= isset( $options['target'] ) ?
$options['target'] : '';
627 $this->contribs
= isset( $options['contribs'] ) ?
$options['contribs'] : 'users';
628 $this->namespace = isset( $options['namespace'] ) ?
$options['namespace'] : '';
629 $this->tagFilter
= isset( $options['tagfilter'] ) ?
$options['tagfilter'] : false;
630 $this->nsInvert
= isset( $options['nsInvert'] ) ?
$options['nsInvert'] : false;
631 $this->associated
= isset( $options['associated'] ) ?
$options['associated'] : false;
633 $this->deletedOnly
= !empty( $options['deletedOnly'] );
634 $this->topOnly
= !empty( $options['topOnly'] );
636 $year = isset( $options['year'] ) ?
$options['year'] : false;
637 $month = isset( $options['month'] ) ?
$options['month'] : false;
638 $this->getDateCond( $year, $month );
640 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
643 function getDefaultQuery() {
644 $query = parent
::getDefaultQuery();
645 $query['target'] = $this->target
;
651 * This method basically executes the exact same code as the parent class, though with
652 * a hook added, to allow extentions to add additional queries.
654 * @param string $offset index offset, inclusive
655 * @param $limit Integer: exact query limit
656 * @param $descending Boolean: query direction, false for ascending, true for descending
657 * @return ResultWrapper
659 function reallyDoQuery( $offset, $limit, $descending ) {
660 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
668 * This hook will allow extensions to add in additional queries, so they can get their data
669 * in My Contributions as well. Extensions should append their results to the $data array.
671 * Extension queries have to implement the navbar requirement as well. They should
672 * - have a column aliased as $pager->getIndexField()
674 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
675 * - have the ORDER BY specified based upon the details provided by the navbar
677 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
679 * &$data: an array of results of all contribs queries
680 * $pager: the ContribsPager object hooked into
681 * $offset: see phpdoc above
682 * $limit: see phpdoc above
683 * $descending: see phpdoc above
685 $data = array( $this->mDb
->select(
686 $tables, $fields, $conds, $fname, $options, $join_conds
689 'ContribsPager::reallyDoQuery',
690 array( &$data, $pager, $offset, $limit, $descending )
695 // loop all results and collect them in an array
696 foreach ( $data as $query ) {
697 foreach ( $query as $i => $row ) {
698 // use index column as key, allowing us to easily sort in PHP
699 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
711 $result = array_slice( $result, 0, $limit );
713 // get rid of array keys
714 $result = array_values( $result );
716 return new FakeResultWrapper( $result );
719 function getQueryInfo() {
720 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
722 $user = $this->getUser();
723 $conds = array_merge( $userCond, $this->getNamespaceCond() );
725 // Paranoia: avoid brute force searches (bug 17342)
726 if ( !$user->isAllowed( 'deletedhistory' ) ) {
727 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0';
728 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
729 $conds[] = $this->mDb
->bitAnd( 'rev_deleted', Revision
::SUPPRESSED_USER
) .
730 ' != ' . Revision
::SUPPRESSED_USER
;
733 # Don't include orphaned revisions
734 $join_cond['page'] = Revision
::pageJoinCond();
735 # Get the current user name for accounts
736 $join_cond['user'] = Revision
::userJoinCond();
740 'fields' => array_merge(
741 Revision
::selectFields(),
742 Revision
::selectUserFields(),
743 array( 'page_namespace', 'page_title', 'page_is_new',
744 'page_latest', 'page_is_redirect', 'page_len' )
747 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
748 'join_conds' => $join_cond
751 ChangeTags
::modifyDisplayQuery(
752 $queryInfo['tables'],
753 $queryInfo['fields'],
755 $queryInfo['join_conds'],
756 $queryInfo['options'],
760 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
765 function getUserCond() {
766 $condition = array();
767 $join_conds = array();
768 $tables = array( 'revision', 'page', 'user' );
769 if ( $this->contribs
== 'newbie' ) {
770 $max = $this->mDb
->selectField( 'user', 'max(user_id)', false, __METHOD__
);
771 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
772 $index = 'user_timestamp';
773 # ignore local groups with the bot right
774 # @todo FIXME: Global groups may have 'bot' rights
775 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
776 if ( count( $groupsWithBotPermission ) ) {
777 $tables[] = 'user_groups';
778 $condition[] = 'ug_group IS NULL';
779 $join_conds['user_groups'] = array(
781 'ug_user = rev_user',
782 'ug_group' => $groupsWithBotPermission
787 $uid = User
::idFromName( $this->target
);
789 $condition['rev_user'] = $uid;
790 $index = 'user_timestamp';
792 $condition['rev_user_text'] = $this->target
;
793 $index = 'usertext_timestamp';
797 if ( $this->deletedOnly
) {
798 $condition[] = 'rev_deleted != 0';
801 if ( $this->topOnly
) {
802 $condition[] = 'rev_id = page_latest';
805 return array( $tables, $index, $condition, $join_conds );
808 function getNamespaceCond() {
809 if ( $this->namespace !== '' ) {
810 $selectedNS = $this->mDb
->addQuotes( $this->namespace );
811 $eq_op = $this->nsInvert ?
'!=' : '=';
812 $bool_op = $this->nsInvert ?
'AND' : 'OR';
814 if ( !$this->associated
) {
815 return array( "page_namespace $eq_op $selectedNS" );
818 $associatedNS = $this->mDb
->addQuotes(
819 MWNamespace
::getAssociated( $this->namespace )
823 "page_namespace $eq_op $selectedNS " .
825 " page_namespace $eq_op $associatedNS"
832 function getIndexField() {
833 return 'rev_timestamp';
836 function doBatchLookups() {
837 # Do a link batch query
838 $this->mResult
->seek( 0 );
840 $batch = new LinkBatch();
841 # Give some pointers to make (last) links
842 foreach ( $this->mResult
as $row ) {
843 if ( isset( $row->rev_parent_id
) && $row->rev_parent_id
) {
844 $revIds[] = $row->rev_parent_id
;
846 if ( isset( $row->rev_id
) ) {
847 if ( $this->contribs
=== 'newbie' ) { // multiple users
848 $batch->add( NS_USER
, $row->user_name
);
849 $batch->add( NS_USER_TALK
, $row->user_name
);
851 $batch->add( $row->page_namespace
, $row->page_title
);
854 $this->mParentLens
= Revision
::getParentLengths( $this->getDatabase(), $revIds );
856 $this->mResult
->seek( 0 );
862 function getStartBody() {
869 function getEndBody() {
874 * Generates each row in the contributions list.
876 * Contributions which are marked "top" are currently on top of the history.
877 * For these contributions, a [rollback] link is shown for users with roll-
878 * back privileges. The rollback link restores the most recent version that
879 * was not written by the target user.
881 * @todo This would probably look a lot nicer in a table.
885 function formatRow( $row ) {
886 wfProfileIn( __METHOD__
);
892 * There may be more than just revision rows. To make sure that we'll only be processing
893 * revisions here, let's _try_ to build a revision out of our row (without displaying
894 * notices though) and then trying to grab data from the built object. If we succeed,
895 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
896 * to extensions to subscribe to the hook to parse the row.
898 wfSuppressWarnings();
899 $rev = new Revision( $row );
900 $validRevision = (bool)$rev->getId();
903 if ( $validRevision ) {
906 $page = Title
::newFromRow( $row );
907 $link = Linker
::link(
909 htmlspecialchars( $page->getPrefixedText() ),
910 array( 'class' => 'mw-contributions-title' ),
911 $page->isRedirect() ?
array( 'redirect' => 'no' ) : array()
913 # Mark current revisions
915 $user = $this->getUser();
916 if ( $row->rev_id
== $row->page_latest
) {
917 $topmarktext .= '<span class="mw-uctop">' . $this->messages
['uctop'] . '</span>';
919 if ( !$row->page_is_new
&& $page->quickUserCan( 'rollback', $user )
920 && $page->quickUserCan( 'edit', $user )
922 $this->preventClickjacking();
923 $topmarktext .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
926 # Is there a visible previous revision?
927 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) && $rev->getParentId() !== 0 ) {
928 $difftext = Linker
::linkKnown(
930 $this->messages
['diff'],
934 'oldid' => $row->rev_id
938 $difftext = $this->messages
['diff'];
940 $histlink = Linker
::linkKnown(
942 $this->messages
['hist'],
944 array( 'action' => 'history' )
947 if ( $row->rev_parent_id
=== null ) {
948 // For some reason rev_parent_id isn't populated for this row.
949 // Its rumoured this is true on wikipedia for some revisions (bug 34922).
950 // Next best thing is to have the total number of bytes.
951 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
952 $chardiff .= Linker
::formatRevisionSize( $row->rev_len
);
953 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
956 if ( isset( $this->mParentLens
[$row->rev_parent_id
] ) ) {
957 $parentLen = $this->mParentLens
[$row->rev_parent_id
];
960 $chardiff = ' <span class="mw-changeslist-separator">. .</span> ';
961 $chardiff .= ChangesList
::showCharacterDifference(
966 $chardiff .= ' <span class="mw-changeslist-separator">. .</span> ';
969 $lang = $this->getLanguage();
970 $comment = $lang->getDirMark() . Linker
::revComment( $rev, false, true );
971 $date = $lang->userTimeAndDate( $row->rev_timestamp
, $user );
972 if ( $rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
973 $d = Linker
::linkKnown(
975 htmlspecialchars( $date ),
976 array( 'class' => 'mw-changeslist-date' ),
977 array( 'oldid' => intval( $row->rev_id
) )
980 $d = htmlspecialchars( $date );
982 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
983 $d = '<span class="history-deleted">' . $d . '</span>';
986 # Show user names for /newbies as there may be different users.
987 # Note that we already excluded rows with hidden user names.
988 if ( $this->contribs
== 'newbie' ) {
989 $userlink = ' . . ' . $lang->getDirMark() . Linker
::userLink( $rev->getUser(), $rev->getUserText() );
990 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
991 Linker
::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
996 if ( $rev->getParentId() === 0 ) {
997 $nflag = ChangesList
::flag( 'newpage' );
1002 if ( $rev->isMinor() ) {
1003 $mflag = ChangesList
::flag( 'minor' );
1008 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
1009 if ( $del !== '' ) {
1013 $diffHistLinks = $this->msg( 'parentheses' )
1014 ->rawParams( $difftext . $this->messages
['pipe-separator'] . $histlink )
1016 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
1017 $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
1019 # Denote if username is redacted for this edit
1020 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1021 $ret .= " <strong>" .
1022 $this->msg( 'rev-deleted-user-contribs' )->escaped() .
1027 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
1031 $classes = array_merge( $classes, $newClasses );
1032 $ret .= " $tagSummary";
1035 // Let extensions add data
1036 wfRunHooks( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) );
1038 if ( $classes === array() && $ret === '' ) {
1039 wfDebug( 'Dropping Special:Contribution row that could not be formatted' );
1040 $ret = "<!-- Could not format Special:Contribution row. -->\n";
1042 $ret = Html
::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
1045 wfProfileOut( __METHOD__
);
1051 * Overwrite Pager function and return a helpful comment
1054 function getSqlComment() {
1055 if ( $this->namespace ||
$this->deletedOnly
) {
1056 // potentially slow, see CR r58153
1057 return 'contributions page filtered for namespace or RevisionDeleted edits';
1059 return 'contributions page unfiltered';
1063 protected function preventClickjacking() {
1064 $this->preventClickjacking
= true;
1070 public function getPreventClickjacking() {
1071 return $this->preventClickjacking
;