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