## online page editing
-To support editing pages in a web browser, a CGI script is needed that
-pulls the page out of [[Subversion]], presents it to the user for editing,
-and then commits the changed page back to [[Subversion]].
-
-Due to [[WikiSpam]], this will probably also need to incorporate a user
-registration system. So there will need to be a script that handles logins
-and registrations, sets a cookie, and the page editor can refuse to edit
-pages for users who arn't logged in, and include a not of who made the
-change in the svn log.
-
-If possible I'd prefer to use someone else's generic web user registration
-and login system, if one exists.
+* Missing support for preview, cancel.
+* Missing conflict detection.
+* Missing commit message box.
+* No support for web user tracking/login yet.
+* Doesn't svn commit yet.
## [[RecentChanges]]
my $default_pagetype=".mdwn";
my $cgi=0;
my $url="";
+my $svn=1;
sub usage {
die "usage: ikiwiki [options] source dest\n";
close OUT;
}
-sub update () {
+sub rcs_update () {
if (-d "$srcdir/.svn") {
if (system("svn", "update", "--quiet", $srcdir) != 0) {
warn("svn update failed\n");
}
}
+sub rcs_commit ($) {
+ my $message=shift;
+
+ if (-d "$srcdir/.svn") {
+ if (system("svn", "commit", "--quiet", "-m",
+ possibly_foolish_untaint($message), $srcdir) != 0) {
+ warn("svn commit failed\n");
+ }
+ }
+}
+
+sub rcs_ad ($) {
+ my $file=shift;
+
+ if (-d "$srcdir/.svn") {
+ if (system("svn", "add", "--quiet", $file) != 0) {
+ warn("svn add failed\n");
+ }
+ }
+}
+
sub prune ($) {
my $file=shift;
# Generates a C wrapper program for running ikiwiki in a specific way.
# The wrapper may be safely made suid.
sub gen_wrapper ($$) {
- my ($offline, $rebuild)=@_;
+ my ($svn, $rebuild)=@_;
eval {use Cwd 'abs_path'};
$srcdir=abs_path($srcdir);
my $call=qq{"$this", "$this", "$srcdir", "$destdir", "--wikiname=$wikiname"};
$call.=', "--verbose"' if $verbose;
$call.=', "--rebuild"' if $rebuild;
- $call.=', "--offline"' if $offline;
+ $call.=', "--nosvn"' if !$svn;
$call.=', "--cgi"' if $cgi;
$call.=', "--url='.$url.'"' if $url;
- # For CGI we need all these environment variables.
- my @envsave=qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
- CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE};
+ my @envsave;
+ push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
+ CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE} if $cgi;
my $envsave="";
foreach my $var (@envsave) {
$envsave.=<<"EOF"
int main (void) {
/* Sanitize environment. */
- if ($cgi) {
- char *s;
- char *newenviron[$#envsave+2];
- int i=0;
- $envsave;
- newenviron[i]=NULL;
- environ=newenviron;
- }
- else {
- clearenv();
- }
+ char *s;
+ char *newenviron[$#envsave+3];
+ int i=0;
+ $envsave;
+ newenviron[i++]="HOME=$ENV{HOME}";
+ newenviron[i]=NULL;
+ environ=newenviron;
execl($call, NULL);
perror("failed to run $this");
-default => $content,
-rows => 20,
-columns => 80),
- $q->p,
+ $q->br,
+ "$ENV{HOME} Optional comment about this change",
+ $q->br,
+ $q->textfield(-name => "comments", -size => 80),
+ $q->br,
$q->submit("Save Changes"),
- # TODO: Cancel button returns to page.
- # TODO: Preview button.
- # TODO: Commit message field.
- # TODO: Conflict prevention.
$q->end_form,
$q->end_html;
}
elsif ($do eq 'save') {
my $file=$page.$default_pagetype;
+ my $newfile=1;
if (exists $pagesources{lc($page)}) {
$file=$pagesources{lc($page)};
+ $newfile=0;
}
my $content=$q->param('content');
$content=~s/\r/\n/g;
writefile("$srcdir/$file", $content);
+ my $message="web commit from $ENV{REMOTE_ADDR}";
+ if (defined $q->param('comments')) {
+ $message.="\n".$q->param('comments');
+ }
+
+ if ($svn) {
+ if ($newfile) {
+ rcs_add($file);
+ }
+ # presumably the commit will trigger an update
+ # of the wiki
+ rcs_commit($message);
+ }
+ else {
+ refresh();
+ }
+
print $q->redirect("$url/".htmlpage($page));
}
else {
}
my $rebuild=0;
-my $offline=0;
my $wrapper=0;
if (grep /^-/, @ARGV) {
eval {use Getopt::Long};
"verbose|v" => \$verbose,
"rebuild" => \$rebuild,
"wrapper" => \$wrapper,
- "offline" => \$offline,
+ "svn!" => \$svn,
"cgi" => \$cgi,
"url=s" => \$url,
) || usage();
error("Must specify url to wiki with --url when using --cgi");
}
-gen_wrapper($offline, $rebuild) if $wrapper;
+gen_wrapper($svn, $rebuild) if $wrapper;
memoize('pagename');
memoize('bestlink');
loadindex() unless $rebuild;
cgi();
}
else {
- update() unless $offline;
+ rcs_update() if $svn;
refresh();
saveindex();
}