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 ) {
260 global $wgQueryPageDefaultLimit;
263 $user = $this->getUser();
265 if ( !$this->userCanExecute( $user ) ) {
266 $this->displayRestrictionError();
270 $request = $this->getRequest();
271 $out = $this->getOutput();
272 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
276 if ( $par !== null ) {
279 $target = $request->getVal( 'target' );
282 if ( !strlen( $target ) ) {
283 $out->addHTML( $this->getForm( '' ) );
287 $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit );
288 $options['target'] = $target;
290 $nt = Title
::makeTitleSafe( NS_USER
, $target );
292 $out->addHTML( $this->getForm( '' ) );
295 $id = User
::idFromName( $nt->getText() );
297 $target = $nt->getText();
298 $out->addSubtitle( $this->getSubTitle( $nt, $id ) );
300 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
301 $options['namespace'] = intval( $ns );
303 $options['namespace'] = '';
306 $out->addHTML( $this->getForm( $options ) );
308 $pager = new DeletedContribsPager( $target, $options['namespace'] );
309 if ( !$pager->getNumRows() ) {
310 $out->addWikiMsg( 'nocontribs' );
314 # Show a message about slave lag, if applicable
315 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
317 $out->showLagWarning( $lag );
320 '<p>' . $pager->getNavigationBar() . '</p>' .
322 '<p>' . $pager->getNavigationBar() . '</p>' );
324 # If there were contributions, and it was a valid user or IP, show
325 # the appropriate "footer" message - WHOIS tools, etc.
326 if( $target != 'newbies' ) {
327 $message = IP
::isIPAddress( $target )
328 ?
'sp-contributions-footer-anon'
329 : 'sp-contributions-footer';
331 if( !wfMessage( $message )->isDisabled() ) {
332 $out->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
338 * Generates the subheading with links
339 * @param $nt Title object for the target
340 * @param $id Integer: User ID for the target
341 * @return String: appropriately-escaped HTML to be output literally
342 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
344 function getSubTitle( $nt, $id ) {
345 if ( $id === null ) {
346 $user = htmlspecialchars( $nt->getText() );
348 $user = Linker
::link( $nt, htmlspecialchars( $nt->getText() ) );
350 $userObj = User
::newFromName( $nt->getText(), /* check for username validity not needed */ false );
351 $talk = $nt->getTalkPage();
354 $tools[] = Linker
::link( $talk, wfMsgHtml( 'sp-contributions-talk' ) );
355 if( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
356 if( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
357 if ( $userObj->isBlocked() ) {
358 $tools[] = Linker
::linkKnown( # Change block link
359 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
360 wfMsgHtml( 'change-blocklink' )
362 $tools[] = Linker
::linkKnown( # Unblock link
363 SpecialPage
::getTitleFor( 'BlockList' ),
364 wfMsgHtml( 'unblocklink' ),
367 'action' => 'unblock',
368 'ip' => $nt->getDBkey()
372 else { # User is not blocked
373 $tools[] = Linker
::linkKnown( # Block link
374 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
375 wfMsgHtml( 'blocklink' )
380 $tools[] = Linker
::linkKnown(
381 SpecialPage
::getTitleFor( 'Log' ),
382 wfMsgHtml( 'sp-contributions-blocklog' ),
386 'page' => $nt->getPrefixedText()
391 $tools[] = Linker
::linkKnown(
392 SpecialPage
::getTitleFor( 'Log' ),
393 wfMsgHtml( 'sp-contributions-logs' ),
395 array( 'user' => $nt->getText() )
397 # Link to contributions
398 $tools[] = Linker
::linkKnown(
399 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
400 wfMsgHtml( 'sp-deletedcontributions-contribs' )
403 # Add a link to change user rights for privileged users
404 $userrightsPage = new UserrightsPage();
405 if( $id !== null && $userrightsPage->userCanChangeRights( User
::newFromId( $id ) ) ) {
406 $tools[] = Linker
::linkKnown(
407 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
408 wfMsgHtml( 'sp-contributions-userrights' )
412 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
414 $links = $this->getLang()->pipeList( $tools );
416 // Show a note if the user is blocked and display the last block log entry.
417 if ( $userObj->isBlocked() ) {
418 $out = $this->getOutput(); // LogEventsList::showLogExtract() wants the first parameter by ref
419 LogEventsList
::showLogExtract(
426 'showIfEmpty' => false,
428 'sp-contributions-blocked-notice',
429 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
431 'offset' => '' # don't use $this->getRequest() parameter offset
437 // Old message 'contribsub' had one parameter, but that doesn't work for
438 // languages that want to put the "for" bit right after $user but before
439 // $links. If 'contribsub' is around, use it for reverse compatibility,
440 // otherwise use 'contribsub2'.
441 $oldMsg = $this->msg( 'contribsub' );
442 if ( $oldMsg->exists() ) {
443 return $oldMsg->rawParams( "$user ($links)" );
445 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
450 * Generates the namespace selector form with hidden attributes.
451 * @param $options Array: the options to be included.
453 function getForm( $options ) {
456 $options['title'] = $this->getTitle()->getPrefixedText();
457 if ( !isset( $options['target'] ) ) {
458 $options['target'] = '';
460 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
463 if ( !isset( $options['namespace'] ) ) {
464 $options['namespace'] = '';
467 if ( !isset( $options['contribs'] ) ) {
468 $options['contribs'] = 'user';
471 if ( $options['contribs'] == 'newbie' ) {
472 $options['target'] = '';
475 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
477 foreach ( $options as $name => $value ) {
478 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
481 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
484 $f .= Xml
::openElement( 'fieldset' ) .
485 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
486 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
487 Html
::input( 'target', $options['target'], 'text', array(
490 ) +
( $options['target'] ?
array() : array( 'autofocus' ) ) ) . ' '.
491 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
492 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
493 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
494 Xml
::closeElement( 'fieldset' ) .
495 Xml
::closeElement( 'form' );