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