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 undeleteviewlink 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( 'deleterevision' ) ) {
34 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::DELETED_USER
) . ' = 0';
35 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
36 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::SUPPRESSED_USER
) .
37 ' != ' . Revision
::SUPPRESSED_USER
;
40 'tables' => array( 'archive' ),
42 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
43 'ar_user', 'ar_user_text', 'ar_deleted'
46 'options' => array( 'USE INDEX' => $index )
50 function getUserCond() {
53 $condition['ar_user_text'] = $this->target
;
54 $index = 'usertext_timestamp';
56 return array( $index, $condition );
59 function getIndexField() {
60 return 'ar_timestamp';
63 function getStartBody() {
67 function getEndBody() {
71 function getNavigationBar() {
74 if ( isset( $this->mNavigationBar
) ) {
75 return $this->mNavigationBar
;
77 $fmtLimit = $wgLang->formatNum( $this->mLimit
);
79 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
80 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
81 'first' => wfMsgHtml( 'histlast' ),
82 'last' => wfMsgHtml( 'histfirst' )
85 $pagingLinks = $this->getPagingLinks( $linkTexts );
86 $limitLinks = $this->getLimitLinks();
87 $limits = $wgLang->pipeList( $limitLinks );
89 $this->mNavigationBar
= "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
90 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
91 return $this->mNavigationBar
;
94 function getNamespaceCond() {
95 if ( $this->namespace !== '' ) {
96 return array( 'ar_namespace' => (int)$this->namespace );
103 * Generates each row in the contributions list.
105 * Contributions which are marked "top" are currently on top of the history.
106 * For these contributions, a [rollback] link is shown for users with sysop
107 * privileges. The rollback link restores the most recent version that was not
108 * written by the target user.
110 * @todo This would probably look a lot nicer in a table.
112 function formatRow( $row ) {
113 global $wgUser, $wgLang;
114 wfProfileIn( __METHOD__
);
116 $sk = $this->getSkin();
118 $rev = new Revision( array(
119 'id' => $row->ar_rev_id
,
120 'comment' => $row->ar_comment
,
121 'user' => $row->ar_user
,
122 'user_text' => $row->ar_user_text
,
123 'timestamp' => $row->ar_timestamp
,
124 'minor_edit' => $row->ar_minor_edit
,
125 'deleted' => $row->ar_deleted
,
128 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
130 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
132 $logs = SpecialPage
::getTitleFor( 'Log' );
133 $dellog = $sk->linkKnown(
135 $this->messages
['deletionlog'],
139 'page' => $page->getPrefixedText()
143 $reviewlink = $sk->linkKnown(
144 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
145 $this->messages
['undeleteviewlink']
148 $last = $sk->linkKnown(
150 $this->messages
['diff'],
153 'target' => $page->getPrefixedText(),
154 'timestamp' => $rev->getTimestamp(),
159 $comment = $sk->revComment( $rev );
160 $date = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
162 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
163 $link = '<span class="history-deleted">' . $date . '</span>';
165 $link = $sk->linkKnown(
170 'target' => $page->getPrefixedText(),
171 'timestamp' => $rev->getTimestamp()
176 $pagelink = $sk->link( $page );
178 if( $rev->isMinor() ) {
179 $mflag = '<abbr class="minor">' . $this->messages
['minoreditletter'] . '</abbr> ';
184 if( $wgUser->isAllowed( 'deleterevision' ) ) {
185 // If revision was hidden from sysops
186 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
187 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
188 '(' . $this->message
['rev-delundel'] . ')' ) . ' ';
189 // Otherwise, show the link...
193 'target' => $page->getPrefixedDbkey(),
194 'ids' => $rev->getTimestamp() );
195 $del = $this->mSkin
->revDeleteLink( $query,
196 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ) . ' ';
202 $ret = "{$del}{$link} ({$last}) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
204 $ret = "<li>$ret</li>\n";
206 wfProfileOut( __METHOD__
);
211 * Get the Database object in use
215 public function getDatabase() {
220 class DeletedContributionsPage
extends SpecialPage
{
221 function __construct() {
222 parent
::__construct( 'DeletedContributions', 'deletedhistory',
223 /*listed*/ true, /*function*/ false, /*file*/ false );
227 * Special page "deleted user contributions".
228 * Shows a list of the deleted contributions of a user.
231 * @param $par String: (optional) user name of the user for which to show the contributions
233 function execute( $par ) {
237 if ( !$this->userCanExecute( $wgUser ) ) {
238 $this->displayRestrictionError();
242 global $wgUser, $wgOut, $wgLang, $wgRequest;
244 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
248 if ( isset( $par ) ) {
251 $target = $wgRequest->getVal( 'target' );
254 if ( !strlen( $target ) ) {
255 $wgOut->addHTML( $this->getForm( '' ) );
259 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
260 $options['target'] = $target;
262 $nt = Title
::makeTitleSafe( NS_USER
, $target );
264 $wgOut->addHTML( $this->getForm( '' ) );
267 $id = User
::idFromName( $nt->getText() );
269 $target = $nt->getText();
270 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
272 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
273 $options['namespace'] = intval( $ns );
275 $options['namespace'] = '';
278 $wgOut->addHTML( $this->getForm( $options ) );
280 $pager = new DeletedContribsPager( $target, $options['namespace'] );
281 if ( !$pager->getNumRows() ) {
282 $wgOut->addWikiMsg( 'nocontribs' );
286 # Show a message about slave lag, if applicable
287 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
288 $wgOut->showLagWarning( $lag );
291 '<p>' . $pager->getNavigationBar() . '</p>' .
293 '<p>' . $pager->getNavigationBar() . '</p>' );
295 # If there were contributions, and it was a valid user or IP, show
296 # the appropriate "footer" message - WHOIS tools, etc.
297 if( $target != 'newbies' ) {
298 $message = IP
::isIPAddress( $target )
299 ?
'sp-contributions-footer-anon'
300 : 'sp-contributions-footer';
303 $text = wfMsgNoTrans( $message, $target );
304 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
305 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
311 * Generates the subheading with links
312 * @param $nt @see Title object for the target
314 function getSubTitle( $nt, $id ) {
315 global $wgSysopUserBans, $wgLang, $wgUser;
317 $sk = $wgUser->getSkin();
320 $user = htmlspecialchars( $nt->getText() );
322 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
324 $talk = $nt->getTalkPage();
327 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
328 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
330 if( $wgUser->isAllowed( 'block' ) )
331 $tools[] = $sk->linkKnown(
332 SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
333 wfMsgHtml( 'blocklink' )
336 $tools[] = $sk->linkKnown(
337 SpecialPage
::getTitleFor( 'Log' ),
338 wfMsgHtml( 'sp-contributions-blocklog' ),
342 'page' => $nt->getPrefixedText()
347 $tools[] = $sk->linkKnown(
348 SpecialPage
::getTitleFor( 'Log' ),
349 wfMsgHtml( 'sp-contributions-logs' ),
351 array( 'user' => $nt->getText() )
353 # Link to undeleted contributions
354 $tools[] = $sk->linkKnown(
355 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
356 wfMsgHtml( 'sp-deletedcontributions-contribs' )
359 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
361 $links = $wgLang->pipeList( $tools );
364 // Old message 'contribsub' had one parameter, but that doesn't work for
365 // languages that want to put the "for" bit right after $user but before
366 // $links. If 'contribsub' is around, use it for reverse compatibility,
367 // otherwise use 'contribsub2'.
368 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
369 return wfMsgHtml( 'contribsub2', $user, $links );
371 return wfMsgHtml( 'contribsub', "$user ($links)" );
376 * Generates the namespace selector form with hidden attributes.
377 * @param $options Array: the options to be included.
379 function getForm( $options ) {
380 global $wgScript, $wgRequest;
382 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->getPrefixedText();
383 if ( !isset( $options['target'] ) ) {
384 $options['target'] = '';
386 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
389 if ( !isset( $options['namespace'] ) ) {
390 $options['namespace'] = '';
393 if ( !isset( $options['contribs'] ) ) {
394 $options['contribs'] = 'user';
397 if ( $options['contribs'] == 'newbie' ) {
398 $options['target'] = '';
401 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
403 foreach ( $options as $name => $value ) {
404 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
407 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
410 $f .= Xml
::openElement( 'fieldset' ) .
411 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
412 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
413 Xml
::input( 'target', 20, $options['target']) . ' '.
414 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
415 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
416 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
417 Xml
::closeElement( 'fieldset' ) .
418 Xml
::closeElement( 'form' );