9use InvalidArgumentException;
42 private const MAX_ERR_LOG_SIZE = 65535;
52 ->getMediaHandlerFactory()->getHandler( $type );
189 $rc =
new ReflectionClass( $this );
190 $rm =
new ReflectionMethod( $this, $name );
191 return $rm->getDeclaringClass()->getName() === $rc->getName();
222 if ( $info ===
false ) {
225 if ( $info !==
null ) {
226 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
227 if ( !is_array( $info[
'metadata'] ) ) {
228 throw new InvalidArgumentException(
'Media handler ' .
229 static::class .
' returned ' . get_debug_type( $info[
'metadata'] ) .
230 ' for metadata, should be array' );
243 if ( $blob ===
false && $size ===
false ) {
248 'width' => $size[0] ?? 0,
249 'height' => $size[1] ?? 0
251 if ( isset( $size[
'bits'] ) ) {
252 $info[
'bits'] = $size[
'bits'];
255 $info = [
'width' => 0,
'height' => 0 ];
257 if ( $blob !==
false ) {
259 $metadata = @unserialize( $blob );
260 if ( $metadata ===
false ) {
262 $metadata = [
'_error' => $blob ];
263 } elseif ( !is_array( $metadata ) ) {
266 $info[
'metadata'] = $metadata;
268 $info[
'metadata'] = [];
294 return implode(
';', $version );
444 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
445 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
462 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
476 if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) ===
false ) {
479 $knownExt = $magic->getExtensionFromMimeTypeOrNull( $mime );
480 if ( $knownExt !==
null ) {
481 return [ $knownExt, $mime ];
487 return [ $ext, $mime ];
635 for ( $i = 1; $i <= $numPages; $i++ ) {
637 if ( is_string( $curPage ) ) {
638 $document .= $curPage .
"\n";
641 if ( $document !==
'' ) {
700 foreach ( $metadataArray as $tag => $vals ) {
701 $v = $this->
formatTag( $tag, $vals, $context );
702 if ( $v ===
false ) {
708 unset( $metadataArray[$tag] );
711 $metadataArray[$tag] = [
'_formatted' => $v ];
712 if ( isset( $v[
'_type'] ) ) {
713 $metadataArray[$tag][
'_type'] = $v[
'_type'];
714 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
722 foreach ( $formatted as $name => $value ) {
723 $tag = strtolower( $name );
725 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
747 protected function formatTag(
string $key, $vals, $context =
false ) {
786 protected static function addMeta( &$array, $visibility, $type, $id, $value, $param =
false ) {
787 $msg =
wfMessage(
"$type-$id", (
string)$param );
788 if ( $msg->exists() ) {
789 $name = $msg->text();
796 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
799 $array[$visibility][] = [
851 return htmlspecialchars(
$wgLang->formatSize( $file->getSize() ), ENT_QUOTES );
862 ->sizeParams( $file->getSize() )
863 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )
875 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
876 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
877 $roundedUp = ceil( $idealWidth );
878 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
879 return (
int)floor( $idealWidth );
924 return Status::newGood();
938 if ( file_exists( $dstPath ) ) {
939 $thumbstat = stat( $dstPath );
940 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
941 $result = unlink( $dstPath );
945 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
946 $thumbstat[
'size'], $dstPath ) );
949 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
950 $thumbstat[
'size'], $dstPath ) );
1021 # Keep error output limited (T59985)
1022 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1025 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1026 wfHostname(), $retval, $errMessage, $cmd ) );
1165 $pageRangesByDimensions = [];
1167 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1169 $firstPage = $pageList[0];
1170 $lastPage = $firstPage - 1;
1172 foreach ( $pageList as $page ) {
1173 if ( $page > $lastPage + 1 ) {
1174 if ( $firstPage !== $lastPage ) {
1175 $ranges[] =
"$firstPage-$lastPage";
1177 $ranges[] =
"$firstPage";
1186 if ( $firstPage != $lastPage ) {
1187 $ranges[] =
"$firstPage-$lastPage";
1189 $ranges[] =
"$firstPage";
1192 $pageRangesByDimensions[ $dimensions ] = $ranges;
1195 $dimensionsString = [];
1196 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1197 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1200 return implode(
'/', $dimensionsString );
1212 return [
'X-Content-Dimensions' =>
'' ];
1229class_alias( MediaHandler::class,
'MediaHandler' );
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(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
Interface for objects which can provide a MediaWiki context on request.