summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 904d615d6915f554099e66c32288183e2ba28f0a (plain)
  1. #!/usr/bin/perl -T
  2. use warnings;
  3. use strict;
  4. use File::Find;
  5. use Memoize;
  6. use File::Spec;
  7. $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
  8. BEGIN {
  9. $blosxom::version="is a proper perl module too much to ask?";
  10. do "/usr/bin/markdown";
  11. }
  12. my ($srcdir, $destdir, %links, %oldlinks, %oldpagemtime, %renderedfiles,
  13. %pagesources);
  14. my $wiki_link_regexp=qr/\[\[([^\s]+)\]\]/;
  15. my $wiki_file_regexp=qr/(^[-A-Za-z0-9_.:\/+]+$)/;
  16. my $wiki_file_prune_regexp=qr!((^|/).svn/|\.\.|^\.|\/\.|\.html?$)!;
  17. my $verbose=0;
  18. my $wikiname="wiki";
  19. my $default_pagetype=".mdwn";
  20. my $cgi=0;
  21. my $url="";
  22. my $cgiurl="";
  23. my $svn=1;
  24. sub usage {
  25. die "usage: ikiwiki [options] source dest\n";
  26. }
  27. sub error ($) {
  28. if ($cgi) {
  29. print "Content-type: text/html\n\n";
  30. print "Error: @_\n";
  31. exit 1;
  32. }
  33. else {
  34. die @_;
  35. }
  36. }
  37. sub debug ($) {
  38. print "@_\n" if $verbose;
  39. }
  40. sub mtime ($) {
  41. my $page=shift;
  42. return (stat($page))[9];
  43. }
  44. sub possibly_foolish_untaint ($) {
  45. my $tainted=shift;
  46. my ($untainted)=$tainted=~/(.*)/;
  47. return $untainted;
  48. }
  49. sub basename {
  50. my $file=shift;
  51. $file=~s!.*/!!;
  52. return $file;
  53. }
  54. sub dirname {
  55. my $file=shift;
  56. $file=~s!/?[^/]+$!!;
  57. return $file;
  58. }
  59. sub pagetype ($) {
  60. my $page=shift;
  61. if ($page =~ /\.mdwn$/) {
  62. return ".mdwn";
  63. }
  64. else {
  65. return "unknown";
  66. }
  67. }
  68. sub pagename ($) {
  69. my $file=shift;
  70. my $type=pagetype($file);
  71. my $page=$file;
  72. $page=~s/\Q$type\E*$// unless $type eq 'unknown';
  73. return $page;
  74. }
  75. sub htmlpage ($) {
  76. my $page=shift;
  77. return $page.".html";
  78. }
  79. sub readfile ($) {
  80. my $file=shift;
  81. local $/=undef;
  82. open (IN, "$file") || error("failed to read $file: $!");
  83. my $ret=<IN>;
  84. close IN;
  85. return $ret;
  86. }
  87. sub writefile ($$) {
  88. my $file=shift;
  89. my $content=shift;
  90. my $dir=dirname($file);
  91. if (! -d $dir) {
  92. my $d="";
  93. foreach my $s (split(m!/+!, $dir)) {
  94. $d.="$s/";
  95. if (! -d $d) {
  96. mkdir($d) || error("failed to create directory $d: $!");
  97. }
  98. }
  99. }
  100. open (OUT, ">$file") || error("failed to write $file: $!");
  101. print OUT $content;
  102. close OUT;
  103. }
  104. sub findlinks {
  105. my $content=shift;
  106. my @links;
  107. while ($content =~ /$wiki_link_regexp/g) {
  108. push @links, lc($1);
  109. }
  110. return @links;
  111. }
  112. # Given a page and the text of a link on the page, determine which existing
  113. # page that link best points to. Prefers pages under a subdirectory with
  114. # the same name as the source page, failing that goes down the directory tree
  115. # to the base looking for matching pages.
  116. sub bestlink ($$) {
  117. my $page=shift;
  118. my $link=lc(shift);
  119. my $cwd=$page;
  120. do {
  121. my $l=$cwd;
  122. $l.="/" if length $l;
  123. $l.=$link;
  124. if (exists $links{$l}) {
  125. #debug("for $page, \"$link\", use $l");
  126. return $l;
  127. }
  128. } while $cwd=~s!/?[^/]+$!!;
  129. #print STDERR "warning: page $page, broken link: $link\n";
  130. return "";
  131. }
  132. sub isinlinableimage ($) {
  133. my $file=shift;
  134. $file=~/\.(png|gif|jpg|jpeg)$/;
  135. }
  136. sub htmllink ($$) {
  137. my $page=shift;
  138. my $link=shift;
  139. my $bestlink=bestlink($page, $link);
  140. return $link if $page eq $bestlink;
  141. # TODO BUG: %renderedfiles may not have it, if the linked to page
  142. # was also added and isn't yet rendered! Note that this bug is
  143. # masked by the bug mentioned below that makes all new files
  144. # be rendered twice.
  145. if (! grep { $_ eq $bestlink } values %renderedfiles) {
  146. $bestlink=htmlpage($bestlink);
  147. }
  148. if (! grep { $_ eq $bestlink } values %renderedfiles) {
  149. return "<a href=\"$cgiurl?do=create&page=$link&from=$page\">?</a>$link"
  150. }
  151. $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
  152. if (isinlinableimage($bestlink)) {
  153. return "<img src=\"$bestlink\">";
  154. }
  155. return "<a href=\"$bestlink\">$link</a>";
  156. }
  157. sub linkify ($$) {
  158. my $content=shift;
  159. my $file=shift;
  160. $content =~ s/$wiki_link_regexp/htmllink(pagename($file), $1)/eg;
  161. return $content;
  162. }
  163. sub htmlize ($$) {
  164. my $type=shift;
  165. my $content=shift;
  166. if ($type eq '.mdwn') {
  167. return Markdown::Markdown($content);
  168. }
  169. else {
  170. error("htmlization of $type not supported");
  171. }
  172. }
  173. sub linkbacks ($$) {
  174. my $content=shift;
  175. my $page=shift;
  176. my @links;
  177. foreach my $p (keys %links) {
  178. next if bestlink($page, $p) eq $page;
  179. if (grep { length $_ && bestlink($p, $_) eq $page } @{$links{$p}}) {
  180. my $href=File::Spec->abs2rel(htmlpage($p), dirname($page));
  181. # Trim common dir prefixes from both pages.
  182. my $p_trimmed=$p;
  183. my $page_trimmed=$page;
  184. my $dir;
  185. 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
  186. defined $dir &&
  187. $p_trimmed=~s/^\Q$dir\E// &&
  188. $page_trimmed=~s/^\Q$dir\E//;
  189. push @links, "<a href=\"$href\">$p_trimmed</a>";
  190. }
  191. }
  192. $content.="<hr><p>Links: ".join(" ", sort @links)."</p>\n" if @links;
  193. return $content;
  194. }
  195. sub finalize ($$) {
  196. my $content=shift;
  197. my $page=shift;
  198. my $title=basename($page);
  199. $title=~s/_/ /g;
  200. my $pagelink="";
  201. my $path="";
  202. foreach my $dir (reverse split("/", $page)) {
  203. if (length($pagelink)) {
  204. $pagelink="<a href=\"$path$dir.html\">$dir</a>/ $pagelink";
  205. }
  206. else {
  207. $pagelink=$dir;
  208. }
  209. $path.="../";
  210. }
  211. $path=~s/\.\.\/$/index.html/;
  212. $pagelink="<a href=\"$path\">$wikiname</a>/ $pagelink";
  213. my @actions;
  214. if (length $cgiurl) {
  215. push @actions, "<a href=\"$cgiurl?do=edit&page=$page\">Edit</a>";
  216. push @actions, "<a href=\"$cgiurl?do=recentchanges\">RecentChanges</a>";
  217. }
  218. $content="<html>\n<head><title>$title</title></head>\n<body>\n".
  219. "<h1>$pagelink</h1>\n".
  220. "@actions\n<hr>\n".
  221. $content.
  222. "</body>\n</html>\n";
  223. return $content;
  224. }
  225. sub render ($) {
  226. my $file=shift;
  227. my $type=pagetype($file);
  228. my $content=readfile("$srcdir/$file");
  229. if ($type ne 'unknown') {
  230. my $page=pagename($file);
  231. $links{$page}=[findlinks($content)];
  232. $content=linkify($content, $file);
  233. $content=htmlize($type, $content);
  234. $content=linkbacks($content, $page);
  235. $content=finalize($content, $page);
  236. writefile("$destdir/".htmlpage($page), $content);
  237. $oldpagemtime{$page}=time;
  238. $renderedfiles{$page}=htmlpage($page);
  239. }
  240. else {
  241. $links{$file}=[];
  242. writefile("$destdir/$file", $content);
  243. $oldpagemtime{$file}=time;
  244. $renderedfiles{$file}=$file;
  245. }
  246. }
  247. sub loadindex () {
  248. open (IN, "$srcdir/.index") || return;
  249. while (<IN>) {
  250. $_=possibly_foolish_untaint($_);
  251. chomp;
  252. my ($mtime, $file, $rendered, @links)=split(' ', $_);
  253. my $page=pagename($file);
  254. $pagesources{$page}=$file;
  255. $oldpagemtime{$page}=$mtime;
  256. $oldlinks{$page}=[@links];
  257. $links{$page}=[@links];
  258. $renderedfiles{$page}=$rendered;
  259. }
  260. close IN;
  261. }
  262. sub saveindex () {
  263. open (OUT, ">$srcdir/.index") || error("cannot write to .index: $!");
  264. foreach my $page (keys %oldpagemtime) {
  265. print OUT "$oldpagemtime{$page} $pagesources{$page} $renderedfiles{$page} ".
  266. join(" ", @{$links{$page}})."\n"
  267. if $oldpagemtime{$page};
  268. }
  269. close OUT;
  270. }
  271. sub rcs_update () {
  272. if (-d "$srcdir/.svn") {
  273. if (system("svn", "update", "--quiet", $srcdir) != 0) {
  274. warn("svn update failed\n");
  275. }
  276. }
  277. }
  278. sub rcs_commit ($) {
  279. my $message=shift;
  280. if (-d "$srcdir/.svn") {
  281. if (system("svn", "commit", "--quiet", "-m",
  282. possibly_foolish_untaint($message), $srcdir) != 0) {
  283. warn("svn commit failed\n");
  284. }
  285. }
  286. }
  287. sub rcs_add ($) {
  288. my $file=shift;
  289. if (-d "$srcdir/.svn") {
  290. my $parent=dirname($file);
  291. while (! -d "$srcdir/$parent/.svn") {
  292. $file=$parent;
  293. $parent=dirname($file);
  294. }
  295. if (system("svn", "add", "--quiet", "$srcdir/$file") != 0) {
  296. warn("svn add failed\n");
  297. }
  298. }
  299. }
  300. sub rcs_recentchanges ($) {
  301. my $num=shift;
  302. my @ret;
  303. eval {use Date::Parse};
  304. eval {use Time::Duration};
  305. if (-d "$srcdir/.svn") {
  306. my $info=`LANG=C svn info $srcdir`;
  307. my ($svn_url)=$info=~/^URL: (.*)$/m;
  308. my $div=qr/^--------------------+$/;
  309. my $infoline=qr/^r(\d+)\s+\|\s+([^\s]+)\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/;
  310. my $state='start';
  311. my ($rev, $user, $when, @pages, $message);
  312. foreach (`LANG=C svn log -v '$svn_url'`) {
  313. chomp;
  314. if ($state eq 'start' && /$div/) {
  315. $state='header';
  316. }
  317. elsif ($state eq 'header' && /$infoline/) {
  318. $rev=$1;
  319. $user=$2;
  320. $when=ago(time - str2time($3));
  321. }
  322. elsif ($state eq 'header' && /^\s+(.*)/) {
  323. push @pages, $1;
  324. }
  325. elsif ($state eq 'header' && /^$/) {
  326. $state='body';
  327. }
  328. elsif ($state eq 'body' && /$div/) {
  329. push @ret, {rev => $rev, user => $user,
  330. date => $when, message => $message,
  331. pages => [@pages]},
  332. last if @ret >= $num;
  333. $state='header';
  334. $message=$rev=$user=$when=undef;
  335. @pages=();
  336. }
  337. elsif ($state eq 'body') {
  338. $message.="$_<br>\n";
  339. }
  340. }
  341. }
  342. return @ret;
  343. }
  344. sub prune ($) {
  345. my $file=shift;
  346. unlink($file);
  347. my $dir=dirname($file);
  348. while (rmdir($dir)) {
  349. $dir=dirname($dir);
  350. }
  351. }
  352. sub refresh () {
  353. # Find existing pages.
  354. my %exists;
  355. my @files;
  356. find({
  357. no_chdir => 1,
  358. wanted => sub {
  359. if (/$wiki_file_prune_regexp/) {
  360. $File::Find::prune=1;
  361. }
  362. elsif (! -d $_) {
  363. my ($f)=/$wiki_file_regexp/; # untaint
  364. if (! defined $f) {
  365. warn("skipping bad filename $_\n");
  366. }
  367. else {
  368. $f=~s/^\Q$srcdir\E\/?//;
  369. push @files, $f;
  370. $exists{pagename($f)}=1;
  371. }
  372. }
  373. },
  374. }, $srcdir);
  375. my %rendered;
  376. # check for added or removed pages
  377. my @add;
  378. foreach my $file (@files) {
  379. my $page=pagename($file);
  380. if (! $oldpagemtime{$page}) {
  381. debug("new page $page");
  382. push @add, $file;
  383. $links{$page}=[];
  384. $pagesources{$page}=$file;
  385. }
  386. }
  387. my @del;
  388. foreach my $page (keys %oldpagemtime) {
  389. if (! $exists{$page}) {
  390. debug("removing old page $page");
  391. push @del, $renderedfiles{$page};
  392. prune($destdir."/".$renderedfiles{$page});
  393. delete $renderedfiles{$page};
  394. $oldpagemtime{$page}=0;
  395. delete $pagesources{$page};
  396. }
  397. }
  398. # render any updated files
  399. foreach my $file (@files) {
  400. my $page=pagename($file);
  401. if (! exists $oldpagemtime{$page} ||
  402. mtime("$srcdir/$file") > $oldpagemtime{$page}) {
  403. debug("rendering changed file $file");
  404. render($file);
  405. $rendered{$file}=1;
  406. }
  407. }
  408. # if any files were added or removed, check to see if each page
  409. # needs an update due to linking to them
  410. # TODO: inefficient; pages may get rendered above and again here;
  411. # problem is the bestlink may have changed and we won't know until
  412. # now
  413. if (@add || @del) {
  414. FILE: foreach my $file (@files) {
  415. my $page=pagename($file);
  416. foreach my $f (@add, @del) {
  417. my $p=pagename($f);
  418. foreach my $link (@{$links{$page}}) {
  419. if (bestlink($page, $link) eq $p) {
  420. debug("rendering $file, which links to $p");
  421. render($file);
  422. $rendered{$file}=1;
  423. next FILE;
  424. }
  425. }
  426. }
  427. }
  428. }
  429. # handle linkbacks; if a page has added/removed links, update the
  430. # pages it links to
  431. # TODO: inefficient; pages may get rendered above and again here;
  432. # problem is the linkbacks could be wrong in the first pass render
  433. # above
  434. if (%rendered) {
  435. my %linkchanged;
  436. foreach my $file (keys %rendered, @del) {
  437. my $page=pagename($file);
  438. if (exists $links{$page}) {
  439. foreach my $link (@{$links{$page}}) {
  440. $link=bestlink($page, $link);
  441. if (length $link &&
  442. ! exists $oldlinks{$page} ||
  443. ! grep { $_ eq $link } @{$oldlinks{$page}}) {
  444. $linkchanged{$link}=1;
  445. }
  446. }
  447. }
  448. if (exists $oldlinks{$page}) {
  449. foreach my $link (@{$oldlinks{$page}}) {
  450. $link=bestlink($page, $link);
  451. if (length $link &&
  452. ! exists $links{$page} ||
  453. ! grep { $_ eq $link } @{$links{$page}}) {
  454. $linkchanged{$link}=1;
  455. }
  456. }
  457. }
  458. }
  459. foreach my $link (keys %linkchanged) {
  460. my $linkfile=$pagesources{$link};
  461. if (defined $linkfile) {
  462. debug("rendering $linkfile, to update its linkbacks");
  463. render($linkfile);
  464. }
  465. }
  466. }
  467. }
  468. # Generates a C wrapper program for running ikiwiki in a specific way.
  469. # The wrapper may be safely made suid.
  470. sub gen_wrapper ($$) {
  471. my ($svn, $rebuild)=@_;
  472. eval {use Cwd 'abs_path'};
  473. $srcdir=abs_path($srcdir);
  474. $destdir=abs_path($destdir);
  475. my $this=abs_path($0);
  476. if (! -x $this) {
  477. error("$this doesn't seem to be executable");
  478. }
  479. my @params=($srcdir, $destdir, "--wikiname=$wikiname");
  480. push @params, "--verbose" if $verbose;
  481. push @params, "--rebuild" if $rebuild;
  482. push @params, "--nosvn" if !$svn;
  483. push @params, "--cgi" if $cgi;
  484. push @params, "--url=$url" if $url;
  485. push @params, "--cgiurl=$cgiurl" if $cgiurl;
  486. my $params=join(" ", @params);
  487. my $call='';
  488. foreach my $p ($this, $this, @params) {
  489. $call.=qq{"$p", };
  490. }
  491. $call.="NULL";
  492. my @envsave;
  493. push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
  494. CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE} if $cgi;
  495. my $envsave="";
  496. foreach my $var (@envsave) {
  497. $envsave.=<<"EOF"
  498. if ((s=getenv("$var")))
  499. asprintf(&newenviron[i++], "%s=%s", "$var", s);
  500. EOF
  501. }
  502. open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
  503. print OUT <<"EOF";
  504. /* A wrapper for ikiwiki, can be safely made suid. */
  505. #define _GNU_SOURCE
  506. #include <stdio.h>
  507. #include <unistd.h>
  508. #include <stdlib.h>
  509. #include <string.h>
  510. extern char **environ;
  511. int main (int argc, char **argv) {
  512. /* Sanitize environment. */
  513. char *s;
  514. char *newenviron[$#envsave+3];
  515. int i=0;
  516. $envsave
  517. newenviron[i++]="HOME=$ENV{HOME}";
  518. newenviron[i]=NULL;
  519. environ=newenviron;
  520. if (argc == 2 && strcmp(argv[1], "--params") == 0) {
  521. printf("$params\\n");
  522. exit(0);
  523. }
  524. execl($call);
  525. perror("failed to run $this");
  526. exit(1);
  527. }
  528. EOF
  529. close OUT;
  530. if (system("gcc", "ikiwiki-wrap.c", "-o", "ikiwiki-wrap") != 0) {
  531. error("failed to compile ikiwiki-wrap.c");
  532. }
  533. unlink("ikiwiki-wrap.c");
  534. print "successfully generated ikiwiki-wrap\n";
  535. exit 0;
  536. }
  537. sub cgi () {
  538. eval q{use CGI};
  539. my $q=CGI->new;
  540. my $do=$q->param('do');
  541. if (! defined $do || ! length $do) {
  542. error("\"do\" parameter missing");
  543. }
  544. if ($do eq 'recentchanges') {
  545. my $list="<ul>\n";
  546. foreach my $change (rcs_recentchanges(100)) {
  547. $list.="<li>";
  548. foreach my $page (@{$change->{pages}}) {
  549. $list.=$page." ";
  550. }
  551. $list.="<br>\n";
  552. $list.="changed ".$change->{when}." by ".
  553. htmllink("index", $change->{user}).
  554. ": <i>".$change->{message}."<br>\n";
  555. $list.="</li>\n";
  556. }
  557. $list.="</ul>\n";
  558. print $q->header,
  559. $q->start_html("RecentChanges"),
  560. $q->h1("<a href=\"$url\">$wikiname</a>/ RecentChanges"),
  561. $list,
  562. $q->end_form,
  563. $q->end_html;
  564. return;
  565. }
  566. my ($page)=$q->param('page')=~/$wiki_file_regexp/;
  567. if (! defined $page || ! length $page || $page ne $q->param('page') ||
  568. $page=~/$wiki_file_prune_regexp/ || $page=~/^\//) {
  569. error("bad page name");
  570. }
  571. $page=lc($page);
  572. my $action=$q->request_uri;
  573. $action=~s/\?.*//;
  574. if ($do eq 'create') {
  575. if (exists $pagesources{lc($page)}) {
  576. # hmm, someone else made the page in the meantime?
  577. print $q->redirect("$url/".htmlpage($page));
  578. }
  579. my @page_locs;
  580. my ($from)=$q->param('from')=~/$wiki_file_regexp/;
  581. if (! defined $from || ! length $from ||
  582. $from ne $q->param('from') ||
  583. $from=~/$wiki_file_prune_regexp/ || $from=~/^\//) {
  584. @page_locs=$page;
  585. }
  586. else {
  587. my $dir=$from."/";
  588. $dir=~s![^/]+/$!!;
  589. push @page_locs, $dir.$page;
  590. push @page_locs, "$from/$page";
  591. while (length $dir) {
  592. $dir=~s![^/]+/$!!;
  593. push @page_locs, $dir.$page;
  594. }
  595. }
  596. $q->param("do", "save");
  597. print $q->header,
  598. $q->start_html("Creating $page"),
  599. $q->start_h1("<a href=\"$url\">$wikiname</a>/ Creating $page"),
  600. $q->start_form(-action => $action),
  601. $q->hidden('do'),
  602. "Select page location:",
  603. $q->popup_menu('page', \@page_locs),
  604. $q->textarea(-name => 'content',
  605. -default => "",
  606. -rows => 20,
  607. -columns => 80),
  608. $q->br,
  609. "Optional comment about this change:",
  610. $q->br,
  611. $q->textfield(-name => "comments", -size => 80),
  612. $q->br,
  613. $q->submit("Save Page"),
  614. $q->end_form,
  615. $q->end_html;
  616. }
  617. elsif ($do eq 'edit') {
  618. my $content="";
  619. if (exists $pagesources{lc($page)}) {
  620. $content=readfile("$srcdir/$pagesources{lc($page)}");
  621. $content=~s/\n/\r\n/g;
  622. }
  623. $q->param("do", "save");
  624. print $q->header,
  625. $q->start_html("Editing $page"),
  626. $q->h1("<a href=\"$url\">$wikiname</a>/ Editing $page"),
  627. $q->start_form(-action => $action),
  628. $q->hidden('do'),
  629. $q->hidden('page'),
  630. $q->textarea(-name => 'content',
  631. -default => $content,
  632. -rows => 20,
  633. -columns => 80),
  634. $q->br,
  635. "Optional comment about this change:",
  636. $q->br,
  637. $q->textfield(-name => "comments", -size => 80),
  638. $q->br,
  639. $q->submit("Save Page"),
  640. $q->end_form,
  641. $q->end_html;
  642. }
  643. elsif ($do eq 'save') {
  644. my $file=$page.$default_pagetype;
  645. my $newfile=1;
  646. if (exists $pagesources{lc($page)}) {
  647. $file=$pagesources{lc($page)};
  648. $newfile=0;
  649. }
  650. my $content=$q->param('content');
  651. $content=~s/\r\n/\n/g;
  652. $content=~s/\r/\n/g;
  653. writefile("$srcdir/$file", $content);
  654. my $message="web commit from $ENV{REMOTE_ADDR}";
  655. if (defined $q->param('comments')) {
  656. $message.=": ".$q->param('comments');
  657. }
  658. if ($svn) {
  659. if ($newfile) {
  660. rcs_add($file);
  661. }
  662. # presumably the commit will trigger an update
  663. # of the wiki
  664. rcs_commit($message);
  665. }
  666. else {
  667. refresh();
  668. }
  669. print $q->redirect("$url/".htmlpage($page));
  670. }
  671. else {
  672. error("unknown do parameter");
  673. }
  674. }
  675. my $rebuild=0;
  676. my $wrapper=0;
  677. if (grep /^-/, @ARGV) {
  678. eval {use Getopt::Long};
  679. GetOptions(
  680. "wikiname=s" => \$wikiname,
  681. "verbose|v" => \$verbose,
  682. "rebuild" => \$rebuild,
  683. "wrapper" => \$wrapper,
  684. "svn!" => \$svn,
  685. "cgi" => \$cgi,
  686. "url=s" => \$url,
  687. "cgiurl=s" => \$cgiurl,
  688. ) || usage();
  689. }
  690. usage() unless @ARGV == 2;
  691. ($srcdir) = possibly_foolish_untaint(shift);
  692. ($destdir) = possibly_foolish_untaint(shift);
  693. if ($cgi && ! length $url) {
  694. error("Must specify url to wiki with --url when using --cgi");
  695. }
  696. gen_wrapper($svn, $rebuild) if $wrapper;
  697. memoize('pagename');
  698. memoize('bestlink');
  699. loadindex() unless $rebuild;
  700. if ($cgi) {
  701. cgi();
  702. }
  703. else {
  704. rcs_update() if $svn;
  705. refresh();
  706. saveindex();
  707. }