51 private const MAX_ERR_LOG_SIZE = 65535;
60 return MediaWikiServices::getInstance()
61 ->getMediaHandlerFactory()->getHandler( $type );
198 $rc =
new ReflectionClass( $this );
199 $rm =
new ReflectionMethod( $this, $name );
200 return $rm->getDeclaringClass()->getName() === $rc->getName();
231 if ( $info ===
false ) {
234 if ( $info !==
null ) {
235 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
236 if ( !is_array( $info[
'metadata'] ) ) {
237 throw new InvalidArgumentException(
'Media handler ' .
238 static::class .
' returned ' . get_debug_type( $info[
'metadata'] ) .
239 ' for metadata, should be array' );
252 if ( $blob ===
false && $size ===
false ) {
257 'width' => $size[0] ?? 0,
258 'height' => $size[1] ?? 0
260 if ( isset( $size[
'bits'] ) ) {
261 $info[
'bits'] = $size[
'bits'];
264 $info = [
'width' => 0,
'height' => 0 ];
266 if ( $blob !==
false ) {
268 $metadata = @unserialize( $blob );
269 if ( $metadata ===
false ) {
271 $metadata = [
'_error' => $blob ];
272 } elseif ( !is_array( $metadata ) ) {
275 $info[
'metadata'] = $metadata;
277 $info[
'metadata'] = [];
301 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onGetMetadataVersion( $version );
303 return implode(
';', $version );
352 return self::METADATA_GOOD;
381 return self::METADATA_GOOD;
453 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
454 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
471 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
484 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
485 if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) ===
false ) {
488 $knownExt = $magic->getExtensionFromMimeTypeOrNull( $mime );
489 if ( $knownExt !==
null ) {
490 return [ $knownExt, $mime ];
496 return [ $ext, $mime ];
644 for ( $i = 1; $i <= $numPages; $i++ ) {
646 if ( is_string( $curPage ) ) {
647 $document .= $curPage .
"\n";
650 if ( $document !==
'' ) {
709 foreach ( $metadataArray as $tag => $vals ) {
710 $v = $this->
formatTag( $tag, $vals, $context );
711 if ( $v ===
false ) {
717 unset( $metadataArray[$tag] );
720 $metadataArray[$tag] = [
'_formatted' => $v ];
721 if ( isset( $v[
'_type'] ) ) {
722 $metadataArray[$tag][
'_type'] = $v[
'_type'];
723 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
728 $formatted = FormatMetadata::getFormattedData( $metadataArray, $context );
731 foreach ( $formatted as $name => $value ) {
732 $tag = strtolower( $name );
733 self::addMeta( $result,
734 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
756 protected function formatTag(
string $key, $vals, $context =
false ) {
769 return FormatMetadata::getVisibleFields();
795 protected static function addMeta( &$array, $visibility, $type, $id, $value, $param =
false ) {
796 $msg =
wfMessage(
"$type-$id", (
string)$param );
797 if ( $msg->exists() ) {
798 $name = $msg->text();
805 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
808 $array[$visibility][] = [
824 return self::getGeneralShortDesc( $file );
836 return self::getGeneralLongDesc( $file );
848 return htmlspecialchars(
$wgLang->formatSize( $file->getSize() ) );
858 return wfMessage(
'file-info' )->sizeParams( $file->getSize() )
859 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )->parse();
870 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
871 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
872 $roundedUp = ceil( $idealWidth );
873 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
874 return (
int)floor( $idealWidth );
919 return Status::newGood();
933 if ( file_exists( $dstPath ) ) {
934 $thumbstat = stat( $dstPath );
935 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
936 $result = unlink( $dstPath );
940 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
941 $thumbstat[
'size'], $dstPath ) );
944 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
945 $thumbstat[
'size'], $dstPath ) );
1016 # Keep error output limited (T59985)
1017 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1020 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1021 wfHostname(), $retval, $errMessage, $cmd ) );
1160 $pageRangesByDimensions = [];
1162 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1164 $firstPage = $pageList[0];
1165 $lastPage = $firstPage - 1;
1167 foreach ( $pageList as $page ) {
1168 if ( $page > $lastPage + 1 ) {
1169 if ( $firstPage !== $lastPage ) {
1170 $ranges[] =
"$firstPage-$lastPage";
1172 $ranges[] =
"$firstPage";
1181 if ( $firstPage != $lastPage ) {
1182 $ranges[] =
"$firstPage-$lastPage";
1184 $ranges[] =
"$firstPage";
1187 $pageRangesByDimensions[ $dimensions ] = $ranges;
1190 $dimensionsString = [];
1191 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1192 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1195 return implode(
'/', $dimensionsString );
1207 return [
'X-Content-Dimensions' =>
'' ];
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfHostname()
Get host name of the current machine, for use in error reporting.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
Interface for objects which can provide a MediaWiki context on request.