jump to correct hash after renaming a file
[phorkie.git] / www / edit.php
index 33b22c2afe09031f3fc264c466ac49ef2eeee8ff..1ced7b6a64fc812745bebb7ec7b32ba3cafa3fd7 100644 (file)
@@ -11,18 +11,38 @@ $repo->loadFromRequest();
 
 $file = null;
 if (isset($_GET['file'])) {
-    $file = $repo->getFileByName($_GET['file']);
+    if ($_GET['file'] == 'newfile') {
+        $file = 'newfile';
+    } else {
+        $file = $repo->getFileByName($_GET['file']);
+    }
 }
 
 $repopo = new Repository_Post($repo);
 if ($repopo->process($_POST, $_SESSION)) {
     $anchor = '';
-    if ($file !== null) {
-        $anchor = '#' . $file->getAnchorName();
+    if ($file instanceof File) {
+        if (isset($repopo->renameMap[$file->getFilename()])) {
+            $anchor = '#'
+                . $repo->getFileByName(
+                    $repopo->renameMap[$file->getFilename()]
+                )->getAnchorName();
+        } else {
+            $anchor = '#' . $file->getAnchorName();
+        }
+    } else if ($file === 'newfile' && $repopo->newfileName) {
+        $anchor = '#' . $repo->getFileByName($repopo->newfileName)->getAnchorName();
     }
     redirect($repo->getLink('display', null, true) . $anchor);
 }
 
+$actionFile = null;
+if ($file instanceof File) {
+    $actionFile = $file->getFilename();
+} else if ($file === 'newfile') {
+    $actionFile = 'newfile';
+}
+
 render(
     'edit',
     array(
@@ -30,6 +50,7 @@ render(
         'singlefile' => $file,
         'dh'   => new \Date_HumanDiff(),
         'htmlhelper' => new HtmlHelper(),
+        'formaction' => $repo->getLink('edit', $actionFile)
     )
 );
 ?>