2007-04-20 12:31:36 +00:00
|
|
|
<?php
|
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
|
|
|
|
|
|
|
|
/**
|
2007-05-30 21:02:32 +00:00
|
|
|
* Base class for the output of MediaHandler::doTransform() and File::transform().
|
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 MediaTransformOutput {
|
2007-08-31 02:51:23 +00:00
|
|
|
var $file, $width, $height, $url, $page, $path;
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Get the width of the output box
|
|
|
|
|
*/
|
|
|
|
|
function getWidth() {
|
|
|
|
|
return $this->width;
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the height of the output box
|
|
|
|
|
*/
|
|
|
|
|
function getHeight() {
|
|
|
|
|
return $this->height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string The thumbnail URL
|
|
|
|
|
*/
|
|
|
|
|
function getUrl() {
|
|
|
|
|
return $this->url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string Destination file path (local filesystem)
|
|
|
|
|
*/
|
|
|
|
|
function getPath() {
|
|
|
|
|
return $this->path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch HTML for this transform output
|
2007-08-31 02:51:23 +00:00
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* @param array $options Associative array of options. Boolean options
|
|
|
|
|
* should be indicated with a value of true for true, and false or
|
2007-08-31 02:51:23 +00:00
|
|
|
* absent for false.
|
|
|
|
|
*
|
|
|
|
|
* alt Alternate text or caption
|
|
|
|
|
* desc-link Boolean, show a description link
|
|
|
|
|
* file-link Boolean, show a file download link
|
2008-10-06 05:55:27 +00:00
|
|
|
* custom-url-link Custom URL to link to
|
|
|
|
|
* custom-title-link Custom Title object to link to
|
2007-08-31 02:51:23 +00:00
|
|
|
* valign vertical-align property, if the output is an inline element
|
|
|
|
|
* img-class Class applied to the <img> tag, if there is such a tag
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* For images, desc-link and file-link are implemented as a click-through. For
|
|
|
|
|
* sounds and videos, they may be displayed in other ways.
|
2007-08-31 02:51:23 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2007-08-31 02:51:23 +00:00
|
|
|
abstract function toHtml( $options = array() );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This will be overridden to return true in error classes
|
|
|
|
|
*/
|
|
|
|
|
function isError() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wrap some XHTML text in an anchor tag with the given attributes
|
|
|
|
|
*/
|
|
|
|
|
protected function linkWrap( $linkAttribs, $contents ) {
|
|
|
|
|
if ( $linkAttribs ) {
|
|
|
|
|
return Xml::tags( 'a', $linkAttribs, $contents );
|
|
|
|
|
} else {
|
|
|
|
|
return $contents;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-31 02:51:23 +00:00
|
|
|
|
2009-07-11 04:47:12 +00:00
|
|
|
function getDescLinkAttribs( $title = null, $params = '' ) {
|
2007-08-31 02:51:23 +00:00
|
|
|
$query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : '';
|
2008-05-19 18:55:48 +00:00
|
|
|
if( $params ) {
|
|
|
|
|
$query .= $query ? '&'.$params : $params;
|
|
|
|
|
}
|
2009-07-11 04:47:12 +00:00
|
|
|
$attribs = array(
|
2007-08-31 02:51:23 +00:00
|
|
|
'href' => $this->file->getTitle()->getLocalURL( $query ),
|
|
|
|
|
'class' => 'image',
|
|
|
|
|
);
|
2009-07-11 04:47:12 +00:00
|
|
|
if ( $title ) {
|
|
|
|
|
$attribs['title'] = $title;
|
|
|
|
|
}
|
|
|
|
|
return $attribs;
|
2007-08-31 02:51:23 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Media transform output for images
|
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
|
|
|
*/
|
|
|
|
|
class ThumbnailImage extends MediaTransformOutput {
|
|
|
|
|
/**
|
|
|
|
|
* @param string $path Filesystem path to the thumb
|
|
|
|
|
* @param string $url URL path to the thumb
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2007-08-31 02:51:23 +00:00
|
|
|
function ThumbnailImage( $file, $url, $width, $height, $path = false, $page = false ) {
|
|
|
|
|
$this->file = $file;
|
2007-04-20 12:31:36 +00:00
|
|
|
$this->url = $url;
|
|
|
|
|
# These should be integers when they get here.
|
|
|
|
|
# If not, there's a bug somewhere. But let's at
|
|
|
|
|
# least produce valid HTML code regardless.
|
|
|
|
|
$this->width = round( $width );
|
|
|
|
|
$this->height = round( $height );
|
|
|
|
|
$this->path = $path;
|
2007-08-31 02:51:23 +00:00
|
|
|
$this->page = $page;
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return HTML <img ... /> tag for the thumbnail, will include
|
|
|
|
|
* width and height attributes and a blank alt text (as required).
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
|
|
|
|
* @param array $options Associative array of options. Boolean options
|
|
|
|
|
* should be indicated with a value of true for true, and false or
|
2007-08-31 02:51:23 +00:00
|
|
|
* absent for false.
|
2007-04-20 12:31:36 +00:00
|
|
|
*
|
2008-10-08 16:33:36 +00:00
|
|
|
* alt HTML alt attribute
|
|
|
|
|
* title HTML title attribute
|
2007-08-31 02:51:23 +00:00
|
|
|
* desc-link Boolean, show a description link
|
|
|
|
|
* file-link Boolean, show a file download link
|
|
|
|
|
* valign vertical-align property, if the output is an inline element
|
|
|
|
|
* img-class Class applied to the <img> tag, if there is such a tag
|
2008-05-19 18:55:48 +00:00
|
|
|
* desc-query String, description link query params
|
2008-10-06 05:55:27 +00:00
|
|
|
* custom-url-link Custom URL to link to
|
|
|
|
|
* custom-title-link Custom Title object to link to
|
2007-04-20 12:31:36 +00:00
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* For images, desc-link and file-link are implemented as a click-through. For
|
|
|
|
|
* sounds and videos, they may be displayed in other ways.
|
2007-04-20 12:31:36 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
2007-08-31 02:51:23 +00:00
|
|
|
function toHtml( $options = array() ) {
|
|
|
|
|
if ( count( func_get_args() ) == 2 ) {
|
|
|
|
|
throw new MWException( __METHOD__ .' called in the old style' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$alt = empty( $options['alt'] ) ? '' : $options['alt'];
|
2009-07-11 04:47:12 +00:00
|
|
|
|
|
|
|
|
$query = empty( $options['desc-query'] ) ? '' : $options['desc-query'];
|
2008-10-08 16:33:36 +00:00
|
|
|
|
2008-10-06 05:55:27 +00:00
|
|
|
if ( !empty( $options['custom-url-link'] ) ) {
|
|
|
|
|
$linkAttribs = array( 'href' => $options['custom-url-link'] );
|
2009-07-11 04:47:12 +00:00
|
|
|
if ( !empty( $options['title'] ) ) {
|
|
|
|
|
$linkAttribs['title'] = $options['title'];
|
2009-05-15 19:43:09 +00:00
|
|
|
}
|
2008-10-06 05:55:27 +00:00
|
|
|
} elseif ( !empty( $options['custom-title-link'] ) ) {
|
|
|
|
|
$title = $options['custom-title-link'];
|
2009-07-11 04:47:12 +00:00
|
|
|
$linkAttribs = array(
|
|
|
|
|
'href' => $title->getLinkUrl(),
|
|
|
|
|
'title' => empty( $options['title'] ) ? $title->getFullText() : $options['title']
|
|
|
|
|
);
|
2008-10-06 05:55:27 +00:00
|
|
|
} elseif ( !empty( $options['desc-link'] ) ) {
|
2009-07-11 04:47:12 +00:00
|
|
|
$linkAttribs = $this->getDescLinkAttribs( empty( $options['title'] ) ? null : $options['title'], $query );
|
2007-08-31 02:51:23 +00:00
|
|
|
} elseif ( !empty( $options['file-link'] ) ) {
|
|
|
|
|
$linkAttribs = array( 'href' => $this->file->getURL() );
|
|
|
|
|
} else {
|
|
|
|
|
$linkAttribs = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$attribs = array(
|
|
|
|
|
'alt' => $alt,
|
|
|
|
|
'src' => $this->url,
|
|
|
|
|
'width' => $this->width,
|
|
|
|
|
'height' => $this->height,
|
|
|
|
|
);
|
|
|
|
|
if ( !empty( $options['valign'] ) ) {
|
|
|
|
|
$attribs['style'] = "vertical-align: {$options['valign']}";
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $options['img-class'] ) ) {
|
|
|
|
|
$attribs['class'] = $options['img-class'];
|
|
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Basic media transform error 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
|
|
|
*/
|
|
|
|
|
class MediaTransformError extends MediaTransformOutput {
|
|
|
|
|
var $htmlMsg, $textMsg, $width, $height, $url, $path;
|
|
|
|
|
|
|
|
|
|
function __construct( $msg, $width, $height /*, ... */ ) {
|
|
|
|
|
$args = array_slice( func_get_args(), 3 );
|
|
|
|
|
$htmlArgs = array_map( 'htmlspecialchars', $args );
|
|
|
|
|
$htmlArgs = array_map( 'nl2br', $htmlArgs );
|
|
|
|
|
|
|
|
|
|
$this->htmlMsg = wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $msg, true ) ), $htmlArgs );
|
|
|
|
|
$this->textMsg = wfMsgReal( $msg, $args );
|
|
|
|
|
$this->width = intval( $width );
|
|
|
|
|
$this->height = intval( $height );
|
|
|
|
|
$this->url = false;
|
|
|
|
|
$this->path = false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-31 02:51:23 +00:00
|
|
|
function toHtml( $options = array() ) {
|
2007-04-20 12:31:36 +00:00
|
|
|
return "<table class=\"MediaTransformError\" style=\"" .
|
|
|
|
|
"width: {$this->width}px; height: {$this->height}px;\"><tr><td>" .
|
|
|
|
|
$this->htmlMsg .
|
|
|
|
|
"</td></tr></table>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toText() {
|
|
|
|
|
return $this->textMsg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHtmlMsg() {
|
|
|
|
|
return $this->htmlMsg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isError() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shortcut class for parameter validation errors
|
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
|
|
|
*/
|
|
|
|
|
class TransformParameterError extends MediaTransformError {
|
|
|
|
|
function __construct( $params ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
parent::__construct( 'thumbnail_error',
|
|
|
|
|
max( isset( $params['width'] ) ? $params['width'] : 0, 180 ),
|
|
|
|
|
max( isset( $params['height'] ) ? $params['height'] : 0, 180 ),
|
2007-04-20 12:31:36 +00:00
|
|
|
wfMsg( 'thumbnail_invalid_params' ) );
|
|
|
|
|
}
|
|
|
|
|
}
|