sub linkify ($$) { #{{{
my $content=shift;
- my $file=shift;
+ my $page=shift;
$content =~ s{(\\?)$config{wiki_link_regexp}}{
- $1 ? "[[$2]]" : htmllink(pagename($file), $2)
+ $1 ? "[[$2]]" : htmllink($page, $2)
}eg;
return $content;
", before, so not rendering from $src");
}
} #}}}
-
+
sub render ($) { #{{{
my $file=shift;
$links{$page}=[findlinks($content, $page)];
- $content=linkify($content, $file);
+ $content=linkify($content, $page);
$content=htmlize($type, $content);
$content=finalize($content, $page);
}
} #}}}
+sub unlockwiki () { #{{{
+ close WIKILOCK;
+} #}}}
+
sub loadindex () { #{{{
open (IN, "$config{srcdir}/.ikiwiki/index") || return;
while (<IN>) {
}
} #}}}
-sub rcs_commit ($) { #{{{
+sub rcs_commit ($$) { #{{{
+ # Tries to commit the page; returns undef on _success_ and
+ # a version of the page with the rcs's conflict markers on failure.
+ # The file is relative to the srcdir.
my $message=shift;
+ my $file=shift;
if (-d "$config{srcdir}/.svn") {
+ # svn up to let svn merge in other changes
+ if (system("svn", "update", "$config{srcdir}/$file") != 0) {
+ warn("svn update failed\n");
+ }
if (system("svn", "commit", "--quiet", "-m",
possibly_foolish_untaint($message),
- $config{srcdir}) != 0) {
+ "$config{srcdir}/$file") != 0) {
warn("svn commit failed\n");
+ my $conflict=readfile("$config{srcdir}/$file");
+ if (system("svn", "revert", "$config{srcdir}/$file") != 0) {
+ warn("svn revert failed\n");
+ }
+ return $conflict;
}
}
+ return undef # success
} #}}}
sub rcs_add ($) { #{{{
+ # filename is relative to the root of the srcdir
my $file=shift;
if (-d "$config{srcdir}/.svn") {
my $num=shift;
my @ret;
+ eval q{use CGI 'escapeHTML'};
eval q{use Date::Parse};
eval q{use Time::Duration};
} #}}}
sub refresh () { #{{{
- # Find existing pages.
+ # find existing pages
my %exists;
my @files;
-
eval q{use File::Find};
find({
no_chdir => 1,
foreach my $page (keys %oldpagemtime) {
if (! $exists{$page}) {
debug("removing old page $page");
- push @del, $renderedfiles{$page};
+ push @del, $pagesources{$page};
prune($config{destdir}."/".$renderedfiles{$page});
delete $renderedfiles{$page};
$oldpagemtime{$page}=0;
table => 0,
template => "$config{templatedir}/editpage.tmpl"
);
+ my @buttons=("Save Page", "Preview", "Cancel");
my ($page)=$form->param('page')=~/$config{wiki_file_regexp}/;
if (! defined $page || ! length $page || $page ne $q->param('page') ||
print $q->redirect("$config{url}/".htmlpage($page));
return;
}
- if (! $form->submitted || ! $form->validate) {
+ elsif ($form->submitted eq "Preview") {
+ $form->tmpl_param("page_preview",
+ htmlize($config{default_pageext},
+ linkify($form->field('content'), $page)));
+ }
+ else {
+ $form->tmpl_param("page_preview", "");
+ }
+ $form->tmpl_param("page_conflict", "");
+
+ if (! $form->submitted || $form->submitted eq "Preview" ||
+ ! $form->validate) {
if ($form->field("do") eq "create") {
if (exists $pagesources{lc($page)}) {
# hmm, someone else made the page in the
$form->title("creating $page");
}
elsif ($form->field("do") eq "edit") {
- my $content="";
- if (exists $pagesources{lc($page)}) {
- $content=readfile("$config{srcdir}/$pagesources{lc($page)}");
- $content=~s/\n/\r\n/g;
+ if (! length $form->field('content')) {
+ my $content="";
+ if (exists $pagesources{lc($page)}) {
+ $content=readfile("$config{srcdir}/$pagesources{lc($page)}");
+ $content=~s/\n/\r\n/g;
+ }
+ $form->field(name => "content", value => $content,
+ force => 1);
}
$form->tmpl_param("page_select", 0);
- $form->field(name => "content", value => $content,
- force => 1);
$form->field(name => "page", type => 'hidden');
$form->title("editing $page");
}
$form->tmpl_param("can_commit", $config{svn});
$form->tmpl_param("indexlink", indexlink());
- print $form->render(submit => ["Save Page", "Cancel"]);
+ print $form->render(submit => \@buttons);
}
else {
# save page
if ($newfile) {
rcs_add($file);
}
+ # prevent deadlock with post-commit hook
+ unlockwiki();
# presumably the commit will trigger an update
# of the wiki
- rcs_commit($message);
+ my $conflict=rcs_commit($file, $message);
+
+ if (defined $conflict) {
+ $form->tmpl_param("page_conflict", 1);
+ $form->field("content", $conflict);
+ $form->field("do", "edit)");
+ print $form->render(submit => \@buttons);
+ return;
+ }
}
else {
loadindex();