2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-09-04 18:13:18 +00:00
|
|
|
* Local file in the wiki's own database
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup FileRepo
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bump this number when serialized cache records may be incompatible.
|
|
|
|
|
*/
|
2008-05-10 19:22:14 +00:00
|
|
|
define( 'MW_FILE_VERSION', 8 );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to represent a local file in the wiki's own database
|
|
|
|
|
*
|
|
|
|
|
* Provides methods to retrieve paths (physical, logical, URL),
|
|
|
|
|
* to generate image thumbnails or for uploading.
|
|
|
|
|
*
|
2007-05-31 01:43:41 +00:00
|
|
|
* Note that only the repo object knows what its file class is called. You should
|
2008-04-14 07:45:50 +00:00
|
|
|
* never name a file class explictly outside of the repo class. Instead use the
|
2007-05-31 01:43:41 +00:00
|
|
|
* repo's factory functions to generate file objects, for example:
|
|
|
|
|
*
|
|
|
|
|
* RepoGroup::singleton()->getLocalRepo()->newFile($title);
|
|
|
|
|
*
|
|
|
|
|
* The convenience functions wfLocalFile() and wfFindFile() should be sufficient
|
|
|
|
|
* in most cases.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup FileRepo
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
class LocalFile extends File {
|
2007-05-30 21:02:32 +00:00
|
|
|
/**#@+
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2010-09-11 09:20:53 +00:00
|
|
|
var
|
2011-05-02 18:48:35 +00:00
|
|
|
$fileExists, # does the file exist on disk? (loadFromXxx)
|
2010-09-11 09:20:53 +00:00
|
|
|
$historyLine, # Number of line to return by nextHistoryLine() (constructor)
|
|
|
|
|
$historyRes, # result of the query for the file's history (nextHistoryLine)
|
2008-01-20 06:48:57 +00:00
|
|
|
$width, # \
|
|
|
|
|
$height, # |
|
|
|
|
|
$bits, # --- returned by getimagesize (loadFromXxx)
|
|
|
|
|
$attr, # /
|
|
|
|
|
$media_type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
|
|
|
|
|
$mime, # MIME type, determined by MimeMagic::guessMimeType
|
|
|
|
|
$major_mime, # Major mime type
|
|
|
|
|
$minor_mime, # Minor mime type
|
|
|
|
|
$size, # Size in bytes (loadFromXxx)
|
|
|
|
|
$metadata, # Handler-specific metadata
|
|
|
|
|
$timestamp, # Upload timestamp
|
|
|
|
|
$sha1, # SHA-1 base 36 content hash
|
|
|
|
|
$user, $user_text, # User, who uploaded the file
|
|
|
|
|
$description, # Description of current revision of the file
|
|
|
|
|
$dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
|
|
|
|
|
$upgraded, # Whether the row was upgraded on load
|
2008-03-15 00:27:57 +00:00
|
|
|
$locked, # True if the image row is locked
|
2009-04-26 11:12:39 +00:00
|
|
|
$missing, # True if file is not present in file system. Not to be cached in memcached
|
2010-09-11 09:20:53 +00:00
|
|
|
$deleted; # Bitfield akin to rev_deleted
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**#@-*/
|
|
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Create a LocalFile from a title
|
|
|
|
|
* Do not call this except from inside a repo class.
|
2008-04-05 12:26:10 +00:00
|
|
|
*
|
|
|
|
|
* Note: $unused param is only here to avoid an E_STRICT
|
2007-05-31 01:43:41 +00:00
|
|
|
*/
|
2008-04-05 12:26:10 +00:00
|
|
|
static function newFromTitle( $title, $repo, $unused = null ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return new self( $title, $repo );
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Create a LocalFile from a title
|
|
|
|
|
* Do not call this except from inside a repo class.
|
|
|
|
|
*/
|
2007-06-05 18:44:49 +00:00
|
|
|
static function newFromRow( $row, $repo ) {
|
2008-12-01 17:14:30 +00:00
|
|
|
$title = Title::makeTitle( NS_FILE, $row->img_name );
|
2007-05-30 21:02:32 +00:00
|
|
|
$file = new self( $title, $repo );
|
|
|
|
|
$file->loadFromRow( $row );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $file;
|
|
|
|
|
}
|
2010-09-04 01:06:34 +00:00
|
|
|
|
2008-05-20 02:58:40 +00:00
|
|
|
/**
|
|
|
|
|
* Create a LocalFile from a SHA-1 key
|
|
|
|
|
* Do not call this except from inside a repo class.
|
2011-02-18 23:56:08 +00:00
|
|
|
* @param $sha1
|
|
|
|
|
* @param $repo LocalRepo
|
|
|
|
|
* @param $timestamp
|
2008-05-20 02:58:40 +00:00
|
|
|
*/
|
|
|
|
|
static function newFromKey( $sha1, $repo, $timestamp = false ) {
|
|
|
|
|
$conds = array( 'img_sha1' => $sha1 );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $timestamp ) {
|
2008-05-20 02:58:40 +00:00
|
|
|
$conds['img_timestamp'] = $timestamp;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-07-25 11:40:52 +00:00
|
|
|
$dbr = $repo->getSlaveDB();
|
|
|
|
|
$row = $dbr->selectRow( 'image', self::selectFields(), $conds, __METHOD__ );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $row ) {
|
2008-05-20 02:58:40 +00:00
|
|
|
return self::newFromRow( $row, $repo );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-04 01:06:34 +00:00
|
|
|
|
2008-05-14 15:11:48 +00:00
|
|
|
/**
|
|
|
|
|
* Fields in the image table
|
|
|
|
|
*/
|
|
|
|
|
static function selectFields() {
|
|
|
|
|
return array(
|
|
|
|
|
'img_name',
|
|
|
|
|
'img_size',
|
|
|
|
|
'img_width',
|
|
|
|
|
'img_height',
|
|
|
|
|
'img_metadata',
|
|
|
|
|
'img_bits',
|
|
|
|
|
'img_media_type',
|
|
|
|
|
'img_major_mime',
|
|
|
|
|
'img_minor_mime',
|
|
|
|
|
'img_description',
|
|
|
|
|
'img_user',
|
|
|
|
|
'img_user_text',
|
|
|
|
|
'img_timestamp',
|
|
|
|
|
'img_sha1',
|
|
|
|
|
);
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
* Do not call this except from inside a repo class.
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function __construct( $title, $repo ) {
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( !is_object( $title ) ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
throw new MWException( __CLASS__ . ' constructor given bogus title.' );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
parent::__construct( $title, $repo );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->metadata = '';
|
|
|
|
|
$this->historyLine = 0;
|
2007-07-07 03:04:20 +00:00
|
|
|
$this->historyRes = null;
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->dataLoaded = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-04 01:06:34 +00:00
|
|
|
* Get the memcached key for the main data for this file, or false if
|
2009-06-17 07:31:00 +00:00
|
|
|
* there is no access to the shared cache.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getCacheKey() {
|
2010-02-07 19:31:24 +00:00
|
|
|
$hashedName = md5( $this->getName() );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
return $this->repo->getSharedCacheKey( 'file', $hashedName );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Try to load file metadata from memcached. Returns true on success.
|
|
|
|
|
*/
|
|
|
|
|
function loadFromCache() {
|
|
|
|
|
global $wgMemc;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$this->dataLoaded = false;
|
|
|
|
|
$key = $this->getCacheKey();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$key ) {
|
2009-04-04 17:28:08 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2007-05-30 21:02:32 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$cachedValues = $wgMemc->get( $key );
|
|
|
|
|
|
|
|
|
|
// Check if the key existed and belongs to this version of MediaWiki
|
2010-02-07 19:31:24 +00:00
|
|
|
if ( isset( $cachedValues['version'] ) && ( $cachedValues['version'] == MW_FILE_VERSION ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
wfDebug( "Pulling file metadata from cache key $key\n" );
|
|
|
|
|
$this->fileExists = $cachedValues['fileExists'];
|
|
|
|
|
if ( $this->fileExists ) {
|
2007-11-19 10:04:18 +00:00
|
|
|
$this->setProps( $cachedValues );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2007-11-19 10:22:29 +00:00
|
|
|
$this->dataLoaded = true;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $this->dataLoaded ) {
|
|
|
|
|
wfIncrStats( 'image_cache_hit' );
|
|
|
|
|
} else {
|
|
|
|
|
wfIncrStats( 'image_cache_miss' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $this->dataLoaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save the file metadata to memcached
|
|
|
|
|
*/
|
|
|
|
|
function saveToCache() {
|
|
|
|
|
global $wgMemc;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->load();
|
|
|
|
|
$key = $this->getCacheKey();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$key ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$fields = $this->getCacheFields( '' );
|
|
|
|
|
$cache = array( 'version' => MW_FILE_VERSION );
|
|
|
|
|
$cache['fileExists'] = $this->fileExists;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $this->fileExists ) {
|
|
|
|
|
foreach ( $fields as $field ) {
|
|
|
|
|
$cache[$field] = $this->$field;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgMemc->set( $key, $cache, 60 * 60 * 24 * 7 ); // A week
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load metadata from the file itself
|
|
|
|
|
*/
|
|
|
|
|
function loadFromFile() {
|
2007-06-19 15:11:20 +00:00
|
|
|
$this->setProps( self::getPropsFromPath( $this->getPath() ) );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCacheFields( $prefix = 'img_' ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
|
2008-01-20 12:48:39 +00:00
|
|
|
'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user', 'user_text', 'description' );
|
2007-05-30 21:02:32 +00:00
|
|
|
static $results = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $prefix == '' ) {
|
|
|
|
|
return $fields;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $results[$prefix] ) ) {
|
|
|
|
|
$prefixedFields = array();
|
|
|
|
|
foreach ( $fields as $field ) {
|
|
|
|
|
$prefixedFields[] = $prefix . $field;
|
|
|
|
|
}
|
|
|
|
|
$results[$prefix] = $prefixedFields;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $results[$prefix];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load file metadata from the DB
|
|
|
|
|
*/
|
|
|
|
|
function loadFromDB() {
|
2007-07-22 14:45:12 +00:00
|
|
|
# Polymorphic function name to distinguish foreign and local fetches
|
|
|
|
|
$fname = get_class( $this ) . '::' . __FUNCTION__;
|
|
|
|
|
wfProfileIn( $fname );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
# Unconditionally set loaded=true, we don't want the accessors constantly rechecking
|
|
|
|
|
$this->dataLoaded = true;
|
|
|
|
|
|
2008-01-29 01:14:50 +00:00
|
|
|
$dbr = $this->repo->getMasterDB();
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
$row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
|
2007-07-22 14:45:12 +00:00
|
|
|
array( 'img_name' => $this->getName() ), $fname );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $row ) {
|
|
|
|
|
$this->loadFromRow( $row );
|
|
|
|
|
} else {
|
|
|
|
|
$this->fileExists = false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
wfProfileOut( $fname );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Decode a row from the database (either object or array) to an array
|
2007-05-30 21:02:32 +00:00
|
|
|
* with timestamps and MIME types decoded, and the field prefix removed.
|
|
|
|
|
*/
|
|
|
|
|
function decodeRow( $row, $prefix = 'img_' ) {
|
|
|
|
|
$array = (array)$row;
|
|
|
|
|
$prefixLength = strlen( $prefix );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
// Sanity check prefix once
|
|
|
|
|
if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
throw new MWException( __METHOD__ . ': incorrect $prefix parameter' );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$decoded = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
foreach ( $array as $name => $value ) {
|
|
|
|
|
$decoded[substr( $name, $prefixLength )] = $value;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( empty( $decoded['major_mime'] ) ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
$decoded['mime'] = 'unknown/unknown';
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
2010-02-07 19:31:24 +00:00
|
|
|
if ( !$decoded['minor_mime'] ) {
|
|
|
|
|
$decoded['minor_mime'] = 'unknown';
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-02-07 19:31:24 +00:00
|
|
|
$decoded['mime'] = $decoded['major_mime'] . '/' . $decoded['minor_mime'];
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
# Trim zero padding from char/binary field
|
|
|
|
|
$decoded['sha1'] = rtrim( $decoded['sha1'], "\0" );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $decoded;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2007-05-30 21:02:32 +00:00
|
|
|
* Load file metadata from a DB result row
|
|
|
|
|
*/
|
|
|
|
|
function loadFromRow( $row, $prefix = 'img_' ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$this->dataLoaded = true;
|
2007-05-30 21:02:32 +00:00
|
|
|
$array = $this->decodeRow( $row, $prefix );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
foreach ( $array as $name => $value ) {
|
|
|
|
|
$this->$name = $value;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->fileExists = true;
|
2008-03-17 19:57:31 +00:00
|
|
|
$this->maybeUpgradeRow();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load file metadata from cache or DB, unless already loaded
|
|
|
|
|
*/
|
|
|
|
|
function load() {
|
|
|
|
|
if ( !$this->dataLoaded ) {
|
|
|
|
|
if ( !$this->loadFromCache() ) {
|
|
|
|
|
$this->loadFromDB();
|
|
|
|
|
$this->saveToCache();
|
|
|
|
|
}
|
|
|
|
|
$this->dataLoaded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Upgrade a row if it needs it
|
|
|
|
|
*/
|
|
|
|
|
function maybeUpgradeRow() {
|
2011-04-16 01:23:15 +00:00
|
|
|
global $wgUpdateCompatibleMetadata;
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
if ( is_null( $this->media_type ) ||
|
2007-08-25 13:54:12 +00:00
|
|
|
$this->mime == 'image/svg'
|
2007-07-22 14:45:12 +00:00
|
|
|
) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->upgradeRow();
|
|
|
|
|
$this->upgraded = true;
|
|
|
|
|
} else {
|
|
|
|
|
$handler = $this->getHandler();
|
2011-04-16 01:23:15 +00:00
|
|
|
if ( $handler ) {
|
|
|
|
|
$validity = $handler->isMetadataValid( $this, $this->metadata );
|
|
|
|
|
if ( $validity === MediaHandler::METADATA_BAD
|
|
|
|
|
|| ( $validity === MediaHandler::METADATA_COMPATIBLE && $wgUpdateCompatibleMetadata )
|
|
|
|
|
) {
|
|
|
|
|
$this->upgradeRow();
|
|
|
|
|
$this->upgraded = true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUpgraded() {
|
|
|
|
|
return $this->upgraded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fix assorted version-related problems with the image row by reloading it from the file
|
|
|
|
|
*/
|
|
|
|
|
function upgradeRow() {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$this->loadFromFile();
|
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
# Don't destroy file info of missing files
|
|
|
|
|
if ( !$this->fileExists ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
|
2009-04-04 17:51:13 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$dbw = $this->repo->getMasterDB();
|
|
|
|
|
list( $major, $minor ) = self::splitMime( $this->mime );
|
|
|
|
|
|
2008-01-29 01:14:50 +00:00
|
|
|
if ( wfReadOnly() ) {
|
2009-04-04 17:51:13 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-01-29 01:14:50 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-02-07 19:31:24 +00:00
|
|
|
wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
$dbw->update( 'image',
|
|
|
|
|
array(
|
|
|
|
|
'img_width' => $this->width,
|
|
|
|
|
'img_height' => $this->height,
|
|
|
|
|
'img_bits' => $this->bits,
|
|
|
|
|
'img_media_type' => $this->media_type,
|
|
|
|
|
'img_major_mime' => $major,
|
|
|
|
|
'img_minor_mime' => $minor,
|
|
|
|
|
'img_metadata' => $this->metadata,
|
2007-07-22 14:45:12 +00:00
|
|
|
'img_sha1' => $this->sha1,
|
2007-05-30 21:02:32 +00:00
|
|
|
), array( 'img_name' => $this->getName() ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->saveToCache();
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-19 10:04:18 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Set properties in this object to be equal to those given in the
|
2007-11-19 10:04:18 +00:00
|
|
|
* associative array $info. Only cacheable fields can be set.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
|
|
|
|
* If 'mime' is given, it will be split into major_mime/minor_mime.
|
2007-11-19 10:04:18 +00:00
|
|
|
* If major_mime/minor_mime are given, $this->mime will also be set.
|
|
|
|
|
*/
|
2007-06-16 02:55:25 +00:00
|
|
|
function setProps( $info ) {
|
|
|
|
|
$this->dataLoaded = true;
|
|
|
|
|
$fields = $this->getCacheFields( '' );
|
|
|
|
|
$fields[] = 'fileExists';
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
foreach ( $fields as $field ) {
|
|
|
|
|
if ( isset( $info[$field] ) ) {
|
|
|
|
|
$this->$field = $info[$field];
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-11 18:56:38 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
// Fix up mime fields
|
|
|
|
|
if ( isset( $info['major_mime'] ) ) {
|
|
|
|
|
$this->mime = "{$info['major_mime']}/{$info['minor_mime']}";
|
|
|
|
|
} elseif ( isset( $info['mime'] ) ) {
|
2010-08-11 18:56:38 +00:00
|
|
|
$this->mime = $info['mime'];
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
list( $this->major_mime, $this->minor_mime ) = self::splitMime( $this->mime );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/** splitMime inherited */
|
|
|
|
|
/** getName inherited */
|
|
|
|
|
/** getTitle inherited */
|
|
|
|
|
/** getURL inherited */
|
|
|
|
|
/** getViewURL inherited */
|
|
|
|
|
/** getPath inherited */
|
2008-03-15 00:27:57 +00:00
|
|
|
/** isVisible inhereted */
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
function isMissing() {
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( $this->missing === null ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
list( $fileExists ) = $this->repo->fileExistsBatch( array( $this->getVirtualUrl() ), FileRepo::FILES_ONLY );
|
|
|
|
|
$this->missing = !$fileExists;
|
|
|
|
|
}
|
|
|
|
|
return $this->missing;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Return the width of the image
|
|
|
|
|
*
|
|
|
|
|
* Returns false on error
|
|
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
public function getWidth( $page = 1 ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->load();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $this->isMultipage() ) {
|
|
|
|
|
$dim = $this->getHandler()->getPageDimensions( $this, $page );
|
|
|
|
|
if ( $dim ) {
|
|
|
|
|
return $dim['width'];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return $this->width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the height of the image
|
|
|
|
|
*
|
|
|
|
|
* Returns false on error
|
|
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
public function getHeight( $page = 1 ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->load();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $this->isMultipage() ) {
|
|
|
|
|
$dim = $this->getHandler()->getPageDimensions( $this, $page );
|
|
|
|
|
if ( $dim ) {
|
|
|
|
|
return $dim['height'];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return $this->height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Returns ID or name of user who uploaded the file
|
|
|
|
|
*
|
|
|
|
|
* @param $type string 'text' or 'id'
|
|
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
function getUser( $type = 'text' ) {
|
2008-01-20 12:17:43 +00:00
|
|
|
$this->load();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $type == 'text' ) {
|
2008-01-20 06:48:57 +00:00
|
|
|
return $this->user_text;
|
2010-09-04 13:48:16 +00:00
|
|
|
} elseif ( $type == 'id' ) {
|
2008-01-20 06:48:57 +00:00
|
|
|
return $this->user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get handler-specific metadata
|
|
|
|
|
*/
|
|
|
|
|
function getMetadata() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->metadata;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-31 20:10:36 +00:00
|
|
|
function getBitDepth() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->bits;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Return the size of the image file, in bytes
|
|
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
public function getSize() {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->load();
|
|
|
|
|
return $this->size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the mime type of the file.
|
|
|
|
|
*/
|
|
|
|
|
function getMimeType() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->mime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the type of the media in the file.
|
|
|
|
|
* Use the value returned by this function with the MEDIATYPE_xxx constants.
|
|
|
|
|
*/
|
|
|
|
|
function getMediaType() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->media_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** canRender inherited */
|
|
|
|
|
/** mustRender inherited */
|
|
|
|
|
/** allowInlineDisplay inherited */
|
|
|
|
|
/** isSafeFile inherited */
|
|
|
|
|
/** isTrustedFile inherited */
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-02 18:48:35 +00:00
|
|
|
* Returns true if the file exists on disk.
|
|
|
|
|
* @return boolean Whether file exist on disk.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
public function exists() {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->load();
|
|
|
|
|
return $this->fileExists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** getTransformScript inherited */
|
|
|
|
|
/** getUnscaledThumb inherited */
|
|
|
|
|
/** thumbName inherited */
|
|
|
|
|
/** createThumb inherited */
|
|
|
|
|
/** transform inherited */
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Fix thumbnail files from 1.4 or before, with extreme prejudice
|
|
|
|
|
*/
|
|
|
|
|
function migrateThumbFile( $thumbName ) {
|
|
|
|
|
$thumbDir = $this->getThumbPath();
|
|
|
|
|
$thumbPath = "$thumbDir/$thumbName";
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( is_dir( $thumbPath ) ) {
|
|
|
|
|
// Directory where file should be
|
|
|
|
|
// This happened occasionally due to broken migration code in 1.5
|
|
|
|
|
// Rename to broken-*
|
|
|
|
|
for ( $i = 0; $i < 100 ; $i++ ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
$broken = $this->repo->getZonePath( 'public' ) . "/broken-$i-$thumbName";
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !file_exists( $broken ) ) {
|
|
|
|
|
rename( $thumbPath, $broken );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Doesn't exist anymore
|
|
|
|
|
clearstatcache();
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( is_file( $thumbDir ) ) {
|
|
|
|
|
// File where directory should be
|
|
|
|
|
unlink( $thumbDir );
|
|
|
|
|
// Doesn't exist anymore
|
|
|
|
|
clearstatcache();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** getHandler inherited */
|
|
|
|
|
/** iconThumb inherited */
|
|
|
|
|
/** getLastError inherited */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all thumbnail names previously generated for this file
|
|
|
|
|
*/
|
|
|
|
|
function getThumbnails() {
|
2008-05-16 20:21:20 +00:00
|
|
|
$this->load();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-16 20:21:20 +00:00
|
|
|
$files = array();
|
|
|
|
|
$dir = $this->getThumbPath();
|
|
|
|
|
|
|
|
|
|
if ( is_dir( $dir ) ) {
|
2010-12-23 21:49:01 +00:00
|
|
|
$handle = opendir( $dir );
|
|
|
|
|
|
|
|
|
|
if ( $handle ) {
|
|
|
|
|
while ( false !== ( $file = readdir( $handle ) ) ) {
|
|
|
|
|
if ( $file { 0 } != '.' ) {
|
|
|
|
|
$files[] = $file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir( $handle );
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-12-23 21:49:01 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refresh metadata in memcached, but don't touch thumbnails or squid
|
|
|
|
|
*/
|
|
|
|
|
function purgeMetadataCache() {
|
2007-06-16 02:55:25 +00:00
|
|
|
$this->loadFromDB();
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->saveToCache();
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->purgeHistory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purge the shared history (OldLocalFile) cache
|
|
|
|
|
*/
|
|
|
|
|
function purgeHistory() {
|
|
|
|
|
global $wgMemc;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
$hashedName = md5( $this->getName() );
|
2009-06-17 09:39:13 +00:00
|
|
|
$oldKey = $this->repo->getSharedCacheKey( 'oldfile', $hashedName );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
if ( $oldKey ) {
|
|
|
|
|
$wgMemc->delete( $oldKey );
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function purgeCache() {
|
2007-05-30 21:02:32 +00:00
|
|
|
// Refresh metadata cache
|
|
|
|
|
$this->purgeMetadataCache();
|
|
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
// Delete thumbnails
|
|
|
|
|
$this->purgeThumbnails();
|
|
|
|
|
|
|
|
|
|
// Purge squid cache for this file
|
2008-03-20 22:00:59 +00:00
|
|
|
SquidUpdate::purge( array( $this->getURL() ) );
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete cached transformed files
|
|
|
|
|
*/
|
|
|
|
|
function purgeThumbnails() {
|
2011-03-20 16:38:08 +00:00
|
|
|
global $wgUseSquid, $wgExcludeFromThumbnailPurge;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
// Delete thumbnails
|
|
|
|
|
$files = $this->getThumbnails();
|
|
|
|
|
$dir = $this->getThumbPath();
|
|
|
|
|
$urls = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
foreach ( $files as $file ) {
|
2011-03-20 16:38:08 +00:00
|
|
|
// Only remove files not in the $wgExcludeFromThumbnailPurge configuration variable
|
|
|
|
|
$ext = pathinfo( "$dir/$file", PATHINFO_EXTENSION );
|
|
|
|
|
if ( in_array( $ext, $wgExcludeFromThumbnailPurge ) ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
# 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 ) {
|
|
|
|
|
$url = $this->getThumbUrl( $file );
|
|
|
|
|
$urls[] = $url;
|
|
|
|
|
@unlink( "$dir/$file" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Purge the squid
|
|
|
|
|
if ( $wgUseSquid ) {
|
2008-03-20 22:00:59 +00:00
|
|
|
SquidUpdate::purge( $urls );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** purgeDescription inherited */
|
|
|
|
|
/** purgeEverything inherited */
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
|
2008-01-20 06:48:57 +00:00
|
|
|
$dbr = $this->repo->getSlaveDB();
|
2010-02-07 19:31:24 +00:00
|
|
|
$tables = array( 'oldimage' );
|
2008-06-08 17:39:24 +00:00
|
|
|
$fields = OldLocalFile::selectFields();
|
2008-12-14 03:53:05 +00:00
|
|
|
$conds = $opts = $join_conds = array();
|
2010-02-07 19:31:24 +00:00
|
|
|
$eq = $inc ? '=' : '';
|
2009-05-24 08:29:10 +00:00
|
|
|
$conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBkey() );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $start ) {
|
2008-12-14 03:53:05 +00:00
|
|
|
$conds[] = "oi_timestamp <$eq " . $dbr->addQuotes( $dbr->timestamp( $start ) );
|
2008-01-20 06:48:57 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $end ) {
|
2008-12-14 03:53:05 +00:00
|
|
|
$conds[] = "oi_timestamp >$eq " . $dbr->addQuotes( $dbr->timestamp( $end ) );
|
2008-01-20 06:48:57 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $limit ) {
|
2008-01-20 06:48:57 +00:00
|
|
|
$opts['LIMIT'] = $limit;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-12-13 19:38:34 +00:00
|
|
|
// Search backwards for time > x queries
|
2010-02-07 19:31:24 +00:00
|
|
|
$order = ( !$start && $end !== null ) ? 'ASC' : 'DESC';
|
2008-12-13 19:38:34 +00:00
|
|
|
$opts['ORDER BY'] = "oi_timestamp $order";
|
2010-02-07 19:31:24 +00:00
|
|
|
$opts['USE INDEX'] = array( 'oldimage' => 'oi_name_timestamp' );
|
|
|
|
|
|
2010-09-04 01:06:34 +00:00
|
|
|
wfRunHooks( 'LocalFile::getHistory', array( &$this, &$tables, &$fields,
|
2008-12-13 19:38:34 +00:00
|
|
|
&$conds, &$opts, &$join_conds ) );
|
2010-02-07 19:31:24 +00:00
|
|
|
|
2008-06-08 17:39:24 +00:00
|
|
|
$res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
|
2008-01-20 06:48:57 +00:00
|
|
|
$r = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2010-04-26 14:44:54 +00:00
|
|
|
if ( $this->repo->oldFileFromRowFactory ) {
|
|
|
|
|
$r[] = call_user_func( $this->repo->oldFileFromRowFactory, $row, $this->repo );
|
|
|
|
|
} else {
|
|
|
|
|
$r[] = OldLocalFile::newFromRow( $row, $this->repo );
|
|
|
|
|
}
|
2008-01-20 06:48:57 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $order == 'ASC' ) {
|
2008-12-13 19:38:34 +00:00
|
|
|
$r = array_reverse( $r ); // make sure it ends up descending
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Return the history of this file, line by line.
|
|
|
|
|
* starts with current version, then old versions.
|
|
|
|
|
* uses $this->historyLine to check which line to return:
|
|
|
|
|
* 0 return line for current version
|
|
|
|
|
* 1 query for old versions, return first one
|
|
|
|
|
* 2, ... return next old version from above query
|
|
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
public function nextHistoryLine() {
|
2008-01-29 01:14:50 +00:00
|
|
|
# Polymorphic function name to distinguish foreign and local fetches
|
|
|
|
|
$fname = get_class( $this ) . '::' . __FUNCTION__;
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$dbr = $this->repo->getSlaveDB();
|
|
|
|
|
|
|
|
|
|
if ( $this->historyLine == 0 ) {// called for the first time, return line from cur
|
2008-04-14 07:45:50 +00:00
|
|
|
$this->historyRes = $dbr->select( 'image',
|
2007-05-30 21:02:32 +00:00
|
|
|
array(
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
'*',
|
2008-03-15 00:27:57 +00:00
|
|
|
"'' AS oi_archive_name",
|
|
|
|
|
'0 as oi_deleted',
|
|
|
|
|
'img_sha1'
|
2007-05-30 21:02:32 +00:00
|
|
|
),
|
|
|
|
|
array( 'img_name' => $this->title->getDBkey() ),
|
2008-01-29 01:14:50 +00:00
|
|
|
$fname
|
2007-05-30 21:02:32 +00:00
|
|
|
);
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( 0 == $dbr->numRows( $this->historyRes ) ) {
|
2007-07-07 03:04:20 +00:00
|
|
|
$this->historyRes = null;
|
2010-02-07 19:31:24 +00:00
|
|
|
return false;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-02-07 19:31:24 +00:00
|
|
|
} elseif ( $this->historyLine == 1 ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$this->historyRes = $dbr->select( 'oldimage', '*',
|
2007-05-30 21:02:32 +00:00
|
|
|
array( 'oi_name' => $this->title->getDBkey() ),
|
2008-01-29 01:14:50 +00:00
|
|
|
$fname,
|
2007-05-30 21:02:32 +00:00
|
|
|
array( 'ORDER BY' => 'oi_timestamp DESC' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$this->historyLine ++;
|
|
|
|
|
|
|
|
|
|
return $dbr->fetchObject( $this->historyRes );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the history pointer to the first element of the history
|
|
|
|
|
*/
|
2010-02-07 19:31:24 +00:00
|
|
|
public function resetHistory() {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->historyLine = 0;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
if ( !is_null( $this->historyRes ) ) {
|
2007-07-07 03:04:20 +00:00
|
|
|
$this->historyRes = null;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** getFullPath inherited */
|
|
|
|
|
/** getHashPath inherited */
|
|
|
|
|
/** getRel inherited */
|
|
|
|
|
/** getUrlRel inherited */
|
2007-07-22 14:45:12 +00:00
|
|
|
/** getArchiveRel inherited */
|
|
|
|
|
/** getThumbRel inherited */
|
2007-05-30 21:02:32 +00:00
|
|
|
/** getArchivePath inherited */
|
|
|
|
|
/** getThumbPath inherited */
|
|
|
|
|
/** getArchiveUrl inherited */
|
|
|
|
|
/** getThumbUrl inherited */
|
|
|
|
|
/** getArchiveVirtualUrl inherited */
|
|
|
|
|
/** getThumbVirtualUrl inherited */
|
|
|
|
|
/** isHashed inherited */
|
|
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
/**
|
|
|
|
|
* Upload a file and record it in the DB
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $srcPath String: source path or virtual URL
|
|
|
|
|
* @param $comment String: upload description
|
|
|
|
|
* @param $pageText String: text to use for the new description page,
|
|
|
|
|
* if a new description page is created
|
|
|
|
|
* @param $flags Integer: flags for publish()
|
|
|
|
|
* @param $props Array: File properties, if known. This can be used to reduce the
|
|
|
|
|
* upload time when uploading virtual URLs for which the file info
|
|
|
|
|
* is already known
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $timestamp String: timestamp for img_timestamp, or false to use the current time
|
|
|
|
|
* @param $user Mixed: User object or null to use $wgUser
|
2007-06-16 02:55:25 +00:00
|
|
|
*
|
2007-07-22 14:45:12 +00:00
|
|
|
* @return FileRepoStatus object. On success, the value member contains the
|
2008-04-14 07:45:50 +00:00
|
|
|
* archive name, or an empty string if it was a new file.
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
2008-08-27 17:38:33 +00:00
|
|
|
function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->lock();
|
|
|
|
|
$status = $this->publish( $srcPath, $flags );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
if ( $status->ok ) {
|
2008-08-27 17:38:33 +00:00
|
|
|
if ( !$this->recordUpload2( $status->value, $comment, $pageText, $props, $timestamp, $user ) ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$status->fatal( 'filenotfound', $srcPath );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->unlock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Record a file upload in the upload log and the image table
|
|
|
|
|
*/
|
2011-04-02 16:49:47 +00:00
|
|
|
function recordUpload2(
|
|
|
|
|
$oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null
|
|
|
|
|
) {
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( is_null( $user ) ) {
|
2008-08-27 17:38:33 +00:00
|
|
|
global $wgUser;
|
2010-09-04 01:06:34 +00:00
|
|
|
$user = $wgUser;
|
2008-08-27 17:38:33 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
$dbw = $this->repo->getMasterDB();
|
2008-09-05 04:14:15 +00:00
|
|
|
$dbw->begin();
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
if ( !$props ) {
|
|
|
|
|
$props = $this->repo->getFileProps( $this->getVirtualUrl() );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2011-04-02 16:49:47 +00:00
|
|
|
if ( $timestamp === false ) {
|
|
|
|
|
$timestamp = $dbw->timestamp();
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 12:48:39 +00:00
|
|
|
$props['description'] = $comment;
|
2008-08-27 17:38:33 +00:00
|
|
|
$props['user'] = $user->getId();
|
|
|
|
|
$props['user_text'] = $user->getName();
|
2011-04-02 16:49:47 +00:00
|
|
|
$props['timestamp'] = wfTimestamp( TS_MW, $timestamp ); // DB -> TS_MW
|
2007-06-16 02:55:25 +00:00
|
|
|
$this->setProps( $props );
|
|
|
|
|
|
2010-08-31 11:12:33 +00:00
|
|
|
# Delete thumbnails
|
2007-06-16 02:55:25 +00:00
|
|
|
$this->purgeThumbnails();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-08-31 11:12:33 +00:00
|
|
|
# The file is already on its final location, remove it from the squid cache
|
2008-03-20 22:00:59 +00:00
|
|
|
SquidUpdate::purge( array( $this->getURL() ) );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2010-08-31 11:12:33 +00:00
|
|
|
# Fail now if the file isn't there
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->fileExists ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
wfDebug( __METHOD__ . ": File " . $this->getPath() . " went missing!\n" );
|
2007-05-30 21:02:32 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-15 19:52:28 +00:00
|
|
|
$reupload = false;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
# Test to see if the row exists using INSERT IGNORE
|
|
|
|
|
# This avoids race conditions by locking the row until the commit, and also
|
|
|
|
|
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
|
|
|
|
|
$dbw->insert( 'image',
|
|
|
|
|
array(
|
|
|
|
|
'img_name' => $this->getName(),
|
2010-09-04 13:48:16 +00:00
|
|
|
'img_size' => $this->size,
|
2007-05-30 21:02:32 +00:00
|
|
|
'img_width' => intval( $this->width ),
|
|
|
|
|
'img_height' => intval( $this->height ),
|
|
|
|
|
'img_bits' => $this->bits,
|
|
|
|
|
'img_media_type' => $this->media_type,
|
2007-06-16 02:55:25 +00:00
|
|
|
'img_major_mime' => $this->major_mime,
|
|
|
|
|
'img_minor_mime' => $this->minor_mime,
|
2007-05-30 21:02:32 +00:00
|
|
|
'img_timestamp' => $timestamp,
|
2007-06-16 02:55:25 +00:00
|
|
|
'img_description' => $comment,
|
2008-08-27 17:38:33 +00:00
|
|
|
'img_user' => $user->getId(),
|
|
|
|
|
'img_user_text' => $user->getName(),
|
2007-05-30 21:02:32 +00:00
|
|
|
'img_metadata' => $this->metadata,
|
2007-07-22 14:45:12 +00:00
|
|
|
'img_sha1' => $this->sha1
|
2007-05-30 21:02:32 +00:00
|
|
|
),
|
|
|
|
|
__METHOD__,
|
|
|
|
|
'IGNORE'
|
|
|
|
|
);
|
|
|
|
|
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( $dbw->affectedRows() == 0 ) {
|
2007-08-15 19:52:28 +00:00
|
|
|
$reupload = true;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
# Collision, this is an update of a file
|
|
|
|
|
# Insert previous contents into oldimage
|
|
|
|
|
$dbw->insertSelect( 'oldimage', 'image',
|
|
|
|
|
array(
|
|
|
|
|
'oi_name' => 'img_name',
|
|
|
|
|
'oi_archive_name' => $dbw->addQuotes( $oldver ),
|
|
|
|
|
'oi_size' => 'img_size',
|
|
|
|
|
'oi_width' => 'img_width',
|
|
|
|
|
'oi_height' => 'img_height',
|
|
|
|
|
'oi_bits' => 'img_bits',
|
|
|
|
|
'oi_timestamp' => 'img_timestamp',
|
|
|
|
|
'oi_description' => 'img_description',
|
|
|
|
|
'oi_user' => 'img_user',
|
|
|
|
|
'oi_user_text' => 'img_user_text',
|
2007-07-22 14:45:12 +00:00
|
|
|
'oi_metadata' => 'img_metadata',
|
|
|
|
|
'oi_media_type' => 'img_media_type',
|
|
|
|
|
'oi_major_mime' => 'img_major_mime',
|
|
|
|
|
'oi_minor_mime' => 'img_minor_mime',
|
2008-03-15 00:27:57 +00:00
|
|
|
'oi_sha1' => 'img_sha1'
|
2007-05-30 21:02:32 +00:00
|
|
|
), array( 'img_name' => $this->getName() ), __METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Update the current image row
|
|
|
|
|
$dbw->update( 'image',
|
|
|
|
|
array( /* SET */
|
|
|
|
|
'img_size' => $this->size,
|
|
|
|
|
'img_width' => intval( $this->width ),
|
|
|
|
|
'img_height' => intval( $this->height ),
|
|
|
|
|
'img_bits' => $this->bits,
|
|
|
|
|
'img_media_type' => $this->media_type,
|
2007-06-16 02:55:25 +00:00
|
|
|
'img_major_mime' => $this->major_mime,
|
|
|
|
|
'img_minor_mime' => $this->minor_mime,
|
2007-05-30 21:02:32 +00:00
|
|
|
'img_timestamp' => $timestamp,
|
2007-06-16 02:55:25 +00:00
|
|
|
'img_description' => $comment,
|
2008-08-27 17:38:33 +00:00
|
|
|
'img_user' => $user->getId(),
|
|
|
|
|
'img_user_text' => $user->getName(),
|
2007-05-30 21:02:32 +00:00
|
|
|
'img_metadata' => $this->metadata,
|
2007-07-22 14:45:12 +00:00
|
|
|
'img_sha1' => $this->sha1
|
2007-05-30 21:02:32 +00:00
|
|
|
), array( /* WHERE */
|
|
|
|
|
'img_name' => $this->getName()
|
|
|
|
|
), __METHOD__
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
# This is a new file
|
|
|
|
|
# Update the image count
|
|
|
|
|
$site_stats = $dbw->tableName( 'site_stats' );
|
|
|
|
|
$dbw->query( "UPDATE $site_stats SET ss_images=ss_images+1", __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$descTitle = $this->getTitle();
|
2008-12-15 22:02:01 +00:00
|
|
|
$article = new ImagePage( $descTitle );
|
2008-12-15 23:51:28 +00:00
|
|
|
$article->setFile( $this );
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
# Add the log entry
|
|
|
|
|
$log = new LogPage( 'upload' );
|
2007-08-15 19:52:28 +00:00
|
|
|
$action = $reupload ? 'overwrite' : 'upload';
|
2008-08-27 17:38:33 +00:00
|
|
|
$log->addEntry( $action, $descTitle, $comment, array(), $user );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( $descTitle->exists() ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
# Create a null revision
|
2008-07-27 21:50:35 +00:00
|
|
|
$latest = $descTitle->getLatestRevID();
|
2010-09-04 13:48:16 +00:00
|
|
|
$nullRevision = Revision::newNullRevision(
|
|
|
|
|
$dbw,
|
|
|
|
|
$descTitle->getArticleId(),
|
|
|
|
|
$log->getRcComment(),
|
|
|
|
|
false
|
|
|
|
|
);
|
2008-05-17 15:53:58 +00:00
|
|
|
$nullRevision->insertOn( $dbw );
|
2010-09-04 01:06:34 +00:00
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $user ) );
|
2007-08-19 16:34:45 +00:00
|
|
|
$article->updateRevisionOn( $dbw, $nullRevision );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
# Invalidate the cache for the description page
|
|
|
|
|
$descTitle->invalidateCache();
|
|
|
|
|
$descTitle->purgeSquid();
|
|
|
|
|
} else {
|
2010-08-31 11:12:33 +00:00
|
|
|
# New file; create the description page.
|
|
|
|
|
# There's already a log entry, so don't make a second RC entry
|
|
|
|
|
# Squid and file cache for the description page are purged by doEdit.
|
2008-12-31 17:25:08 +00:00
|
|
|
$article->doEdit( $pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Commit the transaction now, in case something goes wrong later
|
|
|
|
|
# The most important thing is that files don't get lost, especially archives
|
2009-12-14 23:05:35 +00:00
|
|
|
$dbw->commit();
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2010-08-31 11:12:33 +00:00
|
|
|
# Save to cache and purge the squid
|
|
|
|
|
# We shall not saveToCache before the commit since otherwise
|
|
|
|
|
# in case of a rollback there is an usable file from memcached
|
|
|
|
|
# which in fact doesn't really exist (bug 24978)
|
|
|
|
|
$this->saveToCache();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-08-31 13:16:42 +00:00
|
|
|
# Hooks, hooks, the magic of hooks...
|
|
|
|
|
wfRunHooks( 'FileUpload', array( $this, $reupload, $descTitle->exists() ) );
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
# Invalidate cache for all pages using this file
|
|
|
|
|
$update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
|
|
|
|
|
$update->doUpdate();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-04-12 18:06:57 +00:00
|
|
|
# Invalidate cache for all pages that redirects on this page
|
|
|
|
|
$redirs = $this->getTitle()->getRedirectsHere();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $redirs as $redir ) {
|
2008-04-12 18:06:57 +00:00
|
|
|
$update = new HTMLCacheUpdate( $redir, 'imagelinks' );
|
|
|
|
|
$update->doUpdate();
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Move or copy a file to its public location. If a file exists at the
|
2010-04-16 15:20:12 +00:00
|
|
|
* destination, move it to an archive. Returns a FileRepoStatus object with
|
|
|
|
|
* the archive name in the "value" member on success.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* The archive name should be passed through to recordUpload for database
|
|
|
|
|
* registration.
|
|
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $srcPath String: local filesystem path to the source image
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $flags Integer: a bitwise combination of:
|
2011-04-07 20:19:44 +00:00
|
|
|
* File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
|
|
|
|
|
* @param $dstArchiveName string File name if the file is to be published
|
|
|
|
|
* into the archive
|
2007-07-22 14:45:12 +00:00
|
|
|
* @return FileRepoStatus object. On success, the value member contains the
|
2008-04-14 07:45:50 +00:00
|
|
|
* archive name, or an empty string if it was a new file.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-04-07 20:19:44 +00:00
|
|
|
function publish( $srcPath, $flags = 0, $dstArchiveName = null ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->lock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2011-04-07 20:19:44 +00:00
|
|
|
if ( $dstArchiveName ) {
|
|
|
|
|
$dstRel = 'archive/' . $this->getHashPath() . $dstArchiveName;
|
|
|
|
|
} else {
|
|
|
|
|
$dstRel = $this->getRel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$archiveName = wfTimestamp( TS_MW ) . '!'. $this->getName();
|
2007-06-16 02:55:25 +00:00
|
|
|
$archiveRel = 'archive/' . $this->getHashPath() . $archiveName;
|
2007-05-30 21:02:32 +00:00
|
|
|
$flags = $flags & File::DELETE_SOURCE ? LocalRepo::DELETE_SOURCE : 0;
|
2007-06-16 02:55:25 +00:00
|
|
|
$status = $this->repo->publish( $srcPath, $dstRel, $archiveRel, $flags );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $status->value == 'new' ) {
|
|
|
|
|
$status->value = '';
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
2007-07-22 14:45:12 +00:00
|
|
|
$status->value = $archiveName;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->unlock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** getLinksTo inherited */
|
|
|
|
|
/** getExifData inherited */
|
|
|
|
|
/** isLocal inherited */
|
|
|
|
|
/** wasDeleted inherited */
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
/**
|
|
|
|
|
* Move file to the new title
|
|
|
|
|
*
|
|
|
|
|
* Move current, old version and all thumbnails
|
|
|
|
|
* to the new filename. Old file is deleted.
|
|
|
|
|
*
|
|
|
|
|
* Cache purging is done; checks for validity
|
|
|
|
|
* and logging are caller's responsibility
|
|
|
|
|
*
|
|
|
|
|
* @param $target Title New file name
|
|
|
|
|
* @return FileRepoStatus object.
|
|
|
|
|
*/
|
|
|
|
|
function move( $target ) {
|
2008-07-06 20:39:11 +00:00
|
|
|
wfDebugLog( 'imagemove', "Got request to move {$this->name} to " . $target->getText() );
|
2008-05-03 13:09:34 +00:00
|
|
|
$this->lock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-07-04 13:04:03 +00:00
|
|
|
$batch = new LocalFileMoveBatch( $this, $target );
|
2008-05-03 13:09:34 +00:00
|
|
|
$batch->addCurrent();
|
|
|
|
|
$batch->addOlds();
|
|
|
|
|
|
|
|
|
|
$status = $batch->execute();
|
2008-07-06 20:39:11 +00:00
|
|
|
wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
$this->purgeEverything();
|
|
|
|
|
$this->unlock();
|
|
|
|
|
|
2008-05-07 15:03:18 +00:00
|
|
|
if ( $status->isOk() ) {
|
|
|
|
|
// Now switch the object
|
|
|
|
|
$this->title = $target;
|
|
|
|
|
// Force regeneration of the name and hashpath
|
|
|
|
|
unset( $this->name );
|
|
|
|
|
unset( $this->hashPath );
|
|
|
|
|
// Purge the new image
|
|
|
|
|
$this->purgeEverything();
|
|
|
|
|
}
|
2010-09-04 01:06:34 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Delete all versions of the file.
|
|
|
|
|
*
|
|
|
|
|
* Moves the files into an archive directory (or deletes them)
|
|
|
|
|
* and removes the database rows.
|
|
|
|
|
*
|
|
|
|
|
* Cache purging is done; logging is caller's responsibility.
|
|
|
|
|
*
|
|
|
|
|
* @param $reason
|
2008-03-15 00:27:57 +00:00
|
|
|
* @param $suppress
|
2007-07-22 14:45:12 +00:00
|
|
|
* @return FileRepoStatus object.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-03-15 00:27:57 +00:00
|
|
|
function delete( $reason, $suppress = false ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->lock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
$batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
|
2007-07-22 14:45:12 +00:00
|
|
|
$batch->addCurrent();
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
# Get old version relative paths
|
|
|
|
|
$dbw = $this->repo->getMasterDB();
|
|
|
|
|
$result = $dbw->select( 'oldimage',
|
|
|
|
|
array( 'oi_archive_name' ),
|
|
|
|
|
array( 'oi_name' => $this->getName() ) );
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $result as $row ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$batch->addOld( $row->oi_archive_name );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
$status = $batch->execute();
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $status->ok ) {
|
|
|
|
|
// Update site_stats
|
|
|
|
|
$site_stats = $dbw->tableName( 'site_stats' );
|
|
|
|
|
$dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", __METHOD__ );
|
|
|
|
|
$this->purgeEverything();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->unlock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete an old version of the file.
|
|
|
|
|
*
|
|
|
|
|
* Moves the file into an archive directory (or deletes it)
|
|
|
|
|
* and removes the database row.
|
|
|
|
|
*
|
|
|
|
|
* Cache purging is done; logging is caller's responsibility.
|
|
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $archiveName String
|
|
|
|
|
* @param $reason String
|
|
|
|
|
* @param $suppress Boolean
|
2009-07-20 05:19:40 +00:00
|
|
|
* @throws MWException or FSException on database or file store failure
|
2007-07-22 14:45:12 +00:00
|
|
|
* @return FileRepoStatus object.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2010-09-04 13:48:16 +00:00
|
|
|
function deleteOld( $archiveName, $reason, $suppress = false ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->lock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
$batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
|
2007-07-22 14:45:12 +00:00
|
|
|
$batch->addOld( $archiveName );
|
|
|
|
|
$status = $batch->execute();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->unlock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $status->ok ) {
|
|
|
|
|
$this->purgeDescription();
|
|
|
|
|
$this->purgeHistory();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-01 19:50:25 +00:00
|
|
|
/**
|
2007-05-30 21:02:32 +00:00
|
|
|
* Restore all or specified deleted revisions to the given file.
|
|
|
|
|
* Permissions and logging are left to the caller.
|
|
|
|
|
*
|
|
|
|
|
* May throw database exceptions on error.
|
|
|
|
|
*
|
2007-10-01 19:50:25 +00:00
|
|
|
* @param $versions set of record ids of deleted items to restore,
|
|
|
|
|
* or empty to restore all revisions.
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $unsuppress Boolean
|
2007-07-22 14:45:12 +00:00
|
|
|
* @return FileRepoStatus
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-10-01 19:50:25 +00:00
|
|
|
function restore( $versions = array(), $unsuppress = false ) {
|
2008-03-15 00:27:57 +00:00
|
|
|
$batch = new LocalFileRestoreBatch( $this, $unsuppress );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-10-01 19:50:25 +00:00
|
|
|
if ( !$versions ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$batch->addAll();
|
|
|
|
|
} else {
|
2007-10-01 19:50:25 +00:00
|
|
|
$batch->addIds( $versions );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$status = $batch->execute();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2011-02-04 20:54:11 +00:00
|
|
|
if ( !$status->isGood() ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$cleanupStatus = $batch->cleanup();
|
|
|
|
|
$cleanupStatus->successCount = 0;
|
|
|
|
|
$cleanupStatus->failCount = 0;
|
|
|
|
|
$status->merge( $cleanupStatus );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** isMultipage inherited */
|
|
|
|
|
/** pageCount inherited */
|
|
|
|
|
/** scaleHeight inherited */
|
|
|
|
|
/** getImageSize inherited */
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-03-02 21:06:54 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL of the file description page.
|
|
|
|
|
*/
|
|
|
|
|
function getDescriptionUrl() {
|
|
|
|
|
return $this->title->getLocalUrl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTML text of the description page
|
|
|
|
|
* This is not used by ImagePage for local files, since (among other things)
|
|
|
|
|
* it skips the parser cache.
|
|
|
|
|
*/
|
|
|
|
|
function getDescriptionText() {
|
|
|
|
|
global $wgParser;
|
|
|
|
|
$revision = Revision::newFromTitle( $this->title );
|
|
|
|
|
if ( !$revision ) return false;
|
|
|
|
|
$text = $revision->getText();
|
|
|
|
|
if ( !$text ) return false;
|
|
|
|
|
$pout = $wgParser->parse( $text, $this->title, new ParserOptions() );
|
|
|
|
|
return $pout->getText();
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
function getDescription() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
function getTimestamp() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->timestamp;
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
function getSha1() {
|
|
|
|
|
$this->load();
|
2007-08-25 13:54:12 +00:00
|
|
|
// Initialise now if necessary
|
|
|
|
|
if ( $this->sha1 == '' && $this->fileExists ) {
|
|
|
|
|
$this->sha1 = File::sha1Base36( $this->getPath() );
|
2008-10-12 17:07:09 +00:00
|
|
|
if ( !wfReadOnly() && strval( $this->sha1 ) != '' ) {
|
2007-08-25 13:54:12 +00:00
|
|
|
$dbw = $this->repo->getMasterDB();
|
2008-04-14 07:45:50 +00:00
|
|
|
$dbw->update( 'image',
|
2007-08-25 13:54:12 +00:00
|
|
|
array( 'img_sha1' => $this->sha1 ),
|
|
|
|
|
array( 'img_name' => $this->getName() ),
|
|
|
|
|
__METHOD__ );
|
|
|
|
|
$this->saveToCache();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $this->sha1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start a transaction and lock the image for update
|
|
|
|
|
* Increments a reference counter if the lock is already held
|
|
|
|
|
* @return boolean True if the image exists, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
function lock() {
|
|
|
|
|
$dbw = $this->repo->getMasterDB();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( !$this->locked ) {
|
|
|
|
|
$dbw->begin();
|
|
|
|
|
$this->locked++;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $dbw->selectField( 'image', '1', array( 'img_name' => $this->getName() ), __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Decrement the lock reference count. If the reference count is reduced to zero, commits
|
2007-07-22 14:45:12 +00:00
|
|
|
* the transaction and thereby releases the image lock.
|
|
|
|
|
*/
|
|
|
|
|
function unlock() {
|
|
|
|
|
if ( $this->locked ) {
|
|
|
|
|
--$this->locked;
|
|
|
|
|
if ( !$this->locked ) {
|
|
|
|
|
$dbw = $this->repo->getMasterDB();
|
|
|
|
|
$dbw->commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Roll back the DB transaction and mark the image unlocked
|
|
|
|
|
*/
|
|
|
|
|
function unlockAndRollback() {
|
|
|
|
|
$this->locked = false;
|
|
|
|
|
$dbw = $this->repo->getMasterDB();
|
|
|
|
|
$dbw->rollback();
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
} // LocalFile class
|
|
|
|
|
|
2010-09-04 13:48:16 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2007-07-22 14:45:12 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2007-07-22 14:45:12 +00:00
|
|
|
* Helper class for file deletion
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup FileRepo
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
class LocalFileDeleteBatch {
|
2011-02-18 23:56:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var LocalFile
|
|
|
|
|
*/
|
|
|
|
|
var $file;
|
|
|
|
|
|
|
|
|
|
var $reason, $srcRels = array(), $archiveUrls = array(), $deletionBatch, $suppress;
|
2007-07-22 14:45:12 +00:00
|
|
|
var $status;
|
|
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
function __construct( File $file, $reason = '', $suppress = false ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->file = $file;
|
|
|
|
|
$this->reason = $reason;
|
2008-03-15 00:27:57 +00:00
|
|
|
$this->suppress = $suppress;
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->status = $file->repo->newGood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addCurrent() {
|
|
|
|
|
$this->srcRels['.'] = $this->file->getRel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addOld( $oldName ) {
|
|
|
|
|
$this->srcRels[$oldName] = $this->file->getArchiveRel( $oldName );
|
|
|
|
|
$this->archiveUrls[] = $this->file->getArchiveUrl( $oldName );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getOldRels() {
|
|
|
|
|
if ( !isset( $this->srcRels['.'] ) ) {
|
|
|
|
|
$oldRels =& $this->srcRels;
|
|
|
|
|
$deleteCurrent = false;
|
|
|
|
|
} else {
|
|
|
|
|
$oldRels = $this->srcRels;
|
|
|
|
|
unset( $oldRels['.'] );
|
|
|
|
|
$deleteCurrent = true;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return array( $oldRels, $deleteCurrent );
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 03:31:15 +00:00
|
|
|
protected function getHashes() {
|
2007-07-22 14:45:12 +00:00
|
|
|
$hashes = array();
|
|
|
|
|
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $deleteCurrent ) {
|
|
|
|
|
$hashes['.'] = $this->file->getSha1();
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( count( $oldRels ) ) {
|
|
|
|
|
$dbw = $this->file->repo->getMasterDB();
|
2010-09-04 13:48:16 +00:00
|
|
|
$res = $dbw->select(
|
|
|
|
|
'oldimage',
|
|
|
|
|
array( 'oi_archive_name', 'oi_sha1' ),
|
|
|
|
|
'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')',
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( rtrim( $row->oi_sha1, "\0" ) === '' ) {
|
|
|
|
|
// Get the hash from the file
|
|
|
|
|
$oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
|
|
|
|
|
$props = $this->file->repo->getFileProps( $oldUrl );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $props['fileExists'] ) {
|
|
|
|
|
// Upgrade the oldimage row
|
2008-04-14 07:45:50 +00:00
|
|
|
$dbw->update( 'oldimage',
|
2007-07-22 14:45:12 +00:00
|
|
|
array( 'oi_sha1' => $props['sha1'] ),
|
|
|
|
|
array( 'oi_name' => $this->file->getName(), 'oi_archive_name' => $row->oi_archive_name ),
|
|
|
|
|
__METHOD__ );
|
|
|
|
|
$hashes[$row->oi_archive_name] = $props['sha1'];
|
|
|
|
|
} else {
|
|
|
|
|
$hashes[$row->oi_archive_name] = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$hashes[$row->oi_archive_name] = $row->oi_sha1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$missing = array_diff_key( $this->srcRels, $hashes );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
foreach ( $missing as $name => $rel ) {
|
|
|
|
|
$this->status->error( 'filedelete-old-unregistered', $name );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
foreach ( $hashes as $name => $hash ) {
|
|
|
|
|
if ( !$hash ) {
|
|
|
|
|
$this->status->error( 'filedelete-missing', $this->srcRels[$name] );
|
|
|
|
|
unset( $hashes[$name] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $hashes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doDBInserts() {
|
|
|
|
|
global $wgUser;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$dbw = $this->file->repo->getMasterDB();
|
|
|
|
|
$encTimestamp = $dbw->addQuotes( $dbw->timestamp() );
|
2008-05-22 16:39:43 +00:00
|
|
|
$encUserId = $dbw->addQuotes( $wgUser->getId() );
|
2007-07-22 14:45:12 +00:00
|
|
|
$encReason = $dbw->addQuotes( $this->reason );
|
|
|
|
|
$encGroup = $dbw->addQuotes( 'deleted' );
|
|
|
|
|
$ext = $this->file->getExtension();
|
|
|
|
|
$dotExt = $ext === '' ? '' : ".$ext";
|
|
|
|
|
$encExt = $dbw->addQuotes( $dotExt );
|
|
|
|
|
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
// Bitfields to further suppress the content
|
|
|
|
|
if ( $this->suppress ) {
|
|
|
|
|
$bitfield = 0;
|
|
|
|
|
// This should be 15...
|
|
|
|
|
$bitfield |= Revision::DELETED_TEXT;
|
|
|
|
|
$bitfield |= Revision::DELETED_COMMENT;
|
|
|
|
|
$bitfield |= Revision::DELETED_USER;
|
|
|
|
|
$bitfield |= Revision::DELETED_RESTRICTED;
|
|
|
|
|
} else {
|
|
|
|
|
$bitfield = 'oi_deleted';
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
if ( $deleteCurrent ) {
|
2007-09-23 22:23:01 +00:00
|
|
|
$concat = $dbw->buildConcat( array( "img_sha1", $encExt ) );
|
2007-07-22 14:45:12 +00:00
|
|
|
$where = array( 'img_name' => $this->file->getName() );
|
|
|
|
|
$dbw->insertSelect( 'filearchive', 'image',
|
|
|
|
|
array(
|
|
|
|
|
'fa_storage_group' => $encGroup,
|
2007-09-23 22:23:01 +00:00
|
|
|
'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
|
2007-07-22 14:45:12 +00:00
|
|
|
'fa_deleted_user' => $encUserId,
|
|
|
|
|
'fa_deleted_timestamp' => $encTimestamp,
|
|
|
|
|
'fa_deleted_reason' => $encReason,
|
2008-03-15 00:27:57 +00:00
|
|
|
'fa_deleted' => $this->suppress ? $bitfield : 0,
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
'fa_name' => 'img_name',
|
|
|
|
|
'fa_archive_name' => 'NULL',
|
|
|
|
|
'fa_size' => 'img_size',
|
|
|
|
|
'fa_width' => 'img_width',
|
|
|
|
|
'fa_height' => 'img_height',
|
|
|
|
|
'fa_metadata' => 'img_metadata',
|
|
|
|
|
'fa_bits' => 'img_bits',
|
|
|
|
|
'fa_media_type' => 'img_media_type',
|
|
|
|
|
'fa_major_mime' => 'img_major_mime',
|
|
|
|
|
'fa_minor_mime' => 'img_minor_mime',
|
|
|
|
|
'fa_description' => 'img_description',
|
|
|
|
|
'fa_user' => 'img_user',
|
|
|
|
|
'fa_user_text' => 'img_user_text',
|
|
|
|
|
'fa_timestamp' => 'img_timestamp'
|
|
|
|
|
), $where, __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( count( $oldRels ) ) {
|
2007-09-23 22:23:01 +00:00
|
|
|
$concat = $dbw->buildConcat( array( "oi_sha1", $encExt ) );
|
2007-07-22 14:45:12 +00:00
|
|
|
$where = array(
|
|
|
|
|
'oi_name' => $this->file->getName(),
|
|
|
|
|
'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')' );
|
2008-04-14 07:45:50 +00:00
|
|
|
$dbw->insertSelect( 'filearchive', 'oldimage',
|
2007-07-22 14:45:12 +00:00
|
|
|
array(
|
|
|
|
|
'fa_storage_group' => $encGroup,
|
2007-09-23 22:23:01 +00:00
|
|
|
'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
|
2007-07-22 14:45:12 +00:00
|
|
|
'fa_deleted_user' => $encUserId,
|
|
|
|
|
'fa_deleted_timestamp' => $encTimestamp,
|
|
|
|
|
'fa_deleted_reason' => $encReason,
|
2008-03-15 00:27:57 +00:00
|
|
|
'fa_deleted' => $this->suppress ? $bitfield : 'oi_deleted',
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
'fa_name' => 'oi_name',
|
|
|
|
|
'fa_archive_name' => 'oi_archive_name',
|
|
|
|
|
'fa_size' => 'oi_size',
|
|
|
|
|
'fa_width' => 'oi_width',
|
|
|
|
|
'fa_height' => 'oi_height',
|
|
|
|
|
'fa_metadata' => 'oi_metadata',
|
|
|
|
|
'fa_bits' => 'oi_bits',
|
|
|
|
|
'fa_media_type' => 'oi_media_type',
|
|
|
|
|
'fa_major_mime' => 'oi_major_mime',
|
|
|
|
|
'fa_minor_mime' => 'oi_minor_mime',
|
|
|
|
|
'fa_description' => 'oi_description',
|
|
|
|
|
'fa_user' => 'oi_user',
|
|
|
|
|
'fa_user_text' => 'oi_user_text',
|
2008-03-15 00:27:57 +00:00
|
|
|
'fa_timestamp' => 'oi_timestamp',
|
|
|
|
|
'fa_deleted' => $bitfield
|
2007-07-22 14:45:12 +00:00
|
|
|
), $where, __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doDBDeletes() {
|
2011-04-11 18:46:35 +00:00
|
|
|
$dbw = $this->file->repo->getMasterDB();
|
2007-07-22 14:45:12 +00:00
|
|
|
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( count( $oldRels ) ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$dbw->delete( 'oldimage',
|
2007-07-22 14:45:12 +00:00
|
|
|
array(
|
|
|
|
|
'oi_name' => $this->file->getName(),
|
2008-09-16 12:47:44 +00:00
|
|
|
'oi_archive_name' => array_keys( $oldRels )
|
2007-07-22 14:45:12 +00:00
|
|
|
), __METHOD__ );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-02-10 16:59:44 +00:00
|
|
|
if ( $deleteCurrent ) {
|
|
|
|
|
$dbw->delete( 'image', array( 'img_name' => $this->file->getName() ), __METHOD__ );
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run the transaction
|
|
|
|
|
*/
|
|
|
|
|
function execute() {
|
2009-04-28 03:03:48 +00:00
|
|
|
global $wgUseSquid;
|
2007-07-22 14:45:12 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$this->file->lock();
|
2008-03-15 00:27:57 +00:00
|
|
|
// Leave private files alone
|
|
|
|
|
$privateFiles = array();
|
|
|
|
|
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
|
|
|
|
|
$dbw = $this->file->repo->getMasterDB();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( !empty( $oldRels ) ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$res = $dbw->select( 'oldimage',
|
2008-03-15 08:48:21 +00:00
|
|
|
array( 'oi_archive_name' ),
|
2008-03-15 00:27:57 +00:00
|
|
|
array( 'oi_name' => $this->file->getName(),
|
2010-09-04 13:48:16 +00:00
|
|
|
'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')',
|
|
|
|
|
$dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE ),
|
2008-03-15 00:27:57 +00:00
|
|
|
__METHOD__ );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2008-03-15 00:27:57 +00:00
|
|
|
$privateFiles[$row->oi_archive_name] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
// Prepare deletion batch
|
|
|
|
|
$hashes = $this->getHashes();
|
|
|
|
|
$this->deletionBatch = array();
|
|
|
|
|
$ext = $this->file->getExtension();
|
|
|
|
|
$dotExt = $ext === '' ? '' : ".$ext";
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
foreach ( $this->srcRels as $name => $srcRel ) {
|
2008-03-15 00:27:57 +00:00
|
|
|
// Skip files that have no hash (missing source).
|
|
|
|
|
// Keep private files where they are.
|
2010-02-07 19:31:24 +00:00
|
|
|
if ( isset( $hashes[$name] ) && !array_key_exists( $name, $privateFiles ) ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$hash = $hashes[$name];
|
|
|
|
|
$key = $hash . $dotExt;
|
|
|
|
|
$dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
|
|
|
|
|
$this->deletionBatch[$name] = array( $srcRel, $dstRel );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lock the filearchive rows so that the files don't get deleted by a cleanup operation
|
|
|
|
|
// We acquire this lock by running the inserts now, before the file operations.
|
|
|
|
|
//
|
2008-04-14 07:45:50 +00:00
|
|
|
// This potentially has poor lock contention characteristics -- an alternative
|
2007-07-22 14:45:12 +00:00
|
|
|
// scheme would be to insert stub filearchive entries with no fa_name and commit
|
|
|
|
|
// them in a separate transaction, then run the file ops, then update the fa_name fields.
|
|
|
|
|
$this->doDBInserts();
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
// Removes non-existent file from the batch, so we don't get errors.
|
|
|
|
|
$this->deletionBatch = $this->removeNonexistentFiles( $this->deletionBatch );
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
// Execute the file deletion batch
|
|
|
|
|
$status = $this->file->repo->deleteBatch( $this->deletionBatch );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
$this->status->merge( $status );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$this->status->ok ) {
|
|
|
|
|
// Critical file deletion error
|
|
|
|
|
// Roll back inserts, release lock and abort
|
|
|
|
|
// TODO: delete the defunct filearchive rows if we are using a non-transactional DB
|
|
|
|
|
$this->file->unlockAndRollback();
|
2009-04-04 17:51:13 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2007-07-22 14:45:12 +00:00
|
|
|
return $this->status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Purge squid
|
|
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
$urls = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
foreach ( $this->srcRels as $srcRel ) {
|
|
|
|
|
$urlRel = str_replace( '%2F', '/', rawurlencode( $srcRel ) );
|
2007-08-22 16:32:10 +00:00
|
|
|
$urls[] = $this->file->repo->getZoneUrl( 'public' ) . '/' . $urlRel;
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
SquidUpdate::purge( $urls );
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-01 19:50:25 +00:00
|
|
|
// Delete image/oldimage rows
|
|
|
|
|
$this->doDBDeletes();
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
// Commit and return
|
|
|
|
|
$this->file->unlock();
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $this->status;
|
|
|
|
|
}
|
2009-04-26 11:12:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes non-existent files from a deletion batch.
|
|
|
|
|
*/
|
|
|
|
|
function removeNonexistentFiles( $batch ) {
|
|
|
|
|
$files = $newBatch = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $batch as $batchItem ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
list( $src, $dest ) = $batchItem;
|
|
|
|
|
$files[$src] = $this->file->repo->getVirtualUrl( 'public' ) . '/' . rawurlencode( $src );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
$result = $this->file->repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $batch as $batchItem ) {
|
|
|
|
|
if ( $result[$batchItem[0]] ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
$newBatch[] = $batchItem;
|
2010-09-04 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
return $newBatch;
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2010-09-04 13:48:16 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/**
|
|
|
|
|
* Helper class for file undeletion
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup FileRepo
|
2007-07-22 14:45:12 +00:00
|
|
|
*/
|
|
|
|
|
class LocalFileRestoreBatch {
|
2011-02-18 23:56:08 +00:00
|
|
|
/**
|
|
|
|
|
* @var LocalFile
|
|
|
|
|
*/
|
|
|
|
|
var $file;
|
|
|
|
|
|
|
|
|
|
var $cleanupBatch, $ids, $all, $unsuppress = false;
|
2007-07-22 14:45:12 +00:00
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
function __construct( File $file, $unsuppress = false ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->file = $file;
|
|
|
|
|
$this->cleanupBatch = $this->ids = array();
|
|
|
|
|
$this->ids = array();
|
2008-03-15 00:27:57 +00:00
|
|
|
$this->unsuppress = $unsuppress;
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a file by ID
|
|
|
|
|
*/
|
|
|
|
|
function addId( $fa_id ) {
|
|
|
|
|
$this->ids[] = $fa_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a whole lot of files by ID
|
|
|
|
|
*/
|
|
|
|
|
function addIds( $ids ) {
|
|
|
|
|
$this->ids = array_merge( $this->ids, $ids );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add all revisions of the file
|
|
|
|
|
*/
|
2007-10-01 19:50:25 +00:00
|
|
|
function addAll() {
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->all = true;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Run the transaction, except the cleanup batch.
|
2007-07-22 14:45:12 +00:00
|
|
|
* The cleanup batch should be run in a separate transaction, because it locks different
|
|
|
|
|
* rows and there's no need to keep the image row locked while it's acquiring those locks
|
|
|
|
|
* The caller may have its own transaction open.
|
|
|
|
|
* So we save the batch and let the caller call cleanup()
|
|
|
|
|
*/
|
|
|
|
|
function execute() {
|
2009-04-28 03:03:48 +00:00
|
|
|
global $wgLang;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( !$this->all && !$this->ids ) {
|
|
|
|
|
// Do nothing
|
|
|
|
|
return $this->file->repo->newGood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$exists = $this->file->lock();
|
|
|
|
|
$dbw = $this->file->repo->getMasterDB();
|
|
|
|
|
$status = $this->file->repo->newGood();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
// Fetch all or selected archived revisions for the file,
|
|
|
|
|
// sorted from the most recent to the oldest.
|
|
|
|
|
$conditions = array( 'fa_name' => $this->file->getName() );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( !$this->all ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$conditions[] = 'fa_id IN (' . $dbw->makeList( $this->ids ) . ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $dbw->select( 'filearchive', '*',
|
|
|
|
|
$conditions,
|
|
|
|
|
__METHOD__,
|
2008-11-08 01:58:18 +00:00
|
|
|
array( 'ORDER BY' => 'fa_timestamp DESC' )
|
|
|
|
|
);
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
$idsPresent = array();
|
|
|
|
|
$storeBatch = array();
|
|
|
|
|
$insertBatch = array();
|
|
|
|
|
$insertCurrent = false;
|
|
|
|
|
$deleteIds = array();
|
|
|
|
|
$first = true;
|
|
|
|
|
$archiveNames = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $result as $row ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
$idsPresent[] = $row->fa_id;
|
2008-03-15 00:27:57 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $row->fa_name != $this->file->getName() ) {
|
|
|
|
|
$status->error( 'undelete-filename-mismatch', $wgLang->timeanddate( $row->fa_timestamp ) );
|
|
|
|
|
$status->failCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $row->fa_storage_key == '' ) {
|
|
|
|
|
// Revision was missing pre-deletion
|
|
|
|
|
$status->error( 'undelete-bad-store-key', $wgLang->timeanddate( $row->fa_timestamp ) );
|
|
|
|
|
$status->failCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$deletedRel = $this->file->repo->getDeletedHashPath( $row->fa_storage_key ) . $row->fa_storage_key;
|
|
|
|
|
$deletedUrl = $this->file->repo->getVirtualUrl() . '/deleted/' . $deletedRel;
|
|
|
|
|
|
|
|
|
|
$sha1 = substr( $row->fa_storage_key, 0, strcspn( $row->fa_storage_key, '.' ) );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
# Fix leading zero
|
|
|
|
|
if ( strlen( $sha1 ) == 32 && $sha1[0] == '0' ) {
|
|
|
|
|
$sha1 = substr( $sha1, 1 );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown'
|
2007-08-25 20:18:56 +00:00
|
|
|
|| 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,
|
2008-11-08 01:58:18 +00:00
|
|
|
'metadata' => $row->fa_metadata
|
|
|
|
|
);
|
2007-08-25 20:18:56 +00:00
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
if ( $first && !$exists ) {
|
|
|
|
|
// This revision will be published as the new current version
|
|
|
|
|
$destRel = $this->file->getRel();
|
|
|
|
|
$insertCurrent = array(
|
|
|
|
|
'img_name' => $row->fa_name,
|
|
|
|
|
'img_size' => $row->fa_size,
|
|
|
|
|
'img_width' => $row->fa_width,
|
|
|
|
|
'img_height' => $row->fa_height,
|
2007-08-25 20:18:56 +00:00
|
|
|
'img_metadata' => $props['metadata'],
|
2007-07-22 14:45:12 +00:00
|
|
|
'img_bits' => $row->fa_bits,
|
2007-08-25 20:18:56 +00:00
|
|
|
'img_media_type' => $props['media_type'],
|
|
|
|
|
'img_major_mime' => $props['major_mime'],
|
|
|
|
|
'img_minor_mime' => $props['minor_mime'],
|
2007-07-22 14:45:12 +00:00
|
|
|
'img_description' => $row->fa_description,
|
|
|
|
|
'img_user' => $row->fa_user,
|
|
|
|
|
'img_user_text' => $row->fa_user_text,
|
|
|
|
|
'img_timestamp' => $row->fa_timestamp,
|
2008-11-08 01:58:18 +00:00
|
|
|
'img_sha1' => $sha1
|
|
|
|
|
);
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-11-08 01:58:18 +00:00
|
|
|
// The live (current) version cannot be hidden!
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( !$this->unsuppress && $row->fa_deleted ) {
|
2008-11-08 01:58:18 +00:00
|
|
|
$storeBatch[] = array( $deletedUrl, 'public', $destRel );
|
|
|
|
|
$this->cleanupBatch[] = $row->fa_storage_key;
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
} else {
|
|
|
|
|
$archiveName = $row->fa_archive_name;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $archiveName == '' ) {
|
2007-07-22 14:45:12 +00:00
|
|
|
// This was originally a current version; we
|
|
|
|
|
// have to devise a new archive name for it.
|
|
|
|
|
// Format is <timestamp of archiving>!<name>
|
|
|
|
|
$timestamp = wfTimestamp( TS_UNIX, $row->fa_deleted_timestamp );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
do {
|
|
|
|
|
$archiveName = wfTimestamp( TS_MW, $timestamp ) . '!' . $row->fa_name;
|
|
|
|
|
$timestamp++;
|
|
|
|
|
} while ( isset( $archiveNames[$archiveName] ) );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$archiveNames[$archiveName] = true;
|
|
|
|
|
$destRel = $this->file->getArchiveRel( $archiveName );
|
|
|
|
|
$insertBatch[] = array(
|
|
|
|
|
'oi_name' => $row->fa_name,
|
|
|
|
|
'oi_archive_name' => $archiveName,
|
|
|
|
|
'oi_size' => $row->fa_size,
|
|
|
|
|
'oi_width' => $row->fa_width,
|
|
|
|
|
'oi_height' => $row->fa_height,
|
|
|
|
|
'oi_bits' => $row->fa_bits,
|
|
|
|
|
'oi_description' => $row->fa_description,
|
|
|
|
|
'oi_user' => $row->fa_user,
|
|
|
|
|
'oi_user_text' => $row->fa_user_text,
|
|
|
|
|
'oi_timestamp' => $row->fa_timestamp,
|
2007-08-25 20:18:56 +00:00
|
|
|
'oi_metadata' => $props['metadata'],
|
|
|
|
|
'oi_media_type' => $props['media_type'],
|
|
|
|
|
'oi_major_mime' => $props['major_mime'],
|
|
|
|
|
'oi_minor_mime' => $props['minor_mime'],
|
2008-03-15 00:27:57 +00:00
|
|
|
'oi_deleted' => $this->unsuppress ? 0 : $row->fa_deleted,
|
2007-07-22 14:45:12 +00:00
|
|
|
'oi_sha1' => $sha1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$deleteIds[] = $row->fa_id;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( !$this->unsuppress && $row->fa_deleted & File::DELETED_FILE ) {
|
2008-03-15 00:27:57 +00:00
|
|
|
// private files can stay where they are
|
2008-08-29 13:17:12 +00:00
|
|
|
$status->successCount++;
|
2008-03-15 00:27:57 +00:00
|
|
|
} else {
|
|
|
|
|
$storeBatch[] = array( $deletedUrl, 'public', $destRel );
|
|
|
|
|
$this->cleanupBatch[] = $row->fa_storage_key;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$first = false;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
unset( $result );
|
|
|
|
|
|
|
|
|
|
// Add a warning to the status object for missing IDs
|
|
|
|
|
$missingIds = array_diff( $this->ids, $idsPresent );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
foreach ( $missingIds as $id ) {
|
|
|
|
|
$status->error( 'undelete-missing-filearchive', $id );
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
// Remove missing files from batch, so we don't get errors when undeleting them
|
|
|
|
|
$storeBatch = $this->removeNonexistentFiles( $storeBatch );
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
// Run the store batch
|
|
|
|
|
// Use the OVERWRITE_SAME flag to smooth over a common error
|
|
|
|
|
$storeStatus = $this->file->repo->storeBatch( $storeBatch, FileRepo::OVERWRITE_SAME );
|
|
|
|
|
$status->merge( $storeStatus );
|
|
|
|
|
|
2011-02-04 20:54:11 +00:00
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
// Even if some files could be copied, fail entirely as that is the
|
|
|
|
|
// easiest thing to do without data loss
|
|
|
|
|
$this->cleanupFailedBatch( $storeStatus, $storeBatch );
|
|
|
|
|
$status->ok = false;
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->file->unlock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run the DB updates
|
|
|
|
|
// Because we have locked the image row, key conflicts should be rare.
|
2008-04-14 07:45:50 +00:00
|
|
|
// If they do occur, we can roll back the transaction at this time with
|
|
|
|
|
// no data loss, but leaving unregistered files scattered throughout the
|
2007-07-22 14:45:12 +00:00
|
|
|
// public zone.
|
|
|
|
|
// This is not ideal, which is why it's important to lock the image row.
|
|
|
|
|
if ( $insertCurrent ) {
|
|
|
|
|
$dbw->insert( 'image', $insertCurrent, __METHOD__ );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $insertBatch ) {
|
|
|
|
|
$dbw->insert( 'oldimage', $insertBatch, __METHOD__ );
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $deleteIds ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$dbw->delete( 'filearchive',
|
|
|
|
|
array( 'fa_id IN (' . $dbw->makeList( $deleteIds ) . ')' ),
|
2007-07-22 14:45:12 +00:00
|
|
|
__METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
// If store batch is empty (all files are missing), deletion is to be considered successful
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( $status->successCount > 0 || !$storeBatch ) {
|
|
|
|
|
if ( !$exists ) {
|
2010-02-07 19:31:24 +00:00
|
|
|
wfDebug( __METHOD__ . " restored {$status->successCount} items, creating a new current\n" );
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
// Update site_stats
|
|
|
|
|
$site_stats = $dbw->tableName( 'site_stats' );
|
|
|
|
|
$dbw->query( "UPDATE $site_stats SET ss_images=ss_images+1", __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$this->file->purgeEverything();
|
|
|
|
|
} else {
|
2010-02-07 19:31:24 +00:00
|
|
|
wfDebug( __METHOD__ . " restored {$status->successCount} as archived versions\n" );
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->file->purgeDescription();
|
|
|
|
|
$this->file->purgeHistory();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$this->file->unlock();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
/**
|
|
|
|
|
* Removes non-existent files from a store batch.
|
|
|
|
|
*/
|
|
|
|
|
function removeNonexistentFiles( $triplets ) {
|
|
|
|
|
$files = $filteredTriplets = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
foreach ( $triplets as $file )
|
2009-04-26 11:12:39 +00:00
|
|
|
$files[$file[0]] = $file[0];
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
$result = $this->file->repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $triplets as $file ) {
|
|
|
|
|
if ( $result[$file[0]] ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
$filteredTriplets[] = $file;
|
2010-09-04 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
return $filteredTriplets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes non-existent files from a cleanup batch.
|
|
|
|
|
*/
|
|
|
|
|
function removeNonexistentFromCleanup( $batch ) {
|
|
|
|
|
$files = $newBatch = array();
|
|
|
|
|
$repo = $this->file->repo;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $batch as $file ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
$files[$file] = $repo->getVirtualUrl( 'deleted' ) . '/' .
|
|
|
|
|
rawurlencode( $repo->getDeletedHashPath( $file ) . $file );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $batch as $file ) {
|
|
|
|
|
if ( $result[$file] ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
$newBatch[] = $file;
|
2010-09-04 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
return $newBatch;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/**
|
|
|
|
|
* Delete unused files in the deleted zone.
|
|
|
|
|
* This should be called from outside the transaction in which execute() was called.
|
|
|
|
|
*/
|
|
|
|
|
function cleanup() {
|
|
|
|
|
if ( !$this->cleanupBatch ) {
|
|
|
|
|
return $this->file->repo->newGood();
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
$this->cleanupBatch = $this->removeNonexistentFromCleanup( $this->cleanupBatch );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
$status = $this->file->repo->cleanupDeletedBatch( $this->cleanupBatch );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
2011-02-04 20:54:11 +00:00
|
|
|
|
2011-05-26 18:41:06 +00:00
|
|
|
/**
|
|
|
|
|
* Cleanup a failed batch. The batch was only partially successful, so
|
|
|
|
|
* rollback by removing all items that were succesfully copied.
|
|
|
|
|
*
|
|
|
|
|
* @param Status $storeStatus
|
|
|
|
|
* @param array $storeBatch
|
|
|
|
|
*/
|
2011-02-04 20:54:11 +00:00
|
|
|
function cleanupFailedBatch( $storeStatus, $storeBatch ) {
|
|
|
|
|
$cleanupBatch = array();
|
|
|
|
|
|
|
|
|
|
foreach ( $storeStatus->success as $i => $success ) {
|
|
|
|
|
if ( $success ) {
|
|
|
|
|
$cleanupBatch[] = array( $storeBatch[$i][1], $storeBatch[$i][1] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->file->repo->cleanupBatch( $cleanupBatch );
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
2008-05-03 13:09:34 +00:00
|
|
|
|
2010-09-04 13:48:16 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2008-05-03 13:09:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper class for file movement
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup FileRepo
|
2008-05-03 13:09:34 +00:00
|
|
|
*/
|
|
|
|
|
class LocalFileMoveBatch {
|
2008-07-10 13:24:42 +00:00
|
|
|
var $file, $cur, $olds, $oldCount, $archive, $target, $db;
|
2008-05-03 13:09:34 +00:00
|
|
|
|
2008-07-04 13:04:03 +00:00
|
|
|
function __construct( File $file, Title $target ) {
|
2008-05-03 13:09:34 +00:00
|
|
|
$this->file = $file;
|
|
|
|
|
$this->target = $target;
|
|
|
|
|
$this->oldHash = $this->file->repo->getHashPath( $this->file->getName() );
|
2009-05-24 08:29:10 +00:00
|
|
|
$this->newHash = $this->file->repo->getHashPath( $this->target->getDBkey() );
|
2008-05-03 13:09:34 +00:00
|
|
|
$this->oldName = $this->file->getName();
|
|
|
|
|
$this->newName = $this->file->repo->getNameFromTitle( $this->target );
|
|
|
|
|
$this->oldRel = $this->oldHash . $this->oldName;
|
|
|
|
|
$this->newRel = $this->newHash . $this->newName;
|
2008-07-04 13:04:03 +00:00
|
|
|
$this->db = $file->repo->getMasterDb();
|
2008-05-03 13:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2008-07-10 13:24:42 +00:00
|
|
|
* Add the current image to the batch
|
|
|
|
|
*/
|
2008-05-03 13:09:34 +00:00
|
|
|
function addCurrent() {
|
|
|
|
|
$this->cur = array( $this->oldRel, $this->newRel );
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2008-07-10 13:24:42 +00:00
|
|
|
* Add the old versions of the image to the batch
|
|
|
|
|
*/
|
2008-05-03 13:09:34 +00:00
|
|
|
function addOlds() {
|
|
|
|
|
$archiveBase = 'archive';
|
|
|
|
|
$this->olds = array();
|
2008-07-10 13:24:42 +00:00
|
|
|
$this->oldCount = 0;
|
2008-05-03 13:09:34 +00:00
|
|
|
|
|
|
|
|
$result = $this->db->select( 'oldimage',
|
2008-05-03 14:45:06 +00:00
|
|
|
array( 'oi_archive_name', 'oi_deleted' ),
|
2008-05-03 13:09:34 +00:00
|
|
|
array( 'oi_name' => $this->oldName ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $result as $row ) {
|
2008-07-10 13:24:42 +00:00
|
|
|
$oldName = $row->oi_archive_name;
|
|
|
|
|
$bits = explode( '!', $oldName, 2 );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( count( $bits ) != 2 ) {
|
2009-01-13 20:28:54 +00:00
|
|
|
wfDebug( "Invalid old file name: $oldName \n" );
|
2008-05-03 13:09:34 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
list( $timestamp, $filename ) = $bits;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $this->oldName != $filename ) {
|
2009-01-13 20:28:54 +00:00
|
|
|
wfDebug( "Invalid old file name: $oldName \n" );
|
2008-05-03 13:09:34 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-07-10 13:24:42 +00:00
|
|
|
$this->oldCount++;
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-07-10 13:24:42 +00:00
|
|
|
// Do we want to add those to oldCount?
|
2010-09-04 13:48:16 +00:00
|
|
|
if ( $row->oi_deleted & File::DELETED_FILE ) {
|
2008-05-03 14:45:06 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
$this->olds[] = array(
|
2008-09-29 19:23:31 +00:00
|
|
|
"{$archiveBase}/{$this->oldHash}{$oldName}",
|
2008-05-07 15:09:25 +00:00
|
|
|
"{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"
|
2008-05-03 13:09:34 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2008-07-10 13:24:42 +00:00
|
|
|
* Perform the move.
|
|
|
|
|
*/
|
2008-05-03 13:09:34 +00:00
|
|
|
function execute() {
|
|
|
|
|
$repo = $this->file->repo;
|
|
|
|
|
$status = $repo->newGood();
|
|
|
|
|
$triplets = $this->getMoveTriplets();
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
$triplets = $this->removeNonexistentFiles( $triplets );
|
2011-03-04 21:57:23 +00:00
|
|
|
|
|
|
|
|
// Copy the files into their new location
|
|
|
|
|
$statusMove = $repo->storeBatch( $triplets );
|
2008-07-06 20:39:11 +00:00
|
|
|
wfDebugLog( 'imagemove', "Moved files for {$this->file->name}: {$statusMove->successCount} successes, {$statusMove->failCount} failures" );
|
2011-03-04 21:57:23 +00:00
|
|
|
if ( !$statusMove->isGood() ) {
|
2008-07-06 20:39:11 +00:00
|
|
|
wfDebugLog( 'imagemove', "Error in moving files: " . $statusMove->getWikiText() );
|
2011-03-04 21:57:23 +00:00
|
|
|
$this->cleanupTarget( $triplets );
|
|
|
|
|
$statusMove->ok = false;
|
|
|
|
|
return $statusMove;
|
2008-05-03 13:09:34 +00:00
|
|
|
}
|
2009-03-29 13:42:29 +00:00
|
|
|
|
2011-03-04 21:57:23 +00:00
|
|
|
$this->db->begin();
|
|
|
|
|
$statusDb = $this->doDBUpdates();
|
|
|
|
|
wfDebugLog( 'imagemove', "Renamed {$this->file->name} in database: {$statusDb->successCount} successes, {$statusDb->failCount} failures" );
|
|
|
|
|
if ( !$statusDb->isGood() ) {
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
// Something went wrong with the DB updates, so remove the target files
|
|
|
|
|
$this->cleanupTarget( $triplets );
|
|
|
|
|
$statusDb->ok = false;
|
|
|
|
|
return $statusDb;
|
|
|
|
|
}
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
|
|
|
|
// Everything went ok, remove the source files
|
|
|
|
|
$this->cleanupSource( $triplets );
|
|
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
$status->merge( $statusDb );
|
|
|
|
|
$status->merge( $statusMove );
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2010-04-16 15:20:12 +00:00
|
|
|
* Do the database updates and return a new FileRepoStatus indicating how
|
|
|
|
|
* many rows where updated.
|
|
|
|
|
*
|
|
|
|
|
* @return FileRepoStatus
|
2008-07-10 13:24:42 +00:00
|
|
|
*/
|
2008-05-03 13:09:34 +00:00
|
|
|
function doDBUpdates() {
|
|
|
|
|
$repo = $this->file->repo;
|
|
|
|
|
$status = $repo->newGood();
|
|
|
|
|
$dbw = $this->db;
|
|
|
|
|
|
|
|
|
|
// Update current image
|
2010-09-04 01:06:34 +00:00
|
|
|
$dbw->update(
|
2008-05-03 13:09:34 +00:00
|
|
|
'image',
|
|
|
|
|
array( 'img_name' => $this->newName ),
|
|
|
|
|
array( 'img_name' => $this->oldName ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
if ( $dbw->affectedRows() ) {
|
2008-05-03 13:09:34 +00:00
|
|
|
$status->successCount++;
|
|
|
|
|
} else {
|
|
|
|
|
$status->failCount++;
|
2011-03-04 21:57:23 +00:00
|
|
|
$status->fatal( 'imageinvalidfilename' );
|
|
|
|
|
return $status;
|
2008-05-03 13:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update old images
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'oldimage',
|
|
|
|
|
array(
|
|
|
|
|
'oi_name' => $this->newName,
|
2010-09-04 13:48:16 +00:00
|
|
|
'oi_archive_name = ' . $dbw->strreplace( 'oi_archive_name', $dbw->addQuotes( $this->oldName ), $dbw->addQuotes( $this->newName ) ),
|
2008-05-03 13:09:34 +00:00
|
|
|
),
|
|
|
|
|
array( 'oi_name' => $this->oldName ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
$affected = $dbw->affectedRows();
|
2008-07-10 13:24:42 +00:00
|
|
|
$total = $this->oldCount;
|
2008-05-03 13:09:34 +00:00
|
|
|
$status->successCount += $affected;
|
|
|
|
|
$status->failCount += $total - $affected;
|
2011-03-04 21:57:23 +00:00
|
|
|
if ( $status->failCount ) {
|
|
|
|
|
$status->error( 'imageinvalidfilename' );
|
|
|
|
|
}
|
2008-05-03 13:09:34 +00:00
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2008-07-10 13:24:42 +00:00
|
|
|
* Generate triplets for FSRepo::storeBatch().
|
2010-09-04 01:06:34 +00:00
|
|
|
*/
|
2008-05-03 13:09:34 +00:00
|
|
|
function getMoveTriplets() {
|
2008-07-07 09:38:27 +00:00
|
|
|
$moves = array_merge( array( $this->cur ), $this->olds );
|
2008-05-07 15:03:18 +00:00
|
|
|
$triplets = array(); // The format is: (srcUrl, destZone, destUrl)
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $moves as $move ) {
|
2008-05-07 15:03:18 +00:00
|
|
|
// $move: (oldRelativePath, newRelativePath)
|
2008-05-03 13:09:34 +00:00
|
|
|
$srcUrl = $this->file->repo->getVirtualUrl() . '/public/' . rawurlencode( $move[0] );
|
|
|
|
|
$triplets[] = array( $srcUrl, 'public', $move[1] );
|
2008-07-06 20:39:11 +00:00
|
|
|
wfDebugLog( 'imagemove', "Generated move triplet for {$this->file->name}: {$srcUrl} :: public :: {$move[1]}" );
|
2008-05-03 13:09:34 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
return $triplets;
|
|
|
|
|
}
|
2009-03-29 13:42:29 +00:00
|
|
|
|
2010-02-07 19:31:24 +00:00
|
|
|
/**
|
2009-04-26 11:12:39 +00:00
|
|
|
* Removes non-existent files from move batch.
|
2010-09-04 01:06:34 +00:00
|
|
|
*/
|
2009-04-26 11:12:39 +00:00
|
|
|
function removeNonexistentFiles( $triplets ) {
|
2009-03-29 13:42:29 +00:00
|
|
|
$files = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $triplets as $file ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
$files[$file[0]] = $file[0];
|
2010-09-04 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-29 13:42:29 +00:00
|
|
|
$result = $this->file->repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
|
2009-04-26 11:12:39 +00:00
|
|
|
$filteredTriplets = array();
|
2010-09-04 13:48:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $triplets as $file ) {
|
|
|
|
|
if ( $result[$file[0]] ) {
|
2009-04-26 11:12:39 +00:00
|
|
|
$filteredTriplets[] = $file;
|
|
|
|
|
} else {
|
|
|
|
|
wfDebugLog( 'imagemove', "File {$file[0]} does not exist" );
|
2009-03-29 13:42:29 +00:00
|
|
|
}
|
2010-09-04 13:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
2009-04-26 11:12:39 +00:00
|
|
|
return $filteredTriplets;
|
2009-03-29 13:42:29 +00:00
|
|
|
}
|
2011-03-04 21:57:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cleanup a partially moved array of triplets by deleting the target
|
|
|
|
|
* files. Called if something went wrong half way.
|
|
|
|
|
*/
|
|
|
|
|
function cleanupTarget( $triplets ) {
|
|
|
|
|
// Create dest pairs from the triplets
|
|
|
|
|
$pairs = array();
|
|
|
|
|
foreach ( $triplets as $triplet ) {
|
|
|
|
|
$pairs[] = array( $triplet[1], $triplet[2] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->file->repo->cleanupBatch( $pairs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cleanup a fully moved array of triplets by deleting the source files.
|
|
|
|
|
* Called at the end of the move process if everything else went ok.
|
|
|
|
|
*/
|
|
|
|
|
function cleanupSource( $triplets ) {
|
|
|
|
|
// Create source file names from the triplets
|
|
|
|
|
$files = array();
|
|
|
|
|
foreach ( $triplets as $triplet ) {
|
|
|
|
|
$files[] = $triplet[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->file->repo->cleanupBatch( $files );
|
|
|
|
|
}
|
2008-05-03 13:09:34 +00:00
|
|
|
}
|