54 return MediaWikiServices::getInstance()
55 ->getMediaHandlerFactory()->getHandler(
$type );
189 $rc =
new ReflectionClass( $this );
190 $rm =
new ReflectionMethod( $this, $name );
191 return $rm->getDeclaringClass()->getName() === $rc->getName();
222 if ( $info ===
false ) {
225 if ( $info !==
null ) {
226 $info += [
'width' => 0,
'height' => 0,
'metadata' => [] ];
227 if ( !is_array( $info[
'metadata'] ) ) {
228 throw new InvalidArgumentException(
'Media handler ' .
229 static::class .
' returned ' . gettype( $info[
'metadata'] ) .
230 ' for metadata, should be array' );
243 if (
$blob ===
false && $size ===
false ) {
248 'width' => $size[0] ?? 0,
249 'height' => $size[1] ?? 0
251 if ( isset( $size[
'bits'] ) ) {
252 $info[
'bits'] = $size[
'bits'];
255 $info = [
'width' => 0,
'height' => 0 ];
257 if (
$blob !==
false ) {
260 if ( $metadata ===
false ) {
262 $metadata = [
'_error' =>
$blob ];
263 } elseif ( !is_array( $metadata ) ) {
266 $info[
'metadata'] = $metadata;
268 $info[
'metadata'] = [];
292 Hooks::runner()->onGetMetadataVersion( $version );
294 return implode(
';', $version );
444 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
445 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
462 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
475 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
476 if ( !
$ext || $magic->isMatchingExtension(
$ext,
$mime ) ===
false ) {
479 $knownExt = $magic->getExtensionFromMimeTypeOrNull(
$mime );
480 if ( $knownExt !==
null ) {
481 return [ $knownExt,
$mime ];
629 $numPages =
$file->pageCount();
635 for ( $i = 1; $i <= $numPages; $i++ ) {
637 if ( is_string( $curPage ) ) {
638 $document .= $curPage .
"\n";
641 if ( $document !==
'' ) {
700 foreach ( $metadataArray as $tag => $vals ) {
701 $v = $this->
formatTag( $tag, $vals, $context );
702 if ( $v ===
false ) {
708 unset( $metadataArray[$tag] );
711 $metadataArray[$tag] = [
'_formatted' => $v ];
712 if ( isset( $v[
'_type'] ) ) {
713 $metadataArray[$tag][
'_type'] = $v[
'_type'];
714 unset( $metadataArray[$tag][
'_formatted'][
'_type'] );
722 foreach ( $formatted as $name => $value ) {
723 $tag = strtolower( $name );
725 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
747 protected function formatTag(
string $key, $vals, $context =
false ) {
786 protected static function addMeta( &$array, $visibility,
$type, $id, $value, $param =
false ) {
788 if ( $msg->exists() ) {
789 $name = $msg->text();
796 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
799 $array[$visibility][] = [
839 return htmlspecialchars(
$wgLang->formatSize(
$file->getSize() ) );
850 ->params(
'<span class="mime-type">' .
$file->getMimeType() .
'</span>' )->parse();
861 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
862 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
863 $roundedUp = ceil( $idealWidth );
864 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
865 return floor( $idealWidth );
911 return Status::newGood();
925 if ( file_exists( $dstPath ) ) {
926 $thumbstat = stat( $dstPath );
927 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
928 $result = unlink( $dstPath );
932 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
933 $thumbstat[
'size'], $dstPath ) );
936 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
937 $thumbstat[
'size'], $dstPath ) );
1008 # Keep error output limited (T59985)
1009 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
1012 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
1013 wfHostname(), $retval, $errMessage, $cmd ) );
1151 $pageRangesByDimensions = [];
1153 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
1155 $firstPage = $pageList[0];
1156 $lastPage = $firstPage - 1;
1158 foreach ( $pageList as $page ) {
1159 if ( $page > $lastPage + 1 ) {
1160 if ( $firstPage != $lastPage ) {
1161 $ranges[] =
"$firstPage-$lastPage";
1163 $ranges[] =
"$firstPage";
1172 if ( $firstPage != $lastPage ) {
1173 $ranges[] =
"$firstPage-$lastPage";
1175 $ranges[] =
"$firstPage";
1178 $pageRangesByDimensions[ $dimensions ] = $ranges;
1181 $dimensionsString = [];
1182 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
1183 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1186 return implode(
'/', $dimensionsString );
1198 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,...
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