edit/page: keep page named after existing directory
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 28 Oct 2019 02:36:22 +0000 (03:36 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Nov 2019 06:08:13 +0000 (07:08 +0100)
Allow either subdir.html or subdir/index.html, preventing edit from creating
conforming duplicates.

Reported-by: Arie van Marion
edit/page.js
edit/page/index.php

index 522d63e3c41d5b55f05b987ea5b05c6d7620b2b2..9997e293c7615a3af4c6b29945f56583503a49e5 100644 (file)
@@ -2,7 +2,7 @@ CKEDITOR.plugins.add('inlinesave', {
        init: function(editor) {
                editor.addCommand( 'inlinesave', {
                        exec: function (editor) {
-                               var pagename = window.location.pathname.replace(/\/$/, '/index');
+                               var pagename = window.location.pathname;
                                var body = editor.getData();
                                // empty line is equivalent to a paragraph break
                                body = body.replace(/<br \/>\s*<br \/>/g, '<p>');
index 086c7531c56683381713bf213fafb915127cae2e..48f8942e144e3487dee87ca1f7efabb6a50ca068 100644 (file)
@@ -45,9 +45,12 @@ if (!$_POST)
 if (!$Args)
        abort("geen bestand aangeleverd", '409 input error');
 
-$filename = ltrim($Args, '/').'.html';
+$filename = trim($Args, '/');
 if (preg_match('{^\.}', $filename))
        abort("ongeldige bestandsnaam: $filename", '403 input error');
+if (is_dir($filename) && !file_exists("$filename.html"))
+       $filename .= '/index';
+$filename .= '.html';
 if (file_exists($filename) and !is_writable($filename))
        abort("onwijzigbaar bestand: $filename", '403 input error');