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