785f75e13b675f4415e84fff75e6c1578309ac7e
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 if( $wgUser->isAllowed('delete') ) {
149 $last = $sk->linkKnown(
151 $this->messages
['diff'],
154 'target' => $page->getPrefixedText(),
155 'timestamp' => $rev->getTimestamp(),
160 $last = $this->messages
['diff'];
163 $comment = $sk->revComment( $rev );
164 $date = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
166 if( !$wgUser->isAllowed('delete') ||
!$rev->userCan(Revision
::DELETED_TEXT
) ) {
167 $link = $date; // unusable link
169 $link = $sk->linkKnown(
174 'target' => $page->getPrefixedText(),
175 'timestamp' => $rev->getTimestamp()
179 // Style deleted items
180 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
181 $link = '<span class="history-deleted">' . $link . '</span>';
184 $pagelink = $sk->link( $page );
186 if( $rev->isMinor() ) {
187 $mflag = '<abbr class="minor">' . $this->messages
['minoreditletter'] . '</abbr> ';
192 if( $wgUser->isAllowed( 'deleterevision' ) ) {
193 // If revision was hidden from sysops
194 if( !$rev->userCan( Revision
::DELETED_RESTRICTED
) ) {
195 $del = Xml
::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
196 '(' . $this->message
['rev-delundel'] . ')' ) . ' ';
197 // Otherwise, show the link...
201 'target' => $page->getPrefixedDbkey(),
202 'ids' => $rev->getTimestamp() );
203 $del = $this->mSkin
->revDeleteLink( $query,
204 $rev->isDeleted( Revision
::DELETED_RESTRICTED
) ) . ' ';
210 $ret = "{$del}{$link} ({$last}) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
212 $ret = "<li>$ret</li>\n";
214 wfProfileOut( __METHOD__
);
219 * Get the Database object in use
223 public function getDatabase() {
228 class DeletedContributionsPage
extends SpecialPage
{
229 function __construct() {
230 parent
::__construct( 'DeletedContributions', 'deletedhistory',
231 /*listed*/ true, /*function*/ false, /*file*/ false );
235 * Special page "deleted user contributions".
236 * Shows a list of the deleted contributions of a user.
239 * @param $par String: (optional) user name of the user for which to show the contributions
241 function execute( $par ) {
245 if ( !$this->userCanExecute( $wgUser ) ) {
246 $this->displayRestrictionError();
250 global $wgUser, $wgOut, $wgLang, $wgRequest;
252 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
256 if ( isset( $par ) ) {
259 $target = $wgRequest->getVal( 'target' );
262 if ( !strlen( $target ) ) {
263 $wgOut->addHTML( $this->getForm( '' ) );
267 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
268 $options['target'] = $target;
270 $nt = Title
::makeTitleSafe( NS_USER
, $target );
272 $wgOut->addHTML( $this->getForm( '' ) );
275 $id = User
::idFromName( $nt->getText() );
277 $target = $nt->getText();
278 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
280 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
281 $options['namespace'] = intval( $ns );
283 $options['namespace'] = '';
286 $wgOut->addHTML( $this->getForm( $options ) );
288 $pager = new DeletedContribsPager( $target, $options['namespace'] );
289 if ( !$pager->getNumRows() ) {
290 $wgOut->addWikiMsg( 'nocontribs' );
294 # Show a message about slave lag, if applicable
295 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
296 $wgOut->showLagWarning( $lag );
299 '<p>' . $pager->getNavigationBar() . '</p>' .
301 '<p>' . $pager->getNavigationBar() . '</p>' );
303 # If there were contributions, and it was a valid user or IP, show
304 # the appropriate "footer" message - WHOIS tools, etc.
305 if( $target != 'newbies' ) {
306 $message = IP
::isIPAddress( $target )
307 ?
'sp-contributions-footer-anon'
308 : 'sp-contributions-footer';
311 $text = wfMsgNoTrans( $message, $target );
312 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
313 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
319 * Generates the subheading with links
320 * @param $nt @see Title object for the target
322 function getSubTitle( $nt, $id ) {
323 global $wgSysopUserBans, $wgLang, $wgUser;
325 $sk = $wgUser->getSkin();
328 $user = htmlspecialchars( $nt->getText() );
330 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
332 $talk = $nt->getTalkPage();
335 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
336 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
338 if( $wgUser->isAllowed( 'block' ) )
339 $tools[] = $sk->linkKnown(
340 SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
341 wfMsgHtml( 'blocklink' )
344 $tools[] = $sk->linkKnown(
345 SpecialPage
::getTitleFor( 'Log' ),
346 wfMsgHtml( 'sp-contributions-blocklog' ),
350 'page' => $nt->getPrefixedText()
355 $tools[] = $sk->linkKnown(
356 SpecialPage
::getTitleFor( 'Log' ),
357 wfMsgHtml( 'sp-contributions-logs' ),
359 array( 'user' => $nt->getText() )
361 # Link to undeleted contributions
362 $tools[] = $sk->linkKnown(
363 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
364 wfMsgHtml( 'sp-deletedcontributions-contribs' )
367 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
369 $links = $wgLang->pipeList( $tools );
372 // Old message 'contribsub' had one parameter, but that doesn't work for
373 // languages that want to put the "for" bit right after $user but before
374 // $links. If 'contribsub' is around, use it for reverse compatibility,
375 // otherwise use 'contribsub2'.
376 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
377 return wfMsgHtml( 'contribsub2', $user, $links );
379 return wfMsgHtml( 'contribsub', "$user ($links)" );
384 * Generates the namespace selector form with hidden attributes.
385 * @param $options Array: the options to be included.
387 function getForm( $options ) {
388 global $wgScript, $wgRequest;
390 $options['title'] = SpecialPage
::getTitleFor( 'DeletedContributions' )->getPrefixedText();
391 if ( !isset( $options['target'] ) ) {
392 $options['target'] = '';
394 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
397 if ( !isset( $options['namespace'] ) ) {
398 $options['namespace'] = '';
401 if ( !isset( $options['contribs'] ) ) {
402 $options['contribs'] = 'user';
405 if ( $options['contribs'] == 'newbie' ) {
406 $options['target'] = '';
409 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
411 foreach ( $options as $name => $value ) {
412 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
415 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
418 $f .= Xml
::openElement( 'fieldset' ) .
419 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
420 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
421 Xml
::input( 'target', 20, $options['target']) . ' '.
422 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
423 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
424 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
425 Xml
::closeElement( 'fieldset' ) .
426 Xml
::closeElement( 'form' );