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