Fix careless error in suppression on SpecialDeletedContributions.
[lhc/web/wiklou.git] / includes / specials / SpecialDeletedContributions.php
1 <?php
2 /**
3 * Implements Special:DeletedContributions to display archived revisions
4 * @ingroup SpecialPage
5 */
6
7 class DeletedContribsPager extends IndexPager {
8 public $mDefaultDirection = true;
9 var $messages, $target;
10 var $namespace = '', $mDb;
11
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') );
16 }
17 $this->target = $target;
18 $this->namespace = $namespace;
19 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
20 }
21
22 function getDefaultQuery() {
23 $query = parent::getDefaultQuery();
24 $query['target'] = $this->target;
25 return $query;
26 }
27
28 function getQueryInfo() {
29 list( $index, $userCond ) = $this->getUserCond();
30 $conds = array_merge( $userCond, $this->getNamespaceCond() );
31
32 return array(
33 'tables' => array( 'archive' ),
34 'fields' => array(
35 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
36 'ar_user', 'ar_user_text', 'ar_deleted'
37 ),
38 'conds' => $conds,
39 'options' => array( 'USE INDEX' => $index )
40 );
41 }
42
43 function getUserCond() {
44 $condition = array();
45
46 $condition['ar_user_text'] = $this->target;
47 $index = 'usertext_timestamp';
48
49 return array( $index, $condition );
50 }
51
52 function getIndexField() {
53 return 'ar_timestamp';
54 }
55
56 function getStartBody() {
57 return "<ul>\n";
58 }
59
60 function getEndBody() {
61 return "</ul>\n";
62 }
63
64 function getNavigationBar() {
65 global $wgLang;
66
67 if ( isset( $this->mNavigationBar ) ) {
68 return $this->mNavigationBar;
69 }
70 $linkTexts = array(
71 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ),
72 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ),
73 'first' => wfMsgHtml( 'histlast' ),
74 'last' => wfMsgHtml( 'histfirst' )
75 );
76
77 $pagingLinks = $this->getPagingLinks( $linkTexts );
78 $limitLinks = $this->getLimitLinks();
79 $limits = $wgLang->pipeList( $limitLinks );
80
81 $this->mNavigationBar = "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
82 wfMsgExt( 'viewprevnext', array( 'parsemag' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
83 return $this->mNavigationBar;
84 }
85
86 function getNamespaceCond() {
87 if ( $this->namespace !== '' ) {
88 return array( 'ar_namespace' => (int)$this->namespace );
89 } else {
90 return array();
91 }
92 }
93
94 /**
95 * Generates each row in the contributions list.
96 *
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.
101 *
102 * @todo This would probably look a lot nicer in a table.
103 */
104 function formatRow( $row ) {
105 wfProfileIn( __METHOD__ );
106
107 global $wgLang, $wgUser;
108
109 $sk = $this->getSkin();
110
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 'deleted' => $row->ar_deleted,
119 ) );
120
121 $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
122
123 $undelete = SpecialPage::getTitleFor( 'Undelete' );
124
125 $logs = SpecialPage::getTitleFor( 'Log' );
126 $dellog = $sk->makeKnownLinkObj( $logs,
127 $this->messages['deletionlog'],
128 'type=delete&page=' . $page->getPrefixedUrl() );
129
130 $reviewlink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
131 $this->messages['undeletebtn'] );
132
133 $link = $sk->makeKnownLinkObj( $undelete,
134 htmlspecialchars( $page->getPrefixedText() ),
135 'target=' . $page->getPrefixedUrl() .
136 '&timestamp=' . $rev->getTimestamp() );
137
138 $last = $sk->makeKnownLinkObj( $undelete,
139 $this->messages['diff'],
140 "target=" . $page->getPrefixedUrl() .
141 "&timestamp=" . $rev->getTimestamp() .
142 "&diff=prev" );
143
144 $comment = $sk->revComment( $rev );
145 $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
146
147 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
148 $d = '<span class="history-deleted">' . $d . '</span>';
149 } else {
150 $link = $sk->makeKnownLinkObj( $undelete, $d,
151 'target=' . $page->getPrefixedUrl() .
152 '&timestamp=' . $rev->getTimestamp() );
153 }
154
155 $pagelink = $sk->makeLinkObj( $page );
156
157 if( $rev->isMinor() ) {
158 $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
159 } else {
160 $mflag = '';
161 }
162
163
164 $ret = "{$link} ($last) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
165 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
166 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
167 }
168
169 $ret = "<li>$ret</li>\n";
170
171 wfProfileOut( __METHOD__ );
172 return $ret;
173 }
174
175 /**
176 * Get the Database object in use
177 *
178 * @return Database
179 */
180 public function getDatabase() {
181 return $this->mDb;
182 }
183 }
184
185 class DeletedContributionsPage extends SpecialPage {
186 function __construct() {
187 parent::__construct( 'DeletedContributions', 'deletedhistory',
188 /*listed*/ true, /*function*/ false, /*file*/ false );
189 }
190
191 /**
192 * Special page "deleted user contributions".
193 * Shows a list of the deleted contributions of a user.
194 *
195 * @return none
196 * @param $par String: (optional) user name of the user for which to show the contributions
197 */
198 function execute( $par ) {
199 global $wgUser;
200 $this->setHeaders();
201
202 if ( !$this->userCanExecute( $wgUser ) ) {
203 $this->displayRestrictionError();
204 return;
205 }
206
207 global $wgUser, $wgOut, $wgLang, $wgRequest;
208
209 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
210
211 $options = array();
212
213 if ( isset( $par ) ) {
214 $target = $par;
215 } else {
216 $target = $wgRequest->getVal( 'target' );
217 }
218
219 if ( !strlen( $target ) ) {
220 $wgOut->addHTML( $this->getForm( '' ) );
221 return;
222 }
223
224 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
225 $options['target'] = $target;
226
227 $nt = Title::makeTitleSafe( NS_USER, $target );
228 if ( !$nt ) {
229 $wgOut->addHTML( $this->getForm( '' ) );
230 return;
231 }
232 $id = User::idFromName( $nt->getText() );
233
234 $target = $nt->getText();
235 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
236
237 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
238 $options['namespace'] = intval( $ns );
239 } else {
240 $options['namespace'] = '';
241 }
242
243 $wgOut->addHTML( $this->getForm( $options ) );
244
245 $pager = new DeletedContribsPager( $target, $options['namespace'] );
246 if ( !$pager->getNumRows() ) {
247 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
248 return;
249 }
250
251 # Show a message about slave lag, if applicable
252 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
253 $wgOut->showLagWarning( $lag );
254
255 $wgOut->addHTML(
256 '<p>' . $pager->getNavigationBar() . '</p>' .
257 $pager->getBody() .
258 '<p>' . $pager->getNavigationBar() . '</p>' );
259
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';
266
267
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>' );
273 }
274 }
275 }
276
277 /**
278 * Generates the subheading with links
279 * @param $nt @see Title object for the target
280 */
281 function getSubTitle( $nt, $id ) {
282 global $wgSysopUserBans, $wgLang, $wgUser;
283
284 $sk = $wgUser->getSkin();
285
286 if ( 0 == $id ) {
287 $user = $nt->getText();
288 } else {
289 $user = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
290 }
291 $talk = $nt->getTalkPage();
292 if( $talk ) {
293 # Talk page link
294 $tools[] = $sk->makeLinkObj( $talk, wfMsgHtml( 'talkpagelinktext' ) );
295 if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
296 # Block link
297 if( $wgUser->isAllowed( 'block' ) )
298 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
299 wfMsgHtml( 'blocklink' ) );
300 # Block log link
301 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
302 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
303 }
304 # Other logs link
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' ) );
310
311 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
312
313 $links = $wgLang->pipeList( $tools );
314 }
315
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 );
322 } else {
323 return wfMsgHtml( 'contribsub', "$user ($links)" );
324 }
325 }
326
327 /**
328 * Generates the namespace selector form with hidden attributes.
329 * @param $options Array: the options to be included.
330 */
331 function getForm( $options ) {
332 global $wgScript, $wgTitle, $wgRequest;
333
334 $options['title'] = $wgTitle->getPrefixedText();
335 if ( !isset( $options['target'] ) ) {
336 $options['target'] = '';
337 } else {
338 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
339 }
340
341 if ( !isset( $options['namespace'] ) ) {
342 $options['namespace'] = '';
343 }
344
345 if ( !isset( $options['contribs'] ) ) {
346 $options['contribs'] = 'user';
347 }
348
349 if ( $options['contribs'] == 'newbie' ) {
350 $options['target'] = '';
351 }
352
353 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
354
355 foreach ( $options as $name => $value ) {
356 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
357 continue;
358 }
359 $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
360 }
361
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' );
371 return $f;
372 }
373 }