54 return MediaWikiServices::getInstance()
55 ->getMediaHandlerFactory()->getHandler(
$type );
153 Hooks::runner()->onGetMetadataVersion( $version );
155 return implode(
';', $version );
170 if ( !is_array( $metadata ) ) {
172 Wikimedia\suppressWarnings();
174 Wikimedia\restoreWarnings();
285 final public function getTransform( $image, $dstPath, $dstUrl, $params ) {
286 return $this->
doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
303 abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
316 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
317 if ( !
$ext || $magic->isMatchingExtension(
$ext,
$mime ) ===
false ) {
320 $knownExt = $magic->getExtensionFromMimeTypeOrNull(
$mime );
321 if ( $knownExt !==
null ) {
322 return [ $knownExt,
$mime ];
479 $numPages =
$file->pageCount();
485 for ( $i = 1; $i <= $numPages; $i++ ) {
487 if ( is_string( $curPage ) ) {
488 $document .= $curPage .
"\n";
491 if ( $document !==
'' ) {
552 foreach ( $formatted as $name => $value ) {
553 $tag = strtolower( $name );
555 in_array( $tag, $visibleFields ) ?
'visible' :
'collapsed',
600 protected static function addMeta( &$array, $visibility,
$type, $id, $value, $param =
false ) {
602 if ( $msg->exists() ) {
603 $name = $msg->text();
610 wfDebug( __METHOD__ .
' Unknown metadata name: ' . $id );
613 $array[$visibility][] = [
653 return htmlspecialchars(
$wgLang->formatSize(
$file->getSize() ) );
664 ->params(
'<span class="mime-type">' .
$file->getMimeType() .
'</span>' )->parse();
675 public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
676 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
677 $roundedUp = ceil( $idealWidth );
678 if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
679 return floor( $idealWidth );
725 return Status::newGood();
739 if ( file_exists( $dstPath ) ) {
740 $thumbstat = stat( $dstPath );
741 if ( $thumbstat[
'size'] == 0 || $retval != 0 ) {
742 $result = unlink( $dstPath );
746 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() succeeded',
747 $thumbstat[
'size'], $dstPath ) );
750 sprintf(
'Removing bad %d-byte thumbnail "%s". unlink() failed',
751 $thumbstat[
'size'], $dstPath ) );
822 # Keep error output limited (T59985)
823 $errMessage = trim( substr( $err, 0, self::MAX_ERR_LOG_SIZE ) );
826 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
965 $pageRangesByDimensions = [];
967 foreach ( $pagesByDimensions as $dimensions => $pageList ) {
969 $firstPage = $pageList[0];
970 $lastPage = $firstPage - 1;
972 foreach ( $pageList as $page ) {
973 if ( $page > $lastPage + 1 ) {
974 if ( $firstPage != $lastPage ) {
975 $ranges[] =
"$firstPage-$lastPage";
977 $ranges[] =
"$firstPage";
986 if ( $firstPage != $lastPage ) {
987 $ranges[] =
"$firstPage-$lastPage";
989 $ranges[] =
"$firstPage";
992 $pageRangesByDimensions[ $dimensions ] = $ranges;
995 $dimensionsString = [];
996 foreach ( $pageRangesByDimensions as $dimensions => $pageRanges ) {
997 $dimensionsString[] =
"$dimensions:" . implode(
',', $pageRanges );
1000 return implode(
'/', $dimensionsString );
1012 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