Fix syntax errors in r51305.
[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', 'escape', 'replaceafter' ), $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 = htmlspecialchars( $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(
174 'type' => 'archive',
175 'target' => $page->getPrefixedDbkey(),
176 'ids' => $rev->getTimestamp() );
177 $del = $this->mSkin->revDeleteLink( $query,
178 $rev->isDeleted( Revision::DELETED_RESTRICTED ) ) . ' ';
179 }
180 } else {
181 $del = '';
182 }
183
184 $ret = "{$del}{$link} ({$last}) ({$dellog}) ({$reviewlink}) . . {$mflag} {$pagelink} {$comment}";
185
186 $ret = "<li>$ret</li>\n";
187
188 wfProfileOut( __METHOD__ );
189 return $ret;
190 }
191
192 /**
193 * Get the Database object in use
194 *
195 * @return Database
196 */
197 public function getDatabase() {
198 return $this->mDb;
199 }
200 }
201
202 class DeletedContributionsPage extends SpecialPage {
203 function __construct() {
204 parent::__construct( 'DeletedContributions', 'deletedhistory',
205 /*listed*/ true, /*function*/ false, /*file*/ false );
206 }
207
208 /**
209 * Special page "deleted user contributions".
210 * Shows a list of the deleted contributions of a user.
211 *
212 * @return none
213 * @param $par String: (optional) user name of the user for which to show the contributions
214 */
215 function execute( $par ) {
216 global $wgUser;
217 $this->setHeaders();
218
219 if ( !$this->userCanExecute( $wgUser ) ) {
220 $this->displayRestrictionError();
221 return;
222 }
223
224 global $wgUser, $wgOut, $wgLang, $wgRequest;
225
226 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
227
228 $options = array();
229
230 if ( isset( $par ) ) {
231 $target = $par;
232 } else {
233 $target = $wgRequest->getVal( 'target' );
234 }
235
236 if ( !strlen( $target ) ) {
237 $wgOut->addHTML( $this->getForm( '' ) );
238 return;
239 }
240
241 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
242 $options['target'] = $target;
243
244 $nt = Title::makeTitleSafe( NS_USER, $target );
245 if ( !$nt ) {
246 $wgOut->addHTML( $this->getForm( '' ) );
247 return;
248 }
249 $id = User::idFromName( $nt->getText() );
250
251 $target = $nt->getText();
252 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
253
254 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
255 $options['namespace'] = intval( $ns );
256 } else {
257 $options['namespace'] = '';
258 }
259
260 $wgOut->addHTML( $this->getForm( $options ) );
261
262 $pager = new DeletedContribsPager( $target, $options['namespace'] );
263 if ( !$pager->getNumRows() ) {
264 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
265 return;
266 }
267
268 # Show a message about slave lag, if applicable
269 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
270 $wgOut->showLagWarning( $lag );
271
272 $wgOut->addHTML(
273 '<p>' . $pager->getNavigationBar() . '</p>' .
274 $pager->getBody() .
275 '<p>' . $pager->getNavigationBar() . '</p>' );
276
277 # If there were contributions, and it was a valid user or IP, show
278 # the appropriate "footer" message - WHOIS tools, etc.
279 if( $target != 'newbies' ) {
280 $message = IP::isIPAddress( $target )
281 ? 'sp-contributions-footer-anon'
282 : 'sp-contributions-footer';
283
284
285 $text = wfMsgNoTrans( $message, $target );
286 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
287 $wgOut->addHTML( '<div class="mw-contributions-footer">' );
288 $wgOut->addWikiText( $text );
289 $wgOut->addHTML( '</div>' );
290 }
291 }
292 }
293
294 /**
295 * Generates the subheading with links
296 * @param $nt @see Title object for the target
297 */
298 function getSubTitle( $nt, $id ) {
299 global $wgSysopUserBans, $wgLang, $wgUser;
300
301 $sk = $wgUser->getSkin();
302
303 if ( 0 == $id ) {
304 $user = $nt->getText();
305 } else {
306 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
307 }
308 $talk = $nt->getTalkPage();
309 if( $talk ) {
310 # Talk page link
311 $tools[] = $sk->link( $talk, wfMsgHtml( 'talkpagelinktext' ) );
312 if( ( $id != 0 && $wgSysopUserBans ) || ( $id == 0 && User::isIP( $nt->getText() ) ) ) {
313 # Block link
314 if( $wgUser->isAllowed( 'block' ) )
315 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
316 wfMsgHtml( 'blocklink' ) );
317 # Block log link
318 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
319 wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
320 }
321 # Other logs link
322 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ),
323 wfMsgHtml( 'sp-contributions-logs' ), 'user=' . $nt->getPartialUrl() );
324 # Link to undeleted contributions
325 $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
326 wfMsgHtml( 'contributions' ) );
327
328 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
329
330 $links = $wgLang->pipeList( $tools );
331 }
332
333 // Old message 'contribsub' had one parameter, but that doesn't work for
334 // languages that want to put the "for" bit right after $user but before
335 // $links. If 'contribsub' is around, use it for reverse compatibility,
336 // otherwise use 'contribsub2'.
337 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
338 return wfMsgHtml( 'contribsub2', $user, $links );
339 } else {
340 return wfMsgHtml( 'contribsub', "$user ($links)" );
341 }
342 }
343
344 /**
345 * Generates the namespace selector form with hidden attributes.
346 * @param $options Array: the options to be included.
347 */
348 function getForm( $options ) {
349 global $wgScript, $wgRequest;
350
351 $options['title'] = SpecialPage::getTitleFor( 'DeletedContributions' )->getPrefixedText();
352 if ( !isset( $options['target'] ) ) {
353 $options['target'] = '';
354 } else {
355 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
356 }
357
358 if ( !isset( $options['namespace'] ) ) {
359 $options['namespace'] = '';
360 }
361
362 if ( !isset( $options['contribs'] ) ) {
363 $options['contribs'] = 'user';
364 }
365
366 if ( $options['contribs'] == 'newbie' ) {
367 $options['target'] = '';
368 }
369
370 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
371
372 foreach ( $options as $name => $value ) {
373 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
374 continue;
375 }
376 $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
377 }
378
379 $f .= Xml::openElement( 'fieldset' ) .
380 Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
381 Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
382 Xml::input( 'target', 20, $options['target']) . ' '.
383 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
384 Xml::namespaceSelector( $options['namespace'], '' ) . ' ' .
385 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
386 Xml::closeElement( 'fieldset' ) .
387 Xml::closeElement( 'form' );
388 return $f;
389 }
390 }