From fa80d44451530ac76e6bfec38295056d93f06884 Mon Sep 17 00:00:00 2001 From: Jan Gerber Date: Tue, 15 Jan 2013 23:30:41 +0000 Subject: [PATCH] Bug 43343 add zone "transcoded" for audio/video to allow different storage strategies for thumbnails and audio/video derivatives, add a new zone "transcoded". Change-Id: I204c843dae4966b02f4807f15e6b0bac672f34dc --- includes/filebackend/FileBackendGroup.php | 4 +++ includes/filerepo/FSRepo.php | 4 +++ includes/filerepo/FileRepo.php | 15 ++++++-- includes/filerepo/file/File.php | 43 ++++++++++++++++++++--- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index 53272045a9..0bf5279af5 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -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" ), diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index 635cb95efe..e49f37d280 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -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, diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 5f7972a2d5..05e71d4ecf 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -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 ) ); } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index bccbe648d8..f3711150b2 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -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 * -- 2.20.1