46 private const MAX_ERR_LOG_SIZE = 65535;
55 return MediaWikiServices::getInstance()
56 ->getMediaHandlerFactory()->getHandler(
$type );
193 $rc =
new ReflectionClass( $this );
194 $rm =
new ReflectionMethod( $this, $name );
195 return $rm->getDeclaringClass()->getName() === $rc->getName();
226 if ( $info ===
false ) {
229 if ( $info !==
null ) {
230 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
231 if ( !is_array( $info[
'metadata'] ) ) {
232 throw new InvalidArgumentException(
'Media handler ' .
233 static::class .
' returned ' . gettype( $info[
'metadata'] ) .
234 ' for metadata, should be array' );
247 if (
$blob ===
false && $size ===
false ) {
252 'width' => $size[0] ?? 0,
253 'height' => $size[1] ?? 0
255 if ( isset( $size[
'bits'] ) ) {
256 $info[
'bits'] = $size[
'bits'];
259 $info = [
'width' => 0,
'height' => 0 ];
261 if (
$blob !==
false ) {
263 $metadata = @unserialize(
$blob );
264 if ( $metadata ===
false ) {
266 $metadata = [
'_error' =>
$blob ];
267 } elseif ( !is_array( $metadata ) ) {
270 $info[
'metadata'] = $metadata;
272 $info[
'metadata'] = [];
296 Hooks::runner()->onGetMetadataVersion( $version );
298 return implode(
';', $version );
448 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
449 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
466 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
479 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
480 if ( !
$ext || $magic->isMatchingExtension(
$ext,
$mime ) ===
false ) {
483 $knownExt = $magic->getExtensionFromMimeTypeOrNull(
$mime );
484 if ( $knownExt !==
null ) {
485 return [ $knownExt,
$mime ];
633 $numPages =
$file->pageCount();
639 for ( $i = 1; $i <= $numPages; $i++ ) {
641 if ( is_string( $curPage ) ) {
642 $document .= $curPage .
"\n";
645 if ( $document !==
'' ) {
704 foreach ( $metadataArray as $tag => $vals ) {
705 $v = $this->
formatTag( $tag, $vals, $context );
706 if ( $v ===
false ) {
712 unset( $metadataArray[$tag] );
715 $metadataArray[$tag] = [
'_formatted' => $v ];
716 if ( isset( $v[
'_type'] ) ) {
717 $metadataArray[$tag][
'_type'] = $v[
'_type'];
718 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
726 foreach ( $formatted as $name => $value ) {
727 $tag = strtolower( $name );
729 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
751 protected function formatTag(
string $key, $vals, $context =
false ) {
790 protected static function addMeta( &$array, $visibility,
$type, $id, $value, $param =
false ) {
792 if ( $msg->exists() ) {
793 $name = $msg->text();
800 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
803 $array[$visibility][] = [
843 return htmlspecialchars(
$wgLang->formatSize(
$file->getSize() ) );
854 ->params(
'<span class="mime-type">' .
$file->getMimeType() .
'</span>' )->parse();
865 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
866 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
867 $roundedUp = ceil( $idealWidth );
868 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
869 return (
int)floor( $idealWidth );
914 return Status::newGood();
928 if ( file_exists( $dstPath ) ) {
929 $thumbstat = stat( $dstPath );
930 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
931 $result = unlink( $dstPath );
935 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
936 $thumbstat[
'size'], $dstPath ) );
939 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
940 $thumbstat[
'size'], $dstPath ) );
1011 # Keep error output limited (T59985)
1012 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1015 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1016 wfHostname(), $retval, $errMessage, $cmd ) );
1155 $pageRangesByDimensions = [];
1157 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1159 $firstPage = $pageList[0];
1160 $lastPage = $firstPage - 1;
1162 foreach ( $pageList as $page ) {
1163 if ( $page > $lastPage + 1 ) {
1164 if ( $firstPage !== $lastPage ) {
1165 $ranges[] =
"$firstPage-$lastPage";
1167 $ranges[] =
"$firstPage";
1176 if ( $firstPage != $lastPage ) {
1177 $ranges[] =
"$firstPage-$lastPage";
1179 $ranges[] =
"$firstPage";
1182 $pageRangesByDimensions[ $dimensions ] = $ranges;
1185 $dimensionsString = [];
1186 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1187 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1190 return implode(
'/', $dimensionsString );
1202 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