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[] = '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->makeKnownLinkObj( $logs,
130 $this->messages
['deletionlog'],
131 'type=delete&page=' . $page->getPrefixedUrl() );
133 $reviewlink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
134 $this->messages
['undeletebtn'] );
136 $link = $sk->makeKnownLinkObj( $undelete,
137 htmlspecialchars( $page->getPrefixedText() ),
138 'target=' . $page->getPrefixedUrl() .
139 '×tamp=' . $rev->getTimestamp() );
141 $last = $sk->makeKnownLinkObj( $undelete,
142 $this->messages
['diff'],
143 "target=" . $page->getPrefixedUrl() .
144 "×tamp=" . $rev->getTimestamp() .
147 $comment = $sk->revComment( $rev );
148 $d = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
150 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
151 $d = '<span class="history-deleted">' . $d . '</span>';
153 $link = $sk->makeKnownLinkObj( $undelete, $d,
154 'target=' . $page->getPrefixedUrl() .
155 '×tamp=' . $rev->getTimestamp() );
158 $pagelink = $sk->link( $page );
160 if( $rev->isMinor() ) {
161 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
166 if( $wgUser->isAllowed( 'deleterevision' ) ) {
167 // If revision was hidden from sysops
168 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
169 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
170 '(' . $this->message
['rev-delundel'] . ')' ) . ' ';
171 // Otherwise, show the link...
173 $query = array( 'target' => $page->getPrefixedDbkey(),
174 'artimestamp' => $rev->getTimestamp() );
175 $del = $this->mSkin
->revDeleteLink( $query,
176 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ) . ' ';
182 $ret = "{$del}{$link} ({$last}) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
184 $ret = "<li>$ret</li>\n";
186 wfProfileOut( __METHOD__
);
191 * Get the Database object in use
195 public function getDatabase() {
200 class DeletedContributionsPage
extends SpecialPage
{
201 function __construct() {
202 parent
::__construct( 'DeletedContributions', 'deletedhistory',
203 /*listed*/ true, /*function*/ false, /*file*/ false );
207 * Special page "deleted user contributions".
208 * Shows a list of the deleted contributions of a user.
211 * @param $par String: (optional) user name of the user for which to show the contributions
213 function execute( $par ) {
217 if ( !$this->userCanExecute( $wgUser ) ) {
218 $this->displayRestrictionError();
222 global $wgUser, $wgOut, $wgLang, $wgRequest;
224 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
228 if ( isset( $par ) ) {
231 $target = $wgRequest->getVal( 'target' );
234 if ( !strlen( $target ) ) {
235 $wgOut->addHTML( $this->getForm( '' ) );
239 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
240 $options['target'] = $target;
242 $nt = Title
::makeTitleSafe( NS_USER
, $target );
244 $wgOut->addHTML( $this->getForm( '' ) );
247 $id = User
::idFromName( $nt->getText() );
249 $target = $nt->getText();
250 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
252 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
253 $options['namespace'] = intval( $ns );
255 $options['namespace'] = '';
258 $wgOut->addHTML( $this->getForm( $options ) );
260 $pager = new DeletedContribsPager( $target, $options['namespace'] );
261 if ( !$pager->getNumRows() ) {
262 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
266 # Show a message about slave lag, if applicable
267 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
268 $wgOut->showLagWarning( $lag );
271 '<p>' . $pager->getNavigationBar() . '</p>' .
273 '<p>' . $pager->getNavigationBar() . '</p>' );
275 # If there were contributions, and it was a valid user or IP, show
276 # the appropriate "footer" message - WHOIS tools, etc.
277 if( $target != 'newbies' ) {
278 $message = IP
::isIPAddress( $target )
279 ?
'sp-contributions-footer-anon'
280 : 'sp-contributions-footer';
283 $text = wfMsgNoTrans( $message, $target );
284 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
285 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
286 $wgOut->addWikiText( $text );
287 $wgOut->addHTML( '</div>' );
293 * Generates the subheading with links
294 * @param $nt @see Title object for the target
296 function getSubTitle( $nt, $id ) {
297 global $wgSysopUserBans, $wgLang, $wgUser;
299 $sk = $wgUser->getSkin();
302 $user = $nt->getText();
304 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
306 $talk = $nt->getTalkPage();
309 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
310 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
312 if( $wgUser->isAllowed( 'block' ) )
313 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
314 wfMsgHtml( 'blocklink' ) );
316 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
317 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
320 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
321 wfMsgHtml( 'sp-contributions-logs' ), 'user=' . $nt->getPartialUrl() );
322 # Link to undeleted contributions
323 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
324 wfMsgHtml( 'contributions' ) );
326 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
328 $links = $wgLang->pipeList( $tools );
331 // Old message 'contribsub' had one parameter, but that doesn't work for
332 // languages that want to put the "for" bit right after $user but before
333 // $links. If 'contribsub' is around, use it for reverse compatibility,
334 // otherwise use 'contribsub2'.
335 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
336 return wfMsgHtml( 'contribsub2', $user, $links );
338 return wfMsgHtml( 'contribsub', "$user ($links)" );
343 * Generates the namespace selector form with hidden attributes.
344 * @param $options Array: the options to be included.
346 function getForm( $options ) {
347 global $wgScript, $wgRequest;
349 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->getPrefixedText();
350 if ( !isset( $options['target'] ) ) {
351 $options['target'] = '';
353 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
356 if ( !isset( $options['namespace'] ) ) {
357 $options['namespace'] = '';
360 if ( !isset( $options['contribs'] ) ) {
361 $options['contribs'] = 'user';
364 if ( $options['contribs'] == 'newbie' ) {
365 $options['target'] = '';
368 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
370 foreach ( $options as $name => $value ) {
371 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
374 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
377 $f .= Xml
::openElement( 'fieldset' ) .
378 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
379 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
380 Xml
::input( 'target', 20, $options['target']) . ' '.
381 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
382 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
383 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
384 Xml
::closeElement( 'fieldset' ) .
385 Xml
::closeElement( 'form' );