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
|
|
|
/**
|
2010-08-15 17:27:41 +00:00
|
|
|
* Base class for the output of file transformation methods.
|
|
|
|
|
*
|
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 {
|
2011-02-18 23:34:24 +00:00
|
|
|
/**
|
|
|
|
|
* @var File
|
|
|
|
|
*/
|
|
|
|
|
var $file;
|
|
|
|
|
|
|
|
|
|
var $width, $height, $url, $page, $path;
|
2007-08-31 02:51:23 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-03-27 20:57:32 +00:00
|
|
|
* @return String: destination file path (local filesystem)
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
function getPath() {
|
|
|
|
|
return $this->path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch HTML for this transform output
|
2007-08-31 02:51:23 +00:00
|
|
|
*
|
2011-05-28 18:59:42 +00:00
|
|
|
* @param $options array Associative array of options. Boolean options
|
2008-04-14 07:45:50 +00:00
|
|
|
* 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
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @param $linkAttribs array
|
|
|
|
|
* @param $contents string
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
|
|
|
|
protected function linkWrap( $linkAttribs, $contents ) {
|
|
|
|
|
if ( $linkAttribs ) {
|
|
|
|
|
return Xml::tags( 'a', $linkAttribs, $contents );
|
|
|
|
|
} else {
|
|
|
|
|
return $contents;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-31 02:51:23 +00:00
|
|
|
|
2011-05-28 18:59:42 +00:00
|
|
|
/**
|
|
|
|
|
* @param $title string
|
|
|
|
|
* @param $params array
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
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 {
|
2010-03-27 20:57:32 +00:00
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
2010-03-27 20:57:32 +00:00
|
|
|
* @param $file File object
|
|
|
|
|
* @param $url String: URL path to the thumb
|
|
|
|
|
* @param $width Integer: file's width
|
|
|
|
|
* @param $height Integer: file's height
|
|
|
|
|
* @param $path String: filesystem path to the thumb
|
|
|
|
|
* @param $page Integer: page number, for multipage files
|
2007-04-20 12:31:36 +00:00
|
|
|
* @private
|
|
|
|
|
*/
|
2010-08-30 16:52:51 +00:00
|
|
|
function __construct( $file, $url, $width, $height, $path = false, $page = false ) {
|
2007-08-31 02:51:23 +00:00
|
|
|
$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
|
|
|
*
|
2011-05-28 18:59:42 +00:00
|
|
|
* @param $options array Associative array of options. Boolean options
|
2008-04-14 07:45:50 +00:00
|
|
|
* 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
|
2010-03-27 20:57:32 +00:00
|
|
|
* 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
|
2010-11-09 12:25:57 +00:00
|
|
|
* custom target-link Value of the target attribute, for custom-target-link
|
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
|
|
|
|
|
*/
|
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
|
|
|
}
|
2010-11-09 12:25:57 +00:00
|
|
|
if ( !empty( $options['custom-target-link'] ) ) {
|
|
|
|
|
$linkAttribs['target'] = $options['custom-target-link'];
|
|
|
|
|
}
|
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(
|
2011-11-10 03:27:55 +00:00
|
|
|
'href' => $title->getLinkURL(),
|
2009-07-11 04:47:12 +00:00
|
|
|
'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 );
|
|
|
|
|
|
2011-02-04 16:52:26 +00:00
|
|
|
$this->htmlMsg = wfMessage( $msg )->rawParams( $htmlArgs )->escaped();
|
|
|
|
|
$this->textMsg = wfMessage( $msg )->rawParams( $htmlArgs )->text();
|
2007-04-20 12:31:36 +00:00
|
|
|
$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() ) {
|
2010-04-20 22:49:50 +00:00
|
|
|
return "<div class=\"MediaTransformError\" style=\"" .
|
|
|
|
|
"width: {$this->width}px; height: {$this->height}px; display:inline-block;\">" .
|
2007-04-20 12:31:36 +00:00
|
|
|
$this->htmlMsg .
|
2010-04-20 22:49:50 +00:00
|
|
|
"</div>";
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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',
|
2010-04-20 22:49:50 +00:00
|
|
|
max( isset( $params['width'] ) ? $params['width'] : 0, 120 ),
|
|
|
|
|
max( isset( $params['height'] ) ? $params['height'] : 0, 120 ),
|
2007-04-20 12:31:36 +00:00
|
|
|
wfMsg( 'thumbnail_invalid_params' ) );
|
|
|
|
|
}
|
|
|
|
|
}
|