Make phpcs-strict pass on includes/ (4/~10)
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 5bc7b5e..73ab04d 100644 (file)
@@ -496,6 +496,8 @@ class LocalFile extends File {
 
                $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
 
+               $decoded['metadata'] = $this->repo->getSlaveDB()->decodeBlob( $decoded['metadata'] );
+
                if ( empty( $decoded['major_mime'] ) ) {
                        $decoded['mime'] = 'unknown/unknown';
                } else {
@@ -822,41 +824,6 @@ class LocalFile extends File {
        /** createThumb inherited */
        /** transform inherited */
 
-       /**
-        * Fix thumbnail files from 1.4 or before, with extreme prejudice
-        * @todo Do we still care about this? Perhaps a maintenance script
-        *   can be made instead. Enabling this code results in a serious
-        *   RTT regression for wikis without 404 handling.
-        *
-        * @param string $thumbName
-        */
-       function migrateThumbFile( $thumbName ) {
-               /* Old code for bug 2532
-               $thumbDir = $this->getThumbPath();
-               $thumbPath = "$thumbDir/$thumbName";
-               if ( is_dir( $thumbPath ) ) {
-                       // Directory where file should be
-                       // This happened occasionally due to broken migration code in 1.5
-                       // Rename to broken-*
-                       for ( $i = 0; $i < 100; $i++ ) {
-                               $broken = $this->repo->getZonePath( 'public' ) . "/broken-$i-$thumbName";
-                               if ( !file_exists( $broken ) ) {
-                                       rename( $thumbPath, $broken );
-                                       break;
-                               }
-                       }
-                       // Doesn't exist anymore
-                       clearstatcache();
-               }
-               */
-               /*
-               if ( $this->repo->fileExists( $thumbDir ) ) {
-                       // Delete file where directory should be
-                       $this->repo->cleanupBatch( array( $thumbDir ) );
-               }
-               */
-       }
-
        /** getHandler inherited */
        /** iconThumb inherited */
        /** getLastError inherited */
@@ -1632,14 +1599,15 @@ class LocalFile extends File {
         *
         * @param string $reason
         * @param bool $suppress
+        * @param User|null $user
         * @return FileRepoStatus
         */
-       function delete( $reason, $suppress = false ) {
+       function delete( $reason, $suppress = false, $user = null ) {
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
 
-               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
+               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user );
 
                $this->lock(); // begin
                $batch->addCurrent();
@@ -1689,16 +1657,17 @@ class LocalFile extends File {
         * @param string $archiveName
         * @param string $reason
         * @param bool $suppress
+        * @param User|null $user
         * @throws MWException Exception on database or file store failure
         * @return FileRepoStatus
         */
-       function deleteOld( $archiveName, $reason, $suppress = false ) {
+       function deleteOld( $archiveName, $reason, $suppress = false, $user = null ) {
                global $wgUseSquid;
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
 
-               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
+               $batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user );
 
                $this->lock(); // begin
                $batch->addOld( $archiveName );
@@ -1997,15 +1966,25 @@ class LocalFileDeleteBatch {
        /** @var FileRepoStatus */
        private $status;
 
+       /** @var User */
+       private $user;
+
        /**
         * @param File $file
         * @param string $reason
         * @param bool $suppress
+        * @param User|null $user
         */
-       function __construct( File $file, $reason = '', $suppress = false ) {
+       function __construct( File $file, $reason = '', $suppress = false, $user = null ) {
                $this->file = $file;
                $this->reason = $reason;
                $this->suppress = $suppress;
+               if ( $user ) {
+                       $this->user = $user;
+               } else {
+                       global $wgUser;
+                       $this->user = $wgUser;
+               }
                $this->status = $file->repo->newGood();
        }
 
@@ -2119,11 +2098,9 @@ class LocalFileDeleteBatch {
        }
 
        function doDBInserts() {
-               global $wgUser;
-
                $dbw = $this->file->repo->getMasterDB();
                $encTimestamp = $dbw->addQuotes( $dbw->timestamp() );
-               $encUserId = $dbw->addQuotes( $wgUser->getId() );
+               $encUserId = $dbw->addQuotes( $this->user->getId() );
                $encReason = $dbw->addQuotes( $this->reason );
                $encGroup = $dbw->addQuotes( 'deleted' );
                $ext = $this->file->getExtension();
@@ -2149,7 +2126,11 @@ class LocalFileDeleteBatch {
                        $dbw->insertSelect( 'filearchive', 'image',
                                array(
                                        'fa_storage_group' => $encGroup,
-                                       'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
+                                       'fa_storage_key' => $dbw->conditional(
+                                               array( 'img_sha1' => '' ),
+                                               $dbw->addQuotes( '' ),
+                                               $concat
+                                       ),
                                        'fa_deleted_user' => $encUserId,
                                        'fa_deleted_timestamp' => $encTimestamp,
                                        'fa_deleted_reason' => $encReason,
@@ -2181,7 +2162,11 @@ class LocalFileDeleteBatch {
                        $dbw->insertSelect( 'filearchive', 'oldimage',
                                array(
                                        'fa_storage_group' => $encGroup,
-                                       'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
+                                       'fa_storage_key' => $dbw->conditional(
+                                               array( 'oi_sha1' => '' ),
+                                               $dbw->addQuotes( '' ),
+                                               $concat
+                                       ),
                                        'fa_deleted_user' => $encUserId,
                                        'fa_deleted_timestamp' => $encTimestamp,
                                        'fa_deleted_reason' => $encReason,