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