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/\/\./,
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",
446 description => "running in getctime mode",
453 description => "running in w3mmode",
460 description => "path to the .ikiwiki directory holding ikiwiki state",
467 description => "path to setup file",
473 default => "Standard",
474 description => "perl class to use to dump setup file",
478 allow_symlinks_before_srcdir => {
481 description => "allow symlinks in the path leading to the srcdir (potentially insecure)",
487 sub defaultconfig () {
490 foreach my $key (keys %s) {
491 push @ret, $key, $s{$key}->{default};
498 # locale stuff; avoid LC_ALL since it overrides everything
499 if (defined $ENV{LC_ALL}) {
500 $ENV{LANG} = $ENV{LC_ALL};
503 if (defined $config{locale}) {
504 if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
505 $ENV{LANG}=$config{locale};
510 if (! defined $config{wiki_file_regexp}) {
511 $config{wiki_file_regexp}=qr/(^[$config{wiki_file_chars}]+$)/;
514 if (ref $config{ENV} eq 'HASH') {
515 foreach my $val (keys %{$config{ENV}}) {
516 $ENV{$val}=$config{ENV}{$val};
520 if ($config{w3mmode}) {
521 eval q{use Cwd q{abs_path}};
523 $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
524 $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
525 $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
526 unless $config{cgiurl} =~ m!file:///!;
527 $config{url}="file://".$config{destdir};
530 if ($config{cgi} && ! length $config{url}) {
531 error(gettext("Must specify url to wiki with --url when using --cgi"));
534 $config{wikistatedir}="$config{srcdir}/.ikiwiki"
535 unless exists $config{wikistatedir} && defined $config{wikistatedir};
537 if (defined $config{umask}) {
538 umask(possibly_foolish_untaint($config{umask}));
541 run_hooks(checkconfig => sub { shift->() });
549 foreach my $dir (@INC, $config{libdir}) {
550 next unless defined $dir && length $dir;
551 foreach my $file (glob("$dir/IkiWiki/Plugin/*.pm")) {
552 my ($plugin)=$file=~/.*\/(.*)\.pm$/;
556 foreach my $dir ($config{libdir}, "$installdir/lib/ikiwiki") {
557 next unless defined $dir && length $dir;
558 foreach my $file (glob("$dir/plugins/*")) {
559 $ret{basename($file)}=1 if -x $file;
567 if (defined $config{libdir} && length $config{libdir}) {
568 unshift @INC, possibly_foolish_untaint($config{libdir});
571 foreach my $plugin (@{$config{default_plugins}}, @{$config{add_plugins}}) {
576 if (exists $hooks{rcs}) {
577 error(gettext("cannot use multiple rcs plugins"));
579 loadplugin($config{rcs});
581 if (! exists $hooks{rcs}) {
585 run_hooks(getopt => sub { shift->() });
586 if (grep /^-/, @ARGV) {
587 print STDERR "Unknown option (or missing parameter): $_\n"
588 foreach grep /^-/, @ARGV;
598 return if grep { $_ eq $plugin} @{$config{disable_plugins}};
600 foreach my $dir (defined $config{libdir} ? possibly_foolish_untaint($config{libdir}) : undef,
601 "$installdir/lib/ikiwiki") {
602 if (defined $dir && -x "$dir/plugins/$plugin") {
603 eval { require IkiWiki::Plugin::external };
606 error(sprintf(gettext("failed to load external plugin needed for %s plugin: %s"), $plugin, $reason));
608 import IkiWiki::Plugin::external "$dir/plugins/$plugin";
609 $loaded_plugins{$plugin}=1;
614 my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
617 error("Failed to load plugin $mod: $@");
619 $loaded_plugins{$plugin}=1;
626 log_message('err' => $message) if $config{syslog};
627 if (defined $cleaner) {
634 return unless $config{verbose};
635 return log_message(debug => @_);
639 sub log_message ($$) {
642 if ($config{syslog}) {
645 Sys::Syslog::setlogsock('unix');
646 Sys::Syslog::openlog('ikiwiki', '', 'user');
650 Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
653 elsif (! $config{cgi}) {
657 return print STDERR "@_\n";
661 sub possibly_foolish_untaint ($) {
663 my ($untainted)=$tainted=~/(.*)/s;
683 return exists $pagesources{$page} &&
684 $pagesources{$page} =~ /\._([^.]+)$/;
690 if ($file =~ /\.([^.]+)$/) {
691 return $1 if exists $hooks{htmlize}{$1};
693 my $base=basename($file);
694 if (exists $hooks{htmlize}{$base} &&
695 $hooks{htmlize}{$base}{noextension}) {
706 if (exists $pagename_cache{$file}) {
707 return $pagename_cache{$file};
710 my $type=pagetype($file);
712 $page=~s/\Q.$type\E*$//
713 if defined $type && !$hooks{htmlize}{$type}{keepextension}
714 && !$hooks{htmlize}{$type}{noextension};
715 if ($config{indexpages} && $page=~/(.*)\/index$/) {
719 $pagename_cache{$file} = $page;
723 sub newpagefile ($$) {
727 if (! $config{indexpages} || $page eq 'index') {
728 return $page.".".$type;
731 return $page."/index.".$type;
735 sub targetpage ($$;$) {
740 if (defined $filename) {
741 return $page."/".$filename.".".$ext;
743 elsif (! $config{usedirs} || $page eq 'index') {
744 return $page.".".$ext;
747 return $page."/index.".$ext;
754 return targetpage($page, $config{htmlext});
761 return "$config{srcdir}/$file", stat(_) if -e "$config{srcdir}/$file";
762 foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
763 return "$dir/$file", stat(_) if -e "$dir/$file";
765 error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow;
770 return (srcfile_stat(@_))[0];
773 sub add_underlay ($) {
777 $dir="$config{underlaydirbase}/$dir";
780 if (! grep { $_ eq $dir } @{$config{underlaydirs}}) {
781 unshift @{$config{underlaydirs}}, $dir;
787 sub readfile ($;$$) {
793 error("cannot read a symlink ($file)");
797 open (my $in, "<", $file) || error("failed to read $file: $!");
798 binmode($in) if ($binary);
799 return \*$in if $wantfd;
801 # check for invalid utf-8, and toss it back to avoid crashes
802 if (! utf8::valid($ret)) {
803 $ret=encode_utf8($ret);
805 close $in || error("failed to read $file: $!");
809 sub prep_writefile ($$) {
814 while (length $test) {
815 if (-l "$destdir/$test") {
816 error("cannot write to a symlink ($test)");
818 $test=dirname($test);
821 my $dir=dirname("$destdir/$file");
824 foreach my $s (split(m!/+!, $dir)) {
827 mkdir($d) || error("failed to create directory $d: $!");
835 sub writefile ($$$;$$) {
836 my $file=shift; # can include subdirs
837 my $destdir=shift; # directory to put file in
842 prep_writefile($file, $destdir);
844 my $newfile="$destdir/$file.ikiwiki-new";
846 error("cannot write to a symlink ($newfile)");
849 my $cleanup = sub { unlink($newfile) };
850 open (my $out, '>', $newfile) || error("failed to write $newfile: $!", $cleanup);
851 binmode($out) if ($binary);
853 $writer->(\*$out, $cleanup);
856 print $out $content or error("failed writing to $newfile: $!", $cleanup);
858 close $out || error("failed saving $newfile: $!", $cleanup);
859 rename($newfile, "$destdir/$file") ||
860 error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
866 sub will_render ($$;$) {
871 # Important security check.
872 if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
873 ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}}, @{$wikistate{editpage}{previews}})) {
874 error("$config{destdir}/$dest independently created, not overwriting with version from $page");
877 if (! $clear || $cleared{$page}) {
878 $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
881 foreach my $old (@{$renderedfiles{$page}}) {
882 delete $destsources{$old};
884 $renderedfiles{$page}=[$dest];
887 $destsources{$dest}=$page;
897 if ($link=~s/^\/+//) {
905 $l.="/" if length $l;
908 if (exists $pagesources{$l}) {
911 elsif (exists $pagecase{lc $l}) {
912 return $pagecase{lc $l};
914 } while $cwd=~s{/?[^/]+$}{};
916 if (length $config{userdir}) {
917 my $l = "$config{userdir}/".lc($link);
918 if (exists $pagesources{$l}) {
921 elsif (exists $pagecase{lc $l}) {
922 return $pagecase{lc $l};
926 #print STDERR "warning: page $page, broken link: $link\n";
930 sub isinlinableimage ($) {
933 return $file =~ /\.(png|gif|jpg|jpeg)$/i;
936 sub pagetitle ($;$) {
941 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
944 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
952 # support use w/o %config set
953 my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_";
954 $title=~s/([^$chars]|_)/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
960 my $chars = defined $config{wiki_file_chars} ? $config{wiki_file_chars} : "-[:alnum:]+/.:_";
961 $link=~s/([^$chars])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
968 my $cgiurl=$config{cgiurl};
969 if (exists $params{cgiurl}) {
970 $cgiurl=$params{cgiurl};
971 delete $params{cgiurl};
974 join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
980 return "$config{url}/" if ! defined $page;
982 $page=htmlpage($page);
984 $page=~s/[^\/]+\//..\//g;
989 # Work around very innefficient behavior in File::Spec if abs2rel
990 # is passed two relative paths. It's much faster if paths are
991 # absolute! (Debian bug #376658; fixed in debian unstable now)
996 my $ret=File::Spec->abs2rel($path, $base);
997 $ret=~s/^// if defined $ret;
1001 sub displaytime ($;$) {
1002 # Plugins can override this function to mark up the time to
1004 return '<span class="date">'.formattime(@_).'</span>';
1007 sub formattime ($;$) {
1008 # Plugins can override this function to format the time.
1011 if (! defined $format) {
1012 $format=$config{timeformat};
1015 # strftime doesn't know about encodings, so make sure
1016 # its output is properly treated as utf8
1017 return decode_utf8(POSIX::strftime($format, localtime($time)));
1020 sub beautify_urlpath ($) {
1023 # Ensure url is not an empty link, and if necessary,
1024 # add ./ to avoid colon confusion.
1025 if ($url !~ /^\// && $url !~ /^\.\.?\//) {
1029 if ($config{usedirs}) {
1030 $url =~ s!/index.$config{htmlext}$!/!;
1042 return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
1045 if (! $destsources{$to}) {
1050 return $config{url}.beautify_urlpath("/".$to);
1053 my $link = abs2rel($to, dirname(htmlpage($from)));
1055 return beautify_urlpath($link);
1058 sub htmllink ($$$;@) {
1059 my $lpage=shift; # the page doing the linking
1060 my $page=shift; # the page that will contain the link (different for inline)
1067 if (! $opts{forcesubpage}) {
1068 $bestlink=bestlink($lpage, $link);
1071 $bestlink="$lpage/".lc($link);
1075 if (defined $opts{linktext}) {
1076 $linktext=$opts{linktext};
1079 $linktext=pagetitle(basename($link));
1082 return "<span class=\"selflink\">$linktext</span>"
1083 if length $bestlink && $page eq $bestlink &&
1084 ! defined $opts{anchor};
1086 if (! $destsources{$bestlink}) {
1087 $bestlink=htmlpage($bestlink);
1089 if (! $destsources{$bestlink}) {
1090 return $linktext unless length $config{cgiurl};
1091 return "<span class=\"createlink\"><a href=\"".
1097 "\" rel=\"nofollow\">?</a>$linktext</span>"
1101 $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
1102 $bestlink=beautify_urlpath($bestlink);
1104 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
1105 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
1108 if (defined $opts{anchor}) {
1109 $bestlink.="#".$opts{anchor};
1113 foreach my $attr (qw{rel class title}) {
1114 if (defined $opts{$attr}) {
1115 push @attrs, " $attr=\"$opts{$attr}\"";
1119 return "<a href=\"$bestlink\"@attrs>$linktext</a>";
1124 return length $config{userdir} ? "$config{userdir}/$user" : $user;
1127 sub openiduser ($) {
1130 if ($user =~ m!^https?://! &&
1131 eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
1134 if (Net::OpenID::VerifiedIdentity->can("DisplayOfURL")) {
1135 $display = Net::OpenID::VerifiedIdentity::DisplayOfURL($user);
1138 # backcompat with old version
1139 my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
1140 $display=$oid->display;
1143 # Convert "user.somehost.com" to "user [somehost.com]"
1144 # (also "user.somehost.co.uk")
1145 if ($display !~ /\[/) {
1146 $display=~s/^([-a-zA-Z0-9]+?)\.([-.a-zA-Z0-9]+\.[a-z]+)$/$1 [$2]/;
1148 # Convert "http://somehost.com/user" to "user [somehost.com]".
1149 # (also "https://somehost.com/user/")
1150 if ($display !~ /\[/) {
1151 $display=~s/^https?:\/\/(.+)\/([^\/#?]+)\/?(?:[#?].*)?$/$2 [$1]/;
1153 $display=~s!^https?://!!; # make sure this is removed
1154 eval q{use CGI 'escapeHTML'};
1156 return escapeHTML($display);
1161 sub htmlize ($$$$) {
1167 my $oneline = $content !~ /\n/;
1169 if (exists $hooks{htmlize}{$type}) {
1170 $content=$hooks{htmlize}{$type}{call}->(
1172 content => $content,
1176 error("htmlization of $type not supported");
1179 run_hooks(sanitize => sub {
1182 destpage => $destpage,
1183 content => $content,
1188 # hack to get rid of enclosing junk added by markdown
1189 # and other htmlizers/sanitizers
1190 $content=~s/^<p>//i;
1191 $content=~s/<\/p>\n*$//i;
1202 run_hooks(linkify => sub {
1205 destpage => $destpage,
1206 content => $content,
1214 our $preprocess_preview=0;
1215 sub preprocess ($$$;$$) {
1216 my $page=shift; # the page the data comes from
1217 my $destpage=shift; # the page the data will appear in (different for inline)
1222 # Using local because it needs to be set within any nested calls
1224 local $preprocess_preview=$preview if defined $preview;
1231 $params="" if ! defined $params;
1233 if (length $escape) {
1234 return "[[$prefix$command $params]]";
1236 elsif (exists $hooks{preprocess}{$command}) {
1237 return "" if $scan && ! $hooks{preprocess}{$command}{scan};
1238 # Note: preserve order of params, some plugins may
1239 # consider it significant.
1241 while ($params =~ m{
1242 (?:([-\w]+)=)? # 1: named parameter key?
1244 """(.*?)""" # 2: triple-quoted value
1246 "([^"]*?)" # 3: single-quoted value
1248 (\S+) # 4: unquoted value
1250 (?:\s+|$) # delimiter to next param
1260 elsif (defined $3) {
1263 elsif (defined $4) {
1268 push @params, $key, $val;
1271 push @params, $val, '';
1274 if ($preprocessing{$page}++ > 3) {
1275 # Avoid loops of preprocessed pages preprocessing
1276 # other pages that preprocess them, etc.
1277 return "[[!$command <span class=\"error\">".
1278 sprintf(gettext("preprocessing loop detected on %s at depth %i"),
1279 $page, $preprocessing{$page}).
1285 $hooks{preprocess}{$command}{call}->(
1288 destpage => $destpage,
1289 preview => $preprocess_preview,
1295 $ret="[[!$command <span class=\"error\">".
1296 gettext("Error").": $error"."</span>]]";
1300 # use void context during scan pass
1302 $hooks{preprocess}{$command}{call}->(
1305 destpage => $destpage,
1306 preview => $preprocess_preview,
1311 $preprocessing{$page}--;
1315 return "[[$prefix$command $params]]";
1320 if ($config{prefix_directives}) {
1323 \[\[(!) # directive open; 2: prefix
1324 ([-\w]+) # 3: command
1325 ( # 4: the parameters..
1326 \s+ # Must have space if parameters present
1328 (?:[-\w]+=)? # named parameter key?
1330 """.*?""" # triple-quoted value
1332 "[^"]*?" # single-quoted value
1334 [^"\s\]]+ # unquoted value
1336 \s* # whitespace or end
1339 *)? # 0 or more parameters
1340 \]\] # directive closed
1346 \[\[(!?) # directive open; 2: optional prefix
1347 ([-\w]+) # 3: command
1349 ( # 4: the parameters..
1351 (?:[-\w]+=)? # named parameter key?
1353 """.*?""" # triple-quoted value
1355 "[^"]*?" # single-quoted value
1357 [^"\s\]]+ # unquoted value
1359 \s* # whitespace or end
1362 *) # 0 or more parameters
1363 \]\] # directive closed
1367 $content =~ s{$regex}{$handle->($1, $2, $3, $4)}eg;
1376 run_hooks(filter => sub {
1377 $content=shift->(page => $page, destpage => $destpage,
1378 content => $content);
1385 return "<a href=\"$config{url}\">$config{wikiname}</a>";
1388 sub check_canedit ($$$;$) {
1395 run_hooks(canedit => sub {
1396 return if defined $canedit;
1397 my $ret=shift->($page, $q, $session);
1402 elsif (ref $ret eq 'CODE') {
1403 $ret->() unless $nonfatal;
1406 elsif (defined $ret) {
1407 error($ret) unless $nonfatal;
1412 return defined $canedit ? $canedit : 1;
1415 sub check_content (@) {
1418 return 1 if ! exists $hooks{checkcontent}; # optimisation
1420 if (exists $pagesources{$params{page}}) {
1422 my %old=map { $_ => 1 }
1423 split("\n", readfile(srcfile($pagesources{$params{page}})));
1424 foreach my $line (split("\n", $params{content})) {
1425 push @diff, $line if ! exists $old{$line};
1427 $params{diff}=join("\n", @diff);
1431 run_hooks(checkcontent => sub {
1432 return if defined $ok;
1433 my $ret=shift->(%params);
1438 elsif (ref $ret eq 'CODE') {
1439 $ret->() unless $params{nonfatal};
1442 elsif (defined $ret) {
1443 error($ret) unless $params{nonfatal};
1449 return defined $ok ? $ok : 1;
1455 # Take an exclusive lock on the wiki to prevent multiple concurrent
1456 # run issues. The lock will be dropped on program exit.
1457 if (! -d $config{wikistatedir}) {
1458 mkdir($config{wikistatedir});
1460 open($wikilock, '>', "$config{wikistatedir}/lockfile") ||
1461 error ("cannot write to $config{wikistatedir}/lockfile: $!");
1462 if (! flock($wikilock, 2)) { # LOCK_EX
1463 error("failed to get lock");
1469 POSIX::close($ENV{IKIWIKI_CGILOCK_FD}) if exists $ENV{IKIWIKI_CGILOCK_FD};
1470 return close($wikilock) if $wikilock;
1476 sub commit_hook_enabled () {
1477 open($commitlock, '+>', "$config{wikistatedir}/commitlock") ||
1478 error("cannot write to $config{wikistatedir}/commitlock: $!");
1479 if (! flock($commitlock, 1 | 4)) { # LOCK_SH | LOCK_NB to test
1480 close($commitlock) || error("failed closing commitlock: $!");
1483 close($commitlock) || error("failed closing commitlock: $!");
1487 sub disable_commit_hook () {
1488 open($commitlock, '>', "$config{wikistatedir}/commitlock") ||
1489 error("cannot write to $config{wikistatedir}/commitlock: $!");
1490 if (! flock($commitlock, 2)) { # LOCK_EX
1491 error("failed to get commit lock");
1496 sub enable_commit_hook () {
1497 return close($commitlock) if $commitlock;
1502 %oldrenderedfiles=%pagectime=();
1503 if (! $config{rebuild}) {
1504 %pagesources=%pagemtime=%oldlinks=%links=%depends=
1505 %destsources=%renderedfiles=%pagecase=%pagestate=
1506 %depends_simple=%typedlinks=%oldtypedlinks=();
1509 if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
1510 if (-e "$config{wikistatedir}/index") {
1511 system("ikiwiki-transition", "indexdb", $config{srcdir});
1512 open ($in, "<", "$config{wikistatedir}/indexdb") || return;
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_receive () {
1794 $hooks{rcs}{rcs_receive}{call}->();
1797 sub add_depends ($$;$) {
1800 my $deptype=shift || $DEPEND_CONTENT;
1802 # Is the pagespec a simple page name?
1803 if ($pagespec =~ /$config{wiki_file_regexp}/ &&
1804 $pagespec !~ /[\s*?()!]/) {
1805 $depends_simple{$page}{lc $pagespec} |= $deptype;
1809 # Add explicit dependencies for influences.
1810 my $sub=pagespec_translate($pagespec);
1811 return unless defined $sub;
1812 foreach my $p (keys %pagesources) {
1813 my $r=$sub->($p, location => $page);
1814 my $i=$r->influences;
1815 foreach my $k (keys %$i) {
1816 $depends_simple{$page}{lc $k} |= $i->{$k};
1818 last if $r->influences_static;
1821 $depends{$page}{$pagespec} |= $deptype;
1827 foreach my $type (@_) {
1828 if ($type eq 'presence') {
1829 $deptype |= $DEPEND_PRESENCE;
1831 elsif ($type eq 'links') {
1832 $deptype |= $DEPEND_LINKS;
1834 elsif ($type eq 'content') {
1835 $deptype |= $DEPEND_CONTENT;
1841 my $file_prune_regexp;
1842 sub file_pruned ($;$) {
1846 $file=File::Spec->canonpath($file);
1847 my $base=File::Spec->canonpath(shift);
1848 return if $file eq $base;
1849 $file =~ s#^\Q$base\E/+##;
1852 if (defined $config{include} && length $config{include}) {
1853 return 0 if $file =~ m/$config{include}/;
1856 if (! defined $file_prune_regexp) {
1857 $file_prune_regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')';
1858 $file_prune_regexp=qr/$file_prune_regexp/;
1860 return $file =~ m/$file_prune_regexp/;
1863 sub define_gettext () {
1864 # If translation is needed, redefine the gettext function to do it.
1865 # Otherwise, it becomes a quick no-op.
1868 if ((exists $ENV{LANG} && length $ENV{LANG}) ||
1869 (exists $ENV{LC_ALL} && length $ENV{LC_ALL}) ||
1870 (exists $ENV{LC_MESSAGES} && length $ENV{LC_MESSAGES})) {
1872 $gettext_obj=eval q{
1873 use Locale::gettext q{textdomain};
1874 Locale::gettext->domain('ikiwiki')
1879 no warnings 'redefine';
1881 $getobj->() if $getobj;
1883 $gettext_obj->get(shift);
1890 $getobj->() if $getobj;
1892 $gettext_obj->nget(@_);
1895 return ($_[2] == 1 ? $_[0] : $_[1])
1913 return (defined $val && (lc($val) eq gettext("yes") || lc($val) eq "yes" || $val eq "1"));
1917 # Injects a new function into the symbol table to replace an
1918 # exported function.
1921 # This is deep ugly perl foo, beware.
1924 if (! defined $params{parent}) {
1925 $params{parent}='::';
1926 $params{old}=\&{$params{name}};
1927 $params{name}=~s/.*:://;
1929 my $parent=$params{parent};
1930 foreach my $ns (grep /^\w+::/, keys %{$parent}) {
1931 $ns = $params{parent} . $ns;
1932 inject(%params, parent => $ns) unless $ns eq '::main::';
1933 *{$ns . $params{name}} = $params{call}
1934 if exists ${$ns}{$params{name}} &&
1935 \&{${$ns}{$params{name}}} == $params{old};
1941 sub add_link ($$;$) {
1946 push @{$links{$page}}, $link
1947 unless grep { $_ eq $link } @{$links{$page}};
1949 if (defined $type) {
1950 $typedlinks{$page}{$type}{$link} = 1;
1954 sub sortspec_translate ($$) {
1956 my $reverse = shift;
1962 (-?) # group 1: perhaps negated
1965 \w+\([^\)]*\) # command(params)
1967 [^\s]+ # or anything else
1975 if ($word =~ m/^(\w+)\((.*)\)$/) {
1976 # command with parameters
1980 elsif ($word !~ m/^\w+$/) {
1981 error(sprintf(gettext("invalid sort type %s"), $word));
1992 if (exists $IkiWiki::SortSpec::{"cmp_$word"}) {
1993 if (defined $params) {
1994 push @data, $params;
1995 $code .= "IkiWiki::SortSpec::cmp_$word(\$data[$#data])";
1998 $code .= "IkiWiki::SortSpec::cmp_$word(undef)";
2002 error(sprintf(gettext("unknown sort type %s"), $word));
2006 if (! length $code) {
2007 # undefined sorting method... sort arbitrarily
2016 return eval 'sub { '.$code.' }';
2019 sub pagespec_translate ($) {
2022 # Convert spec to perl code.
2026 \s* # ignore whitespace
2027 ( # 1: match a single word
2034 \w+\([^\)]*\) # command(params)
2036 [^\s()]+ # any other text
2038 \s* # ignore whitespace
2041 if (lc $word eq 'and') {
2044 elsif (lc $word eq 'or') {
2047 elsif ($word eq "(" || $word eq ")" || $word eq "!") {
2050 elsif ($word =~ /^(\w+)\((.*)\)$/) {
2051 if (exists $IkiWiki::PageSpec::{"match_$1"}) {
2053 $code.="IkiWiki::PageSpec::match_$1(\$page, \$data[$#data], \@_)";
2056 push @data, qq{unknown function in pagespec "$word"};
2057 $code.="IkiWiki::ErrorReason->new(\$data[$#data])";
2062 $code.=" IkiWiki::PageSpec::match_glob(\$page, \$data[$#data], \@_)";
2066 if (! length $code) {
2067 $code="IkiWiki::FailReason->new('empty pagespec')";
2071 return eval 'sub { my $page=shift; '.$code.' }';
2074 sub pagespec_match ($$;@) {
2079 # Backwards compatability with old calling convention.
2081 unshift @params, 'location';
2084 my $sub=pagespec_translate($spec);
2085 return IkiWiki::ErrorReason->new("syntax error in pagespec \"$spec\"")
2087 return $sub->($page, @params);
2090 sub pagespec_match_list ($$;@) {
2095 # Backwards compatability with old calling convention.
2097 print STDERR "warning: a plugin (".caller().") is using pagespec_match_list in an obsolete way, and needs to be updated\n";
2098 $params{list}=$page;
2099 $page=$params{location}; # ugh!
2102 my $sub=pagespec_translate($pagespec);
2103 error "syntax error in pagespec \"$pagespec\""
2105 my $sort=sortspec_translate($params{sort}, $params{reverse})
2106 if defined $params{sort};
2109 if (exists $params{list}) {
2110 @candidates=exists $params{filter}
2111 ? grep { ! $params{filter}->($_) } @{$params{list}}
2115 @candidates=exists $params{filter}
2116 ? grep { ! $params{filter}->($_) } keys %pagesources
2117 : keys %pagesources;
2120 # clear params, remainder is passed to pagespec
2121 $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT);
2122 my $num=$params{num};
2123 delete @params{qw{num deptype reverse sort filter list}};
2125 # when only the top matches will be returned, it's efficient to
2126 # sort before matching to pagespec,
2127 if (defined $num && defined $sort) {
2128 @candidates=IkiWiki::SortSpec::sort_pages(
2129 $sort, @candidates);
2135 my $accum=IkiWiki::SuccessReason->new();
2136 foreach my $p (@candidates) {
2137 my $r=$sub->($p, %params, location => $page);
2138 error(sprintf(gettext("cannot match pages: %s"), $r))
2139 if $r->isa("IkiWiki::ErrorReason");
2143 last if defined $num && ++$count == $num;
2147 # Add simple dependencies for accumulated influences.
2148 my $i=$accum->influences;
2149 foreach my $k (keys %$i) {
2150 $depends_simple{$page}{lc $k} |= $i->{$k};
2153 # when all matches will be returned, it's efficient to
2154 # sort after matching
2155 if (! defined $num && defined $sort) {
2156 return IkiWiki::SortSpec::sort_pages(
2164 sub pagespec_valid ($) {
2167 return defined pagespec_translate($spec);
2171 my $re=quotemeta(shift);
2177 package IkiWiki::FailReason;
2180 '""' => sub { $_[0][0] },
2182 '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
2183 '&' => sub { $_[0]->merge_influences($_[1], 1); $_[0] },
2184 '|' => sub { $_[1]->merge_influences($_[0]); $_[1] },
2188 our @ISA = 'IkiWiki::SuccessReason';
2190 package IkiWiki::SuccessReason;
2193 '""' => sub { $_[0][0] },
2195 '!' => sub { bless $_[0], 'IkiWiki::FailReason'},
2196 '&' => sub { $_[1]->merge_influences($_[0], 1); $_[1] },
2197 '|' => sub { $_[0]->merge_influences($_[1]); $_[0] },
2204 return bless [$value, {@_}], $class;
2209 $this->[1]={@_} if @_;
2210 my %i=%{$this->[1]};
2215 sub influences_static {
2216 return ! $_[0][1]->{""};
2219 sub merge_influences {
2224 if (! $anded || (($this || %{$this->[1]}) &&
2225 ($other || %{$other->[1]}))) {
2226 foreach my $influence (keys %{$other->[1]}) {
2227 $this->[1]{$influence} |= $other->[1]{$influence};
2236 package IkiWiki::ErrorReason;
2238 our @ISA = 'IkiWiki::FailReason';
2240 package IkiWiki::PageSpec;
2246 if ($path =~ m!^\./!) {
2247 $from=~s#/?[^/]+$## if defined $from;
2249 $path="$from/$path" if length $from;
2255 sub match_glob ($$;@) {
2260 $glob=derel($glob, $params{location});
2262 my $regexp=IkiWiki::glob2re($glob);
2263 if ($page=~/^$regexp$/i) {
2264 if (! IkiWiki::isinternal($page) || $params{internal}) {
2265 return IkiWiki::SuccessReason->new("$glob matches $page");
2268 return IkiWiki::FailReason->new("$glob matches $page, but the page is an internal page");
2272 return IkiWiki::FailReason->new("$glob does not match $page");
2276 sub match_internal ($$;@) {
2277 return match_glob($_[0], $_[1], @_, internal => 1)
2280 sub match_link ($$;@) {
2285 $link=derel($link, $params{location});
2286 my $from=exists $params{location} ? $params{location} : '';
2287 my $linktype=$params{linktype};
2289 if (defined $linktype) {
2290 $qualifier=" with type $linktype";
2293 my $links = $IkiWiki::links{$page};
2294 return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2295 unless $links && @{$links};
2296 my $bestlink = IkiWiki::bestlink($from, $link);
2297 foreach my $p (@{$links}) {
2298 if (length $bestlink) {
2299 if ((!defined $linktype || exists $IkiWiki::typedlinks{$page}{$linktype}{$p}) && $bestlink eq IkiWiki::bestlink($page, $p)) {
2300 return IkiWiki::SuccessReason->new("$page links to $link$qualifier", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2304 if ((!defined $linktype || exists $IkiWiki::typedlinks{$page}{$linktype}{$p}) && match_glob($p, $link, %params)) {
2305 return IkiWiki::SuccessReason->new("$page links to page $p$qualifier, matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2307 my ($p_rel)=$p=~/^\/?(.*)/;
2309 if ((!defined $linktype || exists $IkiWiki::typedlinks{$page}{$linktype}{$p_rel}) && match_glob($p_rel, $link, %params)) {
2310 return IkiWiki::SuccessReason->new("$page links to page $p_rel$qualifier, matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
2314 return IkiWiki::FailReason->new("$page does not link to $link$qualifier", $page => $IkiWiki::DEPEND_LINKS, "" => 1);
2317 sub match_backlink ($$;@) {
2318 my $ret=match_link($_[1], $_[0], @_);
2319 $ret->influences($_[1] => $IkiWiki::DEPEND_LINKS);
2323 sub match_created_before ($$;@) {
2328 $testpage=derel($testpage, $params{location});
2330 if (exists $IkiWiki::pagectime{$testpage}) {
2331 if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
2332 return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2335 return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2339 return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
2343 sub match_created_after ($$;@) {
2348 $testpage=derel($testpage, $params{location});
2350 if (exists $IkiWiki::pagectime{$testpage}) {
2351 if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
2352 return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2355 return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
2359 return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
2363 sub match_creation_day ($$;@) {
2364 if ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift) {
2365 return IkiWiki::SuccessReason->new('creation_day matched');
2368 return IkiWiki::FailReason->new('creation_day did not match');
2372 sub match_creation_month ($$;@) {
2373 if ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
2374 return IkiWiki::SuccessReason->new('creation_month matched');
2377 return IkiWiki::FailReason->new('creation_month did not match');
2381 sub match_creation_year ($$;@) {
2382 if ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift) {
2383 return IkiWiki::SuccessReason->new('creation_year matched');
2386 return IkiWiki::FailReason->new('creation_year did not match');
2390 sub match_user ($$;@) {
2395 my $regexp=IkiWiki::glob2re($user);
2397 if (! exists $params{user}) {
2398 return IkiWiki::ErrorReason->new("no user specified");
2401 if (defined $params{user} && $params{user}=~/^$regexp$/i) {
2402 return IkiWiki::SuccessReason->new("user is $user");
2404 elsif (! defined $params{user}) {
2405 return IkiWiki::FailReason->new("not logged in");
2408 return IkiWiki::FailReason->new("user is $params{user}, not $user");
2412 sub match_admin ($$;@) {
2417 if (! exists $params{user}) {
2418 return IkiWiki::ErrorReason->new("no user specified");
2421 if (defined $params{user} && IkiWiki::is_admin($params{user})) {
2422 return IkiWiki::SuccessReason->new("user is an admin");
2424 elsif (! defined $params{user}) {
2425 return IkiWiki::FailReason->new("not logged in");
2428 return IkiWiki::FailReason->new("user is not an admin");
2432 sub match_ip ($$;@) {
2437 if (! exists $params{ip}) {
2438 return IkiWiki::ErrorReason->new("no IP specified");
2441 if (defined $params{ip} && lc $params{ip} eq lc $ip) {
2442 return IkiWiki::SuccessReason->new("IP is $ip");
2445 return IkiWiki::FailReason->new("IP is $params{ip}, not $ip");
2449 package IkiWiki::SortSpec;
2451 # This is in the SortSpec namespace so that the $a and $b that sort() uses
2452 # are easily available in this namespace, for cmp functions to use them.
2459 IkiWiki::pagetitle(IkiWiki::basename($a))
2461 IkiWiki::pagetitle(IkiWiki::basename($b))
2464 sub cmp_mtime { $IkiWiki::pagemtime{$b} <=> $IkiWiki::pagemtime{$a} }
2465 sub cmp_age { $IkiWiki::pagectime{$b} <=> $IkiWiki::pagectime{$a} }