9 use URI::Escape q{uri_escape_utf8};
12 use open qw{:utf8 :std};
14 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
15 %pagestate %wikistate %renderedfiles %oldrenderedfiles
16 %pagesources %destsources %depends %depends_simple %hooks
17 %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks};
19 use Exporter q{import};
20 our @EXPORT = qw(hook debug error template htmlpage deptype
21 add_depends pagespec_match pagespec_match_list bestlink
22 htmllink readfile writefile pagetype srcfile pagename
23 displaytime will_render gettext ngettext urlto targetpage
24 add_underlay pagetitle titlepage linkpage newpagefile
26 %config %links %pagestate %wikistate %renderedfiles
27 %pagesources %destsources %typedlinks);
28 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
29 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
30 our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
32 # Page dependency types.
33 our $DEPEND_CONTENT=1;
34 our $DEPEND_PRESENCE=2;
40 memoize("sortspec_translate");
41 memoize("pagespec_translate");
42 memoize("template_file");
48 description => "name of the wiki",
55 example => 'me@example.com',
56 description => "contact email for wiki",
63 description => "users who are wiki admins",
70 description => "users who are banned from the wiki",
77 example => "$ENV{HOME}/wiki",
78 description => "where the source of the wiki is located",
85 example => "/var/www/wiki",
86 description => "where to build the wiki",
93 example => "http://example.com/wiki",
94 description => "base url to the wiki",
101 example => "http://example.com/wiki/ikiwiki.cgi",
102 description => "url to the ikiwiki.cgi",
109 example => "/var/www/wiki/ikiwiki.cgi",
110 description => "filename of cgi wrapper to generate",
117 description => "mode for cgi_wrapper (can safely be made suid)",
124 description => "rcs backend to use",
125 safe => 0, # don't allow overriding
130 default => [qw{mdwn link inline meta htmlscrubber passwordauth
131 openid signinedit lockedit conditional
132 recentchanges parentlinks editpage}],
133 description => "plugins to enable by default",
140 description => "plugins to add to the default configuration",
147 description => "plugins to disable",
153 default => "$installdir/share/ikiwiki/templates",
154 description => "location of template files",
162 description => "additional directories containing template files",
168 default => "$installdir/share/ikiwiki/basewiki",
169 description => "base wiki source location",
176 default => "$installdir/share/ikiwiki",
177 description => "parent directory containing additional underlays",
184 description => "wrappers to generate",
191 description => "additional underlays to use",
198 description => "display verbose messages?",
205 description => "log to syslog?",
212 description => "create output files named page/index.html?",
213 safe => 0, # changing requires manual transition
216 prefix_directives => {
219 description => "use '!'-prefixed preprocessor directives?",
220 safe => 0, # changing requires manual transition
226 description => "use page/index.mdwn source files",
233 description => "enable Discussion pages?",
239 default => gettext("Discussion"),
240 description => "name of Discussion pages",
247 description => "only send cookies over SSL connections?",
255 description => "extension to use for new pages",
256 safe => 0, # not sanitized
262 description => "extension to use for html files",
263 safe => 0, # not sanitized
269 description => "strftime format string to display date",
277 example => "en_US.UTF-8",
278 description => "UTF-8 locale to use",
287 description => "put user pages below specified page",
294 description => "how many backlinks to show before hiding excess (0 to show all)",
301 description => "attempt to hardlink source files? (optimisation for large files)",
303 safe => 0, # paranoia
309 description => "force ikiwiki to use a particular umask",
311 safe => 0, # paranoia
316 example => "ikiwiki",
317 description => "group for wrappers to run in",
319 safe => 0, # paranoia
325 example => "$ENV{HOME}/.ikiwiki/",
326 description => "extra library and plugin directory",
328 safe => 0, # directory
334 description => "environment variables",
335 safe => 0, # paranoia
341 example => '^\.htaccess$',
342 description => "regexp of normally excluded files to include",
350 example => '^(*\.private|Makefile)$',
351 description => "regexp of files that should be skipped",
356 wiki_file_prune_regexps => {
358 default => [qr/(^|\/)\.\.(\/|$)/, qr/^\//, qr/^\./, qr/\/\./,
359 qr/\.x?html?$/, qr/\.ikiwiki-new$/,
360 qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
361 qr/(^|\/)_MTN\//, qr/(^|\/)_darcs\//,
362 qr/(^|\/)CVS\//, qr/\.dpkg-tmp$/],
363 description => "regexps of source files to ignore",
369 description => "specifies the characters that are allowed in source filenames",
370 default => "-[:alnum:]+/.:_",
374 wiki_file_regexp => {
376 description => "regexp of legal source files",
380 web_commit_regexp => {
382 default => qr/^web commit (by (.*?(?=: |$))|from ([0-9a-fA-F:.]+[0-9a-fA-F])):?(.*)/,
383 description => "regexp to parse web commits from logs",
390 description => "run as a cgi",
394 cgi_disable_uploads => {
397 description => "whether CGI should accept file uploads",
404 description => "run as a post-commit hook",
411 description => "running in rebuild mode",
418 description => "running in setup mode",
425 description => "running in clean mode",
432 description => "running in refresh mode",
439 description => "running in receive test mode",
445 description => "running in gettime mode",
452 description => "running in w3mmode",
459 description => "path to the .ikiwiki directory holding ikiwiki state",
466 description => "path to setup file",
472 default => "Standard",
473 description => "perl class to use to dump setup file",
477 allow_symlinks_before_srcdir => {
480 description => "allow symlinks in the path leading to the srcdir (potentially insecure)",
486 sub defaultconfig () {
489 foreach my $key (keys %s) {
490 push @ret, $key, $s{$key}->{default};
497 # locale stuff; avoid LC_ALL since it overrides everything
498 if (defined $ENV{LC_ALL}) {
499 $ENV{LANG} = $ENV{LC_ALL};
502 if (defined $config{locale}) {
503 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
504 $ENV{LANG}=$config{locale};
509 if (! defined $config{wiki_file_regexp}) {
510 $config{wiki_file_regexp}=qr/(^[$config{wiki_file_chars}]+$)/;
513 if (ref $config{ENV} eq 'HASH') {
514 foreach my $val (keys %{$config{ENV}}) {
515 $ENV{$val}=$config{ENV}{$val};
519 if ($config{w3mmode}) {
520 eval q{use Cwd q{abs_path}};
522 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
523 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
524 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
525 unless $config{cgiurl} =~ m!file:///!;
526 $config{url}="file://".$config{destdir};
529 if ($config{cgi} && ! length $config{url}) {
530 error(gettext("Must specify url to wiki with --url when using --cgi"));
533 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
534 unless exists $config{wikistatedir} && defined $config{wikistatedir};
536 if (defined $config{umask}) {
537 umask(possibly_foolish_untaint($config{umask}));
540 run_hooks(checkconfig => sub { shift->() });
548 foreach my $dir (@INC, $config{libdir}) {
549 next unless defined $dir && length $dir;
550 foreach my $file (glob("$dir/IkiWiki/Plugin/*.pm")) {
551 my ($plugin)=$file=~/.*\/(.*)\.pm$/;
555 foreach my $dir ($config{libdir}, "$installdir/lib/ikiwiki") {
556 next unless defined $dir && length $dir;
557 foreach my $file (glob("$dir/plugins/*")) {
558 $ret{basename($file)}=1 if -x $file;
566 if (defined $config{libdir} && length $config{libdir}) {
567 unshift @INC, possibly_foolish_untaint($config{libdir});
570 foreach my $plugin (@{$config{default_plugins}}, @{$config{add_plugins}}) {
575 if (exists $hooks{rcs}) {
576 error(gettext("cannot use multiple rcs plugins"));
578 loadplugin($config{rcs});
580 if (! exists $hooks{rcs}) {
584 run_hooks(getopt => sub { shift->() });
585 if (grep /^-/, @ARGV) {
586 print STDERR "Unknown option (or missing parameter): $_\n"
587 foreach grep /^-/, @ARGV;
597 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
599 foreach my $dir (defined $config{libdir} ? possibly_foolish_untaint($config{libdir}) : undef,
600 "$installdir/lib/ikiwiki") {
601 if (defined $dir && -x "$dir/plugins/$plugin") {
602 eval { require IkiWiki::Plugin::external };
605 error(sprintf(gettext("failed to load external plugin needed for %s plugin: %s"), $plugin, $reason));
607 import IkiWiki::Plugin::external "$dir/plugins/$plugin";
608 $loaded_plugins{$plugin}=1;
613 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
616 error("Failed to load plugin $mod: $@");
618 $loaded_plugins{$plugin}=1;
625 log_message('err' => $message) if $config{syslog};
626 if (defined $cleaner) {
633 return unless $config{verbose};
634 return log_message(debug => @_);
638 sub log_message ($$) {
641 if ($config{syslog}) {
644 Sys::Syslog::setlogsock('unix');
645 Sys::Syslog::openlog('ikiwiki', '', 'user');
649 Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
652 elsif (! $config{cgi}) {
656 return print STDERR "@_\n";
660 sub possibly_foolish_untaint ($) {
662 my ($untainted)=$tainted=~/(.*)/s;
682 return exists $pagesources{$page} &&
683 $pagesources{$page} =~ /\._([^.]+)$/;
689 if ($file =~ /\.([^.]+)$/) {
690 return $1 if exists $hooks{htmlize}{$1};
692 my $base=basename($file);
693 if (exists $hooks{htmlize}{$base} &&
694 $hooks{htmlize}{$base}{noextension}) {
705 if (exists $pagename_cache{$file}) {
706 return $pagename_cache{$file};
709 my $type=pagetype($file);
711 $page=~s/\Q.$type\E*$//
712 if defined $type && !$hooks{htmlize}{$type}{keepextension}
713 && !$hooks{htmlize}{$type}{noextension};
714 if ($config{indexpages} && $page=~/(.*)\/index$/) {
718 $pagename_cache{$file} = $page;
722 sub newpagefile ($$) {
726 if (! $config{indexpages} || $page eq 'index') {
727 return $page.".".$type;
730 return $page."/index.".$type;
734 sub targetpage ($$;$) {
739 if (defined $filename) {
740 return $page."/".$filename.".".$ext;
742 elsif (! $config{usedirs} || $page eq 'index') {
743 return $page.".".$ext;
746 return $page."/index.".$ext;
753 return targetpage($page, $config{htmlext});
760 return "$config{srcdir}/$file", stat(_) if -e "$config{srcdir}/$file";
761 foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
762 return "$dir/$file", stat(_) if -e "$dir/$file";
764 error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow;
769 return (srcfile_stat(@_))[0];
772 sub add_underlay ($) {
776 $dir="$config{underlaydirbase}/$dir";
779 if (! grep { $_ eq $dir } @{$config{underlaydirs}}) {
780 unshift @{$config{underlaydirs}}, $dir;
786 sub readfile ($;$$) {
792 error("cannot read a symlink ($file)");
796 open (my $in, "<", $file) || error("failed to read $file: $!");
797 binmode($in) if ($binary);
798 return \*$in if $wantfd;
800 # check for invalid utf-8, and toss it back to avoid crashes
801 if (! utf8::valid($ret)) {
802 $ret=encode_utf8($ret);
804 close $in || error("failed to read $file: $!");
808 sub prep_writefile ($$) {
813 while (length $test) {
814 if (-l "$destdir/$test") {
815 error("cannot write to a symlink ($test)");
817 $test=dirname($test);
820 my $dir=dirname("$destdir/$file");
823 foreach my $s (split(m!/+!, $dir)) {
826 mkdir($d) || error("failed to create directory $d: $!");
834 sub writefile ($$$;$$) {
835 my $file=shift; # can include subdirs
836 my $destdir=shift; # directory to put file in
841 prep_writefile($file, $destdir);
843 my $newfile="$destdir/$file.ikiwiki-new";
845 error("cannot write to a symlink ($newfile)");
848 my $cleanup = sub { unlink($newfile) };
849 open (my $out, '>', $newfile) || error("failed to write $newfile: $!", $cleanup);
850 binmode($out) if ($binary);
852 $writer->(\*$out, $cleanup);
855 print $out $content or error("failed writing to $newfile: $!", $cleanup);
857 close $out || error("failed saving $newfile: $!", $cleanup);
858 rename($newfile, "$destdir/$file") ||
859 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
865 sub will_render ($$;$) {
870 # Important security check.
871 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
872 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}}, @{$wikistate{editpage}{previews}})) {
873 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
876 if (! $clear || $cleared{$page}) {
877 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
880 foreach my $old (@{$renderedfiles{$page}}) {
881 delete $destsources{$old};
883 $renderedfiles{$page}=[$dest];
886 $destsources{$dest}=$page;
896 if ($link=~s/^\/+//) {
904 $l.="/" if length $l;
907 if (exists $pagesources{$l}) {
910 elsif (exists $pagecase{lc $l}) {
911 return $pagecase{lc $l};
913 } while $cwd=~s{/?[^/]+$}{};
915 if (length $config{userdir}) {
916 my $l = "$config{userdir}/".lc($link);
917 if (exists $pagesources{$l}) {
920 elsif (exists $pagecase{lc $l}) {
921 return $pagecase{lc $l};
925 #print STDERR "warning: page $page, broken link: $link\n";
929 sub isinlinableimage ($) {
932 return $file =~ /\.(png|gif|jpg|jpeg)$/i;
935 sub pagetitle ($;$) {
940 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
943 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
951 # support use w/o %config set
952 my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_";
953 $title=~s/([^$chars]|_)/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
959 my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_";
960 $link=~s/([^$chars])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
967 my $cgiurl=$config{cgiurl};
968 if (exists $params{cgiurl}) {
969 $cgiurl=$params{cgiurl};
970 delete $params{cgiurl};
973 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
979 return "$config{url}/" if ! defined $page;
981 $page=htmlpage($page);
983 $page=~s/[^\/]+\//..\//g;
988 # Work around very innefficient behavior in File::Spec if abs2rel
989 # is passed two relative paths. It's much faster if paths are
990 # absolute! (Debian bug #376658; fixed in debian unstable now)
995 my $ret=File::Spec->abs2rel($path, $base);
996 $ret=~s/^// if defined $ret;
1000 sub displaytime ($;$) {
1001 # Plugins can override this function to mark up the time to
1003 return '<span class="date">'.formattime(@_).'</span>';
1006 sub formattime ($;$) {
1007 # Plugins can override this function to format the time.
1010 if (! defined $format) {
1011 $format=$config{timeformat};
1014 # strftime doesn't know about encodings, so make sure
1015 # its output is properly treated as utf8
1016 return decode_utf8(POSIX::strftime($format, localtime($time)));
1019 sub beautify_urlpath ($) {
1022 # Ensure url is not an empty link, and if necessary,
1023 # add ./ to avoid colon confusion.
1024 if ($url !~ /^\// && $url !~ /^\.\.?\//) {
1028 if ($config{usedirs}) {
1029 $url =~ s!/index.$config{htmlext}$!/!;
1041 return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
1044 if (! $destsources{$to}) {
1049 return $config{url}.beautify_urlpath("/".$to);
1052 my $link = abs2rel($to, dirname(htmlpage($from)));
1054 return beautify_urlpath($link);
1057 sub htmllink ($$$;@) {
1058 my $lpage=shift; # the page doing the linking
1059 my $page=shift; # the page that will contain the link (different for inline)
1066 if (! $opts{forcesubpage}) {
1067 $bestlink=bestlink($lpage, $link);
1070 $bestlink="$lpage/".lc($link);
1074 if (defined $opts{linktext}) {
1075 $linktext=$opts{linktext};
1078 $linktext=pagetitle(basename($link));
1081 return "<span class=\"selflink\">$linktext</span>"
1082 if length $bestlink && $page eq $bestlink &&
1083 ! defined $opts{anchor};
1085 if (! $destsources{$bestlink}) {
1086 $bestlink=htmlpage($bestlink);
1088 if (! $destsources{$bestlink}) {
1089 return $linktext unless length $config{cgiurl};
1090 return "<span class=\"createlink\"><a href=\"".
1096 "\" rel=\"nofollow\">?</a>$linktext</span>"
1100 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
1101 $bestlink=beautify_urlpath($bestlink);
1103 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
1104 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
1107 if (defined $opts{anchor}) {
1108 $bestlink.="#".$opts{anchor};
1112 foreach my $attr (qw{rel class title}) {
1113 if (defined $opts{$attr}) {
1114 push @attrs, " $attr=\"$opts{$attr}\"";
1118 return "<a href=\"$bestlink\"@attrs>$linktext</a>";
1123 return length $config{userdir} ? "$config{userdir}/$user" : $user;
1126 sub openiduser ($) {
1129 if ($user =~ m!^https?://! &&
1130 eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
1133 if (Net::OpenID::VerifiedIdentity->can("DisplayOfURL")) {
1134 $display = Net::OpenID::VerifiedIdentity::DisplayOfURL($user);
1137 # backcompat with old version
1138 my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
1139 $display=$oid->display;
1142 # Convert "user.somehost.com" to "user [somehost.com]"
1143 # (also "user.somehost.co.uk")
1144 if ($display !~ /\[/) {
1145 $display=~s/^([-a-zA-Z0-9]+?)\.([-.a-zA-Z0-9]+\.[a-z]+)$/$1 [$2]/;
1147 # Convert "http://somehost.com/user" to "user [somehost.com]".
1148 # (also "https://somehost.com/user/")
1149 if ($display !~ /\[/) {
1150 $display=~s/^https?:\/\/(.+)\/([^\/#?]+)\/?(?:[#?].*)?$/$2 [$1]/;
1152 $display=~s!^https?://!!; # make sure this is removed
1153 eval q{use CGI 'escapeHTML'};
1155 return escapeHTML($display);
1160 sub htmlize ($$$$) {
1166 my $oneline = $content !~ /\n/;
1168 if (exists $hooks{htmlize}{$type}) {
1169 $content=$hooks{htmlize}{$type}{call}->(
1171 content => $content,
1175 error("htmlization of $type not supported");
1178 run_hooks(sanitize => sub {
1181 destpage => $destpage,
1182 content => $content,
1187 # hack to get rid of enclosing junk added by markdown
1188 # and other htmlizers/sanitizers
1189 $content=~s/^<p>//i;
1190 $content=~s/<\/p>\n*$//i;
1201 run_hooks(linkify => sub {
1204 destpage => $destpage,
1205 content => $content,
1213 our $preprocess_preview=0;
1214 sub preprocess ($$$;$$) {
1215 my $page=shift; # the page the data comes from
1216 my $destpage=shift; # the page the data will appear in (different for inline)
1221 # Using local because it needs to be set within any nested calls
1223 local $preprocess_preview=$preview if defined $preview;
1230 $params="" if ! defined $params;
1232 if (length $escape) {
1233 return "[[$prefix$command $params]]";
1235 elsif (exists $hooks{preprocess}{$command}) {
1236 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
1237 # Note: preserve order of params, some plugins may
1238 # consider it significant.
1240 while ($params =~ m{
1241 (?:([-\w]+)=)? # 1: named parameter key?
1243 """(.*?)""" # 2: triple-quoted value
1245 "([^"]*?)" # 3: single-quoted value
1247 (\S+) # 4: unquoted value
1249 (?:\s+|$) # delimiter to next param
1259 elsif (defined $3) {
1262 elsif (defined $4) {
1267 push @params, $key, $val;
1270 push @params, $val, '';
1273 if ($preprocessing{$page}++ > 3) {
1274 # Avoid loops of preprocessed pages preprocessing
1275 # other pages that preprocess them, etc.
1276 return "[[!$command <span class=\"error\">".
1277 sprintf(gettext("preprocessing loop detected on %s at depth %i"),
1278 $page, $preprocessing{$page}).
1284 $hooks{preprocess}{$command}{call}->(
1287 destpage => $destpage,
1288 preview => $preprocess_preview,
1294 $ret="[[!$command <span class=\"error\">".
1295 gettext("Error").": $error"."</span>]]";
1299 # use void context during scan pass
1301 $hooks{preprocess}{$command}{call}->(
1304 destpage => $destpage,
1305 preview => $preprocess_preview,
1310 $preprocessing{$page}--;
1314 return "[[$prefix$command $params]]";
1319 if ($config{prefix_directives}) {
1322 \[\[(!) # directive open; 2: prefix
1323 ([-\w]+) # 3: command
1324 ( # 4: the parameters..
1325 \s+ # Must have space if parameters present
1327 (?:[-\w]+=)? # named parameter key?
1329 """.*?""" # triple-quoted value
1331 "[^"]*?" # single-quoted value
1333 [^"\s\]]+ # unquoted value
1335 \s* # whitespace or end
1338 *)? # 0 or more parameters
1339 \]\] # directive closed
1345 \[\[(!?) # directive open; 2: optional prefix
1346 ([-\w]+) # 3: command
1348 ( # 4: the parameters..
1350 (?:[-\w]+=)? # named parameter key?
1352 """.*?""" # triple-quoted value
1354 "[^"]*?" # single-quoted value
1356 [^"\s\]]+ # unquoted value
1358 \s* # whitespace or end
1361 *) # 0 or more parameters
1362 \]\] # directive closed
1366 $content =~ s{$regex}{$handle->($1, $2, $3, $4)}eg;
1375 run_hooks(filter => sub {
1376 $content=shift->(page => $page, destpage => $destpage,
1377 content => $content);
1384 return "<a href=\"$config{url}\">$config{wikiname}</a>";
1387 sub check_canedit ($$$;$) {
1394 run_hooks(canedit => sub {
1395 return if defined $canedit;
1396 my $ret=shift->($page, $q, $session);
1401 elsif (ref $ret eq 'CODE') {
1402 $ret->() unless $nonfatal;
1405 elsif (defined $ret) {
1406 error($ret) unless $nonfatal;
1411 return defined $canedit ? $canedit : 1;
1414 sub check_content (@) {
1417 return 1 if ! exists $hooks{checkcontent}; # optimisation
1419 if (exists $pagesources{$params{page}}) {
1421 my %old=map { $_ => 1 }
1422 split("\n", readfile(srcfile($pagesources{$params{page}})));
1423 foreach my $line (split("\n", $params{content})) {
1424 push @diff, $line if ! exists $old{$line};
1426 $params{diff}=join("\n", @diff);
1430 run_hooks(checkcontent => sub {
1431 return if defined $ok;
1432 my $ret=shift->(%params);
1437 elsif (ref $ret eq 'CODE') {
1438 $ret->() unless $params{nonfatal};
1441 elsif (defined $ret) {
1442 error($ret) unless $params{nonfatal};
1448 return defined $ok ? $ok : 1;
1454 # Take an exclusive lock on the wiki to prevent multiple concurrent
1455 # run issues. The lock will be dropped on program exit.
1456 if (! -d $config{wikistatedir}) {
1457 mkdir($config{wikistatedir});
1459 open($wikilock, '>', "$config{wikistatedir}/lockfile") ||
1460 error ("cannot write to $config{wikistatedir}/lockfile: $!");
1461 if (! flock($wikilock, 2)) { # LOCK_EX
1462 error("failed to get lock");
1468 POSIX::close($ENV{IKIWIKI_CGILOCK_FD}) if exists $ENV{IKIWIKI_CGILOCK_FD};
1469 return close($wikilock) if $wikilock;
1475 sub commit_hook_enabled () {
1476 open($commitlock, '+>', "$config{wikistatedir}/commitlock") ||
1477 error("cannot write to $config{wikistatedir}/commitlock: $!");
1478 if (! flock($commitlock, 1 | 4)) { # LOCK_SH | LOCK_NB to test
1479 close($commitlock) || error("failed closing commitlock: $!");
1482 close($commitlock) || error("failed closing commitlock: $!");
1486 sub disable_commit_hook () {
1487 open($commitlock, '>', "$config{wikistatedir}/commitlock") ||
1488 error("cannot write to $config{wikistatedir}/commitlock: $!");
1489 if (! flock($commitlock, 2)) { # LOCK_EX
1490 error("failed to get commit lock");
1495 sub enable_commit_hook () {
1496 return close($commitlock) if $commitlock;
1501 %oldrenderedfiles=%pagectime=();
1502 if (! $config{rebuild}) {
1503 %pagesources=%pagemtime=%oldlinks=%links=%depends=
1504 %destsources=%renderedfiles=%pagecase=%pagestate=
1505 %depends_simple=%typedlinks=%oldtypedlinks=();
1508 if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
1509 if (-e "$config{wikistatedir}/index") {
1510 system("ikiwiki-transition", "indexdb", $config{srcdir});
1511 open ($in, "<", "$config{wikistatedir}/indexdb") || return;
1514 $config{gettime}=1; # first build
1519 my $index=Storable::fd_retrieve($in);
1520 if (! defined $index) {
1525 if (exists $index->{version} && ! ref $index->{version}) {
1526 $pages=$index->{page};
1527 %wikistate=%{$index->{state}};
1534 foreach my $src (keys %$pages) {
1535 my $d=$pages->{$src};
1536 my $page=pagename($src);
1537 $pagectime{$page}=$d->{ctime};
1538 if (! $config{rebuild}) {
1539 $pagesources{$page}=$src;
1540 $pagemtime{$page}=$d->{mtime};
1541 $renderedfiles{$page}=$d->{dest};
1542 if (exists $d->{links} && ref $d->{links}) {
1543 $links{$page}=$d->{links};
1544 $oldlinks{$page}=[@{$d->{links}}];
1546 if (ref $d->{depends_simple} eq 'ARRAY') {
1548 $depends_simple{$page}={
1549 map { $_ => 1 } @{$d->{depends_simple}}
1552 elsif (exists $d->{depends_simple}) {
1553 $depends_simple{$page}=$d->{depends_simple};
1555 if (exists $d->{dependslist}) {
1558 map { $_ => $DEPEND_CONTENT }
1559 @{$d->{dependslist}}
1562 elsif (exists $d->{depends} && ! ref $d->{depends}) {
1564 $depends{$page}={$d->{depends} => $DEPEND_CONTENT };
1566 elsif (exists $d->{depends}) {
1567 $depends{$page}=$d->{depends};
1569 if (exists $d->{state}) {
1570 $pagestate{$page}=$d->{state};
1572 if (exists $d->{typedlinks}) {
1573 $typedlinks{$page}=$d->{typedlinks};
1575 while (my ($type, $links) = each %{$typedlinks{$page}}) {
1576 next unless %$links;
1577 $oldtypedlinks{$page}{$type} = {%$links};
1581 $oldrenderedfiles{$page}=[@{$d->{dest}}];
1583 foreach my $page (keys %pagesources) {
1584 $pagecase{lc $page}=$page;
1586 foreach my $page (keys %renderedfiles) {
1587 $destsources{$_}=$page foreach @{$renderedfiles{$page}};
1593 run_hooks(savestate => sub { shift->() });
1596 foreach my $type (keys %hooks) {
1597 $hookids{$_}=1 foreach keys %{$hooks{$type}};
1599 my @hookids=keys %hookids;
1601 if (! -d $config{wikistatedir}) {
1602 mkdir($config{wikistatedir});
1604 my $newfile="$config{wikistatedir}/indexdb.new";
1605 my $cleanup = sub { unlink($newfile) };
1606 open (my $out, '>', $newfile) || error("cannot write to $newfile: $!", $cleanup);
1609 foreach my $page (keys %pagemtime) {
1610 next unless $pagemtime{$page};
1611 my $src=$pagesources{$page};
1613 $index{page}{$src}={
1614 ctime => $pagectime{$page},
1615 mtime => $pagemtime{$page},
1616 dest => $renderedfiles{$page},
1617 links => $links{$page},
1620 if (exists $depends{$page}) {
1621 $index{page}{$src}{depends} = $depends{$page};
1624 if (exists $depends_simple{$page}) {
1625 $index{page}{$src}{depends_simple} = $depends_simple{$page};
1628 if (exists $typedlinks{$page} && %{$typedlinks{$page}}) {
1629 $index{page}{$src}{typedlinks} = $typedlinks{$page};
1632 if (exists $pagestate{$page}) {
1633 foreach my $id (@hookids) {
1634 foreach my $key (keys %{$pagestate{$page}{$id}}) {
1635 $index{page}{$src}{state}{$id}{$key}=$pagestate{$page}{$id}{$key};
1642 foreach my $id (@hookids) {
1643 foreach my $key (keys %{$wikistate{$id}}) {
1644 $index{state}{$id}{$key}=$wikistate{$id}{$key};
1648 $index{version}="3";
1649 my $ret=Storable::nstore_fd(\%index, $out);
1650 return if ! defined $ret || ! $ret;
1651 close $out || error("failed saving to $newfile: $!", $cleanup);
1652 rename($newfile, "$config{wikistatedir}/indexdb") ||
1653 error("failed renaming $newfile to $config{wikistatedir}/indexdb", $cleanup);
1658 sub template_file ($) {
1661 foreach my $dir ($config{templatedir}, @{$config{templatedirs}},
1662 "$installdir/share/ikiwiki/templates") {
1663 return "$dir/$template" if -e "$dir/$template";
1668 sub template_params (@) {
1669 my $filename=template_file(shift);
1671 if (! defined $filename) {
1672 return if wantarray;
1678 my $text_ref = shift;
1679 ${$text_ref} = decode_utf8(${$text_ref});
1681 filename => $filename,
1682 loop_context_vars => 1,
1683 die_on_bad_params => 0,
1686 return wantarray ? @ret : {@ret};
1689 sub template ($;@) {
1690 require HTML::Template;
1691 return HTML::Template->new(template_params(@_));
1694 sub misctemplate ($$;@) {
1698 my $template=template("misc.tmpl");
1701 indexlink => indexlink(),
1702 wikiname => $config{wikiname},
1703 pagebody => $pagebody,
1704 baseurl => baseurl(),
1707 run_hooks(pagetemplate => sub {
1708 shift->(page => "", destpage => "", template => $template);
1710 return $template->output;
1716 if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
1717 error 'hook requires type, call, and id parameters';
1720 return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
1722 $hooks{$param{type}}{$param{id}}=\%param;
1726 sub run_hooks ($$) {
1727 # Calls the given sub for each hook of the given type,
1728 # passing it the hook function to call.
1732 if (exists $hooks{$type}) {
1733 my (@first, @middle, @last);
1734 foreach my $id (keys %{$hooks{$type}}) {
1735 if ($hooks{$type}{$id}{first}) {
1738 elsif ($hooks{$type}{$id}{last}) {
1745 foreach my $id (@first, @middle, @last) {
1746 $sub->($hooks{$type}{$id}{call});
1754 $hooks{rcs}{rcs_update}{call}->(@_);
1757 sub rcs_prepedit ($) {
1758 $hooks{rcs}{rcs_prepedit}{call}->(@_);
1761 sub rcs_commit ($$$;$$) {
1762 $hooks{rcs}{rcs_commit}{call}->(@_);
1765 sub rcs_commit_staged ($$$) {
1766 $hooks{rcs}{rcs_commit_staged}{call}->(@_);
1770 $hooks{rcs}{rcs_add}{call}->(@_);
1773 sub rcs_remove ($) {
1774 $hooks{rcs}{rcs_remove}{call}->(@_);
1777 sub rcs_rename ($$) {
1778 $hooks{rcs}{rcs_rename}{call}->(@_);
1781 sub rcs_recentchanges ($) {
1782 $hooks{rcs}{rcs_recentchanges}{call}->(@_);
1786 $hooks{rcs}{rcs_diff}{call}->(@_);
1789 sub rcs_getctime ($) {
1790 $hooks{rcs}{rcs_getctime}{call}->(@_);
1793 sub rcs_getmtime ($) {
1794 $hooks{rcs}{rcs_getmtime}{call}->(@_);
1797 sub rcs_receive () {
1798 $hooks{rcs}{rcs_receive}{call}->();
1801 sub add_depends ($$;$) {
1804 my $deptype=shift || $DEPEND_CONTENT;
1806 # Is the pagespec a simple page name?
1807 if ($pagespec =~ /$config{wiki_file_regexp}/ &&
1808 $pagespec !~ /[\s*?()!]/) {
1809 $depends_simple{$page}{lc $pagespec} |= $deptype;
1813 # Add explicit dependencies for influences.
1814 my $sub=pagespec_translate($pagespec);
1815 return unless defined $sub;
1816 foreach my $p (keys %pagesources) {
1817 my $r=$sub->($p, location => $page);
1818 my $i=$r->influences;
1819 foreach my $k (keys %$i) {
1820 $depends_simple{$page}{lc $k} |= $i->{$k};
1822 last if $r->influences_static;
1825 $depends{$page}{$pagespec} |= $deptype;
1831 foreach my $type (@_) {
1832 if ($type eq 'presence') {
1833 $deptype |= $DEPEND_PRESENCE;
1835 elsif ($type eq 'links') {
1836 $deptype |= $DEPEND_LINKS;
1838 elsif ($type eq 'content') {
1839 $deptype |= $DEPEND_CONTENT;
1845 my $file_prune_regexp;
1846 sub file_pruned ($) {
1849 if (defined $config{include} && length $config{include}) {
1850 return 0 if $file =~ m/$config{include}/;
1853 if (! defined $file_prune_regexp) {
1854 $file_prune_regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
1855 $file_prune_regexp=qr/$file_prune_regexp/;
1857 return $file =~ m/$file_prune_regexp/;
1860 sub define_gettext () {
1861 # If translation is needed, redefine the gettext function to do it.
1862 # Otherwise, it becomes a quick no-op.
1865 if ((exists $ENV{LANG} && length $ENV{LANG}) ||
1866 (exists $ENV{LC_ALL} && length $ENV{LC_ALL}) ||
1867 (exists $ENV{LC_MESSAGES} && length $ENV{LC_MESSAGES})) {
1869 $gettext_obj=eval q{
1870 use Locale::gettext q{textdomain};
1871 Locale::gettext->domain('ikiwiki')
1876 no warnings 'redefine';
1878 $getobj->() if $getobj;
1880 $gettext_obj->get(shift);
1887 $getobj->() if $getobj;
1889 $gettext_obj->nget(@_);
1892 return ($_[2] == 1 ? $_[0] : $_[1])
1910 return (defined $val && (lc($val) eq gettext("yes") || lc($val) eq "yes" || $val eq "1"));
1914 # Injects a new function into the symbol table to replace an
1915 # exported function.
1918 # This is deep ugly perl foo, beware.
1921 if (! defined $params{parent}) {
1922 $params{parent}='::';
1923 $params{old}=\&{$params{name}};
1924 $params{name}=~s/.*:://;
1926 my $parent=$params{parent};
1927 foreach my $ns (grep /^\w+::/, keys %{$parent}) {
1928 $ns = $params{parent} . $ns;
1929 inject(%params, parent => $ns) unless $ns eq '::main::';
1930 *{$ns . $params{name}} = $params{call}
1931 if exists ${$ns}{$params{name}} &&
1932 \&{${$ns}{$params{name}}} == $params{old};
1938 sub add_link ($$;$) {
1943 push @{$links{$page}}, $link
1944 unless grep { $_ eq $link } @{$links{$page}};
1946 if (defined $type) {
1947 $typedlinks{$page}{$type}{$link} = 1;
1951 sub sortspec_translate ($$) {
1953 my $reverse = shift;
1959 (-?) # group 1: perhaps negated
1962 \w+\([^\)]*\) # command(params)
1964 [^\s]+ # or anything else
1972 if ($word =~ m/^(\w+)\((.*)\)$/) {
1973 # command with parameters
1977 elsif ($word !~ m/^\w+$/) {
1978 error(sprintf(gettext("invalid sort type %s"), $word));
1989 if (exists $IkiWiki::SortSpec::{"cmp_$word"}) {
1990 if (defined $params) {
1991 push @data, $params;
1992 $code .= "IkiWiki::SortSpec::cmp_$word(\$data[$#data])";
1995 $code .= "IkiWiki::SortSpec::cmp_$word(undef)";
1999 error(sprintf(gettext("unknown sort type %s"), $word));
2003 if (! length $code) {
2004 # undefined sorting method... sort arbitrarily
2013 return eval 'sub { '.$code.' }';
2016 sub pagespec_translate ($) {
2019 # Convert spec to perl code.
2023 \s* # ignore whitespace
2024 ( # 1: match a single word
2031 \w+\([^\)]*\) # command(params)
2033 [^\s()]+ # any other text
2035 \s* # ignore whitespace
2038 if (lc $word eq 'and') {
2041 elsif (lc $word eq 'or') {
2044 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
2047 elsif ($word =~ /^(\w+)\((.*)\)$/) {
2048 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
2050 $code.="IkiWiki::PageSpec::match_$1(\$page, \$data[$#data], \@_)";
2053 push @data, qq{unknown function in pagespec "$word"};
2054 $code.="IkiWiki::ErrorReason->new(\$data[$#data])";
2059 $code.=" IkiWiki::PageSpec::match_glob(\$page, \$data[$#data], \@_)";
2063 if (! length $code) {
2064 $code="IkiWiki::FailReason->new('empty pagespec')";
2068 return eval 'sub { my $page=shift; '.$code.' }';
2071 sub pagespec_match ($$;@) {
2076 # Backwards compatability with old calling convention.
2078 unshift @params, 'location';
2081 my $sub=pagespec_translate($spec);
2082 return IkiWiki::ErrorReason->new("syntax error in pagespec \"$spec\"")
2084 return $sub->($page, @params);
2087 sub pagespec_match_list ($$;@) {
2092 # Backwards compatability with old calling convention.
2094 print STDERR "warning: a plugin (".caller().") is using pagespec_match_list in an obsolete way, and needs to be updated\n";
2095 $params{list}=$page;
2096 $page=$params{location}; # ugh!
2099 my $sub=pagespec_translate($pagespec);
2100 error "syntax error in pagespec \"$pagespec\""
2102 my $sort=sortspec_translate($params{sort}, $params{reverse})
2103 if defined $params{sort};
2106 if (exists $params{list}) {
2107 @candidates=exists $params{filter}
2108 ? grep { ! $params{filter}->($_) } @{$params{list}}
2112 @candidates=exists $params{filter}
2113 ? grep { ! $params{filter}->($_) } keys %pagesources
2114 : keys %pagesources;
2117 # clear params, remainder is passed to pagespec
2118 $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT);
2119 my $num=$params{num};
2120 delete @params{qw{num deptype reverse sort filter list}};
2122 # when only the top matches will be returned, it's efficient to
2123 # sort before matching to pagespec,
2124 if (defined $num && defined $sort) {
2125 @candidates=IkiWiki::SortSpec::sort_pages(
2126 $sort, @candidates);
2132 my $accum=IkiWiki::SuccessReason->new();
2133 foreach my $p (@candidates) {
2134 my $r=$sub->($p, %params, location => $page);
2135 error(sprintf(gettext("cannot match pages: %s"), $r))
2136 if $r->isa("IkiWiki::ErrorReason");
2140 last if defined $num && ++$count == $num;
2144 # Add simple dependencies for accumulated influences.
2145 my $i=$accum->influences;
2146 foreach my $k (keys %$i) {
2147 $depends_simple{$page}{lc $k} |= $i->{$k};
2150 # when all matches will be returned, it's efficient to
2151 # sort after matching
2152 if (! defined $num && defined $sort) {
2153 return IkiWiki::SortSpec::sort_pages(
2161 sub pagespec_valid ($) {
2164 return defined pagespec_translate($spec);
2168 my $re=quotemeta(shift);
2174 package IkiWiki::FailReason;
2177 '""' => sub { $_[0][0] },
2179 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
2180 '&' => sub { $_[0]->merge_influences($_[1], 1); $_[0] },
2181 '|' => sub { $_[1]->merge_influences($_[0]); $_[1] },
2185 our @ISA = 'IkiWiki::SuccessReason';
2187 package IkiWiki::SuccessReason;
2190 '""' => sub { $_[0][0] },
2192 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
2193 '&' => sub { $_[1]->merge_influences($_[0], 1); $_[1] },
2194 '|' => sub { $_[0]->merge_influences($_[1]); $_[0] },
2201 return bless [$value, {@_}], $class;
2206 $this->[1]={@_} if @_;
2207 my %i=%{$this->[1]};
2212 sub influences_static {
2213 return ! $_[0][1]->{""};
2216 sub merge_influences {
2221 if (! $anded || (($this || %{$this->[1]}) &&
2222 ($other || %{$other->[1]}))) {
2223 foreach my $influence (keys %{$other->[1]}) {
2224 $this->[1]{$influence} |= $other->[1]{$influence};
2233 package IkiWiki::ErrorReason;
2235 our @ISA = 'IkiWiki::FailReason';
2237 package IkiWiki::PageSpec;
2243 if ($path =~ m!^\./!) {
2244 $from=~s#/?[^/]+$## if defined $from;
2246 $path="$from/$path" if length $from;
2252 sub match_glob ($$;@) {
2257 $glob=derel($glob, $params{location});
2259 my $regexp=IkiWiki::glob2re($glob);
2260 if ($page=~/^$regexp$/i) {
2261 if (! IkiWiki::isinternal($page) || $params{internal}) {
2262 return IkiWiki::SuccessReason->new("$glob matches $page");
2265 return IkiWiki::FailReason->new("$glob matches $page, but the page is an internal page");
2269 return IkiWiki::FailReason->new("$glob does not match $page");
2273 sub match_internal ($$;@) {
2274 return match_glob($_[0], $_[1], @_, internal => 1)
2277 sub match_link ($$;@) {
2282 $link=derel($link, $params{location});
2283 my $from=exists $params{location} ? $params{location} : '';
2284 my $linktype=$params{linktype};
2286 if (defined $linktype) {
2287 $qualifier=" with type $linktype";
2290 my $links = $IkiWiki::links{$page};
2291 return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2292 unless $links && @{$links};
2293 my $bestlink = IkiWiki::bestlink($from, $link);
2294 foreach my $p (@{$links}) {
2295 if (length $bestlink) {
2296 if ((!defined $linktype || exists $IkiWiki::typedlinks{$page}{$linktype}{$p}) && $bestlink eq IkiWiki::bestlink($page, $p)) {
2297 return IkiWiki::SuccessReason->new("$page links to $link$qualifier", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2301 if ((!defined $linktype || exists $IkiWiki::typedlinks{$page}{$linktype}{$p}) && match_glob($p, $link, %params)) {
2302 return IkiWiki::SuccessReason->new("$page links to page $p$qualifier, matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2304 my ($p_rel)=$p=~/^\/?(.*)/;
2306 if ((!defined $linktype || exists $IkiWiki::typedlinks{$page}{$linktype}{$p_rel}) && match_glob($p_rel, $link, %params)) {
2307 return IkiWiki::SuccessReason->new("$page links to page $p_rel$qualifier, matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2311 return IkiWiki::FailReason->new("$page does not link to $link$qualifier", $page => $IkiWiki::DEPEND_LINKS, "" => 1);
2314 sub match_backlink ($$;@) {
2315 my $ret=match_link($_[1], $_[0], @_);
2316 $ret->influences($_[1] => $IkiWiki::DEPEND_LINKS);
2320 sub match_created_before ($$;@) {
2325 $testpage=derel($testpage, $params{location});
2327 if (exists $IkiWiki::pagectime{$testpage}) {
2328 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
2329 return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2332 return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2336 return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
2340 sub match_created_after ($$;@) {
2345 $testpage=derel($testpage, $params{location});
2347 if (exists $IkiWiki::pagectime{$testpage}) {
2348 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
2349 return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2352 return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2356 return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
2360 sub match_creation_day ($$;@) {
2361 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
2362 return IkiWiki::SuccessReason->new('creation_day matched');
2365 return IkiWiki::FailReason->new('creation_day did not match');
2369 sub match_creation_month ($$;@) {
2370 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
2371 return IkiWiki::SuccessReason->new('creation_month matched');
2374 return IkiWiki::FailReason->new('creation_month did not match');
2378 sub match_creation_year ($$;@) {
2379 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
2380 return IkiWiki::SuccessReason->new('creation_year matched');
2383 return IkiWiki::FailReason->new('creation_year did not match');
2387 sub match_user ($$;@) {
2392 my $regexp=IkiWiki::glob2re($user);
2394 if (! exists $params{user}) {
2395 return IkiWiki::ErrorReason->new("no user specified");
2398 if (defined $params{user} && $params{user}=~/^$regexp$/i) {
2399 return IkiWiki::SuccessReason->new("user is $user");
2401 elsif (! defined $params{user}) {
2402 return IkiWiki::FailReason->new("not logged in");
2405 return IkiWiki::FailReason->new("user is $params{user}, not $user");
2409 sub match_admin ($$;@) {
2414 if (! exists $params{user}) {
2415 return IkiWiki::ErrorReason->new("no user specified");
2418 if (defined $params{user} && IkiWiki::is_admin($params{user})) {
2419 return IkiWiki::SuccessReason->new("user is an admin");
2421 elsif (! defined $params{user}) {
2422 return IkiWiki::FailReason->new("not logged in");
2425 return IkiWiki::FailReason->new("user is not an admin");
2429 sub match_ip ($$;@) {
2434 if (! exists $params{ip}) {
2435 return IkiWiki::ErrorReason->new("no IP specified");
2438 if (defined $params{ip} && lc $params{ip} eq lc $ip) {
2439 return IkiWiki::SuccessReason->new("IP is $ip");
2442 return IkiWiki::FailReason->new("IP is $params{ip}, not $ip");
2446 package IkiWiki::SortSpec;
2448 # This is in the SortSpec namespace so that the $a and $b that sort() uses
2449 # are easily available in this namespace, for cmp functions to use them.
2456 IkiWiki::pagetitle(IkiWiki::basename($a))
2458 IkiWiki::pagetitle(IkiWiki::basename($b))
2461 sub cmp_mtime { $IkiWiki::pagemtime{$b} <=> $IkiWiki::pagemtime{$a} }
2462 sub cmp_age { $IkiWiki::pagectime{$b} <=> $IkiWiki::pagectime{$a} }