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