const METADATA_BAD = false;
const METADATA_COMPATIBLE = 2; // for old but backwards compatible.
/**
- * Instance cache
+ * Max length of error logged by logErrorForExternalProcess()
*/
- static $handlers = array();
+ const MAX_ERR_LOG_SIZE = 65535;
+
+ /** @var MediaHandler[] Instance cache with array of MediaHandler */
+ protected static $handlers = array();
/**
* Get a MediaHandler for a given MIME type from the instance cache
*
- * @param $type string
+ * @param string $type
*
* @return MediaHandler
*/
global $wgMediaHandlers;
if ( !isset( $wgMediaHandlers[$type] ) ) {
wfDebug( __METHOD__ . ": no handler found for $type.\n" );
+
return false;
}
$class = $wgMediaHandlers[$type];
self::$handlers[$class] = false;
}
}
+
return self::$handlers[$class];
}
* Return true to accept the parameter, and false to reject it.
* If you return false, the parser will do something quiet and forgiving.
*
- * @param $name
+ * @param string $name
* @param $value
*/
abstract function validateParam( $name, $value );
/**
* Merge a parameter array into a string appropriate for inclusion in filenames
*
- * @param $params array Array of parameters that have been through normaliseParams.
- * @return String
+ * @param array $params Array of parameters that have been through normaliseParams.
+ * @return string
*/
abstract function makeParamString( $params );
/**
* Parse a param string made with makeParamString back into an array
*
- * @param $str string The parameter string without file name (e.g. 122px)
- * @return Array|Boolean Array of parameters or false on failure.
+ * @param string $str The parameter string without file name (e.g. 122px)
+ * @return array|bool Array of parameters or false on failure.
*/
abstract function parseParamString( $str );
* Get an image size array like that returned by getimagesize(), or false if it
* can't be determined.
*
- * @param $image File: the image object, or false if there isn't one
+ * @param File $image The image object, or false if there isn't one
* @param string $path the filename
- * @return Array Follow the format of PHP getimagesize() internal function. See http://www.php.net/getimagesize
+ * @return array Follow the format of PHP getimagesize() internal function. See http://www.php.net/getimagesize
*/
abstract function getImageSize( $image, $path );
/**
* Get handler-specific metadata which will be saved in the img_metadata field.
*
- * @param $image File: the image object, or false if there isn't one.
+ * @param File $image The image object, or false if there isn't one.
* Warning, FSFile::getPropsFromPath might pass an (object)array() instead (!)
- * @param string $path the filename
- * @return String
+ * @param string $path The filename
+ * @return string
*/
function getMetadata( $image, $path ) {
return '';
* 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'.
*
- * @return string version string
+ * @return string Version string
*/
static function getMetadataVersion() {
- $version = Array( '2' ); // core metadata version
- wfRunHooks( 'GetMetadataVersion', Array( &$version ) );
+ $version = array( '2' ); // core metadata version
+ wfRunHooks( 'GetMetadataVersion', array( &$version ) );
+
return implode( ';', $version );
}
* By default just returns $metadata, but can be used to allow
* media handlers to convert between metadata versions.
*
- * @param $metadata Mixed String or Array metadata array (serialized if string)
- * @param $version Integer target version
- * @return Array serialized metadata in specified version, or $metadata on fail.
+ * @param mixed|string|array $metadata Metadata array (serialized if string)
+ * @param int $version Target version
+ * @return array Serialized metadata in specified version, or $metadata on fail.
*/
function convertMetadataVersion( $metadata, $version = 1 ) {
if ( !is_array( $metadata ) ) {
wfSuppressWarnings();
$ret = unserialize( $metadata );
wfRestoreWarnings();
+
return $ret;
}
+
return $metadata;
}
/**
* Get a string describing the type of metadata, for display purposes.
- *
+ * @param $image
* @return string
*/
function getMetadataType( $image ) {
*
* @param File $file
*
- * @return Array or false if interface not supported
+ * @return array|bool False if interface not supported
* @since 1.23
*/
public function getCommonMetaArray( File $file ) {
* Get a MediaTransformOutput object representing the transformed output. Does not
* actually do the transform.
*
- * @param $image File: the image object
+ * @param File $image The image object
* @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()
* Get a MediaTransformOutput object representing the transformed output. Does the
* transform unless $flags contains self::TRANSFORM_LATER.
*
- * @param $image File: the image object
+ * @param File $image The image object
* @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()
* Note: These parameters have *not* gone through $this->normaliseParams()
- * @param $flags Integer: a bitfield, may contain self::TRANSFORM_LATER
+ * @param int $flags A bitfield, may contain self::TRANSFORM_LATER
*
* @return MediaTransformOutput
*/
/**
* Get the thumbnail extension and MIME type for a given source MIME type
*
- * @param String $ext Extension of original file
- * @param String $mime Mime type of original file
- * @param Array $params Handler specific rendering parameters
+ * @param string $ext Extension of original file
+ * @param string $mime Mime type of original file
+ * @param array $params Handler specific rendering parameters
* @return array thumbnail extension and MIME type
*/
function getThumbType( $ext, $mime, $params = null ) {
/**
* Get useful response headers for GET/HEAD requests for a file with the given metadata
- * @param $metadata mixed Result of the getMetadata() function of this handler for a file
- * @return Array
+ * @param mixed $metadata Result of the getMetadata() function of this handler for a file
+ * @return array
*/
public function getStreamHeaders( $metadata ) {
return array();
*
* @note For non-paged media, use getImageSize.
*
- * @param $image File
- * @param $page What page to get dimensions of
+ * @param File $image
+ * @param int $page What page to get dimensions of
* @return array|bool
*/
function getPageDimensions( $image, $page ) {
$value
);
}
+
return $result;
}
*/
function getShortDesc( $file ) {
global $wgLang;
+
return htmlspecialchars( $wgLang->formatSize( $file->getSize() ) );
}
*/
function getLongDesc( $file ) {
global $wgLang;
+
return wfMessage( 'file-info', htmlspecialchars( $wgLang->formatSize( $file->getSize() ) ),
$file->getMimeType() )->parse();
}
*/
static function getGeneralShortDesc( $file ) {
global $wgLang;
+
return $wgLang->formatSize( $file->getSize() );
}
*/
static function getGeneralLongDesc( $file ) {
global $wgLang;
+
return wfMessage( 'file-info', $wgLang->formatSize( $file->getSize() ),
$file->getMimeType() )->parse();
}
* @param Parser $parser
* @param File $file
*/
- function parserTransformHook( $parser, $file ) {}
+ function parserTransformHook( $parser, $file ) {
+ }
/**
* File validation hook called on upload.
sprintf( 'Removing bad %d-byte thumbnail "%s". unlink() failed',
$thumbstat['size'], $dstPath ) );
}
+
return true;
}
}
+
return false;
}
return 0;
}
+ /**
+ * Log an error that occurred in an external process
+ *
+ * Moved from BitmapHandler to MediaHandler with MediaWiki 1.23
+ *
+ * @since 1.23
+ * @param $retval int
+ * @param $err string Error reported by command. Anything longer than
+ * MediaHandler::MAX_ERR_LOG_SIZE is stripped off.
+ * @param $cmd string
+ */
+ protected function logErrorForExternalProcess( $retval, $err, $cmd ) {
+ # Keep error output limited (bug 57985)
+ $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
+
+ wfDebugLog( 'thumbnail',
+ sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
+ wfHostname(), $retval, $errMessage, $cmd ) );
+ }
+
}