47 return MediaWikiServices::getInstance()
48 ->getMediaHandlerFactory()->getHandler(
$type );
143 Hooks::run(
'GetMetadataVersion', [ &$version ] );
145 return implode(
';', $version );
159 if ( !is_array( $metadata ) ) {
161 Wikimedia\suppressWarnings();
163 Wikimedia\restoreWarnings();
265 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
280 abstract function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
291 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
292 if ( !
$ext || $magic->isMatchingExtension(
$ext, $mime ) ===
false ) {
295 $extensions = $magic->getExtensionsForType( $mime );
297 return [ strtok( $extensions,
' ' ), $mime ];
303 return [
$ext, $mime ];
434 $numPages =
$file->pageCount();
440 for ( $i = 1; $i <= $numPages; $i++ ) {
442 if ( is_string( $curPage ) ) {
443 $document .= $curPage .
"\n";
446 if ( $document !==
'' ) {
503 foreach ( $formatted as $name => $value ) {
504 $tag = strtolower( $name );
506 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
549 protected static function addMeta( &$array, $visibility,
$type, $id, $value, $param =
false ) {
551 if ( $msg->exists() ) {
552 $name = $msg->text();
559 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id .
"\n" );
562 $array[$visibility][] = [
598 return htmlspecialchars(
$wgLang->formatSize(
$file->getSize() ) );
609 ->params(
'<span class="mime-type">' .
$file->getMimeType() .
'</span>' )->parse();
620 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
621 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
622 $roundedUp = ceil( $idealWidth );
623 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
624 return floor( $idealWidth );
664 return Status::newGood();
676 if ( file_exists( $dstPath ) ) {
677 $thumbstat = stat( $dstPath );
678 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
679 $result = unlink( $dstPath );
683 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
684 $thumbstat[
'size'], $dstPath ) );
687 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
688 $thumbstat[
'size'], $dstPath ) );
754 # Keep error output limited (T59985)
755 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
758 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
882 $pageRangesByDimensions = [];
884 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
886 $firstPage = $pageList[0];
887 $lastPage = $firstPage - 1;
889 foreach ( $pageList as $page ) {
890 if ( $page > $lastPage + 1 ) {
891 if ( $firstPage != $lastPage ) {
892 $ranges[] =
"$firstPage-$lastPage";
894 $ranges[] =
"$firstPage";
903 if ( $firstPage != $lastPage ) {
904 $ranges[] =
"$firstPage-$lastPage";
906 $ranges[] =
"$firstPage";
909 $pageRangesByDimensions[ $dimensions ] = $ranges;
912 $dimensionsString = [];
913 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
914 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
917 return implode(
'/', $dimensionsString );
927 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...
getLocalRefPath()
Get an FS copy or original of this file and return the path.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!is_readable( $file)) $ext