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