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