39 private function getFileInfo(
$file,
Authority $performer, $transforms ) {
40 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
44 'title' =>
$file->getTitle()->getText(),
51 foreach ( array_keys( $transforms ) as $transformType ) {
52 $responseFile[$transformType] =
null;
55 if (
$file->exists() ) {
56 $uploader =
$file->getUploader( File::FOR_THIS_USER, $performer );
59 'id' => $uploader->getId(),
60 'name' => $uploader->getName(),
68 $responseFile[
'latest'] = [
76 $duration =
$file->getLength();
78 if ( $duration == 0 && !in_array(
$file->getMediaType(), $mediaTypesWithDurations ) ) {
82 if (
$file->allowInlineDisplay() ) {
83 foreach ( $transforms as $transformType => $transform ) {
84 $responseFile[$transformType] = $this->getTransformInfo(
88 $transform[
'maxWidth'],
89 $transform[
'maxHeight']
94 $responseFile[
'original'] = [
95 'mediatype' =>
$file->getMediaType(),
96 'size' =>
$file->getSize(),
97 'width' =>
$file->getWidth() ?:
null,
98 'height' =>
$file->getHeight() ?:
null,
99 'duration' => $duration,
104 return $responseFile;
114 private function getTransformInfo(
$file, $duration, $maxWidth, $maxHeight ) {
115 $transformInfo =
null;
118 [ $width, $height ] =
$file->getDisplayWidthHeight( $maxWidth, $maxHeight );
119 $transform =
$file->transform( [
'width' => $width,
'height' => $height ] );
120 if ( $transform && !$transform->isError() ) {
123 if (
$file->getWidth() == $transform->getWidth() &&
124 $file->getHeight() == $transform->getHeight()
126 $size =
$file->getSize();
130 'mediatype' => $transform->getFile()->getMediaType(),
132 'width' => $transform->getWidth() ?:
null,
133 'height' => $transform->getHeight() ?:
null,
134 'duration' => $duration,
135 'url' => MediaWikiServices::getInstance()->getUrlUtils()
143 return $transformInfo;
154 public static function getImageLimitsFromOption(
UserIdentity $user,
string $optionName ) {
155 $imageLimits = MediaWikiServices::getInstance()->getMainConfig()
156 ->get( MainConfigNames::ImageLimits );
157 $optionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
158 $option = $optionsLookup->getIntOption( $user, $optionName );
159 if ( !isset( $imageLimits[$option] ) ) {
160 $option = $optionsLookup->getDefaultOption( $optionName );
165 if ( !isset( $imageLimits[$option] ) ) {
171 return $imageLimits[$option] ?? [ 800, 600 ];
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
A class containing constants representing the names of configuration variables.
const MEDIATYPE_MULTIMEDIA
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.