3 * Implements Special:DeletedContributions to display archived revisions
7 class DeletedContribsPager
extends IndexPager
{
8 public $mDefaultDirection = true;
9 var $messages, $target;
10 var $namespace = '', $mDb;
12 function __construct( $target, $namespace = false ) {
13 parent
::__construct();
14 foreach( explode( ' ', 'deletionlog undeletebtn minoreditletter diff' ) as $msg ) {
15 $this->messages
[$msg] = wfMsgExt( $msg, array( 'escape') );
17 $this->target
= $target;
18 $this->namespace = $namespace;
19 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
22 function getDefaultQuery() {
23 $query = parent
::getDefaultQuery();
24 $query['target'] = $this->target
;
28 function getQueryInfo() {
30 list( $index, $userCond ) = $this->getUserCond();
31 $conds = array_merge( $userCond, $this->getNamespaceCond() );
32 // Paranoia: avoid brute force searches (bug 17792)
33 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
34 $conds[] = $this->mDb
->bitAnd('ar_deleted', Revision
::DELETED_USER
) . ' = 0';
37 'tables' => array( 'archive' ),
39 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
40 'ar_user', 'ar_user_text', 'ar_deleted'
43 'options' => array( 'USE INDEX' => $index )
47 function getUserCond() {
50 $condition['ar_user_text'] = $this->target
;
51 $index = 'usertext_timestamp';
53 return array( $index, $condition );
56 function getIndexField() {
57 return 'ar_timestamp';
60 function getStartBody() {
64 function getEndBody() {
68 function getNavigationBar() {
71 if ( isset( $this->mNavigationBar
) ) {
72 return $this->mNavigationBar
;
75 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit
),
76 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit
),
77 'first' => wfMsgHtml( 'histlast' ),
78 'last' => wfMsgHtml( 'histfirst' )
81 $pagingLinks = $this->getPagingLinks( $linkTexts );
82 $limitLinks = $this->getLimitLinks();
83 $limits = $wgLang->pipeList( $limitLinks );
85 $this->mNavigationBar
= "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
86 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
87 return $this->mNavigationBar
;
90 function getNamespaceCond() {
91 if ( $this->namespace !== '' ) {
92 return array( 'ar_namespace' => (int)$this->namespace );
99 * Generates each row in the contributions list.
101 * Contributions which are marked "top" are currently on top of the history.
102 * For these contributions, a [rollback] link is shown for users with sysop
103 * privileges. The rollback link restores the most recent version that was not
104 * written by the target user.
106 * @todo This would probably look a lot nicer in a table.
108 function formatRow( $row ) {
109 global $wgUser, $wgLang;
110 wfProfileIn( __METHOD__
);
112 $sk = $this->getSkin();
114 $rev = new Revision( array(
115 'id' => $row->ar_rev_id
,
116 'comment' => $row->ar_comment
,
117 'user' => $row->ar_user
,
118 'user_text' => $row->ar_user_text
,
119 'timestamp' => $row->ar_timestamp
,
120 'minor_edit' => $row->ar_minor_edit
,
121 'deleted' => $row->ar_deleted
,
124 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
126 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
128 $logs = SpecialPage
::getTitleFor( 'Log' );
129 $dellog = $sk->linkKnown(
131 $this->messages
['deletionlog'],
135 'page' => $page->getPrefixedText()
139 $reviewlink = $sk->linkKnown(
140 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
141 $this->messages
['undeletebtn']
144 $link = $sk->linkKnown(
146 htmlspecialchars( $page->getPrefixedText() ),
149 'target' => $page->getPrefixedText(),
150 'timestamp' => $rev->getTimestamp()
154 $last = $sk->linkKnown(
156 $this->messages
['diff'],
159 'target' => $page->getPrefixedText(),
160 'timestamp' => $rev->getTimestamp(),
165 $comment = $sk->revComment( $rev );
166 $d = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
168 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
169 $d = '<span class="history-deleted">' . $d . '</span>';
171 $link = $sk->linkKnown(
176 'target' => $page->getPrefixedText(),
177 'timestamp' => $rev->getTimestamp()
182 $pagelink = $sk->link( $page );
184 if( $rev->isMinor() ) {
185 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
190 if( $wgUser->isAllowed( 'deleterevision' ) ) {
191 // If revision was hidden from sysops
192 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
193 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
194 '(' . $this->message
['rev-delundel'] . ')' ) . ' ';
195 // Otherwise, show the link...
199 'target' => $page->getPrefixedDbkey(),
200 'ids' => $rev->getTimestamp() );
201 $del = $this->mSkin
->revDeleteLink( $query,
202 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ) . ' ';
208 $ret = "{$del}{$link} ({$last}) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
210 $ret = "<li>$ret</li>\n";
212 wfProfileOut( __METHOD__
);
217 * Get the Database object in use
221 public function getDatabase() {
226 class DeletedContributionsPage
extends SpecialPage
{
227 function __construct() {
228 parent
::__construct( 'DeletedContributions', 'deletedhistory',
229 /*listed*/ true, /*function*/ false, /*file*/ false );
233 * Special page "deleted user contributions".
234 * Shows a list of the deleted contributions of a user.
237 * @param $par String: (optional) user name of the user for which to show the contributions
239 function execute( $par ) {
243 if ( !$this->userCanExecute( $wgUser ) ) {
244 $this->displayRestrictionError();
248 global $wgUser, $wgOut, $wgLang, $wgRequest;
250 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
254 if ( isset( $par ) ) {
257 $target = $wgRequest->getVal( 'target' );
260 if ( !strlen( $target ) ) {
261 $wgOut->addHTML( $this->getForm( '' ) );
265 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
266 $options['target'] = $target;
268 $nt = Title
::makeTitleSafe( NS_USER
, $target );
270 $wgOut->addHTML( $this->getForm( '' ) );
273 $id = User
::idFromName( $nt->getText() );
275 $target = $nt->getText();
276 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
278 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
279 $options['namespace'] = intval( $ns );
281 $options['namespace'] = '';
284 $wgOut->addHTML( $this->getForm( $options ) );
286 $pager = new DeletedContribsPager( $target, $options['namespace'] );
287 if ( !$pager->getNumRows() ) {
288 $wgOut->addWikiMsg( 'nocontribs' );
292 # Show a message about slave lag, if applicable
293 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
294 $wgOut->showLagWarning( $lag );
297 '<p>' . $pager->getNavigationBar() . '</p>' .
299 '<p>' . $pager->getNavigationBar() . '</p>' );
301 # If there were contributions, and it was a valid user or IP, show
302 # the appropriate "footer" message - WHOIS tools, etc.
303 if( $target != 'newbies' ) {
304 $message = IP
::isIPAddress( $target )
305 ?
'sp-contributions-footer-anon'
306 : 'sp-contributions-footer';
309 $text = wfMsgNoTrans( $message, $target );
310 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
311 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
317 * Generates the subheading with links
318 * @param $nt @see Title object for the target
320 function getSubTitle( $nt, $id ) {
321 global $wgSysopUserBans, $wgLang, $wgUser;
323 $sk = $wgUser->getSkin();
326 $user = $nt->getText();
328 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
330 $talk = $nt->getTalkPage();
333 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
334 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
336 if( $wgUser->isAllowed( 'block' ) )
337 $tools[] = $sk->linkKnown(
338 SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
339 wfMsgHtml( 'blocklink' )
342 $tools[] = $sk->linkKnown(
343 SpecialPage
::getTitleFor( 'Log' ),
344 wfMsgHtml( 'sp-contributions-blocklog' ),
348 'page' => $nt->getPrefixedText()
353 $tools[] = $sk->linkKnown(
354 SpecialPage
::getTitleFor( 'Log' ),
355 wfMsgHtml( 'sp-contributions-logs' ),
357 array( 'user' => $nt->getText() )
359 # Link to undeleted contributions
360 $tools[] = $sk->linkKnown(
361 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
362 wfMsgHtml( 'sp-deletedcontributions-contribs' )
365 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
367 $links = $wgLang->pipeList( $tools );
370 // Old message 'contribsub' had one parameter, but that doesn't work for
371 // languages that want to put the "for" bit right after $user but before
372 // $links. If 'contribsub' is around, use it for reverse compatibility,
373 // otherwise use 'contribsub2'.
374 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
375 return wfMsgHtml( 'contribsub2', $user, $links );
377 return wfMsgHtml( 'contribsub', "$user ($links)" );
382 * Generates the namespace selector form with hidden attributes.
383 * @param $options Array: the options to be included.
385 function getForm( $options ) {
386 global $wgScript, $wgRequest;
388 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->getPrefixedText();
389 if ( !isset( $options['target'] ) ) {
390 $options['target'] = '';
392 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
395 if ( !isset( $options['namespace'] ) ) {
396 $options['namespace'] = '';
399 if ( !isset( $options['contribs'] ) ) {
400 $options['contribs'] = 'user';
403 if ( $options['contribs'] == 'newbie' ) {
404 $options['target'] = '';
407 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
409 foreach ( $options as $name => $value ) {
410 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
413 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
416 $f .= Xml
::openElement( 'fieldset' ) .
417 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
418 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
419 Xml
::input( 'target', 20, $options['target']) . ' '.
420 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
421 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
422 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
423 Xml
::closeElement( 'fieldset' ) .
424 Xml
::closeElement( 'form' );