Bug 43343 add zone "transcoded" for audio/video
authorJan Gerber <jgerber@wikimedia.org>
Tue, 15 Jan 2013 23:30:41 +0000 (23:30 +0000)
committerJan Gerber <jgerber@wikimedia.org>
Tue, 5 Feb 2013 05:53:57 +0000 (05:53 +0000)
to allow different storage strategies for thumbnails
and audio/video derivatives, add a new zone "transcoded".

Change-Id: I204c843dae4966b02f4807f15e6b0bac672f34dc

includes/filebackend/FileBackendGroup.php
includes/filerepo/FSRepo.php
includes/filerepo/FileRepo.php
includes/filerepo/file/File.php

index 5327204..0bf5279 100644 (file)
@@ -87,6 +87,9 @@ class FileBackendGroup {
                        $thumbDir = isset( $info['thumbDir'] )
                                ? $info['thumbDir']
                                : "{$directory}/thumb";
+                       $transcodedDir = isset( $info['transcodedDir'] )
+                               ? $info['transcodedDir']
+                               : "{$directory}/transcoded";
                        $fileMode = isset( $info['fileMode'] )
                                ? $info['fileMode']
                                : 0644;
@@ -98,6 +101,7 @@ class FileBackendGroup {
                                'containerPaths' => array(
                                        "{$repoName}-public"  => "{$directory}",
                                        "{$repoName}-thumb"   => $thumbDir,
+                                       "{$repoName}-transcoded"   => $transcodedDir,
                                        "{$repoName}-deleted" => $deletedDir,
                                        "{$repoName}-temp"    => "{$directory}/temp"
                                ),
index 635cb95..e49f37d 100644 (file)
@@ -46,6 +46,9 @@ class FSRepo extends FileRepo {
                        $thumbDir = isset( $info['thumbDir'] )
                                ? $info['thumbDir']
                                : "{$directory}/thumb";
+                       $transcodedDir = isset( $info['transcodedDir'] )
+                               ? $info['transcodedDir']
+                               : "{$directory}/transcoded";
                        $fileMode = isset( $info['fileMode'] )
                                ? $info['fileMode']
                                : 0644;
@@ -59,6 +62,7 @@ class FSRepo extends FileRepo {
                                        "{$repoName}-public"  => "{$directory}",
                                        "{$repoName}-temp"    => "{$directory}/temp",
                                        "{$repoName}-thumb"   => $thumbDir,
+                                       "{$repoName}-transcoded"   => $transcodedDir,
                                        "{$repoName}-deleted" => $deletedDir
                                ),
                                'fileMode'       => $fileMode,
index 5f7972a..05e71d4 100644 (file)
@@ -120,7 +120,7 @@ class FileRepo {
                $this->isPrivate = !empty( $info['isPrivate'] );
                // Give defaults for the basic zones...
                $this->zones = isset( $info['zones'] ) ? $info['zones'] : array();
-               foreach ( array( 'public', 'thumb', 'temp', 'deleted' ) as $zone ) {
+               foreach ( array( 'public', 'thumb', 'transcoded', 'temp', 'deleted' ) as $zone ) {
                        if ( !isset( $this->zones[$zone]['container'] ) ) {
                                $this->zones[$zone]['container'] = "{$this->name}-{$zone}";
                        }
@@ -204,7 +204,7 @@ class FileRepo {
         * @return String or false
         */
        public function getZoneUrl( $zone, $ext = null ) {
-               if ( in_array( $zone, array( 'public', 'temp', 'thumb' ) ) ) { // standard public zones
+               if ( in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) ) { // standard public zones
                        if ( $ext !== null && isset( $this->zones[$zone]['urlsByExt'][$ext] ) ) {
                                return $this->zones[$zone]['urlsByExt'][$ext]; // custom URL for extension/zone
                        } elseif ( isset( $this->zones[$zone]['url'] ) ) {
@@ -220,6 +220,8 @@ class FileRepo {
                                return false; // no public URL
                        case 'thumb':
                                return $this->thumbUrl;
+                       case 'transcoded':
+                               return "{$this->url}/transcoded";
                        default:
                                return false;
                }
@@ -240,7 +242,7 @@ class FileRepo {
         */
        public function getZoneHandlerUrl( $zone ) {
                if ( isset( $this->zones[$zone]['handlerUrl'] )
-                       && in_array( $zone, array( 'public', 'temp', 'thumb' ) ) )
+                       && in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) )
                {
                        return $this->zones[$zone]['handlerUrl'];
                }
@@ -1670,10 +1672,17 @@ class FileRepo {
                                        'directory' => ( $this->zones['thumb']['directory'] == '' )
                                                ? 'temp'
                                                : $this->zones['thumb']['directory'] . '/temp'
+                               ),
+                               'transcoded'  => array(
+                                       'container' => $this->zones['transcoded']['container'],
+                                       'directory' => ( $this->zones['transcoded']['directory'] == '' )
+                                               ? 'temp'
+                                               : $this->zones['transcoded']['directory'] . '/temp'
                                )
                        ),
                        'url'        => $this->getZoneUrl( 'temp' ),
                        'thumbUrl'   => $this->getZoneUrl( 'thumb' ) . '/temp',
+                       'transcodedUrl'   => $this->getZoneUrl( 'transcoded' ) . '/temp',
                        'hashLevels' => $this->hashLevels // performance
                ) );
        }
index bccbe64..f371115 100644 (file)
@@ -1247,6 +1247,18 @@ abstract class File {
                return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
        }
 
+       /**
+        * Get the path of the transcoded directory, or a particular file if $suffix is specified
+        *
+        * @param $suffix bool|string if not false, the name of a media file
+        *
+        * @return string
+        */
+       function getTranscodedPath( $suffix = false ) {
+               $this->assertRepoDefined();
+               return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix );
+       }
+
        /**
         * Get the URL of the archive directory, or a particular file if $suffix is specified
         *
@@ -1288,22 +1300,45 @@ abstract class File {
        }
 
        /**
-        * Get the URL of the thumbnail directory, or a particular file if $suffix is specified
+        * Get the URL of the zone directory, or a particular file if $suffix is specified
         *
-        * @param $suffix bool|string if not false, the name of a thumbnail file
+        * @param $zone string name of requested zone
+        * @param $suffix bool|string if not false, the name of a file in zone
         *
         * @return string path
         */
-       function getThumbUrl( $suffix = false ) {
+       function getZoneUrl( $zone, $suffix = false ) {
                $this->assertRepoDefined();
                $ext = $this->getExtension();
-               $path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/' . $this->getUrlRel();
+               $path = $this->repo->getZoneUrl( $zone, $ext ) . '/' . $this->getUrlRel();
                if ( $suffix !== false ) {
                        $path .= '/' . rawurlencode( $suffix );
                }
                return $path;
        }
 
+       /**
+        * Get the URL of the thumbnail directory, or a particular file if $suffix is specified
+        *
+        * @param $suffix bool|string if not false, the name of a thumbnail file
+        *
+        * @return string path
+        */
+       function getThumbUrl( $suffix = false ) {
+               return $this->getZoneUrl( 'thumb', $suffix );
+       }
+
+       /**
+        * Get the URL of the transcoded directory, or a particular file if $suffix is specified
+        *
+        * @param $suffix bool|string if not false, the name of a media file
+        *
+        * @return string path
+        */
+       function getTranscodedUrl( $suffix = false ) {
+               return $this->getZoneUrl( 'transcoded', $suffix );
+       }
+
        /**
         * Get the public zone virtual URL for a current version source file
         *