-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
55 lines (52 loc) · 2.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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