67b05ca186770001ff363e8a755966181e400fea
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' ), $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 wfProfileIn( __METHOD__
);
111 global $wgLang, $wgUser;
113 $sk = $this->getSkin();
115 $rev = new Revision( array(
116 'id' => $row->ar_rev_id
,
117 'comment' => $row->ar_comment
,
118 'user' => $row->ar_user
,
119 'user_text' => $row->ar_user_text
,
120 'timestamp' => $row->ar_timestamp
,
121 'minor_edit' => $row->ar_minor_edit
,
122 'deleted' => $row->ar_deleted
,
125 $page = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
127 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
129 $logs = SpecialPage
::getTitleFor( 'Log' );
130 $dellog = $sk->makeKnownLinkObj( $logs,
131 $this->messages
['deletionlog'],
132 'type=delete&page=' . $page->getPrefixedUrl() );
134 $reviewlink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
135 $this->messages
['undeletebtn'] );
137 $link = $sk->makeKnownLinkObj( $undelete,
138 htmlspecialchars( $page->getPrefixedText() ),
139 'target=' . $page->getPrefixedUrl() .
140 '×tamp=' . $rev->getTimestamp() );
142 $last = $sk->makeKnownLinkObj( $undelete,
143 $this->messages
['diff'],
144 "target=" . $page->getPrefixedUrl() .
145 "×tamp=" . $rev->getTimestamp() .
148 $comment = $sk->revComment( $rev );
149 $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
151 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
152 $d = '<span class="history-deleted">' . $d . '</span>';
154 $link = $sk->makeKnownLinkObj( $undelete, $d,
155 'target=' . $page->getPrefixedUrl() .
156 '×tamp=' . $rev->getTimestamp() );
159 $pagelink = $sk->makeLinkObj( $page );
161 if( $rev->isMinor() ) {
162 $mflag = '<span class="minor">' . $this->messages
['minoreditletter'] . '</span> ';
168 $ret = "{$link} ($last) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
169 if( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
170 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
173 $ret = "<li>$ret</li>\n";
175 wfProfileOut( __METHOD__
);
180 * Get the Database object in use
184 public function getDatabase() {
189 class DeletedContributionsPage
extends SpecialPage
{
190 function __construct() {
191 parent
::__construct( 'DeletedContributions', 'deletedhistory',
192 /*listed*/ true, /*function*/ false, /*file*/ false );
196 * Special page "deleted user contributions".
197 * Shows a list of the deleted contributions of a user.
200 * @param $par String: (optional) user name of the user for which to show the contributions
202 function execute( $par ) {
206 if ( !$this->userCanExecute( $wgUser ) ) {
207 $this->displayRestrictionError();
211 global $wgUser, $wgOut, $wgLang, $wgRequest;
213 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
217 if ( isset( $par ) ) {
220 $target = $wgRequest->getVal( 'target' );
223 if ( !strlen( $target ) ) {
224 $wgOut->addHTML( $this->getForm( '' ) );
228 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
229 $options['target'] = $target;
231 $nt = Title
::makeTitleSafe( NS_USER
, $target );
233 $wgOut->addHTML( $this->getForm( '' ) );
236 $id = User
::idFromName( $nt->getText() );
238 $target = $nt->getText();
239 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
241 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
242 $options['namespace'] = intval( $ns );
244 $options['namespace'] = '';
247 $wgOut->addHTML( $this->getForm( $options ) );
249 $pager = new DeletedContribsPager( $target, $options['namespace'] );
250 if ( !$pager->getNumRows() ) {
251 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
255 # Show a message about slave lag, if applicable
256 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
257 $wgOut->showLagWarning( $lag );
260 '<p>' . $pager->getNavigationBar() . '</p>' .
262 '<p>' . $pager->getNavigationBar() . '</p>' );
264 # If there were contributions, and it was a valid user or IP, show
265 # the appropriate "footer" message - WHOIS tools, etc.
266 if( $target != 'newbies' ) {
267 $message = IP
::isIPAddress( $target )
268 ?
'sp-contributions-footer-anon'
269 : 'sp-contributions-footer';
272 $text = wfMsgNoTrans( $message, $target );
273 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
274 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
275 $wgOut->addWikiText( $text );
276 $wgOut->addHTML( '</div>' );
282 * Generates the subheading with links
283 * @param $nt @see Title object for the target
285 function getSubTitle( $nt, $id ) {
286 global $wgSysopUserBans, $wgLang, $wgUser;
288 $sk = $wgUser->getSkin();
291 $user = $nt->getText();
293 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
295 $talk = $nt->getTalkPage();
298 $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
299 if( ( $id != 0 && $wgSysopUserBans ) ||
( $id == 0 && User
::isIP( $nt->getText() ) ) ) {
301 if( $wgUser->isAllowed( 'block' ) )
302 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Blockip', $nt->getDBkey() ),
303 wfMsgHtml( 'blocklink' ) );
305 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
306 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
309 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Log' ),
310 wfMsgHtml( 'log' ), 'user=' . $nt->getPartialUrl() );
311 # Link to undeleted contributions
312 $tools[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
313 wfMsgHtml( 'contributions' ) );
315 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
317 $links = $wgLang->pipeList( $tools );
320 // Old message 'contribsub' had one parameter, but that doesn't work for
321 // languages that want to put the "for" bit right after $user but before
322 // $links. If 'contribsub' is around, use it for reverse compatibility,
323 // otherwise use 'contribsub2'.
324 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
325 return wfMsgHtml( 'contribsub2', $user, $links );
327 return wfMsgHtml( 'contribsub', "$user ($links)" );
332 * Generates the namespace selector form with hidden attributes.
333 * @param $options Array: the options to be included.
335 function getForm( $options ) {
336 global $wgScript, $wgTitle, $wgRequest;
338 $options['title'] = $wgTitle->getPrefixedText();
339 if ( !isset( $options['target'] ) ) {
340 $options['target'] = '';
342 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
345 if ( !isset( $options['namespace'] ) ) {
346 $options['namespace'] = '';
349 if ( !isset( $options['contribs'] ) ) {
350 $options['contribs'] = 'user';
353 if ( $options['contribs'] == 'newbie' ) {
354 $options['target'] = '';
357 $f = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
359 foreach ( $options as $name => $value ) {
360 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
363 $f .= "\t" . Xml
::hidden( $name, $value ) . "\n";
366 $f .= Xml
::openElement( 'fieldset' ) .
367 Xml
::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
368 Xml
::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
369 Xml
::input( 'target', 20, $options['target']) . ' '.
370 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
371 Xml
::namespaceSelector( $options['namespace'], '' ) . ' ' .
372 Xml
::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
373 Xml
::closeElement( 'fieldset' ) .
374 Xml
::closeElement( 'form' );