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