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
29 class DeletedContribsPager
extends IndexPager
{
30 public $mDefaultDirection = true;
31 var $messages, $target;
32 var $namespace = '', $mDb;
34 function __construct( $target, $namespace = false ) {
35 parent
::__construct();
36 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
37 foreach( $msgs as $msg ) {
38 $this->messages
[$msg] = wfMsgExt( $msg, array( 'escapenoentities') );
40 $this->target
= $target;
41 $this->namespace = $namespace;
42 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
45 function getDefaultQuery() {
46 $query = parent
::getDefaultQuery();
47 $query['target'] = $this->target
;
51 function getQueryInfo() {
53 list( $index, $userCond ) = $this->getUserCond();
54 $conds = array_merge( $userCond, $this->getNamespaceCond() );
55 // Paranoia: avoid brute force searches (bug 17792)
56 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
57 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::DELETED_USER
) . ' = 0';
58 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
59 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::SUPPRESSED_USER
) .
60 ' != ' . Revision
::SUPPRESSED_USER
;
63 'tables' => array( 'archive' ),
65 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
66 'ar_user', 'ar_user_text', 'ar_deleted', 'ar_len'
69 'options' => array( 'USE INDEX' => $index )
73 function getUserCond() {
76 $condition['ar_user_text'] = $this->target
;
77 $index = array( 'archive' => 'ar_usertext_timestamp' );
79 return array( $index, $condition );
82 function getIndexField() {
83 return 'ar_timestamp';
86 function getStartBody() {
90 function getEndBody() {
94 function getNavigationBar() {
97 if ( isset( $this->mNavigationBar
) ) {
98 return $this->mNavigationBar
;
100 $fmtLimit = $wgLang->formatNum( $this->mLimit
);
102 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
103 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
104 'first' => wfMsgHtml( 'histlast' ),
105 'last' => wfMsgHtml( 'histfirst' )
108 $pagingLinks = $this->getPagingLinks( $linkTexts );
109 $limitLinks = $this->getLimitLinks();
110 $limits = $wgLang->pipeList( $limitLinks );
112 $this->mNavigationBar
= "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
113 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
114 return $this->mNavigationBar
;
117 function getNamespaceCond() {
118 if ( $this->namespace !== '' ) {
119 return array( 'ar_namespace' => (int)$this->namespace );
126 * Generates each row in the contributions list.
128 * Contributions which are marked "top" are currently on top of the history.
129 * For these contributions, a [rollback] link is shown for users with sysop
130 * privileges. The rollback link restores the most recent version that was not
131 * written by the target user.
133 * @todo This would probably look a lot nicer in a table.
135 function formatRow( $row ) {
136 global $wgUser, $wgLang;
137 wfProfileIn( __METHOD__
);
139 $sk = $this->getSkin();
141 $rev = new Revision( array(
142 'id' => $row->ar_rev_id
,
143 'comment' => $row->ar_comment
,
144 'user' => $row->ar_user
,
145 'user_text' => $row->ar_user_text
,
146 'timestamp' => $row->ar_timestamp
,
147 'minor_edit' => $row->ar_minor_edit
,
148 'deleted' => $row->ar_deleted
,
151 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
153 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
155 $logs = SpecialPage
::getTitleFor( 'Log' );
156 $dellog = $sk->linkKnown(
158 $this->messages
['deletionlog'],
162 'page' => $page->getPrefixedText()
166 $reviewlink = $sk->linkKnown(
167 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
168 $this->messages
['undeleteviewlink']
171 if( $wgUser->isAllowed('deletedtext') ) {
172 $last = $sk->linkKnown(
174 $this->messages
['diff'],
177 'target' => $page->getPrefixedText(),
178 'timestamp' => $rev->getTimestamp(),
183 $last = $this->messages
['diff'];
186 $comment = $sk->revComment( $rev );
187 $date = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
189 if( !$wgUser->isAllowed('undelete') ||
!$rev->userCan(Revision
::DELETED_TEXT
) ) {
190 $link = $date; // unusable link
192 $link = $sk->linkKnown(
197 'target' => $page->getPrefixedText(),
198 'timestamp' => $rev->getTimestamp()
202 // Style deleted items
203 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
204 $link = '<span class="history-deleted">' . $link . '</span>';
207 $pagelink = $sk->link( $page );
209 if( $rev->isMinor() ) {
210 $mflag = ChangesList
::flag( 'minor' );
215 // Revision delete link
216 $canHide = $wgUser->isAllowed( 'deleterevision' );
217 if( $canHide ||
($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
218 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
219 $del = $this->mSkin
->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
223 'target' => $page->getPrefixedDbkey(),
224 'ids' => $rev->getTimestamp() );
225 $del = $this->mSkin
->revDeleteLink( $query,
226 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), $canHide ) . ' ';
232 $tools = Html
::rawElement(
234 array( 'class' => 'mw-deletedcontribs-tools' ),
235 wfMsg( 'parentheses', $wgLang->pipeList( array( $last, $dellog, $reviewlink ) ) )
238 $diffOut = Linker
::formatRevisionSize( $row->ar_len
);
239 $ret = "{$del}{$link} {$tools} . . {$mflag} {$diffOut} {$pagelink} {$comment}";
241 # Denote if username is redacted for this edit
242 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
243 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
246 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
248 wfProfileOut( __METHOD__
);
253 * Get the Database object in use
257 public function getDatabase() {
262 class DeletedContributionsPage
extends SpecialPage
{
263 function __construct() {
264 parent
::__construct( 'DeletedContributions', 'deletedhistory',
265 /*listed*/ true, /*function*/ false, /*file*/ false );
269 * Special page "deleted user contributions".
270 * Shows a list of the deleted contributions of a user.
273 * @param $par String: (optional) user name of the user for which to show the contributions
275 function execute( $par ) {
279 if ( !$this->userCanExecute( $wgUser ) ) {
280 $this->displayRestrictionError();
284 global $wgOut, $wgRequest;
286 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
290 if ( isset( $par ) ) {
293 $target = $wgRequest->getVal( 'target' );
296 if ( !strlen( $target ) ) {
297 $wgOut->addHTML( $this->getForm( '' ) );
301 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
302 $options['target'] = $target;
304 $nt = Title
::makeTitleSafe( NS_USER
, $target );
306 $wgOut->addHTML( $this->getForm( '' ) );
309 $id = User
::idFromName( $nt->getText() );
311 $target = $nt->getText();
312 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
314 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
315 $options['namespace'] = intval( $ns );
317 $options['namespace'] = '';
320 $wgOut->addHTML( $this->getForm( $options ) );
322 $pager = new DeletedContribsPager( $target, $options['namespace'] );
323 if ( !$pager->getNumRows() ) {
324 $wgOut->addWikiMsg( 'nocontribs' );
328 # Show a message about slave lag, if applicable
329 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
330 $wgOut->showLagWarning( $lag );
333 '<p>' . $pager->getNavigationBar() . '</p>' .
335 '<p>' . $pager->getNavigationBar() . '</p>' );
337 # If there were contributions, and it was a valid user or IP, show
338 # the appropriate "footer" message - WHOIS tools, etc.
339 if( $target != 'newbies' ) {
340 $message = IP
::isIPAddress( $target )
341 ?
'sp-contributions-footer-anon'
342 : 'sp-contributions-footer';
344 if( !wfMessage( $message )->isDisabled() ) {
345 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
351 * Generates the subheading with links
352 * @param $nt Title object for the target
353 * @param $id Integer: User ID for the target
354 * @return String: appropriately-escaped HTML to be output literally
355 * @todo Fixme: almost the same as contributionsSub in SpecialContributions.php. Could be combined.
357 function getSubTitle( $nt, $id ) {
358 global $wgLang, $wgUser, $wgOut;
360 $sk = $wgUser->getSkin();
362 if ( $id === null ) {
363 $user = htmlspecialchars( $nt->getText() );
365 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
367 $userObj = User
::newFromName( $nt->getText(), /* check for username validity not needed */ false );
368 $talk = $nt->getTalkPage();
371 $tools[] = $sk->link( $talk, wfMsgHtml( 'sp-contributions-talk' ) );
372 if( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
373 if( $wgUser->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
374 if ( $userObj->isBlocked() ) {
375 $tools[] = $sk->linkKnown( # Change block link
376 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
377 wfMsgHtml( 'change-blocklink' )
379 $tools[] = $sk->linkKnown( # Unblock link
380 SpecialPage
::getTitleFor( 'BlockList' ),
381 wfMsgHtml( 'unblocklink' ),
384 'action' => 'unblock',
385 'ip' => $nt->getDBkey()
389 else { # User is not blocked
390 $tools[] = $sk->linkKnown( # Block link
391 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
392 wfMsgHtml( 'blocklink' )
397 $tools[] = $sk->linkKnown(
398 SpecialPage
::getTitleFor( 'Log' ),
399 wfMsgHtml( 'sp-contributions-blocklog' ),
403 'page' => $nt->getPrefixedText()
408 $tools[] = $sk->linkKnown(
409 SpecialPage
::getTitleFor( 'Log' ),
410 wfMsgHtml( 'sp-contributions-logs' ),
412 array( 'user' => $nt->getText() )
414 # Link to contributions
415 $tools[] = $sk->linkKnown(
416 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
417 wfMsgHtml( 'sp-deletedcontributions-contribs' )
420 # Add a link to change user rights for privileged users
421 $userrightsPage = new UserrightsPage();
422 if( $id !== null && $userrightsPage->userCanChangeRights( User
::newFromId( $id ) ) ) {
423 $tools[] = $sk->linkKnown(
424 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
425 wfMsgHtml( 'sp-contributions-userrights' )
429 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
431 $links = $wgLang->pipeList( $tools );
433 // Show a note if the user is blocked and display the last block log entry.
434 if ( $userObj->isBlocked() ) {
435 LogEventsList
::showLogExtract(
438 $nt->getPrefixedText(),
442 'showIfEmpty' => false,
444 'sp-contributions-blocked-notice',
445 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
447 'offset' => '' # don't use $wgRequest parameter offset
453 // Old message 'contribsub' had one parameter, but that doesn't work for
454 // languages that want to put the "for" bit right after $user but before
455 // $links. If 'contribsub' is around, use it for reverse compatibility,
456 // otherwise use 'contribsub2'.
457 if( wfEmptyMsg( 'contribsub' ) ) {
458 return wfMsgHtml( 'contribsub2', $user, $links );
460 return wfMsgHtml( 'contribsub', "$user ($links)" );
465 * Generates the namespace selector form with hidden attributes.
466 * @param $options Array: the options to be included.
468 function getForm( $options ) {
471 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->getPrefixedText();
472 if ( !isset( $options['target'] ) ) {
473 $options['target'] = '';
475 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
478 if ( !isset( $options['namespace'] ) ) {
479 $options['namespace'] = '';
482 if ( !isset( $options['contribs'] ) ) {
483 $options['contribs'] = 'user';
486 if ( $options['contribs'] == 'newbie' ) {
487 $options['target'] = '';
490 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
492 foreach ( $options as $name => $value ) {
493 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
496 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
499 $f .= Xml
::openElement( 'fieldset' ) .
500 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
501 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
502 Html
::input( 'target', $options['target'], 'text', array(
505 ) +
( $options['target'] ?
array() : array( 'autofocus' ) ) ) . ' '.
506 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
507 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
508 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
509 Xml
::closeElement( 'fieldset' ) .
510 Xml
::closeElement( 'form' );