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