7f515fc0451744ded56f4093e6edc7fabe3301d4
[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 );
576 if ( $this->showSizeDiff && !$wgMiserMode ) {
577 $fields = array_merge( $fields, array( 'rc_old_len', 'rc_new_len' ) );
578 array_unshift( $tables, 'recentchanges' );
579 $join_cond['recentchanges'] = array( 'INNER JOIN', "rev_id = rc_this_oldid" );
580 }
581
582 $queryInfo = array(
583 'tables' => $tables,
584 'fields' => $fields,
585 'conds' => $conds,
586 'options' => array( 'USE INDEX' => array('revision' => $index) ),
587 'join_conds' => $join_cond
588 );
589 ChangeTags::modifyDisplayQuery(
590 $queryInfo['tables'],
591 $queryInfo['fields'],
592 $queryInfo['conds'],
593 $queryInfo['join_conds'],
594 $queryInfo['options'],
595 $this->tagFilter
596 );
597
598 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
599 return $queryInfo;
600 }
601
602 function getUserCond() {
603 $condition = array();
604 $join_conds = array();
605
606 if( $this->target == 'newbies' ) {
607 $tables = array( 'user_groups', 'page', 'revision' );
608 $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
609 $condition[] = 'rev_user >' . (int)($max - $max / 100);
610 $condition[] = 'ug_group IS NULL';
611 $index = 'user_timestamp';
612 # FIXME: other groups may have 'bot' rights
613 $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
614 } else {
615 $tables = array( 'page', 'revision' );
616 $condition['rev_user_text'] = $this->target;
617 $index = 'usertext_timestamp';
618 }
619 if( $this->deletedOnly ) {
620 $condition[] = "rev_deleted != '0'";
621 }
622 if( $this->topOnly ) {
623 $condition[] = "rev_id = page_latest";
624 }
625 return array( $tables, $index, $condition, $join_conds );
626 }
627
628 function getNamespaceCond() {
629 global $wgMiserMode;
630 if( $this->namespace !== '' && !$wgMiserMode ) {
631 return array( 'page_namespace' => (int)$this->namespace );
632 } else {
633 return array();
634 }
635 }
636
637 function getIndexField() {
638 return 'rev_timestamp';
639 }
640
641 function getStartBody() {
642 return "<ul>\n";
643 }
644
645 function getEndBody() {
646 return "</ul>\n";
647 }
648
649 /**
650 * Generates each row in the contributions list.
651 *
652 * Contributions which are marked "top" are currently on top of the history.
653 * For these contributions, a [rollback] link is shown for users with roll-
654 * back privileges. The rollback link restores the most recent version that
655 * was not written by the target user.
656 *
657 * @todo This would probably look a lot nicer in a table.
658 */
659 function formatRow( $row ) {
660 global $wgUser, $wgLang, $wgContLang;
661 wfProfileIn( __METHOD__ );
662
663 $sk = $this->getSkin();
664 $rev = new Revision( $row );
665 $classes = array();
666
667 $page = Title::newFromRow( $row );
668 $link = $sk->link(
669 $page,
670 htmlspecialchars( $page->getPrefixedText() ),
671 array(),
672 $page->isRedirect() ? array( 'redirect' => 'no' ) : array()
673 );
674 # Mark current revisions
675 $topmarktext = '';
676 if( $row->rev_id == $row->page_latest ) {
677 $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
678 # Add rollback link
679 if( !$row->page_is_new && $page->quickUserCan( 'rollback' )
680 && $page->quickUserCan( 'edit' ) )
681 {
682 $this->preventClickjacking();
683 $topmarktext .= ' '.$sk->generateRollback( $rev );
684 }
685 }
686 # Is there a visible previous revision?
687 if( $rev->userCan( Revision::DELETED_TEXT ) && $rev->getParentId() !== 0 ) {
688 $difftext = $sk->linkKnown(
689 $page,
690 $this->messages['diff'],
691 array(),
692 array(
693 'diff' => 'prev',
694 'oldid' => $row->rev_id
695 )
696 );
697 } else {
698 $difftext = $this->messages['diff'];
699 }
700 $histlink = $sk->linkKnown(
701 $page,
702 $this->messages['hist'],
703 array(),
704 array( 'action' => 'history' )
705 );
706
707 $comment = $wgContLang->getDirMark() . $sk->revComment( $rev, false, true );
708 $date = $wgLang->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
709 if( $rev->userCan( Revision::DELETED_TEXT ) ) {
710 $d = $sk->linkKnown(
711 $page,
712 htmlspecialchars($date),
713 array(),
714 array( 'oldid' => intval( $row->rev_id ) )
715 );
716 } else {
717 $d = htmlspecialchars( $date );
718 }
719 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
720 $d = '<span class="history-deleted">' . $d . '</span>';
721 }
722
723 if( $this->target == 'newbies' ) {
724 $userlink = ' . . ' . $sk->userLink( $row->rev_user, $row->rev_user_text );
725 $userlink .= ' ' . wfMsg( 'parentheses', $sk->userTalkLink( $row->rev_user, $row->rev_user_text ) ) . ' ';
726 } else {
727 $userlink = '';
728 }
729
730 if( $rev->getParentId() === 0 ) {
731 $nflag = ChangesList::flag( 'newpage' );
732 } else {
733 $nflag = '';
734 }
735
736 if( $rev->isMinor() ) {
737 $mflag = ChangesList::flag( 'minor' );
738 } else {
739 $mflag = '';
740 }
741
742 // Don't show useless link to people who cannot hide revisions
743 $canHide = $wgUser->isAllowed( 'deleterevision' );
744 if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
745 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
746 $del = $this->mSkin->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
747 } else {
748 $query = array(
749 'type' => 'revision',
750 'target' => $page->getPrefixedDbkey(),
751 'ids' => $rev->getId()
752 );
753 $del = $this->mSkin->revDeleteLink( $query,
754 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
755 }
756 $del .= ' ';
757 } else {
758 $del = '';
759 }
760
761 $diffHistLinks = '(' . $difftext . $this->messages['pipe-separator'] . $histlink . ')';
762
763
764 $diffOut = ( $this->showSizeDiff ) ? ' . . '.ChangesList::showCharacterDifference( $row->rc_old_len, $row->rc_new_len ) : '';
765
766 $ret = "{$del}{$d} {$diffHistLinks} {$nflag}{$mflag} {$link}{$diffOut}{$userlink} {$comment} {$topmarktext}";
767
768 # Denote if username is redacted for this edit
769 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
770 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
771 }
772
773 # Tags, if any.
774 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'contributions' );
775 $classes = array_merge( $classes, $newClasses );
776 $ret .= " $tagSummary";
777
778 // Let extensions add data
779 wfRunHooks( 'ContributionsLineEnding', array( &$this, &$ret, $row ) );
780
781 $classes = implode( ' ', $classes );
782 $ret = "<li class=\"$classes\">$ret</li>\n";
783 wfProfileOut( __METHOD__ );
784 return $ret;
785 }
786
787 /**
788 * Get the Database object in use
789 *
790 * @return DatabaseBase
791 */
792 public function getDatabase() {
793 return $this->mDb;
794 }
795
796 /**
797 * Overwrite Pager function and return a helpful comment
798 */
799 function getSqlComment() {
800 if ( $this->namespace || $this->deletedOnly ) {
801 return 'contributions page filtered for namespace or RevisionDeleted edits'; // potentially slow, see CR r58153
802 } else {
803 return 'contributions page unfiltered';
804 }
805 }
806
807 protected function preventClickjacking() {
808 $this->preventClickjacking = true;
809 }
810
811 public function getPreventClickjacking() {
812 return $this->preventClickjacking;
813 }
814 }