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