48 private const MAX_ERR_LOG_SIZE = 65535;
57 return MediaWikiServices::getInstance()
58 ->getMediaHandlerFactory()->getHandler( $type );
195 $rc =
new ReflectionClass( $this );
196 $rm =
new ReflectionMethod( $this, $name );
197 return $rm->getDeclaringClass()->getName() === $rc->getName();
228 if ( $info ===
false ) {
231 if ( $info !==
null ) {
232 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
233 if ( !is_array( $info[
'metadata'] ) ) {
234 throw new InvalidArgumentException(
'Media handler ' .
235 static::class .
' returned ' . gettype( $info[
'metadata'] ) .
236 ' for metadata, should be array' );
249 if ( $blob ===
false && $size ===
false ) {
254 'width' => $size[0] ?? 0,
255 'height' => $size[1] ?? 0
257 if ( isset( $size[
'bits'] ) ) {
258 $info[
'bits'] = $size[
'bits'];
261 $info = [
'width' => 0,
'height' => 0 ];
263 if ( $blob !==
false ) {
265 $metadata = @unserialize( $blob );
266 if ( $metadata ===
false ) {
268 $metadata = [
'_error' => $blob ];
269 } elseif ( !is_array( $metadata ) ) {
272 $info[
'metadata'] = $metadata;
274 $info[
'metadata'] = [];
298 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onGetMetadataVersion( $version );
300 return implode(
';', $version );
450 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
451 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
468 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
481 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
482 if ( !
$ext || $magic->isMatchingExtension(
$ext,
$mime ) ===
false ) {
485 $knownExt = $magic->getExtensionFromMimeTypeOrNull(
$mime );
486 if ( $knownExt !==
null ) {
487 return [ $knownExt,
$mime ];
635 $numPages =
$file->pageCount();
641 for ( $i = 1; $i <= $numPages; $i++ ) {
643 if ( is_string( $curPage ) ) {
644 $document .= $curPage .
"\n";
647 if ( $document !==
'' ) {
706 foreach ( $metadataArray as $tag => $vals ) {
707 $v = $this->
formatTag( $tag, $vals, $context );
708 if ( $v ===
false ) {
714 unset( $metadataArray[$tag] );
717 $metadataArray[$tag] = [
'_formatted' => $v ];
718 if ( isset( $v[
'_type'] ) ) {
719 $metadataArray[$tag][
'_type'] = $v[
'_type'];
720 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
728 foreach ( $formatted as $name => $value ) {
729 $tag = strtolower( $name );
731 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
753 protected function formatTag(
string $key, $vals, $context =
false ) {
792 protected static function addMeta( &$array, $visibility, $type, $id, $value, $param =
false ) {
794 if ( $msg->exists() ) {
795 $name = $msg->text();
802 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
805 $array[$visibility][] = [
845 return htmlspecialchars(
$wgLang->formatSize(
$file->getSize() ) );
856 ->params(
'<span class="mime-type">' .
$file->getMimeType() .
'</span>' )->parse();
867 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
868 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
869 $roundedUp = ceil( $idealWidth );
870 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
871 return (
int)floor( $idealWidth );
916 return Status::newGood();
930 if ( file_exists( $dstPath ) ) {
931 $thumbstat = stat( $dstPath );
932 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
933 $result = unlink( $dstPath );
937 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
938 $thumbstat[
'size'], $dstPath ) );
941 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
942 $thumbstat[
'size'], $dstPath ) );
1013 # Keep error output limited (T59985)
1014 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1017 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1018 wfHostname(), $retval, $errMessage, $cmd ) );
1157 $pageRangesByDimensions = [];
1159 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1161 $firstPage = $pageList[0];
1162 $lastPage = $firstPage - 1;
1164 foreach ( $pageList as $page ) {
1165 if ( $page > $lastPage + 1 ) {
1166 if ( $firstPage !== $lastPage ) {
1167 $ranges[] =
"$firstPage-$lastPage";
1169 $ranges[] =
"$firstPage";
1178 if ( $firstPage != $lastPage ) {
1179 $ranges[] =
"$firstPage-$lastPage";
1181 $ranges[] =
"$firstPage";
1184 $pageRangesByDimensions[ $dimensions ] = $ranges;
1187 $dimensionsString = [];
1188 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1189 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1192 return implode(
'/', $dimensionsString );
1204 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.
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.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
Implements some public methods and some protected utility functions which are required by multiple ch...
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!is_readable( $file)) $ext