MediaWiki
master
|
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 } 00151 00152 # For reviewing deleted files... 00153 $this->archiveName = $request->getVal( 'file' ); 00154 $this->token = $request->getVal( 'token' ); 00155 if ( $this->archiveName && $this->targetObj ) { 00156 $this->tryShowFile( $this->archiveName ); 00157 return; 00158 } 00159 00160 if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) { 00161 $this->typeName = self::$deprecatedTypeMap[$this->typeName]; 00162 } 00163 00164 # No targets? 00165 if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) { 00166 throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); 00167 } 00168 $this->typeInfo = self::$allowedTypes[$this->typeName]; 00169 $this->mIsAllowed = $user->isAllowed( $this->typeInfo['permission'] ); 00170 00171 # If we have revisions, get the title from the first one 00172 # since they should all be from the same page. This allows 00173 # for more flexibility with page moves... 00174 if( $this->typeName == 'revision' ) { 00175 $rev = Revision::newFromId( $this->ids[0] ); 00176 $this->targetObj = $rev ? $rev->getTitle() : $this->targetObj; 00177 } 00178 00179 $this->otherReason = $request->getVal( 'wpReason' ); 00180 # We need a target page! 00181 if( is_null($this->targetObj) ) { 00182 $output->addWikiMsg( 'undelete-header' ); 00183 return; 00184 } 00185 # Give a link to the logs/hist for this page 00186 $this->showConvenienceLinks(); 00187 00188 # Initialise checkboxes 00189 $this->checks = array( 00190 array( $this->typeInfo['check-label'], 'wpHidePrimary', $this->typeInfo['deletion-bits'] ), 00191 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ), 00192 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ) 00193 ); 00194 if( $user->isAllowed('suppressrevision') ) { 00195 $this->checks[] = array( 'revdelete-hide-restricted', 00196 'wpHideRestricted', Revision::DELETED_RESTRICTED ); 00197 } 00198 00199 # Either submit or create our form 00200 if( $this->mIsAllowed && $this->submitClicked ) { 00201 $this->submit( $request ); 00202 } else { 00203 $this->showForm(); 00204 } 00205 00206 $qc = $this->getLogQueryCond(); 00207 # Show relevant lines from the deletion log 00208 $deleteLogPage = new LogPage( 'delete' ); 00209 $output->addHTML( "<h2>" . $deleteLogPage->getName()->escaped() . "</h2>\n" ); 00210 LogEventsList::showLogExtract( $output, 'delete', 00211 $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) ); 00212 # Show relevant lines from the suppression log 00213 if( $user->isAllowed( 'suppressionlog' ) ) { 00214 $suppressLogPage = new LogPage( 'suppress' ); 00215 $output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" ); 00216 LogEventsList::showLogExtract( $output, 'suppress', 00217 $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) ); 00218 } 00219 } 00220 00224 protected function showConvenienceLinks() { 00225 # Give a link to the logs/hist for this page 00226 if( $this->targetObj ) { 00227 $links = array(); 00228 $links[] = Linker::linkKnown( 00229 SpecialPage::getTitleFor( 'Log' ), 00230 $this->msg( 'viewpagelogs' )->escaped(), 00231 array(), 00232 array( 'page' => $this->targetObj->getPrefixedText() ) 00233 ); 00234 if ( !$this->targetObj->isSpecialPage() ) { 00235 # Give a link to the page history 00236 $links[] = Linker::linkKnown( 00237 $this->targetObj, 00238 $this->msg( 'pagehist' )->escaped(), 00239 array(), 00240 array( 'action' => 'history' ) 00241 ); 00242 # Link to deleted edits 00243 if( $this->getUser()->isAllowed('undelete') ) { 00244 $undelete = SpecialPage::getTitleFor( 'Undelete' ); 00245 $links[] = Linker::linkKnown( 00246 $undelete, 00247 $this->msg( 'deletedhist' )->escaped(), 00248 array(), 00249 array( 'target' => $this->targetObj->getPrefixedDBkey() ) 00250 ); 00251 } 00252 } 00253 # Logs themselves don't have histories or archived revisions 00254 $this->getOutput()->addSubtitle( $this->getLanguage()->pipeList( $links ) ); 00255 } 00256 } 00257 00262 protected function getLogQueryCond() { 00263 $conds = array(); 00264 // Revision delete logs for these item 00265 $conds['log_type'] = array( 'delete', 'suppress' ); 00266 $conds['log_action'] = $this->getList()->getLogAction(); 00267 $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName ); 00268 $conds['ls_value'] = $this->ids; 00269 return $conds; 00270 } 00271 00276 protected function tryShowFile( $archiveName ) { 00277 $repo = RepoGroup::singleton()->getLocalRepo(); 00278 $oimage = $repo->newFromArchiveName( $this->targetObj, $archiveName ); 00279 $oimage->load(); 00280 // Check if user is allowed to see this file 00281 if ( !$oimage->exists() ) { 00282 $this->getOutput()->addWikiMsg( 'revdelete-no-file' ); 00283 return; 00284 } 00285 $user = $this->getUser(); 00286 if( !$oimage->userCan( File::DELETED_FILE, $user ) ) { 00287 if( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) { 00288 throw new PermissionsError( 'suppressrevision' ); 00289 } else { 00290 throw new PermissionsError( 'deletedtext' ); 00291 } 00292 } 00293 if ( !$user->matchEditToken( $this->token, $archiveName ) ) { 00294 $lang = $this->getLanguage(); 00295 $this->getOutput()->addWikiMsg( 'revdelete-show-file-confirm', 00296 $this->targetObj->getText(), 00297 $lang->userDate( $oimage->getTimestamp(), $user ), 00298 $lang->userTime( $oimage->getTimestamp(), $user ) ); 00299 $this->getOutput()->addHTML( 00300 Xml::openElement( 'form', array( 00301 'method' => 'POST', 00302 'action' => $this->getTitle()->getLocalUrl( 00303 'target=' . urlencode( $this->targetObj->getPrefixedDBkey() ) . 00304 '&file=' . urlencode( $archiveName ) . 00305 '&token=' . urlencode( $user->getEditToken( $archiveName ) ) ) 00306 ) 00307 ) . 00308 Xml::submitButton( $this->msg( 'revdelete-show-file-submit' )->text() ) . 00309 '</form>' 00310 ); 00311 return; 00312 } 00313 $this->getOutput()->disable(); 00314 # We mustn't allow the output to be Squid cached, otherwise 00315 # if an admin previews a deleted image, and it's cached, then 00316 # a user without appropriate permissions can toddle off and 00317 # nab the image, and Squid will serve it 00318 $this->getRequest()->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); 00319 $this->getRequest()->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); 00320 $this->getRequest()->response()->header( 'Pragma: no-cache' ); 00321 00322 $key = $oimage->getStorageKey(); 00323 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key; 00324 $repo->streamFile( $path ); 00325 } 00326 00330 protected function getList() { 00331 if ( is_null( $this->list ) ) { 00332 $class = $this->typeInfo['list-class']; 00333 $this->list = new $class( $this->getContext(), $this->targetObj, $this->ids ); 00334 } 00335 return $this->list; 00336 } 00337 00342 protected function showForm() { 00343 $UserAllowed = true; 00344 00345 if ( $this->typeName == 'logging' ) { 00346 $this->getOutput()->addWikiMsg( 'logdelete-selected', $this->getLanguage()->formatNum( count($this->ids) ) ); 00347 } else { 00348 $this->getOutput()->addWikiMsg( 'revdelete-selected', 00349 $this->targetObj->getPrefixedText(), count( $this->ids ) ); 00350 } 00351 00352 $this->getOutput()->addHTML( "<ul>" ); 00353 00354 $numRevisions = 0; 00355 // Live revisions... 00356 $list = $this->getList(); 00357 for ( $list->reset(); $list->current(); $list->next() ) { 00358 $item = $list->current(); 00359 if ( !$item->canView() ) { 00360 if( !$this->submitClicked ) { 00361 throw new PermissionsError( 'suppressrevision' ); 00362 } 00363 $UserAllowed = false; 00364 } 00365 $numRevisions++; 00366 $this->getOutput()->addHTML( $item->getHTML() ); 00367 } 00368 00369 if( !$numRevisions ) { 00370 throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); 00371 } 00372 00373 $this->getOutput()->addHTML( "</ul>" ); 00374 // Explanation text 00375 $this->addUsageText(); 00376 00377 // Normal sysops can always see what they did, but can't always change it 00378 if( !$UserAllowed ) return; 00379 00380 // Show form if the user can submit 00381 if( $this->mIsAllowed ) { 00382 $out = Xml::openElement( 'form', array( 'method' => 'post', 00383 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ), 00384 'id' => 'mw-revdel-form-revisions' ) ) . 00385 Xml::fieldset( $this->msg( 'revdelete-legend' )->text() ) . 00386 $this->buildCheckBoxes() . 00387 Xml::openElement( 'table' ) . 00388 "<tr>\n" . 00389 '<td class="mw-label">' . 00390 Xml::label( $this->msg( 'revdelete-log' )->text(), 'wpRevDeleteReasonList' ) . 00391 '</td>' . 00392 '<td class="mw-input">' . 00393 Xml::listDropDown( 'wpRevDeleteReasonList', 00394 $this->msg( 'revdelete-reason-dropdown' )->inContentLanguage()->text(), 00395 $this->msg( 'revdelete-reasonotherlist' )->inContentLanguage()->text(), 00396 '', 'wpReasonDropDown', 1 00397 ) . 00398 '</td>' . 00399 "</tr><tr>\n" . 00400 '<td class="mw-label">' . 00401 Xml::label( $this->msg( 'revdelete-otherreason' )->text(), 'wpReason' ) . 00402 '</td>' . 00403 '<td class="mw-input">' . 00404 Xml::input( 'wpReason', 60, $this->otherReason, array( 'id' => 'wpReason', 'maxlength' => 100 ) ) . 00405 '</td>' . 00406 "</tr><tr>\n" . 00407 '<td></td>' . 00408 '<td class="mw-submit">' . 00409 Xml::submitButton( $this->msg( 'revdelete-submit', $numRevisions )->text(), 00410 array( 'name' => 'wpSubmit' ) ) . 00411 '</td>' . 00412 "</tr>\n" . 00413 Xml::closeElement( 'table' ) . 00414 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) . 00415 Html::hidden( 'target', $this->targetObj->getPrefixedText() ) . 00416 Html::hidden( 'type', $this->typeName ) . 00417 Html::hidden( 'ids', implode( ',', $this->ids ) ) . 00418 Xml::closeElement( 'fieldset' ) . "\n"; 00419 } else { 00420 $out = ''; 00421 } 00422 if( $this->mIsAllowed ) { 00423 $out .= Xml::closeElement( 'form' ) . "\n"; 00424 // Show link to edit the dropdown reasons 00425 if( $this->getUser()->isAllowed( 'editinterface' ) ) { 00426 $title = Title::makeTitle( NS_MEDIAWIKI, 'Revdelete-reason-dropdown' ); 00427 $link = Linker::link( 00428 $title, 00429 $this->msg( 'revdelete-edit-reasonlist' )->escaped(), 00430 array(), 00431 array( 'action' => 'edit' ) 00432 ); 00433 $out .= Xml::tags( 'p', array( 'class' => 'mw-revdel-editreasons' ), $link ) . "\n"; 00434 } 00435 } 00436 $this->getOutput()->addHTML( $out ); 00437 } 00438 00443 protected function addUsageText() { 00444 $this->getOutput()->addWikiMsg( 'revdelete-text' ); 00445 if( $this->getUser()->isAllowed( 'suppressrevision' ) ) { 00446 $this->getOutput()->addWikiMsg( 'revdelete-suppress-text' ); 00447 } 00448 if( $this->mIsAllowed ) { 00449 $this->getOutput()->addWikiMsg( 'revdelete-confirm' ); 00450 } 00451 } 00452 00456 protected function buildCheckBoxes() { 00457 $html = '<table>'; 00458 // If there is just one item, use checkboxes 00459 $list = $this->getList(); 00460 if( $list->length() == 1 ) { 00461 $list->reset(); 00462 $bitfield = $list->current()->getBits(); // existing field 00463 if( $this->submitClicked ) { 00464 $bitfield = $this->extractBitfield( $this->extractBitParams(), $bitfield ); 00465 } 00466 foreach( $this->checks as $item ) { 00467 list( $message, $name, $field ) = $item; 00468 $innerHTML = Xml::checkLabel( $this->msg( $message )->text(), $name, $name, $bitfield & $field ); 00469 if( $field == Revision::DELETED_RESTRICTED ) 00470 $innerHTML = "<b>$innerHTML</b>"; 00471 $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML ); 00472 $html .= "<tr>$line</tr>\n"; 00473 } 00474 // Otherwise, use tri-state radios 00475 } else { 00476 $html .= '<tr>'; 00477 $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-same' )->escaped() . '</th>'; 00478 $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-unset' )->escaped() . '</th>'; 00479 $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-set' )->escaped() . '</th>'; 00480 $html .= "<th></th></tr>\n"; 00481 foreach( $this->checks as $item ) { 00482 list( $message, $name, $field ) = $item; 00483 // If there are several items, use third state by default... 00484 if( $this->submitClicked ) { 00485 $selected = $this->getRequest()->getInt( $name, 0 /* unchecked */ ); 00486 } else { 00487 $selected = -1; // use existing field 00488 } 00489 $line = '<td class="mw-revdel-checkbox">' . Xml::radio( $name, -1, $selected == -1 ) . '</td>'; 00490 $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 0, $selected == 0 ) . '</td>'; 00491 $line .= '<td class="mw-revdel-checkbox">' . Xml::radio( $name, 1, $selected == 1 ) . '</td>'; 00492 $label = $this->msg( $message )->escaped(); 00493 if( $field == Revision::DELETED_RESTRICTED ) { 00494 $label = "<b>$label</b>"; 00495 } 00496 $line .= "<td>$label</td>"; 00497 $html .= "<tr>$line</tr>\n"; 00498 } 00499 } 00500 00501 $html .= '</table>'; 00502 return $html; 00503 } 00504 00510 protected function submit() { 00511 # Check edit token on submission 00512 $token = $this->getRequest()->getVal('wpEditToken'); 00513 if( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) { 00514 $this->getOutput()->addWikiMsg( 'sessionfailure' ); 00515 return false; 00516 } 00517 $bitParams = $this->extractBitParams(); 00518 $listReason = $this->getRequest()->getText( 'wpRevDeleteReasonList', 'other' ); // from dropdown 00519 $comment = $listReason; 00520 if( $comment != 'other' && $this->otherReason != '' ) { 00521 // Entry from drop down menu + additional comment 00522 $comment .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->otherReason; 00523 } elseif( $comment == 'other' ) { 00524 $comment = $this->otherReason; 00525 } 00526 # Can the user set this field? 00527 if( $bitParams[Revision::DELETED_RESTRICTED]==1 && !$this->getUser()->isAllowed('suppressrevision') ) { 00528 throw new PermissionsError( 'suppressrevision' ); 00529 } 00530 # If the save went through, go to success message... 00531 $status = $this->save( $bitParams, $comment, $this->targetObj ); 00532 if ( $status->isGood() ) { 00533 $this->success(); 00534 return true; 00535 # ...otherwise, bounce back to form... 00536 } else { 00537 $this->failure( $status ); 00538 } 00539 return false; 00540 } 00541 00545 protected function success() { 00546 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) ); 00547 $this->getOutput()->wrapWikiMsg( "<span class=\"success\">\n$1\n</span>", $this->typeInfo['success'] ); 00548 $this->list->reloadFromMaster(); 00549 $this->showForm(); 00550 } 00551 00555 protected function failure( $status ) { 00556 $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) ); 00557 $this->getOutput()->addWikiText( $status->getWikiText( $this->typeInfo['failure'] ) ); 00558 $this->showForm(); 00559 } 00560 00566 protected function extractBitParams() { 00567 $bitfield = array(); 00568 foreach( $this->checks as $item ) { 00569 list( /* message */ , $name, $field ) = $item; 00570 $val = $this->getRequest()->getInt( $name, 0 /* unchecked */ ); 00571 if( $val < -1 || $val > 1) { 00572 $val = -1; // -1 for existing value 00573 } 00574 $bitfield[$field] = $val; 00575 } 00576 if( !isset($bitfield[Revision::DELETED_RESTRICTED]) ) { 00577 $bitfield[Revision::DELETED_RESTRICTED] = 0; 00578 } 00579 return $bitfield; 00580 } 00581 00588 public static function extractBitfield( $bitPars, $oldfield ) { 00589 // Build the actual new rev_deleted bitfield 00590 $newBits = 0; 00591 foreach( $bitPars as $const => $val ) { 00592 if( $val == 1 ) { 00593 $newBits |= $const; // $const is the *_deleted const 00594 } elseif( $val == -1 ) { 00595 $newBits |= ($oldfield & $const); // use existing 00596 } 00597 } 00598 return $newBits; 00599 } 00600 00608 protected function save( $bitfield, $reason, $title ) { 00609 return $this->getList()->setVisibility( 00610 array( 'value' => $bitfield, 'comment' => $reason ) 00611 ); 00612 } 00613 } 00614