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