3 * Implements Special:DeletedContributions
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.
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.
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
21 * @ingroup SpecialPage
25 * Implements Special:DeletedContributions to display archived revisions
26 * @ingroup SpecialPage
28 class DeletedContribsPager
extends IndexPager
{
29 public $mDefaultDirection = true;
30 var $messages, $target;
31 var $namespace = '', $mDb;
34 * @var string Navigation bar with paging links.
36 protected $mNavigationBar;
38 function __construct( IContextSource
$context, $target, $namespace = false ) {
39 parent
::__construct( $context );
40 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
41 foreach ( $msgs as $msg ) {
42 $this->messages
[$msg] = $this->msg( $msg )->escaped();
44 $this->target
= $target;
45 $this->namespace = $namespace;
46 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
49 function getDefaultQuery() {
50 $query = parent
::getDefaultQuery();
51 $query['target'] = $this->target
;
56 function getQueryInfo() {
57 list( $index, $userCond ) = $this->getUserCond();
58 $conds = array_merge( $userCond, $this->getNamespaceCond() );
59 $user = $this->getUser();
60 // Paranoia: avoid brute force searches (bug 17792)
61 if ( !$user->isAllowed( 'deletedhistory' ) ) {
62 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::DELETED_USER
) . ' = 0';
63 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
64 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::SUPPRESSED_USER
) .
65 ' != ' . Revision
::SUPPRESSED_USER
;
69 'tables' => array( 'archive' ),
71 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment',
72 'ar_minor_edit', 'ar_user', 'ar_user_text', 'ar_deleted'
75 'options' => array( 'USE INDEX' => $index )
79 function getUserCond() {
82 $condition['ar_user_text'] = $this->target
;
83 $index = 'usertext_timestamp';
85 return array( $index, $condition );
88 function getIndexField() {
89 return 'ar_timestamp';
92 function getStartBody() {
96 function getEndBody() {
100 function getNavigationBar() {
101 if ( isset( $this->mNavigationBar
) ) {
102 return $this->mNavigationBar
;
106 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit
)->escaped(),
107 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit
)->escaped(),
108 'first' => $this->msg( 'histlast' )->escaped(),
109 'last' => $this->msg( 'histfirst' )->escaped()
112 $pagingLinks = $this->getPagingLinks( $linkTexts );
113 $limitLinks = $this->getLimitLinks();
114 $lang = $this->getLanguage();
115 $limits = $lang->pipeList( $limitLinks );
117 $firstLast = $lang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) );
118 $firstLast = $this->msg( 'parentheses' )->rawParams( $firstLast )->escaped();
119 $prevNext = $this->msg( 'viewprevnext' )
121 $pagingLinks['prev'],
122 $pagingLinks['next'],
125 $separator = $this->msg( 'word-separator' )->escaped();
126 $this->mNavigationBar
= $firstLast . $separator . $prevNext;
128 return $this->mNavigationBar
;
131 function getNamespaceCond() {
132 if ( $this->namespace !== '' ) {
133 return array( 'ar_namespace' => (int)$this->namespace );
140 * Generates each row in the contributions list.
142 * Contributions which are marked "top" are currently on top of the history.
143 * For these contributions, a [rollback] link is shown for users with sysop
144 * privileges. The rollback link restores the most recent version that was not
145 * written by the target user.
147 * @todo This would probably look a lot nicer in a table.
151 function formatRow( $row ) {
152 wfProfileIn( __METHOD__
);
154 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
156 $rev = new Revision( array(
158 'id' => $row->ar_rev_id
,
159 'comment' => $row->ar_comment
,
160 'user' => $row->ar_user
,
161 'user_text' => $row->ar_user_text
,
162 'timestamp' => $row->ar_timestamp
,
163 'minor_edit' => $row->ar_minor_edit
,
164 'deleted' => $row->ar_deleted
,
167 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
169 $logs = SpecialPage
::getTitleFor( 'Log' );
170 $dellog = Linker
::linkKnown(
172 $this->messages
['deletionlog'],
176 'page' => $page->getPrefixedText()
180 $reviewlink = Linker
::linkKnown(
181 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
182 $this->messages
['undeleteviewlink']
185 $user = $this->getUser();
187 if ( $user->isAllowed( 'deletedtext' ) ) {
188 $last = Linker
::linkKnown(
190 $this->messages
['diff'],
193 'target' => $page->getPrefixedText(),
194 'timestamp' => $rev->getTimestamp(),
199 $last = $this->messages
['diff'];
202 $comment = Linker
::revComment( $rev );
203 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user );
204 $date = htmlspecialchars( $date );
206 if ( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
207 $link = $date; // unusable link
209 $link = Linker
::linkKnown(
212 array( 'class' => 'mw-changeslist-date' ),
214 'target' => $page->getPrefixedText(),
215 'timestamp' => $rev->getTimestamp()
219 // Style deleted items
220 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
221 $link = '<span class="history-deleted">' . $link . '</span>';
224 $pagelink = Linker
::link(
227 array( 'class' => 'mw-changeslist-title' )
230 if ( $rev->isMinor() ) {
231 $mflag = ChangesList
::flag( 'minor' );
236 // Revision delete link
237 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
242 $tools = Html
::rawElement(
244 array( 'class' => 'mw-deletedcontribs-tools' ),
245 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
246 array( $last, $dellog, $reviewlink ) ) )->escaped()
249 $separator = '<span class="mw-changeslist-separator">. .</span>';
250 $ret = "{$del}{$link} {$tools} {$separator} {$mflag} {$pagelink} {$comment}";
252 # Denote if username is redacted for this edit
253 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
254 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
257 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
259 wfProfileOut( __METHOD__
);
265 * Get the Database object in use
267 * @return DatabaseBase
269 public function getDatabase() {
274 class DeletedContributionsPage
extends SpecialPage
{
275 function __construct() {
276 parent
::__construct( 'DeletedContributions', 'deletedhistory',
277 /*listed*/true, /*function*/false, /*file*/false );
281 * Special page "deleted user contributions".
282 * Shows a list of the deleted contributions of a user.
284 * @param string $par (optional) user name of the user for which to show the contributions
286 function execute( $par ) {
287 global $wgQueryPageDefaultLimit;
290 $this->outputHeader();
292 $user = $this->getUser();
294 if ( !$this->userCanExecute( $user ) ) {
295 $this->displayRestrictionError();
300 $request = $this->getRequest();
301 $out = $this->getOutput();
302 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
306 if ( $par !== null ) {
309 $target = $request->getVal( 'target' );
312 if ( !strlen( $target ) ) {
313 $out->addHTML( $this->getForm( '' ) );
318 $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit );
319 $options['target'] = $target;
321 $userObj = User
::newFromName( $target, false );
323 $out->addHTML( $this->getForm( '' ) );
327 $this->getSkin()->setRelevantUser( $userObj );
329 $target = $userObj->getName();
330 $out->addSubtitle( $this->getSubTitle( $userObj ) );
332 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
333 $options['namespace'] = intval( $ns );
335 $options['namespace'] = '';
338 $out->addHTML( $this->getForm( $options ) );
340 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
341 if ( !$pager->getNumRows() ) {
342 $out->addWikiMsg( 'nocontribs' );
347 # Show a message about slave lag, if applicable
348 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
350 $out->showLagWarning( $lag );
354 '<p>' . $pager->getNavigationBar() . '</p>' .
356 '<p>' . $pager->getNavigationBar() . '</p>' );
358 # If there were contributions, and it was a valid user or IP, show
359 # the appropriate "footer" message - WHOIS tools, etc.
360 if ( $target != 'newbies' ) {
361 $message = IP
::isIPAddress( $target )
362 ?
'sp-contributions-footer-anon'
363 : 'sp-contributions-footer';
365 if ( !$this->msg( $message )->isDisabled() ) {
367 "<div class='mw-contributions-footer'>\n$1\n</div>",
368 array( $message, $target )
375 * Generates the subheading with links
376 * @param $userObj User object for the target
377 * @return String: appropriately-escaped HTML to be output literally
378 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
380 function getSubTitle( $userObj ) {
381 if ( $userObj->isAnon() ) {
382 $user = htmlspecialchars( $userObj->getName() );
384 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
387 $nt = $userObj->getUserPage();
388 $id = $userObj->getID();
389 $talk = $nt->getTalkPage();
392 $tools[] = Linker
::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
393 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
394 # Block / Change block / Unblock links
395 if ( $this->getUser()->isAllowed( 'block' ) ) {
396 if ( $userObj->isBlocked() ) {
397 $tools[] = Linker
::linkKnown( # Change block link
398 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
399 $this->msg( 'change-blocklink' )->escaped()
401 $tools[] = Linker
::linkKnown( # Unblock link
402 SpecialPage
::getTitleFor( 'BlockList' ),
403 $this->msg( 'unblocklink' )->escaped(),
406 'action' => 'unblock',
407 'ip' => $nt->getDBkey()
411 # User is not blocked
412 $tools[] = Linker
::linkKnown( # Block link
413 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
414 $this->msg( 'blocklink' )->escaped()
419 $tools[] = Linker
::linkKnown(
420 SpecialPage
::getTitleFor( 'Log' ),
421 $this->msg( 'sp-contributions-blocklog' )->escaped(),
425 'page' => $nt->getPrefixedText()
431 $tools[] = Linker
::linkKnown(
432 SpecialPage
::getTitleFor( 'Listfiles', $userObj->getName() ),
433 $this->msg( 'sp-contributions-uploads' )->escaped()
437 $tools[] = Linker
::linkKnown(
438 SpecialPage
::getTitleFor( 'Log' ),
439 $this->msg( 'sp-contributions-logs' )->escaped(),
441 array( 'user' => $nt->getText() )
443 # Link to contributions
444 $tools[] = Linker
::linkKnown(
445 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
446 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
449 # Add a link to change user rights for privileged users
450 $userrightsPage = new UserrightsPage();
451 $userrightsPage->setContext( $this->getContext() );
452 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
453 $tools[] = Linker
::linkKnown(
454 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
455 $this->msg( 'sp-contributions-userrights' )->escaped()
459 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
461 $links = $this->getLanguage()->pipeList( $tools );
463 // Show a note if the user is blocked and display the last block log entry.
464 if ( $userObj->isBlocked() ) {
465 // LogEventsList::showLogExtract() wants the first parameter by ref
466 $out = $this->getOutput();
467 LogEventsList
::showLogExtract(
474 'showIfEmpty' => false,
476 'sp-contributions-blocked-notice',
477 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
479 'offset' => '' # don't use $this->getRequest() parameter offset
485 // Old message 'contribsub' had one parameter, but that doesn't work for
486 // languages that want to put the "for" bit right after $user but before
487 // $links. If 'contribsub' is around, use it for reverse compatibility,
488 // otherwise use 'contribsub2'.
489 $oldMsg = $this->msg( 'contribsub' );
490 if ( $oldMsg->exists() ) {
491 return $oldMsg->rawParams( "$user ($links)" );
494 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
498 * Generates the namespace selector form with hidden attributes.
499 * @param array $options the options to be included.
502 function getForm( $options ) {
505 $options['title'] = $this->getTitle()->getPrefixedText();
506 if ( !isset( $options['target'] ) ) {
507 $options['target'] = '';
509 $options['target'] = str_replace( '_', ' ', $options['target'] );
512 if ( !isset( $options['namespace'] ) ) {
513 $options['namespace'] = '';
516 if ( !isset( $options['contribs'] ) ) {
517 $options['contribs'] = 'user';
520 if ( $options['contribs'] == 'newbie' ) {
521 $options['target'] = '';
524 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
526 foreach ( $options as $name => $value ) {
527 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
530 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
533 $f .= Xml
::openElement( 'fieldset' );
534 $f .= Xml
::element( 'legend', array(), $this->msg( 'sp-contributions-search' )->text() );
537 array( 'for' => 'target' ),
538 $this->msg( 'sp-contributions-username' )->parse()
547 ) +
( $options['target'] ?
array() : array( 'autofocus' ) )
549 $f .= Html
::namespaceSelector(
551 'selected' => $options['namespace'],
553 'label' => $this->msg( 'namespace' )->text()
556 'name' => 'namespace',
558 'class' => 'namespaceselector',
561 $f .= Xml
::submitButton( $this->msg( 'sp-contributions-submit' )->text() );
562 $f .= Xml
::closeElement( 'fieldset' );
563 $f .= Xml
::closeElement( 'form' );
568 protected function getGroupName() {