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