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