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 = IndexPager
::DIR_DESCENDING
;
32 public $namespace = '';
36 * @var string Navigation bar with paging links.
38 protected $mNavigationBar;
40 function __construct( IContextSource
$context, $target, $namespace = false ) {
41 parent
::__construct( $context );
42 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
43 foreach ( $msgs as $msg ) {
44 $this->messages
[$msg] = $this->msg( $msg )->escaped();
46 $this->target
= $target;
47 $this->namespace = $namespace;
48 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
51 function getDefaultQuery() {
52 $query = parent
::getDefaultQuery();
53 $query['target'] = $this->target
;
58 function getQueryInfo() {
59 list( $index, $userCond ) = $this->getUserCond();
60 $conds = array_merge( $userCond, $this->getNamespaceCond() );
61 $user = $this->getUser();
62 // Paranoia: avoid brute force searches (bug 17792)
63 if ( !$user->isAllowed( 'deletedhistory' ) ) {
64 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::DELETED_USER
) . ' = 0';
65 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
66 $conds[] = $this->mDb
->bitAnd( 'ar_deleted', Revision
::SUPPRESSED_USER
) .
67 ' != ' . Revision
::SUPPRESSED_USER
;
71 'tables' => array( 'archive' ),
73 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment',
74 'ar_minor_edit', 'ar_user', 'ar_user_text', 'ar_deleted'
77 'options' => array( 'USE INDEX' => $index )
81 function getUserCond() {
84 $condition['ar_user_text'] = $this->target
;
85 $index = 'usertext_timestamp';
87 return array( $index, $condition );
90 function getIndexField() {
91 return 'ar_timestamp';
94 function getStartBody() {
98 function getEndBody() {
102 function getNavigationBar() {
103 if ( isset( $this->mNavigationBar
) ) {
104 return $this->mNavigationBar
;
108 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit
)->escaped(),
109 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit
)->escaped(),
110 'first' => $this->msg( 'histlast' )->escaped(),
111 'last' => $this->msg( 'histfirst' )->escaped()
114 $pagingLinks = $this->getPagingLinks( $linkTexts );
115 $limitLinks = $this->getLimitLinks();
116 $lang = $this->getLanguage();
117 $limits = $lang->pipeList( $limitLinks );
119 $firstLast = $lang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) );
120 $firstLast = $this->msg( 'parentheses' )->rawParams( $firstLast )->escaped();
121 $prevNext = $this->msg( 'viewprevnext' )
123 $pagingLinks['prev'],
124 $pagingLinks['next'],
127 $separator = $this->msg( 'word-separator' )->escaped();
128 $this->mNavigationBar
= $firstLast . $separator . $prevNext;
130 return $this->mNavigationBar
;
133 function getNamespaceCond() {
134 if ( $this->namespace !== '' ) {
135 return array( 'ar_namespace' => (int)$this->namespace );
142 * Generates each row in the contributions list.
144 * Contributions which are marked "top" are currently on top of the history.
145 * For these contributions, a [rollback] link is shown for users with sysop
146 * privileges. The rollback link restores the most recent version that was not
147 * written by the target user.
149 * @todo This would probably look a lot nicer in a table.
150 * @param stdClass $row
153 function formatRow( $row ) {
155 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
157 $rev = new Revision( array(
159 'id' => $row->ar_rev_id
,
160 'comment' => $row->ar_comment
,
161 'user' => $row->ar_user
,
162 'user_text' => $row->ar_user_text
,
163 'timestamp' => $row->ar_timestamp
,
164 'minor_edit' => $row->ar_minor_edit
,
165 'deleted' => $row->ar_deleted
,
168 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
170 $logs = SpecialPage
::getTitleFor( 'Log' );
171 $dellog = Linker
::linkKnown(
173 $this->messages
['deletionlog'],
177 'page' => $page->getPrefixedText()
181 $reviewlink = Linker
::linkKnown(
182 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
183 $this->messages
['undeleteviewlink']
186 $user = $this->getUser();
188 if ( $user->isAllowed( 'deletedtext' ) ) {
189 $last = Linker
::linkKnown(
191 $this->messages
['diff'],
194 'target' => $page->getPrefixedText(),
195 'timestamp' => $rev->getTimestamp(),
200 $last = $this->messages
['diff'];
203 $comment = Linker
::revComment( $rev );
204 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user );
205 $date = htmlspecialchars( $date );
207 if ( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
208 $link = $date; // unusable link
210 $link = Linker
::linkKnown(
213 array( 'class' => 'mw-changeslist-date' ),
215 'target' => $page->getPrefixedText(),
216 'timestamp' => $rev->getTimestamp()
220 // Style deleted items
221 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
222 $link = '<span class="history-deleted">' . $link . '</span>';
225 $pagelink = Linker
::link(
228 array( 'class' => 'mw-changeslist-title' )
231 if ( $rev->isMinor() ) {
232 $mflag = ChangesList
::flag( 'minor' );
237 // Revision delete link
238 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
243 $tools = Html
::rawElement(
245 array( 'class' => 'mw-deletedcontribs-tools' ),
246 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
247 array( $last, $dellog, $reviewlink ) ) )->escaped()
250 $separator = '<span class="mw-changeslist-separator">. .</span>';
251 $ret = "{$del}{$link} {$tools} {$separator} {$mflag} {$pagelink} {$comment}";
253 # Denote if username is redacted for this edit
254 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
255 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
258 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
265 * Get the Database object in use
269 public function getDatabase() {
274 class DeletedContributionsPage
extends SpecialPage
{
275 function __construct() {
276 parent
::__construct( 'DeletedContributions', 'deletedhistory',
277 /*listed*/true, /*function*/false, /*file*/false );
281 * Special page "deleted user contributions".
282 * Shows a list of the deleted contributions of a user.
284 * @param string $par (optional) user name of the user for which to show the contributions
286 function execute( $par ) {
288 $this->outputHeader();
290 $user = $this->getUser();
292 if ( !$this->userCanExecute( $user ) ) {
293 $this->displayRestrictionError();
298 $request = $this->getRequest();
299 $out = $this->getOutput();
300 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
304 if ( $par !== null ) {
307 $target = $request->getVal( 'target' );
310 if ( !strlen( $target ) ) {
311 $out->addHTML( $this->getForm( '' ) );
316 $options['limit'] = $request->getInt( 'limit',
317 $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
318 $options['target'] = $target;
320 $userObj = User
::newFromName( $target, false );
322 $out->addHTML( $this->getForm( '' ) );
326 $this->getSkin()->setRelevantUser( $userObj );
328 $target = $userObj->getName();
329 $out->addSubtitle( $this->getSubTitle( $userObj ) );
331 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
332 $options['namespace'] = intval( $ns );
334 $options['namespace'] = '';
337 $out->addHTML( $this->getForm( $options ) );
339 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
340 if ( !$pager->getNumRows() ) {
341 $out->addWikiMsg( 'nocontribs' );
346 # Show a message about slave lag, if applicable
347 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
349 $out->showLagWarning( $lag );
353 '<p>' . $pager->getNavigationBar() . '</p>' .
355 '<p>' . $pager->getNavigationBar() . '</p>' );
357 # If there were contributions, and it was a valid user or IP, show
358 # the appropriate "footer" message - WHOIS tools, etc.
359 if ( $target != 'newbies' ) {
360 $message = IP
::isIPAddress( $target ) ?
361 'sp-contributions-footer-anon' :
362 'sp-contributions-footer';
364 if ( !$this->msg( $message )->isDisabled() ) {
366 "<div class='mw-contributions-footer'>\n$1\n</div>",
367 array( $message, $target )
374 * Generates the subheading with links
375 * @param User $userObj User object for the target
376 * @return string Appropriately-escaped HTML to be output literally
377 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
379 function getSubTitle( $userObj ) {
380 if ( $userObj->isAnon() ) {
381 $user = htmlspecialchars( $userObj->getName() );
383 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
386 $nt = $userObj->getUserPage();
387 $id = $userObj->getID();
388 $talk = $nt->getTalkPage();
391 $tools[] = Linker
::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
392 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
393 # Block / Change block / Unblock links
394 if ( $this->getUser()->isAllowed( 'block' ) ) {
395 if ( $userObj->isBlocked() ) {
396 $tools[] = Linker
::linkKnown( # Change block link
397 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
398 $this->msg( 'change-blocklink' )->escaped()
400 $tools[] = Linker
::linkKnown( # Unblock link
401 SpecialPage
::getTitleFor( 'BlockList' ),
402 $this->msg( 'unblocklink' )->escaped(),
405 'action' => 'unblock',
406 'ip' => $nt->getDBkey()
410 # User is not blocked
411 $tools[] = Linker
::linkKnown( # Block link
412 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
413 $this->msg( 'blocklink' )->escaped()
418 $tools[] = Linker
::linkKnown(
419 SpecialPage
::getTitleFor( 'Log' ),
420 $this->msg( 'sp-contributions-blocklog' )->escaped(),
424 'page' => $nt->getPrefixedText()
427 # Suppression log link (bug 59120)
428 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
429 $tools[] = Linker
::linkKnown(
430 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
431 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
433 array( 'offender' => $userObj->getName() )
439 $tools[] = Linker
::linkKnown(
440 SpecialPage
::getTitleFor( 'Listfiles', $userObj->getName() ),
441 $this->msg( 'sp-contributions-uploads' )->escaped()
445 $tools[] = Linker
::linkKnown(
446 SpecialPage
::getTitleFor( 'Log' ),
447 $this->msg( 'sp-contributions-logs' )->escaped(),
449 array( 'user' => $nt->getText() )
451 # Link to contributions
452 $tools[] = Linker
::linkKnown(
453 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
454 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
457 # Add a link to change user rights for privileged users
458 $userrightsPage = new UserrightsPage();
459 $userrightsPage->setContext( $this->getContext() );
460 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
461 $tools[] = Linker
::linkKnown(
462 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
463 $this->msg( 'sp-contributions-userrights' )->escaped()
467 Hooks
::run( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
469 $links = $this->getLanguage()->pipeList( $tools );
471 // Show a note if the user is blocked and display the last block log entry.
472 $block = Block
::newFromTarget( $userObj, $userObj );
473 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
474 if ( $block->getType() == Block
::TYPE_RANGE
) {
475 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
478 // LogEventsList::showLogExtract() wants the first parameter by ref
479 $out = $this->getOutput();
480 LogEventsList
::showLogExtract(
487 'showIfEmpty' => false,
489 'sp-contributions-blocked-notice',
490 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
492 'offset' => '' # don't use $this->getRequest() parameter offset
498 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
502 * Generates the namespace selector form with hidden attributes.
503 * @param array $options The options to be included.
506 function getForm( $options ) {
507 $options['title'] = $this->getPageTitle()->getPrefixedText();
508 if ( !isset( $options['target'] ) ) {
509 $options['target'] = '';
511 $options['target'] = str_replace( '_', ' ', $options['target'] );
514 if ( !isset( $options['namespace'] ) ) {
515 $options['namespace'] = '';
518 if ( !isset( $options['contribs'] ) ) {
519 $options['contribs'] = 'user';
522 if ( $options['contribs'] == 'newbie' ) {
523 $options['target'] = '';
526 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) );
528 foreach ( $options as $name => $value ) {
529 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
532 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
535 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
537 $f .= Xml
::openElement( 'fieldset' );
538 $f .= Xml
::element( 'legend', array(), $this->msg( 'sp-contributions-search' )->text() );
541 array( 'for' => 'target' ),
542 $this->msg( 'sp-contributions-username' )->parse()
552 'mw-autocomplete-user', // used by mediawiki.userSuggest
554 ) +
( $options['target'] ?
array() : array( 'autofocus' ) )
556 $f .= Html
::namespaceSelector(
558 'selected' => $options['namespace'],
560 'label' => $this->msg( 'namespace' )->text()
563 'name' => 'namespace',
565 'class' => 'namespaceselector',
568 $f .= Xml
::submitButton( $this->msg( 'sp-contributions-submit' )->text() );
569 $f .= Xml
::closeElement( 'fieldset' );
570 $f .= Xml
::closeElement( 'form' );
575 protected function getGroupName() {