55 return MediaWikiServices::getInstance()
56 ->getMediaHandlerFactory()->getHandler(
$type );
190 $rc =
new ReflectionClass( $this );
191 $rm =
new ReflectionMethod( $this, $name );
192 return $rm->getDeclaringClass()->getName() === $rc->getName();
223 if ( $info ===
false ) {
226 if ( $info !==
null ) {
227 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
228 if ( !is_array( $info[
'metadata'] ) ) {
229 throw new InvalidArgumentException(
'Media handler ' .
230 static::class .
' returned ' . gettype( $info[
'metadata'] ) .
231 ' for metadata, should be array' );
244 if (
$blob ===
false && $size ===
false ) {
249 'width' => $size[0] ?? 0,
250 'height' => $size[1] ?? 0
252 if ( isset( $size[
'bits'] ) ) {
253 $info[
'bits'] = $size[
'bits'];
256 $info = [
'width' => 0,
'height' => 0 ];
258 if (
$blob !==
false ) {
261 if ( $metadata ===
false ) {
263 $metadata = [
'_error' =>
$blob ];
264 } elseif ( !is_array( $metadata ) ) {
267 $info[
'metadata'] = $metadata;
269 $info[
'metadata'] = [];
293 Hooks::runner()->onGetMetadataVersion( $version );
295 return implode(
';', $version );
445 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
446 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
463 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
476 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
477 if ( !
$ext || $magic->isMatchingExtension(
$ext,
$mime ) ===
false ) {
480 $knownExt = $magic->getExtensionFromMimeTypeOrNull(
$mime );
481 if ( $knownExt !==
null ) {
482 return [ $knownExt,
$mime ];
630 $numPages =
$file->pageCount();
636 for ( $i = 1; $i <= $numPages; $i++ ) {
638 if ( is_string( $curPage ) ) {
639 $document .= $curPage .
"\n";
642 if ( $document !==
'' ) {
701 foreach ( $metadataArray as $tag => $vals ) {
702 $v = $this->
formatTag( $tag, $vals, $context );
703 if ( $v ===
false ) {
709 unset( $metadataArray[$tag] );
712 $metadataArray[$tag] = [
'_formatted' => $v ];
713 if ( isset( $v[
'_type'] ) ) {
714 $metadataArray[$tag][
'_type'] = $v[
'_type'];
715 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
723 foreach ( $formatted as $name => $value ) {
724 $tag = strtolower( $name );
726 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
748 protected function formatTag(
string $key, $vals, $context =
false ) {
787 protected static function addMeta( &$array, $visibility,
$type, $id, $value, $param =
false ) {
789 if ( $msg->exists() ) {
790 $name = $msg->text();
797 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
800 $array[$visibility][] = [
840 return htmlspecialchars(
$wgLang->formatSize(
$file->getSize() ) );
851 ->params(
'<span class="mime-type">' .
$file->getMimeType() .
'</span>' )->parse();
862 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
863 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
864 $roundedUp = ceil( $idealWidth );
865 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
866 return (
int)floor( $idealWidth );
912 return Status::newGood();
926 if ( file_exists( $dstPath ) ) {
927 $thumbstat = stat( $dstPath );
928 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
929 $result = unlink( $dstPath );
933 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
934 $thumbstat[
'size'], $dstPath ) );
937 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
938 $thumbstat[
'size'], $dstPath ) );
1009 # Keep error output limited (T59985)
1010 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1013 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1014 wfHostname(), $retval, $errMessage, $cmd ) );
1152 $pageRangesByDimensions = [];
1154 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1156 $firstPage = $pageList[0];
1157 $lastPage = $firstPage - 1;
1159 foreach ( $pageList as $page ) {
1160 if ( $page > $lastPage + 1 ) {
1161 if ( $firstPage != $lastPage ) {
1162 $ranges[] =
"$firstPage-$lastPage";
1164 $ranges[] =
"$firstPage";
1173 if ( $firstPage != $lastPage ) {
1174 $ranges[] =
"$firstPage-$lastPage";
1176 $ranges[] =
"$firstPage";
1179 $pageRangesByDimensions[ $dimensions ] = $ranges;
1182 $dimensionsString = [];
1183 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1184 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1187 return implode(
'/', $dimensionsString );
1199 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