MediaWiki
REL1_19
|
00001 <?php 00023 require_once( dirname( __FILE__ ) . '/Maintenance.php' ); 00024 00025 class PurgeDeletedFiles extends Maintenance { 00026 public function __construct() { 00027 parent::__construct(); 00028 $this->mDescription = "Scan the logging table and purge files that where deleted."; 00029 $this->addOption( 'starttime', 'Starting timestamp', false, true ); 00030 $this->addOption( 'endtime', 'Ending timestamp', false, true ); 00031 } 00032 00033 public function execute() { 00034 $this->output( "Purging cache and thumbnails for deleted files...\n" ); 00035 $this->purgeFromLogType( 'delete' ); 00036 $this->output( "...deleted files purged.\n\n" ); 00037 00038 $this->output( "Purging cache and thumbnails for suppressed files...\n" ); 00039 $this->purgeFromLogType( 'suppress' ); 00040 $this->output( "...suppressed files purged.\n" ); 00041 } 00042 00043 protected function purgeFromLogType( $logType ) { 00044 $repo = RepoGroup::singleton()->getLocalRepo(); 00045 $db = $repo->getSlaveDB(); 00046 00047 $conds = array( 00048 'log_namespace' => NS_FILE, 00049 'log_type' => $logType, 00050 'log_action' => array( 'delete', 'revision' ) 00051 ); 00052 $start = $this->getOption( 'starttime' ); 00053 if ( $start ) { 00054 $conds[] = 'log_timestamp >= ' . $db->addQuotes( $db->timestamp( $start ) ); 00055 } 00056 $end = $this->getOption( 'endtime' ); 00057 if ( $end ) { 00058 $conds[] = 'log_timestamp <= ' . $db->addQuotes( $db->timestamp( $end ) ); 00059 } 00060 00061 $res = $db->select( 'logging', array( 'log_title', 'log_timestamp' ), $conds, __METHOD__ ); 00062 foreach ( $res as $row ) { 00063 $file = $repo->newFile( Title::makeTitle( NS_FILE, $row->log_title ) ); 00064 00065 // Purge current version and any versions in oldimage table 00066 $file->purgeCache(); 00067 $file->purgeHistory(); 00068 // Purge items from fileachive table (rows are likely here) 00069 $this->purgeFromArchiveTable( $file ); 00070 00071 $this->output( "Purged file {$row->log_title}; deleted on {$row->log_timestamp}.\n" ); 00072 } 00073 } 00074 00075 protected function purgeFromArchiveTable( LocalFile $file ) { 00076 $db = $file->getRepo()->getSlaveDB(); 00077 $res = $db->select( 'filearchive', 00078 array( 'fa_archive_name' ), 00079 array( 'fa_name' => $file->getName() ), 00080 __METHOD__ 00081 ); 00082 foreach ( $res as $row ) { 00083 $file->purgeOldThumbnails( $row->fa_archive_name ); 00084 } 00085 } 00086 } 00087 00088 $maintClass = "PurgeDeletedFiles"; 00089 require_once( RUN_MAINTENANCE_IF_MAIN );