X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2Ffile%2FLocalFile.php;h=8514cc8d29bea96d1ecab2e0d43b0ae9c2ed25e2;hb=b8292cef0136b1fb5da9f7178d99eace9eefd93a;hp=c109fba9163d73f0ede689fb433ca54b083ce014;hpb=c6436de8f690b073c2b9315870e8c5e78a9515fb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index c109fba916..f71e1dc273 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -21,7 +21,8 @@ * @ingroup FileAbstraction */ -use \MediaWiki\Logger\LoggerFactory; +use MediaWiki\Logger\LoggerFactory; +use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; /** @@ -592,7 +593,7 @@ class LocalFile extends File { if ( $upgrade ) { $this->upgrading = true; // Defer updates unless in auto-commit CLI mode - DeferredUpdates::addCallableUpdate( function() { + DeferredUpdates::addCallableUpdate( function () { $this->upgrading = false; // avoid duplicate updates try { $this->upgradeRow(); @@ -715,6 +716,11 @@ class LocalFile extends File { * @return int */ public function getWidth( $page = 1 ) { + $page = (int)$page; + if ( $page < 1 ) { + $page = 1; + } + $this->load(); if ( $this->isMultipage() ) { @@ -742,6 +748,11 @@ class LocalFile extends File { * @return int */ public function getHeight( $page = 1 ) { + $page = (int)$page; + if ( $page < 1 ) { + $page = 1; + } + $this->load(); if ( $this->isMultipage() ) { @@ -1021,9 +1032,15 @@ class LocalFile extends File { $purgeList = []; foreach ( $files as $file ) { - # Check that the base file name is part of the thumb name + if ( $this->repo->supportsSha1URLs() ) { + $reference = $this->getSha1(); + } else { + $reference = $this->getName(); + } + + # Check that the reference (filename or sha1) is part of the thumb name # This is a basic sanity check to avoid erasing unrelated directories - if ( strpos( $file, $this->getName() ) !== false + if ( strpos( $file, $reference ) !== false || strpos( $file, "-thumbnail" ) !== false // "short" thumb name ) { $purgeList[] = "{$dir}/{$file}"; @@ -1199,7 +1216,13 @@ class LocalFile extends File { $options = []; $handler = MediaHandler::getHandler( $props['mime'] ); if ( $handler ) { - $options['headers'] = $handler->getStreamHeaders( $props['metadata'] ); + $metadata = MediaWiki\quietCall( 'unserialize', $props['metadata'] ); + + if ( !is_array( $metadata ) ) { + $metadata = []; + } + + $options['headers'] = $handler->getContentHeaders( $metadata ); } else { $options['headers'] = []; }