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;
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->isAllowed( 'suppressrevision' ) ) {
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.
153 function formatRow( $row ) {
154 wfProfileIn( __METHOD__
);
156 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
158 $rev = new Revision( array(
160 'id' => $row->ar_rev_id
,
161 'comment' => $row->ar_comment
,
162 'user' => $row->ar_user
,
163 'user_text' => $row->ar_user_text
,
164 'timestamp' => $row->ar_timestamp
,
165 'minor_edit' => $row->ar_minor_edit
,
166 'deleted' => $row->ar_deleted
,
169 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
171 $logs = SpecialPage
::getTitleFor( 'Log' );
172 $dellog = Linker
::linkKnown(
174 $this->messages
['deletionlog'],
178 'page' => $page->getPrefixedText()
182 $reviewlink = Linker
::linkKnown(
183 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
184 $this->messages
['undeleteviewlink']
187 $user = $this->getUser();
189 if ( $user->isAllowed( 'deletedtext' ) ) {
190 $last = Linker
::linkKnown(
192 $this->messages
['diff'],
195 'target' => $page->getPrefixedText(),
196 'timestamp' => $rev->getTimestamp(),
201 $last = $this->messages
['diff'];
204 $comment = Linker
::revComment( $rev );
205 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user );
206 $date = htmlspecialchars( $date );
208 if ( !$user->isAllowed( 'undelete' ) ||
!$rev->userCan( Revision
::DELETED_TEXT
, $user ) ) {
209 $link = $date; // unusable link
211 $link = Linker
::linkKnown(
214 array( 'class' => 'mw-changeslist-date' ),
216 'target' => $page->getPrefixedText(),
217 'timestamp' => $rev->getTimestamp()
221 // Style deleted items
222 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
223 $link = '<span class="history-deleted">' . $link . '</span>';
226 $pagelink = Linker
::link(
229 array( 'class' => 'mw-changeslist-title' )
232 if ( $rev->isMinor() ) {
233 $mflag = ChangesList
::flag( 'minor' );
238 // Revision delete link
239 $del = Linker
::getRevDeleteLink( $user, $rev, $page );
244 $tools = Html
::rawElement(
246 array( 'class' => 'mw-deletedcontribs-tools' ),
247 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
248 array( $last, $dellog, $reviewlink ) ) )->escaped()
251 $separator = '<span class="mw-changeslist-separator">. .</span>';
252 $ret = "{$del}{$link} {$tools} {$separator} {$mflag} {$pagelink} {$comment}";
254 # Denote if username is redacted for this edit
255 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
256 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
259 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
261 wfProfileOut( __METHOD__
);
267 * Get the Database object in use
269 * @return DatabaseBase
271 public function getDatabase() {
276 class DeletedContributionsPage
extends SpecialPage
{
277 function __construct() {
278 parent
::__construct( 'DeletedContributions', 'deletedhistory',
279 /*listed*/true, /*function*/false, /*file*/false );
283 * Special page "deleted user contributions".
284 * Shows a list of the deleted contributions of a user.
286 * @param string $par (optional) user name of the user for which to show the contributions
288 function execute( $par ) {
289 global $wgQueryPageDefaultLimit;
292 $this->outputHeader();
294 $user = $this->getUser();
296 if ( !$this->userCanExecute( $user ) ) {
297 $this->displayRestrictionError();
302 $request = $this->getRequest();
303 $out = $this->getOutput();
304 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
308 if ( $par !== null ) {
311 $target = $request->getVal( 'target' );
314 if ( !strlen( $target ) ) {
315 $out->addHTML( $this->getForm( '' ) );
320 $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit );
321 $options['target'] = $target;
323 $userObj = User
::newFromName( $target, false );
325 $out->addHTML( $this->getForm( '' ) );
329 $this->getSkin()->setRelevantUser( $userObj );
331 $target = $userObj->getName();
332 $out->addSubtitle( $this->getSubTitle( $userObj ) );
334 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
335 $options['namespace'] = intval( $ns );
337 $options['namespace'] = '';
340 $out->addHTML( $this->getForm( $options ) );
342 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
343 if ( !$pager->getNumRows() ) {
344 $out->addWikiMsg( 'nocontribs' );
349 # Show a message about slave lag, if applicable
350 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
352 $out->showLagWarning( $lag );
356 '<p>' . $pager->getNavigationBar() . '</p>' .
358 '<p>' . $pager->getNavigationBar() . '</p>' );
360 # If there were contributions, and it was a valid user or IP, show
361 # the appropriate "footer" message - WHOIS tools, etc.
362 if ( $target != 'newbies' ) {
363 $message = IP
::isIPAddress( $target ) ?
364 'sp-contributions-footer-anon' :
365 'sp-contributions-footer';
367 if ( !$this->msg( $message )->isDisabled() ) {
369 "<div class='mw-contributions-footer'>\n$1\n</div>",
370 array( $message, $target )
377 * Generates the subheading with links
378 * @param $userObj User object for the target
379 * @return String: appropriately-escaped HTML to be output literally
380 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
382 function getSubTitle( $userObj ) {
383 if ( $userObj->isAnon() ) {
384 $user = htmlspecialchars( $userObj->getName() );
386 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
389 $nt = $userObj->getUserPage();
390 $id = $userObj->getID();
391 $talk = $nt->getTalkPage();
394 $tools[] = Linker
::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
395 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
396 # Block / Change block / Unblock links
397 if ( $this->getUser()->isAllowed( 'block' ) ) {
398 if ( $userObj->isBlocked() ) {
399 $tools[] = Linker
::linkKnown( # Change block link
400 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
401 $this->msg( 'change-blocklink' )->escaped()
403 $tools[] = Linker
::linkKnown( # Unblock link
404 SpecialPage
::getTitleFor( 'BlockList' ),
405 $this->msg( 'unblocklink' )->escaped(),
408 'action' => 'unblock',
409 'ip' => $nt->getDBkey()
413 # User is not blocked
414 $tools[] = Linker
::linkKnown( # Block link
415 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
416 $this->msg( 'blocklink' )->escaped()
421 $tools[] = Linker
::linkKnown(
422 SpecialPage
::getTitleFor( 'Log' ),
423 $this->msg( 'sp-contributions-blocklog' )->escaped(),
427 'page' => $nt->getPrefixedText()
433 $tools[] = Linker
::linkKnown(
434 SpecialPage
::getTitleFor( 'Listfiles', $userObj->getName() ),
435 $this->msg( 'sp-contributions-uploads' )->escaped()
439 $tools[] = Linker
::linkKnown(
440 SpecialPage
::getTitleFor( 'Log' ),
441 $this->msg( 'sp-contributions-logs' )->escaped(),
443 array( 'user' => $nt->getText() )
445 # Link to contributions
446 $tools[] = Linker
::linkKnown(
447 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
448 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
451 # Add a link to change user rights for privileged users
452 $userrightsPage = new UserrightsPage();
453 $userrightsPage->setContext( $this->getContext() );
454 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
455 $tools[] = Linker
::linkKnown(
456 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
457 $this->msg( 'sp-contributions-userrights' )->escaped()
461 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
463 $links = $this->getLanguage()->pipeList( $tools );
465 // Show a note if the user is blocked and display the last block log entry.
466 if ( $userObj->isBlocked() ) {
467 // LogEventsList::showLogExtract() wants the first parameter by ref
468 $out = $this->getOutput();
469 LogEventsList
::showLogExtract(
476 'showIfEmpty' => false,
478 'sp-contributions-blocked-notice',
479 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
481 'offset' => '' # don't use $this->getRequest() parameter offset
487 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
491 * Generates the namespace selector form with hidden attributes.
492 * @param array $options the options to be included.
495 function getForm( $options ) {
498 $options['title'] = $this->getTitle()->getPrefixedText();
499 if ( !isset( $options['target'] ) ) {
500 $options['target'] = '';
502 $options['target'] = str_replace( '_', ' ', $options['target'] );
505 if ( !isset( $options['namespace'] ) ) {
506 $options['namespace'] = '';
509 if ( !isset( $options['contribs'] ) ) {
510 $options['contribs'] = 'user';
513 if ( $options['contribs'] == 'newbie' ) {
514 $options['target'] = '';
517 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
519 foreach ( $options as $name => $value ) {
520 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
523 $f .= "\t" . Html
::hidden( $name, $value ) . "\n";
526 $f .= Xml
::openElement( 'fieldset' );
527 $f .= Xml
::element( 'legend', array(), $this->msg( 'sp-contributions-search' )->text() );
530 array( 'for' => 'target' ),
531 $this->msg( 'sp-contributions-username' )->parse()
540 ) +
( $options['target'] ?
array() : array( 'autofocus' ) )
542 $f .= Html
::namespaceSelector(
544 'selected' => $options['namespace'],
546 'label' => $this->msg( 'namespace' )->text()
549 'name' => 'namespace',
551 'class' => 'namespaceselector',
554 $f .= Xml
::submitButton( $this->msg( 'sp-contributions-submit' )->text() );
555 $f .= Xml
::closeElement( 'fieldset' );
556 $f .= Xml
::closeElement( 'form' );
561 protected function getGroupName() {