2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
|
*/
|
2008-05-20 17:05:57 +00:00
|
|
|
var $repo, $title, $lastError, $redirected, $redirectedTitle;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
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',
|
|
|
|
|
'tiff' => 'tif' );
|
|
|
|
|
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
|
|
|
|
|
*/
|
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'.
|
|
|
|
|
*
|
|
|
|
|
* @param $mime "text/html" etc
|
|
|
|
|
* @return array ("text", "html") etc
|
|
|
|
|
*/
|
|
|
|
|
static function splitMime( $mime ) {
|
|
|
|
|
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
|
|
|
|
|
*/
|
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"
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
public function getTitle() { return $this->title; }
|
2008-05-20 17:05:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the title used to find this file
|
|
|
|
|
*/
|
|
|
|
|
public function getOriginalTitle() {
|
|
|
|
|
if ( $this->redirected )
|
|
|
|
|
return $this->getRedirectedTitle();
|
|
|
|
|
return $this->title;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the URL of the file
|
|
|
|
|
*/
|
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.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
|
function getViewURL() {
|
|
|
|
|
if( $this->mustRender()) {
|
|
|
|
|
if( $this->canRender() ) {
|
|
|
|
|
return $this->createThumb( $this->getWidth() );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* May return false if the file is not locally accessible.
|
|
|
|
|
*/
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Alias for getPath()
|
|
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
public function getFullPath() {
|
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
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +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
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +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'
|
|
|
|
|
*/
|
|
|
|
|
public function getUser( $type='text' ) { return null; }
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function getLength() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getLength( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get handler-specific metadata
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2007-06-24 06:35:47 +00:00
|
|
|
function getMetadata() { return false; }
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the size of the image file, in bytes
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +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
|
|
|
|
|
*/
|
|
|
|
|
function getMimeType() { return 'unknown/unknown'; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
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()
|
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.
|
|
|
|
|
*/
|
|
|
|
|
function isSafeFile() {
|
|
|
|
|
if ( !isset( $this->isSafeFile ) ) {
|
|
|
|
|
$this->isSafeFile = $this->_getIsSafeFile();
|
|
|
|
|
}
|
|
|
|
|
return $this->isSafeFile;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/** Accessor for __get() */
|
|
|
|
|
protected function getIsSafeFile() {
|
|
|
|
|
return $this->isSafeFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Uncached accessor */
|
|
|
|
|
protected function _getIsSafeFile() {
|
|
|
|
|
if ($this->allowInlineDisplay()) return true;
|
|
|
|
|
if ($this->isTrustedFile()) return true;
|
|
|
|
|
|
|
|
|
|
global $wgTrustedMediaFormats;
|
|
|
|
|
|
|
|
|
|
$type= $this->getMediaType();
|
|
|
|
|
$mime= $this->getMimeType();
|
|
|
|
|
#wfDebug("LocalFile::isSafeFile: type= $type, mime= $mime\n");
|
|
|
|
|
|
|
|
|
|
if (!$type || $type===MEDIATYPE_UNKNOWN) return false; #unknown type, not trusted
|
|
|
|
|
if ( in_array( $type, $wgTrustedMediaFormats) ) return true;
|
|
|
|
|
|
|
|
|
|
if ($mime==="unknown/unknown") return false; #unknown type, not trusted
|
|
|
|
|
if ( in_array( $mime, $wgTrustedMediaFormats) ) return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function isVisible() {
|
2008-03-09 03:10:28 +00:00
|
|
|
return $this->exists();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
function getUnscaledThumb( $page = false ) {
|
|
|
|
|
$width = $this->getWidth( $page );
|
|
|
|
|
if ( !$width ) {
|
|
|
|
|
return $this->iconThumb();
|
|
|
|
|
}
|
|
|
|
|
if ( $page ) {
|
|
|
|
|
$params = array(
|
|
|
|
|
'page' => $page,
|
|
|
|
|
'width' => $this->getWidth( $page )
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$params = array( 'width' => $this->getWidth() );
|
|
|
|
|
}
|
|
|
|
|
return $this->transform( $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the file name of a thumbnail with the specified parameters
|
|
|
|
|
*
|
|
|
|
|
* @param array $params Handler-specific parameters
|
2007-06-24 12:38:03 +00:00
|
|
|
* @private -ish
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 12:38:03 +00:00
|
|
|
function thumbName( $params ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$extension = $this->getExtension();
|
|
|
|
|
list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType() );
|
|
|
|
|
$thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getName();
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @param integer $width maximum width of the generated thumbnail
|
|
|
|
|
* @param integer $height maximum height of the image (optional)
|
|
|
|
|
*/
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* As createThumb, but returns a ThumbnailImage object. This can
|
|
|
|
|
* provide access to the actual file, the real size of the thumb,
|
|
|
|
|
* and can produce a convenient <img> tag for you.
|
|
|
|
|
*
|
|
|
|
|
* For non-image formats, this may return a filetype-specific icon.
|
|
|
|
|
*
|
|
|
|
|
* @param integer $width maximum width of the generated thumbnail
|
|
|
|
|
* @param integer $height maximum height of the image (optional)
|
|
|
|
|
* @param boolean $render True to render the thumbnail if it doesn't exist,
|
|
|
|
|
* false to just return the URL
|
|
|
|
|
*
|
|
|
|
|
* @return ThumbnailImage or null on failure
|
|
|
|
|
*
|
|
|
|
|
* @deprecated use transform()
|
|
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function getThumbnail( $width, $height=-1, $render = true ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$params = array( 'width' => $width );
|
|
|
|
|
if ( $height != -1 ) {
|
|
|
|
|
$params['height'] = $height;
|
|
|
|
|
}
|
|
|
|
|
$flags = $render ? self::RENDER_NOW : 0;
|
|
|
|
|
return $this->transform( $params, $flags );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transform a media file
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* @param array $params An associative array of handler-specific parameters. Typical
|
2007-05-30 21:02:32 +00:00
|
|
|
* keys are width, height and page.
|
|
|
|
|
* @param integer $flags A bitfield, may contain self::RENDER_NOW to force rendering
|
|
|
|
|
* @return MediaTransformOutput
|
|
|
|
|
*/
|
|
|
|
|
function transform( $params, $flags = 0 ) {
|
|
|
|
|
global $wgUseSquid, $wgIgnoreImageErrors;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
|
|
|
|
|
$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 );
|
|
|
|
|
if ( file_exists( $thumbPath ) ) {
|
|
|
|
|
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-02 21:29:05 +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
|
|
|
|
|
// "thumbs" which have the main image URL though (bug 13776)
|
2008-05-02 21:37:53 +00:00
|
|
|
if ( $wgUseSquid && ($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__ );
|
|
|
|
|
return $thumb;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
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
|
|
|
|
|
*/
|
|
|
|
|
function getThumbnails() { return array(); }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
function getHistory($limit = null, $start = null, $end = null) {
|
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.
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
function getRel() {
|
|
|
|
|
return $this->getHashPath() . $this->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get urlencoded relative path of the file
|
|
|
|
|
*/
|
|
|
|
|
function getUrlRel() {
|
2007-06-16 02:55:25 +00:00
|
|
|
return $this->getHashPath() . rawurlencode( $this->getName() );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/** Get the relative path for an archive file */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/** Get relative path for a thumbnail file */
|
|
|
|
|
function getThumbRel( $suffix = false ) {
|
|
|
|
|
$path = 'thumb/' . $this->getRel();
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $suffix !== false ) {
|
|
|
|
|
$path .= '/' . $suffix;
|
|
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/** Get the path of the archive directory, or a particular file if $suffix is specified */
|
|
|
|
|
function getArchivePath( $suffix = false ) {
|
2008-04-05 12:26:10 +00:00
|
|
|
return $this->repo->getZonePath('public') . '/' . $this->getArchiveRel( $suffix );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the path of the thumbnail directory, or a particular file if $suffix is specified */
|
|
|
|
|
function getThumbPath( $suffix = false ) {
|
|
|
|
|
return $this->repo->getZonePath('public') . '/' . $this->getThumbRel( $suffix );
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/** Get the URL of the archive directory, or a particular file if $suffix is specified */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the URL of the thumbnail directory, or a particular file if $suffix is specified */
|
|
|
|
|
function getThumbUrl( $suffix = false ) {
|
|
|
|
|
$path = $this->repo->getZoneUrl('public') . '/thumb/' . $this->getUrlRel();
|
|
|
|
|
if ( $suffix !== false ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the virtual URL for an archive file or directory */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the virtual URL for a thumbnail file or directory */
|
|
|
|
|
function getThumbVirtualUrl( $suffix = false ) {
|
2007-06-11 14:46:18 +00:00
|
|
|
$path = $this->repo->getVirtualUrl() . '/public/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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
/** Get the virtual URL for the file itself */
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
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
|
|
|
|
|
* destination, move it to an archive. Returns the archive name on success
|
|
|
|
|
* or an empty string if it was a new file, and a wikitext-formatted
|
|
|
|
|
* WikiError object on failure.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* The archive name should be passed through to recordUpload for database
|
|
|
|
|
* registration.
|
|
|
|
|
*
|
|
|
|
|
* @param string $sourcePath Local filesystem path to the source image
|
|
|
|
|
* @param integer $flags 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
|
2008-04-14 07:45:50 +00:00
|
|
|
* @return The archive name on success or an empty string if it was a new
|
|
|
|
|
* file, and a wikitext-formatted WikiError object on failure.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
|
|
|
|
function publish( $srcPath, $flags = 0 ) {
|
|
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an array of Title objects which are articles which use this file
|
|
|
|
|
* Also adds their IDs to the link cache
|
|
|
|
|
*
|
|
|
|
|
* This is mostly copied from Title::getLinksTo()
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use HTMLCacheUpdate, this function uses too much memory
|
|
|
|
|
*/
|
|
|
|
|
function getLinksTo( $options = '' ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// Note: use local DB not repo DB, we want to know local links
|
|
|
|
|
if ( $options ) {
|
|
|
|
|
$db = wfGetDB( DB_MASTER );
|
|
|
|
|
} else {
|
|
|
|
|
$db = wfGetDB( DB_SLAVE );
|
|
|
|
|
}
|
2008-04-09 18:23:34 +00:00
|
|
|
$linkCache = LinkCache::singleton();
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' );
|
|
|
|
|
$encName = $db->addQuotes( $this->getName() );
|
2008-04-14 07:45:50 +00:00
|
|
|
$sql = "SELECT page_namespace,page_title,page_id,page_len,page_is_redirect,
|
2008-04-08 20:34:09 +00:00
|
|
|
FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
|
2007-05-30 21:02:32 +00:00
|
|
|
$res = $db->query( $sql, __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$retVal = array();
|
|
|
|
|
if ( $db->numRows( $res ) ) {
|
|
|
|
|
while ( $row = $db->fetchObject( $res ) ) {
|
2008-04-08 20:34:09 +00:00
|
|
|
if ( $titleObj = Title::newFromRow( $row ) ) {
|
2008-04-09 05:21:00 +00:00
|
|
|
$linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
|
2007-05-30 21:02:32 +00:00
|
|
|
$retVal[] = $titleObj;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$db->freeResult( $res );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $retVal;
|
|
|
|
|
}
|
|
|
|
|
|
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() {
|
|
|
|
|
return $this->getRepoName() == 'local';
|
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
|
|
|
}
|
2008-05-15 19:17:21 +00:00
|
|
|
/*
|
|
|
|
|
* Returns the repository
|
|
|
|
|
*/
|
|
|
|
|
function getRepo() {
|
|
|
|
|
return $this->repo;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the image is an old version
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function isOld() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this file a "deleted" file in a private archive?
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function isDeleted( $field ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Was this file ever deleted from the wiki?
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function wasDeleted() {
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
return $title && $title->isDeleted() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @param $reason
|
2008-03-15 07:59:21 +00:00
|
|
|
* @param $suppress, 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.
|
|
|
|
|
*
|
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.
|
2008-03-15 00:27:57 +00:00
|
|
|
* @param $unsuppress, remove restrictions on content upon restoration?
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return the number of file revisions restored if successful,
|
|
|
|
|
* or false on failure
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2008-03-15 00:27:57 +00:00
|
|
|
function restore( $versions=array(), $unsuppress=false ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns 'true' if this image is a multipage document, e.g. a DJVU
|
|
|
|
|
* document.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of pages of a multipage document, or NULL for
|
|
|
|
|
* documents which aren't multipage documents
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
/**
|
2008-04-14 07:45:50 +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.
|
|
|
|
|
*
|
|
|
|
|
* @param string $fileName The filename
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
function getDescriptionUrl() {
|
|
|
|
|
return $this->repo->getDescriptionUrl( $this->getName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTML text of the description page, if available
|
|
|
|
|
*/
|
|
|
|
|
function getDescriptionText() {
|
|
|
|
|
if ( !$this->repo->fetchDescription ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() );
|
|
|
|
|
if ( $renderUrl ) {
|
|
|
|
|
wfDebug( "Fetching shared description from $renderUrl\n" );
|
|
|
|
|
return Http::get( $renderUrl );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Get discription of file revision
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
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
|
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
|
|
|
|
|
*/
|
|
|
|
|
function getSha1() {
|
|
|
|
|
return self::sha1Base36( $this->getPath() );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +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
|
2008-04-14 07:45:50 +00:00
|
|
|
* @param int $field
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
*
|
|
|
|
|
* @param string $path Absolute local filesystem path
|
2008-04-14 07:45:50 +00:00
|
|
|
* @param mixed $ext The file extension, or true to extract it from the filename.
|
2007-06-18 06:35:20 +00:00
|
|
|
* Set it to false to ignore the extension.
|
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();
|
|
|
|
|
|
2007-06-18 06:35:20 +00:00
|
|
|
$info['mime'] = $magic->guessMimeType( $path, $ext );
|
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 {
|
|
|
|
|
$info['mime'] = NULL;
|
|
|
|
|
$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.
|
|
|
|
|
*
|
|
|
|
|
* Returns false on failure
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
|
function getLongDesc() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getLongDesc( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return MediaHandler::getLongDesc( $this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getShortDesc() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getShortDesc( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return MediaHandler::getShortDesc( $this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDimensionsString() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getDimensionsString( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-16 18:31:00 +00:00
|
|
|
|
|
|
|
|
function getRedirected() {
|
|
|
|
|
return $this->redirected;
|
|
|
|
|
}
|
2008-05-20 17:05:57 +00:00
|
|
|
|
|
|
|
|
function getRedirectedTitle() {
|
|
|
|
|
if ( $this->redirected ) {
|
|
|
|
|
if ( !$this->redirectTitle )
|
|
|
|
|
$this->redirectTitle = Title::makeTitle( NS_IMAGE, $this->redirected );
|
|
|
|
|
return $this->redirectTitle;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-16 18:31:00 +00:00
|
|
|
|
|
|
|
|
function redirectedFrom( $from ) {
|
|
|
|
|
$this->redirected = $from;
|
|
|
|
|
}
|
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 );
|