2008-05-20 06:30:36 +00:00
|
|
|
<?php
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* Foreign file accessible through api.php requests.
|
|
|
|
|
*
|
2012-05-07 07:11:33 +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
|
|
|
|
|
*
|
2010-09-04 18:13:18 +00:00
|
|
|
* @file
|
2012-02-08 15:51:16 +00:00
|
|
|
* @ingroup FileAbstraction
|
2010-09-04 18:13:18 +00:00
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
|
2018-05-04 13:39:33 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* Foreign file accessible through api.php requests.
|
|
|
|
|
* Very hacky and inefficient, do not use :D
|
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
|
|
|
*
|
2012-02-08 15:51:16 +00:00
|
|
|
* @ingroup FileAbstraction
|
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
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
class ForeignAPIFile extends File {
|
2016-09-18 05:29:06 +00:00
|
|
|
/** @var bool */
|
2008-12-04 21:21:48 +00:00
|
|
|
private $mExists;
|
2016-09-18 05:29:06 +00:00
|
|
|
/** @var array */
|
|
|
|
|
private $mInfo = [];
|
2011-02-18 23:56:08 +00:00
|
|
|
|
2018-05-04 06:58:42 +00:00
|
|
|
protected $repoClass = ForeignAPIRepo::class;
|
2011-11-07 21:54:19 +00:00
|
|
|
|
2011-02-18 23:56:08 +00:00
|
|
|
/**
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param Title|string|bool $title
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param ForeignApiRepo $repo
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param array $info
|
2011-02-18 23:56:08 +00:00
|
|
|
* @param bool $exists
|
|
|
|
|
*/
|
2008-12-04 21:21:48 +00:00
|
|
|
function __construct( $title, $repo, $info, $exists = false ) {
|
2008-05-20 06:30:36 +00:00
|
|
|
parent::__construct( $title, $repo );
|
2011-11-07 21:54:19 +00:00
|
|
|
|
2008-05-20 06:30:36 +00:00
|
|
|
$this->mInfo = $info;
|
2008-12-04 21:21:48 +00:00
|
|
|
$this->mExists = $exists;
|
2011-11-07 21:54:19 +00:00
|
|
|
|
|
|
|
|
$this->assertRepoDefined();
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-01-06 15:47:57 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param ForeignApiRepo $repo
|
2011-01-06 15:47:57 +00:00
|
|
|
* @return ForeignAPIFile|null
|
|
|
|
|
*/
|
2011-11-04 23:33:53 +00:00
|
|
|
static function newFromTitle( Title $title, $repo ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$data = $repo->fetchImageQuery( [
|
2013-04-20 17:18:13 +00:00
|
|
|
'titles' => 'File:' . $title->getDBkey(),
|
|
|
|
|
'iiprop' => self::getProps(),
|
|
|
|
|
'prop' => 'imageinfo',
|
2013-10-28 18:18:05 +00:00
|
|
|
'iimetadataversion' => MediaHandler::getMetadataVersion(),
|
|
|
|
|
// extmetadata is language-dependant, accessing the current language here
|
|
|
|
|
// would be problematic, so we just get them all
|
|
|
|
|
'iiextmetadatamultilang' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2010-05-21 15:59:01 +00:00
|
|
|
|
|
|
|
|
$info = $repo->getImageInfo( $data );
|
|
|
|
|
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $info ) {
|
2011-01-06 15:47:57 +00:00
|
|
|
$lastRedirect = isset( $data['query']['redirects'] )
|
|
|
|
|
? count( $data['query']['redirects'] ) - 1
|
|
|
|
|
: -1;
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $lastRedirect >= 0 ) {
|
2013-03-24 10:01:51 +00:00
|
|
|
$newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to'] );
|
2011-11-04 23:33:53 +00:00
|
|
|
$img = new self( $newtitle, $repo, $info, true );
|
2018-12-02 18:14:36 +00:00
|
|
|
$img->redirectedFrom( $title->getDBkey() );
|
2010-05-21 15:59:01 +00:00
|
|
|
} else {
|
2011-11-04 23:33:53 +00:00
|
|
|
$img = new self( $title, $repo, $info, true );
|
2010-05-21 15:59:01 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2010-05-21 15:59:01 +00:00
|
|
|
return $img;
|
2008-05-22 16:17:42 +00:00
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2010-07-02 18:37:06 +00:00
|
|
|
/**
|
|
|
|
|
* Get the property string for iiprop and aiprop
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return string
|
2010-07-02 18:37:06 +00:00
|
|
|
*/
|
|
|
|
|
static function getProps() {
|
2013-10-09 22:14:52 +00:00
|
|
|
return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
|
2010-07-02 18:37:06 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2008-05-20 06:30:36 +00:00
|
|
|
// Dummy functions...
|
2012-05-18 02:58:15 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function exists() {
|
2008-12-04 21:21:48 +00:00
|
|
|
return $this->mExists;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function getPath() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-05-21 22:39:08 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $params
|
2012-05-18 02:58:15 +00:00
|
|
|
* @param int $flags
|
|
|
|
|
* @return bool|MediaTransformOutput
|
|
|
|
|
*/
|
2008-05-21 22:39:08 +00:00
|
|
|
function transform( $params, $flags = 0 ) {
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( !$this->canRender() ) {
|
2008-12-23 17:35:05 +00:00
|
|
|
// show icon
|
|
|
|
|
return parent::transform( $params, $flags );
|
|
|
|
|
}
|
2011-02-05 08:49:48 +00:00
|
|
|
|
2011-02-13 07:30:49 +00:00
|
|
|
// Note, the this->canRender() check above implies
|
|
|
|
|
// that we have a handler, and it can do makeParamString.
|
|
|
|
|
$otherParams = $this->handler->makeParamString( $params );
|
2017-10-06 22:17:58 +00:00
|
|
|
$width = $params['width'] ?? -1;
|
|
|
|
|
$height = $params['height'] ?? -1;
|
2011-02-05 08:49:48 +00:00
|
|
|
|
2008-09-29 08:23:16 +00:00
|
|
|
$thumbUrl = $this->repo->getThumbUrlFromCache(
|
2010-11-05 18:01:16 +00:00
|
|
|
$this->getName(),
|
2013-04-13 14:28:02 +00:00
|
|
|
$width,
|
|
|
|
|
$height,
|
|
|
|
|
$otherParams
|
|
|
|
|
);
|
|
|
|
|
if ( $thumbUrl === false ) {
|
|
|
|
|
global $wgLang;
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2013-04-13 14:28:02 +00:00
|
|
|
return $this->repo->getThumbError(
|
|
|
|
|
$this->getName(),
|
|
|
|
|
$width,
|
|
|
|
|
$height,
|
|
|
|
|
$otherParams,
|
|
|
|
|
$wgLang->getCode()
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2010-08-24 22:03:18 +00:00
|
|
|
return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2008-05-21 22:39:08 +00:00
|
|
|
|
2008-05-20 06:30:36 +00:00
|
|
|
// Info we can get from API...
|
2012-05-18 02:58:15 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $page
|
2012-05-18 02:58:15 +00:00
|
|
|
* @return int|number
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function getWidth( $page = 1 ) {
|
2011-07-06 22:07:05 +00:00
|
|
|
return isset( $this->mInfo['width'] ) ? intval( $this->mInfo['width'] ) : 0;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $page
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function getHeight( $page = 1 ) {
|
2011-07-06 22:07:05 +00:00
|
|
|
return isset( $this->mInfo['height'] ) ? intval( $this->mInfo['height'] ) : 0;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool|null|string
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function getMetadata() {
|
2009-02-18 23:21:51 +00:00
|
|
|
if ( isset( $this->mInfo['metadata'] ) ) {
|
2009-05-05 09:47:53 +00:00
|
|
|
return serialize( self::parseMetadata( $this->mInfo['metadata'] ) );
|
2009-02-18 23:21:51 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-02-18 23:21:51 +00:00
|
|
|
return null;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2013-08-12 16:18:29 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return array|null Extended metadata (see imageinfo API for format) or
|
|
|
|
|
* null on error
|
2013-08-12 16:18:29 +00:00
|
|
|
*/
|
|
|
|
|
public function getExtendedMetadata() {
|
|
|
|
|
if ( isset( $this->mInfo['extmetadata'] ) ) {
|
|
|
|
|
return $this->mInfo['extmetadata'];
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2013-08-12 16:18:29 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2018-04-19 08:30:33 +00:00
|
|
|
* @param mixed $metadata
|
|
|
|
|
* @return mixed
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2009-05-05 09:47:53 +00:00
|
|
|
public static function parseMetadata( $metadata ) {
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( !is_array( $metadata ) ) {
|
2009-05-05 09:47:53 +00:00
|
|
|
return $metadata;
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret = [];
|
2013-04-20 17:18:13 +00:00
|
|
|
foreach ( $metadata as $meta ) {
|
2013-03-24 10:01:51 +00:00
|
|
|
$ret[$meta['name']] = self::parseMetadata( $meta['value'] );
|
2009-05-05 09:47:53 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-05-05 09:47:53 +00:00
|
|
|
return $ret;
|
|
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool|int|null
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function getSize() {
|
2010-07-02 18:37:06 +00:00
|
|
|
return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return null|string
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
public function getUrl() {
|
2010-07-02 18:37:06 +00:00
|
|
|
return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-04 23:40:01 +00:00
|
|
|
/**
|
|
|
|
|
* Get short description URL for a file based on the foreign API response,
|
|
|
|
|
* or if unavailable, the short URL is constructed from the foreign page ID.
|
|
|
|
|
*
|
|
|
|
|
* @return null|string
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
public function getDescriptionShortUrl() {
|
|
|
|
|
if ( isset( $this->mInfo['descriptionshorturl'] ) ) {
|
|
|
|
|
return $this->mInfo['descriptionshorturl'];
|
|
|
|
|
} elseif ( isset( $this->mInfo['pageid'] ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$url = $this->repo->makeUrl( [ 'curid' => $this->mInfo['pageid'] ] );
|
2016-01-04 23:40:01 +00:00
|
|
|
if ( $url !== false ) {
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2015-05-06 15:33:08 +00:00
|
|
|
* @param string $type
|
2012-05-18 02:58:15 +00:00
|
|
|
* @return int|null|string
|
|
|
|
|
*/
|
2015-05-06 15:33:08 +00:00
|
|
|
public function getUser( $type = 'text' ) {
|
|
|
|
|
if ( $type == 'text' ) {
|
|
|
|
|
return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null;
|
2016-09-18 05:29:06 +00:00
|
|
|
} else {
|
2015-05-06 15:33:08 +00:00
|
|
|
return 0; // What makes sense here, for a remote user?
|
|
|
|
|
}
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $audience
|
2018-04-19 08:30:33 +00:00
|
|
|
* @param User|null $user
|
2012-05-18 02:58:15 +00:00
|
|
|
* @return null|string
|
|
|
|
|
*/
|
2012-06-06 00:29:40 +00:00
|
|
|
public function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
|
2010-07-02 18:37:06 +00:00
|
|
|
return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null;
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return null|string
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2008-05-22 16:17:42 +00:00
|
|
|
function getSha1() {
|
2011-12-20 03:52:06 +00:00
|
|
|
return isset( $this->mInfo['sha1'] )
|
2015-11-24 22:51:42 +00:00
|
|
|
? Wikimedia\base_convert( strval( $this->mInfo['sha1'] ), 16, 36, 31 )
|
2011-12-20 03:52:06 +00:00
|
|
|
: null;
|
2008-05-22 16:17:42 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return bool|string
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2008-05-22 16:17:42 +00:00
|
|
|
function getTimestamp() {
|
2011-09-07 12:00:58 +00:00
|
|
|
return wfTimestamp( TS_MW,
|
2011-12-20 03:52:06 +00:00
|
|
|
isset( $this->mInfo['timestamp'] )
|
|
|
|
|
? strval( $this->mInfo['timestamp'] )
|
|
|
|
|
: null
|
2010-07-02 18:37:06 +00:00
|
|
|
);
|
2008-05-22 16:17:42 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
function getMimeType() {
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( !isset( $this->mInfo['mime'] ) ) {
|
2017-11-27 01:33:57 +00:00
|
|
|
$magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
|
2009-02-18 22:52:33 +00:00
|
|
|
$this->mInfo['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
|
2008-05-22 16:25:45 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-02-18 22:52:33 +00:00
|
|
|
return $this->mInfo['mime'];
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return int|string
|
|
|
|
|
*/
|
2008-05-20 06:30:36 +00:00
|
|
|
function getMediaType() {
|
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( $this->mInfo['mediatype'] ) ) {
|
|
|
|
|
return $this->mInfo['mediatype'];
|
|
|
|
|
}
|
2017-11-27 01:33:57 +00:00
|
|
|
$magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-05-22 16:25:45 +00:00
|
|
|
return $magic->getMediaType( null, $this->getMimeType() );
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool|string
|
|
|
|
|
*/
|
2008-05-21 22:39:08 +00:00
|
|
|
function getDescriptionUrl() {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $this->mInfo['descriptionurl'] ?? false;
|
2008-05-21 22:39:08 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2008-08-24 20:02:50 +00:00
|
|
|
/**
|
|
|
|
|
* Only useful if we're locally caching thumbs anyway...
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $suffix
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return null|string
|
2008-08-24 20:02:50 +00:00
|
|
|
*/
|
|
|
|
|
function getThumbPath( $suffix = '' ) {
|
2008-09-23 00:07:24 +00:00
|
|
|
if ( $this->repo->canCacheThumbs() ) {
|
2018-12-01 16:48:35 +00:00
|
|
|
$path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getHashPath();
|
2008-08-24 20:02:50 +00:00
|
|
|
if ( $suffix ) {
|
|
|
|
|
$path = $path . $suffix . '/';
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-08-24 20:02:50 +00:00
|
|
|
return $path;
|
2010-11-05 18:01:16 +00:00
|
|
|
} else {
|
|
|
|
|
return null;
|
2008-08-24 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2018-04-19 08:30:33 +00:00
|
|
|
* @return string[]
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2008-08-24 20:02:50 +00:00
|
|
|
function getThumbnails() {
|
|
|
|
|
$dir = $this->getThumbPath( $this->getName() );
|
2016-02-17 09:09:32 +00:00
|
|
|
$iter = $this->repo->getBackend()->getFileList( [ 'dir' => $dir ] );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$files = [];
|
2018-02-07 18:39:03 +00:00
|
|
|
if ( $iter ) {
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$files[] = $file;
|
|
|
|
|
}
|
2008-08-24 20:02:50 +00:00
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2008-08-24 20:02:50 +00:00
|
|
|
return $files;
|
|
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
function purgeCache( $options = [] ) {
|
2011-11-28 08:53:03 +00:00
|
|
|
$this->purgeThumbnails( $options );
|
2008-08-24 20:02:50 +00:00
|
|
|
$this->purgeDescriptionPage();
|
|
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2008-08-24 20:02:50 +00:00
|
|
|
function purgeDescriptionPage() {
|
2018-08-18 04:02:39 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2018-07-29 12:24:54 +00:00
|
|
|
$url = $this->repo->getDescriptionRenderUrl(
|
2018-08-18 04:02:39 +00:00
|
|
|
$this->getName(), $services->getContentLanguage()->getCode() );
|
2013-02-03 19:42:08 +00:00
|
|
|
$key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', md5( $url ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2018-08-18 04:02:39 +00:00
|
|
|
$services->getMainWANObjectCache()->delete( $key );
|
2008-08-24 20:02:50 +00:00
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param array $options
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
function purgeThumbnails( $options = [] ) {
|
2009-06-17 07:31:00 +00:00
|
|
|
$key = $this->repo->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $this->getName() );
|
2018-05-04 13:39:33 +00:00
|
|
|
MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2008-08-24 20:02:50 +00:00
|
|
|
$files = $this->getThumbnails();
|
2011-11-28 08:53:03 +00:00
|
|
|
// Give media handler a chance to filter the purge list
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
$handler->filterThumbnailPurgeList( $files, $options );
|
|
|
|
|
}
|
2012-01-21 00:04:09 +00:00
|
|
|
|
2008-08-24 20:02:50 +00:00
|
|
|
$dir = $this->getThumbPath( $this->getName() );
|
2016-02-17 09:09:32 +00:00
|
|
|
$purgeList = [];
|
2008-08-24 20:02:50 +00:00
|
|
|
foreach ( $files as $file ) {
|
2012-01-21 00:04:09 +00:00
|
|
|
$purgeList[] = "{$dir}{$file}";
|
2008-08-24 20:02:50 +00:00
|
|
|
}
|
2012-01-21 00:04:09 +00:00
|
|
|
|
|
|
|
|
# Delete the thumbnails
|
2012-04-16 23:51:55 +00:00
|
|
|
$this->repo->quickPurgeBatch( $purgeList );
|
2012-01-21 00:04:09 +00:00
|
|
|
# Clear out the thumbnail directory if empty
|
2012-04-25 17:47:59 +00:00
|
|
|
$this->repo->quickCleanDir( $dir );
|
2008-08-24 20:02:50 +00:00
|
|
|
}
|
2015-01-24 17:30:17 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The thumbnail is created on the foreign server and fetched over internet
|
|
|
|
|
* @since 1.25
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isTransformedLocally() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-05-20 06:30:36 +00:00
|
|
|
}
|