wfDebug( "Pulling file metadata from cache key $key\n" );
$this->fileExists = $cachedValues['fileExists'];
if ( $this->fileExists ) {
- unset( $cachedValues['version'] );
- unset( $cachedValues['fileExists'] );
- foreach ( $cachedValues as $name => $value ) {
- $this->$name = $value;
- }
+ $this->setProps( $cachedValues );
}
+ $this->dataLoaded = true;
}
if ( $this->dataLoaded ) {
wfIncrStats( 'image_cache_hit' );
}
$decoded = array();
foreach ( $array as $name => $value ) {
- $deprefixedName = substr( $name, $prefixLength );
$decoded[substr( $name, $prefixLength )] = $value;
}
$decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
return;
}
if ( is_null($this->media_type) ||
- $this->mime == 'image/svg' ||
- $this->sha1 == ''
+ $this->mime == 'image/svg'
) {
$this->upgradeRow();
$this->upgraded = true;
wfProfileOut( __METHOD__ );
}
+ /**
+ * Set properties in this object to be equal to those given in the
+ * associative array $info. Only cacheable fields can be set.
+ *
+ * If 'mime' is given, it will be split into major_mime/minor_mime.
+ * If major_mime/minor_mime are given, $this->mime will also be set.
+ */
function setProps( $info ) {
$this->dataLoaded = true;
$fields = $this->getCacheFields( '' );
$dir = $this->getThumbPath();
$urls = array();
foreach ( $files as $file ) {
- $m = array();
# Check that the base file name is part of the thumb name
# This is a basic sanity check to avoid erasing unrelated directories
if ( strpos( $file, $this->getName() ) !== false ) {
return false;
}
+ $reupload = false;
if ( $timestamp === false ) {
$timestamp = $dbw->timestamp();
}
);
if( $dbw->affectedRows() == 0 ) {
+ $reupload = true;
+
# Collision, this is an update of a file
# Insert previous contents into oldimage
$dbw->insertSelect( 'oldimage', 'image',
# Add the log entry
$log = new LogPage( 'upload' );
- $log->addEntry( 'upload', $descTitle, $comment );
+ $action = $reupload ? 'overwrite' : 'upload';
+ $log->addEntry( $action, $descTitle, $comment );
if( $descTitle->exists() ) {
# Create a null revision
$nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
$nullRevision->insertOn( $dbw );
+ $article->updateRevisionOn( $dbw, $nullRevision );
# Invalidate the cache for the description page
$descTitle->invalidateCache();
function getSha1() {
$this->load();
+ // Initialise now if necessary
+ if ( $this->sha1 == '' && $this->fileExists ) {
+ $this->sha1 = File::sha1Base36( $this->getPath() );
+ if ( strval( $this->sha1 ) != '' ) {
+ $dbw = $this->repo->getMasterDB();
+ $dbw->update( 'image',
+ array( 'img_sha1' => $this->sha1 ),
+ array( 'img_name' => $this->getName() ),
+ __METHOD__ );
+ $this->saveToCache();
+ }
+ }
+
return $this->sha1;
}
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
if ( $deleteCurrent ) {
+ $concat = $dbw->buildConcat( array( "img_sha1", $encExt ) );
$where = array( 'img_name' => $this->file->getName() );
$dbw->insertSelect( 'filearchive', 'image',
array(
'fa_storage_group' => $encGroup,
- 'fa_storage_key' => "IF(img_sha1='', '', CONCAT(img_sha1,$encExt))",
-
+ 'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
'fa_deleted_user' => $encUserId,
'fa_deleted_timestamp' => $encTimestamp,
'fa_deleted_reason' => $encReason,
}
if ( count( $oldRels ) ) {
+ $concat = $dbw->buildConcat( array( "oi_sha1", $encExt ) );
$where = array(
'oi_name' => $this->file->getName(),
'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')' );
-
$dbw->insertSelect( 'filearchive', 'oldimage',
array(
'fa_storage_group' => $encGroup,
- 'fa_storage_key' => "IF(oi_sha1='', '', CONCAT(oi_sha1,$encExt))",
-
+ 'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
'fa_deleted_user' => $encUserId,
'fa_deleted_timestamp' => $encTimestamp,
'fa_deleted_reason' => $encReason,
$dbw = $this->file->repo->getMasterDB();
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
if ( $deleteCurrent ) {
- $where = array( 'img_name' => $this->file->getName() );
$dbw->delete( 'image', array( 'img_name' => $this->file->getName() ), __METHOD__ );
}
if ( count( $oldRels ) ) {
$urls = array();
foreach ( $this->srcRels as $srcRel ) {
$urlRel = str_replace( '%2F', '/', rawurlencode( $srcRel ) );
- $urls[] = $this->repo->getZoneUrl( 'public' ) . '/' . $urlRel;
+ $urls[] = $this->file->repo->getZoneUrl( 'public' ) . '/' . $urlRel;
}
SquidUpdate::purge( $urls );
}
if ( strlen( $sha1 ) == 32 && $sha1[0] == '0' ) {
$sha1 = substr( $sha1, 1 );
}
+
+ if( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown'
+ || is_null( $row->fa_minor_mime ) || $row->fa_minor_mime == 'unknown'
+ || is_null( $row->fa_media_type ) || $row->fa_media_type == 'UNKNOWN'
+ || is_null( $row->fa_metadata ) ) {
+ // Refresh our metadata
+ // Required for a new current revision; nice for older ones too. :)
+ $props = RepoGroup::singleton()->getFileProps( $deletedUrl );
+ } else {
+ $props = array(
+ 'minor_mime' => $row->fa_minor_mime,
+ 'major_mime' => $row->fa_major_mime,
+ 'media_type' => $row->fa_media_type,
+ 'metadata' => $row->fa_metadata );
+ }
if ( $first && !$exists ) {
// This revision will be published as the new current version
$destRel = $this->file->getRel();
- $info = $this->file->repo->getFileProps( $deletedUrl );
$insertCurrent = array(
'img_name' => $row->fa_name,
'img_size' => $row->fa_size,
'img_width' => $row->fa_width,
'img_height' => $row->fa_height,
- 'img_metadata' => $row->fa_metadata,
+ 'img_metadata' => $props['metadata'],
'img_bits' => $row->fa_bits,
- 'img_media_type' => $row->fa_media_type,
- 'img_major_mime' => $row->fa_major_mime,
- 'img_minor_mime' => $row->fa_minor_mime,
+ 'img_media_type' => $props['media_type'],
+ 'img_major_mime' => $props['major_mime'],
+ 'img_minor_mime' => $props['minor_mime'],
'img_description' => $row->fa_description,
'img_user' => $row->fa_user,
'img_user_text' => $row->fa_user_text,
'oi_user' => $row->fa_user,
'oi_user_text' => $row->fa_user_text,
'oi_timestamp' => $row->fa_timestamp,
- 'oi_metadata' => $row->fa_metadata,
- 'oi_media_type' => $row->fa_media_type,
- 'oi_major_mime' => $row->fa_major_mime,
- 'oi_minor_mime' => $row->fa_minor_mime,
+ 'oi_metadata' => $props['metadata'],
+ 'oi_media_type' => $props['media_type'],
+ 'oi_major_mime' => $props['major_mime'],
+ 'oi_minor_mime' => $props['minor_mime'],
'oi_deleted' => $row->fa_deleted,
'oi_sha1' => $sha1 );
}