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.
|
|
|
|
|
*
|
2012-05-03 20:13:10 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
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 {
|
2013-12-05 19:27:27 +00:00
|
|
|
/** @var array Associative array mapping optional supplementary image files
|
|
|
|
|
* from pixel density (eg 1.5 or 2) to additional URLs.
|
Initial stab at responsive images for screen densities.
* adds $wgResponsiveImages setting, defaulting to true, to enable the feature
* adds 'srcset' attribute with 1.5x and 2x URLs to image links and image thumbs
* adds jquery.hidpi plugin to check pixel density and implement partial 'srcset' polyfill
** $.devicePixelRatio() returns window.devicePixelRatio, with compat fallback for IE 10
** $().hidpi() performs a 'srcset' polyfill for browsers with no native 'srcset' support
* adds mediawiki.hidpi RL script to trigger hidpi loads after main images load
Note that this is a work in progress. There will be places where this doesn't yet work which output their imgs differently. If moving from a low to high-DPI screen on a MacBook Pro Retina display, you won't see images load until you reload.
Confirmed basic images and thumbs in wikitext appear to work in Safari 6, Chrome 21, Firefox 18 nightly on MacBook Pro Retina display, and IE 10 in Windows 8 at 150% zoom, 200% zoom, and 140% and 180%-ratio Metro tablet sizes.
Internally this is still a bit of a hack; Linker::makeImageLink and Linker::makeThumbLink explicitly ask for 1.5x and 2x scaled versions and insert their URLs, if different, into the original thumbnail object which (in default handler) outputs the srcset. This means that a number of places that handle images differently won't see the higher-resolution versions, such as <gallery> and the large thumbnail on the File: description page.
At some point we may wish to redo some of how the MediaHandler stuff works so that requesting a single thumbnail automatically produces the extra sizes in all circumstances. We might also consider outputting a 'srcset' or multiple src sizes in 'imageinfo' API requests, which would make ApiForeignRepo/InstantCommons more efficient. (Currently it has to make three requests for each image to get the three sizes.)
Change-Id: Id80ebd07a1a9f401a2c2bfeb21aae987e5aa863b
2012-09-18 07:18:50 +00:00
|
|
|
*/
|
|
|
|
|
public $responsiveUrls = array();
|
|
|
|
|
|
2014-07-24 17:43:25 +00:00
|
|
|
/** @var File */
|
2013-12-05 13:08:49 +00:00
|
|
|
protected $file;
|
|
|
|
|
|
|
|
|
|
/** @var int Image width */
|
|
|
|
|
protected $width;
|
|
|
|
|
|
|
|
|
|
/** @var int Image height */
|
|
|
|
|
protected $height;
|
|
|
|
|
|
|
|
|
|
/** @var string URL path to the thumb */
|
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
|
|
/** @var bool|string */
|
|
|
|
|
protected $page;
|
|
|
|
|
|
|
|
|
|
/** @var bool|string Filesystem path to the thumb */
|
|
|
|
|
protected $path;
|
|
|
|
|
|
|
|
|
|
/** @var bool|string Language code, false if not set */
|
|
|
|
|
protected $lang;
|
|
|
|
|
|
|
|
|
|
/** @var bool|string Permanent storage path */
|
2012-01-05 01:58:05 +00:00
|
|
|
protected $storagePath = false;
|
2007-08-31 02:51:23 +00:00
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
2013-12-05 19:27:27 +00:00
|
|
|
* @return int Width of the output box
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
public function getWidth() {
|
2007-04-20 12:31:36 +00:00
|
|
|
return $this->width;
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-12-05 19:27:27 +00:00
|
|
|
* @return int Height of the output box
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
public function getHeight() {
|
2007-04-20 12:31:36 +00:00
|
|
|
return $this->height;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 08:33:02 +00:00
|
|
|
/**
|
2014-07-24 17:43:25 +00:00
|
|
|
* @return File
|
2014-03-28 08:33:02 +00:00
|
|
|
*/
|
|
|
|
|
public function getFile() {
|
|
|
|
|
return $this->file;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
2012-07-13 15:07:56 +00:00
|
|
|
* Get the final extension of the thumbnail.
|
|
|
|
|
* Returns false for scripted transformations.
|
2014-04-23 11:39:49 +00:00
|
|
|
* @return string|bool
|
2012-07-13 15:07:56 +00:00
|
|
|
*/
|
|
|
|
|
public function getExtension() {
|
|
|
|
|
return $this->path ? FileBackend::extensionFromPath( $this->path ) : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-23 11:39:49 +00:00
|
|
|
* @return string|bool The thumbnail URL
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
public function getUrl() {
|
2007-04-20 12:31:36 +00:00
|
|
|
return $this->url;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-05 01:58:05 +00:00
|
|
|
/**
|
2012-02-09 17:41:50 +00:00
|
|
|
* @return string|bool The permanent thumbnail storage path
|
2012-01-05 01:58:05 +00:00
|
|
|
*/
|
|
|
|
|
public function getStoragePath() {
|
|
|
|
|
return $this->storagePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $storagePath The permanent storage path
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2012-01-05 01:58:05 +00:00
|
|
|
*/
|
|
|
|
|
public function setStoragePath( $storagePath ) {
|
|
|
|
|
$this->storagePath = $storagePath;
|
2014-05-13 23:07:15 +00:00
|
|
|
if ( $this->path === false ) {
|
|
|
|
|
$this->path = $storagePath;
|
|
|
|
|
}
|
2012-01-05 01:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch HTML for this transform output
|
2007-08-31 02:51:23 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $options 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
|
2012-07-10 12:48:06 +00:00
|
|
|
* img-class Class applied to the "<img>" tag, if there is such a tag
|
2007-08-31 02:51:23 +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-08-31 02:51:23 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
abstract public function toHtml( $options = array() );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This will be overridden to return true in error classes
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
public function isError() {
|
2007-04-20 12:31:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
2012-02-01 04:44:08 +00:00
|
|
|
* Check if an output thumbnail file actually exists.
|
2014-05-13 23:07:15 +00:00
|
|
|
*
|
2011-12-20 03:52:06 +00:00
|
|
|
* This will return false if there was an error, the
|
2012-02-01 04:44:08 +00:00
|
|
|
* thumbnail is to be handled client-side only, or if
|
2011-12-20 03:52:06 +00:00
|
|
|
* transformation was deferred via TRANSFORM_LATER.
|
2014-05-13 23:07:15 +00:00
|
|
|
* This file may exist as a new file in /tmp, a file
|
|
|
|
|
* in permanent storage, or even refer to the original.
|
2012-07-13 15:07:56 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @return bool
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
|
|
|
|
public function hasFile() {
|
2012-02-01 04:44:08 +00:00
|
|
|
// If TRANSFORM_LATER, $this->path will be false.
|
|
|
|
|
// Note: a null path means "use the source file".
|
|
|
|
|
return ( !$this->isError() && ( $this->path || $this->path === null ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-01 04:44:08 +00:00
|
|
|
* Check if the output thumbnail is the same as the source.
|
2011-12-20 03:52:06 +00:00
|
|
|
* This can occur if the requested width was bigger than the source.
|
|
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @return bool
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
|
|
|
|
public function fileIsSource() {
|
2012-02-01 04:44:08 +00:00
|
|
|
return ( !$this->isError() && $this->path === null );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-01 04:44:08 +00:00
|
|
|
* Get the path of a file system copy of the thumbnail.
|
|
|
|
|
* Callers should never write to this path.
|
2011-12-20 03:52:06 +00:00
|
|
|
*
|
2012-02-09 17:41:50 +00:00
|
|
|
* @return string|bool Returns false if there isn't one
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
|
|
|
|
public function getLocalCopyPath() {
|
2012-02-01 04:44:08 +00:00
|
|
|
if ( $this->isError() ) {
|
|
|
|
|
return false;
|
|
|
|
|
} elseif ( $this->path === null ) {
|
2013-03-27 19:48:08 +00:00
|
|
|
return $this->file->getLocalRefPath(); // assume thumb was not scaled
|
|
|
|
|
} elseif ( FileBackend::isStoragePath( $this->path ) ) {
|
|
|
|
|
$be = $this->file->getRepo()->getBackend();
|
|
|
|
|
// The temp file will be process cached by FileBackend
|
|
|
|
|
$fsFile = $be->getLocalReference( array( 'src' => $this->path ) );
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2013-03-27 19:48:08 +00:00
|
|
|
return $fsFile ? $fsFile->getPath() : false;
|
2012-02-01 04:44:08 +00:00
|
|
|
} else {
|
|
|
|
|
return $this->path; // may return false
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stream the file if there were no errors
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $headers Additional HTTP headers to send on success
|
2015-08-30 00:13:04 +00:00
|
|
|
* @return Status
|
|
|
|
|
* @since 1.27
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
2015-08-30 00:13:04 +00:00
|
|
|
public function streamFileWithStatus( $headers = array() ) {
|
2012-08-23 04:13:40 +00:00
|
|
|
if ( !$this->path ) {
|
2015-08-30 00:13:04 +00:00
|
|
|
return Status::newFatal( 'backend-fail-stream', '<no path>' );
|
2012-08-23 04:13:40 +00:00
|
|
|
} elseif ( FileBackend::isStoragePath( $this->path ) ) {
|
|
|
|
|
$be = $this->file->getRepo()->getBackend();
|
2015-08-30 00:13:04 +00:00
|
|
|
return $be->streamFile( array( 'src' => $this->path, 'headers' => $headers ) );
|
2012-08-23 04:13:40 +00:00
|
|
|
} else { // FS-file
|
2015-08-30 00:13:04 +00:00
|
|
|
$success = StreamFile::stream( $this->getLocalCopyPath(), $headers );
|
|
|
|
|
return $success ? Status::newGood() : Status::newFatal( 'backend-fail-stream', $this->path );
|
2012-08-23 04:13:40 +00:00
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-30 00:13:04 +00:00
|
|
|
/**
|
|
|
|
|
* Stream the file if there were no errors
|
|
|
|
|
*
|
|
|
|
|
* @deprecated since 1.26, use streamFileWithStatus
|
|
|
|
|
* @param array $headers Additional HTTP headers to send on success
|
|
|
|
|
* @return bool Success
|
|
|
|
|
*/
|
|
|
|
|
public function streamFile( $headers = array() ) {
|
|
|
|
|
$this->streamFileWithStatus( $headers )->isOK();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Wrap some XHTML text in an anchor tag with the given attributes
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param array $linkAttribs
|
|
|
|
|
* @param string $contents
|
2011-05-28 18:59:42 +00:00
|
|
|
* @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
|
|
|
/**
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param string $title
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string|array $params Query parameters to add
|
2011-05-28 18:59:42 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-05-24 12:56:06 +00:00
|
|
|
public function getDescLinkAttribs( $title = null, $params = array() ) {
|
|
|
|
|
if ( is_array( $params ) ) {
|
|
|
|
|
$query = $params;
|
|
|
|
|
} else {
|
|
|
|
|
$query = array();
|
|
|
|
|
}
|
2012-10-17 22:00:54 +00:00
|
|
|
if ( $this->page && $this->page !== 1 ) {
|
2013-05-24 12:56:06 +00:00
|
|
|
$query['page'] = $this->page;
|
2012-10-17 22:00:54 +00:00
|
|
|
}
|
2013-08-24 15:06:25 +00:00
|
|
|
if ( $this->lang ) {
|
2013-05-24 12:56:06 +00:00
|
|
|
$query['lang'] = $this->lang;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( is_string( $params ) && $params !== '' ) {
|
|
|
|
|
$query = $params . '&' . wfArrayToCgi( $query );
|
2008-05-19 18:55:48 +00:00
|
|
|
}
|
2013-05-24 12:56:06 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2009-07-11 04:47:12 +00:00
|
|
|
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 {
|
|
|
|
|
/**
|
2012-02-01 04:44:08 +00:00
|
|
|
* Get a thumbnail object from a file and parameters.
|
|
|
|
|
* If $path is set to null, the output file is treated as a source copy.
|
|
|
|
|
* If $path is set to false, no output file will be created.
|
2012-08-29 20:09:36 +00:00
|
|
|
* $parameters should include, as a minimum, (file) 'width' and 'height'.
|
|
|
|
|
* It may also include a 'page' parameter for multipage files.
|
2012-07-13 15:07:56 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $url URL path to the thumb
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string|bool $path Filesystem path to the thumb
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $parameters Associative array of parameters
|
2007-04-20 12:31:36 +00:00
|
|
|
*/
|
2012-08-29 20:09:36 +00:00
|
|
|
function __construct( $file, $url, $path = false, $parameters = array() ) {
|
|
|
|
|
# Previous parameters:
|
|
|
|
|
# $file, $url, $width, $height, $path = false, $page = false
|
|
|
|
|
|
2013-05-24 12:56:06 +00:00
|
|
|
$defaults = array(
|
|
|
|
|
'page' => false,
|
|
|
|
|
'lang' => false
|
|
|
|
|
);
|
|
|
|
|
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( is_array( $parameters ) ) {
|
2012-08-29 20:09:36 +00:00
|
|
|
$actualParams = $parameters + $defaults;
|
|
|
|
|
} else {
|
|
|
|
|
# Using old format, should convert. Later a warning could be added here.
|
|
|
|
|
$numArgs = func_num_args();
|
|
|
|
|
$actualParams = array(
|
|
|
|
|
'width' => $path,
|
|
|
|
|
'height' => $parameters,
|
|
|
|
|
'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
|
2013-05-24 12:56:06 +00:00
|
|
|
) + $defaults;
|
2012-08-29 20:09:36 +00:00
|
|
|
$path = ( $numArgs > 4 ) ? func_get_arg( 4 ) : false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-31 02:51:23 +00:00
|
|
|
$this->file = $file;
|
2007-04-20 12:31:36 +00:00
|
|
|
$this->url = $url;
|
2012-08-29 20:09:36 +00:00
|
|
|
$this->path = $path;
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
# 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.
|
2012-08-29 20:09:36 +00:00
|
|
|
$this->width = round( $actualParams['width'] );
|
|
|
|
|
$this->height = round( $actualParams['height'] );
|
|
|
|
|
|
|
|
|
|
$this->page = $actualParams['page'];
|
2013-05-24 12:56:06 +00:00
|
|
|
$this->lang = $actualParams['lang'];
|
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
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $options 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
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
* override-width Override width attribute. Should generally not set
|
|
|
|
|
* override-height Override height attribute. Should generally not set
|
2013-10-19 00:24:59 +00:00
|
|
|
* no-dimensions Boolean, skip width and height attributes (useful if
|
|
|
|
|
* set in CSS)
|
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
|
2012-08-06 17:04:07 +00:00
|
|
|
* parser-extlink-* Attributes added by parser for external links:
|
|
|
|
|
* parser-extlink-rel: add rel="nofollow"
|
|
|
|
|
* parser-extlink-target: link target, but overridden by 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
|
|
|
*
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
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 ) {
|
2013-04-13 11:36:24 +00:00
|
|
|
throw new MWException( __METHOD__ . ' called in the old style' );
|
2007-08-31 02:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-03 14:14:35 +00:00
|
|
|
$alt = isset( $options['alt'] ) ? $options['alt'] : '';
|
2009-07-11 04:47:12 +00:00
|
|
|
|
2014-03-03 14:14:35 +00:00
|
|
|
$query = isset( $options['desc-query'] ) ? $options['desc-query'] : '';
|
2008-10-08 16:33:36 +00:00
|
|
|
|
2014-08-10 22:35:37 +00:00
|
|
|
$attribs = array(
|
|
|
|
|
'alt' => $alt,
|
|
|
|
|
'src' => $this->url,
|
|
|
|
|
);
|
|
|
|
|
|
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'];
|
2012-08-06 17:04:07 +00:00
|
|
|
} elseif ( !empty( $options['parser-extlink-target'] ) ) {
|
|
|
|
|
$linkAttribs['target'] = $options['parser-extlink-target'];
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $options['parser-extlink-rel'] ) ) {
|
|
|
|
|
$linkAttribs['rel'] = $options['parser-extlink-rel'];
|
2010-11-09 12:25:57 +00:00
|
|
|
}
|
2008-10-06 05:55:27 +00:00
|
|
|
} elseif ( !empty( $options['custom-title-link'] ) ) {
|
2013-12-05 19:27:27 +00:00
|
|
|
/** @var Title $title */
|
2008-10-06 05:55:27 +00:00
|
|
|
$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'] ) ) {
|
2013-12-05 11:33:18 +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;
|
2014-08-10 22:35:37 +00:00
|
|
|
if ( !empty( $options['title'] ) ) {
|
|
|
|
|
$attribs['title'] = $options['title'];
|
|
|
|
|
}
|
2007-08-31 02:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-19 00:24:59 +00:00
|
|
|
if ( empty( $options['no-dimensions'] ) ) {
|
|
|
|
|
$attribs['width'] = $this->width;
|
|
|
|
|
$attribs['height'] = $this->height;
|
|
|
|
|
}
|
2007-08-31 02:51:23 +00:00
|
|
|
if ( !empty( $options['valign'] ) ) {
|
|
|
|
|
$attribs['style'] = "vertical-align: {$options['valign']}";
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $options['img-class'] ) ) {
|
|
|
|
|
$attribs['class'] = $options['img-class'];
|
|
|
|
|
}
|
New more slick gallery display
This extension adds a "mode" parameter to the gallery
tag, allowing different formats for the gallery tag
(galleries in the ui can be controlled by a global)
The added modes are:
*traditional - The original gallery
*nolines - Like the original, no borders, less padding
*packed - All images aligned by having same height.
JS also justifies the images.
(I think this one is the one that will go over best
with users.)
*packed-overlay - like packed, but caption goes over
top the image in a transloucent box.
*packed-hover - like packed-overlay, but caption only
visible on hover. Degrades gracefully on screen
readers, and falls back to packed-overlay if
you are using a touch screen. I kind of like
this mode when the caption is not that important
(ex a category where its just the file name).
This also adds a hook to allow people to make their
own gallery version. I believe there would be interest
in this, as different people have done different
experiments. For example:
* Wikia: http://community.wikia.com/wiki/Help:Galleries,_Slideshows,_and_Sliders/wikitext
* Wikinews: https://en.wikinews.org/wiki/Template:Picture_select
What I would like to see for this patch, is first it gets
enabled, with the default still "traditional". After
about a month or two we consult with users. If feedback
is positive, we change the default mode to one of the
others (probably "packed").
Adds a "mode" parameter to gallery for different
mode, including one 'height-constrained-overlay'
which looks much more like other modern websites.
Note: This makes one change to the old gallery format.
It makes Nonexistent files be rendered like thumbnails
(i.e. they are rendered with a little grey border).
One thing I'm slightly worried about with this patch,
is that I added an option to MediaTransformOutput::toHtml
to override the width attribute. I'm not sure if that
is the best approach, and would appreciate thoughts
on that.
This should be merged at the same time as Ie82c1548
Change-Id: I33462a8b52502ed76aeb163b66e3704c8618ba23
2013-06-08 04:47:07 +00:00
|
|
|
if ( isset( $options['override-height'] ) ) {
|
|
|
|
|
$attribs['height'] = $options['override-height'];
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $options['override-width'] ) ) {
|
|
|
|
|
$attribs['width'] = $options['override-width'];
|
|
|
|
|
}
|
Initial stab at responsive images for screen densities.
* adds $wgResponsiveImages setting, defaulting to true, to enable the feature
* adds 'srcset' attribute with 1.5x and 2x URLs to image links and image thumbs
* adds jquery.hidpi plugin to check pixel density and implement partial 'srcset' polyfill
** $.devicePixelRatio() returns window.devicePixelRatio, with compat fallback for IE 10
** $().hidpi() performs a 'srcset' polyfill for browsers with no native 'srcset' support
* adds mediawiki.hidpi RL script to trigger hidpi loads after main images load
Note that this is a work in progress. There will be places where this doesn't yet work which output their imgs differently. If moving from a low to high-DPI screen on a MacBook Pro Retina display, you won't see images load until you reload.
Confirmed basic images and thumbs in wikitext appear to work in Safari 6, Chrome 21, Firefox 18 nightly on MacBook Pro Retina display, and IE 10 in Windows 8 at 150% zoom, 200% zoom, and 140% and 180%-ratio Metro tablet sizes.
Internally this is still a bit of a hack; Linker::makeImageLink and Linker::makeThumbLink explicitly ask for 1.5x and 2x scaled versions and insert their URLs, if different, into the original thumbnail object which (in default handler) outputs the srcset. This means that a number of places that handle images differently won't see the higher-resolution versions, such as <gallery> and the large thumbnail on the File: description page.
At some point we may wish to redo some of how the MediaHandler stuff works so that requesting a single thumbnail automatically produces the extra sizes in all circumstances. We might also consider outputting a 'srcset' or multiple src sizes in 'imageinfo' API requests, which would make ApiForeignRepo/InstantCommons more efficient. (Currently it has to make three requests for each image to get the three sizes.)
Change-Id: Id80ebd07a1a9f401a2c2bfeb21aae987e5aa863b
2012-09-18 07:18:50 +00:00
|
|
|
|
|
|
|
|
// Additional densities for responsive images, if specified.
|
|
|
|
|
if ( !empty( $this->responsiveUrls ) ) {
|
|
|
|
|
$attribs['srcset'] = Html::srcSet( $this->responsiveUrls );
|
|
|
|
|
}
|
2012-11-07 05:19:57 +00:00
|
|
|
|
2014-12-09 07:23:30 +00:00
|
|
|
Hooks::run( 'ThumbnailBeforeProduceHTML', array( $this, &$attribs, &$linkAttribs ) );
|
2012-11-07 05:19:57 +00:00
|
|
|
|
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 {
|
2013-12-05 13:08:49 +00:00
|
|
|
/** @var string HTML formatted version of the error */
|
|
|
|
|
private $htmlMsg;
|
|
|
|
|
|
|
|
|
|
/** @var string Plain text formatted version of the error */
|
|
|
|
|
private $textMsg;
|
2007-04-20 12:31:36 +00:00
|
|
|
|
|
|
|
|
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',
|
2013-02-03 19:42:08 +00:00
|
|
|
max( isset( $params['width'] ) ? $params['width'] : 0, 120 ),
|
2010-04-20 22:49:50 +00:00
|
|
|
max( isset( $params['height'] ) ? $params['height'] : 0, 120 ),
|
2012-08-19 23:05:20 +00:00
|
|
|
wfMessage( 'thumbnail_invalid_params' )->text() );
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-25 19:30:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shortcut class for parameter file size errors
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Media
|
|
|
|
|
* @since 1.25
|
|
|
|
|
*/
|
|
|
|
|
class TransformTooBigImageAreaError extends MediaTransformError {
|
|
|
|
|
function __construct( $params, $maxImageArea ) {
|
|
|
|
|
$msg = wfMessage( 'thumbnail_toobigimagearea' );
|
|
|
|
|
|
|
|
|
|
parent::__construct( 'thumbnail_error',
|
|
|
|
|
max( isset( $params['width'] ) ? $params['width'] : 0, 120 ),
|
|
|
|
|
max( isset( $params['height'] ) ? $params['height'] : 0, 120 ),
|
|
|
|
|
$msg->rawParams(
|
|
|
|
|
$msg->getLanguage()->formatComputingNumbers(
|
|
|
|
|
$maxImageArea, 1000, "size-$1pixel" )
|
|
|
|
|
)->text()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|