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;
33 function __construct( IContextSource
$context, $target, $namespace = false ) {
34 parent
::__construct( $context );
35 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
36 foreach( $msgs as $msg ) {
37 $this->messages
[$msg] = $this->msg( $msg )->escaped();
39 $this->target
= $target;
40 $this->namespace = $namespace;
41 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
44 function getDefaultQuery() {
45 $query = parent
::getDefaultQuery();
46 $query['target'] = $this->target
;
50 function getQueryInfo() {
51 list( $index, $userCond ) = $this->getUserCond();
52 $conds = array_merge( $userCond, $this->getNamespaceCond() );
53 $user = $this->getUser();
54 // Paranoia: avoid brute force searches (bug 17792)
55 if( !$user->isAllowed( 'deletedhistory' ) ) {
56 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::DELETED_USER
) . ' = 0';
57 } elseif( !$user->isAllowed( 'suppressrevision' ) ) {
58 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::SUPPRESSED_USER
) .
59 ' != ' . Revision
::SUPPRESSED_USER
;
62 'tables' => array( 'archive' ),
64 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
65 'ar_user', 'ar_user_text', 'ar_deleted'
68 'options' => array( 'USE INDEX' => $index )
72 function getUserCond() {
75 $condition['ar_user_text'] = $this->target
;
76 $index = 'usertext_timestamp';
78 return array( $index, $condition );
81 function getIndexField() {
82 return 'ar_timestamp';
85 function getStartBody() {
89 function getEndBody() {
93 function getNavigationBar() {
94 if ( isset( $this->mNavigationBar
) ) {
95 return $this->mNavigationBar
;
97 $lang = $this->getLanguage();
98 $fmtLimit = $lang->formatNum( $this->mLimit
);
100 'prev' => $this->msg( 'pager-newer-n', $fmtLimit )->escaped(),
101 'next' => $this->msg( 'pager-older-n', $fmtLimit )->escaped(),
102 'first' => $this->msg( 'histlast' )->escaped(),
103 'last' => $this->msg( 'histfirst' )->escaped()
106 $pagingLinks = $this->getPagingLinks( $linkTexts );
107 $limitLinks = $this->getLimitLinks();
108 $limits = $lang->pipeList( $limitLinks );
110 $this->mNavigationBar
= "(" . $lang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
111 $this->msg( 'viewprevnext' )->rawParams( $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
112 return $this->mNavigationBar
;
115 function getNamespaceCond() {
116 if ( $this->namespace !== '' ) {
117 return array( 'ar_namespace' => (int)$this->namespace );
124 * Generates each row in the contributions list.
126 * Contributions which are marked "top" are currently on top of the history.
127 * For these contributions, a [rollback] link is shown for users with sysop
128 * privileges. The rollback link restores the most recent version that was not
129 * written by the target user.
131 * @todo This would probably look a lot nicer in a table.
135 function formatRow( $row ) {
136 wfProfileIn( __METHOD__
);
138 $rev = new Revision( array(
139 'id' => $row->ar_rev_id
,
140 'comment' => $row->ar_comment
,
141 'user' => $row->ar_user
,
142 'user_text' => $row->ar_user_text
,
143 'timestamp' => $row->ar_timestamp
,
144 'minor_edit' => $row->ar_minor_edit
,
145 'deleted' => $row->ar_deleted
,
148 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
150 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
152 $logs = SpecialPage
::getTitleFor( 'Log' );
153 $dellog = Linker
::linkKnown(
155 $this->messages
['deletionlog'],
159 'page' => $page->getPrefixedText()
163 $reviewlink = Linker
::linkKnown(
164 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
165 $this->messages
['undeleteviewlink']
168 $user = $this->getUser();
170 if( $user->isAllowed('deletedtext') ) {
171 $last = Linker
::linkKnown(
173 $this->messages
['diff'],
176 'target' => $page->getPrefixedText(),
177 'timestamp' => $rev->getTimestamp(),
182 $last = $this->messages
['diff'];
185 $comment = Linker
::revComment( $rev );
186 $date = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user ) );
188 if( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
189 $link = $date; // unusable link
191 $link = Linker
::linkKnown(
196 'target' => $page->getPrefixedText(),
197 'timestamp' => $rev->getTimestamp()
201 // Style deleted items
202 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
203 $link = '<span class="history-deleted">' . $link . '</span>';
206 $pagelink = Linker
::link( $page );
208 if( $rev->isMinor() ) {
209 $mflag = ChangesList
::flag( 'minor' );
214 // Revision delete link
215 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
216 if ( $del ) $del .= ' ';
218 $tools = Html
::rawElement(
220 array( 'class' => 'mw-deletedcontribs-tools' ),
221 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
222 array( $last, $dellog, $reviewlink ) ) )->escaped()
225 $ret = "{$del}{$link} {$tools} . . {$mflag} {$pagelink} {$comment}";
227 # Denote if username is redacted for this edit
228 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
229 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
232 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
234 wfProfileOut( __METHOD__
);
239 * Get the Database object in use
241 * @return DatabaseBase
243 public function getDatabase() {
248 class DeletedContributionsPage
extends SpecialPage
{
249 function __construct() {
250 parent
::__construct( 'DeletedContributions', 'deletedhistory',
251 /*listed*/ true, /*function*/ false, /*file*/ false );
255 * Special page "deleted user contributions".
256 * Shows a list of the deleted contributions of a user.
258 * @param $par String: (optional) user name of the user for which to show the contributions
260 function execute( $par ) {
261 global $wgQueryPageDefaultLimit;
263 $this->outputHeader();
265 $user = $this->getUser();
267 if ( !$this->userCanExecute( $user ) ) {
268 $this->displayRestrictionError();
272 $request = $this->getRequest();
273 $out = $this->getOutput();
274 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
278 if ( $par !== null ) {
281 $target = $request->getVal( 'target' );
284 if ( !strlen( $target ) ) {
285 $out->addHTML( $this->getForm( '' ) );
289 $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit );
290 $options['target'] = $target;
292 $userObj = User
::newFromName( $target, false );
294 $out->addHTML( $this->getForm( '' ) );
297 $this->getSkin()->setRelevantUser( $userObj );
299 $target = $userObj->getName();
300 $out->addSubtitle( $this->getSubTitle( $userObj ) );
302 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
303 $options['namespace'] = intval( $ns );
305 $options['namespace'] = '';
308 $out->addHTML( $this->getForm( $options ) );
310 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
311 if ( !$pager->getNumRows() ) {
312 $out->addWikiMsg( 'nocontribs' );
316 # Show a message about slave lag, if applicable
317 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
319 $out->showLagWarning( $lag );
322 '<p>' . $pager->getNavigationBar() . '</p>' .
324 '<p>' . $pager->getNavigationBar() . '</p>' );
326 # If there were contributions, and it was a valid user or IP, show
327 # the appropriate "footer" message - WHOIS tools, etc.
328 if( $target != 'newbies' ) {
329 $message = IP
::isIPAddress( $target )
330 ?
'sp-contributions-footer-anon'
331 : 'sp-contributions-footer';
333 if( !$this->msg( $message )->isDisabled() ) {
334 $out->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
340 * Generates the subheading with links
341 * @param $userObj User object for the target
342 * @return String: appropriately-escaped HTML to be output literally
343 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
345 function getSubTitle( $userObj ) {
346 if ( $userObj->isAnon() ) {
347 $user = htmlspecialchars( $userObj->getName() );
349 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
352 $nt = $userObj->getUserPage();
353 $id = $userObj->getID();
354 $talk = $nt->getTalkPage();
357 $tools[] = Linker
::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
358 if( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
359 if( $this->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
360 if ( $userObj->isBlocked() ) {
361 $tools[] = Linker
::linkKnown( # Change block link
362 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
363 $this->msg( 'change-blocklink' )->escaped()
365 $tools[] = Linker
::linkKnown( # Unblock link
366 SpecialPage
::getTitleFor( 'BlockList' ),
367 $this->msg( 'unblocklink' )->escaped(),
370 'action' => 'unblock',
371 'ip' => $nt->getDBkey()
375 else { # User is not blocked
376 $tools[] = Linker
::linkKnown( # Block link
377 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
378 $this->msg( 'blocklink' )->escaped()
383 $tools[] = Linker
::linkKnown(
384 SpecialPage
::getTitleFor( 'Log' ),
385 $this->msg( 'sp-contributions-blocklog' )->escaped(),
389 'page' => $nt->getPrefixedText()
395 $tools[] = Linker
::linkKnown(
396 SpecialPage
::getTitleFor( 'Listfiles', $userObj->getName() ),
397 $this->msg( 'sp-contributions-uploads' )->escaped()
401 $tools[] = Linker
::linkKnown(
402 SpecialPage
::getTitleFor( 'Log' ),
403 $this->msg( 'sp-contributions-logs' )->escaped(),
405 array( 'user' => $nt->getText() )
407 # Link to contributions
408 $tools[] = Linker
::linkKnown(
409 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
410 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
413 # Add a link to change user rights for privileged users
414 $userrightsPage = new UserrightsPage();
415 $userrightsPage->setContext( $this->getContext() );
416 if( $userrightsPage->userCanChangeRights( $userObj ) ) {
417 $tools[] = Linker
::linkKnown(
418 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
419 $this->msg( 'sp-contributions-userrights' )->escaped()
423 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
425 $links = $this->getLanguage()->pipeList( $tools );
427 // Show a note if the user is blocked and display the last block log entry.
428 if ( $userObj->isBlocked() ) {
429 $out = $this->getOutput(); // LogEventsList::showLogExtract() wants the first parameter by ref
430 LogEventsList
::showLogExtract(
437 'showIfEmpty' => false,
439 'sp-contributions-blocked-notice',
440 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
442 'offset' => '' # don't use $this->getRequest() parameter offset
448 // Old message 'contribsub' had one parameter, but that doesn't work for
449 // languages that want to put the "for" bit right after $user but before
450 // $links. If 'contribsub' is around, use it for reverse compatibility,
451 // otherwise use 'contribsub2'.
452 $oldMsg = $this->msg( 'contribsub' );
453 if ( $oldMsg->exists() ) {
454 return $oldMsg->rawParams( "$user ($links)" );
456 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
461 * Generates the namespace selector form with hidden attributes.
462 * @param $options Array: the options to be included.
465 function getForm( $options ) {
468 $options['title'] = $this->getTitle()->getPrefixedText();
469 if ( !isset( $options['target'] ) ) {
470 $options['target'] = '';
472 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
475 if ( !isset( $options['namespace'] ) ) {
476 $options['namespace'] = '';
479 if ( !isset( $options['contribs'] ) ) {
480 $options['contribs'] = 'user';
483 if ( $options['contribs'] == 'newbie' ) {
484 $options['target'] = '';
487 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
489 foreach ( $options as $name => $value ) {
490 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
493 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
496 $f .= Xml
::openElement( 'fieldset' ) .
497 Xml
::element( 'legend', array(), $this->msg( 'sp-contributions-search' )->text() ) .
498 Xml
::tags( 'label', array( 'for' => 'target' ), $this->msg( 'sp-contributions-username' )->parse() ) . ' ' .
499 Html
::input( 'target', $options['target'], 'text', array(
502 ) +
( $options['target'] ?
array() : array( 'autofocus' ) ) ) . ' '.
503 Html
::namespaceSelector(
505 'selected' => $options['namespace'],
507 'label' => $this->msg( 'namespace' )->text()
509 'name' => 'namespace',
511 'class' => 'namespaceselector',
514 Xml
::submitButton( $this->msg( 'sp-contributions-submit' )->text() ) .
515 Xml
::closeElement( 'fieldset' ) .
516 Xml
::closeElement( 'form' );