-
Notifications
You must be signed in to change notification settings - Fork 0
aitap/nanowiki
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Assertions: - SQLite fts4 extension is used with its docid column as primary key sqlite_create_function is used for search ranking Config options: - get_captcha: subroutine which should return an array of 2 items: - string containing HTML representation of your CAPTCHA challenge - string containing the actual answer to your challenge - check_captcha: subroutine accepting 2 arguments - original answer - what user has entered should return true if the answer is right, false otherwise - preprocess_src: subroutine which accepts the source of wiki article, prior to any (wikilink or textile) processing. Should return the processed source of wiki article. - password: if defined, both read and write access to the wiki would require entering this password first (captcha is disabled) Example preprocess_src: uses "mimetex" program to generate inline images of LaTeX formulae "preprocess_src" => sub { use MIME::Base64 "encode_base64"; my $src = shift; $src =~ s{ (?<!\\) # negative look-behind to make sure start is not escaped # group 1, match dollar signs only # single or double dollar sign enforced by look-arounds ((?<!\$)\${1,2}(?!\$)) (.*?(?R)?.*?) # non-greedy; XXX: it's recursive (?<!\\) # negative look-behind to make sure end is not escaped (?(1)(?<!\$)\1(?!\$)) # if group 1 was start, match \1 }{ my $big = $1 eq '$$'; open my $mt, "-|:raw", "mimetex", "-d", "-o", "-s", ($big ? 5 : 3), $2 or die "mimetex: $!"; my $gif = do {local $/; <$mt>}; my $img = qq{<img src="data:image/gif;base64,}.encode_base64($gif).qq{">}; $big ? qq{<p><center>$img</center></p>} : $img; }exg; return $src; } Example get_captcha: uses ImageMagick to generate an image-captcha (for users without sufficient fonts to use default one, e.g. mobile): "get_captcha" => sub { use Mojo::Util 'b64_encode'; my @operands = qw(- + / *); my $challenge = int rand 20; $challenge .= " ".$operands[int rand @operands]." ".(int(rand 20)+1) for 1..2; my $answer = eval $challenge; # string eval! shock, horrors! $challenge = do { open my $fh, "-|:raw", "convert", "label:$challenge", "+noise", "Gaussian", "-quality", "20", "jpg:-" or die "mimetex: $!"; local $/; '<img src="data:image/jpeg;base64,'.b64_encode(<$fh>).'">'; }; return ($challenge, $answer); } # default check_captcha still works
About
Lightweight wiki with tree page structure and full text search in Mojolicious and SQLite
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published