7c4ec1240a26e1feace00ae691929367c78582df
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * Implements Special:DeletedContributions to display archived revisions
22 * @ingroup SpecialPage
25 class DeletedContribsPager
extends IndexPager
{
26 public $mDefaultDirection = true;
27 var $messages, $target;
28 var $namespace = '', $mDb;
30 function __construct( $target, $namespace = false ) {
31 parent
::__construct();
32 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
33 foreach( $msgs as $msg ) {
34 $this->messages
[$msg] = wfMsgExt( $msg, array( 'escapenoentities') );
36 $this->target
= $target;
37 $this->namespace = $namespace;
38 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
41 function getDefaultQuery() {
42 $query = parent
::getDefaultQuery();
43 $query['target'] = $this->target
;
47 function getQueryInfo() {
49 list( $index, $userCond ) = $this->getUserCond();
50 $conds = array_merge( $userCond, $this->getNamespaceCond() );
51 // Paranoia: avoid brute force searches (bug 17792)
52 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
53 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::DELETED_USER
) . ' = 0';
54 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
55 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::SUPPRESSED_USER
) .
56 ' != ' . Revision
::SUPPRESSED_USER
;
59 'tables' => array( 'archive' ),
61 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
62 'ar_user', 'ar_user_text', 'ar_deleted'
65 'options' => array( 'USE INDEX' => $index )
69 function getUserCond() {
72 $condition['ar_user_text'] = $this->target
;
73 $index = 'usertext_timestamp';
75 return array( $index, $condition );
78 function getIndexField() {
79 return 'ar_timestamp';
82 function getStartBody() {
86 function getEndBody() {
90 function getNavigationBar() {
93 if ( isset( $this->mNavigationBar
) ) {
94 return $this->mNavigationBar
;
96 $fmtLimit = $wgLang->formatNum( $this->mLimit
);
98 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
99 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
100 'first' => wfMsgHtml( 'histlast' ),
101 'last' => wfMsgHtml( 'histfirst' )
104 $pagingLinks = $this->getPagingLinks( $linkTexts );
105 $limitLinks = $this->getLimitLinks();
106 $limits = $wgLang->pipeList( $limitLinks );
108 $this->mNavigationBar
= "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
109 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
110 return $this->mNavigationBar
;
113 function getNamespaceCond() {
114 if ( $this->namespace !== '' ) {
115 return array( 'ar_namespace' => (int)$this->namespace );
122 * Generates each row in the contributions list.
124 * Contributions which are marked "top" are currently on top of the history.
125 * For these contributions, a [rollback] link is shown for users with sysop
126 * privileges. The rollback link restores the most recent version that was not
127 * written by the target user.
129 * @todo This would probably look a lot nicer in a table.
131 function formatRow( $row ) {
132 global $wgUser, $wgLang;
133 wfProfileIn( __METHOD__
);
135 $sk = $this->getSkin();
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 = $sk->linkKnown(
154 $this->messages
['deletionlog'],
158 'page' => $page->getPrefixedText()
162 $reviewlink = $sk->linkKnown(
163 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
164 $this->messages
['undeleteviewlink']
167 if( $wgUser->isAllowed('deletedtext') ) {
168 $last = $sk->linkKnown(
170 $this->messages
['diff'],
173 'target' => $page->getPrefixedText(),
174 'timestamp' => $rev->getTimestamp(),
179 $last = $this->messages
['diff'];
182 $comment = $sk->revComment( $rev );
183 $date = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
185 if( !$wgUser->isAllowed('undelete') ||
!$rev->userCan(Revision
::DELETED_TEXT
) ) {
186 $link = $date; // unusable link
188 $link = $sk->linkKnown(
193 'target' => $page->getPrefixedText(),
194 'timestamp' => $rev->getTimestamp()
198 // Style deleted items
199 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
200 $link = '<span class="history-deleted">' . $link . '</span>';
203 $pagelink = $sk->link( $page );
205 if( $rev->isMinor() ) {
206 $mflag = ChangesList
::flag( 'minor' );
211 // Revision delete link
212 $canHide = $wgUser->isAllowed( 'deleterevision' );
213 if( $canHide ||
($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
214 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
215 $del = $this->mSkin
->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
219 'target' => $page->getPrefixedDbkey(),
220 'ids' => $rev->getTimestamp() );
221 $del = $this->mSkin
->revDeleteLink( $query,
222 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), $canHide ) . ' ';
228 $tools = Html
::rawElement(
230 array( 'class' => 'mw-deletedcontribs-tools' ),
231 wfMsg( 'parentheses', $wgLang->pipeList( array( $last, $dellog, $reviewlink ) ) )
234 $ret = "{$del}{$link} {$tools} . . {$mflag} {$pagelink} {$comment}";
236 # Denote if username is redacted for this edit
237 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
238 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
241 $ret = Html
::rawElement( 'li', array(), $ret ) . "\n";
243 wfProfileOut( __METHOD__
);
248 * Get the Database object in use
252 public function getDatabase() {
257 class DeletedContributionsPage
extends SpecialPage
{
258 function __construct() {
259 parent
::__construct( 'DeletedContributions', 'deletedhistory',
260 /*listed*/ true, /*function*/ false, /*file*/ false );
264 * Special page "deleted user contributions".
265 * Shows a list of the deleted contributions of a user.
268 * @param $par String: (optional) user name of the user for which to show the contributions
270 function execute( $par ) {
274 if ( !$this->userCanExecute( $wgUser ) ) {
275 $this->displayRestrictionError();
279 global $wgOut, $wgLang, $wgRequest;
281 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
285 if ( isset( $par ) ) {
288 $target = $wgRequest->getVal( 'target' );
291 if ( !strlen( $target ) ) {
292 $wgOut->addHTML( $this->getForm( '' ) );
296 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
297 $options['target'] = $target;
299 $nt = Title
::makeTitleSafe( NS_USER
, $target );
301 $wgOut->addHTML( $this->getForm( '' ) );
304 $id = User
::idFromName( $nt->getText() );
306 $target = $nt->getText();
307 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
309 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
310 $options['namespace'] = intval( $ns );
312 $options['namespace'] = '';
315 $wgOut->addHTML( $this->getForm( $options ) );
317 $pager = new DeletedContribsPager( $target, $options['namespace'] );
318 if ( !$pager->getNumRows() ) {
319 $wgOut->addWikiMsg( 'nocontribs' );
323 # Show a message about slave lag, if applicable
324 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
325 $wgOut->showLagWarning( $lag );
328 '<p>' . $pager->getNavigationBar() . '</p>' .
330 '<p>' . $pager->getNavigationBar() . '</p>' );
332 # If there were contributions, and it was a valid user or IP, show
333 # the appropriate "footer" message - WHOIS tools, etc.
334 if( $target != 'newbies' ) {
335 $message = IP
::isIPAddress( $target )
336 ?
'sp-contributions-footer-anon'
337 : 'sp-contributions-footer';
340 $text = wfMsgNoTrans( $message, $target );
341 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
342 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
348 * Generates the subheading with links
349 * @param $nt Title object for the target
350 * @param $id Integer: User ID for the target
351 * @return String: appropriately-escaped HTML to be output literally
352 * @todo Fixme: almost the same as contributionsSub in SpecialContributions.php. Could be combined.
354 function getSubTitle( $nt, $id ) {
355 global $wgSysopUserBans, $wgLang, $wgUser, $wgOut;
357 $sk = $wgUser->getSkin();
359 if ( $id === null ) {
360 $user = htmlspecialchars( $nt->getText() );
362 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
364 $userObj = User
::newFromName( $nt->getText(), /* check for username validity not needed */ false );
365 $talk = $nt->getTalkPage();
368 $tools[] = $sk->link( $talk, wfMsgHtml( 'sp-contributions-talk' ) );
369 if( ( $id !== null && $wgSysopUserBans ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
370 if( $wgUser->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
371 if ( $userObj->isBlocked() ) {
372 $tools[] = $sk->linkKnown( # Change block link
373 SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
374 wfMsgHtml( 'change-blocklink' )
376 $tools[] = $sk->linkKnown( # Unblock link
377 SpecialPage
::getTitleFor( 'BlockList' ),
378 wfMsgHtml( 'unblocklink' ),
381 'action' => 'unblock',
382 'ip' => $nt->getDBkey()
386 else { # User is not blocked
387 $tools[] = $sk->linkKnown( # Block link
388 SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
389 wfMsgHtml( 'blocklink' )
394 $tools[] = $sk->linkKnown(
395 SpecialPage
::getTitleFor( 'Log' ),
396 wfMsgHtml( 'sp-contributions-blocklog' ),
400 'page' => $nt->getPrefixedText()
405 $tools[] = $sk->linkKnown(
406 SpecialPage
::getTitleFor( 'Log' ),
407 wfMsgHtml( 'sp-contributions-logs' ),
409 array( 'user' => $nt->getText() )
411 # Link to contributions
412 $tools[] = $sk->linkKnown(
413 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
414 wfMsgHtml( 'sp-deletedcontributions-contribs' )
417 # Add a link to change user rights for privileged users
418 $userrightsPage = new UserrightsPage();
419 if( $id !== null && $userrightsPage->userCanChangeRights( User
::newFromId( $id ) ) ) {
420 $tools[] = $sk->linkKnown(
421 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
422 wfMsgHtml( 'sp-contributions-userrights' )
426 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
428 $links = $wgLang->pipeList( $tools );
430 // Show a note if the user is blocked and display the last block log entry.
431 if ( $userObj->isBlocked() ) {
432 LogEventsList
::showLogExtract(
435 $nt->getPrefixedText(),
439 'showIfEmpty' => false,
441 'sp-contributions-blocked-notice',
442 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
444 'offset' => '' # don't use $wgRequest parameter offset
450 // Old message 'contribsub' had one parameter, but that doesn't work for
451 // languages that want to put the "for" bit right after $user but before
452 // $links. If 'contribsub' is around, use it for reverse compatibility,
453 // otherwise use 'contribsub2'.
454 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
455 return wfMsgHtml( 'contribsub2', $user, $links );
457 return wfMsgHtml( 'contribsub', "$user ($links)" );
462 * Generates the namespace selector form with hidden attributes.
463 * @param $options Array: the options to be included.
465 function getForm( $options ) {
466 global $wgScript, $wgRequest;
468 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->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" . Xml
::hidden( $name, $value ) . "\n";
496 $f .= Xml
::openElement( 'fieldset' ) .
497 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
498 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
499 Html
::input( 'target', $options['target'], 'text', array(
502 ) +
( $options['target'] ?
array() : array( 'autofocus' ) ) ) . ' '.
503 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
504 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
505 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
506 Xml
::closeElement( 'fieldset' ) .
507 Xml
::closeElement( 'form' );