47 private const MAX_ERR_LOG_SIZE = 65535;
56 return MediaWikiServices::getInstance()
57 ->getMediaHandlerFactory()->getHandler( $type );
194 $rc =
new ReflectionClass( $this );
195 $rm =
new ReflectionMethod( $this, $name );
196 return $rm->getDeclaringClass()->getName() === $rc->getName();
227 if ( $info ===
false ) {
230 if ( $info !==
null ) {
231 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
232 if ( !is_array( $info[
'metadata'] ) ) {
233 throw new InvalidArgumentException(
'Media handler ' .
234 static::class .
' returned ' . gettype( $info[
'metadata'] ) .
235 ' for metadata, should be array' );
248 if ( $blob ===
false && $size ===
false ) {
253 'width' => $size[0] ?? 0,
254 'height' => $size[1] ?? 0
256 if ( isset( $size[
'bits'] ) ) {
257 $info[
'bits'] = $size[
'bits'];
260 $info = [
'width' => 0,
'height' => 0 ];
262 if ( $blob !==
false ) {
264 $metadata = @unserialize( $blob );
265 if ( $metadata ===
false ) {
267 $metadata = [
'_error' => $blob ];
268 } elseif ( !is_array( $metadata ) ) {
271 $info[
'metadata'] = $metadata;
273 $info[
'metadata'] = [];
297 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onGetMetadataVersion( $version );
299 return implode(
';', $version );
348 return self::METADATA_GOOD;
377 return self::METADATA_GOOD;
450 return $this->
doTransform( $image, $dstPath, $dstUrl,
$params, self::TRANSFORM_LATER );
480 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
481 if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) ===
false ) {
484 $knownExt = $magic->getExtensionFromMimeTypeOrNull( $mime );
485 if ( $knownExt !==
null ) {
486 return [ $knownExt, $mime ];
492 return [ $ext, $mime ];
640 for ( $i = 1; $i <= $numPages; $i++ ) {
642 if ( is_string( $curPage ) ) {
643 $document .= $curPage .
"\n";
646 if ( $document !==
'' ) {
705 foreach ( $metadataArray as $tag => $vals ) {
706 $v = $this->
formatTag( $tag, $vals, $context );
707 if ( $v ===
false ) {
713 unset( $metadataArray[$tag] );
716 $metadataArray[$tag] = [
'_formatted' => $v ];
717 if ( isset( $v[
'_type'] ) ) {
718 $metadataArray[$tag][
'_type'] = $v[
'_type'];
719 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
727 foreach ( $formatted as $name => $value ) {
728 $tag = strtolower( $name );
729 self::addMeta( $result,
730 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
752 protected function formatTag(
string $key, $vals, $context =
false ) {
791 protected static function addMeta( &$array, $visibility, $type, $id, $value, $param =
false ) {
793 if ( $msg->exists() ) {
794 $name = $msg->text();
801 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
804 $array[$visibility][] = [
820 return self::getGeneralShortDesc( $file );
832 return self::getGeneralLongDesc( $file );
844 return htmlspecialchars(
$wgLang->formatSize( $file->getSize() ) );
854 return wfMessage(
'file-info' )->sizeParams( $file->getSize() )
855 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )->parse();
866 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
867 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
868 $roundedUp = ceil( $idealWidth );
869 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
870 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' =>
'' ];
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...