Use link() instead of deprecated makeLinkObj() where possible.
[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 global $wgUser;
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';
35 }
36 return array(
37 'tables' => array( 'archive' ),
38 'fields' => array(
39 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
40 'ar_user', 'ar_user_text', 'ar_deleted'
41 ),
42 'conds' => $conds,
43 'options' => array( 'USE INDEX' => $index )
44 );
45 }
46
47 function getUserCond() {
48 $condition = array();
49
50 $condition['ar_user_text'] = $this->target;
51 $index = 'usertext_timestamp';
52
53 return array( $index, $condition );
54 }
55
56 function getIndexField() {
57 return 'ar_timestamp';
58 }
59
60 function getStartBody() {
61 return "<ul>\n";
62 }
63
64 function getEndBody() {
65 return "</ul>\n";
66 }
67
68 function getNavigationBar() {
69 global $wgLang;
70
71 if ( isset( $this->mNavigationBar ) ) {
72 return $this->mNavigationBar;
73 }
74 $linkTexts = array(
75 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ),
76 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ),
77 'first' => wfMsgHtml( 'histlast' ),
78 'last' => wfMsgHtml( 'histfirst' )
79 );
80
81 $pagingLinks = $this->getPagingLinks( $linkTexts );
82 $limitLinks = $this->getLimitLinks();
83 $limits = $wgLang->pipeList( $limitLinks );
84
85 $this->mNavigationBar = "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
86 wfMsgExt( 'viewprevnext', array( 'parsemag' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
87 return $this->mNavigationBar;
88 }
89
90 function getNamespaceCond() {
91 if ( $this->namespace !== '' ) {
92 return array( 'ar_namespace' => (int)$this->namespace );
93 } else {
94 return array();
95 }
96 }
97
98 /**
99 * Generates each row in the contributions list.
100 *
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.
105 *
106 * @todo This would probably look a lot nicer in a table.
107 */
108 function formatRow( $row ) {
109 global $wgUser, $wgLang;
110 wfProfileIn( __METHOD__ );
111
112 $sk = $this->getSkin();
113
114 $rev = new Revision( array(
115 'id' => $row->ar_rev_id,
116 'comment' => $row->ar_comment,
117 'user' => $row->ar_user,
118 'user_text' => $row->ar_user_text,
119 'timestamp' => $row->ar_timestamp,
120 'minor_edit' => $row->ar_minor_edit,
121 'deleted' => $row->ar_deleted,
122 ) );
123
124 $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
125
126 $undelete = SpecialPage::getTitleFor( 'Undelete' );
127
128 $logs = SpecialPage::getTitleFor( 'Log' );
129 $dellog = $sk->makeKnownLinkObj( $logs,
130 $this->messages['deletionlog'],
131 'type=delete&page=' . $page->getPrefixedUrl() );
132
133 $reviewlink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
134 $this->messages['undeletebtn'] );
135
136 $link = $sk->makeKnownLinkObj( $undelete,
137 htmlspecialchars( $page->getPrefixedText() ),
138 'target=' . $page->getPrefixedUrl() .
139 '&timestamp=' . $rev->getTimestamp() );
140
141 $last = $sk->makeKnownLinkObj( $undelete,
142 $this->messages['diff'],
143 "target=" . $page->getPrefixedUrl() .
144 "&timestamp=" . $rev->getTimestamp() .
145 "&diff=prev" );
146
147 $comment = $sk->revComment( $rev );
148 $d = $wgLang->timeanddate( $rev->getTimestamp(), true );
149
150 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
151 $d = '<span class="history-deleted">' . $d . '</span>';
152 } else {
153 $link = $sk->makeKnownLinkObj( $undelete, $d,
154 'target=' . $page->getPrefixedUrl() .
155 '&timestamp=' . $rev->getTimestamp() );
156 }
157
158 $pagelink = $sk->link( $page );
159
160 if( $rev->isMinor() ) {
161 $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
162 } else {
163 $mflag = '';
164 }
165
166 if( $wgUser->isAllowed( 'deleterevision' ) ) {
167 // If revision was hidden from sysops
168 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
169 $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
170 '(' . $this->message['rev-delundel'] . ')' ) . ' ';
171 // Otherwise, show the link...
172 } else {
173 $query = array( 'target' => $page->getPrefixedDbkey(),
174 'artimestamp' => $rev->getTimestamp() );
175 $del = $this->mSkin->revDeleteLink( $query,
176 $rev->isDeleted( Revision::DELETED_RESTRICTED ) ) . ' ';
177 }
178 } else {
179 $del = '';
180 }
181
182 $ret = "{$del}{$link} ({$last}) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
183 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
184 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
185 }
186
187 $ret = "<li>$ret</li>\n";
188
189 wfProfileOut( __METHOD__ );
190 return $ret;
191 }
192
193 /**
194 * Get the Database object in use
195 *
196 * @return Database
197 */
198 public function getDatabase() {
199 return $this->mDb;
200 }
201 }
202
203 class DeletedContributionsPage extends SpecialPage {
204 function __construct() {
205 parent::__construct( 'DeletedContributions', 'deletedhistory',
206 /*listed*/ true, /*function*/ false, /*file*/ false );
207 }
208
209 /**
210 * Special page "deleted user contributions".
211 * Shows a list of the deleted contributions of a user.
212 *
213 * @return none
214 * @param $par String: (optional) user name of the user for which to show the contributions
215 */
216 function execute( $par ) {
217 global $wgUser;
218 $this->setHeaders();
219
220 if ( !$this->userCanExecute( $wgUser ) ) {
221 $this->displayRestrictionError();
222 return;
223 }
224
225 global $wgUser, $wgOut, $wgLang, $wgRequest;
226
227 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
228
229 $options = array();
230
231 if ( isset( $par ) ) {
232 $target = $par;
233 } else {
234 $target = $wgRequest->getVal( 'target' );
235 }
236
237 if ( !strlen( $target ) ) {
238 $wgOut->addHTML( $this->getForm( '' ) );
239 return;
240 }
241
242 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
243 $options['target'] = $target;
244
245 $nt = Title::makeTitleSafe( NS_USER, $target );
246 if ( !$nt ) {
247 $wgOut->addHTML( $this->getForm( '' ) );
248 return;
249 }
250 $id = User::idFromName( $nt->getText() );
251
252 $target = $nt->getText();
253 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
254
255 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
256 $options['namespace'] = intval( $ns );
257 } else {
258 $options['namespace'] = '';
259 }
260
261 $wgOut->addHTML( $this->getForm( $options ) );
262
263 $pager = new DeletedContribsPager( $target, $options['namespace'] );
264 if ( !$pager->getNumRows() ) {
265 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
266 return;
267 }
268
269 # Show a message about slave lag, if applicable
270 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
271 $wgOut->showLagWarning( $lag );
272
273 $wgOut->addHTML(
274 '<p>' . $pager->getNavigationBar() . '</p>' .
275 $pager->getBody() .
276 '<p>' . $pager->getNavigationBar() . '</p>' );
277
278 # If there were contributions, and it was a valid user or IP, show
279 # the appropriate "footer" message - WHOIS tools, etc.
280 if( $target != 'newbies' ) {
281 $message = IP::isIPAddress( $target )
282 ? 'sp-contributions-footer-anon'
283 : 'sp-contributions-footer';
284
285
286 $text = wfMsgNoTrans( $message, $target );
287 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
288 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
289 $wgOut->addWikiText( $text );
290 $wgOut->addHTML( '</div>' );
291 }
292 }
293 }
294
295 /**
296 * Generates the subheading with links
297 * @param $nt @see Title object for the target
298 */
299 function getSubTitle( $nt, $id ) {
300 global $wgSysopUserBans, $wgLang, $wgUser;
301
302 $sk = $wgUser->getSkin();
303
304 if ( 0 == $id ) {
305 $user = $nt->getText();
306 } else {
307 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
308 }
309 $talk = $nt->getTalkPage();
310 if( $talk ) {
311 # Talk page link
312 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
313 if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
314 # Block link
315 if( $wgUser->isAllowed( 'block' ) )
316 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
317 wfMsgHtml( 'blocklink' ) );
318 # Block log link
319 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
320 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
321 }
322 # Other logs link
323 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
324 wfMsgHtml( 'sp-contributions-logs' ), 'user=' . $nt->getPartialUrl() );
325 # Link to undeleted contributions
326 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
327 wfMsgHtml( 'contributions' ) );
328
329 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
330
331 $links = $wgLang->pipeList( $tools );
332 }
333
334 // Old message 'contribsub' had one parameter, but that doesn't work for
335 // languages that want to put the "for" bit right after $user but before
336 // $links. If 'contribsub' is around, use it for reverse compatibility,
337 // otherwise use 'contribsub2'.
338 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
339 return wfMsgHtml( 'contribsub2', $user, $links );
340 } else {
341 return wfMsgHtml( 'contribsub', "$user ($links)" );
342 }
343 }
344
345 /**
346 * Generates the namespace selector form with hidden attributes.
347 * @param $options Array: the options to be included.
348 */
349 function getForm( $options ) {
350 global $wgScript, $wgRequest;
351
352 $options['title'] = SpecialPage::getTitleFor( 'DeletedContributions' )->getPrefixedText();
353 if ( !isset( $options['target'] ) ) {
354 $options['target'] = '';
355 } else {
356 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
357 }
358
359 if ( !isset( $options['namespace'] ) ) {
360 $options['namespace'] = '';
361 }
362
363 if ( !isset( $options['contribs'] ) ) {
364 $options['contribs'] = 'user';
365 }
366
367 if ( $options['contribs'] == 'newbie' ) {
368 $options['target'] = '';
369 }
370
371 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
372
373 foreach ( $options as $name => $value ) {
374 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
375 continue;
376 }
377 $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
378 }
379
380 $f .= Xml::openElement( 'fieldset' ) .
381 Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
382 Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
383 Xml::input( 'target', 20, $options['target']) . ' '.
384 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
385 Xml::namespaceSelector( $options['namespace'], '' ) . ' ' .
386 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
387 Xml::closeElement( 'fieldset' ) .
388 Xml::closeElement( 'form' );
389 return $f;
390 }
391 }