Fix LocalFile::move
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 86b8bbb..d7d6bf7 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
  */
@@ -141,10 +150,10 @@ class LocalFile extends File {
         * @param FileRepo $repo
         * @param null $unused
         *
-        * @return self
+        * @return static
         */
        static function newFromTitle( $title, $repo, $unused = null ) {
-               return new self( $title, $repo );
+               return new static( $title, $repo );
        }
 
        /**
@@ -154,11 +163,11 @@ class LocalFile extends File {
         * @param stdClass $row
         * @param FileRepo $repo
         *
-        * @return self
+        * @return static
         */
        static function newFromRow( $row, $repo ) {
                $title = Title::makeTitle( NS_FILE, $row->img_name );
-               $file = new self( $title, $repo );
+               $file = new static( $title, $repo );
                $file->loadFromRow( $row );
 
                return $file;
@@ -181,12 +190,12 @@ class LocalFile extends File {
                        $conds['img_timestamp'] = $dbr->timestamp( $timestamp );
                }
 
-               $fileQuery = self::getQueryInfo();
+               $fileQuery = static::getQueryInfo();
                $row = $dbr->selectRow(
                        $fileQuery['tables'], $fileQuery['fields'], $conds, __METHOD__, [], $fileQuery['joins']
                );
                if ( $row ) {
-                       return self::newFromRow( $row, $repo );
+                       return static::newFromRow( $row, $repo );
                } else {
                        return false;
                }
@@ -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()->getLocalRepo();
                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->newFile( $this->title );
+               $newTitleFile = $localRepo->newFile( $target );
                // To avoid slow purges in the transaction, move them outside...
                DeferredUpdates::addUpdate(
                        new AutoCommitUpdate(