3ba6cf7f84aebbb314716aa0361f9639faa0c90f
[ikiwiki.git] / IkiWiki / CGI.pm
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use IkiWiki;
6 use IkiWiki::UserInfo;
7 use open qw{:utf8 :std};
8 use Encode;
9
10 package IkiWiki;
11
12 sub printheader ($) { #{{{
13         my $session=shift;
14         
15         if ($config{sslcookie}) {
16                 print $session->header(-charset => 'utf-8',
17                         -cookie => $session->cookie(-secure => 1));
18         } else {
19                 print $session->header(-charset => 'utf-8');
20         }
21
22 } #}}}
23
24 sub redirect ($$) { #{{{
25         my $q=shift;
26         my $url=shift;
27         if (! $config{w3mmode}) {
28                 print $q->redirect($url);
29         }
30         else {
31                 print "Content-type: text/plain\n";
32                 print "W3m-control: GOTO $url\n\n";
33         }
34 } #}}}
35
36 sub page_locked ($$;$) { #{{{
37         my $page=shift;
38         my $session=shift;
39         my $nonfatal=shift;
40         
41         my $user=$session->param("name");
42         return if defined $user && is_admin($user);
43
44         foreach my $admin (@{$config{adminuser}}) {
45                 my $locked_pages=userinfo_get($admin, "locked_pages");
46                 if (pagespec_match($page, userinfo_get($admin, "locked_pages"))) {
47                         return 1 if $nonfatal;
48                         error(htmllink("", "", $page, 1)." is locked by ".
49                               htmllink("", "", $admin, 1)." and cannot be edited.");
50                 }
51         }
52
53         return 0;
54 } #}}}
55
56 sub decode_form_utf8 ($) { #{{{
57         my $form = shift;
58         foreach my $f ($form->field) {
59                 next if Encode::is_utf8(scalar $form->field($f));
60                 $form->field(name  => $f,
61                              value => decode_utf8($form->field($f)),
62                              force => 1,
63                             );
64         }
65 } #}}}
66
67 sub cgi_recentchanges ($) { #{{{
68         my $q=shift;
69         
70         unlockwiki();
71
72         # Optimisation: building recentchanges means calculating lots of
73         # links. Memoizing htmllink speeds it up a lot (can't be memoized
74         # during page builds as the return values may change, but they
75         # won't here.)
76         eval q{use Memoize};
77         memoize("htmllink");
78
79         eval q{use Time::Duration};
80         eval q{use CGI 'escapeHTML'};
81
82         my $changelog=[rcs_recentchanges(100)];
83         foreach my $change (@$changelog) {
84                 $change->{when} = concise(ago($change->{when}));
85                 $change->{user} = htmllink("", "", escapeHTML($change->{user}), 1);
86
87                 my $is_excess = exists $change->{pages}[10]; # limit pages to first 10
88                 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
89                 $change->{pages} = [
90                         map {
91                                 $_->{link} = htmllink("", "", $_->{page}, 1);
92                                 $_;
93                         } @{$change->{pages}}
94                 ];
95                 push @{$change->{pages}}, { link => '...' } if $is_excess;
96         }
97
98         my $template=template("recentchanges.tmpl"); 
99         $template->param(
100                 title => "RecentChanges",
101                 indexlink => indexlink(),
102                 wikiname => $config{wikiname},
103                 changelog => $changelog,
104                 baseurl => baseurl(),
105         );
106         run_hooks(pagetemplate => sub {
107                 shift->(page => "", destpage => "", template => $template);
108         });
109         print $q->header(-charset => 'utf-8'), $template->output;
110 } #}}}
111
112 sub cgi_signin ($$) { #{{{
113         my $q=shift;
114         my $session=shift;
115
116         eval q{use CGI::FormBuilder};
117         my $form = CGI::FormBuilder->new(
118                 title => "signin",
119                 fields => [qw(do title page subpage from name password)],
120                 header => 1,
121                 charset => "utf-8",
122                 method => 'POST',
123                 validate => {
124                         confirm_password => {
125                                 perl => q{eq $form->field("password")},
126                         },
127                         email => 'EMAIL',
128                 },
129                 required => 'NONE',
130                 javascript => 0,
131                 params => $q,
132                 action => $config{cgiurl},
133                 header => 0,
134                 template => (-e "$config{templatedir}/signin.tmpl" ?
135                              {template_params("signin.tmpl")} : ""),
136                 stylesheet => baseurl()."style.css",
137         );
138                 
139         decode_form_utf8($form);
140         
141         $form->field(name => "name", required => 0);
142         $form->field(name => "do", type => "hidden");
143         $form->field(name => "page", type => "hidden");
144         $form->field(name => "title", type => "hidden");
145         $form->field(name => "from", type => "hidden");
146         $form->field(name => "subpage", type => "hidden");
147         $form->field(name => "password", type => "password", required => 0);
148         if ($form->submitted eq "Register" || $form->submitted eq "Create Account") {
149                 $form->title("register");
150                 $form->text("");
151                 $form->field(name => "name", comment => "use FirstnameLastName");
152                 $form->fields(qw(do title page subpage from name password confirm_password email));
153                 $form->field(name => "confirm_password", type => "password");
154                 $form->field(name => "email", type => "text");
155         }
156         if ($q->param("do") ne "signin" && !$form->submitted) {
157                 $form->text("You need to log in first.");
158         }
159         
160         if ($form->submitted) {
161                 # Set required fields based on how form was submitted.
162                 my %required=(
163                         "Login" => [qw(name password)],
164                         "Register" => [],
165                         "Create Account" => [qw(name password confirm_password email)],
166                         "Mail Password" => [qw(name)],
167                 );
168                 foreach my $opt (@{$required{$form->submitted}}) {
169                         $form->field(name => $opt, required => 1);
170                 }
171         
172                 # Validate password differently depending on how
173                 # form was submitted.
174                 if ($form->submitted eq 'Login') {
175                         $form->field(
176                                 name => "password",
177                                 validate => sub {
178                                         length $form->field("name") &&
179                                         shift eq userinfo_get($form->field("name"), 'password');
180                                 },
181                         );
182                         $form->field(name => "name", validate => '/^\w+$/');
183                 }
184                 else {
185                         $form->field(name => "password", validate => 'VALUE');
186                 }
187                 # And make sure the entered name exists when logging
188                 # in or sending email, and does not when registering.
189                 if ($form->submitted eq 'Create Account') {
190                         $form->field(
191                                 name => "name",
192                                 validate => sub {
193                                         my $name=shift;
194                                         length $name &&
195                                         $name=~/$config{wiki_file_regexp}/ &&
196                                         ! userinfo_get($name, "regdate");
197                                 },
198                         );
199                 }
200                 else {
201                         $form->field(
202                                 name => "name",
203                                 validate => sub {
204                                         my $name=shift;
205                                         length $name &&
206                                         userinfo_get($name, "regdate");
207                                 },
208                         );
209                 }
210         }
211         else {
212                 # First time settings.
213                 $form->field(name => "name", comment => "use FirstnameLastName");
214                 if ($session->param("name")) {
215                         $form->field(name => "name", value => $session->param("name"));
216                 }
217         }
218
219         if ($form->submitted && $form->validate) {
220                 if ($form->submitted eq 'Login') {
221                         $session->param("name", $form->field("name"));
222                         if (defined $form->field("do") && 
223                             $form->field("do") ne 'signin') {
224                                 redirect($q, cgiurl(
225                                         do => $form->field("do"),
226                                         page => $form->field("page"),
227                                         title => $form->field("title"),
228                                         subpage => $form->field("subpage"),
229                                         from => $form->field("from"),
230                                 ));
231                         }
232                         else {
233                                 redirect($q, $config{url});
234                         }
235                 }
236                 elsif ($form->submitted eq 'Create Account') {
237                         my $user_name=$form->field('name');
238                         if (userinfo_setall($user_name, {
239                                            'email' => $form->field('email'),
240                                            'password' => $form->field('password'),
241                                            'regdate' => time
242                                          })) {
243                                 $form->field(name => "confirm_password", type => "hidden");
244                                 $form->field(name => "email", type => "hidden");
245                                 $form->text("Account creation successful. Now you can Login.");
246                                 printheader($session);
247                                 print misctemplate($form->title, $form->render(submit => ["Login"]));
248                         }
249                         else {
250                                 error("Error creating account.");
251                         }
252                 }
253                 elsif ($form->submitted eq 'Mail Password') {
254                         my $user_name=$form->field("name");
255                         my $template=template("passwordmail.tmpl");
256                         $template->param(
257                                 user_name => $user_name,
258                                 user_password => userinfo_get($user_name, "password"),
259                                 wikiurl => $config{url},
260                                 wikiname => $config{wikiname},
261                                 REMOTE_ADDR => $ENV{REMOTE_ADDR},
262                         );
263                         
264                         eval q{use Mail::Sendmail};
265                         sendmail(
266                                 To => userinfo_get($user_name, "email"),
267                                 From => "$config{wikiname} admin <$config{adminemail}>",
268                                 Subject => "$config{wikiname} information",
269                                 Message => $template->output,
270                         ) or error("Failed to send mail");
271                         
272                         $form->text("Your password has been emailed to you.");
273                         $form->field(name => "name", required => 0);
274                         printheader($session);
275                         print misctemplate($form->title, $form->render(submit => ["Login", "Mail Password"]));
276                 }
277                 elsif ($form->submitted eq "Register") {
278                         printheader($session);
279                         print misctemplate($form->title, $form->render(submit => ["Create Account"]));
280                 }
281         }
282         elsif ($form->submitted eq "Create Account") {
283                 printheader($session);
284                 print misctemplate($form->title, $form->render(submit => ["Create Account"]));
285         }
286         else {
287                 printheader($session);
288                 print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
289         }
290 } #}}}
291
292 sub cgi_prefs ($$) { #{{{
293         my $q=shift;
294         my $session=shift;
295
296         eval q{use CGI::FormBuilder};
297         my $form = CGI::FormBuilder->new(
298                 title => "preferences",
299                 fields => [qw(do name password confirm_password email 
300                               subscriptions locked_pages)],
301                 header => 0,
302                 charset => "utf-8",
303                 method => 'POST',
304                 validate => {
305                         confirm_password => {
306                                 perl => q{eq $form->field("password")},
307                         },
308                         email => 'EMAIL',
309                 },
310                 required => 'NONE',
311                 javascript => 0,
312                 params => $q,
313                 action => $config{cgiurl},
314                 template => (-e "$config{templatedir}/prefs.tmpl" ?
315                              {template_params("prefs.tmpl")} : ""),
316                 stylesheet => baseurl()."style.css",
317         );
318         my @buttons=("Save Preferences", "Logout", "Cancel");
319         
320         my $user_name=$session->param("name");
321         $form->field(name => "do", type => "hidden");
322         $form->field(name => "name", disabled => 1,
323                 value => $user_name, force => 1);
324         $form->field(name => "password", type => "password");
325         $form->field(name => "confirm_password", type => "password");
326         $form->field(name => "subscriptions", size => 50,
327                 comment => "(".htmllink("", "", "PageSpec", 1).")");
328         $form->field(name => "locked_pages", size => 50,
329                 comment => "(".htmllink("", "", "PageSpec", 1).")");
330         $form->field(name => "banned_users", size => 50);
331         
332         if (! is_admin($user_name)) {
333                 $form->field(name => "locked_pages", type => "hidden");
334                 $form->field(name => "banned_users", type => "hidden");
335         }
336
337         if ($config{httpauth}) {
338                 $form->field(name => "password", type => "hidden");
339                 $form->field(name => "confirm_password", type => "hidden");
340         }
341         
342         if (! $form->submitted) {
343                 $form->field(name => "email", force => 1,
344                         value => userinfo_get($user_name, "email"));
345                 $form->field(name => "subscriptions", force => 1,
346                         value => userinfo_get($user_name, "subscriptions"));
347                 $form->field(name => "locked_pages", force => 1,
348                         value => userinfo_get($user_name, "locked_pages"));
349                 if (is_admin($user_name)) {
350                         $form->field(name => "banned_users", force => 1,
351                                 value => join(" ", get_banned_users()));
352                 }
353         }
354         
355         decode_form_utf8($form);
356         
357         if ($form->submitted eq 'Logout') {
358                 $session->delete();
359                 redirect($q, $config{url});
360                 return;
361         }
362         elsif ($form->submitted eq 'Cancel') {
363                 redirect($q, $config{url});
364                 return;
365         }
366         elsif ($form->submitted eq "Save Preferences" && $form->validate) {
367                 foreach my $field (qw(password email subscriptions locked_pages)) {
368                         if (length $form->field($field)) {
369                                 userinfo_set($user_name, $field, $form->field($field)) || error("failed to set $field");
370                         }
371                 }
372                 if (is_admin($user_name)) {
373                         set_banned_users(grep { ! is_admin($_) }
374                                         split(' ', $form->field("banned_users")));
375                 }
376                 $form->text("Preferences saved.");
377         }
378         
379         printheader($session);
380         print misctemplate($form->title, $form->render(submit => \@buttons));
381 } #}}}
382
383 sub cgi_editpage ($$) { #{{{
384         my $q=shift;
385         my $session=shift;
386
387         my @fields=qw(do rcsinfo subpage from page type editcontent comments);
388         my @buttons=("Save Page", "Preview", "Cancel");
389         
390         eval q{use CGI::FormBuilder; use CGI::FormBuilder::Template::HTML};
391         my $renderer=CGI::FormBuilder::Template::HTML->new(
392                 fields => \@fields,
393                 template_params("editpage.tmpl"),
394         );
395         run_hooks(pagetemplate => sub {
396                 shift->(page => "", destpage => "", template => $renderer->engine);
397         });
398         my $form = CGI::FormBuilder->new(
399                 fields => \@fields,
400                 header => 1,
401                 charset => "utf-8",
402                 method => 'POST',
403                 validate => {
404                         editcontent => '/.+/',
405                 },
406                 required => [qw{editcontent}],
407                 javascript => 0,
408                 params => $q,
409                 action => $config{cgiurl},
410                 table => 0,
411                 template => $renderer,
412         );
413         
414         decode_form_utf8($form);
415         
416         # This untaint is safe because titlepage removes any problematic
417         # characters.
418         my ($page)=$form->field('page');
419         $page=titlepage(possibly_foolish_untaint($page));
420         if (! defined $page || ! length $page ||
421             $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
422                 error("bad page name");
423         }
424         
425         my $from;
426         if (defined $form->field('from')) {
427                 ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
428         }
429         
430         my $file;
431         my $type;
432         if (exists $pagesources{$page}) {
433                 $file=$pagesources{$page};
434                 $type=pagetype($file);
435         }
436         else {
437                 $type=$form->param('type');
438                 if (defined $type && length $type && $hooks{htmlize}{$type}) {
439                         $type=possibly_foolish_untaint($type);
440                 }
441                 elsif (defined $from) {
442                         # favor the type of linking page
443                         $type=pagetype($pagesources{$from});
444                 }
445                 $type=$config{default_pageext} unless defined $type;
446                 $file=$page.".".$type;
447         }
448
449         my $newfile=0;
450         if (! -e "$config{srcdir}/$file") {
451                 $newfile=1;
452         }
453
454         $form->field(name => "do", type => 'hidden');
455         $form->field(name => "from", type => 'hidden');
456         $form->field(name => "rcsinfo", type => 'hidden');
457         $form->field(name => "subpage", type => 'hidden');
458         $form->field(name => "page", value => $page, force => 1);
459         $form->field(name => "type", value => $type, force => 1);
460         $form->field(name => "comments", type => "text", size => 80);
461         $form->field(name => "editcontent", type => "textarea", rows => 20,
462                 cols => 80);
463         $form->tmpl_param("can_commit", $config{rcs});
464         $form->tmpl_param("indexlink", indexlink());
465         $form->tmpl_param("helponformattinglink",
466                 htmllink("", "", "HelpOnFormatting", 1));
467         $form->tmpl_param("baseurl", baseurl());
468         if (! $form->submitted) {
469                 $form->field(name => "rcsinfo", value => rcs_prepedit($file),
470                         force => 1);
471         }
472         
473         if ($form->submitted eq "Cancel") {
474                 if ($newfile && defined $from) {
475                         redirect($q, "$config{url}/".htmlpage($from));
476                 }
477                 elsif ($newfile) {
478                         redirect($q, $config{url});
479                 }
480                 else {
481                         redirect($q, "$config{url}/".htmlpage($page));
482                 }
483                 return;
484         }
485         elsif ($form->submitted eq "Preview") {
486                 my $content=$form->field('editcontent');
487                 my $comments=$form->field('comments');
488                 $form->field(name => "editcontent",
489                                 value => $content, force => 1);
490                 $form->field(name => "comments",
491                                 value => $comments, force => 1);
492                 $config{rss}=$config{atom}=0; # avoid preview writing a feed!
493                 $form->tmpl_param("page_preview",
494                         htmlize($page, $type,
495                         linkify($page, "",
496                         preprocess($page, $page,
497                         filter($page, $content)))));
498         }
499         else {
500                 $form->tmpl_param("page_preview", "");
501         }
502         $form->tmpl_param("page_conflict", "");
503         
504         if (! $form->submitted || $form->submitted eq "Preview" || 
505             ! $form->validate) {
506                 if ($form->field("do") eq "create") {
507                         my @page_locs;
508                         my $best_loc;
509                         if (! defined $from || ! length $from ||
510                             $from ne $form->field('from') ||
511                             $from=~/$config{wiki_file_prune_regexp}/ ||
512                             $from=~/^\// ||
513                             $form->submitted eq "Preview") {
514                                 @page_locs=$best_loc=$page;
515                         }
516                         else {
517                                 my $dir=$from."/";
518                                 $dir=~s![^/]+/+$!!;
519                                 
520                                 if ((defined $form->field('subpage') && length $form->field('subpage')) ||
521                                     $page eq 'discussion') {
522                                         $best_loc="$from/$page";
523                                 }
524                                 else {
525                                         $best_loc=$dir.$page;
526                                 }
527                                 
528                                 push @page_locs, $dir.$page;
529                                 push @page_locs, "$from/$page";
530                                 while (length $dir) {
531                                         $dir=~s![^/]+/+$!!;
532                                         push @page_locs, $dir.$page;
533                                 }
534                         }
535
536                         @page_locs = grep {
537                                 ! exists $pagecase{lc $_} &&
538                                 ! page_locked($_, $session, 1)
539                         } @page_locs;
540                         
541                         if (! @page_locs) {
542                                 # hmm, someone else made the page in the
543                                 # meantime?
544                                 redirect($q, "$config{url}/".htmlpage($page));
545                                 return;
546                         }
547                         
548                         my @page_types;
549                         if (exists $hooks{htmlize}) {
550                                 @page_types=keys %{$hooks{htmlize}};
551                         }
552                         
553                         $form->tmpl_param("page_select", 1);
554                         $form->field(name => "page", type => 'select',
555                                 options => \@page_locs, value => $best_loc);
556                         $form->field(name => "type", type => 'select',
557                                 options => \@page_types);
558                         $form->title("creating ".pagetitle($page));
559                 }
560                 elsif ($form->field("do") eq "edit") {
561                         page_locked($page, $session);
562                         if (! defined $form->field('editcontent') || 
563                             ! length $form->field('editcontent')) {
564                                 my $content="";
565                                 if (exists $pagesources{$page}) {
566                                         $content=readfile(srcfile($pagesources{$page}));
567                                         $content=~s/\n/\r\n/g;
568                                 }
569                                 $form->field(name => "editcontent", value => $content,
570                                         force => 1);
571                         }
572                         $form->tmpl_param("page_select", 0);
573                         $form->field(name => "page", type => 'hidden');
574                         $form->field(name => "type", type => 'hidden');
575                         $form->title("editing ".pagetitle($page));
576                 }
577                 
578                 print $form->render(submit => \@buttons);
579         }
580         else {
581                 # save page
582                 page_locked($page, $session);
583                 
584                 my $content=$form->field('editcontent');
585
586                 $content=~s/\r\n/\n/g;
587                 $content=~s/\r/\n/g;
588                 writefile($file, $config{srcdir}, $content);
589                 
590                 my $message="web commit ";
591                 if (defined $session->param("name") && 
592                     length $session->param("name")) {
593                         $message.="by ".$session->param("name");
594                 }
595                 else {
596                         $message.="from $ENV{REMOTE_ADDR}";
597                 }
598                 if (defined $form->field('comments') &&
599                     length $form->field('comments')) {
600                         $message.=": ".$form->field('comments');
601                 }
602                 
603                 if ($config{rcs}) {
604                         if ($newfile) {
605                                 rcs_add($file);
606                         }
607                         # prevent deadlock with post-commit hook
608                         unlockwiki();
609                         # presumably the commit will trigger an update
610                         # of the wiki
611                         my $conflict=rcs_commit($file, $message,
612                                 $form->field("rcsinfo"));
613                 
614                         if (defined $conflict) {
615                                 $form->field(name => "rcsinfo", value => rcs_prepedit($file),
616                                         force => 1);
617                                 $form->tmpl_param("page_conflict", 1);
618                                 $form->field("editcontent", value => $conflict, force => 1);
619                                 $form->field(name => "comments", value => $form->field('comments'), force => 1);
620                                 $form->field("do", "edit)");
621                                 $form->tmpl_param("page_select", 0);
622                                 $form->field(name => "page", type => 'hidden');
623                                 $form->field(name => "type", type => 'hidden');
624                                 $form->title("editing $page");
625                                 print $form->render(submit => \@buttons);
626                                 return;
627                         }
628                 }
629                 else {
630                         require IkiWiki::Render;
631                         refresh();
632                         saveindex();
633                 }
634                 
635                 # The trailing question mark tries to avoid broken
636                 # caches and get the most recent version of the page.
637                 redirect($q, "$config{url}/".htmlpage($page)."?updated");
638         }
639 } #}}}
640
641 sub cgi () { #{{{
642         eval q{use CGI};
643         eval q{use CGI::Session};
644         
645         my $q=CGI->new;
646         
647         run_hooks(cgi => sub { shift->($q) });
648         
649         my $do=$q->param('do');
650         if (! defined $do || ! length $do) {
651                 my $error = $q->cgi_error;
652                 if ($error) {
653                         error("Request not processed: $error");
654                 }
655                 else {
656                         error("\"do\" parameter missing");
657                 }
658         }
659         
660         # Things that do not need a session.
661         if ($do eq 'recentchanges') {
662                 cgi_recentchanges($q);
663                 return;
664         }
665         elsif ($do eq 'hyperestraier') {
666                 cgi_hyperestraier();
667         }
668         
669         CGI::Session->name("ikiwiki_session_".encode_utf8($config{wikiname}));
670         
671         my $oldmask=umask(077);
672         my $session = CGI::Session->new("driver:DB_File", $q,
673                 { FileName => "$config{wikistatedir}/sessions.db" });
674         umask($oldmask);
675         
676         # Everything below this point needs the user to be signed in.
677         if (((! $config{anonok} || $do eq 'prefs') &&
678              (! $config{httpauth}) &&
679              (! defined $session->param("name") ||
680              ! userinfo_get($session->param("name"), "regdate"))) || $do eq 'signin') {
681                 cgi_signin($q, $session);
682         
683                 # Force session flush with safe umask.
684                 my $oldmask=umask(077);
685                 $session->flush;
686                 umask($oldmask);
687                 
688                 return;
689         }
690
691         if ($config{httpauth} && (! defined $session->param("name"))) {
692                 if (! defined $q->remote_user()) {
693                         error("Could not determine authenticated username.");
694                 }
695                 else {
696                         $session->param("name", $q->remote_user());
697                         if (! userinfo_get($session->param("name"), "regdate")) {
698                                 userinfo_setall($session->param("name"), {
699                                         email => "",
700                                         password => "",
701                                         regdate=>time,
702                                 });
703                         }
704                 }
705         }
706
707         if (userinfo_get($session->param("name"), "banned")) {
708                 print $q->header(-status => "403 Forbidden");
709                 $session->delete();
710                 print "You are banned.";
711                 exit;
712         }
713         
714         if ($do eq 'create' || $do eq 'edit') {
715                 cgi_editpage($q, $session);
716         }
717         elsif ($do eq 'prefs') {
718                 cgi_prefs($q, $session);
719         }
720         elsif ($do eq 'blog') {
721                 my $page=titlepage(decode_utf8($q->param('title')));
722                 # if the page already exists, munge it to be unique
723                 my $from=$q->param('from');
724                 my $add="";
725                 while (exists $pagecase{lc "$from/$page$add"}) {
726                         $add=1 unless length $add;
727                         $add++;
728                 }
729                 $q->param('page', $page.$add);
730                 # now run same as create
731                 $q->param('do', 'create');
732                 cgi_editpage($q, $session);
733         }
734         else {
735                 error("unknown do parameter");
736         }
737 } #}}}
738
739 1