]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/CGI.pm
* Since the CGI had to drop the wiki lock to avoid deadlocking the
[ikiwiki.git] / IkiWiki / CGI.pm
index 6c489df8dc7f724582b3aadd82ba34d6f7b2a947..e62bcf477601ec38be1178ba3ce3207c1e588293 100644 (file)
@@ -89,7 +89,9 @@ sub cgi_recentchanges ($) { #{{{
                delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
                $change->{pages} = [
                        map {
-                               $_->{link} = htmllink("", "", $_->{page}, 1, 0, pagetitle($_->{page}));
+                               $_->{link} = htmllink("", "", $_->{page},
+                                       noimageinline => 1,
+                                       linktext => pagetitle($_->{page}));
                                $_;
                        } @{$change->{pages}}
                ];
@@ -219,7 +221,7 @@ sub cgi_prefs ($$) { #{{{
        $form->field(name => "do", type => "hidden");
        $form->field(name => "email", size => 50);
        $form->field(name => "subscriptions", size => 50,
-               comment => "(".htmllink("", "", "PageSpec", 1).")");
+               comment => "(".htmllink("", "", "PageSpec", noimageinline => 1).")");
        $form->field(name => "banned_users", size => 50);
        
        my $user_name=$session->param("name");
@@ -252,12 +254,15 @@ sub cgi_prefs ($$) { #{{{
        elsif ($form->submitted eq 'Save Preferences' && $form->validate) {
                foreach my $field (qw(email subscriptions)) {
                        if (defined $form->field($field) && length $form->field($field)) {
-                               userinfo_set($user_name, $field, $form->field($field)) || error("failed to set $field");
+                               userinfo_set($user_name, $field, $form->field($field)) ||
+                                       error("failed to set $field");
                        }
                }
                if (is_admin($user_name)) {
                        set_banned_users(grep { ! is_admin($_) }
-                                       split(' ', $form->field("banned_users")));
+                                       split(' ',
+                                               $form->field("banned_users"))) ||
+                               error("failed saving changes");
                }
                $form->text(gettext("Preferences saved."));
        }
@@ -357,7 +362,7 @@ sub cgi_editpage ($$) { #{{{
        $form->tmpl_param("can_commit", $config{rcs});
        $form->tmpl_param("indexlink", indexlink());
        $form->tmpl_param("helponformattinglink",
-               htmllink("", "", "HelpOnFormatting", 1));
+               htmllink("", "", "HelpOnFormatting", noimageinline => 1));
        $form->tmpl_param("baseurl", baseurl());
        if (! $form->submitted) {
                $form->field(name => "rcsinfo", value => rcs_prepedit($file),
@@ -454,7 +459,8 @@ sub cgi_editpage ($$) { #{{{
                        
                        $form->tmpl_param("page_select", 1);
                        $form->field(name => "page", type => 'select',
-                               options => \@editable_locs, value => $best_loc);
+                               options => { map { $_ => pagetitle($_, 1) } @editable_locs },
+                               value => $best_loc);
                        $form->field(name => "type", type => 'select',
                                options => \@page_types);
                        $form->title(sprintf(gettext("creating %s"), pagetitle($page)));
@@ -487,8 +493,27 @@ sub cgi_editpage ($$) { #{{{
 
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
-               writefile($file, $config{srcdir}, $content);
+
+               $config{cgi}=0; # avoid cgi error message
+               eval { writefile($file, $config{srcdir}, $content) };
+               $config{cgi}=1;
+               if ($@) {
+                       $form->field(name => "rcsinfo", value => rcs_prepedit($file),
+                               force => 1);
+                       $form->tmpl_param("failed_save", 1);
+                       $form->tmpl_param("error_message", $@);
+                       $form->field("editcontent", value => $content, force => 1);
+                       $form->field(name => "comments", value => $form->field('comments'), force => 1);
+                       $form->field("do", "edit)");
+                       $form->tmpl_param("page_select", 0);
+                       $form->field(name => "page", type => 'hidden');
+                       $form->field(name => "type", type => 'hidden');
+                       $form->title(sprintf(gettext("editing %s"), $page));
+                       print $form->render(submit => \@buttons);
+                       return;
+               }
                
+               my $conflict;
                if ($config{rcs}) {
                        my $message="";
                        if (defined $form->field('comments') &&
@@ -499,44 +524,44 @@ sub cgi_editpage ($$) { #{{{
                        if ($newfile) {
                                rcs_add($file);
                        }
-                       # prevent deadlock with post-commit hook
-                       unlockwiki();
-                       # presumably the commit will trigger an update
-                       # of the wiki
-                       my $conflict=rcs_commit($file, $message,
+
+                       # Prevent deadlock with post-commit hook by
+                       # signaling to it that it should not try to
+                       # do anything (except send commit mails).
+                       disable_commit_hook();
+                       $conflict=rcs_commit($file, $message,
                                $form->field("rcsinfo"),
                                $session->param("name"), $ENV{REMOTE_ADDR});
+                       enable_commit_hook();
+                       rcs_update();
+               }
                
-                       if (defined $conflict) {
-                               $form->field(name => "rcsinfo", value => rcs_prepedit($file),
-                                       force => 1);
-                               $form->tmpl_param("page_conflict", 1);
-                               $form->field("editcontent", value => $conflict, force => 1);
-                               $form->field(name => "comments", value => $form->field('comments'), force => 1);
-                               $form->field("do", "edit)");
-                               $form->tmpl_param("page_select", 0);
-                               $form->field(name => "page", type => 'hidden');
-                               $form->field(name => "type", type => 'hidden');
-                               $form->title(sprintf(gettext("editing %s"), $page));
-                               print $form->render(submit => \@buttons);
-                               return;
-                       }
-                       else {
-                               # Make sure that the repo is up-to-date;
-                               # locking prevents the post-commit hook
-                               # from updating it.
-                               rcs_update();
-                       }
+               # Refresh even if there was a conflict, since other changes
+               # may have been committed while the post-commit hook was
+               # disabled.
+               require IkiWiki::Render;
+               refresh();
+               saveindex();
+
+               if (defined $conflict) {
+                       $form->field(name => "rcsinfo", value => rcs_prepedit($file),
+                               force => 1);
+                       $form->tmpl_param("page_conflict", 1);
+                       $form->field("editcontent", value => $conflict, force => 1);
+                       $form->field(name => "comments", value => $form->field('comments'), force => 1);
+                       $form->field("do", "edit)");
+                       $form->tmpl_param("page_select", 0);
+                       $form->field(name => "page", type => 'hidden');
+                       $form->field(name => "type", type => 'hidden');
+                       $form->title(sprintf(gettext("editing %s"), $page));
+                       print $form->render(submit => \@buttons);
+                       return;
                }
                else {
-                       require IkiWiki::Render;
-                       refresh();
-                       saveindex();
+                       # The trailing question mark tries to avoid broken
+                       # caches and get the most recent version of the page.
+                       redirect($q, "$config{url}/".htmlpage($page)."?updated");
                }
-               
-               # The trailing question mark tries to avoid broken
-               # caches and get the most recent version of the page.
-               redirect($q, "$config{url}/".htmlpage($page)."?updated");
        }
 } #}}}
 
@@ -616,7 +641,7 @@ sub cgi (;$$) { #{{{
                                        email => "",
                                        password => "",
                                        regdate => time,
-                               });
+                               }) || error("failed adding user");
                        }
                }
        }
@@ -688,7 +713,7 @@ sub userlink ($) { #{{{
        else {
                return htmllink("", "", escapeHTML(
                        length $config{userdir} ? $config{userdir}."/".$user : $user
-               ), 1);
+               ), noimageinline => 1);
        }
 } #}}}