MediaWiki
REL1_22
|
00001 <?php 00030 abstract class RevDel_List extends RevisionListBase { 00031 function __construct( IContextSource $context, Title $title, array $ids ) { 00032 parent::__construct( $context, $title ); 00033 $this->ids = $ids; 00034 } 00035 00042 public static function getRelationType() { 00043 return null; 00044 } 00045 00052 public static function getRestriction() { 00053 return null; 00054 } 00055 00062 public static function getRevdelConstant() { 00063 return null; 00064 } 00065 00074 public static function suggestTarget( $target, array $ids ) { 00075 return $target; 00076 } 00077 00087 public function setVisibility( $params ) { 00088 $bitPars = $params['value']; 00089 $comment = $params['comment']; 00090 00091 $this->res = false; 00092 $dbw = wfGetDB( DB_MASTER ); 00093 $this->doQuery( $dbw ); 00094 $dbw->begin( __METHOD__ ); 00095 $status = Status::newGood(); 00096 $missing = array_flip( $this->ids ); 00097 $this->clearFileOps(); 00098 $idsForLog = array(); 00099 $authorIds = $authorIPs = array(); 00100 00101 for ( $this->reset(); $this->current(); $this->next() ) { 00102 $item = $this->current(); 00103 unset( $missing[$item->getId()] ); 00104 00105 $oldBits = $item->getBits(); 00106 // Build the actual new rev_deleted bitfield 00107 $newBits = RevisionDeleter::extractBitfield( $bitPars, $oldBits ); 00108 00109 if ( $oldBits == $newBits ) { 00110 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() ); 00111 $status->failCount++; 00112 continue; 00113 } elseif ( $oldBits == 0 && $newBits != 0 ) { 00114 $opType = 'hide'; 00115 } elseif ( $oldBits != 0 && $newBits == 0 ) { 00116 $opType = 'show'; 00117 } else { 00118 $opType = 'modify'; 00119 } 00120 00121 if ( $item->isHideCurrentOp( $newBits ) ) { 00122 // Cannot hide current version text 00123 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() ); 00124 $status->failCount++; 00125 continue; 00126 } 00127 if ( !$item->canView() ) { 00128 // Cannot access this revision 00129 $msg = ( $opType == 'show' ) ? 00130 'revdelete-show-no-access' : 'revdelete-modify-no-access'; 00131 $status->error( $msg, $item->formatDate(), $item->formatTime() ); 00132 $status->failCount++; 00133 continue; 00134 } 00135 // Cannot just "hide from Sysops" without hiding any fields 00136 if ( $newBits == Revision::DELETED_RESTRICTED ) { 00137 $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() ); 00138 $status->failCount++; 00139 continue; 00140 } 00141 00142 // Update the revision 00143 $ok = $item->setBits( $newBits ); 00144 00145 if ( $ok ) { 00146 $idsForLog[] = $item->getId(); 00147 $status->successCount++; 00148 if ( $item->getAuthorId() > 0 ) { 00149 $authorIds[] = $item->getAuthorId(); 00150 } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) { 00151 $authorIPs[] = $item->getAuthorName(); 00152 } 00153 } else { 00154 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() ); 00155 $status->failCount++; 00156 } 00157 } 00158 00159 // Handle missing revisions 00160 foreach ( $missing as $id => $unused ) { 00161 $status->error( 'revdelete-modify-missing', $id ); 00162 $status->failCount++; 00163 } 00164 00165 if ( $status->successCount == 0 ) { 00166 $status->ok = false; 00167 $dbw->rollback( __METHOD__ ); 00168 return $status; 00169 } 00170 00171 // Save success count 00172 $successCount = $status->successCount; 00173 00174 // Move files, if there are any 00175 $status->merge( $this->doPreCommitUpdates() ); 00176 if ( !$status->isOK() ) { 00177 // Fatal error, such as no configured archive directory 00178 $dbw->rollback( __METHOD__ ); 00179 return $status; 00180 } 00181 00182 // Log it 00183 $this->updateLog( array( 00184 'title' => $this->title, 00185 'count' => $successCount, 00186 'newBits' => $newBits, 00187 'oldBits' => $oldBits, 00188 'comment' => $comment, 00189 'ids' => $idsForLog, 00190 'authorIds' => $authorIds, 00191 'authorIPs' => $authorIPs 00192 ) ); 00193 $dbw->commit( __METHOD__ ); 00194 00195 // Clear caches 00196 $status->merge( $this->doPostCommitUpdates() ); 00197 return $status; 00198 } 00199 00204 function reloadFromMaster() { 00205 $dbw = wfGetDB( DB_MASTER ); 00206 $this->res = $this->doQuery( $dbw ); 00207 } 00208 00221 protected function updateLog( $params ) { 00222 // Get the URL param's corresponding DB field 00223 $field = RevisionDeleter::getRelationType( $this->getType() ); 00224 if ( !$field ) { 00225 throw new MWException( "Bad log URL param type!" ); 00226 } 00227 // Put things hidden from sysops in the oversight log 00228 if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) { 00229 $logType = 'suppress'; 00230 } else { 00231 $logType = 'delete'; 00232 } 00233 // Add params for effected page and ids 00234 $logParams = $this->getLogParams( $params ); 00235 // Actually add the deletion log entry 00236 $log = new LogPage( $logType ); 00237 $logid = $log->addEntry( $this->getLogAction(), $params['title'], 00238 $params['comment'], $logParams, $this->getUser() ); 00239 // Allow for easy searching of deletion log items for revision/log items 00240 $log->addRelations( $field, $params['ids'], $logid ); 00241 $log->addRelations( 'target_author_id', $params['authorIds'], $logid ); 00242 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid ); 00243 } 00244 00249 public function getLogAction() { 00250 return 'revision'; 00251 } 00252 00258 public function getLogParams( $params ) { 00259 return array( 00260 $this->getType(), 00261 implode( ',', $params['ids'] ), 00262 "ofield={$params['oldBits']}", 00263 "nfield={$params['newBits']}" 00264 ); 00265 } 00266 00271 public function clearFileOps() { 00272 } 00273 00279 public function doPreCommitUpdates() { 00280 return Status::newGood(); 00281 } 00282 00288 public function doPostCommitUpdates() { 00289 return Status::newGood(); 00290 } 00291 00295 abstract public function getSuppressBit(); 00296 } 00297 00301 abstract class RevDel_Item extends RevisionItemBase { 00308 public function isHideCurrentOp( $newBits ) { 00309 return false; 00310 } 00311 00315 abstract public function getBits(); 00316 00327 abstract public function setBits( $newBits ); 00328 }