2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* Base code for files.
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup FileRepo
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Implements some public methods and some protected utility functions which
|
|
|
|
|
* are required by multiple child classes. Contains stub functionality for
|
2007-05-30 21:02:32 +00:00
|
|
|
* unimplemented public methods.
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Stub functions which should be overridden are marked with STUB. Some more
|
2007-05-30 21:02:32 +00:00
|
|
|
* concrete functions are also typically overridden by child classes.
|
|
|
|
|
*
|
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:
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2007-05-31 01:43:41 +00:00
|
|
|
* RepoGroup::singleton()->getLocalRepo()->newFile($title);
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2007-05-31 01:43:41 +00:00
|
|
|
* The convenience functions wfLocalFile() and wfFindFile() should be sufficient
|
|
|
|
|
* in most cases.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
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-06-24 06:32:07 +00:00
|
|
|
abstract class File {
|
2007-05-30 21:02:32 +00:00
|
|
|
const DELETED_FILE = 1;
|
|
|
|
|
const DELETED_COMMENT = 2;
|
|
|
|
|
const DELETED_USER = 4;
|
|
|
|
|
const DELETED_RESTRICTED = 8;
|
|
|
|
|
const RENDER_NOW = 1;
|
|
|
|
|
|
|
|
|
|
const DELETE_SOURCE = 1;
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
|
|
|
|
* Some member variables can be lazy-initialised using __get(). The
|
2007-05-30 21:02:32 +00:00
|
|
|
* initialisation function for these variables is always a function named
|
2008-04-14 07:45:50 +00:00
|
|
|
* like getVar(), where Var is the variable name with upper-case first
|
2007-05-30 21:02:32 +00:00
|
|
|
* letter.
|
|
|
|
|
*
|
|
|
|
|
* The following variables are initialised in this way in this base class:
|
2008-04-14 07:45:50 +00:00
|
|
|
* name, extension, handler, path, canRender, isSafeFile,
|
2007-05-30 21:02:32 +00:00
|
|
|
* transformScript, hashPath, pageCount, url
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Code within this class should generally use the accessor function
|
2007-05-30 21:02:32 +00:00
|
|
|
* directly, since __get() isn't re-entrant and therefore causes bugs that
|
|
|
|
|
* depend on initialisation order.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The following member variables are not lazy-initialised
|
|
|
|
|
*/
|
2011-02-18 23:56:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var LocalRepo
|
|
|
|
|
*/
|
|
|
|
|
var $repo;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
|
|
|
|
var $title;
|
|
|
|
|
|
|
|
|
|
var $lastError, $redirected, $redirectedTitle;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-03-13 22:58:41 +00:00
|
|
|
/**
|
|
|
|
|
* @var MediaHandler
|
|
|
|
|
*/
|
|
|
|
|
protected $handler;
|
|
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Call this constructor from child classes
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function __construct( $title, $repo ) {
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
$this->repo = $repo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function __get( $name ) {
|
|
|
|
|
$function = array( $this, 'get' . ucfirst( $name ) );
|
|
|
|
|
if ( !is_callable( $function ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
$this->$name = call_user_func( $function );
|
|
|
|
|
return $this->$name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalize a file extension to the common form, and ensure it's clean.
|
|
|
|
|
* Extensions with non-alphanumeric characters will be discarded.
|
|
|
|
|
*
|
|
|
|
|
* @param $ext string (without the .)
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
static function normalizeExtension( $ext ) {
|
|
|
|
|
$lower = strtolower( $ext );
|
|
|
|
|
$squish = array(
|
|
|
|
|
'htm' => 'html',
|
|
|
|
|
'jpeg' => 'jpg',
|
|
|
|
|
'mpeg' => 'mpg',
|
2008-06-06 19:58:06 +00:00
|
|
|
'tiff' => 'tif',
|
|
|
|
|
'ogv' => 'ogg' );
|
2007-05-30 21:02:32 +00:00
|
|
|
if( isset( $squish[$lower] ) ) {
|
|
|
|
|
return $squish[$lower];
|
|
|
|
|
} elseif( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
|
|
|
|
|
return $lower;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
/**
|
|
|
|
|
* Checks if file extensions are compatible
|
|
|
|
|
*
|
|
|
|
|
* @param $old File Old file
|
|
|
|
|
* @param $new string New name
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool|null
|
2008-05-03 13:09:34 +00:00
|
|
|
*/
|
2008-05-03 13:39:10 +00:00
|
|
|
static function checkExtensionCompatibility( File $old, $new ) {
|
2008-05-03 13:09:34 +00:00
|
|
|
$oldMime = $old->getMimeType();
|
|
|
|
|
$n = strrpos( $new, '.' );
|
|
|
|
|
$newExt = self::normalizeExtension(
|
|
|
|
|
$n ? substr( $new, $n + 1 ) : '' );
|
|
|
|
|
$mimeMagic = MimeMagic::singleton();
|
|
|
|
|
return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Upgrade the database row if there is one
|
|
|
|
|
* Called by ImagePage
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function upgradeRow() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Split an internet media type into its two components; if not
|
|
|
|
|
* a two-part name, set the minor type to 'unknown'.
|
|
|
|
|
*
|
2011-03-13 22:02:40 +00:00
|
|
|
* @param string $mime "text/html" etc
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return array ("text", "html") etc
|
|
|
|
|
*/
|
2011-03-13 22:02:40 +00:00
|
|
|
public static function splitMime( $mime ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
if( strpos( $mime, '/' ) !== false ) {
|
|
|
|
|
return explode( '/', $mime, 2 );
|
|
|
|
|
} else {
|
|
|
|
|
return array( $mime, 'unknown' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Return the name of this file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function getName() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->name ) ) {
|
2007-06-03 10:44:27 +00:00
|
|
|
$this->name = $this->repo->getNameFromTitle( $this->title );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
return $this->name;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the file extension, e.g. "svg"
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getExtension() {
|
|
|
|
|
if ( !isset( $this->extension ) ) {
|
|
|
|
|
$n = strrpos( $this->getName(), '.' );
|
2008-04-14 07:45:50 +00:00
|
|
|
$this->extension = self::normalizeExtension(
|
2007-05-30 21:02:32 +00:00
|
|
|
$n ? substr( $this->getName(), $n + 1 ) : '' );
|
|
|
|
|
}
|
|
|
|
|
return $this->extension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the associated title object
|
2011-02-02 10:42:17 +00:00
|
|
|
* @return Title
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
public function getTitle() { return $this->title; }
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2008-05-20 17:05:57 +00:00
|
|
|
/**
|
|
|
|
|
* Return the title used to find this file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return Title
|
2008-05-20 17:05:57 +00:00
|
|
|
*/
|
|
|
|
|
public function getOriginalTitle() {
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( $this->redirected ) {
|
2008-05-20 17:05:57 +00:00
|
|
|
return $this->getRedirectedTitle();
|
2011-05-29 13:33:29 +00:00
|
|
|
}
|
2008-05-20 17:05:57 +00:00
|
|
|
return $this->title;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the URL of the file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getUrl() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->url ) ) {
|
|
|
|
|
$this->url = $this->repo->getZoneUrl( 'public' ) . '/' . $this->getUrlRel();
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
return $this->url;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-09-14 15:29:52 +00:00
|
|
|
/**
|
|
|
|
|
* Return a fully-qualified URL to the file.
|
|
|
|
|
* Upload URL paths _may or may not_ be fully qualified, so
|
|
|
|
|
* we check. Local paths are assumed to belong on $wgServer.
|
2010-03-25 20:12:56 +00:00
|
|
|
*
|
|
|
|
|
* @return String
|
2007-09-14 15:29:52 +00:00
|
|
|
*/
|
|
|
|
|
public function getFullUrl() {
|
2008-02-13 05:59:14 +00:00
|
|
|
return wfExpandUrl( $this->getUrl() );
|
2007-09-14 15:29:52 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getViewURL() {
|
|
|
|
|
if( $this->mustRender()) {
|
|
|
|
|
if( $this->canRender() ) {
|
|
|
|
|
return $this->createThumb( $this->getWidth() );
|
2011-05-29 13:33:29 +00:00
|
|
|
} else {
|
2007-05-30 21:02:32 +00:00
|
|
|
wfDebug(__METHOD__.': supposed to render '.$this->getName().' ('.$this->getMimeType()."), but can't!\n");
|
|
|
|
|
return $this->getURL(); #hm... return NULL?
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return $this->getURL();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the full filesystem path to the file. Note that this does
|
|
|
|
|
* not mean that a file actually exists under that location.
|
|
|
|
|
*
|
|
|
|
|
* This path depends on whether directory hashing is active or not,
|
|
|
|
|
* i.e. whether the files are all found in the same directory,
|
|
|
|
|
* or in hashed paths like /images/3/3c.
|
|
|
|
|
*
|
2011-05-04 23:17:00 +00:00
|
|
|
* Most callers don't check the return value, but ForeignAPIFile::getPath
|
|
|
|
|
* returns false.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string|false
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
public function getPath() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->path ) ) {
|
|
|
|
|
$this->path = $this->repo->getZonePath('public') . '/' . $this->getRel();
|
|
|
|
|
}
|
|
|
|
|
return $this->path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-29 13:33:29 +00:00
|
|
|
* Alias for getPath()
|
|
|
|
|
*
|
|
|
|
|
* @deprecated since 1.18 Use getPath().
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
public function getFullPath() {
|
2011-05-04 18:34:50 +00:00
|
|
|
wfDeprecated( __METHOD__ );
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->getPath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Return the width of the image. Returns false if the width is unknown
|
2007-05-30 21:02:32 +00:00
|
|
|
* or undefined.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @param $page int
|
|
|
|
|
*
|
|
|
|
|
* @return number
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
public function getWidth( $page = 1 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Return the height of the image. Returns false if the height is unknown
|
2007-05-30 21:02:32 +00:00
|
|
|
* or undefined
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
|
|
|
|
* @return false|number
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
public function getHeight( $page = 1 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Returns ID or name of user who uploaded the file
|
|
|
|
|
* STUB
|
|
|
|
|
*
|
|
|
|
|
* @param $type string 'text' or 'id'
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
|
|
|
|
* @return string|int
|
2008-01-20 06:48:57 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getUser( $type = 'text' ) {
|
2011-05-29 13:33:29 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2008-01-20 06:48:57 +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
|
|
|
/**
|
|
|
|
|
* Get the duration of a media file in seconds
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return number
|
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
|
|
|
*/
|
|
|
|
|
public function getLength() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getLength( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 21:49:25 +00:00
|
|
|
/**
|
2011-05-29 14:01:47 +00:00
|
|
|
* Return true if the file is vectorized
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2011-05-29 14:01:47 +00:00
|
|
|
* @return bool
|
2011-05-25 15:39:47 +00:00
|
|
|
*/
|
2011-02-02 10:42:17 +00:00
|
|
|
public function isVectorized() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->isVectorized( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-31 21:49:25 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get handler-specific metadata
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getMetadata() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-07-31 20:10:36 +00:00
|
|
|
|
2011-04-16 01:23:15 +00:00
|
|
|
/**
|
|
|
|
|
* get versioned metadata
|
|
|
|
|
*
|
|
|
|
|
* @param $metadata Mixed Array or String of (serialized) metadata
|
|
|
|
|
* @param $version integer version number.
|
|
|
|
|
* @return Array containing metadata, or what was passed to it on fail (unserializing if not array)
|
|
|
|
|
*/
|
|
|
|
|
public function convertMetadataVersion($metadata, $version) {
|
|
|
|
|
$handler = $this->getHandler();
|
2011-04-18 13:08:20 +00:00
|
|
|
if ( !is_array( $metadata ) ) {
|
2011-04-16 01:23:15 +00:00
|
|
|
//just to make the return type consistant
|
2011-05-25 15:39:47 +00:00
|
|
|
$metadata = unserialize( $metadata );
|
2011-04-16 01:23:15 +00:00
|
|
|
}
|
|
|
|
|
if ( $handler ) {
|
2011-04-18 13:08:20 +00:00
|
|
|
return $handler->convertMetadataVersion( $metadata, $version );
|
2011-04-16 01:23:15 +00:00
|
|
|
} else {
|
|
|
|
|
return $metadata;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-31 20:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* Return the bit depth of the file
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getBitDepth() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the size of the image file, in bytes
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getSize() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the mime type of the file.
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
function getMimeType() {
|
|
|
|
|
return 'unknown/unknown';
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the type of the media in the file.
|
|
|
|
|
* Use the value returned by this function with the MEDIATYPE_xxx constants.
|
|
|
|
|
* Overridden by LocalFile,
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function getMediaType() { return MEDIATYPE_UNKNOWN; }
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Checks if the output of transform() for this file is likely
|
|
|
|
|
* to be valid. If this is false, various user elements will
|
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
|
|
|
* display a placeholder instead.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* Currently, this checks if the file is an image format
|
|
|
|
|
* that can be converted to a format
|
|
|
|
|
* supported by all browsers (namely GIF, PNG and JPEG),
|
|
|
|
|
* or if it is an SVG image and SVG conversion is enabled.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function canRender() {
|
|
|
|
|
if ( !isset( $this->canRender ) ) {
|
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->canRender = $this->getHandler() && $this->handler->canRender( $this );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $this->canRender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessor for __get()
|
|
|
|
|
*/
|
|
|
|
|
protected function getCanRender() {
|
|
|
|
|
return $this->canRender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if the file is of a type that can't be directly
|
|
|
|
|
* rendered by typical browsers and needs to be re-rasterized.
|
|
|
|
|
*
|
|
|
|
|
* This returns true for everything but the bitmap types
|
|
|
|
|
* supported by all browsers, i.e. JPEG; GIF and PNG. It will
|
|
|
|
|
* also return true for any non-image formats.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function mustRender() {
|
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 $this->getHandler() && $this->handler->mustRender( $this );
|
2007-05-30 21:02:32 +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
|
|
|
* Alias for canRender()
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function allowInlineDisplay() {
|
|
|
|
|
return $this->canRender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines if this media file is in a format that is unlikely to
|
|
|
|
|
* contain viruses or malicious content. It uses the global
|
|
|
|
|
* $wgTrustedMediaFormats list to determine if the file is safe.
|
|
|
|
|
*
|
|
|
|
|
* This is used to show a warning on the description page of non-safe files.
|
|
|
|
|
* It may also be used to disallow direct [[media:...]] links to such files.
|
|
|
|
|
*
|
|
|
|
|
* Note that this function will always return true if allowInlineDisplay()
|
|
|
|
|
* or isTrustedFile() is true for this file.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isSafeFile() {
|
|
|
|
|
if ( !isset( $this->isSafeFile ) ) {
|
|
|
|
|
$this->isSafeFile = $this->_getIsSafeFile();
|
|
|
|
|
}
|
|
|
|
|
return $this->isSafeFile;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* Accessor for __get()
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
protected function getIsSafeFile() {
|
|
|
|
|
return $this->isSafeFile();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* Uncached accessor
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
protected function _getIsSafeFile() {
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( $this->allowInlineDisplay() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if ($this->isTrustedFile()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
global $wgTrustedMediaFormats;
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
$type = $this->getMediaType();
|
|
|
|
|
$mime = $this->getMimeType();
|
2007-05-30 21:02:32 +00:00
|
|
|
#wfDebug("LocalFile::isSafeFile: type= $type, mime= $mime\n");
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( !$type || $type === MEDIATYPE_UNKNOWN ) {
|
|
|
|
|
return false; #unknown type, not trusted
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( $type, $wgTrustedMediaFormats ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( $mime === "unknown/unknown" ) {
|
|
|
|
|
return false; #unknown type, not trusted
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( $mime, $wgTrustedMediaFormats) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if the file is flagged as trusted. Files flagged that way
|
|
|
|
|
* can be linked to directly, even if that is not allowed for this type of
|
|
|
|
|
* file normally.
|
|
|
|
|
*
|
|
|
|
|
* This is a dummy function right now and always returns false. It could be
|
|
|
|
|
* implemented to extract a flag from the database. The trusted flag could be
|
|
|
|
|
* set on upload, if the user has sufficient privileges, to bypass script-
|
|
|
|
|
* and html-filters. It may even be coupled with cryptographics signatures
|
|
|
|
|
* or such.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function isTrustedFile() {
|
|
|
|
|
#this could be implemented to check a flag in the databas,
|
|
|
|
|
#look for signatures, etc
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if file exists in the repository.
|
|
|
|
|
*
|
|
|
|
|
* Overridden by LocalFile to avoid unnecessary stat calls.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return boolean Whether file exists in the repository.
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function exists() {
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->getPath() && file_exists( $this->path );
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-09 03:10:28 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if file exists in the repository and can be included in a page.
|
|
|
|
|
* It would be unsafe to include private images, making public thumbnails inadvertently
|
|
|
|
|
*
|
|
|
|
|
* @return boolean Whether file exists in the repository and is includable.
|
|
|
|
|
*/
|
2011-04-02 14:48:22 +00:00
|
|
|
public function isVisible() {
|
2008-03-09 03:10:28 +00:00
|
|
|
return $this->exists();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getTransformScript() {
|
|
|
|
|
if ( !isset( $this->transformScript ) ) {
|
|
|
|
|
$this->transformScript = false;
|
|
|
|
|
if ( $this->repo ) {
|
|
|
|
|
$script = $this->repo->getThumbScriptUrl();
|
|
|
|
|
if ( $script ) {
|
|
|
|
|
$this->transformScript = "$script?f=" . urlencode( $this->getName() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $this->transformScript;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a ThumbnailImage which is the same size as the source
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @param $handlerParams array
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2010-05-19 00:40:48 +00:00
|
|
|
function getUnscaledThumb( $handlerParams = array() ) {
|
|
|
|
|
$hp =& $handlerParams;
|
|
|
|
|
$page = isset( $hp['page'] ) ? $hp['page'] : false;
|
2007-05-30 21:02:32 +00:00
|
|
|
$width = $this->getWidth( $page );
|
|
|
|
|
if ( !$width ) {
|
|
|
|
|
return $this->iconThumb();
|
|
|
|
|
}
|
2010-05-19 00:40:48 +00:00
|
|
|
$hp['width'] = $width;
|
|
|
|
|
return $this->transform( $hp );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the file name of a thumbnail with the specified parameters
|
|
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $params Array: handler-specific parameters
|
2007-06-24 12:38:03 +00:00
|
|
|
* @private -ish
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 12:38:03 +00:00
|
|
|
function thumbName( $params ) {
|
2011-02-11 19:13:27 +00:00
|
|
|
return $this->generateThumbName( $this->getName(), $params );
|
2011-02-11 19:10:31 +00:00
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2011-02-11 19:10:31 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a thumbnail file name from a name and specified parameters
|
|
|
|
|
*
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param array $params Parameters which will be passed to MediaHandler::makeParamString
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2011-02-11 19:10:31 +00:00
|
|
|
*/
|
|
|
|
|
function generateThumbName( $name, $params ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$extension = $this->getExtension();
|
2010-06-22 16:01:54 +00:00
|
|
|
list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params );
|
2011-02-11 19:10:31 +00:00
|
|
|
$thumbName = $this->handler->makeParamString( $params ) . '-' . $name;
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $thumbExt != $extension ) {
|
|
|
|
|
$thumbName .= ".$thumbExt";
|
|
|
|
|
}
|
|
|
|
|
return $thumbName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a thumbnail of the image having the specified width/height.
|
|
|
|
|
* The thumbnail will not be created if the width is larger than the
|
|
|
|
|
* image's width. Let the browser do the scaling in this case.
|
|
|
|
|
* The thumbnail is stored on disk and is only computed if the thumbnail
|
|
|
|
|
* file does not exist OR if it is older than the image.
|
|
|
|
|
* Returns the URL.
|
|
|
|
|
*
|
|
|
|
|
* Keeps aspect ratio of original image. If both width and height are
|
|
|
|
|
* specified, the generated image will be no bigger than width x height,
|
|
|
|
|
* and will also have correct aspect ratio.
|
|
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $width Integer: maximum width of the generated thumbnail
|
|
|
|
|
* @param $height Integer: maximum height of the image (optional)
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function createThumb( $width, $height = -1 ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$params = array( 'width' => $width );
|
|
|
|
|
if ( $height != -1 ) {
|
|
|
|
|
$params['height'] = $height;
|
|
|
|
|
}
|
|
|
|
|
$thumb = $this->transform( $params );
|
|
|
|
|
if( is_null( $thumb ) || $thumb->isError() ) return '';
|
|
|
|
|
return $thumb->getUrl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transform a media file
|
|
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $params Array: an associative array of handler-specific parameters.
|
|
|
|
|
* Typical keys are width, height and page.
|
|
|
|
|
* @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
|
2010-11-03 04:32:41 +00:00
|
|
|
* @return MediaTransformOutput | false
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function transform( $params, $flags = 0 ) {
|
2009-12-17 20:25:55 +00:00
|
|
|
global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch, $wgServer;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
do {
|
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
|
|
|
if ( !$this->canRender() ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
// not a bitmap or renderable image, don't try.
|
|
|
|
|
$thumb = $this->iconThumb();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 20:25:55 +00:00
|
|
|
// Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
|
|
|
|
|
$descriptionUrl = $this->getDescriptionUrl();
|
|
|
|
|
if ( $descriptionUrl ) {
|
|
|
|
|
$params['descriptionUrl'] = $wgServer . $descriptionUrl;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
$script = $this->getTransformScript();
|
|
|
|
|
if ( $script && !($flags & self::RENDER_NOW) ) {
|
2008-01-22 03:31:10 +00:00
|
|
|
// Use a script to transform on client request, if possible
|
2007-05-30 21:02:32 +00:00
|
|
|
$thumb = $this->handler->getScriptedTransform( $this, $script, $params );
|
2008-01-22 03:31:10 +00:00
|
|
|
if( $thumb ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$normalisedParams = $params;
|
|
|
|
|
$this->handler->normaliseParams( $this, $normalisedParams );
|
2008-04-14 07:45:50 +00:00
|
|
|
$thumbName = $this->thumbName( $normalisedParams );
|
2007-05-30 21:02:32 +00:00
|
|
|
$thumbPath = $this->getThumbPath( $thumbName );
|
|
|
|
|
$thumbUrl = $this->getThumbUrl( $thumbName );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-11-03 04:32:41 +00:00
|
|
|
if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
wfDebug( __METHOD__.": Doing stat for $thumbPath\n" );
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->migrateThumbFile( $thumbName );
|
2009-12-09 09:10:55 +00:00
|
|
|
if ( file_exists( $thumbPath )) {
|
2009-12-08 10:24:23 +00:00
|
|
|
$thumbTime = filemtime( $thumbPath );
|
|
|
|
|
if ( $thumbTime !== FALSE &&
|
2011-05-25 15:39:47 +00:00
|
|
|
gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) {
|
|
|
|
|
|
2009-12-08 10:24:23 +00:00
|
|
|
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-12-09 09:10:55 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
$thumb = $this->handler->doTransform( $this, $thumbPath, $thumbUrl, $params );
|
|
|
|
|
|
|
|
|
|
// Ignore errors if requested
|
|
|
|
|
if ( !$thumb ) {
|
|
|
|
|
$thumb = null;
|
|
|
|
|
} elseif ( $thumb->isError() ) {
|
|
|
|
|
$this->lastError = $thumb->toText();
|
|
|
|
|
if ( $wgIgnoreImageErrors && !($flags & self::RENDER_NOW) ) {
|
|
|
|
|
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
|
|
|
|
// Purge. Useful in the event of Core -> Squid connection failure or squid
|
|
|
|
|
// purge collisions from elsewhere during failure. Don't keep triggering for
|
2008-05-02 21:29:05 +00:00
|
|
|
// "thumbs" which have the main image URL though (bug 13776)
|
2008-08-12 17:32:37 +00:00
|
|
|
if ( $wgUseSquid && ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL()) ) {
|
2008-03-20 22:00:59 +00:00
|
|
|
SquidUpdate::purge( array( $thumbUrl ) );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2009-02-01 23:09:56 +00:00
|
|
|
return is_object( $thumb ) ? $thumb : false;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2007-05-30 21:02:32 +00:00
|
|
|
* Hook into transform() to allow migration of thumbnail files
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
function migrateThumbFile( $thumbName ) {}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a MediaHandler instance for this file
|
2011-02-02 11:38:50 +00:00
|
|
|
* @return MediaHandler
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function getHandler() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->handler ) ) {
|
|
|
|
|
$this->handler = MediaHandler::getHandler( $this->getMimeType() );
|
|
|
|
|
}
|
|
|
|
|
return $this->handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a ThumbnailImage representing a file type icon
|
|
|
|
|
* @return ThumbnailImage
|
|
|
|
|
*/
|
|
|
|
|
function iconThumb() {
|
|
|
|
|
global $wgStylePath, $wgStyleDirectory;
|
|
|
|
|
|
|
|
|
|
$try = array( 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' );
|
|
|
|
|
foreach( $try as $icon ) {
|
|
|
|
|
$path = '/common/images/icons/' . $icon;
|
|
|
|
|
$filepath = $wgStyleDirectory . $path;
|
|
|
|
|
if( file_exists( $filepath ) ) {
|
2007-08-31 02:51:23 +00:00
|
|
|
return new ThumbnailImage( $this, $wgStylePath . $path, 120, 120 );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get last thumbnailing error.
|
|
|
|
|
* Largely obsolete.
|
|
|
|
|
*/
|
|
|
|
|
function getLastError() {
|
|
|
|
|
return $this->lastError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all thumbnail names previously generated for this file
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
function getThumbnails() {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purge shared caches such as thumbnails and DB data caching
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
function purgeCache() {}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purge the file description page, but don't go after
|
|
|
|
|
* pages using the file. Use when modifying file history
|
|
|
|
|
* but not the current data.
|
|
|
|
|
*/
|
|
|
|
|
function purgeDescription() {
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
if ( $title ) {
|
|
|
|
|
$title->invalidateCache();
|
|
|
|
|
$title->purgeSquid();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Purge metadata and all affected pages when the file is created,
|
2007-07-22 14:45:12 +00:00
|
|
|
* deleted, or majorly updated.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function purgeEverything() {
|
2007-05-30 21:02:32 +00:00
|
|
|
// Delete thumbnails and refresh file metadata cache
|
|
|
|
|
$this->purgeCache();
|
|
|
|
|
$this->purgeDescription();
|
|
|
|
|
|
|
|
|
|
// Purge cache of all pages using this file
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
if ( $title ) {
|
|
|
|
|
$update = new HTMLCacheUpdate( $title, 'imagelinks' );
|
|
|
|
|
$update->doUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Return a fragment of the history of file.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* @param $limit integer Limit of rows to return
|
|
|
|
|
* @param $start timestamp Only revisions older than $start will be returned
|
|
|
|
|
* @param $end timestamp Only revisions newer than $end will be returned
|
2008-12-14 03:53:05 +00:00
|
|
|
* @param $inc bool Include the endpoints of the time range
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2008-01-20 06:48:57 +00:00
|
|
|
*/
|
2008-12-14 03:53:05 +00:00
|
|
|
function getHistory($limit = null, $start = null, $end = null, $inc=true) {
|
2008-05-11 14:54:45 +00:00
|
|
|
return array();
|
2008-01-20 06:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Return the history of this file, line by line. Starts with current version,
|
|
|
|
|
* then old versions. Should return an object similar to an image/oldimage
|
2007-05-30 21:02:32 +00:00
|
|
|
* database row.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden in LocalFile
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function nextHistoryLine() {
|
2007-05-30 21:02:32 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-07-07 03:04:20 +00:00
|
|
|
* Reset the history pointer to the first element of the history.
|
|
|
|
|
* Always call this function after using nextHistoryLine() to free db resources
|
2007-05-30 21:02:32 +00:00
|
|
|
* STUB
|
|
|
|
|
* Overridden in LocalFile.
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function resetHistory() {}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the filename hash component of the directory including trailing slash,
|
|
|
|
|
* e.g. f/fa/
|
|
|
|
|
* If the repository is not hashed, returns an empty string.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getHashPath() {
|
|
|
|
|
if ( !isset( $this->hashPath ) ) {
|
|
|
|
|
$this->hashPath = $this->repo->getHashPath( $this->getName() );
|
|
|
|
|
}
|
|
|
|
|
return $this->hashPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the path of the file relative to the public zone root
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getRel() {
|
|
|
|
|
return $this->getHashPath() . $this->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get urlencoded relative path of the file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getUrlRel() {
|
2007-06-16 02:55:25 +00:00
|
|
|
return $this->getHashPath() . rawurlencode( $this->getName() );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the relative path for an archive file
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function getArchiveRel( $suffix = false ) {
|
|
|
|
|
$path = 'archive/' . $this->getHashPath();
|
2007-06-11 14:46:18 +00:00
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
|
|
|
|
$path .= $suffix;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path of the archive directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function getArchivePath( $suffix = false ) {
|
2011-05-29 14:01:47 +00:00
|
|
|
return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path of the thumbnail directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function getThumbPath( $suffix = false ) {
|
2011-05-29 14:01:47 +00:00
|
|
|
$path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getRel();
|
2009-07-16 18:07:23 +00:00
|
|
|
if ( $suffix !== false ) {
|
|
|
|
|
$path .= '/' . $suffix;
|
|
|
|
|
}
|
|
|
|
|
return $path;
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL of the archive directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getArchiveUrl( $suffix = false ) {
|
|
|
|
|
$path = $this->repo->getZoneUrl('public') . '/archive/' . $this->getHashPath();
|
2007-06-11 14:46:18 +00:00
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL of the thumbnail directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return path
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getThumbUrl( $suffix = false ) {
|
2009-07-16 18:07:23 +00:00
|
|
|
$path = $this->repo->getZoneUrl('thumb') . '/' . $this->getUrlRel();
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $suffix !== false ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the virtual URL for an archive file or directory
|
|
|
|
|
*
|
2011-05-29 14:01:47 +00:00
|
|
|
* @param bool|string $suffix
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getArchiveVirtualUrl( $suffix = false ) {
|
|
|
|
|
$path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
|
2007-06-11 14:46:18 +00:00
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the virtual URL for a thumbnail file or directory
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getThumbVirtualUrl( $suffix = false ) {
|
2009-07-16 18:07:23 +00:00
|
|
|
$path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $suffix !== false ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the virtual URL for the file itself
|
|
|
|
|
*
|
|
|
|
|
* @param $suffix bool
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-06-16 02:55:25 +00:00
|
|
|
function getVirtualUrl( $suffix = false ) {
|
|
|
|
|
$path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel();
|
|
|
|
|
if ( $suffix !== false ) {
|
|
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
|
|
|
|
}
|
|
|
|
|
return $path;
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function isHashed() {
|
|
|
|
|
return $this->repo->isHashed();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function readOnlyError() {
|
|
|
|
|
throw new MWException( get_class($this) . ': write operations are not supported' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Record a file upload in the upload log and the image table
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
2011-05-29 13:33:29 +00:00
|
|
|
* @param $oldver
|
|
|
|
|
* @param $desc
|
|
|
|
|
* @param $license string
|
|
|
|
|
* @param $copyStatus string
|
|
|
|
|
* @param $source string
|
|
|
|
|
* @param $watch bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false ) {
|
|
|
|
|
$this->readOnlyError();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
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:
|
2008-04-14 07:45:50 +00:00
|
|
|
* File::DELETE_SOURCE Delete the source file, i.e. move
|
2007-05-30 21:02:32 +00:00
|
|
|
* rather than copy
|
2010-04-16 15:20:12 +00:00
|
|
|
* @return FileRepoStatus object. On success, the value member contains the
|
|
|
|
|
* archive name, or an empty string if it was a new file.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
|
|
|
|
function publish( $srcPath, $flags = 0 ) {
|
|
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-07-28 01:15:35 +00:00
|
|
|
function formatMetadata() {
|
|
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return false;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2007-07-28 01:15:35 +00:00
|
|
|
return $this->getHandler()->formatMetadata( $this, $this->getMetadata() );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the file comes from the local file repository.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function isLocal() {
|
2010-06-18 20:00:27 +00:00
|
|
|
$repo = $this->getRepo();
|
|
|
|
|
return $repo && $repo->isLocal();
|
2007-07-07 03:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the name of the repository.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function getRepoName() {
|
|
|
|
|
return $this->repo ? $this->repo->getName() : 'unknown';
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2011-05-21 19:35:16 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2008-05-15 19:17:21 +00:00
|
|
|
* Returns the repository
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return FileRepo
|
2008-05-15 19:17:21 +00:00
|
|
|
*/
|
|
|
|
|
function getRepo() {
|
|
|
|
|
return $this->repo;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the image is an old version
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isOld() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this file a "deleted" file in a private archive?
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @param $field
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isDeleted( $field ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2009-09-12 22:02:51 +00:00
|
|
|
/**
|
|
|
|
|
* Return the deletion bitfield
|
|
|
|
|
* STUB
|
2011-05-25 15:39:47 +00:00
|
|
|
*/
|
2009-09-12 22:02:51 +00:00
|
|
|
function getVisibility() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Was this file ever deleted from the wiki?
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function wasDeleted() {
|
|
|
|
|
$title = $this->getTitle();
|
2009-02-24 16:17:23 +00:00
|
|
|
return $title && $title->isDeletedQuick();
|
2007-05-30 21:02:32 +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 ) {
|
|
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $reason String
|
|
|
|
|
* @param $suppress Boolean: hide content from sysops?
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return true on success, false on some kind of failure
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2008-03-15 00:27:57 +00:00
|
|
|
function delete( $reason, $suppress = false ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Restore all or specified deleted revisions to the given file.
|
|
|
|
|
* Permissions and logging are left to the caller.
|
|
|
|
|
*
|
|
|
|
|
* May throw database exceptions on error.
|
|
|
|
|
*
|
2011-05-29 13:33:29 +00:00
|
|
|
* @param $versions array set of record ids of deleted items to restore,
|
2007-10-01 19:50:25 +00:00
|
|
|
* or empty to restore all revisions.
|
2011-05-29 13:33:29 +00:00
|
|
|
* @param $unsuppress bool remove restrictions on content upon restoration?
|
|
|
|
|
* @return int|false the number of file revisions restored if successful,
|
2007-05-30 21:02:32 +00:00
|
|
|
* or false on failure
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
function restore( $versions = array(), $unsuppress = false ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-25 15:39:47 +00:00
|
|
|
* Returns 'true' if this file is a type which supports multiple pages,
|
|
|
|
|
* e.g. DJVU or PDF. Note that this may be true even if the file in
|
2009-12-08 00:07:37 +00:00
|
|
|
* question only has a single page.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* @return Bool
|
|
|
|
|
*/
|
|
|
|
|
function isMultipage() {
|
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 $this->getHandler() && $this->handler->isMultiPage( $this );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-27 18:51:17 +00:00
|
|
|
* Returns the number of pages of a multipage document, or false for
|
2007-05-30 21:02:32 +00:00
|
|
|
* documents which aren't multipage documents
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return false|int
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function pageCount() {
|
|
|
|
|
if ( !isset( $this->pageCount ) ) {
|
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
|
|
|
if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->pageCount = $this->handler->pageCount( $this );
|
|
|
|
|
} else {
|
|
|
|
|
$this->pageCount = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $this->pageCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate the height of a thumbnail using the source and destination width
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @param $srcWidth
|
|
|
|
|
* @param $srcHeight
|
|
|
|
|
* @param $dstWidth
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
|
|
|
|
|
// Exact integer multiply followed by division
|
|
|
|
|
if ( $srcWidth == 0 ) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return round( $srcHeight * $dstWidth / $srcWidth );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2010-06-08 12:15:48 +00:00
|
|
|
* Get an image size array like that returned by getImageSize(), or false if it
|
2007-05-30 21:02:32 +00:00
|
|
|
* can't be determined.
|
|
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $fileName String: The filename
|
|
|
|
|
* @return Array
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getImageSize( $fileName ) {
|
|
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return $this->handler->getImageSize( $this, $fileName );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the URL of the image description page. May return false if it is
|
|
|
|
|
* unknown or not applicable.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getDescriptionUrl() {
|
|
|
|
|
return $this->repo->getDescriptionUrl( $this->getName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTML text of the description page, if available
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getDescriptionText() {
|
2009-08-02 15:22:06 +00:00
|
|
|
global $wgMemc, $wgLang;
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->repo->fetchDescription ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-08-02 15:22:06 +00:00
|
|
|
$renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgLang->getCode() );
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $renderUrl ) {
|
2008-07-03 21:33:09 +00:00
|
|
|
if ( $this->repo->descriptionCacheExpiry > 0 ) {
|
2008-07-07 18:20:39 +00:00
|
|
|
wfDebug("Attempting to get the description from cache...");
|
2011-05-25 15:39:47 +00:00
|
|
|
$key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(),
|
2009-01-27 19:34:21 +00:00
|
|
|
$this->getName() );
|
2008-07-03 18:24:08 +00:00
|
|
|
$obj = $wgMemc->get($key);
|
2008-07-03 07:49:35 +00:00
|
|
|
if ($obj) {
|
|
|
|
|
wfDebug("success!\n");
|
2008-07-03 18:24:08 +00:00
|
|
|
return $obj;
|
2008-07-03 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
wfDebug("miss\n");
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
wfDebug( "Fetching shared description from $renderUrl\n" );
|
2008-07-03 07:49:35 +00:00
|
|
|
$res = Http::get( $renderUrl );
|
2009-01-27 19:34:21 +00:00
|
|
|
if ( $res && $this->repo->descriptionCacheExpiry > 0 ) {
|
|
|
|
|
$wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry );
|
|
|
|
|
}
|
2008-07-03 07:49:35 +00:00
|
|
|
return $res;
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Get discription of file revision
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2008-01-20 06:48:57 +00:00
|
|
|
*/
|
|
|
|
|
function getDescription() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2007-07-29 20:45:07 +00:00
|
|
|
* Get the 14-character timestamp of the file upload, or false if
|
2008-04-14 07:45:50 +00:00
|
|
|
* it doesn't exist
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function getTimestamp() {
|
2007-05-30 21:02:32 +00:00
|
|
|
$path = $this->getPath();
|
|
|
|
|
if ( !file_exists( $path ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-04-05 16:08:26 +00:00
|
|
|
return wfTimestamp( TS_MW, filemtime( $path ) );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the SHA-1 base 36 hash of the file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-07-22 14:45:12 +00:00
|
|
|
*/
|
|
|
|
|
function getSha1() {
|
|
|
|
|
return self::sha1Base36( $this->getPath() );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
/**
|
|
|
|
|
* Get the deletion archive key, <sha1>.<ext>
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
*/
|
|
|
|
|
function getStorageKey() {
|
|
|
|
|
$hash = $this->getSha1();
|
|
|
|
|
if ( !$hash ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$ext = $this->getExtension();
|
|
|
|
|
$dotExt = $ext === '' ? '' : ".$ext";
|
2011-05-25 15:39:47 +00:00
|
|
|
return $hash . $dotExt;
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
|
|
|
|
* field of this file, if it's marked as deleted.
|
|
|
|
|
* STUB
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $field Integer
|
|
|
|
|
* @return Boolean
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function userCan( $field ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
2007-10-10 00:15:51 +00:00
|
|
|
* Get an associative array containing information about a file in the local filesystem.
|
2007-06-18 06:35:20 +00:00
|
|
|
*
|
2010-03-25 20:12:56 +00:00
|
|
|
* @param $path String: absolute local filesystem path
|
|
|
|
|
* @param $ext Mixed: the file extension, or true to extract it from the filename.
|
|
|
|
|
* Set it to false to ignore the extension.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
2007-06-18 06:35:20 +00:00
|
|
|
static function getPropsFromPath( $path, $ext = true ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
wfDebug( __METHOD__.": Getting file info for $path\n" );
|
2008-04-14 07:45:50 +00:00
|
|
|
$info = 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
|
|
|
'fileExists' => file_exists( $path ) && !is_dir( $path )
|
|
|
|
|
);
|
2007-06-16 02:55:25 +00:00
|
|
|
$gis = false;
|
|
|
|
|
if ( $info['fileExists'] ) {
|
|
|
|
|
$magic = MimeMagic::singleton();
|
|
|
|
|
|
2010-08-31 13:47:24 +00:00
|
|
|
if ( $ext === true ) {
|
|
|
|
|
$i = strrpos( $path, '.' );
|
|
|
|
|
$ext = strtolower( $i ? substr( $path, $i + 1 ) : '' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-13 03:10:28 +00:00
|
|
|
# mime type according to file contents
|
|
|
|
|
$info['file-mime'] = $magic->guessMimeType( $path, false );
|
|
|
|
|
# logical mime type
|
|
|
|
|
$info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext );
|
2010-08-31 13:47:24 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
list( $info['major_mime'], $info['minor_mime'] ) = self::splitMime( $info['mime'] );
|
|
|
|
|
$info['media_type'] = $magic->getMediaType( $path, $info['mime'] );
|
|
|
|
|
|
|
|
|
|
# Get size in bytes
|
|
|
|
|
$info['size'] = filesize( $path );
|
|
|
|
|
|
|
|
|
|
# Height, width and metadata
|
|
|
|
|
$handler = MediaHandler::getHandler( $info['mime'] );
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
$tempImage = (object)array();
|
|
|
|
|
$info['metadata'] = $handler->getMetadata( $tempImage, $path );
|
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
|
|
|
$gis = $handler->getImageSize( $tempImage, $path, $info['metadata'] );
|
2007-06-16 02:55:25 +00:00
|
|
|
} else {
|
|
|
|
|
$gis = false;
|
|
|
|
|
$info['metadata'] = '';
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
$info['sha1'] = self::sha1Base36( $path );
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
wfDebug(__METHOD__.": $path loaded, {$info['size']} bytes, {$info['mime']}.\n");
|
|
|
|
|
} else {
|
2009-12-11 21:07:27 +00:00
|
|
|
$info['mime'] = null;
|
2007-06-16 02:55:25 +00:00
|
|
|
$info['media_type'] = MEDIATYPE_UNKNOWN;
|
|
|
|
|
$info['metadata'] = '';
|
2007-07-22 14:45:12 +00:00
|
|
|
$info['sha1'] = '';
|
2007-06-16 02:55:25 +00:00
|
|
|
wfDebug(__METHOD__.": $path NOT FOUND!\n");
|
|
|
|
|
}
|
|
|
|
|
if( $gis ) {
|
|
|
|
|
# NOTE: $gis[2] contains a code for the image type. This is no longer used.
|
|
|
|
|
$info['width'] = $gis[0];
|
|
|
|
|
$info['height'] = $gis[1];
|
|
|
|
|
if ( isset( $gis['bits'] ) ) {
|
|
|
|
|
$info['bits'] = $gis['bits'];
|
|
|
|
|
} else {
|
|
|
|
|
$info['bits'] = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$info['width'] = 0;
|
|
|
|
|
$info['height'] = 0;
|
2007-06-21 21:18:29 +00:00
|
|
|
$info['bits'] = 0;
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $info;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case
|
|
|
|
|
* encoding, zero padded to 31 digits.
|
2007-07-22 14:45:12 +00:00
|
|
|
*
|
|
|
|
|
* 160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36
|
|
|
|
|
* fairly neatly.
|
|
|
|
|
*
|
2011-06-25 16:15:44 +00:00
|
|
|
* @param $path string
|
|
|
|
|
*
|
2011-06-25 16:32:03 +00:00
|
|
|
* @return false|string False on failure
|
2007-07-22 14:45:12 +00:00
|
|
|
*/
|
|
|
|
|
static function sha1Base36( $path ) {
|
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
|
|
|
wfSuppressWarnings();
|
2007-07-22 14:45:12 +00:00
|
|
|
$hash = sha1_file( $path );
|
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
|
|
|
wfRestoreWarnings();
|
2007-07-22 14:45:12 +00:00
|
|
|
if ( $hash === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return wfBaseConvert( $hash, 16, 36, 31 );
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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
|
|
|
function getLongDesc() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getLongDesc( $this );
|
|
|
|
|
} else {
|
2008-12-15 22:22:21 +00:00
|
|
|
return MediaHandler::getGeneralLongDesc( $this );
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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
|
|
|
function getShortDesc() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getShortDesc( $this );
|
|
|
|
|
} else {
|
2008-12-15 22:22:21 +00:00
|
|
|
return MediaHandler::getGeneralShortDesc( $this );
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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
|
|
|
function getDimensionsString() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getDimensionsString( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-16 18:31:00 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2008-01-16 18:31:00 +00:00
|
|
|
function getRedirected() {
|
|
|
|
|
return $this->redirected;
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
2008-05-20 17:05:57 +00:00
|
|
|
function getRedirectedTitle() {
|
|
|
|
|
if ( $this->redirected ) {
|
2011-04-12 00:16:04 +00:00
|
|
|
if ( !$this->redirectTitle ) {
|
2008-12-01 17:14:30 +00:00
|
|
|
$this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
|
2011-04-12 00:16:04 +00:00
|
|
|
}
|
2008-05-20 17:05:57 +00:00
|
|
|
return $this->redirectTitle;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-16 18:31:00 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @param $from
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-01-16 18:31:00 +00:00
|
|
|
function redirectedFrom( $from ) {
|
|
|
|
|
$this->redirected = $from;
|
|
|
|
|
}
|
2009-04-26 11:12:39 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2009-04-26 11:12:39 +00:00
|
|
|
function isMissing() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Aliases for backwards compatibility with 1.6
|
|
|
|
|
*/
|
|
|
|
|
define( 'MW_IMG_DELETED_FILE', File::DELETED_FILE );
|
|
|
|
|
define( 'MW_IMG_DELETED_COMMENT', File::DELETED_COMMENT );
|
|
|
|
|
define( 'MW_IMG_DELETED_USER', File::DELETED_USER );
|
|
|
|
|
define( 'MW_IMG_DELETED_RESTRICTED', File::DELETED_RESTRICTED );
|