2007-04-20 12:31:36 +00:00
|
|
|
<?php
|
2022-01-06 18:44:56 +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
|
|
|
/**
|
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
|
|
|
|
2022-04-26 15:48:03 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2022-01-06 18:44:56 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-08-25 12:29:41 +00:00
|
|
|
use MediaWiki\Status\Status;
|
2024-05-16 10:52:03 +00:00
|
|
|
use MediaWiki\Xml\Xml;
|
2024-05-19 13:40:05 +00:00
|
|
|
use Wikimedia\FileBackend\FileBackend;
|
2024-10-21 18:33:42 +00:00
|
|
|
use Wikimedia\FileBackend\HTTPFileStreamer;
|
2022-01-06 18:44:56 +00:00
|
|
|
|
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
|
|
|
*
|
2020-07-13 09:00:30 +00:00
|
|
|
* @stable to extend
|
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
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public $responsiveUrls = [];
|
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
|
|
|
|
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;
|
|
|
|
|
|
2022-03-03 20:33:11 +00:00
|
|
|
/** @var string|false URL path to the thumb */
|
2013-12-05 13:08:49 +00:00
|
|
|
protected $url;
|
|
|
|
|
|
2022-03-28 20:55:34 +00:00
|
|
|
/** @var string|false */
|
2013-12-05 13:08:49 +00:00
|
|
|
protected $page;
|
|
|
|
|
|
2022-03-08 22:57:00 +00:00
|
|
|
/** @var string|null|false Filesystem path to the thumb */
|
2013-12-05 13:08:49 +00:00
|
|
|
protected $path;
|
|
|
|
|
|
2022-03-28 20:55:34 +00:00
|
|
|
/** @var string|false Language code, false if not set */
|
2013-12-05 13:08:49 +00:00
|
|
|
protected $lang;
|
|
|
|
|
|
2022-03-28 20:55:34 +00:00
|
|
|
/** @var string|false 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.
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 19:15:09 +00:00
|
|
|
*
|
2022-03-28 20:55:34 +00:00
|
|
|
* @return string|false
|
2012-07-13 15:07:56 +00:00
|
|
|
*/
|
|
|
|
|
public function getExtension() {
|
|
|
|
|
return $this->path ? FileBackend::extensionFromPath( $this->path ) : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 19:15:09 +00:00
|
|
|
*
|
2022-03-28 20:55:34 +00:00
|
|
|
* @return string|false 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
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 19:15:09 +00:00
|
|
|
*
|
2022-03-28 20:55:34 +00:00
|
|
|
* @return string|false The permanent thumbnail storage path
|
2012-01-05 01:58:05 +00:00
|
|
|
*/
|
|
|
|
|
public function getStoragePath() {
|
|
|
|
|
return $this->storagePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 19:15:09 +00:00
|
|
|
*
|
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
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
abstract public function toHtml( $options = [] );
|
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
|
|
|
*
|
2022-03-28 20:55:34 +00:00
|
|
|
* @return string|false 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;
|
2023-03-08 20:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->path === null ) {
|
2013-03-27 19:48:08 +00:00
|
|
|
return $this->file->getLocalRefPath(); // assume thumb was not scaled
|
2023-03-08 20:44:20 +00:00
|
|
|
}
|
|
|
|
|
if ( FileBackend::isStoragePath( $this->path ) ) {
|
2013-03-27 19:48:08 +00:00
|
|
|
$be = $this->file->getRepo()->getBackend();
|
|
|
|
|
// The temp file will be process cached by FileBackend
|
2016-02-17 09:09:32 +00:00
|
|
|
$fsFile = $be->getLocalReference( [ '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
|
|
|
}
|
2023-03-08 20:44:20 +00:00
|
|
|
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
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function streamFileWithStatus( $headers = [] ) {
|
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>' );
|
2023-03-08 20:44:20 +00:00
|
|
|
}
|
2024-03-13 21:42:04 +00:00
|
|
|
|
|
|
|
|
$repo = $this->file->getRepo();
|
|
|
|
|
|
|
|
|
|
if ( $repo && FileBackend::isStoragePath( $this->path ) ) {
|
2019-04-20 03:13:49 +00:00
|
|
|
return Status::wrap(
|
2024-03-13 21:42:04 +00:00
|
|
|
$repo->getBackend()->streamFile(
|
|
|
|
|
[ 'src' => $this->path, 'headers' => $headers, ]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$streamer = new HTTPFileStreamer(
|
|
|
|
|
$this->getLocalCopyPath(),
|
|
|
|
|
$repo ? $repo->getBackend()->getStreamerOptions() : []
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$success = $streamer->stream( $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
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function streamFile( $headers = [] ) {
|
2018-12-03 14:26:02 +00:00
|
|
|
return $this->streamFileWithStatus( $headers )->isOK();
|
2015-08-30 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
/**
|
|
|
|
|
* Wrap some XHTML text in an anchor tag with the given attributes
|
2018-02-13 22:51:22 +00:00
|
|
|
* or, fallback to a span in the absence thereof.
|
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 ) {
|
2022-05-09 20:35:04 +00:00
|
|
|
if ( isset( $linkAttribs['href'] ) ) {
|
2007-04-20 12:31:36 +00:00
|
|
|
return Xml::tags( 'a', $linkAttribs, $contents );
|
|
|
|
|
}
|
2023-03-08 20:44:20 +00:00
|
|
|
$parserEnableLegacyMediaDOM = MediaWikiServices::getInstance()
|
|
|
|
|
->getMainConfig()->get( MainConfigNames::ParserEnableLegacyMediaDOM );
|
|
|
|
|
if ( $parserEnableLegacyMediaDOM ) {
|
|
|
|
|
return $contents;
|
|
|
|
|
}
|
|
|
|
|
return Xml::tags( 'span', $linkAttribs ?: null, $contents );
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
2007-08-31 02:51:23 +00:00
|
|
|
|
2011-05-28 18:59:42 +00:00
|
|
|
/**
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $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
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function getDescLinkAttribs( $title = null, $params = [] ) {
|
2013-05-24 12:56:06 +00:00
|
|
|
if ( is_array( $params ) ) {
|
|
|
|
|
$query = $params;
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$query = [];
|
2013-05-24 12:56:06 +00:00
|
|
|
}
|
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
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs = [
|
2007-08-31 02:51:23 +00:00
|
|
|
'href' => $this->file->getTitle()->getLocalURL( $query ),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2018-02-13 22:51:22 +00:00
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
$parserEnableLegacyMediaDOM = MediaWikiServices::getInstance()
|
2022-04-26 15:48:03 +00:00
|
|
|
->getMainConfig()->get( MainConfigNames::ParserEnableLegacyMediaDOM );
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( $parserEnableLegacyMediaDOM ) {
|
2018-02-13 22:51:22 +00:00
|
|
|
$attribs['class'] = 'image';
|
2022-02-18 23:37:32 +00:00
|
|
|
} else {
|
|
|
|
|
$attribs['class'] = 'mw-file-description';
|
2018-02-13 22:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|