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