raw download for older revisions
authorChristian Weiske <cweiske@cweiske.de>
Tue, 17 Apr 2012 17:53:13 +0000 (19:53 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 17 Apr 2012 17:53:13 +0000 (19:53 +0200)
src/phorkie/File.php
src/phorkie/Repository.php
www/.htaccess
www/raw.php

index bc0950fce26f1c1d583649f2e6440b5b1b5db904..acc44cd884468e45ee8248dc8740e3a8661476c8 100644 (file)
@@ -102,7 +102,12 @@ class File
     public function getLink($type, $option = null)
     {
         if ($type == 'raw') {
     public function getLink($type, $option = null)
     {
         if ($type == 'raw') {
-            return '/' . $this->repo->id . '/raw/' . $this->getFilename();
+            if ($this->repo->hash === null) {
+                return '/' . $this->repo->id . '/raw/' . $this->getFilename();
+            } else {
+                return '/' . $this->repo->id . '/rev-raw/' . $this->repo->hash
+                    . '/' . $this->getFilename();
+            }
         } else if ($type == 'tool') {
             return '/' . $this->repo->id . '/tool/' . $option . '/' . $this->getFilename();
         }
         } else if ($type == 'tool') {
             return '/' . $this->repo->id . '/tool/' . $option . '/' . $this->getFilename();
         }
index 6c71b4733006130fa06b915f7ddcec75001c3887..c854cf167186455fc77049914b2c32212be936de 100644 (file)
@@ -118,6 +118,16 @@ class Repository
      * @return File[] Array of files
      */
     public function getFiles()
      * @return File[] Array of files
      */
     public function getFiles()
+    {
+        $files = $this->getFilePaths();
+        $arFiles = array();
+        foreach ($files as $name) {
+            $arFiles[] = new File($name, $this);
+        }
+        return $arFiles;
+    }
+
+    protected function getFilePaths()
     {
         if ($this->hash === null) {
             $hash = 'HEAD';
     {
         if ($this->hash === null) {
             $hash = 'HEAD';
@@ -129,28 +139,23 @@ class Repository
             ->setOption('name-only')
             ->addArgument($hash)
             ->execute();
             ->setOption('name-only')
             ->addArgument($hash)
             ->execute();
-        $files = explode("\n", trim($output));
-        $arFiles = array();
-        foreach ($files as $name) {
-            $arFiles[] = new File($name, $this);
-        }
-        return $arFiles;
+        return explode("\n", trim($output));
     }
 
     public function getFileByName($name, $bHasToExist = true)
     {
     }
 
     public function getFileByName($name, $bHasToExist = true)
     {
-        $base = basename($name);
-        if ($base != $name) {
-            throw new Exception('No directories supported for now');
-        }
+        $name = Tools::sanitizeFilename($name);
         if ($name == '') {
             throw new Exception_Input('Empty file name given');
         }
         if ($name == '') {
             throw new Exception_Input('Empty file name given');
         }
-        $fullpath = $this->workDir . '/' . $base;
-        if ($bHasToExist && !is_readable($fullpath)) {
-            throw new Exception_Input('File does not exist');
+
+        if ($bHasToExist) {
+            $files = $this->getFilePaths();
+            if (array_search($name, $files) === false) {
+                throw new Exception_Input('File does not exist');
+            }
         }
         }
-        return new File($base, $this);
+        return new File($name, $this);
     }
 
     public function hasFile($name)
     }
 
     public function hasFile($name)
index 73ba7dbc38a0372ff04b706c96e9dd3329dea724..697b6ec095d866193a78b5c91e3dc351897fd6ea 100644 (file)
@@ -9,6 +9,7 @@ RewriteRule ^([0-9]+)/edit$ /edit.php?id=$1
 RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1
 RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
 RewriteRule ^([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2
 RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1
 RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
 RewriteRule ^([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2
+RewriteRule ^([0-9]+)/rev-raw/(.+)/(.+)$ /raw.php?id=$1&rev=$2&file=$3
 RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3
 
 RewriteRule ^list$ /list.php
 RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3
 
 RewriteRule ^list$ /list.php
index 28f7c56ee6ca3475a68507e3de2e27ec422a48d7..8bda11e8fbaeb9b363bb726bf27239ad9de32eef 100644 (file)
@@ -17,5 +17,10 @@ if ($mimetype === null) {
     $mimetype = 'text/plain';
 }
 header('Content-Type: ' . $mimetype);
     $mimetype = 'text/plain';
 }
 header('Content-Type: ' . $mimetype);
-readfile($file->getFullPath());
+if ($repo->hash === null) {
+    //IIRC readfile is not so memory-intensive for big files
+    readfile($file->getFullPath());
+} else {
+    echo $file->getContent();
+}
 ?>
 ?>