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 ) {
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 );
915 return Status::newGood();
929 if ( file_exists( $dstPath ) ) {
930 $thumbstat = stat( $dstPath );
931 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
932 $result = unlink( $dstPath );
936 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
937 $thumbstat[
'size'], $dstPath ) );
940 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
941 $thumbstat[
'size'], $dstPath ) );
1012 # Keep error output limited (T59985)
1013 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1016 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1017 wfHostname(), $retval, $errMessage, $cmd ) );
1156 $pageRangesByDimensions = [];
1158 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1160 $firstPage = $pageList[0];
1161 $lastPage = $firstPage - 1;
1163 foreach ( $pageList as $page ) {
1164 if ( $page > $lastPage + 1 ) {
1165 if ( $firstPage != $lastPage ) {
1166 $ranges[] =
"$firstPage-$lastPage";
1168 $ranges[] =
"$firstPage";
1177 if ( $firstPage != $lastPage ) {
1178 $ranges[] =
"$firstPage-$lastPage";
1180 $ranges[] =
"$firstPage";
1183 $pageRangesByDimensions[ $dimensions ] = $ranges;
1186 $dimensionsString = [];
1187 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1188 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1191 return implode(
'/', $dimensionsString );
1203 return [
'X-Content-Dimensions' =>
'' ];
unserialize( $serialized)
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