From: Derick Alangi Date: Tue, 14 May 2019 17:00:34 +0000 (+0100) Subject: Replace some uses of deprecated wfFindFile() and wfLocalFile() X-Git-Tag: 1.34.0-rc.0~1457^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=21e2d71560cb87191dd80ae0750d0190b45063c1;p=lhc%2Fweb%2Fwiklou.git Replace some uses of deprecated wfFindFile() and wfLocalFile() These global functions were deprecated in 1.34 and services made available to replace them. See services below; * wfFindFile() - MediaWikiServices::getInstance()->getRepoGroup()->findFile() * wfLocalFind() - MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile() NOTES: * wfFindFile() and wfLocalFind() usages in tests have been ignored in this change per @Timo's comments about state of objects. * includes/upload/UploadBase.php also maintained for now as it causes some failures I don't fully understand, will investigate and handle it in a follow up patch. * Also, includes/MovePage.php Change-Id: I9437494de003f40fbe591321da7b42d16bb732d6 --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 0bcc893ba9..2eeede96da 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2591,7 +2591,7 @@ ERROR; } } elseif ( $namespace == NS_FILE ) { # Show a hint to shared repo - $file = wfFindFile( $this->mTitle ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $this->mTitle ); if ( $file && !$file->isLocal() ) { $descUrl = $file->getDescriptionUrl(); # there must be a description url to show a hint to shared repo diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 7256eab2fb..759732f8a2 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2984,7 +2984,7 @@ function wfUnpack( $format, $data, $length = false ) { function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { # Handle redirects; callers almost always hit wfFindFile() anyway, # so just use that method because it has a fast process cache. - $file = wfFindFile( $name ); // get the final name + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name ); // get the final name $name = $file ? $file->getTitle()->getDBkey() : $name; # Run the extension hook diff --git a/includes/Linker.php b/includes/Linker.php index ae50c66ff2..39f43946d2 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -555,7 +555,8 @@ class Linker { # Use manually specified thumbnail $manual_title = Title::makeTitleSafe( NS_FILE, $frameParams['manualthumb'] ); if ( $manual_title ) { - $manual_img = wfFindFile( $manual_title ); + $manual_img = MediaWikiServices::getInstance()->getRepoGroup() + ->findFile( $manual_title ); if ( $manual_img ) { $thumb = $manual_img->getUnscaledThumb( $handlerParams ); $manualthumb = true; @@ -693,7 +694,8 @@ class Linker { $label = $title->getPrefixedText(); } $encLabel = htmlspecialchars( $label ); - $currentExists = $time ? ( wfFindFile( $title ) != false ) : false; + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); + $currentExists = $time ? ( $file != false ) : false; if ( ( $wgUploadMissingFileUrl || $wgUploadNavigationUrl || $wgEnableUploads ) && !$currentExists @@ -756,11 +758,13 @@ class Linker { * @since 1.16.3 * @param LinkTarget $title * @param string $html Pre-sanitized HTML - * @param string $time MW timestamp of file creation time + * @param string|false $time MW timestamp of file creation time * @return string HTML */ public static function makeMediaLinkObj( $title, $html = '', $time = false ) { - $img = wfFindFile( $title, [ 'time' => $time ] ); + $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile( + $title, [ 'time' => $time ] + ); return self::makeMediaLinkFile( $title, $img, $html ); } diff --git a/includes/Title.php b/includes/Title.php index dee6c52596..b7b28afaf7 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3584,7 +3584,8 @@ class Title implements LinkTarget, IDBAccessObject { # Is it an existing file? if ( $nt->getNamespace() == NS_FILE ) { - $file = wfLocalFile( $nt ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $nt ); $file->load( File::READ_LATEST ); if ( $file->exists() ) { wfDebug( __METHOD__ . ": file exists\n" ); @@ -4056,15 +4057,15 @@ class Title implements LinkTarget, IDBAccessObject { return true; // any interwiki link might be viewable, for all we know } + $services = MediaWikiServices::getInstance(); switch ( $this->mNamespace ) { case NS_MEDIA: case NS_FILE: // file exists, possibly in a foreign repo - return (bool)wfFindFile( $this ); + return (bool)$services->getRepoGroup()->findFile( $this ); case NS_SPECIAL: // valid special page - return MediaWikiServices::getInstance()->getSpecialPageFactory()-> - exists( $this->mDbkeyform ); + return $services->getSpecialPageFactory()->exists( $this->mDbkeyform ); case NS_MAIN: // selflink, possibly with fragment return $this->mDbkeyform == ''; diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index ab95b97c47..e91863a656 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -450,7 +450,7 @@ class InfoAction extends FormlessAction { // Display image SHA-1 value if ( $title->inNamespace( NS_FILE ) ) { - $fileObj = wfFindFile( $title ); + $fileObj = $services->getRepoGroup()->findFile( $title ); if ( $fileObj !== false ) { // Convert the base-36 sha1 value obtained from database to base-16 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 ); diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php index 704513822f..668bd0e427 100644 --- a/includes/api/ApiImageRotate.php +++ b/includes/api/ApiImageRotate.php @@ -1,4 +1,7 @@ true ] ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( + $title, [ 'latest' => true ] + ); if ( !$file ) { $r['result'] = 'Failure'; $r['errors'] = $this->getErrorFormatter()->arrayFromStatus( diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 89ecc43bd9..540860b3a9 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * API Module to move pages * @ingroup API @@ -59,7 +61,7 @@ class ApiMove extends ApiBase { if ( $toTitle->getNamespace() == NS_FILE && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle ) - && wfFindFile( $toTitle ) + && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $toTitle ) ) { if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) { $this->dieWithError( 'apierror-fileexists-sharedrepo-perm' ); diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 051e12796f..e123a2ac46 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -110,7 +110,8 @@ class ApiQueryImageInfo extends ApiQueryBase { if ( !isset( $images[$title] ) ) { if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) { // uploadwarning and badfile need info about non-existing files - $images[$title] = wfLocalFile( $title ); + $images[$title] = MediaWikiServices::getInstance()->getRepoGroup() + ->getLocalRepo()->newFile( $title ); // Doesn't exist, so set an empty image repository $info['imagerepository'] = ''; } else { diff --git a/includes/content/FileContentHandler.php b/includes/content/FileContentHandler.php index 3028dfdac8..6a1cc62595 100644 --- a/includes/content/FileContentHandler.php +++ b/includes/content/FileContentHandler.php @@ -1,5 +1,7 @@ getNamespace() ) { return []; } - $file = wfLocalFile( $title ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $title ); if ( !$file || !$file->exists() ) { return []; } diff --git a/includes/deferred/WANCacheReapUpdate.php b/includes/deferred/WANCacheReapUpdate.php index a218f76114..b193d5f4e4 100644 --- a/includes/deferred/WANCacheReapUpdate.php +++ b/includes/deferred/WANCacheReapUpdate.php @@ -114,7 +114,8 @@ class WANCacheReapUpdate implements DeferrableUpdate { } if ( $t->inNamespace( NS_FILE ) ) { - $entities[] = wfLocalFile( $t->getText() ); + $entities[] = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $t->getText() ); } if ( $t->inNamespace( NS_USER ) ) { $entities[] = User::newFromName( $t->getText(), false ); diff --git a/includes/export/XmlDumpWriter.php b/includes/export/XmlDumpWriter.php index d3fd374a37..0659ec18cb 100644 --- a/includes/export/XmlDumpWriter.php +++ b/includes/export/XmlDumpWriter.php @@ -462,7 +462,8 @@ class XmlDumpWriter { */ function writeUploads( $row, $dumpContents = false ) { if ( $row->page_namespace == NS_FILE ) { - $img = wfLocalFile( $row->page_title ); + $img = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $row->page_title ); if ( $img && $img->exists() ) { $out = ''; foreach ( array_reverse( $img->getHistory() ) as $ver ) { diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 124afef681..ee7ee6f90d 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -45,8 +45,16 @@ use MediaWiki\MediaWikiServices; * * RepoGroup::singleton()->getLocalRepo()->newFile( $title ); * - * The convenience functions wfLocalFile() and wfFindFile() should be sufficient - * in most cases. + * Consider the services container below; + * + * $services = MediaWikiServices::getInstance(); + * + * The convenience services $services->getRepoGroup()->getLocalRepo()->newFile() + * and $services->getRepoGroup()->findFile() should be sufficient in most cases. + * + * @TODO: DI - Instead of using MediaWikiServices::getInstance(), a service should + * ideally accept a RepoGroup in its constructor and then, use $this->repoGroup->findFile() + * and $this->repoGroup->getLocalRepo()->newFile(). * * @ingroup FileAbstraction */ diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index dd8962d4ca..54bcea3979 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -39,8 +39,16 @@ use MediaWiki\MediaWikiServices; * * RepoGroup::singleton()->getLocalRepo()->newFile( $title ); * - * The convenience functions wfLocalFile() and wfFindFile() should be sufficient - * in most cases. + * Consider the services container below; + * + * $services = MediaWikiServices::getInstance(); + * + * The convenience services $services->getRepoGroup()->getLocalRepo()->newFile() + * and $services->getRepoGroup()->findFile() should be sufficient in most cases. + * + * @TODO: DI - Instead of using MediaWikiServices::getInstance(), a service should + * ideally accept a RepoGroup in its constructor and then, use $this->repoGroup->findFile() + * and $this->repoGroup->getLocalRepo()->newFile(). * * @ingroup FileAbstraction */ @@ -1898,6 +1906,7 @@ class LocalFile extends File { * @return Status */ function move( $target ) { + $localRepo = MediaWikiServices::getInstance()->getRepoGroup(); if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); } @@ -1914,8 +1923,8 @@ class LocalFile extends File { wfDebugLog( 'imagemove', "Finished moving {$this->name}" ); // Purge the source and target files... - $oldTitleFile = wfLocalFile( $this->title ); - $newTitleFile = wfLocalFile( $target ); + $oldTitleFile = $localRepo->findFile( $this->title ); + $newTitleFile = $localRepo->findFile( $target ); // To avoid slow purges in the transaction, move them outside... DeferredUpdates::addUpdate( new AutoCommitUpdate( diff --git a/includes/filerepo/file/LocalFileMoveBatch.php b/includes/filerepo/file/LocalFileMoveBatch.php index 55940049bc..21980b90eb 100644 --- a/includes/filerepo/file/LocalFileMoveBatch.php +++ b/includes/filerepo/file/LocalFileMoveBatch.php @@ -21,6 +21,7 @@ * @ingroup FileAbstraction */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IDatabase; /** @@ -125,7 +126,8 @@ class LocalFileMoveBatch { public function execute() { $repo = $this->file->repo; $status = $repo->newGood(); - $destFile = wfLocalFile( $this->target ); + $destFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $this->target ); $this->file->lock(); $destFile->lock(); // quickly fail if destination is not available diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 4d5222cd79..d25d9aa861 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -1,4 +1,7 @@ mParser->fetchFileAndTitle( $nt, $options ); } else { - $img = wfFindFile( $nt ); + $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt ); } } else { $img = false; diff --git a/includes/import/ImportableUploadRevisionImporter.php b/includes/import/ImportableUploadRevisionImporter.php index f1ac42c013..40c9417c11 100644 --- a/includes/import/ImportableUploadRevisionImporter.php +++ b/includes/import/ImportableUploadRevisionImporter.php @@ -62,7 +62,8 @@ class ImportableUploadRevisionImporter implements UploadRevisionImporter { $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(), RepoGroup::singleton()->getLocalRepo(), $archiveName ); } else { - $file = wfLocalFile( $importableRevision->getTitle() ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $importableRevision->getTitle() ); $file->load( File::READ_LATEST ); $this->logger->debug( __METHOD__ . 'Importing new file as ' . $file->getName() . "\n" ); if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) { diff --git a/includes/jobqueue/jobs/ThumbnailRenderJob.php b/includes/jobqueue/jobs/ThumbnailRenderJob.php index eb8b1a2780..85e3af9d2d 100644 --- a/includes/jobqueue/jobs/ThumbnailRenderJob.php +++ b/includes/jobqueue/jobs/ThumbnailRenderJob.php @@ -21,6 +21,8 @@ * @ingroup JobQueue */ +use MediaWiki\MediaWikiServices; + /** * Job for asynchronous rendering of thumbnails. * @@ -36,7 +38,8 @@ class ThumbnailRenderJob extends Job { $transformParams = $this->params['transformParams']; - $file = wfLocalFile( $this->title ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $this->title ); $file->load( File::READ_LATEST ); if ( $file && $file->exists() ) { diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index 86c59add09..e929ed8a73 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -75,9 +75,10 @@ class ImagePage extends Article { Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] ); if ( !$img ) { // not set by hook? - $img = wfFindFile( $this->getTitle() ); + $services = MediaWikiServices::getInstance(); + $img = $services->getRepoGroup()->findFile( $this->getTitle() ); if ( !$img ) { - $img = wfLocalFile( $this->getTitle() ); + $img = $services->getRepoGroup()->getLocalRepo()->newFile( $this->getTitle() ); } } $this->mPage->setFile( $img ); diff --git a/includes/page/PageArchive.php b/includes/page/PageArchive.php index a314f3a9ea..cdaf06268b 100644 --- a/includes/page/PageArchive.php +++ b/includes/page/PageArchive.php @@ -420,7 +420,9 @@ class PageArchive { $restoreFiles = $restoreAll || !empty( $fileVersions ); if ( $restoreFiles && $this->title->getNamespace() == NS_FILE ) { - $img = wfLocalFile( $this->title ); + /** @var LocalFile $img */ + $img = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $this->title ); $img->load( File::READ_LATEST ); $this->fileStatus = $img->restore( $fileVersions, $unsuppress ); if ( !$this->fileStatus->isOK() ) { diff --git a/includes/page/WikiFilePage.php b/includes/page/WikiFilePage.php index c457a34fe1..8df9ab242a 100644 --- a/includes/page/WikiFilePage.php +++ b/includes/page/WikiFilePage.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\FakeResultWrapper; /** @@ -55,14 +56,16 @@ class WikiFilePage extends WikiPage { * @return bool */ protected function loadFile() { + $services = MediaWikiServices::getInstance(); if ( $this->mFileLoaded ) { return true; } $this->mFileLoaded = true; - $this->mFile = wfFindFile( $this->mTitle ); + $this->mFile = $services->getRepoGroup()->findFile( $this->mTitle ); if ( !$this->mFile ) { - $this->mFile = wfLocalFile( $this->mTitle ); // always a File + $this->mFile = $services->getRepoGroup()->getLocalRepo() + ->newFile( $this->mTitle ); // always a File } $this->mRepo = $this->mFile->getRepo(); return true; diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 0c745c9f18..7fece00398 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -1030,7 +1030,7 @@ class CoreParserFunctions { * @return array|string */ public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) { - $file = wfFindFile( $name ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name ); if ( $argA == 'nowiki' ) { // {{filepath: | option [| size] }} diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 6249791580..486fdf4413 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3898,7 +3898,7 @@ class Parser { } elseif ( isset( $options['sha1'] ) ) { // get by (sha1,timestamp) $file = RepoGroup::singleton()->findFileFromKey( $options['sha1'], $options ); } else { // get by (name,timestamp) - $file = wfFindFile( $title, $options ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title, $options ); } return $file; } diff --git a/includes/revisiondelete/RevDelFileList.php b/includes/revisiondelete/RevDelFileList.php index 6a6b86c099..ca7bc040d0 100644 --- a/includes/revisiondelete/RevDelFileList.php +++ b/includes/revisiondelete/RevDelFileList.php @@ -19,6 +19,7 @@ * @ingroup RevisionDelete */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IDatabase; /** @@ -109,7 +110,8 @@ class RevDelFileList extends RevDelList { } public function doPostCommitUpdates( array $visibilityChangeMap ) { - $file = wfLocalFile( $this->title ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $this->title ); $file->purgeCache(); $file->purgeDescription(); diff --git a/includes/search/SearchNearMatcher.php b/includes/search/SearchNearMatcher.php index 9ee3e17586..d400267710 100644 --- a/includes/search/SearchNearMatcher.php +++ b/includes/search/SearchNearMatcher.php @@ -1,5 +1,7 @@ getNamespace() == NS_FILE ) { - $image = wfFindFile( $title ); + $image = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); if ( $image ) { return $title; } diff --git a/includes/search/SearchResult.php b/includes/search/SearchResult.php index f85c58fe2d..7e51432b71 100644 --- a/includes/search/SearchResult.php +++ b/includes/search/SearchResult.php @@ -86,16 +86,17 @@ class SearchResult { */ protected function initFromTitle( $title ) { $this->mTitle = $title; + $services = MediaWikiServices::getInstance(); if ( !is_null( $this->mTitle ) ) { $id = false; Hooks::run( 'SearchResultInitFromTitle', [ $title, &$id ] ); $this->mRevision = Revision::newFromTitle( $this->mTitle, $id, Revision::READ_NORMAL ); if ( $this->mTitle->getNamespace() === NS_FILE ) { - $this->mImage = wfFindFile( $this->mTitle ); + $this->mImage = $services->getRepoGroup()->findFile( $this->mTitle ); } } - $this->searchEngine = MediaWikiServices::getInstance()->newSearchEngine(); + $this->searchEngine = $services->newSearchEngine(); } /** diff --git a/includes/specials/SpecialFileDuplicateSearch.php b/includes/specials/SpecialFileDuplicateSearch.php index 2326950bee..5d8a415a00 100644 --- a/includes/specials/SpecialFileDuplicateSearch.php +++ b/includes/specials/SpecialFileDuplicateSearch.php @@ -109,7 +109,7 @@ class FileDuplicateSearchPage extends QueryPage { $this->hash = ''; $title = Title::newFromText( $this->filename, NS_FILE ); if ( $title && $title->getText() != '' ) { - $this->file = wfFindFile( $title ); + $this->file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); } $out = $this->getOutput(); diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 507cd450fe..15b7c632ae 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -537,7 +537,7 @@ class MovePageForm extends UnlistedSpecialPage { if ( $nt->getNamespace() == NS_FILE && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) ) && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) - && wfFindFile( $nt ) + && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt ) ) { $this->showForm( [ [ 'file-exists-sharedrepo' ] ] ); @@ -567,7 +567,8 @@ class MovePageForm extends UnlistedSpecialPage { // Delete an associated image if there is if ( $nt->getNamespace() == NS_FILE ) { - $file = wfLocalFile( $nt ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $nt ); $file->load( File::READ_LATEST ); if ( $file->exists() ) { $file->delete( $reason, false, $user ); diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php index 49f1b3cd6a..c1409ffd6f 100644 --- a/includes/specials/SpecialRedirect.php +++ b/includes/specials/SpecialRedirect.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page that redirects to: the user for a numeric user id, * the file for a given filename, or the page for a given revision id. @@ -101,7 +103,7 @@ class SpecialRedirect extends FormSpecialPage { } catch ( MalformedTitleException $e ) { return Status::newFatal( $e->getMessageObject() ); } - $file = wfFindFile( $title ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); if ( !$file || !$file->exists() ) { // Message: redirect-not-exists diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index dcc35fcef7..68fda497b7 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -669,7 +669,8 @@ class SpecialUpload extends SpecialPage { return true; } - $local = wfLocalFile( $this->mDesiredDestName ); + $local = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $this->mDesiredDestName ); if ( $local && $local->exists() ) { // We're uploading a new version of an existing file. // No creation, so don't watch it if we're not already. diff --git a/includes/specials/SpecialWantedfiles.php b/includes/specials/SpecialWantedfiles.php index 2ebbc2d86c..aa3a971d96 100644 --- a/includes/specials/SpecialWantedfiles.php +++ b/includes/specials/SpecialWantedfiles.php @@ -24,6 +24,8 @@ * @author Soxred93 */ +use MediaWiki\MediaWikiServices; + /** * Querypage that lists the most wanted files * @@ -97,14 +99,14 @@ class WantedFilesPage extends WantedQueryPage { /** * Does the file exist? * - * Use wfFindFile so we still think file namespace pages without - * files are missing, but valid file redirects and foreign files are ok. + * Use findFile() so we still think file namespace pages without files + * are missing, but valid file redirects and foreign files are ok. * * @param Title $title * @return bool */ protected function existenceCheck( Title $title ) { - return (bool)wfFindFile( $title ); + return (bool)MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); } function getQueryInfo() { diff --git a/includes/specials/pagers/ImageListPager.php b/includes/specials/pagers/ImageListPager.php index 8f31f3e630..1d29efbf08 100644 --- a/includes/specials/pagers/ImageListPager.php +++ b/includes/specials/pagers/ImageListPager.php @@ -436,7 +436,8 @@ class ImageListPager extends TablePager { * @throws MWException */ function formatValue( $field, $value ) { - $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); + $services = MediaWikiServices::getInstance(); + $linkRenderer = $services->getLinkRenderer(); switch ( $field ) { case 'thumb': $opt = [ 'time' => wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ]; @@ -468,8 +469,9 @@ class ImageListPager extends TablePager { $filePage, $filePage->getText() ); - $download = Xml::element( 'a', - [ 'href' => wfLocalFile( $filePage )->getUrl() ], + $download = Xml::element( + 'a', + [ 'href' => $services->getRepoGroup()->findFile( $filePage )->getUrl() ], $imgfile ); $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped(); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 597c2777cf..ae5b73249d 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -2069,10 +2069,10 @@ abstract class UploadBase { $partname = $n ? substr( $filename, 0, $n ) : $filename; return ( - substr( $partname, 3, 3 ) == 'px-' || - substr( $partname, 2, 3 ) == 'px-' - ) && - preg_match( "/[0-9]{2}/", substr( $partname, 0, 2 ) ); + substr( $partname, 3, 3 ) == 'px-' || + substr( $partname, 2, 3 ) == 'px-' + ) && + preg_match( "/[0-9]{2}/", substr( $partname, 0, 2 ) ); } /** diff --git a/includes/widget/search/FullSearchResultWidget.php b/includes/widget/search/FullSearchResultWidget.php index 66fc030ca4..d70057091e 100644 --- a/includes/widget/search/FullSearchResultWidget.php +++ b/includes/widget/search/FullSearchResultWidget.php @@ -6,6 +6,7 @@ use Category; use Hooks; use HtmlArmor; use MediaWiki\Linker\LinkRenderer; +use MediaWiki\MediaWikiServices; use SearchResult; use SpecialSearch; use Title; @@ -248,7 +249,8 @@ class FullSearchResultWidget implements SearchResultWidget { $descHtml = null; $thumbHtml = null; - $img = $result->getFile() ?: wfFindFile( $title ); + $img = $result->getFile() ?: MediaWikiServices::getInstance()->getRepoGroup() + ->findFile( $title ); if ( $img ) { $thumb = $img->transform( [ 'width' => 120, 'height' => 120 ] ); if ( $thumb ) { diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php index 4f9e488343..ee6e3e5306 100644 --- a/maintenance/deleteBatch.php +++ b/maintenance/deleteBatch.php @@ -28,6 +28,8 @@ * @ingroup Maintenance */ +use MediaWiki\MediaWikiServices; + require_once __DIR__ . '/Maintenance.php'; /** @@ -98,7 +100,9 @@ class DeleteBatch extends Maintenance { $this->output( $title->getPrefixedText() ); if ( $title->getNamespace() == NS_FILE ) { - $img = wfFindFile( $title, [ 'ignoreRedirect' => true ] ); + $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile( + $title, [ 'ignoreRedirect' => true ] + ); if ( $img && $img->isLocal() && !$img->delete( $reason ) ) { $this->output( " FAILED to delete associated file... " ); } diff --git a/maintenance/dumpUploads.php b/maintenance/dumpUploads.php index a5bc6cc0bc..c4ca056c59 100644 --- a/maintenance/dumpUploads.php +++ b/maintenance/dumpUploads.php @@ -21,6 +21,8 @@ * @ingroup Maintenance */ +use MediaWiki\MediaWikiServices; + require_once __DIR__ . '/Maintenance.php'; /** @@ -109,7 +111,7 @@ By default, outputs relative paths against the parent directory of $wgUploadDire } function outputItem( $name, $shared ) { - $file = wfFindFile( $name ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name ); if ( $file && $this->filterItem( $file, $shared ) ) { $filename = $file->getLocalRefPath(); $rel = wfRelativePath( $filename, $this->mBasePath ); diff --git a/maintenance/eraseArchivedFile.php b/maintenance/eraseArchivedFile.php index ef6d3d8b89..49fadaa2d8 100644 --- a/maintenance/eraseArchivedFile.php +++ b/maintenance/eraseArchivedFile.php @@ -21,6 +21,8 @@ * @ingroup Maintenance */ +use MediaWiki\MediaWikiServices; + require_once __DIR__ . '/Maintenance.php'; /** @@ -66,7 +68,7 @@ class EraseArchivedFile extends Maintenance { $afile = ArchivedFile::newFromRow( $row ); } - $file = wfLocalFile( $filename ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile( $filename ); if ( $file->exists() ) { $this->fatalError( "File '$filename' is still a public file, use the delete form.\n" ); } diff --git a/maintenance/importImages.php b/maintenance/importImages.php index dfa83cdb6a..381926aac4 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -32,6 +32,8 @@ * @author Mij */ +use MediaWiki\MediaWikiServices; + require_once __DIR__ . '/Maintenance.php'; class ImportImages extends Maintenance { @@ -219,7 +221,8 @@ class ImportImages extends Maintenance { } # Check existence - $image = wfLocalFile( $title ); + $image = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $title ); if ( $image->exists() ) { if ( $this->hasOption( 'overwrite' ) ) { $this->output( "{$base} exists, overwriting..." ); diff --git a/maintenance/populateImageSha1.php b/maintenance/populateImageSha1.php index a71abb61ec..0de9d6737e 100644 --- a/maintenance/populateImageSha1.php +++ b/maintenance/populateImageSha1.php @@ -21,6 +21,7 @@ * @ingroup Maintenance */ +use MediaWiki\MediaWikiServices; use MediaWiki\Shell\Shell; require_once __DIR__ . '/Maintenance.php'; @@ -125,7 +126,8 @@ class PopulateImageSha1 extends LoggedUpdateMaintenance { wfWaitForSlaves(); } - $file = wfLocalFile( $row->img_name ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $row->img_name ); if ( !$file ) { continue; } diff --git a/maintenance/rebuildImages.php b/maintenance/rebuildImages.php index c0de33412e..dfce2021e6 100644 --- a/maintenance/rebuildImages.php +++ b/maintenance/rebuildImages.php @@ -195,9 +195,9 @@ class ImageBuilder extends Maintenance { function addMissingImage( $filename, $fullpath ) { $timestamp = $this->dbw->timestamp( $this->getRepo()->getFileTimestamp( $fullpath ) ); + $services = MediaWikiServices::getInstance(); - $altname = MediaWikiServices::getInstance()->getContentLanguage()-> - checkTitleEncoding( $filename ); + $altname = $services->getContentLanguage()->checkTitleEncoding( $filename ); if ( $altname != $filename ) { if ( $this->dryrun ) { $filename = $altname; @@ -214,7 +214,7 @@ class ImageBuilder extends Maintenance { return; } if ( !$this->dryrun ) { - $file = wfLocalFile( $filename ); + $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename ); if ( !$file->recordUpload( '', '(recovered file, missing upload log entry)',