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 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
15 foreach( $msgs as $msg ) {
16 $this->messages
[$msg] = wfMsgExt( $msg, array( 'escapenoentities') );
18 $this->target
= $target;
19 $this->namespace = $namespace;
20 $this->mDb
= wfGetDB( DB_SLAVE
, 'contributions' );
23 function getDefaultQuery() {
24 $query = parent
::getDefaultQuery();
25 $query['target'] = $this->target
;
29 function getQueryInfo() {
31 list( $index, $userCond ) = $this->getUserCond();
32 $conds = array_merge( $userCond, $this->getNamespaceCond() );
33 // Paranoia: avoid brute force searches (bug 17792)
34 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
35 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::DELETED_USER
) . ' = 0';
36 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
37 $conds[] = $this->mDb
->bitAnd('ar_deleted',Revision
::SUPPRESSED_USER
) .
38 ' != ' . Revision
::SUPPRESSED_USER
;
41 'tables' => array( 'archive' ),
43 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
44 'ar_user', 'ar_user_text', 'ar_deleted'
47 'options' => array( 'USE INDEX' => $index )
51 function getUserCond() {
54 $condition['ar_user_text'] = $this->target
;
55 $index = 'usertext_timestamp';
57 return array( $index, $condition );
60 function getIndexField() {
61 return 'ar_timestamp';
64 function getStartBody() {
68 function getEndBody() {
72 function getNavigationBar() {
75 if ( isset( $this->mNavigationBar
) ) {
76 return $this->mNavigationBar
;
78 $fmtLimit = $wgLang->formatNum( $this->mLimit
);
80 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
81 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
82 'first' => wfMsgHtml( 'histlast' ),
83 'last' => wfMsgHtml( 'histfirst' )
86 $pagingLinks = $this->getPagingLinks( $linkTexts );
87 $limitLinks = $this->getLimitLinks();
88 $limits = $wgLang->pipeList( $limitLinks );
90 $this->mNavigationBar
= "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
91 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
92 return $this->mNavigationBar
;
95 function getNamespaceCond() {
96 if ( $this->namespace !== '' ) {
97 return array( 'ar_namespace' => (int)$this->namespace );
104 * Generates each row in the contributions list.
106 * Contributions which are marked "top" are currently on top of the history.
107 * For these contributions, a [rollback] link is shown for users with sysop
108 * privileges. The rollback link restores the most recent version that was not
109 * written by the target user.
111 * @todo This would probably look a lot nicer in a table.
113 function formatRow( $row ) {
114 global $wgUser, $wgLang;
115 wfProfileIn( __METHOD__
);
117 $sk = $this->getSkin();
119 $rev = new Revision( array(
120 'id' => $row->ar_rev_id
,
121 'comment' => $row->ar_comment
,
122 'user' => $row->ar_user
,
123 'user_text' => $row->ar_user_text
,
124 'timestamp' => $row->ar_timestamp
,
125 'minor_edit' => $row->ar_minor_edit
,
126 'deleted' => $row->ar_deleted
,
129 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
131 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
133 $logs = SpecialPage
::getTitleFor( 'Log' );
134 $dellog = $sk->linkKnown(
136 $this->messages
['deletionlog'],
140 'page' => $page->getPrefixedText()
144 $reviewlink = $sk->linkKnown(
145 SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
146 $this->messages
['undeleteviewlink']
149 if( $wgUser->isAllowed('deletedtext') ) {
150 $last = $sk->linkKnown(
152 $this->messages
['diff'],
155 'target' => $page->getPrefixedText(),
156 'timestamp' => $rev->getTimestamp(),
161 $last = $this->messages
['diff'];
164 $comment = $sk->revComment( $rev );
165 $date = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
167 if( !$wgUser->isAllowed('undelete') ||
!$rev->userCan(Revision
::DELETED_TEXT
) ) {
168 $link = $date; // unusable link
170 $link = $sk->linkKnown(
175 'target' => $page->getPrefixedText(),
176 'timestamp' => $rev->getTimestamp()
180 // Style deleted items
181 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
182 $link = '<span class="history-deleted">' . $link . '</span>';
185 $pagelink = $sk->link( $page );
187 if( $rev->isMinor() ) {
188 $mflag = ChangesList
::flag( 'minor' );
193 // Don't show useless link to people who cannot hide revisions
194 if( $wgUser->isAllowed('deleterevision') ||
($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
195 // If revision was hidden from sysops
196 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
197 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
198 '(' . $this->message
['rev-delundel'] . ')' ) . ' ';
199 // Otherwise, show the link...
203 'target' => $page->getPrefixedDbkey(),
204 'ids' => $rev->getTimestamp() );
205 $del = $this->mSkin
->revDeleteLink( $query,
206 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ) . ' ';
212 $tools = Html
::rawElement(
214 array( 'class' => 'mw-deletedcontribs-tools' ),
215 wfMsg( 'parentheses', $wgLang->pipeList( array( $last, $dellog, $reviewlink ) ) )
218 $ret = Html
::rawElement(
221 "{$del}{$link} {$tools} . . {$mflag} {$pagelink} {$comment}"
224 wfProfileOut( __METHOD__
);
229 * Get the Database object in use
233 public function getDatabase() {
238 class DeletedContributionsPage
extends SpecialPage
{
239 function __construct() {
240 parent
::__construct( 'DeletedContributions', 'deletedhistory',
241 /*listed*/ true, /*function*/ false, /*file*/ false );
245 * Special page "deleted user contributions".
246 * Shows a list of the deleted contributions of a user.
249 * @param $par String: (optional) user name of the user for which to show the contributions
251 function execute( $par ) {
255 if ( !$this->userCanExecute( $wgUser ) ) {
256 $this->displayRestrictionError();
260 global $wgUser, $wgOut, $wgLang, $wgRequest;
262 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
266 if ( isset( $par ) ) {
269 $target = $wgRequest->getVal( 'target' );
272 if ( !strlen( $target ) ) {
273 $wgOut->addHTML( $this->getForm( '' ) );
277 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
278 $options['target'] = $target;
280 $nt = Title
::makeTitleSafe( NS_USER
, $target );
282 $wgOut->addHTML( $this->getForm( '' ) );
285 $id = User
::idFromName( $nt->getText() );
287 $target = $nt->getText();
288 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
290 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
291 $options['namespace'] = intval( $ns );
293 $options['namespace'] = '';
296 $wgOut->addHTML( $this->getForm( $options ) );
298 $pager = new DeletedContribsPager( $target, $options['namespace'] );
299 if ( !$pager->getNumRows() ) {
300 $wgOut->addWikiMsg( 'nocontribs' );
304 # Show a message about slave lag, if applicable
305 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
306 $wgOut->showLagWarning( $lag );
309 '<p>' . $pager->getNavigationBar() . '</p>' .
311 '<p>' . $pager->getNavigationBar() . '</p>' );
313 # If there were contributions, and it was a valid user or IP, show
314 # the appropriate "footer" message - WHOIS tools, etc.
315 if( $target != 'newbies' ) {
316 $message = IP
::isIPAddress( $target )
317 ?
'sp-contributions-footer-anon'
318 : 'sp-contributions-footer';
321 $text = wfMsgNoTrans( $message, $target );
322 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
323 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
329 * Generates the subheading with links
330 * @param $nt @see Title object for the target
332 function getSubTitle( $nt, $id ) {
333 global $wgSysopUserBans, $wgLang, $wgUser;
335 $sk = $wgUser->getSkin();
338 $user = htmlspecialchars( $nt->getText() );
340 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
342 $talk = $nt->getTalkPage();
345 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
346 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
348 if( $wgUser->isAllowed( 'block' ) )
349 $tools[] = $sk->linkKnown(
350 SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
351 wfMsgHtml( 'blocklink' )
354 $tools[] = $sk->linkKnown(
355 SpecialPage
::getTitleFor( 'Log' ),
356 wfMsgHtml( 'sp-contributions-blocklog' ),
360 'page' => $nt->getPrefixedText()
365 $tools[] = $sk->linkKnown(
366 SpecialPage
::getTitleFor( 'Log' ),
367 wfMsgHtml( 'sp-contributions-logs' ),
369 array( 'user' => $nt->getText() )
371 # Link to undeleted contributions
372 $tools[] = $sk->linkKnown(
373 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
374 wfMsgHtml( 'sp-deletedcontributions-contribs' )
377 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
379 $links = $wgLang->pipeList( $tools );
382 // Old message 'contribsub' had one parameter, but that doesn't work for
383 // languages that want to put the "for" bit right after $user but before
384 // $links. If 'contribsub' is around, use it for reverse compatibility,
385 // otherwise use 'contribsub2'.
386 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
387 return wfMsgHtml( 'contribsub2', $user, $links );
389 return wfMsgHtml( 'contribsub', "$user ($links)" );
394 * Generates the namespace selector form with hidden attributes.
395 * @param $options Array: the options to be included.
397 function getForm( $options ) {
398 global $wgScript, $wgRequest;
400 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->getPrefixedText();
401 if ( !isset( $options['target'] ) ) {
402 $options['target'] = '';
404 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
407 if ( !isset( $options['namespace'] ) ) {
408 $options['namespace'] = '';
411 if ( !isset( $options['contribs'] ) ) {
412 $options['contribs'] = 'user';
415 if ( $options['contribs'] == 'newbie' ) {
416 $options['target'] = '';
419 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
421 foreach ( $options as $name => $value ) {
422 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
425 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
428 $f .= Xml
::openElement( 'fieldset' ) .
429 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
430 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
431 Html
::input( 'target', $options['target'], 'text', array(
434 ) +
( $options['target'] ?
array() : array( 'autofocus' ) ) ) . ' '.
435 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
436 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
437 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
438 Xml
::closeElement( 'fieldset' ) .
439 Xml
::closeElement( 'form' );