Fix fixme on r107328, attempting to use $this in a static method
[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 $this->setHeaders();
40 $this->outputHeader();
41 $out = $this->getOutput();
42 $out->addModuleStyles( 'mediawiki.special' );
43
44 $this->opts = array();
45 $request = $this->getRequest();
46
47 if ( $par == 'newbies' ) {
48 $target = 'newbies';
49 $this->opts['contribs'] = 'newbie';
50 } elseif ( $par !== null ) {
51 $target = $par;
52 } else {
53 $target = $request->getVal( 'target' );
54 }
55
56 // check for radiobox
57 if ( $request->getVal( 'contribs' ) == 'newbie' ) {
58 $target = 'newbies';
59 $this->opts['contribs'] = 'newbie';
60 } else {
61 $this->opts['contribs'] = 'user';
62 }
63
64 $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
65
66 if ( !strlen( $target ) ) {
67 $out->addHTML( $this->getForm() );
68 return;
69 }
70
71 $user = $this->getUser();
72
73 $this->opts['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
74 $this->opts['target'] = $target;
75 $this->opts['topOnly'] = $request->getBool( 'topOnly' );
76
77 $userObj = User::newFromName( $target, false );
78 if ( !$userObj ) {
79 $out->addHTML( $this->getForm() );
80 return;
81 }
82 $nt = $userObj->getUserPage();
83 $id = $userObj->getID();
84
85 if ( $this->opts['contribs'] != 'newbie' ) {
86 $target = $nt->getText();
87 $out->addSubtitle( $this->contributionsSub( $userObj ) );
88 $out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'contributions-title', $target )->plain() ) );
89 $this->getSkin()->setRelevantUser( $userObj );
90 } else {
91 $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) );
92 $out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'sp-contributions-newbies-title' )->plain() ) );
93 }
94
95 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
96 $this->opts['namespace'] = intval( $ns );
97 } else {
98 $this->opts['namespace'] = '';
99 }
100
101 $this->opts['associated'] = $request->getBool( 'associated' );
102
103 $this->opts['nsInvert'] = (bool) $request->getVal( 'nsInvert' );
104
105 $this->opts['tagfilter'] = (string) $request->getVal( 'tagfilter' );
106
107 // Allows reverts to have the bot flag in recent changes. It is just here to
108 // be passed in the form at the top of the page
109 if ( $user->isAllowed( 'markbotedits' ) && $request->getBool( 'bot' ) ) {
110 $this->opts['bot'] = '1';
111 }
112
113 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
114 # Offset overrides year/month selection
115 if ( $skip ) {
116 $this->opts['year'] = '';
117 $this->opts['month'] = '';
118 } else {
119 $this->opts['year'] = $request->getIntOrNull( 'year' );
120 $this->opts['month'] = $request->getIntOrNull( 'month' );
121 }
122
123 $feedType = $request->getVal( 'feed' );
124 if ( $feedType ) {
125 // Maintain some level of backwards compatability
126 // If people request feeds using the old parameters, redirect to API
127 $apiParams = array(
128 'action' => 'feedcontributions',
129 'feedformat' => $feedType,
130 'user' => $target,
131 );
132 if ( $this->opts['topOnly'] ) {
133 $apiParams['toponly'] = true;
134 }
135 if ( $this->opts['deletedOnly'] ) {
136 $apiParams['deletedonly'] = true;
137 }
138 if ( $this->opts['tagfilter'] !== '' ) {
139 $apiParams['tagfilter'] = $this->opts['tagfilter'];
140 }
141 if ( $this->opts['namespace'] !== '' ) {
142 $apiParams['namespace'] = $this->opts['namespace'];
143 }
144 if ( $this->opts['year'] !== null ) {
145 $apiParams['year'] = $this->opts['year'];
146 }
147 if ( $this->opts['month'] !== null ) {
148 $apiParams['month'] = $this->opts['month'];
149 }
150
151 $url = wfScript( 'api' ) . '?' . wfArrayToCGI( $apiParams );
152
153 $out->redirect( $url, '301' );
154 return;
155 }
156
157 // Add RSS/atom links
158 $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) );
159
160 if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
161
162 $out->addHTML( $this->getForm() );
163
164 $pager = new ContribsPager( $this->getContext(), array(
165 'target' => $target,
166 'contribs' => $this->opts['contribs'],
167 'namespace' => $this->opts['namespace'],
168 'year' => $this->opts['year'],
169 'month' => $this->opts['month'],
170 'deletedOnly' => $this->opts['deletedOnly'],
171 'topOnly' => $this->opts['topOnly'],
172 'nsInvert' => $this->opts['nsInvert'],
173 'associated' => $this->opts['associated'],
174 ) );
175 if ( !$pager->getNumRows() ) {
176 $out->addWikiMsg( 'nocontribs', $target );
177 } else {
178 # Show a message about slave lag, if applicable
179 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
180 if ( $lag > 0 )
181 $out->showLagWarning( $lag );
182
183 $out->addHTML(
184 '<p>' . $pager->getNavigationBar() . '</p>' .
185 $pager->getBody() .
186 '<p>' . $pager->getNavigationBar() . '</p>'
187 );
188 }
189 $out->preventClickjacking( $pager->getPreventClickjacking() );
190
191 # Show the appropriate "footer" message - WHOIS tools, etc.
192 if ( $this->opts['contribs'] != 'newbie' ) {
193 $message = 'sp-contributions-footer';
194 if ( IP::isIPAddress( $target ) ) {
195 $message = 'sp-contributions-footer-anon';
196 } else {
197 if ( $userObj->isAnon() ) {
198 // No message for non-existing users
199 return;
200 }
201 }
202
203 if ( !$this->msg( $message, $target )->isDisabled() ) {
204 $out->wrapWikiMsg(
205 "<div class='mw-contributions-footer'>\n$1\n</div>",
206 array( $message, $target ) );
207 }
208 }
209 }
210 }
211
212 /**
213 * Generates the subheading with links
214 * @param $userObj User object for the target
215 * @return String: appropriately-escaped HTML to be output literally
216 * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
217 */
218 protected function contributionsSub( $userObj ) {
219 if ( $userObj->isAnon() ) {
220 $user = htmlspecialchars( $userObj->getName() );
221 } else {
222 $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
223 }
224 $nt = $userObj->getUserPage();
225 $talk = $userObj->getTalkPage();
226 if ( $talk ) {
227 $tools = $this->getUserLinks( $nt, $talk, $userObj, $this->getUser() );
228 $links = $this->getLanguage()->pipeList( $tools );
229
230 // Show a note if the user is blocked and display the last block log entry.
231 if ( $userObj->isBlocked() ) {
232 $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
233 LogEventsList::showLogExtract(
234 $out,
235 'block',
236 $nt,
237 '',
238 array(
239 'lim' => 1,
240 'showIfEmpty' => false,
241 'msgKey' => array(
242 $userObj->isAnon() ?
243 'sp-contributions-blocked-notice-anon' :
244 'sp-contributions-blocked-notice',
245 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
246 ),
247 'offset' => '' # don't use WebRequest parameter offset
248 )
249 );
250 }
251 }
252
253 // Old message 'contribsub' had one parameter, but that doesn't work for
254 // languages that want to put the "for" bit right after $user but before
255 // $links. If 'contribsub' is around, use it for reverse compatibility,
256 // otherwise use 'contribsub2'.
257 $oldMsg = $this->msg( 'contribsub' );
258 if ( $oldMsg->exists() ) {
259 return $oldMsg->rawParams( "$user ($links)" );
260 } else {
261 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
262 }
263 }
264
265 /**
266 * Links to different places.
267 * @param $userpage Title: Target user page
268 * @param $talkpage Title: Talk page
269 * @param $target User: Target user object
270 * @param $subject User: The viewing user ($wgUser might be still checked in some cases)
271 * @return array
272 */
273 public function getUserLinks( Title $userpage, Title $talkpage, User $target, User $subject ) {
274
275 $id = $target->getId();
276 $username = $target->getName();
277
278 $tools[] = Linker::link( $talkpage, $this->msg( 'sp-contributions-talk' )->escaped() );
279
280 if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) {
281 if ( $subject->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
282 if ( $target->isBlocked() ) {
283 $tools[] = Linker::linkKnown( # Change block link
284 SpecialPage::getTitleFor( 'Block', $username ),
285 $this->msg( 'change-blocklink' )->escaped()
286 );
287 $tools[] = Linker::linkKnown( # Unblock link
288 SpecialPage::getTitleFor( 'Unblock', $username ),
289 $this->msg( 'unblocklink' )->escaped()
290 );
291 } else { # User is not blocked
292 $tools[] = Linker::linkKnown( # Block link
293 SpecialPage::getTitleFor( 'Block', $username ),
294 $this->msg( 'blocklink' )->escaped()
295 );
296 }
297 }
298 # Block log link
299 $tools[] = Linker::linkKnown(
300 SpecialPage::getTitleFor( 'Log', 'block' ),
301 $this->msg( 'sp-contributions-blocklog' )->escaped(),
302 array(),
303 array(
304 'page' => $userpage->getPrefixedText()
305 )
306 );
307 }
308 # Uploads
309 $tools[] = Linker::linkKnown(
310 SpecialPage::getTitleFor( 'Listfiles', $username ),
311 $this->msg( 'sp-contributions-uploads' )->escaped()
312 );
313
314 # Other logs link
315 $tools[] = Linker::linkKnown(
316 SpecialPage::getTitleFor( 'Log', $username ),
317 $this->msg( 'sp-contributions-logs' )->escaped()
318 );
319
320 # Add link to deleted user contributions for priviledged users
321 if ( $subject->isAllowed( 'deletedhistory' ) ) {
322 $tools[] = Linker::linkKnown(
323 SpecialPage::getTitleFor( 'DeletedContributions', $username ),
324 $this->msg( 'sp-contributions-deleted' )->escaped()
325 );
326 }
327
328 # Add a link to change user rights for privileged users
329 $userrightsPage = new UserrightsPage();
330 $userrightsPage->getContext()->setUser( $subject );
331 if ( $id !== null && $userrightsPage->userCanChangeRights( $target ) ) {
332 $tools[] = Linker::linkKnown(
333 SpecialPage::getTitleFor( 'Userrights', $username ),
334 $this->msg( 'sp-contributions-userrights' )->escaped()
335 );
336 }
337
338 wfRunHooks( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) );
339 return $tools;
340 }
341
342 /**
343 * Generates the namespace selector form with hidden attributes.
344 * @return String: HTML fragment
345 */
346 protected function getForm() {
347 global $wgScript;
348
349 $this->opts['title'] = $this->getTitle()->getPrefixedText();
350 if ( !isset( $this->opts['target'] ) ) {
351 $this->opts['target'] = '';
352 } else {
353 $this->opts['target'] = str_replace( '_' , ' ' , $this->opts['target'] );
354 }
355
356 if ( !isset( $this->opts['namespace'] ) ) {
357 $this->opts['namespace'] = '';
358 }
359
360 if ( !isset( $this->opts['nsInvert'] ) ) {
361 $this->opts['nsInvert'] = '';
362 }
363
364 if ( !isset( $this->opts['associated'] ) ) {
365 $this->opts['associated'] = false;
366 }
367
368 if ( !isset( $this->opts['contribs'] ) ) {
369 $this->opts['contribs'] = 'user';
370 }
371
372 if ( !isset( $this->opts['year'] ) ) {
373 $this->opts['year'] = '';
374 }
375
376 if ( !isset( $this->opts['month'] ) ) {
377 $this->opts['month'] = '';
378 }
379
380 if ( $this->opts['contribs'] == 'newbie' ) {
381 $this->opts['target'] = '';
382 }
383
384 if ( !isset( $this->opts['tagfilter'] ) ) {
385 $this->opts['tagfilter'] = '';
386 }
387
388 if ( !isset( $this->opts['topOnly'] ) ) {
389 $this->opts['topOnly'] = false;
390 }
391
392 $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) );
393
394 # Add hidden params for tracking except for parameters in $skipParameters
395 $skipParameters = array( 'namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly', 'associated' );
396 foreach ( $this->opts as $name => $value ) {
397 if ( in_array( $name, $skipParameters ) ) {
398 continue;
399 }
400 $form .= "\t" . Html::hidden( $name, $value ) . "\n";
401 }
402
403 $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] );
404
405 if ( $tagFilter ) {
406 $filterSelection =
407 Xml::tags( 'td', array( 'class' => 'mw-label' ), array_shift( $tagFilter ) ) .
408 Xml::tags( 'td', array( 'class' => 'mw-input' ), implode( '&#160', $tagFilter ) );
409 } else {
410 $filterSelection = Xml::tags( 'td', array( 'colspan' => 2 ), '' );
411 }
412
413 $targetSelection = Xml::tags( 'td', array( 'colspan' => 2 ),
414 Xml::radioLabel(
415 $this->msg( 'sp-contributions-newbies' )->text(),
416 'contribs',
417 'newbie' ,
418 'newbie',
419 $this->opts['contribs'] == 'newbie',
420 array( 'class' => 'mw-input' )
421 ) . '<br />' .
422 Xml::radioLabel(
423 $this->msg( 'sp-contributions-username' )->text(),
424 'contribs',
425 'user',
426 'user',
427 $this->opts['contribs'] == 'user',
428 array( 'class' => 'mw-input' )
429 ) . ' ' .
430 Html::input(
431 'target',
432 $this->opts['target'],
433 'text',
434 array( 'size' => '20', 'required' => '', 'class' => 'mw-input' ) +
435 ( $this->opts['target'] ? array() : array( 'autofocus' )
436 )
437 ) . ' '
438 ) ;
439
440 $namespaceSelection =
441 Xml::tags( 'td', array( 'class' => 'mw-label' ),
442 Xml::label(
443 $this->msg( 'namespace' )->text(),
444 'namespace',
445 ''
446 )
447 ) .
448 Xml::tags( 'td', null,
449 Xml::namespaceSelector( $this->opts['namespace'], '' ) . '&#160;' .
450 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
451 Xml::checkLabel(
452 $this->msg( 'invert' )->text(),
453 'nsInvert',
454 'nsInvert',
455 $this->opts['nsInvert'],
456 array( 'title' => $this->msg( 'tooltip-invert' )->text(), 'class' => 'mw-input' )
457 ) . '&#160;'
458 ) .
459 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
460 Xml::checkLabel(
461 $this->msg( 'namespace_association' )->text(),
462 'associated',
463 'associated',
464 $this->opts['associated'],
465 array( 'title' => $this->msg( 'tooltip-namespace_association' )->text(), 'class' => 'mw-input' )
466 ) . '&#160;'
467 )
468 ) ;
469
470 $extraOptions = Xml::tags( 'td', array( 'colspan' => 2 ),
471 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
472 Xml::checkLabel(
473 $this->msg( 'history-show-deleted' )->text(),
474 'deletedOnly',
475 'mw-show-deleted-only',
476 $this->opts['deletedOnly'],
477 array( 'class' => 'mw-input' )
478 )
479 ) .
480 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
481 Xml::checkLabel(
482 $this->msg( 'sp-contributions-toponly' )->text(),
483 'topOnly',
484 'mw-show-top-only',
485 $this->opts['topOnly'],
486 array( 'class' => 'mw-input' )
487 )
488 )
489 ) ;
490
491 $dateSelectionAndSubmit = Xml::tags( 'td', array( 'colspan' => 2 ),
492 Xml::dateMenu(
493 $this->opts['year'],
494 $this->opts['month']
495 ) . ' ' .
496 Xml::submitButton(
497 $this->msg( 'sp-contributions-submit' )->text(),
498 array( 'class' => 'mw-submit' )
499 )
500 ) ;
501
502 $form .=
503 Xml::fieldset( $this->msg( 'sp-contributions-search' )->text() ) .
504 Xml::openElement( 'table', array( 'class' => 'mw-contributions-table' ) ) .
505 Xml::openElement( 'tr' ) .
506 $targetSelection .
507 Xml::closeElement( 'tr' ) .
508 Xml::openElement( 'tr' ) .
509 $namespaceSelection .
510 Xml::closeElement( 'tr' ) .
511 Xml::openElement( 'tr' ) .
512 $filterSelection .
513 Xml::closeElement( 'tr' ) .
514 Xml::openElement( 'tr' ) .
515 $extraOptions .
516 Xml::closeElement( 'tr' ) .
517 Xml::openElement( 'tr' ) .
518 $dateSelectionAndSubmit .
519 Xml::closeElement( 'tr' ) .
520 Xml::closeElement( 'table' );
521
522 $explain = $this->msg( 'sp-contributions-explain' );
523 if ( $explain->exists() ) {
524 $form .= "<p id='mw-sp-contributions-explain'>{$explain}</p>";
525 }
526 $form .= Xml::closeElement( 'fieldset' ) .
527 Xml::closeElement( 'form' );
528 return $form;
529 }
530 }
531
532 /**
533 * Pager for Special:Contributions
534 * @ingroup SpecialPage Pager
535 */
536 class ContribsPager extends ReverseChronologicalPager {
537 public $mDefaultDirection = true;
538 var $messages, $target;
539 var $namespace = '', $mDb;
540 var $preventClickjacking = false;
541
542 function __construct( IContextSource $context, array $options ) {
543 parent::__construct( $context );
544
545 $msgs = array( 'uctop', 'diff', 'newarticle', 'rollbacklink', 'diff', 'hist', 'rev-delundel', 'pipe-separator' );
546
547 foreach ( $msgs as $msg ) {
548 $this->messages[$msg] = $this->msg( $msg )->escaped();
549 }
550
551 $this->target = isset( $options['target'] ) ? $options['target'] : '';
552 $this->contribs = isset( $options['contribs'] ) ? $options['contribs'] : 'users';
553 $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
554 $this->tagFilter = isset( $options['tagfilter'] ) ? $options['tagfilter'] : false;
555 $this->nsInvert = isset( $options['nsInvert'] ) ? $options['nsInvert'] : false;
556 $this->associated = isset( $options['associated'] ) ? $options['associated'] : false;
557
558 $this->deletedOnly = !empty( $options['deletedOnly'] );
559 $this->topOnly = !empty( $options['topOnly'] );
560
561 $year = isset( $options['year'] ) ? $options['year'] : false;
562 $month = isset( $options['month'] ) ? $options['month'] : false;
563 $this->getDateCond( $year, $month );
564
565 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
566 }
567
568 function getDefaultQuery() {
569 $query = parent::getDefaultQuery();
570 $query['target'] = $this->target;
571 return $query;
572 }
573
574 function getQueryInfo() {
575 list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
576
577 $user = $this->getUser();
578 $conds = array_merge( $userCond, $this->getNamespaceCond() );
579
580 // Paranoia: avoid brute force searches (bug 17342)
581 if ( !$user->isAllowed( 'deletedhistory' ) ) {
582 $conds[] = $this->mDb->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0';
583 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
584 $conds[] = $this->mDb->bitAnd( 'rev_deleted', Revision::SUPPRESSED_USER ) .
585 ' != ' . Revision::SUPPRESSED_USER;
586 }
587
588 # Don't include orphaned revisions
589 $join_cond['page'] = Revision::pageJoinCond();
590 # Get the current user name for accounts
591 $join_cond['user'] = Revision::userJoinCond();
592
593 $queryInfo = array(
594 'tables' => $tables,
595 'fields' => array_merge(
596 Revision::selectFields(),
597 Revision::selectUserFields(),
598 array( 'page_namespace', 'page_title', 'page_is_new',
599 'page_latest', 'page_is_redirect', 'page_len' )
600 ),
601 'conds' => $conds,
602 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ),
603 'join_conds' => $join_cond
604 );
605
606 ChangeTags::modifyDisplayQuery(
607 $queryInfo['tables'],
608 $queryInfo['fields'],
609 $queryInfo['conds'],
610 $queryInfo['join_conds'],
611 $queryInfo['options'],
612 $this->tagFilter
613 );
614
615 wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
616 return $queryInfo;
617 }
618
619 function getUserCond() {
620 $condition = array();
621 $join_conds = array();
622 $tables = array( 'revision', 'page', 'user' );
623 if ( $this->contribs == 'newbie' ) {
624 $tables[] = 'user_groups';
625 $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
626 $condition[] = 'rev_user >' . (int)( $max - $max / 100 );
627 $condition[] = 'ug_group IS NULL';
628 $index = 'user_timestamp';
629 # @todo FIXME: Other groups may have 'bot' rights
630 $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
631 } else {
632 if ( IP::isIPAddress( $this->target ) ) {
633 $condition['rev_user_text'] = $this->target;
634 $index = 'usertext_timestamp';
635 } else {
636 $condition['rev_user'] = User::idFromName( $this->target );
637 $index = 'user_timestamp';
638 }
639 }
640 if ( $this->deletedOnly ) {
641 $condition[] = "rev_deleted != '0'";
642 }
643 if ( $this->topOnly ) {
644 $condition[] = "rev_id = page_latest";
645 }
646 return array( $tables, $index, $condition, $join_conds );
647 }
648
649 function getNamespaceCond() {
650 if ( $this->namespace !== '' ) {
651 $selectedNS = $this->mDb->addQuotes( $this->namespace );
652 $eq_op = $this->nsInvert ? '!=' : '=';
653 $bool_op = $this->nsInvert ? 'AND' : 'OR';
654
655 if ( !$this->associated ) {
656 return array( "page_namespace $eq_op $selectedNS" );
657 } else {
658 $associatedNS = $this->mDb->addQuotes (
659 MWNamespace::getAssociated( $this->namespace )
660 );
661 return array(
662 "page_namespace $eq_op $selectedNS " .
663 $bool_op .
664 " page_namespace $eq_op $associatedNS"
665 );
666 }
667
668 } else {
669 return array();
670 }
671 }
672
673 function getIndexField() {
674 return 'rev_timestamp';
675 }
676
677 function doBatchLookups() {
678 $this->mResult->rewind();
679 $revIds = array();
680 foreach ( $this->mResult as $row ) {
681 $revIds[] = $row->rev_parent_id;
682 }
683 $this->mParentLens = $this->getParentLengths( $revIds );
684 $this->mResult->rewind(); // reset
685
686 if ( $this->contribs === 'newbie' ) { // multiple users
687 # Do a link batch query
688 $this->mResult->seek( 0 );
689 $batch = new LinkBatch();
690 # Give some pointers to make (last) links
691 foreach ( $this->mResult as $row ) {
692 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
693 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
694 }
695 $batch->execute();
696 $this->mResult->seek( 0 );
697 }
698 }
699
700 /**
701 * Do a batched query to get the parent revision lengths
702 */
703 private function getParentLengths( array $revIds ) {
704 $revLens = array();
705 if ( !$revIds ) {
706 return $revLens; // empty
707 }
708 wfProfileIn( __METHOD__ );
709 $res = $this->getDatabase()->select( 'revision',
710 array( 'rev_id', 'rev_len' ),
711 array( 'rev_id' => $revIds ),
712 __METHOD__ );
713 foreach ( $res as $row ) {
714 $revLens[$row->rev_id] = $row->rev_len;
715 }
716 wfProfileOut( __METHOD__ );
717 return $revLens;
718 }
719
720 /**
721 * @return string
722 */
723 function getStartBody() {
724 return "<ul>\n";
725 }
726
727 /**
728 * @return string
729 */
730 function getEndBody() {
731 return "</ul>\n";
732 }
733
734 /**
735 * Generates each row in the contributions list.
736 *
737 * Contributions which are marked "top" are currently on top of the history.
738 * For these contributions, a [rollback] link is shown for users with roll-
739 * back privileges. The rollback link restores the most recent version that
740 * was not written by the target user.
741 *
742 * @todo This would probably look a lot nicer in a table.
743 */
744 function formatRow( $row ) {
745 wfProfileIn( __METHOD__ );
746
747 $rev = new Revision( $row );
748 $classes = array();
749
750 $page = Title::newFromRow( $row );
751 $link = Linker::link(
752 $page,
753 htmlspecialchars( $page->getPrefixedText() ),
754 array(),
755 $page->isRedirect() ? array( 'redirect' => 'no' ) : array()
756 );
757 # Mark current revisions
758 $topmarktext = '';
759 if ( $row->rev_id == $row->page_latest ) {
760 $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
761 # Add rollback link
762 if ( !$row->page_is_new && $page->quickUserCan( 'rollback' )
763 && $page->quickUserCan( 'edit' ) )
764 {
765 $this->preventClickjacking();
766 $topmarktext .= ' ' . Linker::generateRollback( $rev );
767 }
768 }
769 $user = $this->getUser();
770 # Is there a visible previous revision?
771 if ( $rev->userCan( Revision::DELETED_TEXT, $user ) && $rev->getParentId() !== 0 ) {
772 $difftext = Linker::linkKnown(
773 $page,
774 $this->messages['diff'],
775 array(),
776 array(
777 'diff' => 'prev',
778 'oldid' => $row->rev_id
779 )
780 );
781 } else {
782 $difftext = $this->messages['diff'];
783 }
784 $histlink = Linker::linkKnown(
785 $page,
786 $this->messages['hist'],
787 array(),
788 array( 'action' => 'history' )
789 );
790
791 if ( isset( $this->mParentLens[$row->rev_parent_id] ) ) {
792 $chardiff = ' . . ' . ChangesList::showCharacterDifference(
793 $this->mParentLens[$row->rev_parent_id], $row->rev_len ) . ' . . ';
794 } else {
795 $chardiff = ' ';
796 }
797
798 $lang = $this->getLanguage();
799 $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true );
800 $date = $lang->userTimeAndDate( $row->rev_timestamp, $user );
801 if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
802 $d = Linker::linkKnown(
803 $page,
804 htmlspecialchars( $date ),
805 array(),
806 array( 'oldid' => intval( $row->rev_id ) )
807 );
808 } else {
809 $d = htmlspecialchars( $date );
810 }
811 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
812 $d = '<span class="history-deleted">' . $d . '</span>';
813 }
814
815 # Show user names for /newbies as there may be different users.
816 # Note that we already excluded rows with hidden user names.
817 if ( $this->contribs == 'newbie' ) {
818 $userlink = ' . . ' . Linker::userLink( $rev->getUser(), $rev->getUserText() );
819 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
820 Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
821 } else {
822 $userlink = '';
823 }
824
825 if ( $rev->getParentId() === 0 ) {
826 $nflag = ChangesList::flag( 'newpage' );
827 } else {
828 $nflag = '';
829 }
830
831 if ( $rev->isMinor() ) {
832 $mflag = ChangesList::flag( 'minor' );
833 } else {
834 $mflag = '';
835 }
836
837 // Don't show useless link to people who cannot hide revisions
838 $canHide = $user->isAllowed( 'deleterevision' );
839 if ( $canHide || ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
840 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
841 $del = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
842 } else {
843 $query = array(
844 'type' => 'revision',
845 'target' => $page->getPrefixedDbkey(),
846 'ids' => $rev->getId()
847 );
848 $del = Linker::revDeleteLink( $query,
849 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
850 }
851 $del .= ' ';
852 } else {
853 $del = '';
854 }
855
856 $diffHistLinks = '(' . $difftext . $this->messages['pipe-separator'] . $histlink . ')';
857 $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
858
859 # Denote if username is redacted for this edit
860 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
861 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
862 }
863
864 # Tags, if any.
865 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'contributions' );
866 $classes = array_merge( $classes, $newClasses );
867 $ret .= " $tagSummary";
868
869 // Let extensions add data
870 wfRunHooks( 'ContributionsLineEnding', array( &$this, &$ret, $row ) );
871
872 $classes = implode( ' ', $classes );
873 $ret = "<li class=\"$classes\">$ret</li>\n";
874 wfProfileOut( __METHOD__ );
875 return $ret;
876 }
877
878 /**
879 * Get the Database object in use
880 *
881 * @return DatabaseBase
882 */
883 public function getDatabase() {
884 return $this->mDb;
885 }
886
887 /**
888 * Overwrite Pager function and return a helpful comment
889 */
890 function getSqlComment() {
891 if ( $this->namespace || $this->deletedOnly ) {
892 return 'contributions page filtered for namespace or RevisionDeleted edits'; // potentially slow, see CR r58153
893 } else {
894 return 'contributions page unfiltered';
895 }
896 }
897
898 protected function preventClickjacking() {
899 $this->preventClickjacking = true;
900 }
901
902 public function getPreventClickjacking() {
903 return $this->preventClickjacking;
904 }
905 }