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