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() {
29 list( $index, $userCond ) = $this->getUserCond();
30 $conds = array_merge( $userCond, $this->getNamespaceCond() );
33 'tables' => array( 'archive' ),
35 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
36 'ar_user', 'ar_user_text', 'ar_deleted'
39 'options' => array( 'USE INDEX' => $index )
43 function getUserCond() {
46 $condition['ar_user_text'] = $this->target
;
47 $index = 'usertext_timestamp';
49 return array( $index, $condition );
52 function getIndexField() {
53 return 'ar_timestamp';
56 function getStartBody() {
60 function getEndBody() {
64 function getNavigationBar() {
65 if ( isset( $this->mNavigationBar
) ) {
66 return $this->mNavigationBar
;
69 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit
),
70 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit
),
71 'first' => wfMsgHtml( 'histlast' ),
72 'last' => wfMsgHtml( 'histfirst' )
75 $pagingLinks = $this->getPagingLinks( $linkTexts );
76 $limitLinks = $this->getLimitLinks();
77 $limits = implode( ' | ', $limitLinks );
79 $this->mNavigationBar
= "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
80 wfMsgExt( 'viewprevnext', array( 'parsemag' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
81 return $this->mNavigationBar
;
84 function getNamespaceCond() {
85 if ( $this->namespace !== '' ) {
86 return array( 'ar_namespace' => (int)$this->namespace );
93 * Generates each row in the contributions list.
95 * Contributions which are marked "top" are currently on top of the history.
96 * For these contributions, a [rollback] link is shown for users with sysop
97 * privileges. The rollback link restores the most recent version that was not
98 * written by the target user.
100 * @todo This would probably look a lot nicer in a table.
102 function formatRow( $row ) {
103 wfProfileIn( __METHOD__
);
105 global $wgLang, $wgUser;
107 $sk = $this->getSkin();
109 $rev = new Revision( array(
110 'id' => $row->ar_rev_id
,
111 'comment' => $row->ar_comment
,
112 'user' => $row->ar_user
,
113 'user_text' => $row->ar_user_text
,
114 'timestamp' => $row->ar_timestamp
,
115 'minor_edit' => $row->ar_minor_edit
,
116 'rev_deleted' => $row->ar_deleted
,
119 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
121 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
123 $logs = SpecialPage
::getTitleFor( 'Log' );
124 $dellog = $sk->makeKnownLinkObj( $logs,
125 $this->messages
['deletionlog'],
126 'type=delete&page=' . $page->getPrefixedUrl() );
128 $reviewlink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
129 $this->messages
['undeletebtn'] );
131 $link = $sk->makeKnownLinkObj( $undelete,
132 htmlspecialchars( $page->getPrefixedText() ),
133 'target=' . $page->getPrefixedUrl() .
134 '×tamp=' . $rev->getTimestamp() );
136 $last = $sk->makeKnownLinkObj( $undelete,
137 $this->messages
['diff'],
138 "target=" . $page->getPrefixedUrl() .
139 "×tamp=" . $rev->getTimestamp() .
142 $comment = $sk->revComment( $rev );
143 $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
145 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
146 $d = '<span class="history-deleted">' . $d . '</span>';
148 $link = $sk->makeKnownLinkObj( $undelete, $d,
149 'target=' . $page->getPrefixedUrl() .
150 '×tamp=' . $rev->getTimestamp() );
153 $pagelink = $sk->makeLinkObj( $page );
155 if( $rev->isMinor() ) {
156 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
162 $ret = "{$link} ($last) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
163 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
164 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
167 $ret = "<li>$ret</li>\n";
169 wfProfileOut( __METHOD__
);
174 * Get the Database object in use
178 public function getDatabase() {
183 class DeletedContributionsPage
extends SpecialPage
{
184 function __construct() {
185 parent
::__construct( 'DeletedContributions', 'deletedhistory',
186 /*listed*/ true, /*function*/ false, /*file*/ false );
190 * Special page "deleted user contributions".
191 * Shows a list of the deleted contributions of a user.
194 * @param $par String: (optional) user name of the user for which to show the contributions
196 function execute( $par ) {
200 if ( !$this->userCanExecute( $wgUser ) ) {
201 $this->displayRestrictionError();
205 global $wgUser, $wgOut, $wgLang, $wgRequest;
207 $wgOut->setPageTitle( wfMsg( 'deletedcontributions-title' ) );
211 if ( isset( $par ) ) {
214 $target = $wgRequest->getVal( 'target' );
217 if ( !strlen( $target ) ) {
218 $wgOut->addHTML( $this->getForm( '' ) );
222 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
223 $options['target'] = $target;
225 $nt = Title
::makeTitleSafe( NS_USER
, $target );
227 $wgOut->addHTML( $this->getForm( '' ) );
230 $id = User
::idFromName( $nt->getText() );
232 $target = $nt->getText();
233 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
235 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
236 $options['namespace'] = intval( $ns );
238 $options['namespace'] = '';
241 $wgOut->addHTML( $this->getForm( $options ) );
243 $pager = new DeletedContribsPager( $target, $options['namespace'] );
244 if ( !$pager->getNumRows() ) {
245 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
249 # Show a message about slave lag, if applicable
250 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
251 $wgOut->showLagWarning( $lag );
254 '<p>' . $pager->getNavigationBar() . '</p>' .
256 '<p>' . $pager->getNavigationBar() . '</p>' );
258 # If there were contributions, and it was a valid user or IP, show
259 # the appropriate "footer" message - WHOIS tools, etc.
260 if( $target != 'newbies' ) {
261 $message = IP
::isIPAddress( $target )
262 ?
'sp-contributions-footer-anon'
263 : 'sp-contributions-footer';
266 $text = wfMsgNoTrans( $message, $target );
267 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
268 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
269 $wgOut->addWikiText( $text );
270 $wgOut->addHTML( '</div>' );
276 * Generates the subheading with links
277 * @param $nt @see Title object for the target
279 function getSubTitle( $nt, $id ) {
280 global $wgSysopUserBans, $wgLang, $wgUser;
282 $sk = $wgUser->getSkin();
285 $user = $nt->getText();
287 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
289 $talk = $nt->getTalkPage();
292 $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
293 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
295 if( $wgUser->isAllowed( 'block' ) )
296 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
297 wfMsgHtml( 'blocklink' ) );
299 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
300 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
303 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
304 wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
305 # Link to undeleted contributions
306 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
307 wfMsgHtml( 'contributions' ) );
309 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
311 $links = implode( ' | ', $tools );
314 // Old message 'contribsub' had one parameter, but that doesn't work for
315 // languages that want to put the "for" bit right after $user but before
316 // $links. If 'contribsub' is around, use it for reverse compatibility,
317 // otherwise use 'contribsub2'.
318 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
319 return wfMsgHtml( 'contribsub2', $user, $links );
321 return wfMsgHtml( 'contribsub', "$user ($links)" );
326 * Generates the namespace selector form with hidden attributes.
327 * @param $options Array: the options to be included.
329 function getForm( $options ) {
330 global $wgScript, $wgTitle, $wgRequest;
332 $options['title'] = $wgTitle->getPrefixedText();
333 if ( !isset( $options['target'] ) ) {
334 $options['target'] = '';
336 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
339 if ( !isset( $options['namespace'] ) ) {
340 $options['namespace'] = '';
343 if ( !isset( $options['contribs'] ) ) {
344 $options['contribs'] = 'user';
347 if ( $options['contribs'] == 'newbie' ) {
348 $options['target'] = '';
351 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
353 foreach ( $options as $name => $value ) {
354 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
357 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
360 $f .= Xml
::openElement( 'fieldset' ) .
361 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
362 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
363 Xml
::input( 'target', 20, $options['target']) . ' '.
364 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
365 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
366 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
367 Xml
::closeElement( 'fieldset' ) .
368 Xml
::closeElement( 'form' );