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