49 private const MAX_ERR_LOG_SIZE = 65535;
58 return MediaWikiServices::getInstance()
59 ->getMediaHandlerFactory()->getHandler( $type );
196 $rc =
new ReflectionClass( $this );
197 $rm =
new ReflectionMethod( $this, $name );
198 return $rm->getDeclaringClass()->getName() === $rc->getName();
229 if ( $info ===
false ) {
232 if ( $info !==
null ) {
233 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
234 if ( !is_array( $info[
'metadata'] ) ) {
235 throw new InvalidArgumentException(
'Media handler ' .
236 static::class .
' returned ' . get_debug_type( $info[
'metadata'] ) .
237 ' for metadata, should be array' );
250 if ( $blob ===
false && $size ===
false ) {
255 'width' => $size[0] ?? 0,
256 'height' => $size[1] ?? 0
258 if ( isset( $size[
'bits'] ) ) {
259 $info[
'bits'] = $size[
'bits'];
262 $info = [
'width' => 0,
'height' => 0 ];
264 if ( $blob !==
false ) {
266 $metadata = @unserialize( $blob );
267 if ( $metadata ===
false ) {
269 $metadata = [
'_error' => $blob ];
270 } elseif ( !is_array( $metadata ) ) {
273 $info[
'metadata'] = $metadata;
275 $info[
'metadata'] = [];
299 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onGetMetadataVersion( $version );
301 return implode(
';', $version );
350 return self::METADATA_GOOD;
379 return self::METADATA_GOOD;
452 return $this->
doTransform( $image, $dstPath, $dstUrl,
$params, self::TRANSFORM_LATER );
482 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
483 if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) ===
false ) {
486 $knownExt = $magic->getExtensionFromMimeTypeOrNull( $mime );
487 if ( $knownExt !==
null ) {
488 return [ $knownExt, $mime ];
494 return [ $ext, $mime ];
642 for ( $i = 1; $i <= $numPages; $i++ ) {
644 if ( is_string( $curPage ) ) {
645 $document .= $curPage .
"\n";
648 if ( $document !==
'' ) {
707 foreach ( $metadataArray as $tag => $vals ) {
708 $v = $this->
formatTag( $tag, $vals, $context );
709 if ( $v ===
false ) {
715 unset( $metadataArray[$tag] );
718 $metadataArray[$tag] = [
'_formatted' => $v ];
719 if ( isset( $v[
'_type'] ) ) {
720 $metadataArray[$tag][
'_type'] = $v[
'_type'];
721 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
726 $formatted = FormatMetadata::getFormattedData( $metadataArray, $context );
729 foreach ( $formatted as $name => $value ) {
730 $tag = strtolower( $name );
731 self::addMeta( $result,
732 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
754 protected function formatTag(
string $key, $vals, $context =
false ) {
767 return FormatMetadata::getVisibleFields();
793 protected static function addMeta( &$array, $visibility, $type, $id, $value, $param =
false ) {
794 $msg =
wfMessage(
"$type-$id", (
string)$param );
795 if ( $msg->exists() ) {
796 $name = $msg->text();
803 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
806 $array[$visibility][] = [
822 return self::getGeneralShortDesc( $file );
834 return self::getGeneralLongDesc( $file );
846 return htmlspecialchars(
$wgLang->formatSize( $file->getSize() ) );
856 return wfMessage(
'file-info' )->sizeParams( $file->getSize() )
857 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )->parse();
868 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
869 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
870 $roundedUp = ceil( $idealWidth );
871 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
872 return (
int)floor( $idealWidth );
917 return Status::newGood();
931 if ( file_exists( $dstPath ) ) {
932 $thumbstat = stat( $dstPath );
933 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
934 $result = unlink( $dstPath );
938 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
939 $thumbstat[
'size'], $dstPath ) );
942 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
943 $thumbstat[
'size'], $dstPath ) );
1014 # Keep error output limited (T59985)
1015 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1018 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1019 wfHostname(), $retval, $errMessage, $cmd ) );
1158 $pageRangesByDimensions = [];
1160 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1162 $firstPage = $pageList[0];
1163 $lastPage = $firstPage - 1;
1165 foreach ( $pageList as $page ) {
1166 if ( $page > $lastPage + 1 ) {
1167 if ( $firstPage !== $lastPage ) {
1168 $ranges[] =
"$firstPage-$lastPage";
1170 $ranges[] =
"$firstPage";
1179 if ( $firstPage != $lastPage ) {
1180 $ranges[] =
"$firstPage-$lastPage";
1182 $ranges[] =
"$firstPage";
1185 $pageRangesByDimensions[ $dimensions ] = $ranges;
1188 $dimensionsString = [];
1189 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1190 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1193 return implode(
'/', $dimensionsString );
1205 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
array $params
The job parameters.
Implements some public methods and some protected utility functions which are required by multiple ch...
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren't multipage do...
Interface for objects which can provide a MediaWiki context on request.