FU 97704: I was thinking the space was already added in this case
[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->getPrefixedText(),
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, $wgMiserMode;
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 $fNS = ( $wgMiserMode ) ? '' :
391 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
392 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
393 Xml::namespaceSelector( $this->opts['namespace'], '' )
394 );
395
396 $f .= Xml::fieldset( wfMsg( 'sp-contributions-search' ) ) .
397 Xml::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parsemag' ) ),
398 'contribs', 'newbie' , 'newbie', $this->opts['contribs'] == 'newbie' ) . '<br />' .
399 Xml::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parsemag' ) ),
400 'contribs' , 'user', 'user', $this->opts['contribs'] == 'user' ) . ' ' .
401 Html::input( 'target', $this->opts['target'], 'text', array(
402 'size' => '20',
403 'required' => ''
404 ) + ( $this->opts['target'] ? array() : array( 'autofocus' ) ) ) . ' '.
405 $fNS.
406 Xml::checkLabel( wfMsg( 'history-show-deleted' ),
407 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'] ) . '<br />' .
408 Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'sp-contributions-toponly' ),
409 'topOnly', 'mw-show-top-only', $this->opts['topOnly'] ) ) .
410 ( $tagFilter ? Xml::tags( 'p', null, implode( '&#160;', $tagFilter ) ) : '' ) .
411 Html::rawElement( 'p', array( 'style' => 'white-space: nowrap' ),
412 Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) . ' ' .
413 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) )
414 ) . ' ';
415 $explain = wfMessage( 'sp-contributions-explain' );
416 if ( $explain->exists() ) {
417 $f .= "<p id='mw-sp-contributions-explain'>{$explain}</p>";
418 }
419 $f .= Xml::closeElement('fieldset' ) .
420 Xml::closeElement( 'form' );
421 return $f;
422 }
423 }
424
425 /**
426 * Pager for Special:Contributions
427 * @ingroup SpecialPage Pager
428 */
429 class ContribsPager extends ReverseChronologicalPager {
430 public $mDefaultDirection = true;
431 var $messages, $target;
432 var $namespace = '', $mDb;
433 var $preventClickjacking = false;
434
435 function __construct( $options ) {
436 parent::__construct();
437
438 $msgs = array( 'uctop', 'diff', 'newarticle', 'rollbacklink', 'diff', 'hist', 'rev-delundel', 'pipe-separator' );
439
440 foreach( $msgs as $msg ) {
441 $this->messages[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
442 }
443
444 $this->target = isset( $options['target'] ) ? $options['target'] : '';
445 $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
446 $this->tagFilter = isset( $options['tagFilter'] ) ? $options['tagFilter'] : false;
447
448 $this->deletedOnly = !empty( $options['deletedOnly'] );
449 $this->topOnly = !empty( $options['topOnly'] );
450
451 $year = isset( $options['year'] ) ? $options['year'] : false;
452 $month = isset( $options['month'] ) ? $options['month'] : false;
453 $this->getDateCond( $year, $month );
454
455 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
456 }
457
458 function getDefaultQuery() {
459 $query = parent::getDefaultQuery();
460 $query['target'] = $this->target;
461 return $query;
462 }
463
464 function getQueryInfo() {
465 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
466
467 $user = $this->getUser();
468 $conds = array_merge( $userCond, $this->getNamespaceCond() );
469 // Paranoia: avoid brute force searches (bug 17342)
470 if( !$user->isAllowed( 'deletedhistory' ) || $user->isBlocked() ) {
471 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0';
472 } elseif( !$user->isAllowed( 'suppressrevision' ) ) {
473 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::SUPPRESSED_USER) .
474 ' != ' . Revision::SUPPRESSED_USER;
475 }
476 $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
477
478 $queryInfo = array(
479 'tables' => $tables,
480 'fields' => array(
481 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'page_is_redirect',
482 'page_len','rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment',
483 'rev_minor_edit', 'rev_user', 'rev_user_text', 'rev_parent_id', 'rev_deleted',
484 'rev_len', 'rev_parent_id'
485 ),
486 'conds' => $conds,
487 'options' => array( 'USE INDEX' => array('revision' => $index) ),
488 'join_conds' => $join_cond
489 );
490
491 ChangeTags::modifyDisplayQuery(
492 $queryInfo['tables'],
493 $queryInfo['fields'],
494 $queryInfo['conds'],
495 $queryInfo['join_conds'],
496 $queryInfo['options'],
497 $this->tagFilter
498 );
499
500 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
501 return $queryInfo;
502 }
503
504 function getUserCond() {
505 $condition = array();
506 $join_conds = array();
507 if( $this->target == 'newbies' ) {
508 $tables = array( 'user_groups', 'page', 'revision' );
509 $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
510 $condition[] = 'rev_user >' . (int)($max - $max / 100);
511 $condition[] = 'ug_group IS NULL';
512 $index = 'user_timestamp';
513 # @todo FIXME: Other groups may have 'bot' rights
514 $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
515 } else {
516 $tables = array( 'page', 'revision' );
517 $condition['rev_user_text'] = $this->target;
518 $index = 'usertext_timestamp';
519 }
520 if( $this->deletedOnly ) {
521 $condition[] = "rev_deleted != '0'";
522 }
523 if( $this->topOnly ) {
524 $condition[] = "rev_id = page_latest";
525 }
526 return array( $tables, $index, $condition, $join_conds );
527 }
528
529 function getNamespaceCond() {
530 global $wgMiserMode;
531 if( $this->namespace !== '' && !$wgMiserMode ) {
532 return array( 'page_namespace' => (int)$this->namespace );
533 } else {
534 return array();
535 }
536 }
537
538 function getIndexField() {
539 return 'rev_timestamp';
540 }
541
542 function getStartBody() {
543 return "<ul>\n";
544 }
545
546 function getEndBody() {
547 return "</ul>\n";
548 }
549
550 function getBody() {
551 global $wgRCShowChangedSize;
552 if( !$this->mQueryDone ) {
553 $this->doQuery();
554 }
555 $this->mParentLens = array();
556 if( $wgRCShowChangedSize ) {
557 $this->mResult->rewind();
558 $revIds = array();
559 foreach( $this->mResult as $row ) {
560 $revIds[] = $row->rev_parent_id;
561 }
562 $this->mParentLens = $this->getParentLengths( $revIds );
563 $this->mResult->rewind();
564 }
565 return parent::getBody();
566 }
567
568 /*
569 * Do a batched query to get the parent revision lengths
570 */
571 private function getParentLengths( array $revIds ) {
572 $revLens = array();
573 if ( !$revIds ) {
574 return $revLens; // empty
575 }
576 wfProfileIn( __METHOD__ );
577 $res = $this->getDatabase()->select( 'revision',
578 array( 'rev_id', 'rev_len' ),
579 array( 'rev_id' => $revIds ),
580 __METHOD__ );
581 foreach( $res as $row ) {
582 $revLens[$row->rev_id] = $row->rev_len;
583 }
584 wfProfileOut( __METHOD__ );
585 return $revLens;
586 }
587
588 /**
589 * Generates each row in the contributions list.
590 *
591 * Contributions which are marked "top" are currently on top of the history.
592 * For these contributions, a [rollback] link is shown for users with roll-
593 * back privileges. The rollback link restores the most recent version that
594 * was not written by the target user.
595 *
596 * @todo This would probably look a lot nicer in a table.
597 */
598 function formatRow( $row ) {
599 wfProfileIn( __METHOD__ );
600
601 $rev = new Revision( $row );
602 $classes = array();
603
604 $page = Title::newFromRow( $row );
605 $link = Linker::link(
606 $page,
607 htmlspecialchars( $page->getPrefixedText() ),
608 array(),
609 $page->isRedirect() ? array( 'redirect' => 'no' ) : array()
610 );
611 # Mark current revisions
612 $topmarktext = '';
613 if( $row->rev_id == $row->page_latest ) {
614 $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
615 # Add rollback link
616 if( !$row->page_is_new && $page->quickUserCan( 'rollback' )
617 && $page->quickUserCan( 'edit' ) )
618 {
619 $this->preventClickjacking();
620 $topmarktext .= ' '.Linker::generateRollback( $rev );
621 }
622 }
623 # Is there a visible previous revision?
624 if( $rev->userCan( Revision::DELETED_TEXT ) && $rev->getParentId() !== 0 ) {
625 $difftext = Linker::linkKnown(
626 $page,
627 $this->messages['diff'],
628 array(),
629 array(
630 'diff' => 'prev',
631 'oldid' => $row->rev_id
632 )
633 );
634 } else {
635 $difftext = $this->messages['diff'];
636 }
637 $histlink = Linker::linkKnown(
638 $page,
639 $this->messages['hist'],
640 array(),
641 array( 'action' => 'history' )
642 );
643
644 if ( isset( $this->mParentLens[$row->rev_parent_id] ) ) {
645 $chardiff = ' . . ' . ChangesList::showCharacterDifference(
646 $this->mParentLens[$row->rev_parent_id], $row->rev_len ) . ' . . ';
647 } else {
648 $chardiff = ' ';
649 }
650
651 $comment = $this->getLang()->getDirMark() . Linker::revComment( $rev, false, true );
652 $date = $this->getLang()->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
653 if( $rev->userCan( Revision::DELETED_TEXT ) ) {
654 $d = Linker::linkKnown(
655 $page,
656 htmlspecialchars($date),
657 array(),
658 array( 'oldid' => intval( $row->rev_id ) )
659 );
660 } else {
661 $d = htmlspecialchars( $date );
662 }
663 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
664 $d = '<span class="history-deleted">' . $d . '</span>';
665 }
666
667 if( $this->target == 'newbies' ) {
668 $userlink = ' . . ' . Linker::userLink( $row->rev_user, $row->rev_user_text );
669 $userlink .= ' ' . wfMsg( 'parentheses', Linker::userTalkLink( $row->rev_user, $row->rev_user_text ) ) . ' ';
670 } else {
671 $userlink = '';
672 }
673
674 if( $rev->getParentId() === 0 ) {
675 $nflag = ChangesList::flag( 'newpage' );
676 } else {
677 $nflag = '';
678 }
679
680 if( $rev->isMinor() ) {
681 $mflag = ChangesList::flag( 'minor' );
682 } else {
683 $mflag = '';
684 }
685
686 // Don't show useless link to people who cannot hide revisions
687 $canHide = $this->getUser()->isAllowed( 'deleterevision' );
688 if( $canHide || ($rev->getVisibility() && $this->getUser()->isAllowed('deletedhistory')) ) {
689 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
690 $del = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
691 } else {
692 $query = array(
693 'type' => 'revision',
694 'target' => $page->getPrefixedDbkey(),
695 'ids' => $rev->getId()
696 );
697 $del = Linker::revDeleteLink( $query,
698 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
699 }
700 $del .= ' ';
701 } else {
702 $del = '';
703 }
704
705 $diffHistLinks = '(' . $difftext . $this->messages['pipe-separator'] . $histlink . ')';
706 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
707
708 # Denote if username is redacted for this edit
709 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
710 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
711 }
712
713 # Tags, if any.
714 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'contributions' );
715 $classes = array_merge( $classes, $newClasses );
716 $ret .= " $tagSummary";
717
718 // Let extensions add data
719 wfRunHooks( 'ContributionsLineEnding', array( &$this, &$ret, $row ) );
720
721 $classes = implode( ' ', $classes );
722 $ret = "<li class=\"$classes\">$ret</li>\n";
723 wfProfileOut( __METHOD__ );
724 return $ret;
725 }
726
727 /**
728 * Get the Database object in use
729 *
730 * @return DatabaseBase
731 */
732 public function getDatabase() {
733 return $this->mDb;
734 }
735
736 /**
737 * Overwrite Pager function and return a helpful comment
738 */
739 function getSqlComment() {
740 if ( $this->namespace || $this->deletedOnly ) {
741 return 'contributions page filtered for namespace or RevisionDeleted edits'; // potentially slow, see CR r58153
742 } else {
743 return 'contributions page unfiltered';
744 }
745 }
746
747 protected function preventClickjacking() {
748 $this->preventClickjacking = true;
749 }
750
751 public function getPreventClickjacking() {
752 return $this->preventClickjacking;
753 }
754 }