(bug 24037) Add byte length of revision to Special:Contributions. Patch by Umherirrender
[lhc/web/wiklou.git] / includes / specials / SpecialContributions.php
1 <?php
2 /**
3 * Implements Special:Contributions
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * Special:Contributions, show user contributions in a paged list
26 *
27 * @ingroup SpecialPage
28 */
29
30 class SpecialContributions extends SpecialPage {
31
32 protected $opts;
33
34 public function __construct() {
35 parent::__construct( 'Contributions' );
36 }
37
38 public function execute( $par ) {
39 $this->setHeaders();
40 $this->outputHeader();
41 $out = $this->getOutput();
42 $out->addModuleStyles( 'mediawiki.special' );
43
44 $this->opts = array();
45 $request = $this->getRequest();
46
47 if( $par == 'newbies' ) {
48 $target = 'newbies';
49 $this->opts['contribs'] = 'newbie';
50 } elseif( $par !== null ) {
51 $target = $par;
52 } else {
53 $target = $request->getVal( 'target' );
54 }
55
56 // check for radiobox
57 if( $request->getVal( 'contribs' ) == 'newbie' ) {
58 $target = 'newbies';
59 $this->opts['contribs'] = 'newbie';
60 } else {
61 $this->opts['contribs'] = 'user';
62 }
63
64 $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
65
66 if( !strlen( $target ) ) {
67 $out->addHTML( $this->getForm() );
68 return;
69 }
70
71 $user = $this->getUser();
72
73 $this->opts['limit'] = $request->getInt( 'limit', $user->getOption('rclimit') );
74 $this->opts['target'] = $target;
75 $this->opts['topOnly'] = $request->getBool( 'topOnly' );
76
77 $userObj = User::newFromName( $target, false );
78 if( !$userObj ) {
79 $out->addHTML( $this->getForm() );
80 return;
81 }
82 $nt = $userObj->getUserPage();
83 $id = $userObj->getID();
84
85 if( $this->opts['contribs'] != 'newbie' ) {
86 $target = $nt->getText();
87 $out->addSubtitle( $this->contributionsSub( $userObj ) );
88 $out->setHTMLTitle( $this->msg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ), $target ) ) );
89 $this->getSkin()->setRelevantUser( $userObj );
90 } else {
91 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub') );
92 $out->setHTMLTitle( $this->msg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) );
93 }
94
95 if( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
96 $this->opts['namespace'] = intval( $ns );
97 } else {
98 $this->opts['namespace'] = '';
99 }
100
101 $this->opts['nsInvert'] = (bool) $request->getVal( 'nsInvert' );
102
103 $this->opts['tagfilter'] = (string) $request->getVal( 'tagfilter' );
104
105 // Allows reverts to have the bot flag in recent changes. It is just here to
106 // be passed in the form at the top of the page
107 if( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
108 $this->opts['bot'] = '1';
109 }
110
111 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
112 # Offset overrides year/month selection
113 if( $skip ) {
114 $this->opts['year'] = '';
115 $this->opts['month'] = '';
116 } else {
117 $this->opts['year'] = $request->getIntOrNull( 'year' );
118 $this->opts['month'] = $request->getIntOrNull( 'month' );
119 }
120
121 $feedType = $request->getVal( 'feed' );
122 if( $feedType ) {
123 // Maintain some level of backwards compatability
124 // If people request feeds using the old parameters, redirect to API
125 $apiParams = array(
126 'action' => 'feedcontributions',
127 'feedformat' => $feedType,
128 'user' => $target,
129 );
130 if ( $this->opts['topOnly'] ) {
131 $apiParams['toponly'] = true;
132 }
133 if ( $this->opts['deletedOnly'] ) {
134 $apiParams['deletedonly'] = true;
135 }
136 if ( $this->opts['tagfilter'] !== '' ) {
137 $apiParams['tagfilter'] = $this->opts['tagfilter'];
138 }
139 if ( $this->opts['namespace'] !== '' ) {
140 $apiParams['namespace'] = $this->opts['namespace'];
141 }
142 if ( $this->opts['year'] !== null ) {
143 $apiParams['year'] = $this->opts['year'];
144 }
145 if ( $this->opts['month'] !== null ) {
146 $apiParams['month'] = $this->opts['month'];
147 }
148
149 $url = wfScript( 'api' ) . '?' . wfArrayToCGI( $apiParams );
150
151 $out->redirect( $url, '301' );
152 return;
153 }
154
155 // Add RSS/atom links
156 $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) );
157
158 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
159
160 $out->addHTML( $this->getForm() );
161
162 $pager = new ContribsPager( array(
163 'target' => $target,
164 'contribs' => $this->opts['contribs'],
165 'namespace' => $this->opts['namespace'],
166 'year' => $this->opts['year'],
167 'month' => $this->opts['month'],
168 'deletedOnly' => $this->opts['deletedOnly'],
169 'topOnly' => $this->opts['topOnly'],
170 'nsInvert' => $this->opts['nsInvert'],
171 ) );
172 if( !$pager->getNumRows() ) {
173 $out->addWikiMsg( 'nocontribs', $target );
174 } else {
175 # Show a message about slave lag, if applicable
176 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
177 if( $lag > 0 )
178 $out->showLagWarning( $lag );
179
180 $out->addHTML(
181 '<p>' . $pager->getNavigationBar() . '</p>' .
182 $pager->getBody() .
183 '<p>' . $pager->getNavigationBar() . '</p>'
184 );
185 }
186 $out->preventClickjacking( $pager->getPreventClickjacking() );
187
188 # Show the appropriate "footer" message - WHOIS tools, etc.
189 if( $this->opts['contribs'] != 'newbie' ) {
190 $message = 'sp-contributions-footer';
191 if ( IP::isIPAddress( $target ) ) {
192 $message = 'sp-contributions-footer-anon';
193 } else {
194 if ( $userObj->isAnon() ) {
195 // No message for non-existing users
196 return;
197 }
198 }
199
200 if( !wfMessage( $message, $target )->isDisabled() ) {
201 $out->wrapWikiMsg(
202 "<div class='mw-contributions-footer'>\n$1\n</div>",
203 array( $message, $target ) );
204 }
205 }
206 }
207 }
208
209 /**
210 * Generates the subheading with links
211 * @param $userObj User object for the target
212 * @return String: appropriately-escaped HTML to be output literally
213 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
214 */
215 protected function contributionsSub( $userObj ) {
216 if ( $userObj->isAnon() ) {
217 $user = htmlspecialchars( $userObj->getName() );
218 } else {
219 $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
220 }
221 $nt = $userObj->getUserPage();
222 $talk = $userObj->getTalkPage();
223 if( $talk ) {
224 $tools = self::getUserLinks( $nt, $talk, $userObj, $this->getUser() );
225 $links = $this->getLang()->pipeList( $tools );
226
227 // Show a note if the user is blocked and display the last block log entry.
228 if ( $userObj->isBlocked() ) {
229 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
230 LogEventsList::showLogExtract(
231 $out,
232 'block',
233 $nt,
234 '',
235 array(
236 'lim' => 1,
237 'showIfEmpty' => false,
238 'msgKey' => array(
239 $userObj->isAnon() ?
240 'sp-contributions-blocked-notice-anon' :
241 'sp-contributions-blocked-notice',
242 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
243 ),
244 'offset' => '' # don't use WebRequest parameter offset
245 )
246 );
247 }
248 }
249
250 // Old message 'contribsub' had one parameter, but that doesn't work for
251 // languages that want to put the "for" bit right after $user but before
252 // $links. If 'contribsub' is around, use it for reverse compatibility,
253 // otherwise use 'contribsub2'.
254 $oldMsg = $this->msg( 'contribsub' );
255 if ( $oldMsg->exists() ) {
256 return $oldMsg->rawParams( "$user ($links)" );
257 } else {
258 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
259 }
260 }
261
262 /**
263 * Links to different places.
264 * @param $userpage Title: Target user page
265 * @param $talkpage Title: Talk page
266 * @param $target User: Target user object
267 * @param $subject User: The viewing user ($wgUser might be still checked in some cases)
268 */
269 public static function getUserLinks( Title $userpage, Title $talkpage, User $target, User $subject ) {
270
271 $id = $target->getId();
272 $username = $target->getName();
273
274 $tools[] = Linker::link( $talkpage, wfMsgHtml( 'sp-contributions-talk' ) );
275
276 if( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) {
277 if( $subject->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
278 if ( $target->isBlocked() ) {
279 $tools[] = Linker::linkKnown( # Change block link
280 SpecialPage::getTitleFor( 'Block', $username ),
281 wfMsgHtml( 'change-blocklink' )
282 );
283 $tools[] = Linker::linkKnown( # Unblock link
284 SpecialPage::getTitleFor( 'Unblock', $username ),
285 wfMsgHtml( 'unblocklink' )
286 );
287 } else { # User is not blocked
288 $tools[] = Linker::linkKnown( # Block link
289 SpecialPage::getTitleFor( 'Block', $username ),
290 wfMsgHtml( 'blocklink' )
291 );
292 }
293 }
294 # Block log link
295 $tools[] = Linker::linkKnown(
296 SpecialPage::getTitleFor( 'Log', 'block' ),
297 wfMsgHtml( 'sp-contributions-blocklog' ),
298 array(),
299 array(
300 'page' => $userpage->getPrefixedText()
301 )
302 );
303 }
304 # Uploads
305 $tools[] = Linker::linkKnown(
306 SpecialPage::getTitleFor( 'Listfiles', $username ),
307 wfMsgHtml( 'sp-contributions-uploads' )
308 );
309
310 # Other logs link
311 $tools[] = Linker::linkKnown(
312 SpecialPage::getTitleFor( 'Log', $username ),
313 wfMsgHtml( 'sp-contributions-logs' )
314 );
315
316 # Add link to deleted user contributions for priviledged users
317 if( $subject->isAllowed( 'deletedhistory' ) ) {
318 $tools[] = Linker::linkKnown(
319 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
320 wfMsgHtml( 'sp-contributions-deleted' )
321 );
322 }
323
324 # Add a link to change user rights for privileged users
325 $userrightsPage = new UserrightsPage();
326 $userrightsPage->getContext()->setUser( $subject );
327 if( $id !== null && $userrightsPage->userCanChangeRights( $target ) ) {
328 $tools[] = Linker::linkKnown(
329 SpecialPage::getTitleFor( 'Userrights', $username ),
330 wfMsgHtml( 'sp-contributions-userrights' )
331 );
332 }
333
334 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
335 return $tools;
336 }
337
338 /**
339 * Generates the namespace selector form with hidden attributes.
340 * @return String: HTML fragment
341 */
342 protected function getForm() {
343 global $wgScript;
344
345 $this->opts['title'] = $this->getTitle()->getPrefixedText();
346 if( !isset( $this->opts['target'] ) ) {
347 $this->opts['target'] = '';
348 } else {
349 $this->opts['target'] = str_replace( '_' , ' ' , $this->opts['target'] );
350 }
351
352 if( !isset( $this->opts['namespace'] ) ) {
353 $this->opts['namespace'] = '';
354 }
355
356 if( !isset( $this->opts['nsInvert'] ) ) {
357 $this->opts['nsInvert'] = '';
358 }
359
360 if( !isset( $this->opts['contribs'] ) ) {
361 $this->opts['contribs'] = 'user';
362 }
363
364 if( !isset( $this->opts['year'] ) ) {
365 $this->opts['year'] = '';
366 }
367
368 if( !isset( $this->opts['month'] ) ) {
369 $this->opts['month'] = '';
370 }
371
372 if( $this->opts['contribs'] == 'newbie' ) {
373 $this->opts['target'] = '';
374 }
375
376 if( !isset( $this->opts['tagfilter'] ) ) {
377 $this->opts['tagfilter'] = '';
378 }
379
380 if( !isset( $this->opts['topOnly'] ) ) {
381 $this->opts['topOnly'] = false;
382 }
383
384 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) );
385
386 # Add hidden params for tracking except for parameters in $skipParameters
387 $skipParameters = array( 'namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly' );
388 foreach ( $this->opts as $name => $value ) {
389 if( in_array( $name, $skipParameters ) ) {
390 continue;
391 }
392 $f .= "\t" . Html::hidden( $name, $value ) . "\n";
393 }
394
395 $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] );
396
397 $f .= Xml::fieldset( wfMsg( 'sp-contributions-search' ) ) .
398 Xml::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parsemag' ) ),
399 'contribs', 'newbie' , 'newbie', $this->opts['contribs'] == 'newbie' ) . '<br />' .
400 Xml::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parsemag' ) ),
401 'contribs' , 'user', 'user', $this->opts['contribs'] == 'user' ) . ' ' .
402 Html::input( 'target', $this->opts['target'], 'text', array(
403 'size' => '20',
404 'required' => ''
405 ) + ( $this->opts['target'] ? array() : array( 'autofocus' ) ) ) . ' '.
406 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
407 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
408 Xml::namespaceSelector( $this->opts['namespace'], '' )
409 ) .
410 Xml::checkLabel( wfMsg('invert'), 'nsInvert', 'nsInvert', $this->opts['nsInvert'] ) . '&nbsp;' .
411 Xml::checkLabel( wfMsg( 'history-show-deleted' ),
412 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'] ) . '<br />' .
413 Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'sp-contributions-toponly' ),
414 'topOnly', 'mw-show-top-only', $this->opts['topOnly'] ) ) .
415 ( $tagFilter ? Xml::tags( 'p', null, implode( '&#160;', $tagFilter ) ) : '' ) .
416 Html::rawElement( 'p', array( 'style' => 'white-space: nowrap' ),
417 Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) . ' ' .
418 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) )
419 ) . ' ';
420 $explain = wfMessage( 'sp-contributions-explain' );
421 if ( $explain->exists() ) {
422 $f .= "<p id='mw-sp-contributions-explain'>{$explain}</p>";
423 }
424 $f .= Xml::closeElement('fieldset' ) .
425 Xml::closeElement( 'form' );
426 return $f;
427 }
428 }
429
430 /**
431 * Pager for Special:Contributions
432 * @ingroup SpecialPage Pager
433 */
434 class ContribsPager extends ReverseChronologicalPager {
435 public $mDefaultDirection = true;
436 var $messages, $target;
437 var $namespace = '', $mDb;
438 var $preventClickjacking = false;
439
440 function __construct( $options ) {
441 parent::__construct();
442
443 $msgs = array( 'uctop', 'diff', 'newarticle', 'rollbacklink', 'diff', 'hist', 'rev-delundel', 'pipe-separator' );
444
445 foreach( $msgs as $msg ) {
446 $this->messages[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
447 }
448
449 $this->target = isset( $options['target'] ) ? $options['target'] : '';
450 $this->contribs = isset( $options['contribs'] ) ? $options['contribs'] : 'users';
451 $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
452 $this->tagFilter = isset( $options['tagfilter'] ) ? $options['tagfilter'] : false;
453 $this->nsInvert = isset( $options['nsInvert'] ) ? $options['nsInvert'] : false;
454
455 $this->deletedOnly = !empty( $options['deletedOnly'] );
456 $this->topOnly = !empty( $options['topOnly'] );
457
458 $year = isset( $options['year'] ) ? $options['year'] : false;
459 $month = isset( $options['month'] ) ? $options['month'] : false;
460 $this->getDateCond( $year, $month );
461
462 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
463 }
464
465 function getDefaultQuery() {
466 $query = parent::getDefaultQuery();
467 $query['target'] = $this->target;
468 return $query;
469 }
470
471 function getQueryInfo() {
472 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
473
474 $user = $this->getUser();
475 $conds = array_merge( $userCond, $this->getNamespaceCond() );
476
477 // Paranoia: avoid brute force searches (bug 17342)
478 if( !$user->isAllowed( 'deletedhistory' ) ) {
479 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0';
480 } elseif( !$user->isAllowed( 'suppressrevision' ) ) {
481 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::SUPPRESSED_USER) .
482 ' != ' . Revision::SUPPRESSED_USER;
483 }
484
485 # Don't include orphaned revisions
486 $join_cond['page'] = Revision::pageJoinCond();
487 # Get the current user name for accounts
488 $join_cond['user'] = Revision::userJoinCond();
489
490 $queryInfo = array(
491 'tables' => $tables,
492 'fields' => array_merge(
493 Revision::selectFields(),
494 Revision::selectUserFields(),
495 array( 'page_namespace', 'page_title', 'page_is_new',
496 'page_latest', 'page_is_redirect', 'page_len' )
497 ),
498 'conds' => $conds,
499 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
500 'join_conds' => $join_cond
501 );
502
503 ChangeTags::modifyDisplayQuery(
504 $queryInfo['tables'],
505 $queryInfo['fields'],
506 $queryInfo['conds'],
507 $queryInfo['join_conds'],
508 $queryInfo['options'],
509 $this->tagFilter
510 );
511
512 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
513 return $queryInfo;
514 }
515
516 function getUserCond() {
517 $condition = array();
518 $join_conds = array();
519 $tables = array( 'revision', 'page', 'user' );
520 if( $this->contribs == 'newbie' ) {
521 $tables[] = 'user_groups';
522 $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
523 $condition[] = 'rev_user >' . (int)($max - $max / 100);
524 $condition[] = 'ug_group IS NULL';
525 $index = 'user_timestamp';
526 # @todo FIXME: Other groups may have 'bot' rights
527 $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
528 } else {
529 if ( IP::isIPAddress( $this->target ) ) {
530 $condition['rev_user_text'] = $this->target;
531 $index = 'usertext_timestamp';
532 } else {
533 $condition['rev_user'] = User::idFromName( $this->target );
534 $index = 'user_timestamp';
535 }
536 }
537 if( $this->deletedOnly ) {
538 $condition[] = "rev_deleted != '0'";
539 }
540 if( $this->topOnly ) {
541 $condition[] = "rev_id = page_latest";
542 }
543 return array( $tables, $index, $condition, $join_conds );
544 }
545
546 function getNamespaceCond() {
547 if( $this->namespace !== '' ) {
548 if ( $this->nsInvert ) {
549 return array( 'page_namespace != ' . (int)$this->namespace );
550 } else {
551 return array( 'page_namespace' => (int)$this->namespace );
552 }
553 } else {
554 return array();
555 }
556 }
557
558 function getIndexField() {
559 return 'rev_timestamp';
560 }
561
562 function doBatchLookups() {
563 $this->mResult->rewind();
564 $revIds = array();
565 foreach ( $this->mResult as $row ) {
566 $revIds[] = $row->rev_parent_id;
567 }
568 $this->mParentLens = $this->getParentLengths( $revIds );
569 $this->mResult->rewind(); // reset
570
571 if ( $this->contribs === 'newbie' ) { // multiple users
572 # Do a link batch query
573 $this->mResult->seek( 0 );
574 $batch = new LinkBatch();
575 # Give some pointers to make (last) links
576 foreach ( $this->mResult as $row ) {
577 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
578 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
579 }
580 $batch->execute();
581 $this->mResult->seek( 0 );
582 }
583 }
584
585 /**
586 * Do a batched query to get the parent revision lengths
587 */
588 private function getParentLengths( array $revIds ) {
589 $revLens = array();
590 if ( !$revIds ) {
591 return $revLens; // empty
592 }
593 wfProfileIn( __METHOD__ );
594 $res = $this->getDatabase()->select( 'revision',
595 array( 'rev_id', 'rev_len' ),
596 array( 'rev_id' => $revIds ),
597 __METHOD__ );
598 foreach( $res as $row ) {
599 $revLens[$row->rev_id] = $row->rev_len;
600 }
601 wfProfileOut( __METHOD__ );
602 return $revLens;
603 }
604
605 function getStartBody() {
606 return "<ul>\n";
607 }
608
609 function getEndBody() {
610 return "</ul>\n";
611 }
612
613 /**
614 * Generates each row in the contributions list.
615 *
616 * Contributions which are marked "top" are currently on top of the history.
617 * For these contributions, a [rollback] link is shown for users with roll-
618 * back privileges. The rollback link restores the most recent version that
619 * was not written by the target user.
620 *
621 * @todo This would probably look a lot nicer in a table.
622 */
623 function formatRow( $row ) {
624 wfProfileIn( __METHOD__ );
625
626 $rev = new Revision( $row );
627 $classes = array();
628
629 $page = Title::newFromRow( $row );
630 $link = Linker::link(
631 $page,
632 htmlspecialchars( $page->getPrefixedText() ),
633 array(),
634 $page->isRedirect() ? array( 'redirect' => 'no' ) : array()
635 );
636 # Mark current revisions
637 $topmarktext = '';
638 if( $row->rev_id == $row->page_latest ) {
639 $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
640 # Add rollback link
641 if( !$row->page_is_new && $page->quickUserCan( 'rollback' )
642 && $page->quickUserCan( 'edit' ) )
643 {
644 $this->preventClickjacking();
645 $topmarktext .= ' '.Linker::generateRollback( $rev );
646 }
647 }
648 $user = $this->getUser();
649 # Is there a visible previous revision?
650 if( $rev->userCan( Revision::DELETED_TEXT, $user ) && $rev->getParentId() !== 0 ) {
651 $difftext = Linker::linkKnown(
652 $page,
653 $this->messages['diff'],
654 array(),
655 array(
656 'diff' => 'prev',
657 'oldid' => $row->rev_id
658 )
659 );
660 } else {
661 $difftext = $this->messages['diff'];
662 }
663 $histlink = Linker::linkKnown(
664 $page,
665 $this->messages['hist'],
666 array(),
667 array( 'action' => 'history' )
668 );
669
670 if ( isset( $this->mParentLens[$row->rev_parent_id] ) ) {
671 $chardiff = ' . . ' . ChangesList::showCharacterDifference(
672 $this->mParentLens[$row->rev_parent_id], $row->rev_len ) . ' . . ';
673 } else {
674 $chardiff = ' ';
675 }
676
677 $comment = $this->getLang()->getDirMark() . Linker::revComment( $rev, false, true );
678 $date = $this->getLang()->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
679 if( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
680 $d = Linker::linkKnown(
681 $page,
682 htmlspecialchars($date),
683 array(),
684 array( 'oldid' => intval( $row->rev_id ) )
685 );
686 } else {
687 $d = htmlspecialchars( $date );
688 }
689 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
690 $d = '<span class="history-deleted">' . $d . '</span>';
691 }
692
693 # Show user names for /newbies as there may be different users.
694 # Note that we already excluded rows with hidden user names.
695 if( $this->contribs == 'newbie' ) {
696 $userlink = ' . . ' . Linker::userLink( $rev->getUser(), $rev->getUserText() );
697 $userlink .= ' ' . wfMsg( 'parentheses',
698 Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) ) . ' ';
699 } else {
700 $userlink = '';
701 }
702
703 if( $rev->getParentId() === 0 ) {
704 $nflag = ChangesList::flag( 'newpage' );
705 } else {
706 $nflag = '';
707 }
708
709 if( $rev->isMinor() ) {
710 $mflag = ChangesList::flag( 'minor' );
711 } else {
712 $mflag = '';
713 }
714
715 if ( !is_null( $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
716 $mSize = $this->getSkin()->formatRevisionSize( $rev->getSize() );
717 } else {
718 $mSize = '';
719 }
720
721 // Don't show useless link to people who cannot hide revisions
722 $canHide = $user->isAllowed( 'deleterevision' );
723 if( $canHide || ($rev->getVisibility() && $user->isAllowed('deletedhistory')) ) {
724 if( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
725 $del = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
726 } else {
727 $query = array(
728 'type' => 'revision',
729 'target' => $page->getPrefixedDbkey(),
730 'ids' => $rev->getId()
731 );
732 $del = Linker::revDeleteLink( $query,
733 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
734 }
735 $del .= ' ';
736 } else {
737 $del = '';
738 }
739
740 $diffHistLinks = '(' . $difftext . $this->messages['pipe-separator'] . $histlink . ')';
741 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$mSize} {$comment} {$topmarktext}";
742
743 # Denote if username is redacted for this edit
744 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
745 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
746 }
747
748 # Tags, if any.
749 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'contributions' );
750 $classes = array_merge( $classes, $newClasses );
751 $ret .= " $tagSummary";
752
753 // Let extensions add data
754 wfRunHooks( 'ContributionsLineEnding', array( &$this, &$ret, $row ) );
755
756 $classes = implode( ' ', $classes );
757 $ret = "<li class=\"$classes\">$ret</li>\n";
758 wfProfileOut( __METHOD__ );
759 return $ret;
760 }
761
762 /**
763 * Get the Database object in use
764 *
765 * @return DatabaseBase
766 */
767 public function getDatabase() {
768 return $this->mDb;
769 }
770
771 /**
772 * Overwrite Pager function and return a helpful comment
773 */
774 function getSqlComment() {
775 if ( $this->namespace || $this->deletedOnly ) {
776 return 'contributions page filtered for namespace or RevisionDeleted edits'; // potentially slow, see CR r58153
777 } else {
778 return 'contributions page unfiltered';
779 }
780 }
781
782 protected function preventClickjacking() {
783 $this->preventClickjacking = true;
784 }
785
786 public function getPreventClickjacking() {
787 return $this->preventClickjacking;
788 }
789 }