00001 <?php
00007 class DeletedContribsPager extends IndexPager {
00008 public $mDefaultDirection = true;
00009 var $messages, $target;
00010 var $namespace = '', $mDb;
00011
00012 function __construct( $target, $namespace = false ) {
00013 parent::__construct();
00014 $msgs = array( 'deletionlog', 'undeleteviewlink', 'diff' );
00015 foreach( $msgs as $msg ) {
00016 $this->messages[$msg] = wfMsgExt( $msg, array( 'escapenoentities') );
00017 }
00018 $this->target = $target;
00019 $this->namespace = $namespace;
00020 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
00021 }
00022
00023 function getDefaultQuery() {
00024 $query = parent::getDefaultQuery();
00025 $query['target'] = $this->target;
00026 return $query;
00027 }
00028
00029 function getQueryInfo() {
00030 global $wgUser;
00031 list( $index, $userCond ) = $this->getUserCond();
00032 $conds = array_merge( $userCond, $this->getNamespaceCond() );
00033
00034 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
00035 $conds[] = $this->mDb->bitAnd('ar_deleted',Revision::DELETED_USER) . ' = 0';
00036 } else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
00037 $conds[] = $this->mDb->bitAnd('ar_deleted',Revision::SUPPRESSED_USER) .
00038 ' != ' . Revision::SUPPRESSED_USER;
00039 }
00040 return array(
00041 'tables' => array( 'archive' ),
00042 'fields' => array(
00043 'ar_rev_id', 'ar_namespace', 'ar_title', 'ar_timestamp', 'ar_comment', 'ar_minor_edit',
00044 'ar_user', 'ar_user_text', 'ar_deleted'
00045 ),
00046 'conds' => $conds,
00047 'options' => array( 'USE INDEX' => $index )
00048 );
00049 }
00050
00051 function getUserCond() {
00052 $condition = array();
00053
00054 $condition['ar_user_text'] = $this->target;
00055 $index = 'usertext_timestamp';
00056
00057 return array( $index, $condition );
00058 }
00059
00060 function getIndexField() {
00061 return 'ar_timestamp';
00062 }
00063
00064 function getStartBody() {
00065 return "<ul>\n";
00066 }
00067
00068 function getEndBody() {
00069 return "</ul>\n";
00070 }
00071
00072 function getNavigationBar() {
00073 global $wgLang;
00074
00075 if ( isset( $this->mNavigationBar ) ) {
00076 return $this->mNavigationBar;
00077 }
00078 $fmtLimit = $wgLang->formatNum( $this->mLimit );
00079 $linkTexts = array(
00080 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
00081 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
00082 'first' => wfMsgHtml( 'histlast' ),
00083 'last' => wfMsgHtml( 'histfirst' )
00084 );
00085
00086 $pagingLinks = $this->getPagingLinks( $linkTexts );
00087 $limitLinks = $this->getLimitLinks();
00088 $limits = $wgLang->pipeList( $limitLinks );
00089
00090 $this->mNavigationBar = "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
00091 wfMsgExt( 'viewprevnext', array( 'parsemag', 'escape', 'replaceafter' ), $pagingLinks['prev'], $pagingLinks['next'], $limits );
00092 return $this->mNavigationBar;
00093 }
00094
00095 function getNamespaceCond() {
00096 if ( $this->namespace !== '' ) {
00097 return array( 'ar_namespace' => (int)$this->namespace );
00098 } else {
00099 return array();
00100 }
00101 }
00102
00113 function formatRow( $row ) {
00114 global $wgUser, $wgLang;
00115 wfProfileIn( __METHOD__ );
00116
00117 $sk = $this->getSkin();
00118
00119 $rev = new Revision( array(
00120 'id' => $row->ar_rev_id,
00121 'comment' => $row->ar_comment,
00122 'user' => $row->ar_user,
00123 'user_text' => $row->ar_user_text,
00124 'timestamp' => $row->ar_timestamp,
00125 'minor_edit' => $row->ar_minor_edit,
00126 'deleted' => $row->ar_deleted,
00127 ) );
00128
00129 $page = Title::makeTitle( $row->ar_namespace, $row->ar_title );
00130
00131 $undelete = SpecialPage::getTitleFor( 'Undelete' );
00132
00133 $logs = SpecialPage::getTitleFor( 'Log' );
00134 $dellog = $sk->linkKnown(
00135 $logs,
00136 $this->messages['deletionlog'],
00137 array(),
00138 array(
00139 'type' => 'delete',
00140 'page' => $page->getPrefixedText()
00141 )
00142 );
00143
00144 $reviewlink = $sk->linkKnown(
00145 SpecialPage::getTitleFor( 'Undelete', $page->getPrefixedDBkey() ),
00146 $this->messages['undeleteviewlink']
00147 );
00148
00149 if( $wgUser->isAllowed('deletedtext') ) {
00150 $last = $sk->linkKnown(
00151 $undelete,
00152 $this->messages['diff'],
00153 array(),
00154 array(
00155 'target' => $page->getPrefixedText(),
00156 'timestamp' => $rev->getTimestamp(),
00157 'diff' => 'prev'
00158 )
00159 );
00160 } else {
00161 $last = $this->messages['diff'];
00162 }
00163
00164 $comment = $sk->revComment( $rev );
00165 $date = htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) );
00166
00167 if( !$wgUser->isAllowed('undelete') || !$rev->userCan(Revision::DELETED_TEXT) ) {
00168 $link = $date;
00169 } else {
00170 $link = $sk->linkKnown(
00171 $undelete,
00172 $date,
00173 array(),
00174 array(
00175 'target' => $page->getPrefixedText(),
00176 'timestamp' => $rev->getTimestamp()
00177 )
00178 );
00179 }
00180
00181 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
00182 $link = '<span class="history-deleted">' . $link . '</span>';
00183 }
00184
00185 $pagelink = $sk->link( $page );
00186
00187 if( $rev->isMinor() ) {
00188 $mflag = ChangesList::flag( 'minor' );
00189 } else {
00190 $mflag = '';
00191 }
00192
00193
00194 $canHide = $wgUser->isAllowed( 'deleterevision' );
00195 if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
00196 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
00197 $del = $this->mSkin->revDeleteLinkDisabled( $canHide );
00198 } else {
00199 $query = array(
00200 'type' => 'archive',
00201 'target' => $page->getPrefixedDbkey(),
00202 'ids' => $rev->getTimestamp() );
00203 $del = $this->mSkin->revDeleteLink( $query,
00204 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide ) . ' ';
00205 }
00206 } else {
00207 $del = '';
00208 }
00209
00210 $tools = Html::rawElement(
00211 'span',
00212 array( 'class' => 'mw-deletedcontribs-tools' ),
00213 wfMsg( 'parentheses', $wgLang->pipeList( array( $last, $dellog, $reviewlink ) ) )
00214 );
00215
00216 $ret = "{$del}{$link} {$tools} . . {$mflag} {$pagelink} {$comment}";
00217
00218 # Denote if username is redacted for this edit
00219 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
00220 $ret .= " <strong>" . wfMsgHtml('rev-deleted-user-contribs') . "</strong>";
00221 }
00222
00223 $ret = Html::rawElement( 'li', array(), $ret ) . "\n";
00224
00225 wfProfileOut( __METHOD__ );
00226 return $ret;
00227 }
00228
00234 public function getDatabase() {
00235 return $this->mDb;
00236 }
00237 }
00238
00239 class DeletedContributionsPage extends SpecialPage {
00240 function __construct() {
00241 parent::__construct( 'DeletedContributions', 'deletedhistory',
00242 true, false, false );
00243 }
00244
00252 function execute( $par ) {
00253 global $wgUser;
00254 $this->setHeaders();
00255
00256 if ( !$this->userCanExecute( $wgUser ) ) {
00257 $this->displayRestrictionError();
00258 return;
00259 }
00260
00261 global $wgOut, $wgLang, $wgRequest;
00262
00263 $wgOut->setPageTitle( wfMsgExt( 'deletedcontributions-title', array( 'parsemag' ) ) );
00264
00265 $options = array();
00266
00267 if ( isset( $par ) ) {
00268 $target = $par;
00269 } else {
00270 $target = $wgRequest->getVal( 'target' );
00271 }
00272
00273 if ( !strlen( $target ) ) {
00274 $wgOut->addHTML( $this->getForm( '' ) );
00275 return;
00276 }
00277
00278 $options['limit'] = $wgRequest->getInt( 'limit', 50 );
00279 $options['target'] = $target;
00280
00281 $nt = Title::makeTitleSafe( NS_USER, $target );
00282 if ( !$nt ) {
00283 $wgOut->addHTML( $this->getForm( '' ) );
00284 return;
00285 }
00286 $id = User::idFromName( $nt->getText() );
00287
00288 $target = $nt->getText();
00289 $wgOut->setSubtitle( $this->getSubTitle( $nt, $id ) );
00290
00291 if ( ( $ns = $wgRequest->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
00292 $options['namespace'] = intval( $ns );
00293 } else {
00294 $options['namespace'] = '';
00295 }
00296
00297 $wgOut->addHTML( $this->getForm( $options ) );
00298
00299 $pager = new DeletedContribsPager( $target, $options['namespace'] );
00300 if ( !$pager->getNumRows() ) {
00301 $wgOut->addWikiMsg( 'nocontribs' );
00302 return;
00303 }
00304
00305 # Show a message about slave lag, if applicable
00306 if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
00307 $wgOut->showLagWarning( $lag );
00308
00309 $wgOut->addHTML(
00310 '<p>' . $pager->getNavigationBar() . '</p>' .
00311 $pager->getBody() .
00312 '<p>' . $pager->getNavigationBar() . '</p>' );
00313
00314 # If there were contributions, and it was a valid user or IP, show
00315 # the appropriate "footer" message - WHOIS tools, etc.
00316 if( $target != 'newbies' ) {
00317 $message = IP::isIPAddress( $target )
00318 ? 'sp-contributions-footer-anon'
00319 : 'sp-contributions-footer';
00320
00321
00322 $text = wfMsgNoTrans( $message, $target );
00323 if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
00324 $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
00325 }
00326 }
00327 }
00328
00336 function getSubTitle( $nt, $id ) {
00337 global $wgSysopUserBans, $wgLang, $wgUser, $wgOut;
00338
00339 $sk = $wgUser->getSkin();
00340
00341 if ( $id === null ) {
00342 $user = htmlspecialchars( $nt->getText() );
00343 } else {
00344 $user = $sk->link( $nt, htmlspecialchars( $nt->getText() ) );
00345 }
00346 $userObj = User::newFromName( $nt->getText(), false );
00347 $talk = $nt->getTalkPage();
00348 if( $talk ) {
00349 # Talk page link
00350 $tools[] = $sk->link( $talk, wfMsgHtml( 'sp-contributions-talk' ) );
00351 if( ( $id !== null && $wgSysopUserBans ) || ( $id === null && IP::isIPAddress( $nt->getText() ) ) ) {
00352 if( $wgUser->isAllowed( 'block' ) ) { # Block / Change block / Unblock links
00353 if ( $userObj->isBlocked() ) {
00354 $tools[] = $sk->linkKnown( # Change block link
00355 SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
00356 wfMsgHtml( 'change-blocklink' )
00357 );
00358 $tools[] = $sk->linkKnown( # Unblock link
00359 SpecialPage::getTitleFor( 'BlockList' ),
00360 wfMsgHtml( 'unblocklink' ),
00361 array(),
00362 array(
00363 'action' => 'unblock',
00364 'ip' => $nt->getDBkey()
00365 )
00366 );
00367 }
00368 else { # User is not blocked
00369 $tools[] = $sk->linkKnown( # Block link
00370 SpecialPage::getTitleFor( 'Blockip', $nt->getDBkey() ),
00371 wfMsgHtml( 'blocklink' )
00372 );
00373 }
00374 }
00375 # Block log link
00376 $tools[] = $sk->linkKnown(
00377 SpecialPage::getTitleFor( 'Log' ),
00378 wfMsgHtml( 'sp-contributions-blocklog' ),
00379 array(),
00380 array(
00381 'type' => 'block',
00382 'page' => $nt->getPrefixedText()
00383 )
00384 );
00385 }
00386 # Other logs link
00387 $tools[] = $sk->linkKnown(
00388 SpecialPage::getTitleFor( 'Log' ),
00389 wfMsgHtml( 'sp-contributions-logs' ),
00390 array(),
00391 array( 'user' => $nt->getText() )
00392 );
00393 # Link to contributions
00394 $tools[] = $sk->linkKnown(
00395 SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
00396 wfMsgHtml( 'sp-deletedcontributions-contribs' )
00397 );
00398
00399 # Add a link to change user rights for privileged users
00400 $userrightsPage = new UserrightsPage();
00401 if( $id !== null && $userrightsPage->userCanChangeRights( User::newFromId( $id ) ) ) {
00402 $tools[] = $sk->linkKnown(
00403 SpecialPage::getTitleFor( 'Userrights', $nt->getDBkey() ),
00404 wfMsgHtml( 'sp-contributions-userrights' )
00405 );
00406 }
00407
00408 wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
00409
00410 $links = $wgLang->pipeList( $tools );
00411
00412
00413 if ( $userObj->isBlocked() ) {
00414 LogEventsList::showLogExtract(
00415 $wgOut,
00416 'block',
00417 $nt->getPrefixedText(),
00418 '',
00419 array(
00420 'lim' => 1,
00421 'showIfEmpty' => false,
00422 'msgKey' => array(
00423 'sp-contributions-blocked-notice',
00424 $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
00425 ),
00426 'offset' => '' # don't use $wgRequest parameter offset
00427 )
00428 );
00429 }
00430 }
00431
00432 // Old message 'contribsub' had one parameter, but that doesn't work for
00433
00434
00435
00436 if( wfEmptyMsg( 'contribsub', wfMsg( 'contribsub' ) ) ) {
00437 return wfMsgHtml( 'contribsub2', $user, $links );
00438 } else {
00439 return wfMsgHtml( 'contribsub', "$user ($links)" );
00440 }
00441 }
00442
00447 function getForm( $options ) {
00448 global $wgScript, $wgRequest;
00449
00450 $options['title'] = SpecialPage::getTitleFor( 'DeletedContributions' )->getPrefixedText();
00451 if ( !isset( $options['target'] ) ) {
00452 $options['target'] = '';
00453 } else {
00454 $options['target'] = str_replace( '_' , ' ' , $options['target'] );
00455 }
00456
00457 if ( !isset( $options['namespace'] ) ) {
00458 $options['namespace'] = '';
00459 }
00460
00461 if ( !isset( $options['contribs'] ) ) {
00462 $options['contribs'] = 'user';
00463 }
00464
00465 if ( $options['contribs'] == 'newbie' ) {
00466 $options['target'] = '';
00467 }
00468
00469 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
00470
00471 foreach ( $options as $name => $value ) {
00472 if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
00473 continue;
00474 }
00475 $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
00476 }
00477
00478 $f .= Xml::openElement( 'fieldset' ) .
00479 Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
00480 Xml::tags( 'label', array( 'for' => 'target' ), wfMsgExt( 'sp-contributions-username', 'parseinline' ) ) . ' ' .
00481 Html::input( 'target', $options['target'], 'text', array(
00482 'size' => '20',
00483 'required' => ''
00484 ) + ( $options['target'] ? array() : array( 'autofocus' ) ) ) . ' '.
00485 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
00486 Xml::namespaceSelector( $options['namespace'], '' ) . ' ' .
00487 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
00488 Xml::closeElement( 'fieldset' ) .
00489 Xml::closeElement( 'form' );
00490 return $f;
00491 }
00492 }