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
;
55 function getQueryInfo() {
56 list( $index, $userCond ) = $this->getUserCond();
57 $conds = array_merge( $userCond, $this->getNamespaceCond() );
58 $user = $this->getUser();
59 // Paranoia: avoid brute force searches (bug 17792)
60 if ( !$user->isAllowed( 'deletedhistory' ) ) {
61 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::DELETED_USER
) . ' = 0';
62 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
63 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::SUPPRESSED_USER
) .
64 ' != ' . Revision
::SUPPRESSED_USER
;
67 'tables' => array( 'archive' ),
69 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment',
70 'ar_minor_edit', 'ar_user', 'ar_user_text', 'ar_deleted'
73 'options' => array( 'USE INDEX' => $index )
77 function getUserCond() {
80 $condition['ar_user_text'] = $this->target
;
81 $index = 'usertext_timestamp';
83 return array( $index, $condition );
86 function getIndexField() {
87 return 'ar_timestamp';
90 function getStartBody() {
94 function getEndBody() {
98 function getNavigationBar() {
99 if ( isset( $this->mNavigationBar
) ) {
100 return $this->mNavigationBar
;
104 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit
)->escaped(),
105 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit
)->escaped(),
106 'first' => $this->msg( 'histlast' )->escaped(),
107 'last' => $this->msg( 'histfirst' )->escaped()
110 $pagingLinks = $this->getPagingLinks( $linkTexts );
111 $limitLinks = $this->getLimitLinks();
112 $lang = $this->getLanguage();
113 $limits = $lang->pipeList( $limitLinks );
115 $firstLast = $lang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) );
116 $firstLast = $this->msg( 'parentheses' )->rawParams( $firstLast )->escaped();
117 $prevNext = $this->msg( 'viewprevnext' )
119 $pagingLinks['prev'],
120 $pagingLinks['next'],
123 $separator = $this->msg( 'word-separator' )->escaped();
124 $this->mNavigationBar
= $firstLast . $separator . $prevNext;
126 return $this->mNavigationBar
;
129 function getNamespaceCond() {
130 if ( $this->namespace !== '' ) {
131 return array( 'ar_namespace' => (int)$this->namespace );
138 * Generates each row in the contributions list.
140 * Contributions which are marked "top" are currently on top of the history.
141 * For these contributions, a [rollback] link is shown for users with sysop
142 * privileges. The rollback link restores the most recent version that was not
143 * written by the target user.
145 * @todo This would probably look a lot nicer in a table.
149 function formatRow( $row ) {
150 wfProfileIn( __METHOD__
);
152 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
154 $rev = new Revision( array(
156 'id' => $row->ar_rev_id
,
157 'comment' => $row->ar_comment
,
158 'user' => $row->ar_user
,
159 'user_text' => $row->ar_user_text
,
160 'timestamp' => $row->ar_timestamp
,
161 'minor_edit' => $row->ar_minor_edit
,
162 'deleted' => $row->ar_deleted
,
165 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
167 $logs = SpecialPage
::getTitleFor( 'Log' );
168 $dellog = Linker
::linkKnown(
170 $this->messages
['deletionlog'],
174 'page' => $page->getPrefixedText()
178 $reviewlink = Linker
::linkKnown(
179 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
180 $this->messages
['undeleteviewlink']
183 $user = $this->getUser();
185 if ( $user->isAllowed( 'deletedtext' ) ) {
186 $last = Linker
::linkKnown(
188 $this->messages
['diff'],
191 'target' => $page->getPrefixedText(),
192 'timestamp' => $rev->getTimestamp(),
197 $last = $this->messages
['diff'];
200 $comment = Linker
::revComment( $rev );
201 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user );
202 $date = htmlspecialchars( $date );
204 if ( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
205 $link = $date; // unusable link
207 $link = Linker
::linkKnown(
210 array( 'class' => 'mw-changeslist-date' ),
212 'target' => $page->getPrefixedText(),
213 'timestamp' => $rev->getTimestamp()
217 // Style deleted items
218 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
219 $link = '<span class="history-deleted">' . $link . '</span>';
222 $pagelink = Linker
::link(
225 array( 'class' => 'mw-changeslist-title' )
228 if ( $rev->isMinor() ) {
229 $mflag = ChangesList
::flag( 'minor' );
234 // Revision delete link
235 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
240 $tools = Html
::rawElement(
242 array( 'class' => 'mw-deletedcontribs-tools' ),
243 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
244 array( $last, $dellog, $reviewlink ) ) )->escaped()
247 $separator = '<span class="mw-changeslist-separator">. .</span>';
248 $ret = "{$del}{$link} {$tools} {$separator} {$mflag} {$pagelink} {$comment}";
250 # Denote if username is redacted for this edit
251 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
252 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
255 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
257 wfProfileOut( __METHOD__
);
262 * Get the Database object in use
264 * @return DatabaseBase
266 public function getDatabase() {
271 class DeletedContributionsPage
extends SpecialPage
{
272 function __construct() {
273 parent
::__construct( 'DeletedContributions', 'deletedhistory',
274 /*listed*/true, /*function*/false, /*file*/false );
278 * Special page "deleted user contributions".
279 * Shows a list of the deleted contributions of a user.
281 * @param string $par (optional) user name of the user for which to show the contributions
283 function execute( $par ) {
284 global $wgQueryPageDefaultLimit;
287 $this->outputHeader();
289 $user = $this->getUser();
291 if ( !$this->userCanExecute( $user ) ) {
292 $this->displayRestrictionError();
296 $request = $this->getRequest();
297 $out = $this->getOutput();
298 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
302 if ( $par !== null ) {
305 $target = $request->getVal( 'target' );
308 if ( !strlen( $target ) ) {
309 $out->addHTML( $this->getForm( '' ) );
313 $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit );
314 $options['target'] = $target;
316 $userObj = User
::newFromName( $target, false );
318 $out->addHTML( $this->getForm( '' ) );
321 $this->getSkin()->setRelevantUser( $userObj );
323 $target = $userObj->getName();
324 $out->addSubtitle( $this->getSubTitle( $userObj ) );
326 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
327 $options['namespace'] = intval( $ns );
329 $options['namespace'] = '';
332 $out->addHTML( $this->getForm( $options ) );
334 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
335 if ( !$pager->getNumRows() ) {
336 $out->addWikiMsg( 'nocontribs' );
340 # Show a message about slave lag, if applicable
341 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
343 $out->showLagWarning( $lag );
347 '<p>' . $pager->getNavigationBar() . '</p>' .
349 '<p>' . $pager->getNavigationBar() . '</p>' );
351 # If there were contributions, and it was a valid user or IP, show
352 # the appropriate "footer" message - WHOIS tools, etc.
353 if ( $target != 'newbies' ) {
354 $message = IP
::isIPAddress( $target )
355 ?
'sp-contributions-footer-anon'
356 : 'sp-contributions-footer';
358 if ( !$this->msg( $message )->isDisabled() ) {
360 "<div class='mw-contributions-footer'>\n$1\n</div>",
361 array( $message, $target )
368 * Generates the subheading with links
369 * @param $userObj User object for the target
370 * @return String: appropriately-escaped HTML to be output literally
371 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
373 function getSubTitle( $userObj ) {
374 if ( $userObj->isAnon() ) {
375 $user = htmlspecialchars( $userObj->getName() );
377 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
380 $nt = $userObj->getUserPage();
381 $id = $userObj->getID();
382 $talk = $nt->getTalkPage();
385 $tools[] = Linker
::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
386 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
387 # Block / Change block / Unblock links
388 if ( $this->getUser()->isAllowed( 'block' ) ) {
389 if ( $userObj->isBlocked() ) {
390 $tools[] = Linker
::linkKnown( # Change block link
391 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
392 $this->msg( 'change-blocklink' )->escaped()
394 $tools[] = Linker
::linkKnown( # Unblock link
395 SpecialPage
::getTitleFor( 'BlockList' ),
396 $this->msg( 'unblocklink' )->escaped(),
399 'action' => 'unblock',
400 'ip' => $nt->getDBkey()
404 # User is not blocked
405 $tools[] = Linker
::linkKnown( # Block link
406 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
407 $this->msg( 'blocklink' )->escaped()
412 $tools[] = Linker
::linkKnown(
413 SpecialPage
::getTitleFor( 'Log' ),
414 $this->msg( 'sp-contributions-blocklog' )->escaped(),
418 'page' => $nt->getPrefixedText()
424 $tools[] = Linker
::linkKnown(
425 SpecialPage
::getTitleFor( 'Listfiles', $userObj->getName() ),
426 $this->msg( 'sp-contributions-uploads' )->escaped()
430 $tools[] = Linker
::linkKnown(
431 SpecialPage
::getTitleFor( 'Log' ),
432 $this->msg( 'sp-contributions-logs' )->escaped(),
434 array( 'user' => $nt->getText() )
436 # Link to contributions
437 $tools[] = Linker
::linkKnown(
438 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
439 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
442 # Add a link to change user rights for privileged users
443 $userrightsPage = new UserrightsPage();
444 $userrightsPage->setContext( $this->getContext() );
445 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
446 $tools[] = Linker
::linkKnown(
447 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
448 $this->msg( 'sp-contributions-userrights' )->escaped()
452 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
454 $links = $this->getLanguage()->pipeList( $tools );
456 // Show a note if the user is blocked and display the last block log entry.
457 if ( $userObj->isBlocked() ) {
458 // LogEventsList::showLogExtract() wants the first parameter by ref
459 $out = $this->getOutput();
460 LogEventsList
::showLogExtract(
467 'showIfEmpty' => false,
469 'sp-contributions-blocked-notice',
470 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
472 'offset' => '' # don't use $this->getRequest() parameter offset
478 // Old message 'contribsub' had one parameter, but that doesn't work for
479 // languages that want to put the "for" bit right after $user but before
480 // $links. If 'contribsub' is around, use it for reverse compatibility,
481 // otherwise use 'contribsub2'.
482 $oldMsg = $this->msg( 'contribsub' );
483 if ( $oldMsg->exists() ) {
484 return $oldMsg->rawParams( "$user ($links)" );
487 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
491 * Generates the namespace selector form with hidden attributes.
492 * @param array $options the options to be included.
495 function getForm( $options ) {
498 $options['title'] = $this->getTitle()->getPrefixedText();
499 if ( !isset( $options['target'] ) ) {
500 $options['target'] = '';
502 $options['target'] = str_replace( '_', ' ', $options['target'] );
505 if ( !isset( $options['namespace'] ) ) {
506 $options['namespace'] = '';
509 if ( !isset( $options['contribs'] ) ) {
510 $options['contribs'] = 'user';
513 if ( $options['contribs'] == 'newbie' ) {
514 $options['target'] = '';
517 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
519 foreach ( $options as $name => $value ) {
520 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
523 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
526 $f .= Xml
::openElement( 'fieldset' );
527 $f .= Xml
::element( 'legend', array(), $this->msg( 'sp-contributions-search' )->text() );
530 array( 'for' => 'target' ),
531 $this->msg( 'sp-contributions-username' )->parse()
540 ) +
( $options['target'] ?
array() : array( 'autofocus' ) )
542 $f .= Html
::namespaceSelector(
544 'selected' => $options['namespace'],
546 'label' => $this->msg( 'namespace' )->text()
549 'name' => 'namespace',
551 'class' => 'namespaceselector',
554 $f .= Xml
::submitButton( $this->msg( 'sp-contributions-submit' )->text() );
555 $f .= Xml
::closeElement( 'fieldset' );
556 $f .= Xml
::closeElement( 'form' );
561 protected function getGroupName() {