]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/CGI.pm
improved logic
[ikiwiki.git] / IkiWiki / CGI.pm
index 67bce67952c044d00007471b459bf7ab2fd7cd8a..9e85e1f4402d8399f0714cba1d9cf34f470d3efe 100644 (file)
@@ -308,10 +308,12 @@ sub cgi_editpage ($$) { #{{{
        $page=lc($page);
        
        my $file=$page.$config{default_pageext};
        $page=lc($page);
        
        my $file=$page.$config{default_pageext};
-       my $newfile=1;
        if (exists $pagesources{lc($page)}) {
                $file=$pagesources{lc($page)};
        if (exists $pagesources{lc($page)}) {
                $file=$pagesources{lc($page)};
-               $newfile=0;
+       }
+       my $newfile=0;
+       if (! -e "$config{srcdir}/$file") {
+               $newfile=1;
        }
 
        $form->field(name => "do", type => 'hidden');
        }
 
        $form->field(name => "do", type => 'hidden');
@@ -403,7 +405,7 @@ sub cgi_editpage ($$) { #{{{
                            ! length $form->field('content')) {
                                my $content="";
                                if (exists $pagesources{lc($page)}) {
                            ! length $form->field('content')) {
                                my $content="";
                                if (exists $pagesources{lc($page)}) {
-                                       $content=readfile("$config{srcdir}/$pagesources{lc($page)}");
+                                       $content=readfile(srcfile($pagesources{lc($page)}));
                                        $content=~s/\n/\r\n/g;
                                }
                                $form->field(name => "content", value => $content,
                                        $content=~s/\n/\r\n/g;
                                }
                                $form->field(name => "content", value => $content,
@@ -423,7 +425,7 @@ sub cgi_editpage ($$) { #{{{
                my $content=$form->field('content');
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
                my $content=$form->field('content');
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
-               writefile("$config{srcdir}/$file", $content);
+               writefile($file, $config{srcdir}, $content);
                
                my $message="web commit ";
                if (length $session->param("name")) {
                
                my $message="web commit ";
                if (length $session->param("name")) {
@@ -473,6 +475,12 @@ sub cgi_editpage ($$) { #{{{
        }
 } #}}}
 
        }
 } #}}}
 
+sub cgi_hyperestraier () { #{{{
+       # only works for GET requests
+       chdir("$config{wikistatedir}/hyperestraier") || error("chdir: $!");
+       exec("./".basename($config{cgiurl})) || error("estseek.cgi failed");
+} #}}}
+
 sub cgi () { #{{{
        eval q{use CGI};
        eval q{use CGI::Session};
 sub cgi () { #{{{
        eval q{use CGI};
        eval q{use CGI::Session};
@@ -481,7 +489,12 @@ sub cgi () { #{{{
        
        my $do=$q->param('do');
        if (! defined $do || ! length $do) {
        
        my $do=$q->param('do');
        if (! defined $do || ! length $do) {
-               error("\"do\" parameter missing");
+               if (defined $q->param('phrase')) {
+                       cgi_hyperestraier();
+               }
+               else {
+                       error("\"do\" parameter missing");
+               }
        }
        
        # Things that do not need a session.
        }
        
        # Things that do not need a session.
@@ -489,6 +502,9 @@ sub cgi () { #{{{
                cgi_recentchanges($q);
                return;
        }
                cgi_recentchanges($q);
                return;
        }
+       elsif ($do eq 'hyperestraier') {
+               cgi_hyperestraier();
+       }
        
        CGI::Session->name("ikiwiki_session_$config{wikiname}");
        
        
        CGI::Session->name("ikiwiki_session_$config{wikiname}");