39 private function getFileInfo( $file,
Authority $performer, $transforms ) {
40 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
44 'title' => $file->getTitle()->getText(),
45 'file_description_url' => $urlUtils->expand( $file->getDescriptionUrl(),
PROTO_RELATIVE ),
51 foreach ( $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'] = [
69 'timestamp' =>
wfTimestamp( TS_ISO_8601, $file->getTimestamp() ),
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;
117 [ $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,
134 'url' => MediaWikiServices::getInstance()->getUrlUtils()
139 return $transformInfo;
150 public static function getImageLimitsFromOption(
UserIdentity $user,
string $optionName ) {
151 $imageLimits = MediaWikiServices::getInstance()->getMainConfig()
152 ->get( MainConfigNames::ImageLimits );
153 $optionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
154 $option = $optionsLookup->getIntOption( $user, $optionName );
155 if ( !isset( $imageLimits[$option] ) ) {
156 $option = $optionsLookup->getDefaultOption( $optionName, $user );
161 if ( !isset( $imageLimits[$option] ) ) {
167 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