Reedy has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393504 )
Change subject: Replace MimeMagic::singleton() calls ...................................................................... Replace MimeMagic::singleton() calls Change-Id: Ieed41b5d6b0f568fe2872e7754f2feae7868fe7a --- M includes/Feed.php M includes/StreamFile.php M includes/api/ApiFormatBase.php M includes/filebackend/FileBackendGroup.php M includes/filerepo/FileRepo.php M includes/filerepo/RepoGroup.php M includes/filerepo/file/File.php M includes/filerepo/file/ForeignAPIFile.php M includes/filerepo/file/LocalFile.php M includes/filerepo/file/UnregisteredLocalFile.php M includes/media/DjVu.php M includes/media/MediaHandler.php M includes/specials/SpecialMediaStatistics.php M includes/upload/UploadBase.php M includes/upload/UploadStash.php M includes/utils/MWFileProps.php M maintenance/importImages.php M tests/phpunit/includes/media/WebPTest.php 18 files changed, 27 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/04/393504/1 diff --git a/includes/Feed.php b/includes/Feed.php index fd223e6..55913c6 100644 --- a/includes/Feed.php +++ b/includes/Feed.php @@ -232,7 +232,7 @@ header( "Content-type: $mimetype; charset=UTF-8" ); // Set a sane filename - $exts = MimeMagic::singleton()->getExtensionsForType( $mimetype ); + $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer()->getExtensionsForType( $mimetype ); $ext = $exts ? strtok( $exts, ' ' ) : 'xml'; header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" ); diff --git a/includes/StreamFile.php b/includes/StreamFile.php index 71113a8..2ad42e5 100644 --- a/includes/StreamFile.php +++ b/includes/StreamFile.php @@ -113,7 +113,7 @@ return 'unknown/unknown'; } - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); // Use the extension only, rather than magic numbers, to avoid opening // up vulnerabilities due to uploads of files with allowed extensions // but disallowed types. diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index c5f2fcf..4348fc8 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -78,7 +78,8 @@ } elseif ( $this->getIsHtml() ) { return 'api-result.html'; } else { - $exts = MimeMagic::singleton()->getExtensionsForType( $this->getMimeType() ); + $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() + ->getExtensionsForType( $this->getMimeType() ); $ext = $exts ? strtok( $exts, ' ' ) : strtolower( $this->mFormat ); return "api-result.$ext"; } diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index 5d0da6d..0b61979 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -229,7 +229,7 @@ * @since 1.27 */ public function guessMimeInternal( $storagePath, $content, $fsPath ) { - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); // Trust the extension of the storage path (caller must validate) $ext = FileBackend::extensionFromPath( $storagePath ); $type = $magic->guessTypesForExtension( $ext ); diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 5005280..5d22b8d 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -1543,7 +1543,7 @@ */ public function getFileProps( $virtualUrl ) { $fsFile = $this->getLocalReference( $virtualUrl ); - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); if ( $fsFile ) { $props = $mwProps->getPropsFromPath( $fsFile->getPath(), true ); } else { diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 2edd6d0..5e37d67 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -452,7 +452,7 @@ return $repo->getFileProps( $fileName ); } else { - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); return $mwProps->getPropsFromPath( $fileName, true ); } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 827f4ca..4e79de2 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -250,7 +250,7 @@ $oldMime = $old->getMimeType(); $n = strrpos( $new, '.' ); $newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' ); - $mimeMagic = MimeMagic::singleton(); + $mimeMagic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); return $mimeMagic->isMatchingExtension( $newExt, $oldMime ); } diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index 43b6855..16c154f 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -286,7 +286,7 @@ */ function getMimeType() { if ( !isset( $this->mInfo['mime'] ) ) { - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $this->mInfo['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); } @@ -300,7 +300,7 @@ if ( isset( $this->mInfo['mediatype'] ) ) { return $this->mInfo['mediatype']; } - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); return $magic->getMediaType( null, $this->getMimeType() ); } diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index bb12515..4248f95 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1284,7 +1284,7 @@ ) { $props = $this->repo->getFileProps( $srcPath ); } else { - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); $props = $mwProps->getPropsFromPath( $srcPath, true ); } } diff --git a/includes/filerepo/file/UnregisteredLocalFile.php b/includes/filerepo/file/UnregisteredLocalFile.php index cdad5fc..fde68bb 100644 --- a/includes/filerepo/file/UnregisteredLocalFile.php +++ b/includes/filerepo/file/UnregisteredLocalFile.php @@ -151,7 +151,7 @@ */ function getMimeType() { if ( !isset( $this->mime ) ) { - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $this->mime = $magic->guessMimeType( $this->getLocalRefPath() ); } diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index aae66d3..eb7b6ba 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -357,7 +357,7 @@ global $wgDjvuOutputExtension; static $mime; if ( !isset( $mime ) ) { - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $mime = $magic->guessTypesForExtension( $wgDjvuOutputExtension ); } diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index 481e880..8551a12 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -288,7 +288,7 @@ * @return array Thumbnail extension and MIME type */ function getThumbType( $ext, $mime, $params = null ) { - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) === false ) { // The extension is not valid for this MIME type and we do // recognize the MIME type diff --git a/includes/specials/SpecialMediaStatistics.php b/includes/specials/SpecialMediaStatistics.php index a6d4a3e..31f41b5 100644 --- a/includes/specials/SpecialMediaStatistics.php +++ b/includes/specials/SpecialMediaStatistics.php @@ -237,7 +237,7 @@ * @return string Comma separated list of allowed extensions (e.g. ".ogg, .oga") */ private function getExtensionList( $mime ) { - $exts = MimeMagic::singleton()->getExtensionsForType( $mime ); + $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer()->getExtensionsForType( $mime ); if ( $exts === null ) { return ''; } diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index da3f9f8..c335e2b 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -420,7 +420,7 @@ $chunk = fread( $fp, 256 ); fclose( $fp ); - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $extMime = $magic->guessTypesForExtension( $this->mFinalExtension ); $ieTypes = $magic->getIEMimeTypes( $this->mTempPath, $chunk, $extMime ); foreach ( $ieTypes as $ieType ) { @@ -446,7 +446,7 @@ return $status; } - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); $this->mFileProps = $mwProps->getPropsFromPath( $this->mTempPath, $this->mFinalExtension ); $mime = $this->mFileProps['mime']; @@ -505,7 +505,7 @@ # getTitle() sets some internal parameters like $this->mFinalExtension $this->getTitle(); - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); $this->mFileProps = $mwProps->getPropsFromPath( $this->mTempPath, $this->mFinalExtension ); # check MIME type, if desired @@ -950,7 +950,7 @@ $this->mFinalExtension = ''; # No extension, try guessing one - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $mime = $magic->guessMimeType( $this->mTempPath ); if ( $mime !== 'unknown/unknown' ) { # Get a space separated list of extensions @@ -1207,7 +1207,7 @@ * @return bool */ public static function verifyExtension( $mime, $extension ) { - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); if ( !$mime || $mime == 'unknown' || $mime == 'unknown/unknown' ) { if ( !$magic->isRecognizableExtension( $extension ) ) { diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index c2ab899..ce087bf 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -218,7 +218,7 @@ ); } - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); $fileProps = $mwProps->getPropsFromPath( $path, true ); wfDebug( __METHOD__ . " stashing file at '$path'\n" ); @@ -490,9 +490,9 @@ $extension = $n ? substr( $path, $n + 1 ) : ''; } else { // If not, assume that it should be related to the MIME type of the original file. - $magic = MimeMagic::singleton(); + $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $mimeType = $magic->guessMimeType( $path ); - $extensions = explode( ' ', MimeMagic::singleton()->getExtensionsForType( $mimeType ) ); + $extensions = explode( ' ', $magic->getExtensionsForType( $mimeType ) ); if ( count( $extensions ) ) { $extension = $extensions[0]; } diff --git a/includes/utils/MWFileProps.php b/includes/utils/MWFileProps.php index e60b9ab..9d05c6a 100644 --- a/includes/utils/MWFileProps.php +++ b/includes/utils/MWFileProps.php @@ -30,9 +30,9 @@ private $magic; /** - * @param MimeMagic $magic + * @param MimeAnalyzer $magic */ - public function __construct( MimeMagic $magic ) { + public function __construct( MimeAnalyzer $magic ) { $this->magic = $magic; } diff --git a/maintenance/importImages.php b/maintenance/importImages.php index 526561c..d3aa280 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -299,7 +299,7 @@ " publishing {$file} by '{$wgUser->getName()}', comment '$commentText'... " ); } else { - $mwProps = new MWFileProps( MimeMagic::singleton() ); + $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() ); $props = $mwProps->getPropsFromPath( $file, true ); $flags = 0; $publishOptions = []; diff --git a/tests/phpunit/includes/media/WebPTest.php b/tests/phpunit/includes/media/WebPTest.php index f51693d..b8dadaf 100644 --- a/tests/phpunit/includes/media/WebPTest.php +++ b/tests/phpunit/includes/media/WebPTest.php @@ -123,7 +123,7 @@ * @dataProvider provideTestGetMimeType */ public function testGuessMimeType( $path ) { - $mime = MimeMagic::singleton(); + $mime = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $this->assertEquals( 'image/webp', $mime->guessMimeType( $path, false ) ); } public function provideTestGetMimeType() { -- To view, visit https://gerrit.wikimedia.org/r/393504 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ieed41b5d6b0f568fe2872e7754f2feae7868fe7a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits