Revert r88025 (put Special:Contributions namespace filter behind $wgMiserMode). Peopl...
[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 $this->setHeaders();
40 $this->outputHeader();
41 $out = $this->getOutput();
42 $out->addModuleStyles( 'mediawiki.special' );
43
44 $this->opts = array();
45 $request = $this->getRequest();
46
47 if( $par == 'newbies' ) {
48 $target = 'newbies';
49 $this->opts['contribs'] = 'newbie';
50 } elseif( $par !== null ) {
51 $target = $par;
52 } else {
53 $target = $request->getVal( 'target' );
54 }
55
56 // check for radiobox
57 if( $request->getVal( 'contribs' ) == 'newbie' ) {
58 $target = 'newbies';
59 $this->opts['contribs'] = 'newbie';
60 }
61
62 $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
63
64 if( !strlen( $target ) ) {
65 $out->addHTML( $this->getForm() );
66 return;
67 }
68
69 $user = $this->getUser();
70
71 $this->opts['limit'] = $request->getInt( 'limit', $user->getOption('rclimit') );
72 $this->opts['target'] = $target;
73 $this->opts['topOnly'] = $request->getBool( 'topOnly' );
74
75 $nt = Title::makeTitleSafe( NS_USER, $target );
76 if( !$nt ) {
77 $out->addHTML( $this->getForm() );
78 return;
79 }
80 $id = User::idFromName( $nt->getText() );
81
82 if( $target != 'newbies' ) {
83 $target = $nt->getText();
84 $out->setSubtitle( $this->contributionsSub( $nt, $id ) );
85 $out->setHTMLTitle( wfMsg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ),$target ) ) );
86 $userObj = User::newFromName( $target, false );
87 if ( is_object( $userObj ) ) {
88 $this->getSkin()->setRelevantUser( $userObj );
89 }
90 } else {
91 $out->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
92 $out->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) );
93 }
94
95 if( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
96 $this->opts['namespace'] = intval( $ns );
97 } else {
98 $this->opts['namespace'] = '';
99 }
100
101 $this->opts['tagFilter'] = (string) $request->getVal( 'tagFilter' );
102
103 // Allows reverts to have the bot flag in recent changes. It is just here to
104 // be passed in the form at the top of the page
105 if( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
106 $this->opts['bot'] = '1';
107 }
108
109 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
110 # Offset overrides year/month selection
111 if( $skip ) {
112 $this->opts['year'] = '';
113 $this->opts['month'] = '';
114 } else {
115 $this->opts['year'] = $request->getIntOrNull( 'year' );
116 $this->opts['month'] = $request->getIntOrNull( 'month' );
117 }
118
119 $feedType = $request->getVal( 'feed' );
120 if( $feedType ) {
121 // Maintain some level of backwards compatability
122 // If people request feeds using the old parameters, redirect to API
123 $apiParams = array(
124 'action' => 'feedcontributions',
125 'feedformat' => $feedType,
126 'user' => $target,
127 );
128 if ( $this->opts['topOnly'] ) {
129 $apiParams['toponly'] = true;
130 }
131 if ( $this->opts['deletedOnly'] ) {
132 $apiParams['deletedonly'] = true;
133 }
134 if ( $this->opts['tagFilter'] !== '' ) {
135 $apiParams['tagfilter'] = $this->opts['tagFilter'];
136 }
137 if ( $this->opts['namespace'] !== '' ) {
138 $apiParams['namespace'] = $this->opts['namespace'];
139 }
140 if ( $this->opts['year'] !== null ) {
141 $apiParams['year'] = $this->opts['year'];
142 }
143 if ( $this->opts['month'] !== null ) {
144 $apiParams['month'] = $this->opts['month'];
145 }
146
147 $url = wfScript( 'api' ) . '?' . wfArrayToCGI( $apiParams );
148
149 $out->redirect( $url, '301' );
150 return;
151 }
152
153 // Add RSS/atom links
154 $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) );
155
156 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
157
158 $out->addHTML( $this->getForm() );
159
160 $pager = new ContribsPager( array(
161 'target' => $target,
162 'namespace' => $this->opts['namespace'],
163 'year' => $this->opts['year'],
164 'month' => $this->opts['month'],
165 'deletedOnly' => $this->opts['deletedOnly'],
166 'topOnly' => $this->opts['topOnly'],
167 ) );
168 if( !$pager->getNumRows() ) {
169 $out->addWikiMsg( 'nocontribs', $target );
170 } else {
171 # Show a message about slave lag, if applicable
172 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
173 if( $lag > 0 )
174 $out->showLagWarning( $lag );
175
176 $out->addHTML(
177 '<p>' . $pager->getNavigationBar() . '</p>' .
178 $pager->getBody() .
179 '<p>' . $pager->getNavigationBar() . '</p>'
180 );
181 }
182 $out->preventClickjacking( $pager->getPreventClickjacking() );
183
184 # Show the appropriate "footer" message - WHOIS tools, etc.
185 if( $target != 'newbies' ) {
186 $message = 'sp-contributions-footer';
187 if ( IP::isIPAddress( $target ) ) {
188 $message = 'sp-contributions-footer-anon';
189 } else {
190 $userObj = User::newFromName( $target );
191 if ( !$userObj || $userObj->isAnon() ) {
192 // No message for non-existing users
193 return;
194 }
195 }
196
197 if( !wfMessage( $message, $target )->isDisabled() ) {
198 $out->wrapWikiMsg(
199 "<div class='mw-contributions-footer'>\n$1\n</div>",
200 array( $message, $target ) );
201 }
202 }
203 }
204 }
205
206 /**
207 * Generates the subheading with links
208 * @param $nt Title object for the target
209 * @param $id Integer: User ID for the target
210 * @return String: appropriately-escaped HTML to be output literally
211 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
212 */
213 protected function contributionsSub( $nt, $id ) {
214 if ( $id === null ) {
215 $user = htmlspecialchars( $nt->getText() );
216 } else {
217 $user = Linker::link( $nt, htmlspecialchars( $nt->getText() ) );
218 }
219 $userObj = User::newFromName( $nt->getText(), /* check for username validity not needed */ false );
220 $talk = $nt->getTalkPage();
221 if( $talk ) {
222 $tools = self::getUserLinks( $nt, $talk, $userObj, $this->getUser() );
223 $links = $this->getLang()->pipeList( $tools );
224
225 // Show a note if the user is blocked and display the last block log entry.
226 if ( $userObj->isBlocked() ) {
227 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
228 LogEventsList::showLogExtract(
229 $out,
230 'block',
231 $nt,
232 '',
233 array(
234 'lim' => 1,
235 'showIfEmpty' => false,
236 'msgKey' => array(
237 $userObj->isAnon() ?
238 'sp-contributions-blocked-notice-anon' :
239 'sp-contributions-blocked-notice',
240 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
241 ),
242 'offset' => '' # don't use WebRequest parameter offset
243 )
244 );
245 }
246 }
247
248 // Old message 'contribsub' had one parameter, but that doesn't work for
249 // languages that want to put the "for" bit right after $user but before
250 // $links. If 'contribsub' is around, use it for reverse compatibility,
251 // otherwise use 'contribsub2'.
252 if( wfEmptyMsg( 'contribsub' ) ) {
253 return wfMsgHtml( 'contribsub2', $user, $links );
254 } else {
255 return wfMsgHtml( 'contribsub', "$user ($links)" );
256 }
257 }
258
259 /**
260 * Links to different places.
261 * @param $userpage Title: Target user page
262 * @param $talkpage Title: Talk page
263 * @param $target User: Target user object
264 * @param $subject User: The viewing user ($wgUser might be still checked in some cases)
265 */
266 public static function getUserLinks( Title $userpage, Title $talkpage, User $target, User $subject ) {
267
268 $id = $target->getId();
269 $username = $target->getName();
270
271 $tools[] = Linker::link( $talkpage, wfMsgHtml( 'sp-contributions-talk' ) );
272
273 if( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) {
274 if( $subject->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
275 if ( $target->isBlocked() ) {
276 $tools[] = Linker::linkKnown( # Change block link
277 SpecialPage::getTitleFor( 'Block', $username ),
278 wfMsgHtml( 'change-blocklink' )
279 );
280 $tools[] = Linker::linkKnown( # Unblock link
281 SpecialPage::getTitleFor( 'Unblock', $username ),
282 wfMsgHtml( 'unblocklink' )
283 );
284 } else { # User is not blocked
285 $tools[] = Linker::linkKnown( # Block link
286 SpecialPage::getTitleFor( 'Block', $username ),
287 wfMsgHtml( 'blocklink' )
288 );
289 }
290 }
291 # Block log link
292 $tools[] = Linker::linkKnown(
293 SpecialPage::getTitleFor( 'Log', 'block' ),
294 wfMsgHtml( 'sp-contributions-blocklog' ),
295 array(),
296 array(
297 'page' => $userpage->getPrefixedText()
298 )
299 );
300 }
301 # Uploads
302 $tools[] = Linker::linkKnown(
303 SpecialPage::getTitleFor( 'Listfiles', $username ),
304 wfMsgHtml( 'sp-contributions-uploads' )
305 );
306
307 # Other logs link
308 $tools[] = Linker::linkKnown(
309 SpecialPage::getTitleFor( 'Log', $username ),
310 wfMsgHtml( 'sp-contributions-logs' )
311 );
312
313 # Add link to deleted user contributions for priviledged users
314 if( $subject->isAllowed( 'deletedhistory' ) && !$subject->isBlocked() ) {
315 $tools[] = Linker::linkKnown(
316 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
317 wfMsgHtml( 'sp-contributions-deleted' )
318 );
319 }
320
321 # Add a link to change user rights for privileged users
322 $userrightsPage = new UserrightsPage();
323 $userrightsPage->getContext()->setUser( $subject );
324 if( $id !== null && $userrightsPage->userCanChangeRights( $target ) ) {
325 $tools[] = Linker::linkKnown(
326 SpecialPage::getTitleFor( 'Userrights', $username ),
327 wfMsgHtml( 'sp-contributions-userrights' )
328 );
329 }
330
331 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
332 return $tools;
333 }
334
335 /**
336 * Generates the namespace selector form with hidden attributes.
337 * @return String: HTML fragment
338 */
339 protected function getForm() {
340 global $wgScript;
341
342 $this->opts['title'] = $this->getTitle()->getPrefixedText();
343 if( !isset( $this->opts['target'] ) ) {
344 $this->opts['target'] = '';
345 } else {
346 $this->opts['target'] = str_replace( '_' , ' ' , $this->opts['target'] );
347 }
348
349 if( !isset( $this->opts['namespace'] ) ) {
350 $this->opts['namespace'] = '';
351 }
352
353 if( !isset( $this->opts['contribs'] ) ) {
354 $this->opts['contribs'] = 'user';
355 }
356
357 if( !isset( $this->opts['year'] ) ) {
358 $this->opts['year'] = '';
359 }
360
361 if( !isset( $this->opts['month'] ) ) {
362 $this->opts['month'] = '';
363 }
364
365 if( $this->opts['contribs'] == 'newbie' ) {
366 $this->opts['target'] = '';
367 }
368
369 if( !isset( $this->opts['tagFilter'] ) ) {
370 $this->opts['tagFilter'] = '';
371 }
372
373 if( !isset( $this->opts['topOnly'] ) ) {
374 $this->opts['topOnly'] = false;
375 }
376
377 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) );
378
379 # Add hidden params for tracking except for parameters in $skipParameters
380 $skipParameters = array( 'namespace', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly' );
381 foreach ( $this->opts as $name => $value ) {
382 if( in_array( $name, $skipParameters ) ) {
383 continue;
384 }
385 $f .= "\t" . Html::hidden( $name, $value ) . "\n";
386 }
387
388 $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagFilter'] );
389
390 $f .= Xml::fieldset( wfMsg( 'sp-contributions-search' ) ) .
391 Xml::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parsemag' ) ),
392 'contribs', 'newbie' , 'newbie', $this->opts['contribs'] == 'newbie' ) . '<br />' .
393 Xml::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parsemag' ) ),
394 'contribs' , 'user', 'user', $this->opts['contribs'] == 'user' ) . ' ' .
395 Html::input( 'target', $this->opts['target'], 'text', array(
396 'size' => '20',
397 'required' => ''
398 ) + ( $this->opts['target'] ? array() : array( 'autofocus' ) ) ) . ' '.
399 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
400 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
401 Xml::namespaceSelector( $this->opts['namespace'], '' )
402 ) .
403 Xml::checkLabel( wfMsg( 'history-show-deleted' ),
404 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'] ) . '<br />' .
405 Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'sp-contributions-toponly' ),
406 'topOnly', 'mw-show-top-only', $this->opts['topOnly'] ) ) .
407 ( $tagFilter ? Xml::tags( 'p', null, implode( '&#160;', $tagFilter ) ) : '' ) .
408 Html::rawElement( 'p', array( 'style' => 'white-space: nowrap' ),
409 Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) . ' ' .
410 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) )
411 ) . ' ';
412 $explain = wfMessage( 'sp-contributions-explain' );
413 if ( $explain->exists() ) {
414 $f .= "<p id='mw-sp-contributions-explain'>{$explain}</p>";
415 }
416 $f .= Xml::closeElement('fieldset' ) .
417 Xml::closeElement( 'form' );
418 return $f;
419 }
420 }
421
422 /**
423 * Pager for Special:Contributions
424 * @ingroup SpecialPage Pager
425 */
426 class ContribsPager extends ReverseChronologicalPager {
427 public $mDefaultDirection = true;
428 var $messages, $target;
429 var $namespace = '', $mDb;
430 var $preventClickjacking = false;
431
432 function __construct( $options ) {
433 parent::__construct();
434
435 $msgs = array( 'uctop', 'diff', 'newarticle', 'rollbacklink', 'diff', 'hist', 'rev-delundel', 'pipe-separator' );
436
437 foreach( $msgs as $msg ) {
438 $this->messages[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
439 }
440
441 $this->target = isset( $options['target'] ) ? $options['target'] : '';
442 $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
443 $this->tagFilter = isset( $options['tagFilter'] ) ? $options['tagFilter'] : false;
444
445 $this->deletedOnly = !empty( $options['deletedOnly'] );
446 $this->topOnly = !empty( $options['topOnly'] );
447
448 $year = isset( $options['year'] ) ? $options['year'] : false;
449 $month = isset( $options['month'] ) ? $options['month'] : false;
450 $this->getDateCond( $year, $month );
451
452 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
453 }
454
455 function getDefaultQuery() {
456 $query = parent::getDefaultQuery();
457 $query['target'] = $this->target;
458 return $query;
459 }
460
461 function getQueryInfo() {
462 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
463
464 $user = $this->getUser();
465 $conds = array_merge( $userCond, $this->getNamespaceCond() );
466 // Paranoia: avoid brute force searches (bug 17342)
467 if( !$user->isAllowed( 'deletedhistory' ) || $user->isBlocked() ) {
468 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0';
469 } elseif( !$user->isAllowed( 'suppressrevision' ) ) {
470 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::SUPPRESSED_USER) .
471 ' != ' . Revision::SUPPRESSED_USER;
472 }
473 $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
474
475 $queryInfo = array(
476 'tables' => $tables,
477 'fields' => array(
478 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'page_is_redirect',
479 'page_len','rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment',
480 'rev_minor_edit', 'rev_user', 'rev_user_text', 'rev_parent_id', 'rev_deleted',
481 'rev_len', 'rev_parent_id'
482 ),
483 'conds' => $conds,
484 'options' => array( 'USE INDEX' => array('revision' => $index) ),
485 'join_conds' => $join_cond
486 );
487
488 ChangeTags::modifyDisplayQuery(
489 $queryInfo['tables'],
490 $queryInfo['fields'],
491 $queryInfo['conds'],
492 $queryInfo['join_conds'],
493 $queryInfo['options'],
494 $this->tagFilter
495 );
496
497 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
498 return $queryInfo;
499 }
500
501 function getUserCond() {
502 $condition = array();
503 $join_conds = array();
504 if( $this->target == 'newbies' ) {
505 $tables = array( 'user_groups', 'page', 'revision' );
506 $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
507 $condition[] = 'rev_user >' . (int)($max - $max / 100);
508 $condition[] = 'ug_group IS NULL';
509 $index = 'user_timestamp';
510 # @todo FIXME: Other groups may have 'bot' rights
511 $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
512 } else {
513 $tables = array( 'page', 'revision' );
514 $condition['rev_user_text'] = $this->target;
515 $index = 'usertext_timestamp';
516 }
517 if( $this->deletedOnly ) {
518 $condition[] = "rev_deleted != '0'";
519 }
520 if( $this->topOnly ) {
521 $condition[] = "rev_id = page_latest";
522 }
523 return array( $tables, $index, $condition, $join_conds );
524 }
525
526 function getNamespaceCond() {
527 global $wgMiserMode;
528 if( $this->namespace !== '' && !$wgMiserMode ) {
529 return array( 'page_namespace' => (int)$this->namespace );
530 } else {
531 return array();
532 }
533 }
534
535 function getIndexField() {
536 return 'rev_timestamp';
537 }
538
539 function getStartBody() {
540 return "<ul>\n";
541 }
542
543 function getEndBody() {
544 return "</ul>\n";
545 }
546
547 function getBody() {
548 global $wgRCShowChangedSize;
549 if( !$this->mQueryDone ) {
550 $this->doQuery();
551 }
552 $this->mParentLens = array();
553 if( $wgRCShowChangedSize ) {
554 $this->mResult->rewind();
555 $revIds = array();
556 foreach( $this->mResult as $row ) {
557 $revIds[] = $row->rev_parent_id;
558 }
559 $this->mParentLens = $this->getParentLengths( $revIds );
560 $this->mResult->rewind();
561 }
562 return parent::getBody();
563 }
564
565 /*
566 * Do a batched query to get the parent revision lengths
567 */
568 private function getParentLengths( array $revIds ) {
569 $revLens = array();
570 if ( !$revIds ) {
571 return $revLens; // empty
572 }
573 wfProfileIn( __METHOD__ );
574 $res = $this->getDatabase()->select( 'revision',
575 array( 'rev_id', 'rev_len' ),
576 array( 'rev_id' => $revIds ),
577 __METHOD__ );
578 foreach( $res as $row ) {
579 $revLens[$row->rev_id] = $row->rev_len;
580 }
581 wfProfileOut( __METHOD__ );
582 return $revLens;
583 }
584
585 /**
586 * Generates each row in the contributions list.
587 *
588 * Contributions which are marked "top" are currently on top of the history.
589 * For these contributions, a [rollback] link is shown for users with roll-
590 * back privileges. The rollback link restores the most recent version that
591 * was not written by the target user.
592 *
593 * @todo This would probably look a lot nicer in a table.
594 */
595 function formatRow( $row ) {
596 wfProfileIn( __METHOD__ );
597
598 $rev = new Revision( $row );
599 $classes = array();
600
601 $page = Title::newFromRow( $row );
602 $link = Linker::link(
603 $page,
604 htmlspecialchars( $page->getPrefixedText() ),
605 array(),
606 $page->isRedirect() ? array( 'redirect' => 'no' ) : array()
607 );
608 # Mark current revisions
609 $topmarktext = '';
610 if( $row->rev_id == $row->page_latest ) {
611 $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
612 # Add rollback link
613 if( !$row->page_is_new && $page->quickUserCan( 'rollback' )
614 && $page->quickUserCan( 'edit' ) )
615 {
616 $this->preventClickjacking();
617 $topmarktext .= ' '.Linker::generateRollback( $rev );
618 }
619 }
620 # Is there a visible previous revision?
621 if( $rev->userCan( Revision::DELETED_TEXT ) && $rev->getParentId() !== 0 ) {
622 $difftext = Linker::linkKnown(
623 $page,
624 $this->messages['diff'],
625 array(),
626 array(
627 'diff' => 'prev',
628 'oldid' => $row->rev_id
629 )
630 );
631 } else {
632 $difftext = $this->messages['diff'];
633 }
634 $histlink = Linker::linkKnown(
635 $page,
636 $this->messages['hist'],
637 array(),
638 array( 'action' => 'history' )
639 );
640
641 if ( isset( $this->mParentLens[$row->rev_parent_id] ) ) {
642 $chardiff = ' . . ' . ChangesList::showCharacterDifference(
643 $this->mParentLens[$row->rev_parent_id], $row->rev_len ) . ' . . ';
644 } else {
645 $chardiff = ' ';
646 }
647
648 $comment = $this->getLang()->getDirMark() . Linker::revComment( $rev, false, true );
649 $date = $this->getLang()->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
650 if( $rev->userCan( Revision::DELETED_TEXT ) ) {
651 $d = Linker::linkKnown(
652 $page,
653 htmlspecialchars($date),
654 array(),
655 array( 'oldid' => intval( $row->rev_id ) )
656 );
657 } else {
658 $d = htmlspecialchars( $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 = ' . . ' . Linker::userLink( $row->rev_user, $row->rev_user_text );
666 $userlink .= ' ' . wfMsg( 'parentheses', Linker::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 = $this->getUser()->isAllowed( 'deleterevision' );
685 if( $canHide || ($rev->getVisibility() && $this->getUser()->isAllowed('deletedhistory')) ) {
686 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
687 $del = Linker::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 = Linker::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}{$chardiff}{$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 DatabaseBase
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 protected function preventClickjacking() {
745 $this->preventClickjacking = true;
746 }
747
748 public function getPreventClickjacking() {
749 return $this->preventClickjacking;
750 }
751 }