gopher-server: allow creating new pages

This commit is contained in:
Alex Schroeder
2018-01-03 14:53:30 +01:00
parent eceea26677
commit cc2de3e860
2 changed files with 21 additions and 2 deletions

View File

@@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
package OddMuse;
use strict;
use 5.10.0;
@@ -24,7 +23,7 @@ use Getopt::Long;
our($RunCGI, $DataDir, %IndexHash, @IndexList, $IndexFile, $TagFile,
%Page, $OpenPageName, $MaxPost, $ShowEdits, %Locks, $CommentsPattern,
$CommentsPrefix);
$CommentsPrefix, $EditAllowed, $NoEditFile);
my $host;
my $port;
@@ -222,6 +221,15 @@ sub serve_main_menu {
. "\r\n");
}
if ($EditAllowed and not IsFile($NoEditFile)) {
print_text($stream, join("\t",
"w" . "New page",
"do/new",
$host,
$port)
. "\r\n");
}
my @pages = sort { $b cmp $a } grep(/^\d\d\d\d-\d\d-\d\d/, @IndexList);
for my $id (@pages) {
last unless $id;
@@ -714,6 +722,11 @@ sub process_request {
serve_rc($stream, 0);
} elsif ($id eq "do/rc/showedits") {
serve_rc($stream, 1);
} elsif ($id eq "do/new") {
# second line is page title
($id, $data) = split(/\r?\n/, $data, 2);
utf8::decode($id);
write_text_page($stream, $id, $data);
} elsif ($id =~ m!^([^/]*)/(\d+)/menu$! and $IndexHash{$1}) {
serve_page_menu($stream, $1, $2);
} elsif (substr($id, -5) eq '/menu' and $IndexHash{substr($id, 0, -5)}) {

View File

@@ -206,6 +206,12 @@ like($page, qr/^1Haiku \(current\)\tHaiku\/menu\t/m, "Haiku (current)");
like($page, qr/^i\d\d:\d\d UTC by Alex from \S+: typos \(minor\)/m, "Metadata recorded");
like($page, qr/^1Haiku \(1\)\tHaiku\/1\/menu\t/m, "Haiku (1)");
# new page
$page = query_gopher("do/new", "Haiku_Copy\n$haiku");
like($page, qr/^iPage was saved./m, "Write copy of haiku");
$page = query_gopher("Haiku_Copy");
like($page, qr/^$haiku_re/, "New copy of haiku created");
# Image download
my $image = query_gopher("Picture");
like($image, qr/\211PNG\r\n/, "Image download");