Merge "FileRepo: Use Late Static Binding in File static constructors"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 2359fd6..1e1bde3 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup FileAbstraction
  */
 
+use Wikimedia\AtEase\AtEase;
 use MediaWiki\Logger\LoggerFactory;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
@@ -38,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
  */
@@ -1337,7 +1346,7 @@ class LocalFile extends File {
                $options = [];
                $handler = MediaHandler::getHandler( $props['mime'] );
                if ( $handler ) {
-                       $metadata = Wikimedia\quietCall( 'unserialize', $props['metadata'] );
+                       $metadata = AtEase::quietCall( 'unserialize', $props['metadata'] );
 
                        if ( !is_array( $metadata ) ) {
                                $metadata = [];
@@ -1494,7 +1503,7 @@ class LocalFile extends File {
                                'img_sha1' => $this->sha1
                        ] + $commentFields + $actorFields,
                        __METHOD__,
-                       'IGNORE'
+                       [ 'IGNORE' ]
                );
                $reupload = ( $dbw->affectedRows() == 0 );
 
@@ -1897,6 +1906,7 @@ class LocalFile extends File {
         * @return Status
         */
        function move( $target ) {
+               $localRepo = MediaWikiServices::getInstance()->getRepoGroup();
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
@@ -1913,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(