Replace some uses of deprecated wfFindFile() and wfLocalFile()
authorDerick Alangi <alangiderick@gmail.com>
Tue, 14 May 2019 17:00:34 +0000 (18:00 +0100)
committerD3r1ck01 <xsavitar.wiki@aol.com>
Tue, 11 Jun 2019 13:26:37 +0000 (13:26 +0000)
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

39 files changed:
includes/EditPage.php
includes/GlobalFunctions.php
includes/Linker.php
includes/Title.php
includes/actions/InfoAction.php
includes/api/ApiImageRotate.php
includes/api/ApiMove.php
includes/api/ApiQueryImageInfo.php
includes/content/FileContentHandler.php
includes/deferred/WANCacheReapUpdate.php
includes/export/XmlDumpWriter.php
includes/filerepo/file/File.php
includes/filerepo/file/LocalFile.php
includes/filerepo/file/LocalFileMoveBatch.php
includes/gallery/TraditionalImageGallery.php
includes/import/ImportableUploadRevisionImporter.php
includes/jobqueue/jobs/ThumbnailRenderJob.php
includes/page/ImagePage.php
includes/page/PageArchive.php
includes/page/WikiFilePage.php
includes/parser/CoreParserFunctions.php
includes/parser/Parser.php
includes/revisiondelete/RevDelFileList.php
includes/search/SearchNearMatcher.php
includes/search/SearchResult.php
includes/specials/SpecialFileDuplicateSearch.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialRedirect.php
includes/specials/SpecialUpload.php
includes/specials/SpecialWantedfiles.php
includes/specials/pagers/ImageListPager.php
includes/upload/UploadBase.php
includes/widget/search/FullSearchResultWidget.php
maintenance/deleteBatch.php
maintenance/dumpUploads.php
maintenance/eraseArchivedFile.php
maintenance/importImages.php
maintenance/populateImageSha1.php
maintenance/rebuildImages.php

index 0bcc893..2eeede9 100644 (file)
@@ -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
index 7256eab..759732f 100644 (file)
@@ -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
index ae50c66..39f4394 100644 (file)
@@ -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 );
        }
 
index dee6c52..b7b28af 100644 (file)
@@ -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 == '';
index ab95b97..e91863a 100644 (file)
@@ -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 );
index 7045138..668bd0e 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -56,7 +59,9 @@ class ApiImageRotate extends ApiBase {
                                }
                        }
 
-                       $file = wfFindFile( $title, [ 'latest' => true ] );
+                       $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
+                               $title, [ 'latest' => true ]
+                       );
                        if ( !$file ) {
                                $r['result'] = 'Failure';
                                $r['errors'] = $this->getErrorFormatter()->arrayFromStatus(
index 89ecc43..540860b 100644 (file)
@@ -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' );
index 051e127..e123a2a 100644 (file)
@@ -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 {
index 3028dfd..6a1cc62 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Content handler for File: files
  * TODO: this handler s not used directly now,
@@ -41,7 +43,8 @@ class FileContentHandler extends WikitextContentHandler {
                if ( NS_FILE != $title->getNamespace() ) {
                        return [];
                }
-               $file = wfLocalFile( $title );
+               $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+                       ->newFile( $title );
                if ( !$file || !$file->exists() ) {
                        return [];
                }
index a218f76..b193d5f 100644 (file)
@@ -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 );
index d3fd374..0659ec1 100644 (file)
@@ -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 ) {
index 124afef..ee7ee6f 100644 (file)
@@ -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
  */
index dd8962d..54bcea3 100644 (file)
@@ -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(
index 5594004..21980b9 100644 (file)
@@ -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
index 4d5222c..d25d9aa 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * Image gallery.
  *
@@ -87,7 +90,7 @@ class TraditionalImageGallery extends ImageGalleryBase {
                                        # Fetch and register the file (file title may be different via hooks)
                                        list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
                                } else {
-                                       $img = wfFindFile( $nt );
+                                       $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt );
                                }
                        } else {
                                $img = false;
index f1ac42c..40c9417 100644 (file)
@@ -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() ) {
index eb8b1a2..85e3af9 100644 (file)
@@ -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() ) {
index 86c59ad..e929ed8 100644 (file)
@@ -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 );
index a314f3a..cdaf062 100644 (file)
@@ -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() ) {
index c457a34..8df9ab2 100644 (file)
@@ -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;
index 0c745c9..7fece00 100644 (file)
@@ -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] }}
index 6249791..486fdf4 100644 (file)
@@ -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;
        }
index 6a6b86c..ca7bc04 100644 (file)
@@ -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();
 
index 9ee3e17..d400267 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Implementation of near match title search.
  * TODO: split into service/implementation.
@@ -150,7 +152,7 @@ class SearchNearMatcher {
                # There may have been a funny upload, or it may be on a shared
                # file repository such as Wikimedia Commons.
                if ( $title->getNamespace() == NS_FILE ) {
-                       $image = wfFindFile( $title );
+                       $image = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
                        if ( $image ) {
                                return $title;
                        }
index f85c58f..7e51432 100644 (file)
@@ -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();
        }
 
        /**
index 2326950..5d8a415 100644 (file)
@@ -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();
index 507cd45..15b7c63 100644 (file)
@@ -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 );
index 49f1b3c..c1409ff 100644 (file)
@@ -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
index dcc35fc..68fda49 100644 (file)
@@ -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.
index 2ebbc2d..aa3a971 100644 (file)
@@ -24,6 +24,8 @@
  * @author Soxred93 <soxred93@gmail.com>
  */
 
+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() {
index 8f31f3e..1d29efb 100644 (file)
@@ -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();
index 597c277..ae5b732 100644 (file)
@@ -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 ) );
        }
 
        /**
index 66fc030..d700570 100644 (file)
@@ -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 ) {
index 4f9e488..ee6e3e5 100644 (file)
@@ -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... " );
                                }
index a5bc6cc..c4ca056 100644 (file)
@@ -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 );
index ef6d3d8..49fadaa 100644 (file)
@@ -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" );
                }
index dfa83cd..381926a 100644 (file)
@@ -32,6 +32,8 @@
  * @author Mij <mij@bitchx.it>
  */
 
+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..." );
index a71abb6..0de9d67 100644 (file)
@@ -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;
                        }
index c0de334..dfce202 100644 (file)
@@ -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)',