MediaWiki
REL1_21
|
00001 <?php 00030 class SpecialRevisionDelete extends UnlistedSpecialPage { 00032 var $submitClicked; 00033 00035 var $ids; 00036 00038 var $archiveName; 00039 00041 var $token; 00042 00044 var $targetObj; 00045 00047 var $typeName; 00048 00050 var $checks; 00051 00053 var $typeInfo; 00054 00056 var $list; 00057 00062 static $allowedTypes = array( 00063 'revision' => array( 00064 'check-label' => 'revdelete-hide-text', 00065 'deletion-bits' => Revision::DELETED_TEXT, 00066 'success' => 'revdelete-success', 00067 'failure' => 'revdelete-failure', 00068 'list-class' => 'RevDel_RevisionList', 00069 'permission' => 'deleterevision', 00070 ), 00071 'archive' => array( 00072 'check-label' => 'revdelete-hide-text', 00073 'deletion-bits' => Revision::DELETED_TEXT, 00074 'success' => 'revdelete-success', 00075 'failure' => 'revdelete-failure', 00076 'list-class' => 'RevDel_ArchiveList', 00077 'permission' => 'deleterevision', 00078 ), 00079 'oldimage'=> array( 00080 'check-label' => 'revdelete-hide-image', 00081 'deletion-bits' => File::DELETED_FILE, 00082 'success' => 'revdelete-success', 00083 'failure' => 'revdelete-failure', 00084 'list-class' => 'RevDel_FileList', 00085 'permission' => 'deleterevision', 00086 ), 00087 'filearchive' => array( 00088 'check-label' => 'revdelete-hide-image', 00089 'deletion-bits' => File::DELETED_FILE, 00090 'success' => 'revdelete-success', 00091 'failure' => 'revdelete-failure', 00092 'list-class' => 'RevDel_ArchivedFileList', 00093 'permission' => 'deleterevision', 00094 ), 00095 'logging' => array( 00096 'check-label' => 'revdelete-hide-name', 00097 'deletion-bits' => LogPage::DELETED_ACTION, 00098 'success' => 'logdelete-success', 00099 'failure' => 'logdelete-failure', 00100 'list-class' => 'RevDel_LogList', 00101 'permission' => 'deletelogentry', 00102 ), 00103 ); 00104 00106 static $deprecatedTypeMap = array( 00107 'oldid' => 'revision', 00108 'artimestamp' => 'archive', 00109 'oldimage' => 'oldimage', 00110 'fileid' => 'filearchive', 00111 'logid' => 'logging', 00112 ); 00113 00114 public function __construct() { 00115 parent::__construct( 'Revisiondelete', 'deletedhistory' ); 00116 } 00117 00118 public function execute( $par ) { 00119 $this->checkPermissions(); 00120 $this->checkReadOnly(); 00121 00122 $output = $this->getOutput(); 00123 $user = $this->getUser(); 00124 00125 $this->setHeaders(); 00126 $this->outputHeader(); 00127 $request = $this->getRequest(); 00128 $this->submitClicked = $request->wasPosted() && $request->getBool( 'wpSubmit' ); 00129 # Handle our many different possible input types. 00130 $ids = $request->getVal( 'ids' ); 00131 if ( !is_null( $ids ) ) { 00132 # Allow CSV, for backwards compatibility, or a single ID for show/hide links 00133 $this->ids = explode( ',', $ids ); 00134 } else { 00135 # Array input 00136 $this->ids = array_keys( $request->getArray( 'ids', array() ) ); 00137 } 00138 // $this->ids = array_map( 'intval', $this->ids ); 00139 $this->ids = array_unique( array_filter( $this->ids ) ); 00140 00141 if ( $request->getVal( 'action' ) == 'historysubmit' || $request->getVal( 'action' ) == 'revisiondelete' ) { 00142 // For show/hide form submission from history page 00143 // Since we are access through index.php?title=XXX&action=historysubmit 00144 // getFullTitle() will contain the target title and not our title 00145 $this->targetObj = $this->getFullTitle(); 00146 $this->typeName = 'revision'; 00147 } else { 00148 $this->typeName = $request->getVal( 'type' ); 00149 $this->targetObj = Title::newFromText( $request->getText( 'target' ) ); 00150 if ( $this->targetObj && $this->targetObj->isSpecial( 'Log' ) && count( $this->ids ) !== 0 ) { 00151 $result = wfGetDB( DB_SLAVE )->select( 'logging', 00152 'log_type', 00153 array( 'log_id' => $this->ids ), 00154 __METHOD__, 00155 array( 'DISTINCT' ) 00156 ); 00157 00158 if ( $result->numRows() == 1 ) { 00159 // If there's only one type, the target can be set to include it. 00160 $this->targetObj = SpecialPage::getTitleFor( 'Log', $result->current()->log_type ); 00161 } 00162 } 00163 } 00164 00165 # For reviewing deleted files... 00166 $this->archiveName = $request->getVal( 'file' ); 00167 $this->token = $request->getVal( 'token' ); 00168 if ( $this->archiveName && $this->targetObj ) { 00169 $this->tryShowFile( $this->archiveName ); 00170 return; 00171 } 00172 00173 if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) { 00174 $this->typeName = self::$deprecatedTypeMap[$this->typeName]; 00175 } 00176 00177 # No targets? 00178 if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) { 00179 throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); 00180 } 00181 $this->typeInfo = self::$allowedTypes[$this->typeName]; 00182 $this->mIsAllowed = $user->isAllowed( $this->typeInfo['permission'] ); 00183 00184 # If we have revisions, get the title from the first one 00185 # since they should all be from the same page. This allows 00186 # for more flexibility with page moves... 00187 if( $this->typeName == 'revision' ) { 00188 $rev = Revision::newFromId( $this->ids[0] ); 00189 $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj; 00190 } 00191 00192 $this->otherReason = $request->getVal( 'wpReason' ); 00193 # We need a target page! 00194 if( is_null( $this->targetObj ) ) { 00195 $output->addWikiMsg( 'undelete-header' ); 00196 return; 00197 } 00198 # Give a link to the logs/hist for this page 00199 $this->showConvenienceLinks(); 00200 00201 # Initialise checkboxes 00202 $this->checks = array( 00203 array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ), 00204 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ), 00205 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ) 00206 ); 00207 if( $user->isAllowed( 'suppressrevision' ) ) { 00208 $this->checks[] = array( 'revdelete-hide-restricted', 00209 'wpHideRestricted', Revision::DELETED_RESTRICTED ); 00210 } 00211 00212 # Either submit or create our form 00213 if( $this->mIsAllowed && $this->submitClicked ) { 00214 $this->submit( $request ); 00215 } else { 00216 $this->showForm(); 00217 } 00218 00219 $qc = $this->getLogQueryCond(); 00220 # Show relevant lines from the deletion log 00221 $deleteLogPage = new LogPage( 'delete' ); 00222 $output->addHTML( "<h2>" . $deleteLogPage->getName()->escaped() . "</h2>\n" ); 00223 LogEventsList::showLogExtract( $output, 'delete', 00224 $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) ); 00225 # Show relevant lines from the suppression log 00226 if( $user->isAllowed( 'suppressionlog' ) ) { 00227 $suppressLogPage = new LogPage( 'suppress' ); 00228 $output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" ); 00229 LogEventsList::showLogExtract( $output, 'suppress', 00230 $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) ); 00231 } 00232 } 00233 00237 protected function showConvenienceLinks() { 00238 # Give a link to the logs/hist for this page 00239 if( $this->targetObj ) { 00240 $links = array(); 00241 $links[] = Linker::linkKnown( 00242 SpecialPage::getTitleFor( 'Log' ), 00243 $this->msg( 'viewpagelogs' )->escaped(), 00244 array(), 00245 array( 'page' => $this->targetObj->getPrefixedText() ) 00246 ); 00247 if ( !$this->targetObj->isSpecialPage() ) { 00248 # Give a link to the page history 00249 $links[] = Linker::linkKnown( 00250 $this->targetObj, 00251 $this->msg( 'pagehist' )->escaped(), 00252 array(), 00253 array( 'action' => 'history' ) 00254 ); 00255 # Link to deleted edits 00256 if( $this->getUser()->isAllowed( 'undelete' ) ) { 00257 $undelete = SpecialPage::getTitleFor( 'Undelete' ); 00258 $links[] = Linker::linkKnown( 00259 $undelete, 00260 $this->msg( 'deletedhist' )->escaped(), 00261 array(), 00262 array( 'target' => $this->targetObj->getPrefixedDBkey() ) 00263 ); 00264 } 00265 } 00266 # Logs themselves don't have histories or archived revisions 00267 $this->getOutput()->addSubtitle( $this->getLanguage()->pipeList( $links ) ); 00268 } 00269 } 00270 00275 protected function getLogQueryCond() { 00276 $conds = array(); 00277 // Revision delete logs for these item 00278 $conds['log_type'] = array( 'delete', 'suppress' ); 00279 $conds['log_action'] = $this->getList()->getLogAction(); 00280 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName ); 00281 $conds['ls_value'] = $this->ids; 00282 return $conds; 00283 } 00284 00289 protected function tryShowFile( $archiveName ) { 00290 $repo = RepoGroup::singleton()->getLocalRepo(); 00291 $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName ); 00292 $oimage->load(); 00293 // Check if user is allowed to see this file 00294 if ( !$oimage->exists() ) { 00295 $this->getOutput()->addWikiMsg( 'revdelete-no-file' ); 00296 return; 00297 } 00298 $user = $this->getUser(); 00299 if( !$oimage->userCan( File::DELETED_FILE, $user ) ) { 00300 if( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) { 00301 throw new PermissionsError( 'suppressrevision' ); 00302 } else { 00303 throw new PermissionsError( 'deletedtext' ); 00304 } 00305 } 00306 if ( !$user->matchEditToken( $this->token, $archiveName ) ) { 00307 $lang = $this->getLanguage(); 00308 $this->getOutput()->addWikiMsg( 'revdelete-show-file-confirm', 00309 $this->targetObj->getText(), 00310 $lang->userDate( $oimage->getTimestamp(), $user ), 00311 $lang->userTime( $oimage->getTimestamp(), $user ) ); 00312 $this->getOutput()->addHTML( 00313 Xml::openElement( 'form', array( 00314 'method' => 'POST', 00315 'action' => $this->getTitle()->getLocalUrl( 00316 'target=' . urlencode( $this->targetObj->getPrefixedDBkey() ) . 00317 '&file=' . urlencode( $archiveName ) . 00318 '&token=' . urlencode( $user->getEditToken( $archiveName ) ) ) 00319 ) 00320 ) . 00321 Xml::submitButton( $this->msg( 'revdelete-show-file-submit' )->text() ) . 00322 '</form>' 00323 ); 00324 return; 00325 } 00326 $this->getOutput()->disable(); 00327 # We mustn't allow the output to be Squid cached, otherwise 00328 # if an admin previews a deleted image, and it's cached, then 00329 # a user without appropriate permissions can toddle off and 00330 # nab the image, and Squid will serve it 00331 $this->getRequest()->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); 00332 $this->getRequest()->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); 00333 $this->getRequest()->response()->header( 'Pragma: no-cache' ); 00334 00335 $key = $oimage->getStorageKey(); 00336 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key; 00337 $repo->streamFile( $path ); 00338 } 00339 00343 protected function getList() { 00344 if ( is_null( $this->list ) ) { 00345 $class = $this->typeInfo['list-class']; 00346 $this->list = new $class( $this->getContext(), $this->targetObj, $this->ids ); 00347 } 00348 return $this->list; 00349 } 00350 00355 protected function showForm() { 00356 $UserAllowed = true; 00357 00358 if ( $this->typeName == 'logging' ) { 00359 $this->getOutput()->addWikiMsg( 'logdelete-selected', $this->getLanguage()->formatNum( count( $this->ids ) ) ); 00360 } else { 00361 $this->getOutput()->addWikiMsg( 'revdelete-selected', 00362 $this->targetObj->getPrefixedText(), count( $this->ids ) ); 00363 } 00364 00365 $this->getOutput()->addHTML( "<ul>" ); 00366 00367 $numRevisions = 0; 00368 // Live revisions... 00369 $list = $this->getList(); 00370 for ( $list->reset(); $list->current(); $list->next() ) { 00371 $item = $list->current(); 00372 if ( !$item->canView() ) { 00373 if( !$this->submitClicked ) { 00374 throw new PermissionsError( 'suppressrevision' ); 00375 } 00376 $UserAllowed = false; 00377 } 00378 $numRevisions++; 00379 $this->getOutput()->addHTML( $item->getHTML() ); 00380 } 00381 00382 if( !$numRevisions ) { 00383 throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); 00384 } 00385 00386 $this->getOutput()->addHTML( "</ul>" ); 00387 // Explanation text 00388 $this->addUsageText(); 00389 00390 // Normal sysops can always see what they did, but can't always change it 00391 if( !$UserAllowed ) return; 00392 00393 // Show form if the user can submit 00394 if( $this->mIsAllowed ) { 00395 $out = Xml::openElement( 'form', array( 'method' => 'post', 00396 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ), 00397 'id' => 'mw-revdel-form-revisions' ) ) . 00398 Xml::fieldset( $this->msg( 'revdelete-legend' )->text() ) . 00399 $this->buildCheckBoxes() . 00400 Xml::openElement( 'table' ) . 00401 "<tr>\n" . 00402 '<td class="mw-label">' . 00403 Xml::label( $this->msg( 'revdelete-log' )->text(), 'wpRevDeleteReasonList' ) . 00404 '</td>' . 00405 '<td class="mw-input">' . 00406 Xml::listDropDown( 'wpRevDeleteReasonList', 00407 $this->msg( 'revdelete-reason-dropdown' )->inContentLanguage()->text(), 00408 $this->msg( 'revdelete-reasonotherlist' )->inContentLanguage()->text(), 00409 '', 'wpReasonDropDown', 1 00410 ) . 00411 '</td>' . 00412 "</tr><tr>\n" . 00413 '<td class="mw-label">' . 00414 Xml::label( $this->msg( 'revdelete-otherreason' )->text(), 'wpReason' ) . 00415 '</td>' . 00416 '<td class="mw-input">' . 00417 Xml::input( 'wpReason', 60, $this->otherReason, array( 'id' => 'wpReason', 'maxlength' => 100 ) ) . 00418 '</td>' . 00419 "</tr><tr>\n" . 00420 '<td></td>' . 00421 '<td class="mw-submit">' . 00422 Xml::submitButton( $this->msg( 'revdelete-submit', $numRevisions )->text(), 00423 array( 'name' => 'wpSubmit' ) ) . 00424 '</td>' . 00425 "</tr>\n" . 00426 Xml::closeElement( 'table' ) . 00427 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) . 00428 Html::hidden( 'target', $this->targetObj->getPrefixedText() ) . 00429 Html::hidden( 'type', $this->typeName ) . 00430 Html::hidden( 'ids', implode( ',', $this->ids ) ) . 00431 Xml::closeElement( 'fieldset' ) . "\n"; 00432 } else { 00433 $out = ''; 00434 } 00435 if( $this->mIsAllowed ) { 00436 $out .= Xml::closeElement( 'form' ) . "\n"; 00437 // Show link to edit the dropdown reasons 00438 if( $this->getUser()->isAllowed( 'editinterface' ) ) { 00439 $title = Title::makeTitle( NS_MEDIAWIKI, 'Revdelete-reason-dropdown' ); 00440 $link = Linker::link( 00441 $title, 00442 $this->msg( 'revdelete-edit-reasonlist' )->escaped(), 00443 array(), 00444 array( 'action' => 'edit' ) 00445 ); 00446 $out .= Xml::tags( 'p', array( 'class' => 'mw-revdel-editreasons' ), $link ) . "\n"; 00447 } 00448 } 00449 $this->getOutput()->addHTML( $out ); 00450 } 00451 00456 protected function addUsageText() { 00457 $this->getOutput()->addWikiMsg( 'revdelete-text' ); 00458 if( $this->getUser()->isAllowed( 'suppressrevision' ) ) { 00459 $this->getOutput()->addWikiMsg( 'revdelete-suppress-text' ); 00460 } 00461 if( $this->mIsAllowed ) { 00462 $this->getOutput()->addWikiMsg( 'revdelete-confirm' ); 00463 } 00464 } 00465 00469 protected function buildCheckBoxes() { 00470 $html = '<table>'; 00471 // If there is just one item, use checkboxes 00472 $list = $this->getList(); 00473 if( $list->length() == 1 ) { 00474 $list->reset(); 00475 $bitfield = $list->current()->getBits(); // existing field 00476 if( $this->submitClicked ) { 00477 $bitfield = $this->extractBitfield( $this->extractBitParams(), $bitfield ); 00478 } 00479 foreach( $this->checks as $item ) { 00480 list( $message, $name, $field ) = $item; 00481 $innerHTML = Xml::checkLabel( $this->msg( $message )->text(), $name, $name, $bitfield & $field ); 00482 if( $field == Revision::DELETED_RESTRICTED ) 00483 $innerHTML = "<b>$innerHTML</b>"; 00484 $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML ); 00485 $html .= "<tr>$line</tr>\n"; 00486 } 00487 // Otherwise, use tri-state radios 00488 } else { 00489 $html .= '<tr>'; 00490 $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-same' )->escaped() . '</th>'; 00491 $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-unset' )->escaped() . '</th>'; 00492 $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-set' )->escaped() . '</th>'; 00493 $html .= "<th></th></tr>\n"; 00494 foreach( $this->checks as $item ) { 00495 list( $message, $name, $field ) = $item; 00496 // If there are several items, use third state by default... 00497 if( $this->submitClicked ) { 00498 $selected = $this->getRequest()->getInt( $name, 0 /* unchecked */ ); 00499 } else { 00500 $selected = -1; // use existing field 00501 } 00502 $line = '<td class="mw-revdel-checkbox">' . Xml::radio( $name, -1, $selected == -1 ) . '</td>'; 00503 $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 0, $selected == 0 ) . '</td>'; 00504 $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 1, $selected == 1 ) . '</td>'; 00505 $label = $this->msg( $message )->escaped(); 00506 if( $field == Revision::DELETED_RESTRICTED ) { 00507 $label = "<b>$label</b>"; 00508 } 00509 $line .= "<td>$label</td>"; 00510 $html .= "<tr>$line</tr>\n"; 00511 } 00512 } 00513 00514 $html .= '</table>'; 00515 return $html; 00516 } 00517 00523 protected function submit() { 00524 # Check edit token on submission 00525 $token = $this->getRequest()->getVal( 'wpEditToken' ); 00526 if( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) { 00527 $this->getOutput()->addWikiMsg( 'sessionfailure' ); 00528 return false; 00529 } 00530 $bitParams = $this->extractBitParams(); 00531 $listReason = $this->getRequest()->getText( 'wpRevDeleteReasonList', 'other' ); // from dropdown 00532 $comment = $listReason; 00533 if( $comment != 'other' && $this->otherReason != '' ) { 00534 // Entry from drop down menu + additional comment 00535 $comment .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->otherReason; 00536 } elseif( $comment == 'other' ) { 00537 $comment = $this->otherReason; 00538 } 00539 # Can the user set this field? 00540 if( $bitParams[Revision::DELETED_RESTRICTED] == 1 && !$this->getUser()->isAllowed( 'suppressrevision' ) ) { 00541 throw new PermissionsError( 'suppressrevision' ); 00542 } 00543 # If the save went through, go to success message... 00544 $status = $this->save( $bitParams, $comment, $this->targetObj ); 00545 if ( $status->isGood() ) { 00546 $this->success(); 00547 return true; 00548 # ...otherwise, bounce back to form... 00549 } else { 00550 $this->failure( $status ); 00551 } 00552 return false; 00553 } 00554 00558 protected function success() { 00559 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) ); 00560 $this->getOutput()->wrapWikiMsg( "<span class=\"success\">\n$1\n</span>", $this->typeInfo['success'] ); 00561 $this->list->reloadFromMaster(); 00562 $this->showForm(); 00563 } 00564 00568 protected function failure( $status ) { 00569 $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) ); 00570 $this->getOutput()->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) ); 00571 $this->showForm(); 00572 } 00573 00579 protected function extractBitParams() { 00580 $bitfield = array(); 00581 foreach( $this->checks as $item ) { 00582 list( /* message */, $name, $field ) = $item; 00583 $val = $this->getRequest()->getInt( $name, 0 /* unchecked */ ); 00584 if( $val < -1 || $val > 1) { 00585 $val = -1; // -1 for existing value 00586 } 00587 $bitfield[$field] = $val; 00588 } 00589 if( !isset( $bitfield[Revision::DELETED_RESTRICTED] ) ) { 00590 $bitfield[Revision::DELETED_RESTRICTED] = 0; 00591 } 00592 return $bitfield; 00593 } 00594 00601 public static function extractBitfield( $bitPars, $oldfield ) { 00602 // Build the actual new rev_deleted bitfield 00603 $newBits = 0; 00604 foreach( $bitPars as $const => $val ) { 00605 if( $val == 1 ) { 00606 $newBits |= $const; // $const is the *_deleted const 00607 } elseif( $val == -1 ) { 00608 $newBits |= ($oldfield & $const); // use existing 00609 } 00610 } 00611 return $newBits; 00612 } 00613 00621 protected function save( $bitfield, $reason, $title ) { 00622 return $this->getList()->setVisibility( 00623 array( 'value' => $bitfield, 'comment' => $reason ) 00624 ); 00625 } 00626 00627 protected function getGroupName() { 00628 return 'pagetools'; 00629 } 00630 }