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() {
67 if ( isset( $this->mNavigationBar
) ) {
68 return $this->mNavigationBar
;
71 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit
),
72 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit
),
73 'first' => wfMsgHtml( 'histlast' ),
74 'last' => wfMsgHtml( 'histfirst' )
77 $pagingLinks = $this->getPagingLinks( $linkTexts );
78 $limitLinks = $this->getLimitLinks();
79 $limits = $wgLang->pipeList( $limitLinks );
81 $this->mNavigationBar
= "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
82 wfMsgExt( 'viewprevnext', array( 'parsemag' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
83 return $this->mNavigationBar
;
86 function getNamespaceCond() {
87 if ( $this->namespace !== '' ) {
88 return array( 'ar_namespace' => (int)$this->namespace );
95 * Generates each row in the contributions list.
97 * Contributions which are marked "top" are currently on top of the history.
98 * For these contributions, a [rollback] link is shown for users with sysop
99 * privileges. The rollback link restores the most recent version that was not
100 * written by the target user.
102 * @todo This would probably look a lot nicer in a table.
104 function formatRow( $row ) {
105 wfProfileIn( __METHOD__
);
107 global $wgLang, $wgUser;
109 $sk = $this->getSkin();
111 $rev = new Revision( array(
112 'id' => $row->ar_rev_id
,
113 'comment' => $row->ar_comment
,
114 'user' => $row->ar_user
,
115 'user_text' => $row->ar_user_text
,
116 'timestamp' => $row->ar_timestamp
,
117 'minor_edit' => $row->ar_minor_edit
,
118 'rev_deleted' => $row->ar_deleted
,
121 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
123 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
125 $logs = SpecialPage
::getTitleFor( 'Log' );
126 $dellog = $sk->makeKnownLinkObj( $logs,
127 $this->messages
['deletionlog'],
128 'type=delete&page=' . $page->getPrefixedUrl() );
130 $reviewlink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
131 $this->messages
['undeletebtn'] );
133 $link = $sk->makeKnownLinkObj( $undelete,
134 htmlspecialchars( $page->getPrefixedText() ),
135 'target=' . $page->getPrefixedUrl() .
136 '×tamp=' . $rev->getTimestamp() );
138 $last = $sk->makeKnownLinkObj( $undelete,
139 $this->messages
['diff'],
140 "target=" . $page->getPrefixedUrl() .
141 "×tamp=" . $rev->getTimestamp() .
144 $comment = $sk->revComment( $rev );
145 $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
147 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
148 $d = '<span class="history-deleted">' . $d . '</span>';
150 $link = $sk->makeKnownLinkObj( $undelete, $d,
151 'target=' . $page->getPrefixedUrl() .
152 '×tamp=' . $rev->getTimestamp() );
155 $pagelink = $sk->makeLinkObj( $page );
157 if( $rev->isMinor() ) {
158 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
164 $ret = "{$link} ($last) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
165 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
166 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
169 $ret = "<li>$ret</li>\n";
171 wfProfileOut( __METHOD__
);
176 * Get the Database object in use
180 public function getDatabase() {
185 class DeletedContributionsPage
extends SpecialPage
{
186 function __construct() {
187 parent
::__construct( 'DeletedContributions', 'deletedhistory',
188 /*listed*/ true, /*function*/ false, /*file*/ false );
192 * Special page "deleted user contributions".
193 * Shows a list of the deleted contributions of a user.
196 * @param $par String: (optional) user name of the user for which to show the contributions
198 function execute( $par ) {
202 if ( !$this->userCanExecute( $wgUser ) ) {
203 $this->displayRestrictionError();
207 global $wgUser, $wgOut, $wgLang, $wgRequest;
209 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
213 if ( isset( $par ) ) {
216 $target = $wgRequest->getVal( 'target' );
219 if ( !strlen( $target ) ) {
220 $wgOut->addHTML( $this->getForm( '' ) );
224 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
225 $options['target'] = $target;
227 $nt = Title
::makeTitleSafe( NS_USER
, $target );
229 $wgOut->addHTML( $this->getForm( '' ) );
232 $id = User
::idFromName( $nt->getText() );
234 $target = $nt->getText();
235 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
237 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
238 $options['namespace'] = intval( $ns );
240 $options['namespace'] = '';
243 $wgOut->addHTML( $this->getForm( $options ) );
245 $pager = new DeletedContribsPager( $target, $options['namespace'] );
246 if ( !$pager->getNumRows() ) {
247 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
251 # Show a message about slave lag, if applicable
252 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
253 $wgOut->showLagWarning( $lag );
256 '<p>' . $pager->getNavigationBar() . '</p>' .
258 '<p>' . $pager->getNavigationBar() . '</p>' );
260 # If there were contributions, and it was a valid user or IP, show
261 # the appropriate "footer" message - WHOIS tools, etc.
262 if( $target != 'newbies' ) {
263 $message = IP
::isIPAddress( $target )
264 ?
'sp-contributions-footer-anon'
265 : 'sp-contributions-footer';
268 $text = wfMsgNoTrans( $message, $target );
269 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
270 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
271 $wgOut->addWikiText( $text );
272 $wgOut->addHTML( '</div>' );
278 * Generates the subheading with links
279 * @param $nt @see Title object for the target
281 function getSubTitle( $nt, $id ) {
282 global $wgSysopUserBans, $wgLang, $wgUser;
284 $sk = $wgUser->getSkin();
287 $user = $nt->getText();
289 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
291 $talk = $nt->getTalkPage();
294 $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
295 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
297 if( $wgUser->isAllowed( 'block' ) )
298 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
299 wfMsgHtml( 'blocklink' ) );
301 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
302 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
305 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
306 wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
307 # Link to undeleted contributions
308 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
309 wfMsgHtml( 'contributions' ) );
311 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
313 $links = $wgLang->pipeList( $tools );
316 // Old message 'contribsub' had one parameter, but that doesn't work for
317 // languages that want to put the "for" bit right after $user but before
318 // $links. If 'contribsub' is around, use it for reverse compatibility,
319 // otherwise use 'contribsub2'.
320 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
321 return wfMsgHtml( 'contribsub2', $user, $links );
323 return wfMsgHtml( 'contribsub', "$user ($links)" );
328 * Generates the namespace selector form with hidden attributes.
329 * @param $options Array: the options to be included.
331 function getForm( $options ) {
332 global $wgScript, $wgTitle, $wgRequest;
334 $options['title'] = $wgTitle->getPrefixedText();
335 if ( !isset( $options['target'] ) ) {
336 $options['target'] = '';
338 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
341 if ( !isset( $options['namespace'] ) ) {
342 $options['namespace'] = '';
345 if ( !isset( $options['contribs'] ) ) {
346 $options['contribs'] = 'user';
349 if ( $options['contribs'] == 'newbie' ) {
350 $options['target'] = '';
353 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
355 foreach ( $options as $name => $value ) {
356 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
359 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
362 $f .= Xml
::openElement( 'fieldset' ) .
363 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
364 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
365 Xml
::input( 'target', 20, $options['target']) . ' '.
366 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
367 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
368 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
369 Xml
::closeElement( 'fieldset' ) .
370 Xml
::closeElement( 'form' );