summaryrefslogtreecommitdiff
path: root/includes/media/Generic.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/media/Generic.php')
-rw-r--r--includes/media/Generic.php179
1 files changed, 146 insertions, 33 deletions
diff --git a/includes/media/Generic.php b/includes/media/Generic.php
index 5254e0ea..c7ab7d81 100644
--- a/includes/media/Generic.php
+++ b/includes/media/Generic.php
@@ -36,6 +36,12 @@ abstract class MediaHandler {
return self::$handlers[$class];
}
+ /**
+ * Get an associative array mapping magic word IDs to parameter names.
+ * Will be used by the parser to identify parameters.
+ */
+ abstract function getParamMap();
+
/*
* Validate a thumbnail parameter at parse time.
* Return true to accept the parameter, and false to reject it.
@@ -126,20 +132,20 @@ abstract class MediaHandler {
/**
* True if the handled types can be transformed
*/
- function canRender() { return true; }
+ function canRender( $file ) { return true; }
/**
* True if handled types cannot be displayed directly in a browser
* but can be rendered
*/
- function mustRender() { return false; }
+ function mustRender( $file ) { return false; }
/**
* True if the type has multi-page capabilities
*/
- function isMultiPage() { return false; }
+ function isMultiPage( $file ) { return false; }
/**
* Page count for a multi-page document, false if unsupported or unknown
*/
- function pageCount() { return false; }
+ function pageCount( $file ) { return false; }
/**
* False if the handler is disabled for all files
*/
@@ -152,12 +158,102 @@ abstract class MediaHandler {
* Returns false if unknown or if the document is not multi-page.
*/
function getPageDimensions( $image, $page ) {
- $gis = $this->getImageSize( $image, $image->getImagePath() );
+ $gis = $this->getImageSize( $image, $image->getPath() );
return array(
'width' => $gis[0],
'height' => $gis[1]
);
}
+
+ /**
+ * Get an array structure that looks like this:
+ *
+ * array(
+ * 'visible' => array(
+ * 'Human-readable name' => 'Human readable value',
+ * ...
+ * ),
+ * 'collapsed' => array(
+ * 'Human-readable name' => 'Human readable value',
+ * ...
+ * )
+ * )
+ * The UI will format this into a table where the visible fields are always
+ * visible, and the collapsed fields are optionally visible.
+ *
+ * The function should return false if there is no metadata to display.
+ */
+
+ /**
+ * FIXME: I don't really like this interface, it's not very flexible
+ * I think 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.
+ */
+ function formatMetadata( $image, $metadata ) {
+ return false;
+ }
+
+ /**
+ * @fixme document this!
+ * 'value' thingy goes into a wikitext table; it used to be escaped but
+ * that was incompatible with previous practice 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.
+ */
+ protected static function addMeta( &$array, $visibility, $type, $id, $value, $param = false ) {
+ $array[$visibility][] = array(
+ 'id' => "$type-$id",
+ 'name' => wfMsg( "$type-$id", $param ),
+ 'value' => $value
+ );
+ }
+
+ function getShortDesc( $file ) {
+ global $wgLang;
+ $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
+ $wgLang->formatNum( $file->getSize() ) ) . ')';
+ return "$nbytes";
+ }
+
+ function getLongDesc( $file ) {
+ global $wgUser;
+ $sk = $wgUser->getSkin();
+ return wfMsg( 'file-info', $sk->formatSize( $file->getSize() ), $file->getMimeType() );
+ }
+
+ function getDimensionsString() {
+ return '';
+ }
+
+ /**
+ * Modify the parser object post-transform
+ */
+ function parserTransformHook( $parser, $file ) {}
+
+ /**
+ * Check for zero-sized thumbnails. These can be generated when
+ * no disk space is available or some other error occurs
+ *
+ * @param $dstPath The location of the suspect file
+ * @param $retval Return value of some shell process, file will be deleted if this is non-zero
+ * @return true if removed, false otherwise
+ */
+ function removeBadFile( $dstPath, $retval = 0 ) {
+ if( file_exists( $dstPath ) ) {
+ $thumbstat = stat( $dstPath );
+ if( $thumbstat['size'] == 0 || $retval != 0 ) {
+ wfDebugLog( 'thumbnail',
+ sprintf( 'Removing bad %d-byte thumbnail "%s"',
+ $thumbstat['size'], $dstPath ) );
+ unlink( $dstPath );
+ return true;
+ }
+ }
+ return false;
+ }
}
/**
@@ -166,6 +262,18 @@ abstract class MediaHandler {
* @addtogroup Media
*/
abstract class ImageHandler extends MediaHandler {
+ function canRender( $file ) {
+ if ( $file->getWidth() && $file->getHeight() ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function getParamMap() {
+ return array( 'img_width' => 'width' );
+ }
+
function validateParam( $name, $value ) {
if ( in_array( $name, array( 'width', 'height' ) ) ) {
if ( $value <= 0 ) {
@@ -181,8 +289,10 @@ abstract class ImageHandler extends MediaHandler {
function makeParamString( $params ) {
if ( isset( $params['physicalWidth'] ) ) {
$width = $params['physicalWidth'];
- } else {
+ } elseif ( isset( $params['width'] ) ) {
$width = $params['width'];
+ } else {
+ throw new MWException( 'No width specified to '.__METHOD__ );
}
# Removed for ProofreadPage
#$width = intval( $width );
@@ -218,7 +328,7 @@ abstract class ImageHandler extends MediaHandler {
$params['width'] = wfFitBoxWidth( $srcWidth, $srcHeight, $params['height'] );
}
}
- $params['height'] = Image::scaleHeight( $srcWidth, $srcHeight, $params['width'] );
+ $params['height'] = File::scaleHeight( $srcWidth, $srcHeight, $params['width'] );
if ( !$this->validateThumbParams( $params['width'], $params['height'], $srcWidth, $srcHeight, $mimeType ) ) {
return false;
}
@@ -252,7 +362,7 @@ abstract class ImageHandler extends MediaHandler {
return false;
}
- $height = Image::scaleHeight( $srcWidth, $srcHeight, $width );
+ $height = File::scaleHeight( $srcWidth, $srcHeight, $width );
return true;
}
@@ -261,30 +371,8 @@ abstract class ImageHandler extends MediaHandler {
return false;
}
$url = $script . '&' . wfArrayToCGI( $this->getScriptParams( $params ) );
- return new ThumbnailImage( $url, $params['width'], $params['height'] );
- }
-
- /**
- * Check for zero-sized thumbnails. These can be generated when
- * no disk space is available or some other error occurs
- *
- * @param $dstPath The location of the suspect file
- * @param $retval Return value of some shell process, file will be deleted if this is non-zero
- * @return true if removed, false otherwise
- */
- function removeBadFile( $dstPath, $retval = 0 ) {
- $removed = false;
- if( file_exists( $dstPath ) ) {
- $thumbstat = stat( $dstPath );
- if( $thumbstat['size'] == 0 || $retval != 0 ) {
- wfDebugLog( 'thumbnail',
- sprintf( 'Removing bad %d-byte thumbnail "%s"',
- $thumbstat['size'], $dstPath ) );
- unlink( $dstPath );
- return true;
- }
- }
- return false;
+ $page = isset( $params['page'] ) ? $params['page'] : false;
+ return new ThumbnailImage( $image, $url, $params['width'], $params['height'], $page );
}
function getImageSize( $image, $path ) {
@@ -293,6 +381,31 @@ abstract class ImageHandler extends MediaHandler {
wfRestoreWarnings();
return $gis;
}
+
+ function getShortDesc( $file ) {
+ global $wgLang;
+ $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
+ $wgLang->formatNum( $file->getSize() ) ) . ')';
+ $widthheight = wfMsgHtml( 'widthheight', $file->getWidth(), $file->getHeight() );
+
+ return "$widthheight ($nbytes)";
+ }
+
+ function getLongDesc( $file ) {
+ global $wgLang;
+ return wfMsgHtml('file-info-size', $file->getWidth(), $file->getHeight(),
+ $wgLang->formatSize( $file->getSize() ), $file->getMimeType() );
+ }
+
+ function getDimensionsString( $file ) {
+ $pages = $file->pageCount();
+ if ( $pages > 1 ) {
+ return wfMsg( 'widthheightpage', $file->getWidth(), $file->getHeight(), $pages );
+ } else {
+ return wfMsg( 'widthheight', $file->getWidth(), $file->getHeight() );
+ }
+ }
}
-?>
+
+