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() {
52 list( $index, $userCond ) = $this->getUserCond();
53 $conds = array_merge( $userCond, $this->getNamespaceCond() );
54 $user = $this->getUser();
55 // Paranoia: avoid brute force searches (bug 17792)
56 if( !$user->isAllowed( 'deletedhistory' ) ) {
57 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::DELETED_USER
) . ' = 0';
58 } elseif( !$user->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'
69 'options' => array( 'USE INDEX' => $index )
73 function getUserCond() {
76 $condition['ar_user_text'] = $this->target
;
77 $index = 'usertext_timestamp';
79 return array( $index, $condition );
82 function getIndexField() {
83 return 'ar_timestamp';
86 function getStartBody() {
90 function getEndBody() {
94 function getNavigationBar() {
95 if ( isset( $this->mNavigationBar
) ) {
96 return $this->mNavigationBar
;
98 $lang = $this->getLang();
99 $fmtLimit = $lang->formatNum( $this->mLimit
);
101 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
102 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
103 'first' => wfMsgHtml( 'histlast' ),
104 'last' => wfMsgHtml( 'histfirst' )
107 $pagingLinks = $this->getPagingLinks( $linkTexts );
108 $limitLinks = $this->getLimitLinks();
109 $limits = $lang->pipeList( $limitLinks );
111 $this->mNavigationBar
= "(" . $lang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
112 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
113 return $this->mNavigationBar
;
116 function getNamespaceCond() {
117 if ( $this->namespace !== '' ) {
118 return array( 'ar_namespace' => (int)$this->namespace );
125 * Generates each row in the contributions list.
127 * Contributions which are marked "top" are currently on top of the history.
128 * For these contributions, a [rollback] link is shown for users with sysop
129 * privileges. The rollback link restores the most recent version that was not
130 * written by the target user.
132 * @todo This would probably look a lot nicer in a table.
134 function formatRow( $row ) {
135 wfProfileIn( __METHOD__
);
137 $rev = new Revision( array(
138 'id' => $row->ar_rev_id
,
139 'comment' => $row->ar_comment
,
140 'user' => $row->ar_user
,
141 'user_text' => $row->ar_user_text
,
142 'timestamp' => $row->ar_timestamp
,
143 'minor_edit' => $row->ar_minor_edit
,
144 'deleted' => $row->ar_deleted
,
147 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
149 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
151 $logs = SpecialPage
::getTitleFor( 'Log' );
152 $dellog = Linker
::linkKnown(
154 $this->messages
['deletionlog'],
158 'page' => $page->getPrefixedText()
162 $reviewlink = Linker
::linkKnown(
163 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
164 $this->messages
['undeleteviewlink']
167 $user = $this->getUser();
169 if( $user->isAllowed('deletedtext') ) {
170 $last = Linker
::linkKnown(
172 $this->messages
['diff'],
175 'target' => $page->getPrefixedText(),
176 'timestamp' => $rev->getTimestamp(),
181 $last = $this->messages
['diff'];
184 $comment = Linker
::revComment( $rev );
185 $date = htmlspecialchars( $this->getLang()->timeanddate( $rev->getTimestamp(), true ) );
187 if( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
188 $link = $date; // unusable link
190 $link = Linker
::linkKnown(
195 'target' => $page->getPrefixedText(),
196 'timestamp' => $rev->getTimestamp()
200 // Style deleted items
201 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
202 $link = '<span class="history-deleted">' . $link . '</span>';
205 $pagelink = Linker
::link( $page );
207 if( $rev->isMinor() ) {
208 $mflag = ChangesList
::flag( 'minor' );
213 // Revision delete link
214 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
215 if ( $del ) $del .= ' ';
217 $tools = Html
::rawElement(
219 array( 'class' => 'mw-deletedcontribs-tools' ),
220 wfMsg( 'parentheses', $this->getLang()->pipeList( array( $last, $dellog, $reviewlink ) ) )
223 $ret = "{$del}{$link} {$tools} . . {$mflag} {$pagelink} {$comment}";
225 # Denote if username is redacted for this edit
226 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
227 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
230 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
232 wfProfileOut( __METHOD__
);
237 * Get the Database object in use
241 public function getDatabase() {
246 class DeletedContributionsPage
extends SpecialPage
{
247 function __construct() {
248 parent
::__construct( 'DeletedContributions', 'deletedhistory',
249 /*listed*/ true, /*function*/ false, /*file*/ false );
253 * Special page "deleted user contributions".
254 * Shows a list of the deleted contributions of a user.
257 * @param $par String: (optional) user name of the user for which to show the contributions
259 function execute( $par ) {
262 $user = $this->getUser();
264 if ( !$this->userCanExecute( $user ) ) {
265 $this->displayRestrictionError();
269 $request = $this->getRequest();
270 $out = $this->getOutput();
271 $out->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
275 if ( $par !== null ) {
278 $target = $request->getVal( 'target' );
281 if ( !strlen( $target ) ) {
282 $out->addHTML( $this->getForm( '' ) );
286 $options['limit'] = $request->getInt( 'limit', 50 );
287 $options['target'] = $target;
289 $nt = Title
::makeTitleSafe( NS_USER
, $target );
291 $out->addHTML( $this->getForm( '' ) );
294 $id = User
::idFromName( $nt->getText() );
296 $target = $nt->getText();
297 $out->setSubtitle( $this->getSubTitle( $nt, $id ) );
299 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
300 $options['namespace'] = intval( $ns );
302 $options['namespace'] = '';
305 $out->addHTML( $this->getForm( $options ) );
307 $pager = new DeletedContribsPager( $target, $options['namespace'] );
308 if ( !$pager->getNumRows() ) {
309 $out->addWikiMsg( 'nocontribs' );
313 # Show a message about slave lag, if applicable
314 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
316 $out->showLagWarning( $lag );
319 '<p>' . $pager->getNavigationBar() . '</p>' .
321 '<p>' . $pager->getNavigationBar() . '</p>' );
323 # If there were contributions, and it was a valid user or IP, show
324 # the appropriate "footer" message - WHOIS tools, etc.
325 if( $target != 'newbies' ) {
326 $message = IP
::isIPAddress( $target )
327 ?
'sp-contributions-footer-anon'
328 : 'sp-contributions-footer';
330 if( !wfMessage( $message )->isDisabled() ) {
331 $out->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
337 * Generates the subheading with links
338 * @param $nt Title object for the target
339 * @param $id Integer: User ID for the target
340 * @return String: appropriately-escaped HTML to be output literally
341 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
343 function getSubTitle( $nt, $id ) {
344 if ( $id === null ) {
345 $user = htmlspecialchars( $nt->getText() );
347 $user = Linker
::link( $nt, htmlspecialchars( $nt->getText() ) );
349 $userObj = User
::newFromName( $nt->getText(), /* check for username validity not needed */ false );
350 $talk = $nt->getTalkPage();
353 $tools[] = Linker
::link( $talk, wfMsgHtml( 'sp-contributions-talk' ) );
354 if( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
355 if( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
356 if ( $userObj->isBlocked() ) {
357 $tools[] = Linker
::linkKnown( # Change block link
358 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
359 wfMsgHtml( 'change-blocklink' )
361 $tools[] = Linker
::linkKnown( # Unblock link
362 SpecialPage
::getTitleFor( 'BlockList' ),
363 wfMsgHtml( 'unblocklink' ),
366 'action' => 'unblock',
367 'ip' => $nt->getDBkey()
371 else { # User is not blocked
372 $tools[] = Linker
::linkKnown( # Block link
373 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
374 wfMsgHtml( 'blocklink' )
379 $tools[] = Linker
::linkKnown(
380 SpecialPage
::getTitleFor( 'Log' ),
381 wfMsgHtml( 'sp-contributions-blocklog' ),
385 'page' => $nt->getPrefixedText()
390 $tools[] = Linker
::linkKnown(
391 SpecialPage
::getTitleFor( 'Log' ),
392 wfMsgHtml( 'sp-contributions-logs' ),
394 array( 'user' => $nt->getText() )
396 # Link to contributions
397 $tools[] = Linker
::linkKnown(
398 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
399 wfMsgHtml( 'sp-deletedcontributions-contribs' )
402 # Add a link to change user rights for privileged users
403 $userrightsPage = new UserrightsPage();
404 if( $id !== null && $userrightsPage->userCanChangeRights( User
::newFromId( $id ) ) ) {
405 $tools[] = Linker
::linkKnown(
406 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
407 wfMsgHtml( 'sp-contributions-userrights' )
411 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
413 $links = $this->getLang()->pipeList( $tools );
415 // Show a note if the user is blocked and display the last block log entry.
416 if ( $userObj->isBlocked() ) {
417 $out = $this->getOutput(); // LogEventsList::showLogExtract() wants the first parameter by ref
418 LogEventsList
::showLogExtract(
425 'showIfEmpty' => false,
427 'sp-contributions-blocked-notice',
428 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
430 'offset' => '' # don't use $this->getRequest() parameter offset
436 // Old message 'contribsub' had one parameter, but that doesn't work for
437 // languages that want to put the "for" bit right after $user but before
438 // $links. If 'contribsub' is around, use it for reverse compatibility,
439 // otherwise use 'contribsub2'.
440 if( wfEmptyMsg( 'contribsub' ) ) {
441 return wfMsgHtml( 'contribsub2', $user, $links );
443 return wfMsgHtml( 'contribsub', "$user ($links)" );
448 * Generates the namespace selector form with hidden attributes.
449 * @param $options Array: the options to be included.
451 function getForm( $options ) {
454 $options['title'] = $this->getTitle()->getPrefixedText();
455 if ( !isset( $options['target'] ) ) {
456 $options['target'] = '';
458 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
461 if ( !isset( $options['namespace'] ) ) {
462 $options['namespace'] = '';
465 if ( !isset( $options['contribs'] ) ) {
466 $options['contribs'] = 'user';
469 if ( $options['contribs'] == 'newbie' ) {
470 $options['target'] = '';
473 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
475 foreach ( $options as $name => $value ) {
476 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
479 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
482 $f .= Xml
::openElement( 'fieldset' ) .
483 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
484 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
485 Html
::input( 'target', $options['target'], 'text', array(
488 ) +
( $options['target'] ?
array() : array( 'autofocus' ) ) ) . ' '.
489 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
490 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
491 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
492 Xml
::closeElement( 'fieldset' ) .
493 Xml
::closeElement( 'form' );