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
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];
}
static function getMetadataVersion() {
$version = array( '2' ); // core metadata version
wfRunHooks( 'GetMetadataVersion', array( &$version ) );
+
return implode( ';', $version );
}
wfSuppressWarnings();
$ret = unserialize( $metadata );
wfRestoreWarnings();
+
return $ret;
}
+
return $metadata;
}
*
* @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 ) );
+ }
+
}