2007-04-20 12:31:36 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-05-03 20:13:10 +00:00
|
|
|
* Media-handling base classes and generic functionality.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-15 17:27:41 +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
|
|
|
* @file
|
|
|
|
|
* @ingroup Media
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-07-26 02:19:25 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base media handler class
|
2007-04-24 06:53:31 +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 Media
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
abstract class MediaHandler {
|
|
|
|
|
const TRANSFORM_LATER = 1;
|
2011-04-16 01:23:15 +00:00
|
|
|
const METADATA_GOOD = true;
|
|
|
|
|
const METADATA_BAD = false;
|
|
|
|
|
const METADATA_COMPATIBLE = 2; // for old but backwards compatible.
|
2013-12-04 17:00:21 +00:00
|
|
|
/**
|
|
|
|
|
* Max length of error logged by logErrorForExternalProcess()
|
|
|
|
|
*/
|
|
|
|
|
const MAX_ERR_LOG_SIZE = 65535;
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Get a MediaHandler for a given MIME type from the instance cache
|
2011-02-18 23:56:08 +00:00
|
|
|
*
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param string $type
|
2016-07-26 00:27:24 +00:00
|
|
|
* @return MediaHandler|bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
static function getHandler( $type ) {
|
2016-07-26 02:19:25 +00:00
|
|
|
return MediaWikiServices::getInstance()
|
|
|
|
|
->getMediaHandlerFactory()->getHandler( $type );
|
2014-07-15 23:56:34 +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 an associative array mapping magic word IDs to parameter names.
|
|
|
|
|
* Will be used by the parser to identify parameters.
|
|
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
abstract public function getParamMap();
|
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-21 19:35:16 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Validate a thumbnail parameter at parse time.
|
2007-04-20 12:31:36 +00:00
|
|
|
* Return true to accept the parameter, and false to reject it.
|
|
|
|
|
* If you return false, the parser will do something quiet and forgiving.
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param string $name
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param mixed $value
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
abstract public function validateParam( $name, $value );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Merge a parameter array into a string appropriate for inclusion in filenames
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param array $params Array of parameters that have been through normaliseParams.
|
|
|
|
|
* @return string
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
abstract public function makeParamString( $params );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse a param string made with makeParamString back into an array
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param string $str The parameter string without file name (e.g. 122px)
|
|
|
|
|
* @return array|bool Array of parameters or false on failure.
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
abstract public function parseParamString( $str );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Changes the parameter array as necessary, ready for transformation.
|
2007-04-20 12:31:36 +00:00
|
|
|
* Should be idempotent.
|
|
|
|
|
* Returns false if the parameters are unacceptable and the transform should fail
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $image
|
2017-08-11 00:23:16 +00:00
|
|
|
* @param array &$params
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
abstract function normaliseParams( $image, &$params );
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get an image size array like that returned by getimagesize(), or false if it
|
2007-04-20 12:31:36 +00:00
|
|
|
* can't be determined.
|
|
|
|
|
*
|
2014-06-20 00:16:28 +00:00
|
|
|
* This function is used for determining the width, height and bitdepth directly
|
|
|
|
|
* from an image. The results are stored in the database in the img_width,
|
|
|
|
|
* img_height, img_bits fields.
|
|
|
|
|
*
|
|
|
|
|
* @note If this is a multipage file, return the width and height of the
|
|
|
|
|
* first page.
|
|
|
|
|
*
|
2016-09-19 01:39:59 +00:00
|
|
|
* @param File|FSFile $image The image object, or false if there isn't one.
|
|
|
|
|
* Warning, FSFile::getPropsFromPath might pass an FSFile instead of File (!)
|
2014-07-24 17:43:25 +00:00
|
|
|
* @param string $path The filename
|
2016-09-19 01:39:59 +00:00
|
|
|
* @return array|bool Follow the format of PHP getimagesize() internal function.
|
2016-10-13 05:34:26 +00:00
|
|
|
* See https://secure.php.net/getimagesize. MediaWiki will only ever use the
|
2014-06-20 00:16:28 +00:00
|
|
|
* first two array keys (the width and height), and the 'bits' associative
|
|
|
|
|
* key. All other array keys are ignored. Returning a 'bits' key is optional
|
2016-09-19 01:39:59 +00:00
|
|
|
* as not all formats have a notion of "bitdepth". Returns false on failure.
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
abstract function getImageSize( $image, $path );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get handler-specific metadata which will be saved in the img_metadata field.
|
|
|
|
|
*
|
2016-09-19 01:39:59 +00:00
|
|
|
* @param File|FSFile $image The image object, or false if there isn't one.
|
|
|
|
|
* Warning, FSFile::getPropsFromPath might pass an FSFile instead of File (!)
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param string $path The filename
|
2014-06-20 00:16:28 +00:00
|
|
|
* @return string A string of metadata in php serialized form (Run through serialize())
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2013-04-20 21:11:46 +00:00
|
|
|
function getMetadata( $image, $path ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
2011-04-16 01:23:15 +00:00
|
|
|
/**
|
2013-03-07 16:27:38 +00:00
|
|
|
* Get metadata version.
|
|
|
|
|
*
|
|
|
|
|
* This is not used for validating metadata, this is used for the api when returning
|
|
|
|
|
* metadata, since api content formats should stay the same over time, and so things
|
2014-06-20 00:16:28 +00:00
|
|
|
* using ForeignApiRepo can keep backwards compatibility
|
2013-03-07 16:27:38 +00:00
|
|
|
*
|
|
|
|
|
* All core media handlers share a common version number, and extensions can
|
|
|
|
|
* use the GetMetadataVersion hook to append to the array (they should append a unique
|
|
|
|
|
* string so not to get confusing). If there was a media handler named 'foo' with metadata
|
|
|
|
|
* version 3 it might add to the end of the array the element 'foo=3'. if the core metadata
|
|
|
|
|
* version is 2, the end version string would look like '2;foo=3'.
|
|
|
|
|
*
|
2013-11-23 18:17:19 +00:00
|
|
|
* @return string Version string
|
2013-03-07 16:27:38 +00:00
|
|
|
*/
|
2013-03-18 19:44:43 +00:00
|
|
|
static function getMetadataVersion() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$version = [ '2' ]; // core metadata version
|
|
|
|
|
Hooks::run( 'GetMetadataVersion', [ &$version ] );
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2013-03-24 10:01:51 +00:00
|
|
|
return implode( ';', $version );
|
2013-02-03 19:42:08 +00:00
|
|
|
}
|
2011-04-16 01:23:15 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-03-07 16:27:38 +00:00
|
|
|
* Convert metadata version.
|
|
|
|
|
*
|
|
|
|
|
* By default just returns $metadata, but can be used to allow
|
|
|
|
|
* media handlers to convert between metadata versions.
|
|
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string|array $metadata Metadata array (serialized if string)
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param int $version Target version
|
|
|
|
|
* @return array Serialized metadata in specified version, or $metadata on fail.
|
2013-03-07 16:27:38 +00:00
|
|
|
*/
|
2011-04-16 01:23:15 +00:00
|
|
|
function convertMetadataVersion( $metadata, $version = 1 ) {
|
|
|
|
|
if ( !is_array( $metadata ) ) {
|
2015-09-11 13:44:59 +00:00
|
|
|
// unserialize to keep return parameter consistent.
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2011-04-16 11:17:14 +00:00
|
|
|
$ret = unserialize( $metadata );
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2011-04-16 11:17:14 +00:00
|
|
|
return $ret;
|
2011-04-16 01:23:15 +00:00
|
|
|
}
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2011-04-16 01:23:15 +00:00
|
|
|
return $metadata;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Get a string describing the type of metadata, for display purposes.
|
2014-06-20 00:16:28 +00:00
|
|
|
*
|
|
|
|
|
* @note This method is currently unused.
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $image
|
2011-05-28 18:59:42 +00:00
|
|
|
* @return string
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2013-04-20 21:11:46 +00:00
|
|
|
function getMetadataType( $image ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the metadata string is valid for this handler.
|
2011-04-16 01:23:15 +00:00
|
|
|
* If it returns MediaHandler::METADATA_BAD (or false), Image
|
|
|
|
|
* will reload the metadata from the file and update the database.
|
|
|
|
|
* MediaHandler::METADATA_GOOD for if the metadata is a-ok,
|
2014-06-20 00:16:28 +00:00
|
|
|
* MediaHandler::METADATA_COMPATIBLE if metadata is old but backwards
|
2011-04-16 01:23:15 +00:00
|
|
|
* compatible (which may or may not trigger a metadata reload).
|
2014-06-20 00:16:28 +00:00
|
|
|
*
|
|
|
|
|
* @note Returning self::METADATA_BAD will trigger a metadata reload from
|
|
|
|
|
* file on page view. Always returning this from a broken file, or suddenly
|
|
|
|
|
* triggering as bad metadata for a large number of files can cause
|
|
|
|
|
* performance problems.
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $image
|
2014-06-20 00:16:28 +00:00
|
|
|
* @param string $metadata The metadata in serialized form
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-06-26 19:16:04 +00:00
|
|
|
function isMetadataValid( $image, $metadata ) {
|
2011-04-16 01:23:15 +00:00
|
|
|
return self::METADATA_GOOD;
|
|
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
2013-08-28 23:09:07 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array of standard (FormatMetadata type) metadata values.
|
|
|
|
|
*
|
|
|
|
|
* The returned data is largely the same as that from getMetadata(),
|
|
|
|
|
* but formatted in a standard, stable, handler-independent way.
|
|
|
|
|
* The idea being that some values like ImageDescription or Artist
|
|
|
|
|
* are universal and should be retrievable in a handler generic way.
|
|
|
|
|
*
|
|
|
|
|
* The specific properties are the type of properties that can be
|
|
|
|
|
* handled by the FormatMetadata class. These values are exposed to the
|
|
|
|
|
* user via the filemetadata parser function.
|
|
|
|
|
*
|
|
|
|
|
* Details of the response format of this function can be found at
|
|
|
|
|
* https://www.mediawiki.org/wiki/Manual:File_metadata_handling
|
|
|
|
|
* tl/dr: the response is an associative array of
|
|
|
|
|
* properties keyed by name, but the value can be complex. You probably
|
|
|
|
|
* want to call one of the FormatMetadata::flatten* functions on the
|
|
|
|
|
* property values before using them, or call
|
|
|
|
|
* FormatMetadata::getFormattedData() on the full response array, which
|
|
|
|
|
* transforms all values into prettified, human-readable text.
|
|
|
|
|
*
|
2013-08-12 16:18:29 +00:00
|
|
|
* Subclasses overriding this function must return a value which is a
|
|
|
|
|
* valid API response fragment (all associative array keys are valid
|
|
|
|
|
* XML tagnames).
|
|
|
|
|
*
|
2013-08-28 23:09:07 +00:00
|
|
|
* Note, if the file simply has no metadata, but the handler supports
|
|
|
|
|
* this interface, it should return an empty array, not false.
|
|
|
|
|
*
|
|
|
|
|
* @param File $file
|
2013-11-23 18:17:19 +00:00
|
|
|
* @return array|bool False if interface not supported
|
2013-08-28 23:09:07 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getCommonMetaArray( File $file ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-22 03:31:10 +00:00
|
|
|
/**
|
|
|
|
|
* Get a MediaTransformOutput object representing an alternate of the transformed
|
|
|
|
|
* output which will call an intermediary thumbnail assist script.
|
|
|
|
|
*
|
|
|
|
|
* Used when the repository has a thumbnailScriptUrl option configured.
|
|
|
|
|
*
|
|
|
|
|
* Return false to fall back to the regular getTransform().
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $image
|
|
|
|
|
* @param string $script
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool|ThumbnailImage
|
2008-01-22 03:31:10 +00:00
|
|
|
*/
|
|
|
|
|
function getScriptedTransform( $image, $script, $params ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get a MediaTransformOutput object representing the transformed output. Does not
|
2007-04-20 12:31:36 +00:00
|
|
|
* actually do the transform.
|
|
|
|
|
*
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param File $image
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string $dstPath Filesystem destination path
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $dstUrl Destination URL to use in output HTML
|
|
|
|
|
* @param array $params Arbitrary set of parameters validated by $this->validateParam()
|
2012-02-13 16:35:59 +00:00
|
|
|
* @return MediaTransformOutput
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
final function getTransform( $image, $dstPath, $dstUrl, $params ) {
|
2007-04-20 12:31:36 +00:00
|
|
|
return $this->doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get a MediaTransformOutput object representing the transformed output. Does the
|
2007-04-20 12:31:36 +00:00
|
|
|
* transform unless $flags contains self::TRANSFORM_LATER.
|
|
|
|
|
*
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param File $image
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string $dstPath Filesystem destination path
|
|
|
|
|
* @param string $dstUrl Destination URL to use in output HTML
|
|
|
|
|
* @param array $params Arbitrary set of parameters validated by $this->validateParam()
|
2013-06-15 01:02:44 +00:00
|
|
|
* Note: These parameters have *not* gone through $this->normaliseParams()
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param int $flags A bitfield, may contain self::TRANSFORM_LATER
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return MediaTransformOutput
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
abstract function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the thumbnail extension and MIME type for a given source MIME type
|
2013-06-05 17:28:13 +00:00
|
|
|
*
|
2013-11-23 18:17:19 +00:00
|
|
|
* @param string $ext Extension of original file
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string $mime MIME type of original file
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param array|null $params Handler specific rendering parameters
|
2014-07-24 17:43:25 +00:00
|
|
|
* @return array Thumbnail extension and MIME type
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2010-06-22 16:01:54 +00:00
|
|
|
function getThumbType( $ext, $mime, $params = null ) {
|
2017-11-27 01:33:57 +00:00
|
|
|
$magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
|
2011-02-06 19:20:57 +00:00
|
|
|
if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) === false ) {
|
2014-07-24 14:04:48 +00:00
|
|
|
// The extension is not valid for this MIME type and we do
|
|
|
|
|
// recognize the MIME type
|
2011-02-06 19:20:57 +00:00
|
|
|
$extensions = $magic->getExtensionsForType( $mime );
|
|
|
|
|
if ( $extensions ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ strtok( $extensions, ' ' ), $mime ];
|
2011-02-06 19:20:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-26 19:16:04 +00:00
|
|
|
|
2014-07-24 14:04:48 +00:00
|
|
|
// The extension is correct (true) or the MIME type is unknown to
|
2011-02-06 19:20:57 +00:00
|
|
|
// MediaWiki (null)
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $ext, $mime ];
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if the handled types can be transformed
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
public function canRender( $file ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* True if handled types cannot be displayed directly in a browser
|
2007-04-20 12:31:36 +00:00
|
|
|
* but can be rendered
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
public function mustRender( $file ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* True if the type has multi-page capabilities
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
public function isMultiPage( $file ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Page count for a multi-page document, false if unsupported or unknown
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2015-10-26 17:43:21 +00:00
|
|
|
function pageCount( File $file ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 21:49:25 +00:00
|
|
|
/**
|
|
|
|
|
* The material is vectorized and thus scaling is lossless
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2010-10-31 21:49:25 +00:00
|
|
|
*/
|
2013-04-20 21:11:46 +00:00
|
|
|
function isVectorized( $file ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 01:19:53 +00:00
|
|
|
/**
|
|
|
|
|
* The material is an image, and is animated.
|
|
|
|
|
* In particular, video material need not return true.
|
|
|
|
|
* @note Before 1.20, this was a method of ImageHandler only
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-08-19 01:19:53 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2013-04-20 21:11:46 +00:00
|
|
|
function isAnimatedImage( $file ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 01:19:53 +00:00
|
|
|
/**
|
|
|
|
|
* If the material is animated, we can animate the thumbnail
|
|
|
|
|
* @since 1.20
|
2013-12-05 19:27:27 +00:00
|
|
|
*
|
|
|
|
|
* @param File $file
|
2012-08-19 01:19:53 +00:00
|
|
|
* @return bool If material is not animated, handler may return any value.
|
|
|
|
|
*/
|
2013-04-20 21:11:46 +00:00
|
|
|
function canAnimateThumbnail( $file ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* False if the handler is disabled for all files
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2013-04-20 21:11:46 +00:00
|
|
|
function isEnabled() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an associative array of page dimensions
|
2008-04-14 07:45:50 +00:00
|
|
|
* Currently "width" and "height" are understood, but this might be
|
2007-04-20 12:31:36 +00:00
|
|
|
* expanded in the future.
|
2013-04-16 21:34:43 +00:00
|
|
|
* Returns false if unknown.
|
|
|
|
|
*
|
|
|
|
|
* It is expected that handlers for paged media (e.g. DjVuHandler)
|
|
|
|
|
* will override this method so that it gives the correct results
|
|
|
|
|
* for each specific page of the file, using the $page argument.
|
|
|
|
|
*
|
|
|
|
|
* @note For non-paged media, use getImageSize.
|
2011-02-18 23:34:24 +00:00
|
|
|
*
|
2013-12-04 16:14:01 +00:00
|
|
|
* @param File $image
|
|
|
|
|
* @param int $page What page to get dimensions of
|
2013-04-16 21:34:43 +00:00
|
|
|
* @return array|bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2015-10-26 17:43:21 +00:00
|
|
|
function getPageDimensions( File $image, $page ) {
|
2011-12-20 03:52:06 +00:00
|
|
|
$gis = $this->getImageSize( $image, $image->getLocalRefPath() );
|
2013-04-16 21:34:43 +00:00
|
|
|
if ( $gis ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2013-04-16 21:34:43 +00:00
|
|
|
'width' => $gis[0],
|
|
|
|
|
'height' => $gis[1]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-04-16 21:34:43 +00:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
2007-07-28 01:15:35 +00:00
|
|
|
|
2009-09-23 12:28:19 +00:00
|
|
|
/**
|
|
|
|
|
* Generic getter for text layer.
|
|
|
|
|
* Currently overloaded by PDF and DjVu handlers
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $image
|
|
|
|
|
* @param int $page Page number to get information for
|
2013-12-06 19:34:49 +00:00
|
|
|
* @return bool|string Page text or false when no text found or if
|
|
|
|
|
* unsupported.
|
2009-09-23 12:28:19 +00:00
|
|
|
*/
|
2015-10-26 17:43:21 +00:00
|
|
|
function getPageText( File $image, $page ) {
|
2009-09-23 12:28:19 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 19:34:49 +00:00
|
|
|
/**
|
|
|
|
|
* Get the text of the entire document.
|
|
|
|
|
* @param File $file
|
|
|
|
|
* @return bool|string The text of the document or false if unsupported.
|
|
|
|
|
*/
|
|
|
|
|
public function getEntireText( File $file ) {
|
|
|
|
|
$numPages = $file->pageCount();
|
|
|
|
|
if ( !$numPages ) {
|
|
|
|
|
// Not a multipage document
|
|
|
|
|
return $this->getPageText( $file, 1 );
|
|
|
|
|
}
|
|
|
|
|
$document = '';
|
2013-12-15 19:56:09 +00:00
|
|
|
for ( $i = 1; $i <= $numPages; $i++ ) {
|
2013-12-06 19:34:49 +00:00
|
|
|
$curPage = $this->getPageText( $file, $i );
|
|
|
|
|
if ( is_string( $curPage ) ) {
|
|
|
|
|
$document .= $curPage . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $document !== '' ) {
|
|
|
|
|
return $document;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-28 01:15:35 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array structure that looks like this:
|
|
|
|
|
*
|
2016-09-27 03:15:08 +00:00
|
|
|
* [
|
|
|
|
|
* 'visible' => [
|
2007-07-28 01:15:35 +00:00
|
|
|
* 'Human-readable name' => 'Human readable value',
|
|
|
|
|
* ...
|
2016-09-27 03:15:08 +00:00
|
|
|
* ],
|
|
|
|
|
* 'collapsed' => [
|
2007-07-28 01:15:35 +00:00
|
|
|
* 'Human-readable name' => 'Human readable value',
|
|
|
|
|
* ...
|
2016-09-27 03:15:08 +00:00
|
|
|
* ]
|
|
|
|
|
* ]
|
2008-04-14 07:45:50 +00:00
|
|
|
* The UI will format this into a table where the visible fields are always
|
2007-07-28 01:15:35 +00:00
|
|
|
* visible, and the collapsed fields are optionally visible.
|
|
|
|
|
*
|
|
|
|
|
* The function should return false if there is no metadata to display.
|
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
/**
|
2013-12-05 19:27:27 +00:00
|
|
|
* @todo FIXME: This interface is not very flexible. The media handler
|
|
|
|
|
* should generate HTML instead. It can do all the formatting according
|
|
|
|
|
* to some standard. That makes it possible to do things like visual
|
|
|
|
|
* indication of grouped and chained streams in ogg container files.
|
|
|
|
|
* @param File $image
|
2014-12-28 20:31:34 +00:00
|
|
|
* @param bool|IContextSource $context Context to use (optional)
|
2013-12-05 19:27:27 +00:00
|
|
|
* @return array|bool
|
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
|
|
|
*/
|
2014-12-28 20:31:34 +00:00
|
|
|
function formatMetadata( $image, $context = false ) {
|
2007-07-28 01:15:35 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
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-04-16 01:23:15 +00:00
|
|
|
/** sorts the visible/invisible field.
|
|
|
|
|
* Split off from ImageHandler::formatMetadata, as used by more than
|
|
|
|
|
* one type of handler.
|
|
|
|
|
*
|
|
|
|
|
* This is used by the media handlers that use the FormatMetadata class
|
|
|
|
|
*
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param array $metadataArray
|
2014-12-28 20:31:34 +00:00
|
|
|
* @param bool|IContextSource $context Context to use (optional)
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return array Array for use displaying metadata.
|
2011-04-16 01:23:15 +00:00
|
|
|
*/
|
2014-12-28 20:31:34 +00:00
|
|
|
function formatMetadataHelper( $metadataArray, $context = false ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result = [
|
|
|
|
|
'visible' => [],
|
|
|
|
|
'collapsed' => []
|
|
|
|
|
];
|
2011-04-16 01:23:15 +00:00
|
|
|
|
2014-12-28 20:31:34 +00:00
|
|
|
$formatted = FormatMetadata::getFormattedData( $metadataArray, $context );
|
2011-04-16 01:23:15 +00:00
|
|
|
// Sort fields into visible and collapsed
|
|
|
|
|
$visibleFields = $this->visibleMetadataFields();
|
|
|
|
|
foreach ( $formatted as $name => $value ) {
|
|
|
|
|
$tag = strtolower( $name );
|
|
|
|
|
self::addMeta( $result,
|
|
|
|
|
in_array( $tag, $visibleFields ) ? 'visible' : 'collapsed',
|
|
|
|
|
'exif',
|
|
|
|
|
$tag,
|
|
|
|
|
$value
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2011-04-16 01:23:15 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of metadata items which should be displayed when
|
|
|
|
|
* the metadata table is collapsed.
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return array Array of strings
|
2011-04-16 01:23:15 +00:00
|
|
|
*/
|
2013-12-05 19:40:38 +00:00
|
|
|
protected function visibleMetadataFields() {
|
2013-08-12 16:18:29 +00:00
|
|
|
return FormatMetadata::getVisibleFields();
|
2011-04-16 01:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-25 22:25:17 +00:00
|
|
|
/**
|
2011-04-16 01:23:15 +00:00
|
|
|
* This is used to generate an array element for each metadata value
|
|
|
|
|
* That array is then used to generate the table of metadata values
|
2011-06-26 19:16:04 +00:00
|
|
|
* on the image page
|
2011-04-16 01:23:15 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param array &$array An array containing elements for each type of visibility
|
|
|
|
|
* and each of those elements being an array of metadata items. This function adds
|
|
|
|
|
* a value to that array.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $visibility ('visible' or 'collapsed') if this value is hidden
|
2013-12-05 19:27:27 +00:00
|
|
|
* by default.
|
|
|
|
|
* @param string $type Type of metadata tag (currently always 'exif')
|
|
|
|
|
* @param string $id The name of the metadata tag (like 'artist' for example).
|
|
|
|
|
* its name in the table displayed is the message "$type-$id" (Ex exif-artist ).
|
|
|
|
|
* @param string $value Thingy goes into a wikitext table; it used to be escaped but
|
|
|
|
|
* that was incompatible with previous practise of customized display
|
|
|
|
|
* with wikitext formatting via messages such as 'exif-model-value'.
|
|
|
|
|
* So the escaping is taken back out, but generally this seems a confusing
|
|
|
|
|
* interface.
|
|
|
|
|
* @param bool|string $param Value to pass to the message for the name of the field
|
|
|
|
|
* as $1. Currently this parameter doesn't seem to ever be used.
|
2011-04-16 01:23:15 +00:00
|
|
|
*
|
|
|
|
|
* Note, everything here is passed through the parser later on (!)
|
2007-08-25 22:25:17 +00:00
|
|
|
*/
|
2007-07-28 01:15:35 +00:00
|
|
|
protected static function addMeta( &$array, $visibility, $type, $id, $value, $param = false ) {
|
2011-09-25 14:38:54 +00:00
|
|
|
$msg = wfMessage( "$type-$id", $param );
|
|
|
|
|
if ( $msg->exists() ) {
|
|
|
|
|
$name = $msg->text();
|
|
|
|
|
} else {
|
2011-04-16 01:23:15 +00:00
|
|
|
// This is for future compatibility when using instant commons.
|
2011-06-26 19:16:04 +00:00
|
|
|
// So as to not display as ugly a name if a new metadata
|
2011-04-16 01:23:15 +00:00
|
|
|
// property is defined that we don't know about
|
|
|
|
|
// (not a major issue since such a property would be collapsed
|
|
|
|
|
// by default).
|
|
|
|
|
wfDebug( __METHOD__ . ' Unknown metadata name: ' . $id . "\n" );
|
|
|
|
|
$name = wfEscapeWikiText( $id );
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$array[$visibility][] = [
|
2007-07-28 01:15:35 +00:00
|
|
|
'id' => "$type-$id",
|
2011-04-16 01:23:15 +00:00
|
|
|
'name' => $name,
|
2007-08-25 22:25:17 +00:00
|
|
|
'value' => $value
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2007-07-28 01:15:35 +00:00
|
|
|
}
|
2008-12-15 22:22:21 +00:00
|
|
|
|
2011-02-18 23:34:24 +00:00
|
|
|
/**
|
2014-05-24 19:10:46 +00:00
|
|
|
* Short description. Shown on Special:Search results.
|
2013-06-15 01:02:44 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2011-02-18 23:34:24 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-04-26 18:16:43 +00:00
|
|
|
function getShortDesc( $file ) {
|
2014-05-24 19:58:43 +00:00
|
|
|
return self::getGeneralShortDesc( $file );
|
2008-12-15 21:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-18 23:34:24 +00:00
|
|
|
/**
|
2014-05-24 19:10:46 +00:00
|
|
|
* Long description. Shown under image on image description page surounded by ().
|
2013-06-15 01:02:44 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2011-02-18 23:34:24 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-12-15 21:38:04 +00:00
|
|
|
function getLongDesc( $file ) {
|
2014-05-24 19:58:43 +00:00
|
|
|
return self::getGeneralLongDesc( $file );
|
2008-12-15 22:22:21 +00:00
|
|
|
}
|
2011-02-18 23:34:24 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-05-24 19:10:46 +00:00
|
|
|
* Used instead of getShortDesc if there is no handler registered for file.
|
2013-06-15 01:02:44 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2011-02-18 23:34:24 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-12-15 22:22:21 +00:00
|
|
|
static function getGeneralShortDesc( $file ) {
|
2012-01-19 16:44:49 +00:00
|
|
|
global $wgLang;
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2014-05-24 19:58:43 +00:00
|
|
|
return htmlspecialchars( $wgLang->formatSize( $file->getSize() ) );
|
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-02-18 23:34:24 +00:00
|
|
|
/**
|
2014-05-24 19:10:46 +00:00
|
|
|
* Used instead of getLongDesc if there is no handler registered for file.
|
2013-06-15 01:02:44 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2011-02-18 23:34:24 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-12-15 22:22:21 +00:00
|
|
|
static function getGeneralLongDesc( $file ) {
|
2014-05-24 19:58:43 +00:00
|
|
|
return wfMessage( 'file-info' )->sizeParams( $file->getSize() )
|
2015-03-05 18:52:11 +00:00
|
|
|
->params( '<span class="mime-type">' . $file->getMimeType() . '</span>' )->parse();
|
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-07-28 00:07:08 +00:00
|
|
|
/**
|
|
|
|
|
* Calculate the largest thumbnail width for a given original file size
|
|
|
|
|
* such that the thumbnail's height is at most $maxHeight.
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param int $boxWidth Width of the thumbnail box.
|
|
|
|
|
* @param int $boxHeight Height of the thumbnail box.
|
|
|
|
|
* @param int $maxHeight Maximum height expected for the thumbnail.
|
|
|
|
|
* @return int
|
2011-07-28 00:07:08 +00:00
|
|
|
*/
|
|
|
|
|
public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
|
|
|
|
|
$idealWidth = $boxWidth * $maxHeight / $boxHeight;
|
|
|
|
|
$roundedUp = ceil( $idealWidth );
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
|
2011-07-28 00:07:08 +00:00
|
|
|
return floor( $idealWidth );
|
|
|
|
|
} else {
|
|
|
|
|
return $roundedUp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 01:02:44 +00:00
|
|
|
/**
|
|
|
|
|
* Shown in file history box on image description page.
|
|
|
|
|
*
|
|
|
|
|
* @param File $file
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return string Dimensions
|
2013-06-15 01:02:44 +00:00
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
function getDimensionsString( $file ) {
|
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 '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-15 01:02:44 +00:00
|
|
|
* Modify the parser object post-transform.
|
|
|
|
|
*
|
|
|
|
|
* This is often used to do $parser->addOutputHook(),
|
|
|
|
|
* in order to add some javascript to render a viewer.
|
|
|
|
|
* See TimedMediaHandler or OggHandler for an example.
|
|
|
|
|
*
|
|
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param File $file
|
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
|
|
|
*/
|
2013-12-05 10:05:05 +00:00
|
|
|
function parserTransformHook( $parser, $file ) {
|
|
|
|
|
}
|
2007-09-04 15:13:55 +00:00
|
|
|
|
2010-08-31 14:08:45 +00:00
|
|
|
/**
|
2010-09-07 10:38:19 +00:00
|
|
|
* File validation hook called on upload.
|
2010-08-31 14:08:45 +00:00
|
|
|
*
|
2011-06-26 19:16:04 +00:00
|
|
|
* If the file at the given local path is not valid, or its MIME type does not
|
2010-09-07 10:38:19 +00:00
|
|
|
* match the handler class, a Status object should be returned containing
|
|
|
|
|
* relevant errors.
|
2011-06-26 19:16:04 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $fileName The local path to the file.
|
2014-07-24 17:43:25 +00:00
|
|
|
* @return Status
|
2010-08-31 14:08:45 +00:00
|
|
|
*/
|
2010-09-07 10:38:19 +00:00
|
|
|
function verifyUpload( $fileName ) {
|
|
|
|
|
return Status::newGood();
|
2010-08-31 14:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-04 15:13:55 +00:00
|
|
|
/**
|
|
|
|
|
* Check for zero-sized thumbnails. These can be generated when
|
|
|
|
|
* no disk space is available or some other error occurs
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $dstPath The location of the suspect file
|
|
|
|
|
* @param int $retval Return value of some shell process, file will be deleted if this is non-zero
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return bool True if removed, false otherwise
|
2007-09-04 15:13:55 +00:00
|
|
|
*/
|
|
|
|
|
function removeBadFile( $dstPath, $retval = 0 ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( file_exists( $dstPath ) ) {
|
2007-09-04 15:13:55 +00:00
|
|
|
$thumbstat = stat( $dstPath );
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $thumbstat['size'] == 0 || $retval != 0 ) {
|
2011-08-19 23:06:54 +00:00
|
|
|
$result = unlink( $dstPath );
|
2011-08-21 15:24:44 +00:00
|
|
|
|
|
|
|
|
if ( $result ) {
|
|
|
|
|
wfDebugLog( 'thumbnail',
|
|
|
|
|
sprintf( 'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
|
|
|
|
|
$thumbstat['size'], $dstPath ) );
|
|
|
|
|
} else {
|
|
|
|
|
wfDebugLog( 'thumbnail',
|
|
|
|
|
sprintf( 'Removing bad %d-byte thumbnail "%s". unlink() failed',
|
|
|
|
|
$thumbstat['size'], $dstPath ) );
|
|
|
|
|
}
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2007-09-04 15:13:55 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2007-09-04 15:13:55 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-28 08:53:03 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-06-15 01:02:44 +00:00
|
|
|
* Remove files from the purge list.
|
|
|
|
|
*
|
|
|
|
|
* This is used by some video handlers to prevent ?action=purge
|
|
|
|
|
* from removing a transcoded video, which is expensive to
|
|
|
|
|
* regenerate.
|
|
|
|
|
*
|
|
|
|
|
* @see LocalFile::purgeThumbnails
|
2012-07-13 15:07:56 +00:00
|
|
|
*
|
2017-08-11 00:23:16 +00:00
|
|
|
* @param array &$files
|
2013-06-15 01:02:44 +00:00
|
|
|
* @param array $options Purge options. Currently will always be
|
|
|
|
|
* an array with a single key 'forThumbRefresh' set to true.
|
2011-11-28 08:53:03 +00:00
|
|
|
*/
|
|
|
|
|
public function filterThumbnailPurgeList( &$files, $options ) {
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
2013-01-08 11:35:55 +00:00
|
|
|
|
2014-08-13 19:26:20 +00:00
|
|
|
/**
|
2013-01-08 11:35:55 +00:00
|
|
|
* True if the handler can rotate the media
|
2014-07-09 20:03:31 +00:00
|
|
|
* @since 1.24 non-static. From 1.21-1.23 was static
|
2013-01-08 11:35:55 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2014-07-09 20:03:31 +00:00
|
|
|
public function canRotate() {
|
2013-01-08 11:35:55 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-09-29 02:12:58 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* On supporting image formats, try to read out the low-level orientation
|
|
|
|
|
* of the file and return the angle that the file needs to be rotated to
|
|
|
|
|
* be viewed.
|
|
|
|
|
*
|
|
|
|
|
* This information is only useful when manipulating the original file;
|
|
|
|
|
* the width and height we normally work with is logical, and will match
|
|
|
|
|
* any produced output views.
|
|
|
|
|
*
|
|
|
|
|
* For files we don't know, we return 0.
|
|
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2013-09-29 02:12:58 +00:00
|
|
|
* @return int 0, 90, 180 or 270
|
|
|
|
|
*/
|
|
|
|
|
public function getRotation( $file ) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-12-04 16:28:12 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Log an error that occurred in an external process
|
|
|
|
|
*
|
|
|
|
|
* Moved from BitmapHandler to MediaHandler with MediaWiki 1.23
|
|
|
|
|
*
|
|
|
|
|
* @since 1.23
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param int $retval
|
|
|
|
|
* @param string $err Error reported by command. Anything longer than
|
2013-12-04 17:00:21 +00:00
|
|
|
* MediaHandler::MAX_ERR_LOG_SIZE is stripped off.
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string $cmd
|
2013-12-04 16:28:12 +00:00
|
|
|
*/
|
|
|
|
|
protected function logErrorForExternalProcess( $retval, $err, $cmd ) {
|
2017-02-20 22:44:19 +00:00
|
|
|
# Keep error output limited (T59985)
|
2013-12-04 17:00:21 +00:00
|
|
|
$errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
|
|
|
|
|
|
2013-12-04 16:28:12 +00:00
|
|
|
wfDebugLog( 'thumbnail',
|
|
|
|
|
sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
|
2013-12-04 17:00:21 +00:00
|
|
|
wfHostname(), $retval, $errMessage, $cmd ) );
|
2013-12-04 16:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-16 01:47:51 +00:00
|
|
|
/**
|
|
|
|
|
* Get list of languages file can be viewed in.
|
|
|
|
|
*
|
|
|
|
|
* @param File $file
|
2014-04-23 11:39:49 +00:00
|
|
|
* @return string[] Array of language codes, or empty array if unsupported.
|
2013-11-16 01:47:51 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getAvailableLanguages( File $file ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2013-11-16 01:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-03 21:43:10 +00:00
|
|
|
/**
|
|
|
|
|
* When overridden in a descendant class, returns a language code most suiting
|
|
|
|
|
*
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*
|
|
|
|
|
* @param string $userPreferredLanguage Language code requesed
|
|
|
|
|
* @param string[] $availableLanguages Languages present in the file
|
|
|
|
|
* @return string|null Language code picked or null if not supported/available
|
|
|
|
|
*/
|
|
|
|
|
public function getMatchedLanguage( $userPreferredLanguage, array $availableLanguages ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-16 01:47:51 +00:00
|
|
|
/**
|
|
|
|
|
* On file types that support renderings in multiple languages,
|
|
|
|
|
* which language is used by default if unspecified.
|
|
|
|
|
*
|
|
|
|
|
* If getAvailableLanguages returns a non-empty array, this must return
|
|
|
|
|
* a valid language code. Otherwise can return null if files of this
|
|
|
|
|
* type do not support alternative language renderings.
|
|
|
|
|
*
|
|
|
|
|
* @param File $file
|
2014-04-23 11:39:49 +00:00
|
|
|
* @return string|null Language code or null if multi-language not supported for filetype.
|
2013-11-16 01:47:51 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getDefaultRenderLanguage( File $file ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-03-22 02:28:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If its an audio file, return the length of the file. Otherwise 0.
|
|
|
|
|
*
|
|
|
|
|
* File::getLength() existed for a long time, but was calling a method
|
|
|
|
|
* that only existed in some subclasses of this class (The TMH ones).
|
|
|
|
|
*
|
|
|
|
|
* @param File $file
|
|
|
|
|
* @return float Length in seconds
|
|
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getLength( $file ) {
|
|
|
|
|
return 0.0;
|
|
|
|
|
}
|
2014-05-27 20:09:49 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if creating thumbnails from the file is large or otherwise resource-intensive.
|
|
|
|
|
* @param File $file
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isExpensiveToThumbnail( $file ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-03 16:09:30 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether or not this handler supports the chained generation of thumbnails according
|
|
|
|
|
* to buckets
|
2014-07-24 17:43:25 +00:00
|
|
|
* @return bool
|
|
|
|
|
* @since 1.24
|
2014-06-03 16:09:30 +00:00
|
|
|
*/
|
|
|
|
|
public function supportsBucketing() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a normalised params array for which parameters have been cleaned up for bucketing
|
|
|
|
|
* purposes
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function sanitizeParamsForBucketing( $params ) {
|
|
|
|
|
return $params;
|
|
|
|
|
}
|
2015-03-05 18:52:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets configuration for the file warning message. Return value of
|
|
|
|
|
* the following structure:
|
2016-09-27 03:15:08 +00:00
|
|
|
* [
|
2015-09-26 15:53:53 +00:00
|
|
|
* // Required, module with messages loaded for the client
|
|
|
|
|
* 'module' => 'example.filewarning.messages',
|
|
|
|
|
* // Required, array of names of messages
|
2016-09-27 03:15:08 +00:00
|
|
|
* 'messages' => [
|
2015-09-26 15:53:53 +00:00
|
|
|
* // Required, main warning message
|
|
|
|
|
* 'main' => 'example-filewarning-main',
|
|
|
|
|
* // Optional, header for warning dialog
|
|
|
|
|
* 'header' => 'example-filewarning-header',
|
|
|
|
|
* // Optional, footer for warning dialog
|
|
|
|
|
* 'footer' => 'example-filewarning-footer',
|
|
|
|
|
* // Optional, text for more-information link (see below)
|
|
|
|
|
* 'info' => 'example-filewarning-info',
|
2016-09-27 03:15:08 +00:00
|
|
|
* ],
|
2015-09-26 15:53:53 +00:00
|
|
|
* // Optional, link for more information
|
|
|
|
|
* 'link' => 'http://example.com',
|
2016-09-27 03:15:08 +00:00
|
|
|
* ]
|
2015-03-05 18:52:11 +00:00
|
|
|
*
|
|
|
|
|
* Returns null if no warning is necessary.
|
|
|
|
|
* @param File $file
|
|
|
|
|
* @return array|null
|
|
|
|
|
*/
|
|
|
|
|
public function getWarningConfig( $file ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-04-26 12:01:49 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a dimensions array about a potentially multipage document from an
|
|
|
|
|
* exhaustive list of ordered page numbers to a list of page ranges
|
|
|
|
|
* @param Array $pagesByDimensions
|
|
|
|
|
* @return String
|
|
|
|
|
* @since 1.30
|
2017-08-11 21:45:25 +00:00
|
|
|
*/
|
2017-04-26 12:01:49 +00:00
|
|
|
public static function getPageRangesByDimensions( $pagesByDimensions ) {
|
|
|
|
|
$pageRangesByDimensions = [];
|
|
|
|
|
|
|
|
|
|
foreach ( $pagesByDimensions as $dimensions => $pageList ) {
|
|
|
|
|
$ranges = [];
|
|
|
|
|
$firstPage = $pageList[0];
|
|
|
|
|
$lastPage = $firstPage - 1;
|
|
|
|
|
|
|
|
|
|
foreach ( $pageList as $page ) {
|
|
|
|
|
if ( $page > $lastPage + 1 ) {
|
|
|
|
|
if ( $firstPage != $lastPage ) {
|
|
|
|
|
$ranges[] = "$firstPage-$lastPage";
|
|
|
|
|
} else {
|
|
|
|
|
$ranges[] = "$firstPage";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$firstPage = $page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lastPage = $page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $firstPage != $lastPage ) {
|
|
|
|
|
$ranges[] = "$firstPage-$lastPage";
|
|
|
|
|
} else {
|
|
|
|
|
$ranges[] = "$firstPage";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pageRangesByDimensions[ $dimensions ] = $ranges;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dimensionsString = [];
|
|
|
|
|
foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
|
|
|
|
|
$dimensionsString[] = "$dimensions:" . implode( ',', $pageRanges );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return implode( '/', $dimensionsString );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-11 15:46:31 +00:00
|
|
|
* Get useful response headers for GET/HEAD requests for a file with the given metadata
|
|
|
|
|
* @param array $metadata Contains this handler's unserialized getMetadata() for a file
|
|
|
|
|
* @return array
|
|
|
|
|
* @since 1.30
|
|
|
|
|
*/
|
2017-06-08 20:30:07 +00:00
|
|
|
public function getContentHeaders( $metadata ) {
|
2017-09-21 13:17:10 +00:00
|
|
|
return [ 'X-Content-Dimensions' => '' ]; // T175689
|
2017-04-26 12:01:49 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|