aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-03-28 17:24:44 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-03-28 17:24:44 +0200
commitcec8f61ab84122a3f4b0702aaad6f7a141f99f7b (patch)
tree829ccddf19eaf25ebf918632228eb96088b250d4
parent2f7659becb40e457872fc45f59ad81bff439722f (diff)
downloadphorkie-cec8f61ab84122a3f4b0702aaad6f7a141f99f7b.tar.gz
phorkie-cec8f61ab84122a3f4b0702aaad6f7a141f99f7b.zip
editing works basically
-rw-r--r--data/templates/edit-file.htm5
-rw-r--r--data/templates/edit.htm2
-rw-r--r--src/Phorkie/File.php10
-rw-r--r--src/Phorkie/Repository.php18
-rw-r--r--www/edit.php42
-rw-r--r--www/index.php3
6 files changed, 76 insertions, 4 deletions
diff --git a/data/templates/edit-file.htm b/data/templates/edit-file.htm
index 66647f0..b22314d 100644
--- a/data/templates/edit-file.htm
+++ b/data/templates/edit-file.htm
@@ -2,7 +2,8 @@
<div class="row-fluid">
<div class="span6">
<label for="filename_1">Filename</label>
- <input type="text" name="files[{{fileid}}][name]" id="filename_{{fileid}}" value="{{ file.getFilename }}"/>
+ <input type="hidden" name="files[{{fileid}}][original_name]" value="{{file.getFilename}}"/>
+ <input type="text" name="files[{{fileid}}][name]" id="filename_{{fileid}}" value="{{file.getFilename}}"/>
</div>
<div class="span6" style="text-align: right">
<label for="type_{{fileid}}">Type</label>
@@ -14,6 +15,6 @@
</select>
</div>
</div>
- <textarea name="files[{{fileid}}][content]" id="content_1" cols="80" rows="10" class="content">{{ file.getContent }}</textarea>
+ <textarea name="files[{{fileid}}][content]" id="content_{{fileid}}" cols="80" rows="10" class="content">{{file.getContent}}</textarea>
</div>
diff --git a/data/templates/edit.htm b/data/templates/edit.htm
index 56e08ef..300b6cb 100644
--- a/data/templates/edit.htm
+++ b/data/templates/edit.htm
@@ -2,7 +2,7 @@
{% block title %}Edit paste{% endblock %}
{% block content %}
-<form method="post" action="/">
+<form method="post" action="{{repo.getLink('edit')}}">
<div class="control-group well pastedata">
<label for="description">Description</label>
<input type="text" name="description" id="description" value="{{repo.getDescription}}"/>
diff --git a/src/Phorkie/File.php b/src/Phorkie/File.php
index 6cdc833..3c6ea4b 100644
--- a/src/Phorkie/File.php
+++ b/src/Phorkie/File.php
@@ -59,6 +59,16 @@ class File
}
/**
+ * Return the full path to the file
+ *
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ /**
* Get file extension without dot
*
* @return string
diff --git a/src/Phorkie/Repository.php b/src/Phorkie/Repository.php
index aeccc72..5273b60 100644
--- a/src/Phorkie/Repository.php
+++ b/src/Phorkie/Repository.php
@@ -82,6 +82,9 @@ class Repository
if ($base != $name) {
throw new Exception('No directories supported for now');
}
+ if ($name == '') {
+ throw new Exception_Input('Empty file name given');
+ }
$path = $this->repoDir . '/' . $base;
if (!is_readable($path)) {
throw new Exception_Input('File does not exist');
@@ -89,6 +92,16 @@ class Repository
return new File($path, $this);
}
+ public function hasFile($name)
+ {
+ try {
+ $this->getFileByName($name);
+ } catch (Exception $e) {
+ return false;
+ }
+ return true;
+ }
+
public function getDescription()
{
if (!is_readable($this->repoDir . '/.git/description')) {
@@ -97,6 +110,11 @@ class Repository
return file_get_contents($this->repoDir . '/.git/description');
}
+ public function setDescription($description)
+ {
+ file_put_contents($this->repoDir . '/.git/description', $description);
+ }
+
/**
* Get a link to the repository
*
diff --git a/www/edit.php b/www/edit.php
index d86df41..3bcec6e 100644
--- a/www/edit.php
+++ b/www/edit.php
@@ -8,6 +8,48 @@ require_once 'www-header.php';
$repo = new Repository();
$repo->loadFromRequest();
+if (isset($_POST['files'])) {
+ $vc = $repo->getVc();
+ $repo->setDescription($_POST['description']);
+
+ $bChanged = false;
+ foreach ($_POST['files'] as $num => $arFile) {
+ if (!isset($arFile['original_name'])
+ || !$repo->hasFile($arFile['original_name'])
+ ) {
+ //FIXME: Show error message
+ continue;
+ }
+ //FIXME: fix file names from .. and ./
+ if ($arFile['original_name'] != $arFile['name']) {
+ //FIXME: what to do with overwrites?
+ $vc->getCommand('mv')
+ ->addArgument($arFile['original_name'])
+ ->addArgument($arFile['name'])
+ ->execute();
+ $bChanged = true;
+ }
+ $file = $repo->getFileByName($arFile['name']);
+ if ($file->getContent() != $arFile['content']) {
+ file_put_contents($file->getPath(), $arFile['content']);
+ $command = $vc->getCommand('add')
+ ->addArgument($file->getFilename())
+ ->execute();
+ $bChanged = true;
+ }
+ }
+
+ if ($bChanged) {
+ $vc->getCommand('commit')
+ ->setOption('message', '')
+ ->setOption('allow-empty-message')
+ ->setOption('author', 'Anonymous <anonymous@phorkie>')
+ ->execute();
+ }
+
+ redirect($repo->getLink('display'));
+}
+
render(
'edit',
array(
diff --git a/www/index.php b/www/index.php
index f821c84..db3fd7b 100644
--- a/www/index.php
+++ b/www/index.php
@@ -21,10 +21,11 @@ if (isset($_POST['files'])) {
foreach (glob($repo->repoDir . '/.git/hooks/*') as $hookfile) {
unlink($hookfile);
}
- file_put_contents($repo->repoDir . '.git/description', $_POST['description']);
+ $repo->setDescription($_POST['description']);
foreach ($_POST['files'] as $num => $arFile) {
if ($arFile['name'] != '') {
+ //FIXME: fix file name from ..
$fname = $arFile['name'];
} else {
$fname = 'phork' . $num . '.' . $arFile['type'];