<%once> use utils; <%perl> our(%session,$dbh); $lang = $m->comp('/bits/decidelanguage', lang => $lang); $pagename = $page; % if(!(defined($content) && defined($lang) && defined($version))) { % # print out the editing page % if(defined($session{'username'})) { <%perl> # request the latest, greatest and most appropriate version of the page: my $langarray = $dbh->selectall_arrayref("SELECT * FROM languages WHERE tag = ?", { }, $lang); my $langid = $langarray->[0]->[0]; my $pagequery = $dbh->prepare("SELECT p.version, p.content, p.compressed FROM pages p WHERE p.langId = ? AND p.pagename = ? AND p.latest = 'true'"); $pagequery->execute($langid,$page); my $result = $pagequery->fetchrow_hashref();
Editing <% $page %> <% $langarray->[0]->[4] %>

The Wiki text you enter is rendered by a jbovlaste-modified version of John Cowan's Wiki.pm. In addition to supporting linking to jbovlaste definitions, it also handles tables, and can deal with inline LaTeX.

See the Wiki text help page for more information on the formatting commands available to you.

% } else { Cannot edit <% $page %>

Sorry, but you'll have to log in before I can let you edit this page.

There ought to be a link to the login page down in the very bottom right hand corner of this page.

% } % } else { % # process an editing submission Saving <% $page %>
<%perl> $dbh->begin_work; $dbh->do("LOCK TABLE pages IN EXCLUSIVE MODE"); my $langref = $dbh->selectall_arrayref("SELECT * FROM languages WHERE tag = ?", { }, $lang); my $langid = $langref->[0]->[0]; if(!defined($langid) || $langid<=0) { $m->out("You tried to submit a page for a non-existant language. You ought not encounter this error in practice, unless you were trying to be tricky and evil."); return; } my $resultref = $dbh->selectall_arrayref("SELECT * FROM pages p WHERE p.pagename = ? AND p.version >= ? AND p.langId = ?", { }, $page, $version, $langid); % if($#{$resultref}>=0) { % # new version(s) have been submitted to the database already, we're out % # of date, so disallow submission. Whoa there, there is already a version newer than the one you've submitted. So I'm going to have to reject your submission, sorry. Go back to the edit page and try again. (A little quicker this time! :) % } else { <%perl> $content =~ s/\r//g; my $insertpage = $dbh->prepare("INSERT INTO pages ". "(pagename, version, time, userId, langId, content) ". "VALUES (?,?,?,?,?,?)"); my @insertargs = ($page, $version, time(), $session{'userid'}, $langid, $content); % if(!$insertpage->execute(@insertargs)) {
<% join(", ",@insertargs) %>

Uhoh. There has been an internal error with the database. I'm rolling back the transaction and trying to log an error. Please report this to the admins.

% } else { % $dbh->commit;

I'm pretty sure I saved the page, woohoo!

Return to ">the page.

% } % } % $dbh->rollback; % } <%shared> our $pagename; <%method title> Wiki: Editing: <% $pagename %> <%args> $page $lang $version => undef $content => undef