Whitelist the <wbr> element.
[mediawiki.git] / includes / specials / SpecialDeletedContributions.php
blob28ca24b922e223cc2b967af0237e2358f89aa7e5
1 <?php
2 /**
3 * Implements Special:DeletedContributions
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * Implements Special:DeletedContributions to display archived revisions
26 * @ingroup SpecialPage
28 class DeletedContribsPager extends IndexPager {
29 public $mDefaultDirection = true;
30 var $messages, $target;
31 var $namespace = '', $mDb;
33 /**
34 * @var string Navigation bar with paging links.
36 protected $mNavigationBar;
38 function __construct( IContextSource $context, $target, $namespace = false ) {
39 parent::__construct( $context );
40 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
41 foreach ( $msgs as $msg ) {
42 $this->messages[$msg] = $this->msg( $msg )->escaped();
44 $this->target = $target;
45 $this->namespace = $namespace;
46 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
49 function getDefaultQuery() {
50 $query = parent::getDefaultQuery();
51 $query['target'] = $this->target;
53 return $query;
56 function getQueryInfo() {
57 list( $index, $userCond ) = $this->getUserCond();
58 $conds = array_merge( $userCond, $this->getNamespaceCond() );
59 $user = $this->getUser();
60 // Paranoia: avoid brute force searches (bug 17792)
61 if ( !$user->isAllowed( 'deletedhistory' ) ) {
62 $conds[] = $this->mDb->bitAnd( 'ar_deleted', Revision::DELETED_USER ) . ' = 0';
63 } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
64 $conds[] = $this->mDb->bitAnd( 'ar_deleted', Revision::SUPPRESSED_USER ) .
65 ' != ' . Revision::SUPPRESSED_USER;
68 return array(
69 'tables' => array( 'archive' ),
70 'fields' => array(
71 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment',
72 'ar_minor_edit', 'ar_user', 'ar_user_text', 'ar_deleted'
74 'conds' => $conds,
75 'options' => array( 'USE INDEX' => $index )
79 function getUserCond() {
80 $condition = array();
82 $condition['ar_user_text'] = $this->target;
83 $index = 'usertext_timestamp';
85 return array( $index, $condition );
88 function getIndexField() {
89 return 'ar_timestamp';
92 function getStartBody() {
93 return "<ul>\n";
96 function getEndBody() {
97 return "</ul>\n";
100 function getNavigationBar() {
101 if ( isset( $this->mNavigationBar ) ) {
102 return $this->mNavigationBar;
105 $linkTexts = array(
106 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
107 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
108 'first' => $this->msg( 'histlast' )->escaped(),
109 'last' => $this->msg( 'histfirst' )->escaped()
112 $pagingLinks = $this->getPagingLinks( $linkTexts );
113 $limitLinks = $this->getLimitLinks();
114 $lang = $this->getLanguage();
115 $limits = $lang->pipeList( $limitLinks );
117 $firstLast = $lang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) );
118 $firstLast = $this->msg( 'parentheses' )->rawParams( $firstLast )->escaped();
119 $prevNext = $this->msg( 'viewprevnext' )
120 ->rawParams(
121 $pagingLinks['prev'],
122 $pagingLinks['next'],
123 $limits
124 )->escaped();
125 $separator = $this->msg( 'word-separator' )->escaped();
126 $this->mNavigationBar = $firstLast . $separator . $prevNext;
128 return $this->mNavigationBar;
131 function getNamespaceCond() {
132 if ( $this->namespace !== '' ) {
133 return array( 'ar_namespace' => (int)$this->namespace );
134 } else {
135 return array();
140 * Generates each row in the contributions list.
142 * Contributions which are marked "top" are currently on top of the history.
143 * For these contributions, a [rollback] link is shown for users with sysop
144 * privileges. The rollback link restores the most recent version that was not
145 * written by the target user.
147 * @todo This would probably look a lot nicer in a table.
148 * @param $row
149 * @return string
151 function formatRow( $row ) {
152 wfProfileIn( __METHOD__ );
154 $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
156 $rev = new Revision( array(
157 'title' => $page,
158 'id' => $row->ar_rev_id,
159 'comment' => $row->ar_comment,
160 'user' => $row->ar_user,
161 'user_text' => $row->ar_user_text,
162 'timestamp' => $row->ar_timestamp,
163 'minor_edit' => $row->ar_minor_edit,
164 'deleted' => $row->ar_deleted,
165 ) );
167 $undelete = SpecialPage::getTitleFor( 'Undelete' );
169 $logs = SpecialPage::getTitleFor( 'Log' );
170 $dellog = Linker::linkKnown(
171 $logs,
172 $this->messages['deletionlog'],
173 array(),
174 array(
175 'type' => 'delete',
176 'page' => $page->getPrefixedText()
180 $reviewlink = Linker::linkKnown(
181 SpecialPage::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
182 $this->messages['undeleteviewlink']
185 $user = $this->getUser();
187 if ( $user->isAllowed( 'deletedtext' ) ) {
188 $last = Linker::linkKnown(
189 $undelete,
190 $this->messages['diff'],
191 array(),
192 array(
193 'target' => $page->getPrefixedText(),
194 'timestamp' => $rev->getTimestamp(),
195 'diff' => 'prev'
198 } else {
199 $last = $this->messages['diff'];
202 $comment = Linker::revComment( $rev );
203 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $user );
204 $date = htmlspecialchars( $date );
206 if ( !$user->isAllowed( 'undelete' ) || !$rev->userCan( Revision::DELETED_TEXT, $user ) ) {
207 $link = $date; // unusable link
208 } else {
209 $link = Linker::linkKnown(
210 $undelete,
211 $date,
212 array( 'class' => 'mw-changeslist-date' ),
213 array(
214 'target' => $page->getPrefixedText(),
215 'timestamp' => $rev->getTimestamp()
219 // Style deleted items
220 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
221 $link = '<span class="history-deleted">' . $link . '</span>';
224 $pagelink = Linker::link(
225 $page,
226 null,
227 array( 'class' => 'mw-changeslist-title' )
230 if ( $rev->isMinor() ) {
231 $mflag = ChangesList::flag( 'minor' );
232 } else {
233 $mflag = '';
236 // Revision delete link
237 $del = Linker::getRevDeleteLink( $user, $rev, $page );
238 if ( $del ) {
239 $del .= ' ';
242 $tools = Html::rawElement(
243 'span',
244 array( 'class' => 'mw-deletedcontribs-tools' ),
245 $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList(
246 array( $last, $dellog, $reviewlink ) ) )->escaped()
249 $separator = '<span class="mw-changeslist-separator">. .</span>';
250 $ret = "{$del}{$link} {$tools} {$separator} {$mflag} {$pagelink} {$comment}";
252 # Denote if username is redacted for this edit
253 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
254 $ret .= " <strong>" . $this->msg( 'rev-deleted-user-contribs' )->escaped() . "</strong>";
257 $ret = Html::rawElement( 'li', array(), $ret ) . "\n";
259 wfProfileOut( __METHOD__ );
261 return $ret;
265 * Get the Database object in use
267 * @return DatabaseBase
269 public function getDatabase() {
270 return $this->mDb;
274 class DeletedContributionsPage extends SpecialPage {
275 function __construct() {
276 parent::__construct( 'DeletedContributions', 'deletedhistory',
277 /*listed*/true, /*function*/false, /*file*/false );
281 * Special page "deleted user contributions".
282 * Shows a list of the deleted contributions of a user.
284 * @param string $par (optional) user name of the user for which to show the contributions
286 function execute( $par ) {
287 global $wgQueryPageDefaultLimit;
289 $this->setHeaders();
290 $this->outputHeader();
292 $user = $this->getUser();
294 if ( !$this->userCanExecute( $user ) ) {
295 $this->displayRestrictionError();
297 return;
300 $request = $this->getRequest();
301 $out = $this->getOutput();
302 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
304 $options = array();
306 if ( $par !== null ) {
307 $target = $par;
308 } else {
309 $target = $request->getVal( 'target' );
312 if ( !strlen( $target ) ) {
313 $out->addHTML( $this->getForm( '' ) );
315 return;
318 $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit );
319 $options['target'] = $target;
321 $userObj = User::newFromName( $target, false );
322 if ( !$userObj ) {
323 $out->addHTML( $this->getForm( '' ) );
325 return;
327 $this->getSkin()->setRelevantUser( $userObj );
329 $target = $userObj->getName();
330 $out->addSubtitle( $this->getSubTitle( $userObj ) );
332 if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
333 $options['namespace'] = intval( $ns );
334 } else {
335 $options['namespace'] = '';
338 $out->addHTML( $this->getForm( $options ) );
340 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
341 if ( !$pager->getNumRows() ) {
342 $out->addWikiMsg( 'nocontribs' );
344 return;
347 # Show a message about slave lag, if applicable
348 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
349 if ( $lag > 0 ) {
350 $out->showLagWarning( $lag );
353 $out->addHTML(
354 '<p>' . $pager->getNavigationBar() . '</p>' .
355 $pager->getBody() .
356 '<p>' . $pager->getNavigationBar() . '</p>' );
358 # If there were contributions, and it was a valid user or IP, show
359 # the appropriate "footer" message - WHOIS tools, etc.
360 if ( $target != 'newbies' ) {
361 $message = IP::isIPAddress( $target )
362 ? 'sp-contributions-footer-anon'
363 : 'sp-contributions-footer';
365 if ( !$this->msg( $message )->isDisabled() ) {
366 $out->wrapWikiMsg(
367 "<div class='mw-contributions-footer'>\n$1\n</div>",
368 array( $message, $target )
375 * Generates the subheading with links
376 * @param $userObj User object for the target
377 * @return String: appropriately-escaped HTML to be output literally
378 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
380 function getSubTitle( $userObj ) {
381 if ( $userObj->isAnon() ) {
382 $user = htmlspecialchars( $userObj->getName() );
383 } else {
384 $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
386 $links = '';
387 $nt = $userObj->getUserPage();
388 $id = $userObj->getID();
389 $talk = $nt->getTalkPage();
390 if ( $talk ) {
391 # Talk page link
392 $tools[] = Linker::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
393 if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $nt->getText() ) ) ) {
394 # Block / Change block / Unblock links
395 if ( $this->getUser()->isAllowed( 'block' ) ) {
396 if ( $userObj->isBlocked() ) {
397 $tools[] = Linker::linkKnown( # Change block link
398 SpecialPage::getTitleFor( 'Block', $nt->getDBkey() ),
399 $this->msg( 'change-blocklink' )->escaped()
401 $tools[] = Linker::linkKnown( # Unblock link
402 SpecialPage::getTitleFor( 'BlockList' ),
403 $this->msg( 'unblocklink' )->escaped(),
404 array(),
405 array(
406 'action' => 'unblock',
407 'ip' => $nt->getDBkey()
410 } else {
411 # User is not blocked
412 $tools[] = Linker::linkKnown( # Block link
413 SpecialPage::getTitleFor( 'Block', $nt->getDBkey() ),
414 $this->msg( 'blocklink' )->escaped()
418 # Block log link
419 $tools[] = Linker::linkKnown(
420 SpecialPage::getTitleFor( 'Log' ),
421 $this->msg( 'sp-contributions-blocklog' )->escaped(),
422 array(),
423 array(
424 'type' => 'block',
425 'page' => $nt->getPrefixedText()
430 # Uploads
431 $tools[] = Linker::linkKnown(
432 SpecialPage::getTitleFor( 'Listfiles', $userObj->getName() ),
433 $this->msg( 'sp-contributions-uploads' )->escaped()
436 # Other logs link
437 $tools[] = Linker::linkKnown(
438 SpecialPage::getTitleFor( 'Log' ),
439 $this->msg( 'sp-contributions-logs' )->escaped(),
440 array(),
441 array( 'user' => $nt->getText() )
443 # Link to contributions
444 $tools[] = Linker::linkKnown(
445 SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
446 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
449 # Add a link to change user rights for privileged users
450 $userrightsPage = new UserrightsPage();
451 $userrightsPage->setContext( $this->getContext() );
452 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
453 $tools[] = Linker::linkKnown(
454 SpecialPage::getTitleFor( 'Userrights', $nt->getDBkey() ),
455 $this->msg( 'sp-contributions-userrights' )->escaped()
459 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
461 $links = $this->getLanguage()->pipeList( $tools );
463 // Show a note if the user is blocked and display the last block log entry.
464 if ( $userObj->isBlocked() ) {
465 // LogEventsList::showLogExtract() wants the first parameter by ref
466 $out = $this->getOutput();
467 LogEventsList::showLogExtract(
468 $out,
469 'block',
470 $nt,
472 array(
473 'lim' => 1,
474 'showIfEmpty' => false,
475 'msgKey' => array(
476 'sp-contributions-blocked-notice',
477 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
479 'offset' => '' # don't use $this->getRequest() parameter offset
485 // Old message 'contribsub' had one parameter, but that doesn't work for
486 // languages that want to put the "for" bit right after $user but before
487 // $links. If 'contribsub' is around, use it for reverse compatibility,
488 // otherwise use 'contribsub2'.
489 $oldMsg = $this->msg( 'contribsub' );
490 if ( $oldMsg->exists() ) {
491 return $oldMsg->rawParams( "$user ($links)" );
494 return $this->msg( 'contribsub2' )->rawParams( $user, $links );
498 * Generates the namespace selector form with hidden attributes.
499 * @param array $options the options to be included.
500 * @return string
502 function getForm( $options ) {
503 global $wgScript;
505 $options['title'] = $this->getTitle()->getPrefixedText();
506 if ( !isset( $options['target'] ) ) {
507 $options['target'] = '';
508 } else {
509 $options['target'] = str_replace( '_', ' ', $options['target'] );
512 if ( !isset( $options['namespace'] ) ) {
513 $options['namespace'] = '';
516 if ( !isset( $options['contribs'] ) ) {
517 $options['contribs'] = 'user';
520 if ( $options['contribs'] == 'newbie' ) {
521 $options['target'] = '';
524 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
526 foreach ( $options as $name => $value ) {
527 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
528 continue;
530 $f .= "\t" . Html::hidden( $name, $value ) . "\n";
533 $f .= Xml::openElement( 'fieldset' );
534 $f .= Xml::element( 'legend', array(), $this->msg( 'sp-contributions-search' )->text() );
535 $f .= Xml::tags(
536 'label',
537 array( 'for' => 'target' ),
538 $this->msg( 'sp-contributions-username' )->parse()
539 ) . ' ';
540 $f .= Html::input(
541 'target',
542 $options['target'],
543 'text',
544 array(
545 'size' => '20',
546 'required' => ''
547 ) + ( $options['target'] ? array() : array( 'autofocus' ) )
548 ) . ' ';
549 $f .= Html::namespaceSelector(
550 array(
551 'selected' => $options['namespace'],
552 'all' => '',
553 'label' => $this->msg( 'namespace' )->text()
555 array(
556 'name' => 'namespace',
557 'id' => 'namespace',
558 'class' => 'namespaceselector',
560 ) . ' ';
561 $f .= Xml::submitButton( $this->msg( 'sp-contributions-submit' )->text() );
562 $f .= Xml::closeElement( 'fieldset' );
563 $f .= Xml::closeElement( 'form' );
565 return $f;
568 protected function getGroupName() {
569 return 'users';