39 private function getFileInfo(
$file,
Authority $performer, $transforms ) {
43 'title' =>
$file->getTitle()->getText(),
50 foreach ( array_keys( $transforms ) as $transformType ) {
51 $responseFile[$transformType] =
null;
54 if (
$file->exists() ) {
55 $uploader =
$file->getUploader( File::FOR_THIS_USER, $performer );
58 'id' => $uploader->getId(),
59 'name' => $uploader->getName(),
67 $responseFile[
'latest'] = [
75 $duration =
$file->getLength();
77 if ( $duration == 0 && !in_array(
$file->getMediaType(), $mediaTypesWithDurations ) ) {
81 if (
$file->allowInlineDisplay() ) {
82 foreach ( $transforms as $transformType => $transform ) {
83 $responseFile[$transformType] = $this->getTransformInfo(
87 $transform[
'maxWidth'],
88 $transform[
'maxHeight']
93 $responseFile[
'original'] = [
94 'mediatype' =>
$file->getMediaType(),
95 'size' =>
$file->getSize(),
96 'width' =>
$file->getWidth() ?:
null,
97 'height' =>
$file->getHeight() ?:
null,
98 'duration' => $duration,
103 return $responseFile;
113 private function getTransformInfo(
$file, $duration, $maxWidth, $maxHeight ) {
114 $transformInfo =
null;
117 list( $width, $height ) =
$file->getDisplayWidthHeight( $maxWidth, $maxHeight );
118 $transform =
$file->transform( [
'width' => $width,
'height' => $height ] );
119 if ( $transform && !$transform->isError() ) {
122 if (
$file->getWidth() == $transform->getWidth() &&
123 $file->getHeight() == $transform->getHeight()
125 $size =
$file->getSize();
129 'mediatype' => $transform->getFile()->getMediaType(),
131 'width' => $transform->getWidth() ?:
null,
132 'height' => $transform->getHeight() ?:
null,
133 'duration' => $duration,
141 return $transformInfo;
152 public static function getImageLimitsFromOption(
UserIdentity $user,
string $optionName ) {
153 $imageLimits = MediaWikiServices::getInstance()->getMainConfig()
154 ->get( MainConfigNames::ImageLimits );
155 $optionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
156 $option = $optionsLookup->getIntOption( $user, $optionName );
157 if ( !isset( $imageLimits[$option] ) ) {
158 $option = $optionsLookup->getDefaultOption( $optionName );
163 if ( !isset( $imageLimits[$option] ) ) {
169 return $imageLimits[$option] ?? [ 800, 600 ];
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
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.