Once a friend came out with a wiki project. He wanted to code something on his own, and done so in C++. It took him well over a thousand lines to make something usable. Then I wanted to check, how many lines do I need to make a wiki in Perl. I spent one afternoon in September 2005 on it.


NanoWiki is just what it is meant to be

Source code

use CGI;
use DBI;
my $node = CGI::param('node') || 'main';
my $action = CGI::param('action') || 'show';
my $dbh = DBI->connect("dbi:mysql:wiki","root","");
my $main = my $content = CGI::param('field') || $dbh->selectrow_array('SELECT content FROM pages WHERE title LIKE '.$dbh->quote($node));
if($action eq 'edit'){
    $main = CGI::submit({-label=>'Apply', -name=>'apply'}).CGI::textfield('node', $node).CGI::br().CGI::textarea(-name=>'field', -default=>$content, -rows=>20, -columns=>60);}
    $dbh->do("REPLACE INTO pages (title, content) VALUES (".$dbh->quote($node).",".$dbh->quote(CGI::param('field')).")");}
elsif($action eq 'remove'){
    $main = CGI::submit({-label=>"Delete node $node", -name=>'dodel'}).CGI::hidden('node', $node);}
    $dbh->do("DELETE FROM pages WHERE title LIKE ".$dbh->quote($node));}
foreach(@{$dbh->selectall_arrayref("SELECT title FROM pages")})
{push our @menu, CGI::a({href=>CGI::url()."?action=$action&node=".$_->[0]}, @{$_});}
print CGI::header({-charset=>'ISO-8859-2'}).CGI::start_html({-lang=>'pl-PL', -title=>'Proof of concept wiki', -encoding=>'iso-8859-2'});
foreach (('show', 'edit', 'remove'))
{print CGI::a({href=>CGI::url()."?action=$_&node=$node"},"[$_]");}
print CGI::start_form().CGI::table({-width=>"100%"},CGI::Tr(CGI::td([$main, CGI::ul(\our @menu)]))).CGI::end_form().CGI::end_html();

You can also download.