* Work on firming up the plugin interface:
- Plugins should not need to load IkiWiki::Render to get commonly used functions, so moved some functions from there to IkiWiki. - Picked out the set of functions and variables that most plugins use, documented them, and made IkiWiki export them by default, like a proper perl module should. - Use the other functions at your own risk. - This is not quite complete, I still have to decide whether to export some other things. * Changed all plugins included in ikiwiki to not use "IkiWiki::" when referring to stuff now exported by the IkiWiki module. * Anyone with a third-party ikiwiki plugin is strongly enrouraged to make like changes to it and avoid use of non-exported symboles from "IkiWiki::". * Link debian/changelog and debian/news to NEWS and CHANGELOG. * Support hyperestradier version 1.4.2, which adds a new required phraseform setting.master
parent
d92142d09e
commit
dae0f48e91
151
IkiWiki.pm
151
IkiWiki.pm
|
@ -7,14 +7,19 @@ use Encode;
|
||||||
use HTML::Entities;
|
use HTML::Entities;
|
||||||
use open qw{:utf8 :std};
|
use open qw{:utf8 :std};
|
||||||
|
|
||||||
|
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
|
||||||
|
%renderedfiles %pagesources %depends %hooks %forcerebuild};
|
||||||
|
|
||||||
|
use Exporter q{import};
|
||||||
|
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
|
||||||
|
bestlink htmllink readfile writefile pagetype srcfile pagename
|
||||||
|
%config %links %renderedfiles %pagesources);
|
||||||
|
|
||||||
# Optimisation.
|
# Optimisation.
|
||||||
use Memoize;
|
use Memoize;
|
||||||
memoize("abs2rel");
|
memoize("abs2rel");
|
||||||
memoize("pagespec_translate");
|
memoize("pagespec_translate");
|
||||||
|
|
||||||
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
|
|
||||||
%renderedfiles %pagesources %depends %hooks %forcerebuild};
|
|
||||||
|
|
||||||
my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
|
my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
|
||||||
|
|
||||||
sub defaultconfig () { #{{{
|
sub defaultconfig () { #{{{
|
||||||
|
@ -254,11 +259,6 @@ sub writefile ($$$;$) { #{{{
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub bestlink ($$) { #{{{
|
sub bestlink ($$) { #{{{
|
||||||
# Given a page and the text of a link on the page, determine which
|
|
||||||
# existing page that link best points to. Prefers pages under a
|
|
||||||
# subdirectory with the same name as the source page, failing that
|
|
||||||
# goes down the directory tree to the base looking for matching
|
|
||||||
# pages.
|
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $link=shift;
|
my $link=shift;
|
||||||
|
|
||||||
|
@ -329,6 +329,16 @@ sub abs2rel ($$) { #{{{
|
||||||
return $ret;
|
return $ret;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
sub displaytime ($) { #{{{
|
||||||
|
my $time=shift;
|
||||||
|
|
||||||
|
eval q{use POSIX};
|
||||||
|
# strftime doesn't know about encodings, so make sure
|
||||||
|
# its output is properly treated as utf8
|
||||||
|
return decode_utf8(POSIX::strftime(
|
||||||
|
$config{timeformat}, localtime($time)));
|
||||||
|
} #}}}
|
||||||
|
|
||||||
sub htmllink ($$$;$$$) { #{{{
|
sub htmllink ($$$;$$$) { #{{{
|
||||||
my $lpage=shift; # the page doing the linking
|
my $lpage=shift; # the page doing the linking
|
||||||
my $page=shift; # the page that will contain the link (different for inline)
|
my $page=shift; # the page that will contain the link (different for inline)
|
||||||
|
@ -370,6 +380,117 @@ sub htmllink ($$$;$$$) { #{{{
|
||||||
return "<a href=\"$bestlink\">$linktext</a>";
|
return "<a href=\"$bestlink\">$linktext</a>";
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
sub htmlize ($$$) { #{{{
|
||||||
|
my $page=shift;
|
||||||
|
my $type=shift;
|
||||||
|
my $content=shift;
|
||||||
|
|
||||||
|
if (exists $hooks{htmlize}{$type}) {
|
||||||
|
$content=$hooks{htmlize}{$type}{call}->(
|
||||||
|
page => $page,
|
||||||
|
content => $content,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error("htmlization of $type not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
run_hooks(sanitize => sub {
|
||||||
|
$content=shift->(
|
||||||
|
page => $page,
|
||||||
|
content => $content,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
|
sub linkify ($$$) { #{{{
|
||||||
|
my $lpage=shift; # the page containing the links
|
||||||
|
my $page=shift; # the page the link will end up on (different for inline)
|
||||||
|
my $content=shift;
|
||||||
|
|
||||||
|
$content =~ s{(\\?)$config{wiki_link_regexp}}{
|
||||||
|
$2 ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), 0, 0, pagetitle($2)))
|
||||||
|
: ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3)))
|
||||||
|
}eg;
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
|
my %preprocessing;
|
||||||
|
sub preprocess ($$$) { #{{{
|
||||||
|
my $page=shift; # the page the data comes from
|
||||||
|
my $destpage=shift; # the page the data will appear in (different for inline)
|
||||||
|
my $content=shift;
|
||||||
|
|
||||||
|
my $handle=sub {
|
||||||
|
my $escape=shift;
|
||||||
|
my $command=shift;
|
||||||
|
my $params=shift;
|
||||||
|
if (length $escape) {
|
||||||
|
return "[[$command $params]]";
|
||||||
|
}
|
||||||
|
elsif (exists $hooks{preprocess}{$command}) {
|
||||||
|
# Note: preserve order of params, some plugins may
|
||||||
|
# consider it significant.
|
||||||
|
my @params;
|
||||||
|
while ($params =~ /(?:(\w+)=)?(?:"""(.*?)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
|
||||||
|
my $key=$1;
|
||||||
|
my $val;
|
||||||
|
if (defined $2) {
|
||||||
|
$val=$2;
|
||||||
|
$val=~s/\r\n/\n/mg;
|
||||||
|
$val=~s/^\n+//g;
|
||||||
|
$val=~s/\n+$//g;
|
||||||
|
}
|
||||||
|
elsif (defined $3) {
|
||||||
|
$val=$3;
|
||||||
|
}
|
||||||
|
elsif (defined $4) {
|
||||||
|
$val=$4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined $key) {
|
||||||
|
push @params, $key, $val;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
push @params, $val, '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($preprocessing{$page}++ > 3) {
|
||||||
|
# Avoid loops of preprocessed pages preprocessing
|
||||||
|
# other pages that preprocess them, etc.
|
||||||
|
return "[[$command preprocessing loop detected on $page at depth $preprocessing{$page}]]";
|
||||||
|
}
|
||||||
|
my $ret=$hooks{preprocess}{$command}{call}->(
|
||||||
|
@params,
|
||||||
|
page => $page,
|
||||||
|
destpage => $destpage,
|
||||||
|
);
|
||||||
|
$preprocessing{$page}--;
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "[[$command $params]]";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".*?"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}seg;
|
||||||
|
return $content;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
|
sub filter ($$) {
|
||||||
|
my $page=shift;
|
||||||
|
my $content=shift;
|
||||||
|
|
||||||
|
run_hooks(filter => sub {
|
||||||
|
$content=shift->(page => $page, content => $content);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
sub indexlink () { #{{{
|
sub indexlink () { #{{{
|
||||||
return "<a href=\"$config{url}\">$config{wikiname}</a>";
|
return "<a href=\"$config{url}\">$config{wikiname}</a>";
|
||||||
} #}}}
|
} #}}}
|
||||||
|
@ -478,7 +599,7 @@ sub misctemplate ($$) { #{{{
|
||||||
indexlink => indexlink(),
|
indexlink => indexlink(),
|
||||||
wikiname => $config{wikiname},
|
wikiname => $config{wikiname},
|
||||||
pagebody => $pagebody,
|
pagebody => $pagebody,
|
||||||
baseurl => baseurl(),
|
baseurl => baseurl(),
|
||||||
);
|
);
|
||||||
return $template->output;
|
return $template->output;
|
||||||
}#}}}
|
}#}}}
|
||||||
|
@ -594,6 +715,18 @@ sub pagespec_translate ($) { #{{{
|
||||||
return $code;
|
return $code;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
sub add_depends ($$) { #{{{
|
||||||
|
my $page=shift;
|
||||||
|
my $pagespec=shift;
|
||||||
|
|
||||||
|
if (! exists $depends{$page}) {
|
||||||
|
$depends{$page}=$pagespec;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$depends{$page}=pagespec_merge($depends{$page}, $pagespec);
|
||||||
|
}
|
||||||
|
} # }}}
|
||||||
|
|
||||||
sub pagespec_match ($$) { #{{{
|
sub pagespec_match ($$) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $spec=shift;
|
my $spec=shift;
|
||||||
|
|
|
@ -431,7 +431,6 @@ sub cgi_editpage ($$) { #{{{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
elsif ($form->submitted eq "Preview") {
|
elsif ($form->submitted eq "Preview") {
|
||||||
require IkiWiki::Render;
|
|
||||||
my $content=$form->field('editcontent');
|
my $content=$form->field('editcontent');
|
||||||
my $comments=$form->field('comments');
|
my $comments=$form->field('comments');
|
||||||
$form->field(name => "editcontent",
|
$form->field(name => "editcontent",
|
||||||
|
|
|
@ -14,30 +14,24 @@ my %feeds;
|
||||||
my %guids;
|
my %guids;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "getopt", id => "aggregate",
|
hook(type => "getopt", id => "aggregate", call => \&getopt);
|
||||||
call => \&getopt);
|
hook(type => "checkconfig", id => "aggregate", call => \&checkconfig);
|
||||||
IkiWiki::hook(type => "checkconfig", id => "aggregate",
|
hook(type => "filter", id => "aggregate", call => \&filter);
|
||||||
call => \&checkconfig);
|
hook(type => "preprocess", id => "aggregate", call => \&preprocess);
|
||||||
IkiWiki::hook(type => "filter", id => "aggregate",
|
hook(type => "delete", id => "aggregate", call => \&delete);
|
||||||
call => \&filter);
|
hook(type => "savestate", id => "aggregate", call => \&savestate);
|
||||||
IkiWiki::hook(type => "preprocess", id => "aggregate",
|
|
||||||
call => \&preprocess);
|
|
||||||
IkiWiki::hook(type => "delete", id => "aggregate",
|
|
||||||
call => \&delete);
|
|
||||||
IkiWiki::hook(type => "savestate", id => "aggregate",
|
|
||||||
call => \&savestate);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub getopt () { #{{{
|
sub getopt () { #{{{
|
||||||
eval q{use Getopt::Long};
|
eval q{use Getopt::Long};
|
||||||
Getopt::Long::Configure('pass_through');
|
Getopt::Long::Configure('pass_through');
|
||||||
GetOptions("aggregate" => \$IkiWiki::config{aggregate});
|
GetOptions("aggregate" => \$config{aggregate});
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub checkconfig () { #{{{
|
sub checkconfig () { #{{{
|
||||||
IkiWiki::lockwiki();
|
IkiWiki::lockwiki();
|
||||||
loadstate();
|
loadstate();
|
||||||
if ($IkiWiki::config{aggregate}) {
|
if ($config{aggregate}) {
|
||||||
IkiWiki::loadindex();
|
IkiWiki::loadindex();
|
||||||
aggregate();
|
aggregate();
|
||||||
savestate();
|
savestate();
|
||||||
|
@ -78,7 +72,7 @@ sub preprocess (@) { #{{{
|
||||||
$feed->{url}=$params{url};
|
$feed->{url}=$params{url};
|
||||||
my $dir=exists $params{dir} ? $params{dir} : $params{page}."/".IkiWiki::titlepage($params{name});
|
my $dir=exists $params{dir} ? $params{dir} : $params{page}."/".IkiWiki::titlepage($params{name});
|
||||||
$dir=~s/^\/+//;
|
$dir=~s/^\/+//;
|
||||||
($dir)=$dir=~/$IkiWiki::config{wiki_file_regexp}/;
|
($dir)=$dir=~/$config{wiki_file_regexp}/;
|
||||||
$feed->{dir}=$dir;
|
$feed->{dir}=$dir;
|
||||||
$feed->{feedurl}=defined $params{feedurl} ? $params{feedurl} : "";
|
$feed->{feedurl}=defined $params{feedurl} ? $params{feedurl} : "";
|
||||||
$feed->{updateinterval}=defined $params{updateinterval} ? $params{updateinterval} * 60 : 15 * 60;
|
$feed->{updateinterval}=defined $params{updateinterval} ? $params{updateinterval} * 60 : 15 * 60;
|
||||||
|
@ -109,15 +103,15 @@ sub delete (@) { #{{{
|
||||||
|
|
||||||
# Remove feed data for removed pages.
|
# Remove feed data for removed pages.
|
||||||
foreach my $file (@files) {
|
foreach my $file (@files) {
|
||||||
my $page=IkiWiki::pagename($file);
|
my $page=pagename($file);
|
||||||
remove_feeds($page);
|
remove_feeds($page);
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub loadstate () { #{{{
|
sub loadstate () { #{{{
|
||||||
if (-e "$IkiWiki::config{wikistatedir}/aggregate") {
|
if (-e "$config{wikistatedir}/aggregate") {
|
||||||
open (IN, "$IkiWiki::config{wikistatedir}/aggregate" ||
|
open (IN, "$config{wikistatedir}/aggregate" ||
|
||||||
die "$IkiWiki::config{wikistatedir}/aggregate: $!");
|
die "$config{wikistatedir}/aggregate: $!");
|
||||||
while (<IN>) {
|
while (<IN>) {
|
||||||
$_=IkiWiki::possibly_foolish_untaint($_);
|
$_=IkiWiki::possibly_foolish_untaint($_);
|
||||||
chomp;
|
chomp;
|
||||||
|
@ -151,8 +145,8 @@ sub loadstate () { #{{{
|
||||||
sub savestate () { #{{{
|
sub savestate () { #{{{
|
||||||
eval q{use HTML::Entities};
|
eval q{use HTML::Entities};
|
||||||
die $@ if $@;
|
die $@ if $@;
|
||||||
open (OUT, ">$IkiWiki::config{wikistatedir}/aggregate" ||
|
open (OUT, ">$config{wikistatedir}/aggregate" ||
|
||||||
die "$IkiWiki::config{wikistatedir}/aggregate: $!");
|
die "$config{wikistatedir}/aggregate: $!");
|
||||||
foreach my $data (values %feeds, values %guids) {
|
foreach my $data (values %feeds, values %guids) {
|
||||||
if ($data->{remove}) {
|
if ($data->{remove}) {
|
||||||
if ($data->{name}) {
|
if ($data->{name}) {
|
||||||
|
@ -193,19 +187,19 @@ sub aggregate () { #{{{
|
||||||
die $@ if $@;
|
die $@ if $@;
|
||||||
|
|
||||||
foreach my $feed (values %feeds) {
|
foreach my $feed (values %feeds) {
|
||||||
next unless $IkiWiki::config{rebuild} ||
|
next unless $config{rebuild} ||
|
||||||
time - $feed->{lastupdate} >= $feed->{updateinterval};
|
time - $feed->{lastupdate} >= $feed->{updateinterval};
|
||||||
$feed->{lastupdate}=time;
|
$feed->{lastupdate}=time;
|
||||||
$feed->{newposts}=0;
|
$feed->{newposts}=0;
|
||||||
$IkiWiki::forcerebuild{$feed->{sourcepage}}=1;
|
$IkiWiki::forcerebuild{$feed->{sourcepage}}=1;
|
||||||
|
|
||||||
IkiWiki::debug("checking feed ".$feed->{name}." ...");
|
debug("checking feed ".$feed->{name}." ...");
|
||||||
|
|
||||||
if (! length $feed->{feedurl}) {
|
if (! length $feed->{feedurl}) {
|
||||||
my @urls=XML::Feed->find_feeds($feed->{url});
|
my @urls=XML::Feed->find_feeds($feed->{url});
|
||||||
if (! @urls) {
|
if (! @urls) {
|
||||||
$feed->{message}="could not find feed at ".$feed->{feedurl};
|
$feed->{message}="could not find feed at ".$feed->{feedurl};
|
||||||
IkiWiki::debug($feed->{message});
|
debug($feed->{message});
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
$feed->{feedurl}=pop @urls;
|
$feed->{feedurl}=pop @urls;
|
||||||
|
@ -213,12 +207,12 @@ sub aggregate () { #{{{
|
||||||
my $f=eval{XML::Feed->parse(URI->new($feed->{feedurl}))};
|
my $f=eval{XML::Feed->parse(URI->new($feed->{feedurl}))};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$feed->{message}="feed crashed XML::Feed! $@";
|
$feed->{message}="feed crashed XML::Feed! $@";
|
||||||
IkiWiki::debug($feed->{message});
|
debug($feed->{message});
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if (! $f) {
|
if (! $f) {
|
||||||
$feed->{message}=XML::Feed->errstr;
|
$feed->{message}=XML::Feed->errstr;
|
||||||
IkiWiki::debug($feed->{message});
|
debug($feed->{message});
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +228,7 @@ sub aggregate () { #{{{
|
||||||
}
|
}
|
||||||
|
|
||||||
$feed->{message}="processed ok at ".
|
$feed->{message}="processed ok at ".
|
||||||
IkiWiki::displaytime($feed->{lastupdate});
|
displaytime($feed->{lastupdate});
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: expiry
|
# TODO: expiry
|
||||||
|
@ -264,7 +258,7 @@ sub add_page (@) { #{{{
|
||||||
# directory name or trigger ".." disallowing code.
|
# directory name or trigger ".." disallowing code.
|
||||||
$page=~s!([/.])!"__".ord($1)."__"!eg;
|
$page=~s!([/.])!"__".ord($1)."__"!eg;
|
||||||
$page=$feed->{dir}."/".$page;
|
$page=$feed->{dir}."/".$page;
|
||||||
($page)=$page=~/$IkiWiki::config{wiki_file_regexp}/;
|
($page)=$page=~/$config{wiki_file_regexp}/;
|
||||||
if (! defined $page || ! length $page) {
|
if (! defined $page || ! length $page) {
|
||||||
$page=$feed->{dir}."/item";
|
$page=$feed->{dir}."/item";
|
||||||
}
|
}
|
||||||
|
@ -274,7 +268,7 @@ sub add_page (@) { #{{{
|
||||||
$c++
|
$c++
|
||||||
}
|
}
|
||||||
$guid->{page}=$page;
|
$guid->{page}=$page;
|
||||||
IkiWiki::debug("creating new page $page");
|
debug("creating new page $page");
|
||||||
}
|
}
|
||||||
$guid->{feed}=$feed->{name};
|
$guid->{feed}=$feed->{name};
|
||||||
|
|
||||||
|
@ -284,11 +278,11 @@ sub add_page (@) { #{{{
|
||||||
eval q{use Digest::MD5 'md5_hex'};
|
eval q{use Digest::MD5 'md5_hex'};
|
||||||
require Encode;
|
require Encode;
|
||||||
my $digest=md5_hex(Encode::encode_utf8($params{content}));
|
my $digest=md5_hex(Encode::encode_utf8($params{content}));
|
||||||
return unless ! exists $guid->{md5} || $guid->{md5} ne $digest || $IkiWiki::config{rebuild};
|
return unless ! exists $guid->{md5} || $guid->{md5} ne $digest || $config{rebuild};
|
||||||
$guid->{md5}=$digest;
|
$guid->{md5}=$digest;
|
||||||
|
|
||||||
# Create the page.
|
# Create the page.
|
||||||
my $template=IkiWiki::template("aggregatepost.tmpl", blind_cache => 1);
|
my $template=template("aggregatepost.tmpl", blind_cache => 1);
|
||||||
$template->param(title => $params{title})
|
$template->param(title => $params{title})
|
||||||
if defined $params{title} && length($params{title});
|
if defined $params{title} && length($params{title});
|
||||||
$template->param(content => htmlescape(htmlabs($params{content}, $feed->{feedurl})));
|
$template->param(content => htmlescape(htmlabs($params{content}, $feed->{feedurl})));
|
||||||
|
@ -299,7 +293,7 @@ sub add_page (@) { #{{{
|
||||||
if (ref $feed->{tags}) {
|
if (ref $feed->{tags}) {
|
||||||
$template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
|
$template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
|
||||||
}
|
}
|
||||||
IkiWiki::writefile(IkiWiki::htmlpage($guid->{page}), $IkiWiki::config{srcdir},
|
writefile(htmlpage($guid->{page}), $config{srcdir},
|
||||||
$template->output);
|
$template->output);
|
||||||
|
|
||||||
# Set the mtime, this lets the build process get the right creation
|
# Set the mtime, this lets the build process get the right creation
|
||||||
|
@ -374,7 +368,7 @@ sub remove_feeds () { #{{{
|
||||||
sub pagefile ($) { #{{{
|
sub pagefile ($) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
|
|
||||||
return "$IkiWiki::config{srcdir}/".IkiWiki::htmlpage($page);
|
return "$config{srcdir}/".htmlpage($page);
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
|
@ -7,8 +7,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "brokenlinks",
|
hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -17,19 +16,19 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
# Needs to update whenever a page is added or removed, so
|
# Needs to update whenever a page is added or removed, so
|
||||||
# register a dependency.
|
# register a dependency.
|
||||||
IkiWiki::add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my @broken;
|
my @broken;
|
||||||
foreach my $page (keys %IkiWiki::links) {
|
foreach my $page (keys %links) {
|
||||||
if (IkiWiki::pagespec_match($page, $params{pages})) {
|
if (pagespec_match($page, $params{pages})) {
|
||||||
foreach my $link (@{$IkiWiki::links{$page}}) {
|
foreach my $link (@{$links{$page}}) {
|
||||||
next if $link =~ /.*\/discussion/i && $IkiWiki::config{discussion};
|
next if $link =~ /.*\/discussion/i && $config{discussion};
|
||||||
my $bestlink=IkiWiki::bestlink($page, $link);
|
my $bestlink=bestlink($page, $link);
|
||||||
next if length $bestlink;
|
next if length $bestlink;
|
||||||
push @broken,
|
push @broken,
|
||||||
IkiWiki::htmllink($page, $params{destpage}, $link, 1).
|
htmllink($page, $params{destpage}, $link, 1).
|
||||||
" in ".
|
" in ".
|
||||||
IkiWiki::htmllink($params{page}, $params{destpage}, $page, 1);
|
htmllink($params{page}, $params{destpage}, $page, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
# CamelCase links
|
# CamelCase links
|
||||||
package IkiWiki::Plugin::camelcase;
|
package IkiWiki::Plugin::camelcase;
|
||||||
|
|
||||||
|
use IkiWiki;
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "filter", id => "camelcase", call => \&filter);
|
hook(type => "filter", id => "camelcase", call => \&filter);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub filter (@) { #{{{
|
sub filter (@) { #{{{
|
||||||
|
|
|
@ -2,18 +2,16 @@
|
||||||
# Discordian date support fnord ikiwiki.
|
# Discordian date support fnord ikiwiki.
|
||||||
package IkiWiki::Plugin::ddate;
|
package IkiWiki::Plugin::ddate;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
use IkiWiki::Render; # so we can redefine it here
|
|
||||||
no warnings;
|
no warnings;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "checkconfig", id => "skeleton",
|
hook(type => "checkconfig", id => "skeleton", call => \&checkconfig);
|
||||||
call => \&checkconfig);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub checkconfig () { #{{{
|
sub checkconfig () { #{{{
|
||||||
if (! defined $IkiWiki::config{timeformat} ||
|
if (! defined $config{timeformat} ||
|
||||||
$IkiWiki::config{timeformat} eq '%c') {
|
$config{timeformat} eq '%c') {
|
||||||
$IkiWiki::config{timeformat}='on %{%A, the %e of %B%}, %Y. %N%nCelebrate %H';
|
$config{timeformat}='on %{%A, the %e of %B%}, %Y. %N%nCelebrate %H';
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
@ -21,7 +19,7 @@ sub IkiWiki::displaytime ($) { #{{{
|
||||||
my $time=shift;
|
my $time=shift;
|
||||||
eval q{use POSIX};
|
eval q{use POSIX};
|
||||||
my $gregorian=POSIX::strftime("%d %m %Y", localtime($time));
|
my $gregorian=POSIX::strftime("%d %m %Y", localtime($time));
|
||||||
my $date=`ddate +'$IkiWiki::config{timeformat}' $gregorian`;
|
my $date=`ddate +'$config{timeformat}' $gregorian`;
|
||||||
chomp $date;
|
chomp $date;
|
||||||
if ($? || ! length $date) {
|
if ($? || ! length $date) {
|
||||||
return "some time or other (hail Eris!)";
|
return "some time or other (hail Eris!)";
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
# Include a fortune in a page
|
# Include a fortune in a page
|
||||||
package IkiWiki::Plugin::fortune;
|
package IkiWiki::Plugin::fortune;
|
||||||
|
|
||||||
|
use IkiWiki;
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "fortune",
|
hook(type => "preprocess", id => "fortune", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
|
|
@ -7,9 +7,9 @@ use IkiWiki;
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "googlecalendar",
|
hook(type => "preprocess", id => "googlecalendar",
|
||||||
call => \&preprocess);
|
call => \&preprocess);
|
||||||
IkiWiki::hook(type => "format", id => "googlecalendar",
|
hook(type => "format", id => "googlecalendar",
|
||||||
call => \&format);
|
call => \&format);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "haiku",
|
hook(type => "preprocess", id => "haiku", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -16,7 +15,7 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
my $haiku;
|
my $haiku;
|
||||||
eval q{use Coy};
|
eval q{use Coy};
|
||||||
if ($@) {
|
if ($@ || ! Coy->can("Coy::with_haiku")) {
|
||||||
my @canned=(
|
my @canned=(
|
||||||
"The lack of a Coy:
|
"The lack of a Coy:
|
||||||
No darting, subtle haiku.
|
No darting, subtle haiku.
|
||||||
|
|
|
@ -7,12 +7,12 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "htmlize", id => "html", call => \&htmlize);
|
hook(type => "htmlize", id => "html", call => \&htmlize);
|
||||||
IkiWiki::hook(type => "htmlize", id => "htm", call => \&htmlize);
|
hook(type => "htmlize", id => "htm", call => \&htmlize);
|
||||||
|
|
||||||
# ikiwiki defaults to skipping .html files as a security measure;
|
# ikiwiki defaults to skipping .html files as a security measure;
|
||||||
# make it process them so this plugin can take effect
|
# make it process them so this plugin can take effect
|
||||||
$IkiWiki::config{wiki_file_prune_regexp} =~ s/\|\\\.x\?html\?\$//;
|
$config{wiki_file_prune_regexp} =~ s/\|\\\.x\?html\?\$//;
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub htmlize (@) { #{{{
|
sub htmlize (@) { #{{{
|
||||||
|
|
|
@ -6,8 +6,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "sanitize", id => "htmlscrubber",
|
hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize);
|
||||||
call => \&sanitize);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub sanitize (@) { #{{{
|
sub sanitize (@) { #{{{
|
||||||
|
|
|
@ -13,7 +13,7 @@ use IkiWiki;
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
|
hook(type => "sanitize", id => "tidy", call => \&sanitize);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub sanitize (@) { #{{{
|
sub sanitize (@) { #{{{
|
||||||
|
@ -28,7 +28,7 @@ sub sanitize (@) { #{{{
|
||||||
last unless $@;
|
last unless $@;
|
||||||
$tries--;
|
$tries--;
|
||||||
if ($tries < 1) {
|
if ($tries < 1) {
|
||||||
IkiWiki::debug("failed to run tidy: $@");
|
debug("failed to run tidy: $@");
|
||||||
return $params{content};
|
return $params{content};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,18 @@ package IkiWiki::Plugin::inline;
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
use IkiWiki::Render; # for displaytime
|
||||||
use URI;
|
use URI;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "inline",
|
hook(type => "preprocess", id => "inline",
|
||||||
call => \&IkiWiki::preprocess_inline);
|
call => \&IkiWiki::preprocess_inline);
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "inline",
|
hook(type => "pagetemplate", id => "inline",
|
||||||
call => \&IkiWiki::pagetemplate_inline);
|
call => \&IkiWiki::pagetemplate_inline);
|
||||||
# Hook to change to do pinging since it's called late.
|
# Hook to change to do pinging since it's called late.
|
||||||
# This ensures each page only pings once and prevents slow
|
# This ensures each page only pings once and prevents slow
|
||||||
# pings interrupting page builds.
|
# pings interrupting page builds.
|
||||||
IkiWiki::hook(type => "change", id => "inline",
|
hook(type => "change", id => "inline",
|
||||||
call => \&IkiWiki::pingurl);
|
call => \&IkiWiki::pingurl);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,8 @@ use IkiWiki;
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "linkmap",
|
hook(type => "preprocess", id => "linkmap", call => \&preprocess);
|
||||||
call => \&preprocess);
|
hook(type => "format", id => "linkmap", call => \&format);
|
||||||
IkiWiki::hook(type => "format", id => "linkmap",
|
|
||||||
call => \&format);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
my $mapnum=0;
|
my $mapnum=0;
|
||||||
|
@ -23,7 +21,7 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
# Needs to update whenever a page is added or removed, so
|
# Needs to update whenever a page is added or removed, so
|
||||||
# register a dependency.
|
# register a dependency.
|
||||||
IkiWiki::add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
# Can't just return the linkmap here, since the htmlscrubber
|
# Can't just return the linkmap here, since the htmlscrubber
|
||||||
# scrubs out all <object> tags (with good reason!)
|
# scrubs out all <object> tags (with good reason!)
|
||||||
|
@ -49,9 +47,9 @@ sub genmap ($) { #{{{
|
||||||
|
|
||||||
# Get all the items to map.
|
# Get all the items to map.
|
||||||
my %mapitems = ();
|
my %mapitems = ();
|
||||||
foreach my $item (keys %IkiWiki::links) {
|
foreach my $item (keys %links) {
|
||||||
if (IkiWiki::pagespec_match($item, $params{pages})) {
|
if (pagespec_match($item, $params{pages})) {
|
||||||
my $link=IkiWiki::htmlpage($item);
|
my $link=htmlpage($item);
|
||||||
$link=IkiWiki::abs2rel($link, IkiWiki::dirname($params{page}));
|
$link=IkiWiki::abs2rel($link, IkiWiki::dirname($params{page}));
|
||||||
$mapitems{$item}=$link;
|
$mapitems{$item}=$link;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +57,7 @@ sub genmap ($) { #{{{
|
||||||
|
|
||||||
# Use ikiwiki's function to create the file, this makes sure needed
|
# Use ikiwiki's function to create the file, this makes sure needed
|
||||||
# subdirs are there and does some sanity checking.
|
# subdirs are there and does some sanity checking.
|
||||||
IkiWiki::writefile("$params{page}.png", $IkiWiki::config{destdir}, "");
|
writefile("$params{page}.png", $config{destdir}, "");
|
||||||
|
|
||||||
# Run dot to create the graphic and get the map data.
|
# Run dot to create the graphic and get the map data.
|
||||||
# TODO: should really add the png to renderedfiles and call
|
# TODO: should really add the png to renderedfiles and call
|
||||||
|
@ -69,7 +67,7 @@ sub genmap ($) { #{{{
|
||||||
my $pid;
|
my $pid;
|
||||||
while (1) {
|
while (1) {
|
||||||
eval {
|
eval {
|
||||||
$pid=open2(*IN, *OUT, "dot -Tpng -o '$IkiWiki::config{destdir}/$params{page}.png' -Tcmapx");
|
$pid=open2(*IN, *OUT, "dot -Tpng -o '$config{destdir}/$params{page}.png' -Tcmapx");
|
||||||
};
|
};
|
||||||
last unless $@;
|
last unless $@;
|
||||||
$tries--;
|
$tries--;
|
||||||
|
@ -88,7 +86,7 @@ sub genmap ($) { #{{{
|
||||||
if defined $params{width} and defined $params{height};
|
if defined $params{width} and defined $params{height};
|
||||||
foreach my $item (keys %mapitems) {
|
foreach my $item (keys %mapitems) {
|
||||||
print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
|
print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
|
||||||
foreach my $link (map { IkiWiki::bestlink($item, $_) } @{$IkiWiki::links{$item}}) {
|
foreach my $link (map { bestlink($item, $_) } @{$links{$item}}) {
|
||||||
print OUT "\"$item\" -> \"$link\";\n"
|
print OUT "\"$item\" -> \"$link\";\n"
|
||||||
if $mapitems{$link};
|
if $mapitems{$link};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "map",
|
hook(type => "preprocess", id => "map", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -22,12 +21,12 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
# Needs to update whenever a page is added or removed, so
|
# Needs to update whenever a page is added or removed, so
|
||||||
# register a dependency.
|
# register a dependency.
|
||||||
IkiWiki::add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
# Get all the items to map.
|
# Get all the items to map.
|
||||||
my @mapitems = ();
|
my @mapitems = ();
|
||||||
foreach my $page (keys %IkiWiki::links) {
|
foreach my $page (keys %links) {
|
||||||
if (IkiWiki::pagespec_match($page, $params{pages})) {
|
if (pagespec_match($page, $params{pages})) {
|
||||||
push @mapitems, $page;
|
push @mapitems, $page;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +49,7 @@ sub preprocess (@) { #{{{
|
||||||
}
|
}
|
||||||
$map .= "</li>\n" if $openli;
|
$map .= "</li>\n" if $openli;
|
||||||
$map .= "<li>"
|
$map .= "<li>"
|
||||||
.IkiWiki::htmllink($params{page}, $params{destpage}, $item) ."\n";
|
.htmllink($params{page}, $params{destpage}, $item) ."\n";
|
||||||
$openli=1;
|
$openli=1;
|
||||||
}
|
}
|
||||||
while ($indent > 0) {
|
while ($indent > 0) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "htmlize", id => "mdwn", call => \&htmlize);
|
hook(type => "htmlize", id => "mdwn", call => \&htmlize);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
my $markdown_loaded=0;
|
my $markdown_loaded=0;
|
||||||
|
@ -26,7 +26,7 @@ sub htmlize (@) { #{{{
|
||||||
eval q{use Markdown};
|
eval q{use Markdown};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
do "/usr/bin/markdown" ||
|
do "/usr/bin/markdown" ||
|
||||||
IkiWiki::error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
|
error("failed to load Markdown.pm perl module ($@) or /usr/bin/markdown ($!)");
|
||||||
}
|
}
|
||||||
$markdown_loaded=1;
|
$markdown_loaded=1;
|
||||||
require Encode;
|
require Encode;
|
||||||
|
|
|
@ -13,12 +13,9 @@ my %author;
|
||||||
my %authorurl;
|
my %authorurl;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "meta",
|
hook(type => "preprocess", id => "meta", call => \&preprocess);
|
||||||
call => \&preprocess);
|
hook(type => "filter", id => "meta", call => \&filter);
|
||||||
IkiWiki::hook(type => "filter", id => "meta",
|
hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
|
||||||
call => \&filter);
|
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "meta",
|
|
||||||
call => \&pagetemplate);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub filter (@) { #{{{
|
sub filter (@) { #{{{
|
||||||
|
@ -54,7 +51,7 @@ sub preprocess (@) { #{{{
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# hidden WikiLink
|
# hidden WikiLink
|
||||||
push @{$IkiWiki::links{$page}}, $value;
|
push @{$links{$page}}, $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($key eq 'title') {
|
elsif ($key eq 'title') {
|
||||||
|
|
|
@ -7,8 +7,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "orphans",
|
hook(type => "preprocess", id => "orphans", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -17,30 +16,30 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
# Needs to update whenever a page is added or removed, so
|
# Needs to update whenever a page is added or removed, so
|
||||||
# register a dependency.
|
# register a dependency.
|
||||||
IkiWiki::add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my %linkedto;
|
my %linkedto;
|
||||||
foreach my $p (keys %IkiWiki::links) {
|
foreach my $p (keys %links) {
|
||||||
map { $linkedto{IkiWiki::bestlink($p, $_)}=1 if length $_ }
|
map { $linkedto{bestlink($p, $_)}=1 if length $_ }
|
||||||
@{$IkiWiki::links{$p}};
|
@{$links{$p}};
|
||||||
}
|
}
|
||||||
|
|
||||||
my @orphans;
|
my @orphans;
|
||||||
foreach my $page (keys %IkiWiki::renderedfiles) {
|
foreach my $page (keys %renderedfiles) {
|
||||||
next if $linkedto{$page};
|
next if $linkedto{$page};
|
||||||
next unless IkiWiki::pagespec_match($page, $params{pages});
|
next unless pagespec_match($page, $params{pages});
|
||||||
# If the page has a link to some other page, it's
|
# If the page has a link to some other page, it's
|
||||||
# indirectly linked to a page via that page's backlinks.
|
# indirectly linked to a page via that page's backlinks.
|
||||||
next if grep {
|
next if grep {
|
||||||
length $_ &&
|
length $_ &&
|
||||||
($_ !~ /\/Discussion$/i || ! $IkiWiki::config{discussion}) &&
|
($_ !~ /\/Discussion$/i || ! $config{discussion}) &&
|
||||||
IkiWiki::bestlink($page, $_) !~ /^($page|)$/
|
bestlink($page, $_) !~ /^($page|)$/
|
||||||
} @{$IkiWiki::links{$page}};
|
} @{$links{$page}};
|
||||||
push @orphans, $page;
|
push @orphans, $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "All pages are linked to by other pages." unless @orphans;
|
return "All pages are linked to by other pages." unless @orphans;
|
||||||
return "<ul>\n".join("\n", map { "<li>".IkiWiki::htmllink($params{page}, $params{destpage}, $_, 1)."</li>" } sort @orphans)."</ul>\n";
|
return "<ul>\n".join("\n", map { "<li>".htmllink($params{page}, $params{destpage}, $_, 1)."</li>" } sort @orphans)."</ul>\n";
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
|
@ -7,8 +7,8 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "filter", id => "otl", call => \&filter);
|
hook(type => "filter", id => "otl", call => \&filter);
|
||||||
IkiWiki::hook(type => "htmlize", id => "otl", call => \&htmlize);
|
hook(type => "htmlize", id => "otl", call => \&htmlize);
|
||||||
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ sub filter (@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
# Munge up check boxes to look a little bit better. This is a hack.
|
# Munge up check boxes to look a little bit better. This is a hack.
|
||||||
my $checked=IkiWiki::htmllink($params{page}, $params{page},
|
my $checked=htmllink($params{page}, $params{page},
|
||||||
"smileys/star_on.png", 0, 0, "[X]");
|
"smileys/star_on.png", 0, 0, "[X]");
|
||||||
my $unchecked=IkiWiki::htmllink($params{page}, $params{page},
|
my $unchecked=htmllink($params{page}, $params{page},
|
||||||
"smileys/star_off.png", 0, 0, "[_]");
|
"smileys/star_off.png", 0, 0, "[_]");
|
||||||
$params{content}=~s/^(\s*)\[X\]\s/${1}$checked /mg;
|
$params{content}=~s/^(\s*)\[X\]\s/${1}$checked /mg;
|
||||||
$params{content}=~s/^(\s*)\[_\]\s/${1}$unchecked /mg;
|
$params{content}=~s/^(\s*)\[_\]\s/${1}$unchecked /mg;
|
||||||
|
@ -40,7 +40,7 @@ sub htmlize (@) { #{{{
|
||||||
unless (defined $pid) {
|
unless (defined $pid) {
|
||||||
$tries--;
|
$tries--;
|
||||||
if ($tries < 1) {
|
if ($tries < 1) {
|
||||||
IkiWiki::debug("failed to fork: $@");
|
debug("failed to fork: $@");
|
||||||
return $params{content};
|
return $params{content};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ sub htmlize (@) { #{{{
|
||||||
unless (defined $pid) {
|
unless (defined $pid) {
|
||||||
$tries--;
|
$tries--;
|
||||||
if ($tries < 1) {
|
if ($tries < 1) {
|
||||||
IkiWiki::debug("failed to fork: $@");
|
debug("failed to fork: $@");
|
||||||
print $params{content};
|
print $params{content};
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ sub htmlize (@) { #{{{
|
||||||
|
|
||||||
if (! $pid) {
|
if (! $pid) {
|
||||||
if (! exec 'otl2html', '-S', '/dev/null', '-T', '/dev/stdin') {
|
if (! exec 'otl2html', '-S', '/dev/null', '-T', '/dev/stdin') {
|
||||||
IkiWiki::debug("failed to run otl2html: $@");
|
debug("failed to run otl2html: $@");
|
||||||
print $params{content};
|
print $params{content};
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "pagecount",
|
hook(type => "preprocess", id => "pagecount", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -17,13 +16,13 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
# Needs to update count whenever a page is added or removed, so
|
# Needs to update count whenever a page is added or removed, so
|
||||||
# register a dependency.
|
# register a dependency.
|
||||||
IkiWiki::add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my @pages=keys %IkiWiki::pagesources;
|
my @pages=keys %pagesources;
|
||||||
return $#pages+1 if $params{pages} eq "*"; # optimisation
|
return $#pages+1 if $params{pages} eq "*"; # optimisation
|
||||||
my $count=0;
|
my $count=0;
|
||||||
foreach my $page (@pages) {
|
foreach my $page (@pages) {
|
||||||
$count++ if IkiWiki::pagespec_match($page, $params{pages});
|
$count++ if pagespec_match($page, $params{pages});
|
||||||
}
|
}
|
||||||
return $count;
|
return $count;
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
|
@ -18,8 +18,7 @@ use IkiWiki;
|
||||||
our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' );
|
our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' );
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "pagestats",
|
hook(type => "preprocess", id => "pagestats", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -29,12 +28,12 @@ sub preprocess (@) { #{{{
|
||||||
|
|
||||||
# Needs to update whenever a page is added or removed, so
|
# Needs to update whenever a page is added or removed, so
|
||||||
# register a dependency.
|
# register a dependency.
|
||||||
IkiWiki::add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my %counts;
|
my %counts;
|
||||||
my $max = 0;
|
my $max = 0;
|
||||||
foreach my $page (keys %IkiWiki::links) {
|
foreach my $page (keys %links) {
|
||||||
if (IkiWiki::pagespec_match($page, $params{pages})) {
|
if (pagespec_match($page, $params{pages})) {
|
||||||
my @bl = IkiWiki::backlinks($page);
|
my @bl = IkiWiki::backlinks($page);
|
||||||
$counts{$page} = scalar(@bl);
|
$counts{$page} = scalar(@bl);
|
||||||
$max = $counts{$page} if $counts{$page} > $max;
|
$max = $counts{$page} if $counts{$page} > $max;
|
||||||
|
@ -45,7 +44,7 @@ sub preprocess (@) { #{{{
|
||||||
return "<table class='pageStats'>\n".
|
return "<table class='pageStats'>\n".
|
||||||
join("\n", map {
|
join("\n", map {
|
||||||
"<tr><td>".
|
"<tr><td>".
|
||||||
IkiWiki::htmllink($params{page}, $params{destpage}, $_, 1).
|
htmllink($params{page}, $params{destpage}, $_, 1).
|
||||||
"</td><td>".$counts{$_}."</td></tr>"
|
"</td><td>".$counts{$_}."</td></tr>"
|
||||||
}
|
}
|
||||||
sort { $counts{$b} <=> $counts{$a} } keys %counts).
|
sort { $counts{$b} <=> $counts{$a} } keys %counts).
|
||||||
|
@ -57,7 +56,7 @@ sub preprocess (@) { #{{{
|
||||||
foreach my $page (sort keys %counts) {
|
foreach my $page (sort keys %counts) {
|
||||||
my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
|
my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
|
||||||
$res .= "<span class=\"$class\">".
|
$res .= "<span class=\"$class\">".
|
||||||
IkiWiki::htmllink($params{page}, $params{destpage}, $page).
|
htmllink($params{page}, $params{destpage}, $page).
|
||||||
"</span>\n";
|
"</span>\n";
|
||||||
}
|
}
|
||||||
$res .= "</div>\n";
|
$res .= "</div>\n";
|
||||||
|
|
|
@ -11,8 +11,7 @@ use IkiWiki;
|
||||||
use File::Find;
|
use File::Find;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "polygen",
|
hook(type => "preprocess", id => "polygen", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
|
|
@ -36,7 +36,7 @@ print html[html.find('<body>')+6:html.find('</body>')].strip();
|
||||||
";
|
";
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "htmlize", id => "rst", call => \&htmlize);
|
hook(type => "htmlize", id => "rst", call => \&htmlize);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub htmlize (@) { #{{{
|
sub htmlize (@) { #{{{
|
||||||
|
@ -54,7 +54,7 @@ sub htmlize (@) { #{{{
|
||||||
last unless $@;
|
last unless $@;
|
||||||
$tries--;
|
$tries--;
|
||||||
if ($tries < 1) {
|
if ($tries < 1) {
|
||||||
IkiWiki::debug("failed to run python to convert rst: $@");
|
debug("failed to run python to convert rst: $@");
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,22 +7,22 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "checkconfig", id => "hyperestraier",
|
hook(type => "checkconfig", id => "hyperestraier",
|
||||||
call => \&checkconfig);
|
call => \&checkconfig);
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "hyperestraier",
|
hook(type => "pagetemplate", id => "hyperestraier",
|
||||||
call => \&pagetemplate);
|
call => \&pagetemplate);
|
||||||
IkiWiki::hook(type => "delete", id => "hyperestraier",
|
hook(type => "delete", id => "hyperestraier",
|
||||||
call => \&delete);
|
call => \&delete);
|
||||||
IkiWiki::hook(type => "change", id => "hyperestraier",
|
hook(type => "change", id => "hyperestraier",
|
||||||
call => \&change);
|
call => \&change);
|
||||||
IkiWiki::hook(type => "cgi", id => "hyperestraier",
|
hook(type => "cgi", id => "hyperestraier",
|
||||||
call => \&cgi);
|
call => \&cgi);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub checkconfig () { #{{{
|
sub checkconfig () { #{{{
|
||||||
foreach my $required (qw(url cgiurl)) {
|
foreach my $required (qw(url cgiurl)) {
|
||||||
if (! length $IkiWiki::config{$required}) {
|
if (! length $config{$required}) {
|
||||||
IkiWiki::error("Must specify $required when using the search plugin\n");
|
error("Must specify $required when using the search plugin\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
@ -36,8 +36,8 @@ sub pagetemplate (@) { #{{{
|
||||||
# Add search box to page header.
|
# Add search box to page header.
|
||||||
if ($template->query(name => "searchform")) {
|
if ($template->query(name => "searchform")) {
|
||||||
if (! defined $form) {
|
if (! defined $form) {
|
||||||
my $searchform = IkiWiki::template("searchform.tmpl", blind_cache => 1);
|
my $searchform = template("searchform.tmpl", blind_cache => 1);
|
||||||
$searchform->param(searchaction => $IkiWiki::config{cgiurl});
|
$searchform->param(searchaction => $config{cgiurl});
|
||||||
$form=$searchform->output;
|
$form=$searchform->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,19 +46,19 @@ sub pagetemplate (@) { #{{{
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub delete (@) { #{{{
|
sub delete (@) { #{{{
|
||||||
IkiWiki::debug("cleaning hyperestraier search index");
|
debug("cleaning hyperestraier search index");
|
||||||
IkiWiki::estcmd("purge -cl");
|
estcmd("purge -cl");
|
||||||
IkiWiki::estcfg();
|
estcfg();
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub change (@) { #{{{
|
sub change (@) { #{{{
|
||||||
IkiWiki::debug("updating hyperestraier search index");
|
debug("updating hyperestraier search index");
|
||||||
IkiWiki::estcmd("gather -cm -bc -cl -sd",
|
estcmd("gather -cm -bc -cl -sd",
|
||||||
map {
|
map {
|
||||||
Encode::encode_utf8($IkiWiki::config{destdir}."/".$IkiWiki::renderedfiles{IkiWiki::pagename($_)})
|
Encode::encode_utf8($config{destdir}."/".$renderedfiles{pagename($_)})
|
||||||
} @_
|
} @_
|
||||||
);
|
);
|
||||||
IkiWiki::estcfg();
|
estcfg();
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub cgi ($) { #{{{
|
sub cgi ($) { #{{{
|
||||||
|
@ -66,25 +66,22 @@ sub cgi ($) { #{{{
|
||||||
|
|
||||||
if (defined $cgi->param('phrase')) {
|
if (defined $cgi->param('phrase')) {
|
||||||
# only works for GET requests
|
# only works for GET requests
|
||||||
chdir("$IkiWiki::config{wikistatedir}/hyperestraier") || IkiWiki::error("chdir: $!");
|
chdir("$config{wikistatedir}/hyperestraier") || error("chdir: $!");
|
||||||
exec("./".IkiWiki::basename($IkiWiki::config{cgiurl})) || IkiWiki::error("estseek.cgi failed");
|
exec("./".IkiWiki::basename($config{cgiurl})) || error("estseek.cgi failed");
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
# Easier to keep these in the IkiWiki namespace.
|
|
||||||
package IkiWiki;
|
|
||||||
|
|
||||||
my $configured=0;
|
my $configured=0;
|
||||||
sub estcfg () { #{{{
|
sub estcfg () { #{{{
|
||||||
return if $configured;
|
return if $configured;
|
||||||
$configured=1;
|
$configured=1;
|
||||||
|
|
||||||
my $estdir="$config{wikistatedir}/hyperestraier";
|
my $estdir="$config{wikistatedir}/hyperestraier";
|
||||||
my $cgi=basename($config{cgiurl});
|
my $cgi=IkiWiki::basename($config{cgiurl});
|
||||||
$cgi=~s/\..*$//;
|
$cgi=~s/\..*$//;
|
||||||
open(TEMPLATE, ">$estdir/$cgi.tmpl") ||
|
open(TEMPLATE, ">$estdir/$cgi.tmpl") ||
|
||||||
error("write $estdir/$cgi.tmpl: $!");
|
error("write $estdir/$cgi.tmpl: $!");
|
||||||
print TEMPLATE misctemplate("search",
|
print TEMPLATE IkiWiki::misctemplate("search",
|
||||||
"<!--ESTFORM-->\n\n<!--ESTRESULT-->\n\n<!--ESTINFO-->\n\n");
|
"<!--ESTFORM-->\n\n<!--ESTRESULT-->\n\n<!--ESTINFO-->\n\n");
|
||||||
close TEMPLATE;
|
close TEMPLATE;
|
||||||
open(TEMPLATE, ">$estdir/$cgi.conf") ||
|
open(TEMPLATE, ">$estdir/$cgi.conf") ||
|
||||||
|
@ -94,12 +91,12 @@ sub estcfg () { #{{{
|
||||||
$template->param(
|
$template->param(
|
||||||
index => $estdir,
|
index => $estdir,
|
||||||
tmplfile => "$estdir/$cgi.tmpl",
|
tmplfile => "$estdir/$cgi.tmpl",
|
||||||
destdir => abs_path($config{destdir}),
|
destdir => IkiWiki::abs_path($config{destdir}),
|
||||||
url => $config{url},
|
url => $config{url},
|
||||||
);
|
);
|
||||||
print TEMPLATE $template->output;
|
print TEMPLATE $template->output;
|
||||||
close TEMPLATE;
|
close TEMPLATE;
|
||||||
$cgi="$estdir/".basename($config{cgiurl});
|
$cgi="$estdir/".IkiWiki::basename($config{cgiurl});
|
||||||
unlink($cgi);
|
unlink($cgi);
|
||||||
symlink("/usr/lib/estraier/estseek.cgi", $cgi) ||
|
symlink("/usr/lib/estraier/estseek.cgi", $cgi) ||
|
||||||
error("symlink $cgi: $!");
|
error("symlink $cgi: $!");
|
||||||
|
|
|
@ -9,24 +9,23 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "sidebar",
|
hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
|
||||||
call => \&pagetemplate);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub sidebar_content ($) { #{{{
|
sub sidebar_content ($) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
|
|
||||||
my $sidebar_page=IkiWiki::bestlink($page, "sidebar") || return;
|
my $sidebar_page=bestlink($page, "sidebar") || return;
|
||||||
my $sidebar_file=$IkiWiki::pagesources{$sidebar_page} || return;
|
my $sidebar_file=$pagesources{$sidebar_page} || return;
|
||||||
my $sidebar_type=IkiWiki::pagetype($sidebar_file);
|
my $sidebar_type=pagetype($sidebar_file);
|
||||||
|
|
||||||
if (defined $sidebar_type) {
|
if (defined $sidebar_type) {
|
||||||
# FIXME: This isn't quite right; it won't take into account
|
# FIXME: This isn't quite right; it won't take into account
|
||||||
# adding a new sidebar page. So adding such a page
|
# adding a new sidebar page. So adding such a page
|
||||||
# currently requires a wiki rebuild.
|
# currently requires a wiki rebuild.
|
||||||
IkiWiki::add_depends($page, $sidebar_page);
|
add_depends($page, $sidebar_page);
|
||||||
|
|
||||||
my $content=IkiWiki::readfile(IkiWiki::srcfile($sidebar_file));
|
my $content=readfile(srcfile($sidebar_file));
|
||||||
return unless length $content;
|
return unless length $content;
|
||||||
return IkiWiki::htmlize($page, $sidebar_type,
|
return IkiWiki::htmlize($page, $sidebar_type,
|
||||||
IkiWiki::linkify($sidebar_page, $page,
|
IkiWiki::linkify($sidebar_page, $page,
|
||||||
|
|
|
@ -9,38 +9,26 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "getopt", id => "skeleton",
|
hook(type => "getopt", id => "skeleton", call => \&getopt);
|
||||||
call => \&getopt);
|
hook(type => "checkconfig", id => "skeleton", call => \&checkconfig);
|
||||||
IkiWiki::hook(type => "checkconfig", id => "skeleton",
|
hook(type => "preprocess", id => "skeleton", call => \&preprocess);
|
||||||
call => \&checkconfig);
|
hook(type => "filter", id => "skeleton", call => \&filter);
|
||||||
IkiWiki::hook(type => "preprocess", id => "skeleton",
|
hook(type => "htmlize", id => "skeleton", call => \&htmlize);
|
||||||
call => \&preprocess);
|
hook(type => "sanitize", id => "skeleton", call => \&sanitize);
|
||||||
IkiWiki::hook(type => "filter", id => "skeleton",
|
hook(type => "format", id => "skeleton", call => \&format);
|
||||||
call => \&filter);
|
hook(type => "pagetemplate", id => "skeleton", call => \&pagetemplate);
|
||||||
IkiWiki::hook(type => "htmlize", id => "skeleton",
|
hook(type => "delete", id => "skeleton", call => \&delete);
|
||||||
call => \&htmlize);
|
hook(type => "change", id => "skeleton", call => \&change);
|
||||||
IkiWiki::hook(type => "sanitize", id => "skeleton",
|
hook(type => "cgi", id => "skeleton", call => \&cgi);
|
||||||
call => \&sanitize);
|
hook(type => "savestate", id => "savestate", call => \&savestate);
|
||||||
IkiWiki::hook(type => "format", id => "skeleton",
|
|
||||||
call => \&format);
|
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "skeleton",
|
|
||||||
call => \&pagetemplate);
|
|
||||||
IkiWiki::hook(type => "delete", id => "skeleton",
|
|
||||||
call => \&delete);
|
|
||||||
IkiWiki::hook(type => "change", id => "skeleton",
|
|
||||||
call => \&change);
|
|
||||||
IkiWiki::hook(type => "cgi", id => "skeleton",
|
|
||||||
call => \&cgi);
|
|
||||||
IkiWiki::hook(type => "savestate", id => "savestate",
|
|
||||||
call => \&savestate);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub getopt () { #{{{
|
sub getopt () { #{{{
|
||||||
IkiWiki::debug("skeleton plugin getopt");
|
debug("skeleton plugin getopt");
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub checkconfig () { #{{{
|
sub checkconfig () { #{{{
|
||||||
IkiWiki::debug("skeleton plugin checkconfig");
|
debug("skeleton plugin checkconfig");
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -52,7 +40,7 @@ sub preprocess (@) { #{{{
|
||||||
sub filter (@) { #{{{
|
sub filter (@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin running as filter");
|
debug("skeleton plugin running as filter");
|
||||||
|
|
||||||
return $params{content};
|
return $params{content};
|
||||||
} # }}}
|
} # }}}
|
||||||
|
@ -60,7 +48,7 @@ sub filter (@) { #{{{
|
||||||
sub htmlize (@) { #{{{
|
sub htmlize (@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin running as htmlize");
|
debug("skeleton plugin running as htmlize");
|
||||||
|
|
||||||
return $params{content};
|
return $params{content};
|
||||||
} # }}}
|
} # }}}
|
||||||
|
@ -68,7 +56,7 @@ sub htmlize (@) { #{{{
|
||||||
sub sanitize (@) { #{{{
|
sub sanitize (@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin running as a sanitizer");
|
debug("skeleton plugin running as a sanitizer");
|
||||||
|
|
||||||
return $params{content};
|
return $params{content};
|
||||||
} # }}}
|
} # }}}
|
||||||
|
@ -76,7 +64,7 @@ sub sanitize (@) { #{{{
|
||||||
sub format (@) { #{{{
|
sub format (@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin running as a formatter");
|
debug("skeleton plugin running as a formatter");
|
||||||
|
|
||||||
return $params{content};
|
return $params{content};
|
||||||
} # }}}
|
} # }}}
|
||||||
|
@ -86,29 +74,29 @@ sub pagetemplate (@) { #{{{
|
||||||
my $page=$params{page};
|
my $page=$params{page};
|
||||||
my $template=$params{template};
|
my $template=$params{template};
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin running as a pagetemplate hook");
|
debug("skeleton plugin running as a pagetemplate hook");
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub delete (@) { #{{{
|
sub delete (@) { #{{{
|
||||||
my @files=@_;
|
my @files=@_;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin told that files were deleted: @files");
|
debug("skeleton plugin told that files were deleted: @files");
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub change (@) { #{{{
|
sub change (@) { #{{{
|
||||||
my @files=@_;
|
my @files=@_;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin told that changed files were rendered: @files");
|
debug("skeleton plugin told that changed files were rendered: @files");
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub cgi ($) { #{{{
|
sub cgi ($) { #{{{
|
||||||
my $cgi=shift;
|
my $cgi=shift;
|
||||||
|
|
||||||
IkiWiki::debug("skeleton plugin running in cgi");
|
debug("skeleton plugin running in cgi");
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub savestate () { #{{{
|
sub savestate () { #{{{
|
||||||
IkiWiki::debug("skeleton plugin running in savestate");
|
debug("skeleton plugin running in savestate");
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
|
@ -9,33 +9,33 @@ my %smileys;
|
||||||
my $smiley_regexp;
|
my $smiley_regexp;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "checkconfig", id => "smiley", call => \&setup);
|
hook(type => "checkconfig", id => "smiley", call => \&setup);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub setup () { #{{{
|
sub setup () { #{{{
|
||||||
my $list=IkiWiki::readfile(IkiWiki::srcfile("smileys.mdwn"));
|
my $list=readfile(srcfile("smileys.mdwn"));
|
||||||
while ($list =~ m/^\s*\*\s+\\([^\s]+)\s+\[\[([^]]+)\]\]/mg) {
|
while ($list =~ m/^\s*\*\s+\\([^\s]+)\s+\[\[([^]]+)\]\]/mg) {
|
||||||
$smileys{$1}=$2;
|
$smileys{$1}=$2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! %smileys) {
|
if (! %smileys) {
|
||||||
IkiWiki::debug("failed to parse any smileys, disabling plugin");
|
debug("failed to parse any smileys, disabling plugin");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IkiWiki::hook(type => "filter", id => "smiley", call => \&filter);
|
hook(type => "filter", id => "smiley", call => \&filter);
|
||||||
# sort and reverse so that substrings come after longer strings
|
# sort and reverse so that substrings come after longer strings
|
||||||
# that contain them, in most cases.
|
# that contain them, in most cases.
|
||||||
$smiley_regexp='('.join('|', map { quotemeta }
|
$smiley_regexp='('.join('|', map { quotemeta }
|
||||||
reverse sort keys %smileys).')';
|
reverse sort keys %smileys).')';
|
||||||
#IkiWiki::debug($smiley_regexp);
|
#debug($smiley_regexp);
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub filter (@) { #{{{
|
sub filter (@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
$params{content} =~ s{(?<=\s)(\\?)$smiley_regexp(?=\s)}{
|
$params{content} =~ s{(?<=\s)(\\?)$smiley_regexp(?=\s)}{
|
||||||
$1 ? $2 : IkiWiki::htmllink($params{page}, $params{page}, $smileys{$2}, 0, 0, $2)
|
$1 ? $2 : htmllink($params{page}, $params{page}, $smileys{$2}, 0, 0, $2)
|
||||||
}egs;
|
}egs;
|
||||||
|
|
||||||
return $params{content};
|
return $params{content};
|
||||||
|
|
|
@ -9,26 +9,23 @@ use IkiWiki;
|
||||||
my %tags;
|
my %tags;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "getopt", id => "tag",
|
hook(type => "getopt", id => "tag", call => \&getopt);
|
||||||
call => \&getopt);
|
hook(type => "preprocess", id => "tag", call => \&preprocess);
|
||||||
IkiWiki::hook(type => "preprocess", id => "tag",
|
hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
|
||||||
call => \&preprocess);
|
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "tag",
|
|
||||||
call => \&pagetemplate);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub getopt () { #{{{
|
sub getopt () { #{{{
|
||||||
eval q{use Getopt::Long};
|
eval q{use Getopt::Long};
|
||||||
Getopt::Long::Configure('pass_through');
|
Getopt::Long::Configure('pass_through');
|
||||||
GetOptions("tagbase=s" => \$IkiWiki::config{tagbase});
|
GetOptions("tagbase=s" => \$config{tagbase});
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub tagpage ($) { #{{{
|
sub tagpage ($) { #{{{
|
||||||
my $tag=shift;
|
my $tag=shift;
|
||||||
|
|
||||||
if (exists $IkiWiki::config{tagbase} &&
|
if (exists $config{tagbase} &&
|
||||||
defined $IkiWiki::config{tagbase}) {
|
defined $config{tagbase}) {
|
||||||
$tag=$IkiWiki::config{tagbase}."/".$tag;
|
$tag=$config{tagbase}."/".$tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tag;
|
return $tag;
|
||||||
|
@ -47,7 +44,7 @@ sub preprocess (@) { #{{{
|
||||||
foreach my $tag (keys %params) {
|
foreach my $tag (keys %params) {
|
||||||
push @{$tags{$page}}, $tag;
|
push @{$tags{$page}}, $tag;
|
||||||
# hidden WikiLink
|
# hidden WikiLink
|
||||||
push @{$IkiWiki::links{$page}}, tagpage($tag);
|
push @{$links{$page}}, tagpage($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
@ -61,7 +58,7 @@ sub pagetemplate (@) { #{{{
|
||||||
|
|
||||||
$template->param(tags => [
|
$template->param(tags => [
|
||||||
map {
|
map {
|
||||||
link => IkiWiki::htmllink($page, $destpage, tagpage($_))
|
link => htmllink($page, $destpage, tagpage($_))
|
||||||
}, @{$tags{$page}}
|
}, @{$tags{$page}}
|
||||||
]) if exists $tags{$page} && @{$tags{$page}} && $template->query(name => "tags");
|
]) if exists $tags{$page} && @{$tags{$page}} && $template->query(name => "tags");
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,7 @@ use HTML::Template;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "template",
|
hook(type => "preprocess", id => "template", call => \&preprocess);
|
||||||
call => \&preprocess);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub preprocess (@) { #{{{
|
sub preprocess (@) { #{{{
|
||||||
|
@ -21,11 +20,11 @@ sub preprocess (@) { #{{{
|
||||||
}
|
}
|
||||||
|
|
||||||
my $template_page="templates/$params{id}";
|
my $template_page="templates/$params{id}";
|
||||||
IkiWiki::add_depends($params{page}, $template_page);
|
add_depends($params{page}, $template_page);
|
||||||
|
|
||||||
my $template_file=$IkiWiki::pagesources{$template_page};
|
my $template_file=$pagesources{$template_page};
|
||||||
return "[[template ".
|
return "[[template ".
|
||||||
IkiWiki::htmllink($params{page}, $params{destpage}, $template_page).
|
htmllink($params{page}, $params{destpage}, $template_page).
|
||||||
" not found]]"
|
" not found]]"
|
||||||
unless defined $template_file;
|
unless defined $template_file;
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ sub preprocess (@) { #{{{
|
||||||
my $text_ref = shift;
|
my $text_ref = shift;
|
||||||
$$text_ref=&Encode::decode_utf8($$text_ref);
|
$$text_ref=&Encode::decode_utf8($$text_ref);
|
||||||
},
|
},
|
||||||
filename => IkiWiki::srcfile($template_file),
|
filename => srcfile($template_file),
|
||||||
die_on_bad_params => 0,
|
die_on_bad_params => 0,
|
||||||
no_includes => 1,
|
no_includes => 1,
|
||||||
blind_cache => 1,
|
blind_cache => 1,
|
||||||
|
|
|
@ -8,10 +8,8 @@ use IkiWiki;
|
||||||
use HTML::Parser;
|
use HTML::Parser;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "preprocess", id => "toc",
|
hook(type => "preprocess", id => "toc", call => \&preprocess);
|
||||||
call => \&preprocess);
|
hook(type => "format", id => "toc", call => \&format);
|
||||||
IkiWiki::hook(type => "format", id => "toc",
|
|
||||||
call => \&format);
|
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
my %tocpages;
|
my %tocpages;
|
||||||
|
|
|
@ -8,7 +8,7 @@ use IkiWiki;
|
||||||
use Text::WikiFormat;
|
use Text::WikiFormat;
|
||||||
|
|
||||||
sub import { #{{{
|
sub import { #{{{
|
||||||
IkiWiki::hook(type => "htmlize", id => "wiki", call => \&htmlize);
|
hook(type => "htmlize", id => "wiki", call => \&htmlize);
|
||||||
} # }}}
|
} # }}}
|
||||||
|
|
||||||
sub htmlize (@) { #{{{
|
sub htmlize (@) { #{{{
|
||||||
|
|
|
@ -48,7 +48,7 @@ sub _safe_git (&@) { #{{{
|
||||||
return wantarray ? @lines : ($? == 0);
|
return wantarray ? @lines : ($? == 0);
|
||||||
}
|
}
|
||||||
# Convenient wrappers.
|
# Convenient wrappers.
|
||||||
sub run_or_die ($@) { _safe_git(\&IkiWiki::error, @_) }
|
sub run_or_die ($@) { _safe_git(\&error, @_) }
|
||||||
sub run_or_cry ($@) { _safe_git(sub { warn @_ }, @_) }
|
sub run_or_cry ($@) { _safe_git(sub { warn @_ }, @_) }
|
||||||
sub run_or_non ($@) { _safe_git(undef, @_) }
|
sub run_or_non ($@) { _safe_git(undef, @_) }
|
||||||
#}}}
|
#}}}
|
||||||
|
|
|
@ -7,44 +7,6 @@ use strict;
|
||||||
use IkiWiki;
|
use IkiWiki;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
sub linkify ($$$) { #{{{
|
|
||||||
my $lpage=shift; # the page containing the links
|
|
||||||
my $page=shift; # the page the link will end up on (different for inline)
|
|
||||||
my $content=shift;
|
|
||||||
|
|
||||||
$content =~ s{(\\?)$config{wiki_link_regexp}}{
|
|
||||||
$2 ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), 0, 0, pagetitle($2)))
|
|
||||||
: ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3)))
|
|
||||||
}eg;
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
} #}}}
|
|
||||||
|
|
||||||
sub htmlize ($$$) { #{{{
|
|
||||||
my $page=shift;
|
|
||||||
my $type=shift;
|
|
||||||
my $content=shift;
|
|
||||||
|
|
||||||
if (exists $hooks{htmlize}{$type}) {
|
|
||||||
$content=$hooks{htmlize}{$type}{call}->(
|
|
||||||
page => $page,
|
|
||||||
content => $content,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
error("htmlization of $type not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
run_hooks(sanitize => sub {
|
|
||||||
$content=shift->(
|
|
||||||
page => $page,
|
|
||||||
content => $content,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
} #}}}
|
|
||||||
|
|
||||||
sub backlinks ($) { #{{{
|
sub backlinks ($) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
|
|
||||||
|
@ -91,80 +53,6 @@ sub parentlinks ($) { #{{{
|
||||||
return @ret;
|
return @ret;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
my %preprocessing;
|
|
||||||
sub preprocess ($$$) { #{{{
|
|
||||||
my $page=shift; # the page the data comes from
|
|
||||||
my $destpage=shift; # the page the data will appear in (different for inline)
|
|
||||||
my $content=shift;
|
|
||||||
|
|
||||||
my $handle=sub {
|
|
||||||
my $escape=shift;
|
|
||||||
my $command=shift;
|
|
||||||
my $params=shift;
|
|
||||||
if (length $escape) {
|
|
||||||
return "[[$command $params]]";
|
|
||||||
}
|
|
||||||
elsif (exists $hooks{preprocess}{$command}) {
|
|
||||||
# Note: preserve order of params, some plugins may
|
|
||||||
# consider it significant.
|
|
||||||
my @params;
|
|
||||||
while ($params =~ /(?:(\w+)=)?(?:"""(.*?)"""|"([^"]+)"|(\S+))(?:\s+|$)/sg) {
|
|
||||||
my $key=$1;
|
|
||||||
my $val;
|
|
||||||
if (defined $2) {
|
|
||||||
$val=$2;
|
|
||||||
$val=~s/\r\n/\n/mg;
|
|
||||||
$val=~s/^\n+//g;
|
|
||||||
$val=~s/\n+$//g;
|
|
||||||
}
|
|
||||||
elsif (defined $3) {
|
|
||||||
$val=$3;
|
|
||||||
}
|
|
||||||
elsif (defined $4) {
|
|
||||||
$val=$4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined $key) {
|
|
||||||
push @params, $key, $val;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
push @params, $val, '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($preprocessing{$page}++ > 3) {
|
|
||||||
# Avoid loops of preprocessed pages preprocessing
|
|
||||||
# other pages that preprocess them, etc.
|
|
||||||
return "[[$command preprocessing loop detected on $page at depth $preprocessing{$page}]]";
|
|
||||||
}
|
|
||||||
my $ret=$hooks{preprocess}{$command}{call}->(
|
|
||||||
@params,
|
|
||||||
page => $page,
|
|
||||||
destpage => $destpage,
|
|
||||||
);
|
|
||||||
$preprocessing{$page}--;
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "[[$command $params]]";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$content =~ s{(\\?)\[\[(\w+)\s+((?:(?:\w+=)?(?:""".*?"""|"[^"]+"|[^\s\]]+)\s*)*)\]\]}{$handle->($1, $2, $3)}seg;
|
|
||||||
return $content;
|
|
||||||
} #}}}
|
|
||||||
|
|
||||||
sub add_depends ($$) { #{{{
|
|
||||||
my $page=shift;
|
|
||||||
my $pagespec=shift;
|
|
||||||
|
|
||||||
if (! exists $depends{$page}) {
|
|
||||||
$depends{$page}=$pagespec;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$depends{$page}=pagespec_merge($depends{$page}, $pagespec);
|
|
||||||
}
|
|
||||||
} # }}}
|
|
||||||
|
|
||||||
sub genpage ($$$) { #{{{
|
sub genpage ($$$) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $content=shift;
|
my $content=shift;
|
||||||
|
@ -236,16 +124,6 @@ sub check_overwrite ($$) { #{{{
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub displaytime ($) { #{{{
|
|
||||||
my $time=shift;
|
|
||||||
|
|
||||||
eval q{use POSIX};
|
|
||||||
# strftime doesn't know about encodings, so make sure
|
|
||||||
# its output is properly treated as utf8
|
|
||||||
return decode_utf8(POSIX::strftime(
|
|
||||||
$config{timeformat}, localtime($time)));
|
|
||||||
} #}}}
|
|
||||||
|
|
||||||
sub mtime ($) { #{{{
|
sub mtime ($) { #{{{
|
||||||
my $file=shift;
|
my $file=shift;
|
||||||
|
|
||||||
|
@ -270,17 +148,6 @@ sub findlinks ($$) { #{{{
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub filter ($$) {
|
|
||||||
my $page=shift;
|
|
||||||
my $content=shift;
|
|
||||||
|
|
||||||
run_hooks(filter => sub {
|
|
||||||
$content=shift->(page => $page, content => $content);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub render ($) { #{{{
|
sub render ($) { #{{{
|
||||||
my $file=shift;
|
my $file=shift;
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,25 @@ ikiwiki (1.27) UNRELEASED; urgency=low
|
||||||
* Add a googlecalendar plugin. A bit special-purpose, but it shows
|
* Add a googlecalendar plugin. A bit special-purpose, but it shows
|
||||||
one way to to deal with user-supplied content that could cause XSS
|
one way to to deal with user-supplied content that could cause XSS
|
||||||
issues w/o the htmlscrubber, and won't survive the scrubber.
|
issues w/o the htmlscrubber, and won't survive the scrubber.
|
||||||
|
* Work on firming up the plugin interface:
|
||||||
|
- Plugins should not need to load IkiWiki::Render to get commonly
|
||||||
|
used functions, so moved some functions from there to IkiWiki.
|
||||||
|
- Picked out the set of functions and variables that most plugins
|
||||||
|
use, documented them, and made IkiWiki export them by default,
|
||||||
|
like a proper perl module should.
|
||||||
|
- Use the other functions at your own risk.
|
||||||
|
- This is not quite complete, I still have to decide whether to
|
||||||
|
export some other things.
|
||||||
|
* Changed all plugins included in ikiwiki to not use "IkiWiki::" when
|
||||||
|
referring to stuff now exported by the IkiWiki module.
|
||||||
|
* Anyone with a third-party ikiwiki plugin is strongly enrouraged
|
||||||
|
to make like changes to it and avoid use of non-exported symboles from
|
||||||
|
"IkiWiki::".
|
||||||
|
* Link debian/changelog and debian/news to NEWS and CHANGELOG.
|
||||||
|
* Support hyperestradier version 1.4.2, which adds a new required phraseform
|
||||||
|
setting.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Sat, 9 Sep 2006 03:00:45 -0400
|
-- Joey Hess <joeyh@debian.org> Sat, 9 Sep 2006 18:38:19 -0400
|
||||||
|
|
||||||
ikiwiki (1.26) unstable; urgency=low
|
ikiwiki (1.26) unstable; urgency=low
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,13 @@ being edited.
|
||||||
|
|
||||||
## Registering plugins
|
## Registering plugins
|
||||||
|
|
||||||
Plugins should, when imported, call IkiWiki::hook to hook into ikiwiki's
|
All plugins should `use IkiWiki` to import the ikiwiki plugin interface.
|
||||||
|
|
||||||
|
Plugins should, when imported, call `hook()` to hook into ikiwiki's
|
||||||
processing. The function uses named parameters, and use varies depending on
|
processing. The function uses named parameters, and use varies depending on
|
||||||
the type of plugin being registered. Note that a plugin can call the
|
the type of hook being registered -- see below. Note that a plugin can call
|
||||||
function more than once to register multiple hooks. All calls to
|
the function more than once to register multiple hooks. All calls to
|
||||||
IkiWiki::hook should be passed a "type" parameter, which gives the type of
|
`hook()` should be passed a "type" parameter, which gives the type of
|
||||||
hook, a "id" paramter, which should be a unique string for this plugin, and
|
hook, a "id" paramter, which should be a unique string for this plugin, and
|
||||||
a "call" parameter, which is a reference to a function to call for the
|
a "call" parameter, which is a reference to a function to call for the
|
||||||
hook.
|
hook.
|
||||||
|
@ -34,29 +36,29 @@ In roughly the order they are called.
|
||||||
|
|
||||||
### getopt
|
### getopt
|
||||||
|
|
||||||
IkiWiki::hook(type => "getopt", id => "foo", call => \&getopt);
|
hook(type => "getopt", id => "foo", call => \&getopt);
|
||||||
|
|
||||||
This allows for plugins to perform their own processing of command-line
|
This allows for plugins to perform their own processing of command-line
|
||||||
options and so add options to the ikiwiki command line. It's called during
|
options and so add options to the ikiwiki command line. It's called during
|
||||||
command line processing, with @ARGV full of any options that ikiwiki was
|
command line processing, with @ARGV full of any options that ikiwiki was
|
||||||
not able to process on its own. The function should process any options it
|
not able to process on its own. The function should process any options it
|
||||||
can, removing them from @ARGV, and probably recording the configuration
|
can, removing them from @ARGV, and probably recording the configuration
|
||||||
settings in %IkiWiki::config. It should take care not to abort if it sees
|
settings in %config. It should take care not to abort if it sees
|
||||||
an option it cannot process, and should just skip over those options and
|
an option it cannot process, and should just skip over those options and
|
||||||
leave them in @ARGV.
|
leave them in @ARGV.
|
||||||
|
|
||||||
### checkconfig
|
### checkconfig
|
||||||
|
|
||||||
IkiWiki::hook(type => "checkconfig", id => "foo", call => \&checkconfig);
|
hook(type => "checkconfig", id => "foo", call => \&checkconfig);
|
||||||
|
|
||||||
This is useful if the plugin needs to check for or modify ikiwiki's
|
This is useful if the plugin needs to check for or modify ikiwiki's
|
||||||
configuration. It's called early in the startup process. The
|
configuration. It's called early in the startup process. The
|
||||||
function is passed no values. It's ok for the function to call
|
function is passed no values. It's ok for the function to call
|
||||||
IkiWiki::error if something isn't configured right.
|
`error()` if something isn't configured right.
|
||||||
|
|
||||||
### filter
|
### filter
|
||||||
|
|
||||||
IkiWiki::hook(type => "filter", id => "foo", call => \&filter);
|
hook(type => "filter", id => "foo", call => \&filter);
|
||||||
|
|
||||||
Runs on the raw source of a page, before anything else touches it, and can
|
Runs on the raw source of a page, before anything else touches it, and can
|
||||||
make arbitrary changes. The function is passed named parameters `page` and
|
make arbitrary changes. The function is passed named parameters `page` and
|
||||||
|
@ -67,7 +69,7 @@ make arbitrary changes. The function is passed named parameters `page` and
|
||||||
Adding a [[PreProcessorDirective]] is probably the most common use of a
|
Adding a [[PreProcessorDirective]] is probably the most common use of a
|
||||||
plugin.
|
plugin.
|
||||||
|
|
||||||
IkiWiki::hook(type => "preprocess", id => "foo", call => \&preprocess);
|
hook(type => "preprocess", id => "foo", call => \&preprocess);
|
||||||
|
|
||||||
Replace "foo" with the command name that will be used inside brackets for
|
Replace "foo" with the command name that will be used inside brackets for
|
||||||
the preprocessor directive.
|
the preprocessor directive.
|
||||||
|
@ -89,7 +91,7 @@ the page) along with the rest of the page.
|
||||||
|
|
||||||
### htmlize
|
### htmlize
|
||||||
|
|
||||||
IkiWiki::hook(type => "htmlize", id => "ext", call => \&htmlize);
|
hook(type => "htmlize", id => "ext", call => \&htmlize);
|
||||||
|
|
||||||
Runs on the raw source of a page and turns it into html. The id parameter
|
Runs on the raw source of a page and turns it into html. The id parameter
|
||||||
specifies the filename extension that a file must have to be htmlized using
|
specifies the filename extension that a file must have to be htmlized using
|
||||||
|
@ -101,7 +103,7 @@ return the htmlized content.
|
||||||
|
|
||||||
### pagetemplate
|
### pagetemplate
|
||||||
|
|
||||||
IkiWiki::hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
|
hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
|
||||||
|
|
||||||
Each time a page (or part of a blog page, or an rss feed) is rendered, a
|
Each time a page (or part of a blog page, or an rss feed) is rendered, a
|
||||||
[[template|templates]] is filled out. This hook allows modifying that
|
[[template|templates]] is filled out. This hook allows modifying that
|
||||||
|
@ -116,7 +118,7 @@ a new custom parameter to the template.
|
||||||
|
|
||||||
### sanitize
|
### sanitize
|
||||||
|
|
||||||
IkiWiki::hook(type => "sanitize", id => "foo", call => \&sanitize);
|
hook(type => "sanitize", id => "foo", call => \&sanitize);
|
||||||
|
|
||||||
Use this to implement html sanitization or anything else that needs to
|
Use this to implement html sanitization or anything else that needs to
|
||||||
modify the body of a page after it has been fully converted to html.
|
modify the body of a page after it has been fully converted to html.
|
||||||
|
@ -126,7 +128,7 @@ should return the sanitized content.
|
||||||
|
|
||||||
### format
|
### format
|
||||||
|
|
||||||
IkiWiki::hook(type => "format", id => "foo", call => \&format);
|
hook(type => "format", id => "foo", call => \&format);
|
||||||
|
|
||||||
The difference between format and sanitize is that sanitize only acts on
|
The difference between format and sanitize is that sanitize only acts on
|
||||||
the page body, while format can modify the entire html page including the
|
the page body, while format can modify the entire html page including the
|
||||||
|
@ -137,14 +139,14 @@ should return the formatted content.
|
||||||
|
|
||||||
### delete
|
### delete
|
||||||
|
|
||||||
IkiWiki::hook(type => "delete", id => "foo", call => \&delete);
|
hook(type => "delete", id => "foo", call => \&delete);
|
||||||
|
|
||||||
Each time a page or pages is removed from the wiki, the referenced function
|
Each time a page or pages is removed from the wiki, the referenced function
|
||||||
is called, and passed the names of the source files that were removed.
|
is called, and passed the names of the source files that were removed.
|
||||||
|
|
||||||
### change
|
### change
|
||||||
|
|
||||||
IkiWiki::hook(type => "change", id => "foo", call => \&render);
|
hook(type => "change", id => "foo", call => \&render);
|
||||||
|
|
||||||
Each time ikiwiki renders a change or addition (but not deletion) to the
|
Each time ikiwiki renders a change or addition (but not deletion) to the
|
||||||
wiki, the referenced function is called, and passed the names of the
|
wiki, the referenced function is called, and passed the names of the
|
||||||
|
@ -152,7 +154,7 @@ source files that were rendered.
|
||||||
|
|
||||||
### cgi
|
### cgi
|
||||||
|
|
||||||
IkiWiki::hook(type => "cgi", id => "foo", call => \&cgi);
|
hook(type => "cgi", id => "foo", call => \&cgi);
|
||||||
|
|
||||||
Use this to hook into ikiwiki's cgi script. Each registered cgi hook is
|
Use this to hook into ikiwiki's cgi script. Each registered cgi hook is
|
||||||
called in turn, and passed a CGI object. The hook should examine the
|
called in turn, and passed a CGI object. The hook should examine the
|
||||||
|
@ -161,64 +163,156 @@ terminate the program.
|
||||||
|
|
||||||
### savestate
|
### savestate
|
||||||
|
|
||||||
IkiWiki::hook(type => "savestate", id => "foo", call => \&savestate);
|
hook(type => "savestate", id => "foo", call => \&savestate);
|
||||||
|
|
||||||
This hook is called wheneven ikiwiki normally saves its state, just before
|
This hook is called wheneven ikiwiki normally saves its state, just before
|
||||||
the state is saved. The function can save other state, modify values before
|
the state is saved. The function can save other state, modify values before
|
||||||
they're saved, etc.
|
they're saved, etc.
|
||||||
|
|
||||||
## Error handing
|
## Plugin interface
|
||||||
|
|
||||||
While a plugin can call ikiwiki's `error` routine for a fatal error, for
|
To import the ikiwiki plugin interface:
|
||||||
errors that aren't intended to halt the entire wiki build, including bad
|
|
||||||
parameters passed to a [[PreProcessorDirective]], etc, it's better to just
|
|
||||||
return the error message as the output of the plugin.
|
|
||||||
|
|
||||||
## Wiki configuration
|
use IkiWiki;
|
||||||
|
|
||||||
A plugin can access the wiki's configuration via the `%IkiWiki::config`
|
This will import several variables and functions into your plugin's
|
||||||
|
namespace. These variables and functions are the ones most plugins need,
|
||||||
|
and a special effort will be made to avoid changing them in incompatible
|
||||||
|
ways, and to document any changes that have to be made in the future.
|
||||||
|
|
||||||
|
Note that IkiWiki also provides other variables functions that are not
|
||||||
|
exported by default. No guarantee is made about these in the future, so if
|
||||||
|
it's not exported, the wise choice is to not use it.
|
||||||
|
|
||||||
|
### %config
|
||||||
|
|
||||||
|
A plugin can access the wiki's configuration via the `%config`
|
||||||
hash. The best way to understand the contents of the hash is to look at
|
hash. The best way to understand the contents of the hash is to look at
|
||||||
[[ikiwiki.setup]], which sets the hash content to configure the wiki.
|
[[ikiwiki.setup]], which sets the hash content to configure the wiki.
|
||||||
|
|
||||||
## Wiki data
|
### Other variables
|
||||||
|
|
||||||
If your plugin needs to access data about other pages in the wiki. It can
|
If your plugin needs to access data about other pages in the wiki. It can
|
||||||
use the following hashes, using a page name as the key:
|
use the following hashes, using a page name as the key:
|
||||||
|
|
||||||
* `%IkiWiki::links` lists the names of each page
|
* `%links` lists the names of each page that a page links to, in an array
|
||||||
that a page links to, in an array reference.
|
reference.
|
||||||
* `%IkiWiki::pagemtime` contains the last modification time of each page
|
* `%renderedfiles` contains the name of the file rendered by a page.
|
||||||
* `%IkiWiki::pagectime` contains the creation time of each page
|
* `%pagesources` contains the name of the source file for a page.
|
||||||
* `%IkiWiki::renderedfiles` contains the name of the file rendered by a
|
|
||||||
page
|
|
||||||
* `%IkiWiki::pagesources` contains the name of the source file for a page.
|
|
||||||
* `%IkiWiki::depends` contains a [[PageSpec]] that is used to specify other
|
|
||||||
pages that a page depends on. If one of its dependencies is updated, the
|
|
||||||
page will also get rebuilt.
|
|
||||||
|
|
||||||
Many plugins will need to add dependencies to this hash; the best way to do
|
|
||||||
it is by using the IkiWiki::add_depends function, which takes as its
|
|
||||||
parameters the page name and a [[PageSpec]] of dependencies to add.
|
|
||||||
* `%IkiWiki::forcerebuild` any pages set as the keys to this hash will be
|
|
||||||
treated as if they're modified and rebuilt.
|
|
||||||
|
|
||||||
## Generating html links
|
### Library functions
|
||||||
|
|
||||||
|
#### `hook(@)`
|
||||||
|
|
||||||
|
Hook into ikiwiki's processing. See the discussion of hooks above.
|
||||||
|
|
||||||
|
#### `debug($)`
|
||||||
|
|
||||||
|
Logs a debugging message. These are supressed unless verbose mode is turned
|
||||||
|
on.
|
||||||
|
|
||||||
|
#### `error($)`
|
||||||
|
|
||||||
|
Aborts with an error message.
|
||||||
|
|
||||||
|
Note that while any plugin can use this for a fatal error, plugins should
|
||||||
|
try to avoid dying on bad input, as that will halt the entire wiki build
|
||||||
|
and make the wiki unusable. So for example, if a [[PreProcessorDirective]]
|
||||||
|
is passed bad parameters, it's better to return an error message, which can
|
||||||
|
appear on the wiki page, rather than calling error().
|
||||||
|
|
||||||
|
#### `template($;@)`
|
||||||
|
|
||||||
|
Creates and returns a HTML::Template object. The first parameter is the
|
||||||
|
name of the file in the template directory. The optional remaining
|
||||||
|
parameters are passed to HTML::Template->new.
|
||||||
|
|
||||||
|
#### `htmlpage($)`
|
||||||
|
|
||||||
|
Passed a page name, returns the base name that will be used for a the html
|
||||||
|
page created from it. (Ie, it appends ".html".)
|
||||||
|
|
||||||
|
#### `add_depends($$)`
|
||||||
|
|
||||||
|
Makes the specified page depend on the specified [[PageSpec]].
|
||||||
|
|
||||||
|
#### `pagespec_match($$)`
|
||||||
|
|
||||||
|
Passed a page name, and a [[PageSpec]], returns true if the [[PageSpec]]
|
||||||
|
matches the page.
|
||||||
|
|
||||||
|
#### `bestlink($$)`
|
||||||
|
|
||||||
|
Given a page and the text of a link on the page, determine which
|
||||||
|
existing page that link best points to. Prefers pages under a
|
||||||
|
subdirectory with the same name as the source page, failing that
|
||||||
|
goes down the directory tree to the base looking for matching
|
||||||
|
pages, as described in [[SubPage/LinkingRules]].
|
||||||
|
|
||||||
|
#### `htmllink($$$;$$$)`
|
||||||
|
|
||||||
Many plugins need to generate html links and add them to a page. This is
|
Many plugins need to generate html links and add them to a page. This is
|
||||||
done by using the `IkiWiki::htmllink` function. The usual way to call
|
done by using the `htmllink` function. The usual way to call
|
||||||
htmlllink is:
|
`htmlllink` is:
|
||||||
|
|
||||||
htmllink($page, $page, $link)
|
htmllink($page, $page, $link)
|
||||||
|
|
||||||
Why is $page repeated? Because if a page is inlined inside another, and a
|
Why is `$page` repeated? Because if a page is inlined inside another, and a
|
||||||
link is placed on it, the right way to make that link is actually:
|
link is placed on it, the right way to make that link is actually:
|
||||||
|
|
||||||
htmllink($page, $destpage, $link)
|
htmllink($page, $destpage, $link)
|
||||||
|
|
||||||
Here $destpage is the inlining page. A destpage parameter is passed to some
|
Here `$destpage` is the inlining page. A `destpage` parameter is passed to
|
||||||
of the hook functions above; the ones that are not passed it are not used
|
some of the hook functions above; the ones that are not passed it are not used
|
||||||
during inlining and don't need to worry about this issue.
|
during inlining and don't need to worry about this issue.
|
||||||
|
|
||||||
|
The remaining three optional parameters to `htmllink` are:
|
||||||
|
|
||||||
|
1. noimageinline - set to true to avoid turning links into inline html images
|
||||||
|
1. forcesubpage - set to force a link to a subpage
|
||||||
|
1. linktext - set to force the link text to something
|
||||||
|
|
||||||
|
#### `readfile($;$)`
|
||||||
|
|
||||||
|
Given a filename, reads and returns the entire file.
|
||||||
|
|
||||||
|
The optional second parameter, if set to a true value, makes the file be read
|
||||||
|
in binary mode.
|
||||||
|
|
||||||
|
A failure to read the file will result in it dying with an error.
|
||||||
|
|
||||||
|
#### `writefile($$$;$)`
|
||||||
|
|
||||||
|
Given a filename, a directory to put it in, and the file's content,
|
||||||
|
writes a file.
|
||||||
|
|
||||||
|
The optional second parameter, if set to a true value, makes the file be
|
||||||
|
written in binary mode.
|
||||||
|
|
||||||
|
A failure to write the file will result in it dying with an error.
|
||||||
|
|
||||||
|
If the destination directory doesn't exist, it will first be created.
|
||||||
|
|
||||||
|
#### `pagetype($)`
|
||||||
|
|
||||||
|
Given the name of a source file, returns the type of page it is, if it's
|
||||||
|
a type that ikiwiki knowns how to htmlize. Otherwise, returns undef.
|
||||||
|
|
||||||
|
#### `pagename($)`
|
||||||
|
|
||||||
|
Given the name of a source file, returns the name of the wiki page
|
||||||
|
that corresponds to that file.
|
||||||
|
|
||||||
|
#### `srcfile($)`
|
||||||
|
|
||||||
|
Given the name of a source file in the wiki, searches for the file in
|
||||||
|
the source directory and the underlay directory, and returns the full
|
||||||
|
path to the first file found.
|
||||||
|
|
||||||
|
#### `displaytime($)`
|
||||||
|
|
||||||
|
Given a time, formats it for display.
|
||||||
|
|
||||||
## RCS plugins
|
## RCS plugins
|
||||||
|
|
||||||
ikiwiki's support for revision control systems also uses pluggable perl
|
ikiwiki's support for revision control systems also uses pluggable perl
|
||||||
|
|
|
@ -14,7 +14,7 @@ Released 29 April 2006.
|
||||||
|
|
||||||
* Unit test suite (with tests of at least core stuff like
|
* Unit test suite (with tests of at least core stuff like
|
||||||
[[PageSpec]]). _(status: exists, could of course use more tests)_
|
[[PageSpec]]). _(status: exists, could of course use more tests)_
|
||||||
* [[Plugins]] _(status: done, interface still not quite stable)_
|
* [[Plugins]] _(status: done, interface still not [[quite_stable|todo/firm_up_plugin_interface]])_
|
||||||
* [[Tags]] _(status: fair)_
|
* [[Tags]] _(status: fair)_
|
||||||
* Should have fully working [[todo/utf8]] support. _(status: good)_
|
* Should have fully working [[todo/utf8]] support. _(status: good)_
|
||||||
* [[Optimised_rendering|todo/optimisations]] if possible. Deal with other
|
* [[Optimised_rendering|todo/optimisations]] if possible. Deal with other
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
The plugin interface is currently that they can register hooks, and can
|
||||||
|
call any other ikiwiki internal function they desire, generally through
|
||||||
|
Ikiwiki::function calls. Also, some Ikiwiki::config etc variables can be
|
||||||
|
used.
|
||||||
|
|
||||||
|
This is a very weak interface, and should be firmed up to something more
|
||||||
|
like a proper perl library. I've been waiting to get some idea of what bits
|
||||||
|
of ikiwiki are most useful to plugins before doing it; there are plenty of
|
||||||
|
plugins to know that now.
|
||||||
|
|
||||||
|
IkiWiki will now export some function calls and variables when loaded.
|
||||||
|
|
||||||
|
Functions used by many plugins, which I'm sure should be exported:
|
||||||
|
|
||||||
|
* hook
|
||||||
|
* debug
|
||||||
|
* error
|
||||||
|
* template
|
||||||
|
* htmlpage
|
||||||
|
* add_depends
|
||||||
|
* pagespec_match
|
||||||
|
* bestlink
|
||||||
|
* htmllink
|
||||||
|
* readfile
|
||||||
|
* writefile
|
||||||
|
* pagetype
|
||||||
|
* srcfile
|
||||||
|
* pagename
|
||||||
|
* displaytime
|
||||||
|
|
||||||
|
Functions used by only some plugins, undecided:
|
||||||
|
|
||||||
|
* lockwiki, unlockwiki (aggregate)
|
||||||
|
Too internal to ever be exported.
|
||||||
|
* loadindex (aggregate)
|
||||||
|
Too internal to ever be exported.
|
||||||
|
* titlepage (aggregate)
|
||||||
|
Not until more than one thing uses it.
|
||||||
|
* basename (polygen, inline, search, polygen)
|
||||||
|
* dirname (linkmap, inline)
|
||||||
|
For basename and dirname, they could just use standard perl library
|
||||||
|
stuff. Howevever, ikiwiki's versions are slightly different and I'd
|
||||||
|
need to check if the standard versions work for the uses made in
|
||||||
|
these plugins. Inclined not to export.
|
||||||
|
* abs2rel (linkmap, inline)
|
||||||
|
This *is* the library version, just optimised to work around a bug.
|
||||||
|
Don't export this.
|
||||||
|
* possibly_foolish_untaint (aggregate, polygen)
|
||||||
|
Probably better to implement yourself.
|
||||||
|
* htmlize
|
||||||
|
* linkify
|
||||||
|
* preprocess
|
||||||
|
* filter
|
||||||
|
Used by several, but problimatic since plugins typically define
|
||||||
|
functions with these names..
|
||||||
|
|
||||||
|
Variables used by plugins:
|
||||||
|
|
||||||
|
* %IkiWiki::config (various values; probably not worth locking down any
|
||||||
|
more, export it)
|
||||||
|
* %IkiWiki::links (many, seems clearcut to export)
|
||||||
|
* %IkiWiki::renderedfiles (orphans, inline, search)
|
||||||
|
* %IkiWiki::pagesources (pagecount, sidebar, template, inline)
|
||||||
|
* %IkiWiki::pagecase (aggregate.. will not export yet)
|
||||||
|
* %IkiWIki::backlinks (pagestats.. will not export yet)
|
||||||
|
|
||||||
|
I don't want this interface to be too firm; it's ok for a plugin like
|
||||||
|
`ddate` to redefine an internal function like IkiWiki::displaytime if it
|
||||||
|
wants to.. But plugins that still access stuff through IkiWiki:: should be
|
||||||
|
aware that that stuff can change at any time and break them. Possibly without
|
||||||
|
perl's type checking catching the breakage, in some cases. Plugins that
|
||||||
|
only use exported symbols should not break by future ikiwiki changes.
|
10
t/bestlink.t
10
t/bestlink.t
|
@ -3,23 +3,23 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use Test::More tests => 9;
|
use Test::More tests => 9;
|
||||||
|
|
||||||
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
|
|
||||||
sub test ($$$) {
|
sub test ($$$) {
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $link=shift;
|
my $link=shift;
|
||||||
my @existing_pages=@{shift()};
|
my @existing_pages=@{shift()};
|
||||||
|
|
||||||
%IkiWiki::pagecase=();
|
%IkiWiki::pagecase=();
|
||||||
%IkiWiki::links=();
|
%links=();
|
||||||
foreach my $page (@existing_pages) {
|
foreach my $page (@existing_pages) {
|
||||||
$IkiWiki::pagecase{lc $page}=$page;
|
$IkiWiki::pagecase{lc $page}=$page;
|
||||||
$IkiWiki::links{$page}=[];
|
$links{$page}=[];
|
||||||
}
|
}
|
||||||
|
|
||||||
return IkiWiki::bestlink($page, $link);
|
return bestlink($page, $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
|
||||||
|
|
||||||
is(test("bar", "foo", ["bar"]), "", "broken link");
|
is(test("bar", "foo", ["bar"]), "", "broken link");
|
||||||
is(test("bar", "foo", ["bar", "foo"]), "foo", "simple link");
|
is(test("bar", "foo", ["bar", "foo"]), "foo", "simple link");
|
||||||
is(test("bar", "FoO", ["bar", "foo"]), "foo", "simple link with different input case");
|
is(test("bar", "FoO", ["bar", "foo"]), "foo", "simple link with different input case");
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
# to htmlize are changed.
|
# to htmlize are changed.
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use Test::More tests => 103;
|
use Test::More tests => 102;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
BEGIN { use_ok("IkiWiki::Render"); }
|
|
||||||
|
|
||||||
# Initialize htmlscrubber plugin
|
# Initialize htmlscrubber plugin
|
||||||
%IkiWiki::config=IkiWiki::defaultconfig();
|
%config=IkiWiki::defaultconfig();
|
||||||
$IkiWiki::config{srcdir}=$IkiWiki::config{destdir}="/dev/null";
|
$config{srcdir}=$config{destdir}="/dev/null";
|
||||||
IkiWiki::loadplugins(); IkiWiki::checkconfig();
|
IkiWiki::loadplugins(); IkiWiki::checkconfig();
|
||||||
ok(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test1.mdwn")));
|
ok(IkiWiki::htmlize("foo", "mdwn", readfile("t/test1.mdwn")));
|
||||||
ok(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test3.mdwn")),
|
ok(IkiWiki::htmlize("foo", "mdwn", readfile("t/test3.mdwn")),
|
||||||
"wtf?") for 1..100;
|
"wtf?") for 1..100;
|
||||||
|
|
3
t/html.t
3
t/html.t
|
@ -11,10 +11,9 @@ BEGIN {
|
||||||
plan skip_all => "/usr/bin/validate html validator not present";
|
plan skip_all => "/usr/bin/validate html validator not present";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan(tests => int @pages + 3);
|
plan(tests => int @pages + 2);
|
||||||
}
|
}
|
||||||
use_ok("IkiWiki");
|
use_ok("IkiWiki");
|
||||||
use_ok("IkiWiki::Render");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Have to build the html pages first.
|
# Have to build the html pages first.
|
||||||
|
|
11
t/htmlize.t
11
t/htmlize.t
|
@ -1,22 +1,21 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use Test::More tests => 5;
|
use Test::More tests => 4;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
BEGIN { use_ok("IkiWiki::Render"); }
|
|
||||||
|
|
||||||
# Initialize htmlscrubber plugin
|
# Initialize htmlscrubber plugin
|
||||||
%IkiWiki::config=IkiWiki::defaultconfig();
|
%config=IkiWiki::defaultconfig();
|
||||||
$IkiWiki::config{srcdir}=$IkiWiki::config{destdir}="/dev/null";
|
$config{srcdir}=$config{destdir}="/dev/null";
|
||||||
IkiWiki::loadplugins();
|
IkiWiki::loadplugins();
|
||||||
IkiWiki::checkconfig();
|
IkiWiki::checkconfig();
|
||||||
|
|
||||||
is(IkiWiki::htmlize("foo", "mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
|
is(IkiWiki::htmlize("foo", "mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
|
||||||
"basic");
|
"basic");
|
||||||
is(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test1.mdwn")),
|
is(IkiWiki::htmlize("foo", "mdwn", readfile("t/test1.mdwn")),
|
||||||
Encode::decode_utf8(qq{<p><img src="../images/o.jpg" alt="o" title="ó" />\nóóóóó</p>\n}),
|
Encode::decode_utf8(qq{<p><img src="../images/o.jpg" alt="o" title="ó" />\nóóóóó</p>\n}),
|
||||||
"utf8; bug #373203");
|
"utf8; bug #373203");
|
||||||
ok(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test2.mdwn")),
|
ok(IkiWiki::htmlize("foo", "mdwn", readfile("t/test2.mdwn")),
|
||||||
"this file crashes markdown if it's fed in as decoded utf-8");
|
"this file crashes markdown if it's fed in as decoded utf-8");
|
||||||
|
|
12
t/linkify.t
12
t/linkify.t
|
@ -3,6 +3,8 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use Test::More tests => 13;
|
use Test::More tests => 13;
|
||||||
|
|
||||||
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
|
|
||||||
sub linkify ($$$$) {
|
sub linkify ($$$$) {
|
||||||
my $lpage=shift;
|
my $lpage=shift;
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
|
@ -13,13 +15,13 @@ sub linkify ($$$$) {
|
||||||
# This is what linkify and htmllink need set right now to work.
|
# This is what linkify and htmllink need set right now to work.
|
||||||
# This could change, if so, update it..
|
# This could change, if so, update it..
|
||||||
%IkiWiki::pagecase=();
|
%IkiWiki::pagecase=();
|
||||||
%IkiWiki::links=();
|
%links=();
|
||||||
foreach my $page (@existing_pages) {
|
foreach my $page (@existing_pages) {
|
||||||
$IkiWiki::pagecase{lc $page}=$page;
|
$IkiWiki::pagecase{lc $page}=$page;
|
||||||
$IkiWiki::links{$page}=[];
|
$links{$page}=[];
|
||||||
$IkiWiki::renderedfiles{"$page.mdwn"}=$page;
|
$renderedfiles{"$page.mdwn"}=$page;
|
||||||
}
|
}
|
||||||
%IkiWiki::config=IkiWiki::defaultconfig();
|
%config=IkiWiki::defaultconfig();
|
||||||
|
|
||||||
return IkiWiki::linkify($lpage, $page, $content);
|
return IkiWiki::linkify($lpage, $page, $content);
|
||||||
}
|
}
|
||||||
|
@ -64,8 +66,6 @@ sub links_text ($$) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki::Render"); }
|
|
||||||
|
|
||||||
ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "bar"])), "ok link");
|
ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "bar"])), "ok link");
|
||||||
ok(not_links_to("bar", linkify("foo", "foo", "link to \\[[bar]] ok", ["foo", "bar"])), "escaped link");
|
ok(not_links_to("bar", linkify("foo", "foo", "link to \\[[bar]] ok", ["foo", "bar"])), "escaped link");
|
||||||
ok(links_to("page=bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo"])), "broken link");
|
ok(links_to("page=bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo"])), "broken link");
|
||||||
|
|
|
@ -5,44 +5,44 @@ use Test::More tests => 35;
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
|
|
||||||
ok(IkiWiki::pagespec_match("foo", "*"));
|
ok(pagespec_match("foo", "*"));
|
||||||
ok(IkiWiki::pagespec_match("page", "?ag?"));
|
ok(pagespec_match("page", "?ag?"));
|
||||||
ok(! IkiWiki::pagespec_match("page", "?a?g?"));
|
ok(! pagespec_match("page", "?a?g?"));
|
||||||
ok(IkiWiki::pagespec_match("foo.png", "*.*"));
|
ok(pagespec_match("foo.png", "*.*"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "*.*"));
|
ok(! pagespec_match("foo", "*.*"));
|
||||||
ok(IkiWiki::pagespec_match("foo", "foo or bar"), "simple list");
|
ok(pagespec_match("foo", "foo or bar"), "simple list");
|
||||||
ok(IkiWiki::pagespec_match("bar", "foo or bar"), "simple list 2");
|
ok(pagespec_match("bar", "foo or bar"), "simple list 2");
|
||||||
ok(IkiWiki::pagespec_match("foo", "f?? and !foz"));
|
ok(pagespec_match("foo", "f?? and !foz"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "f?? and !foo"));
|
ok(! pagespec_match("foo", "f?? and !foo"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "* and !foo"));
|
ok(! pagespec_match("foo", "* and !foo"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "foo and !foo"));
|
ok(! pagespec_match("foo", "foo and !foo"));
|
||||||
ok(! IkiWiki::pagespec_match("foo.png", "* and !*.*"));
|
ok(! pagespec_match("foo.png", "* and !*.*"));
|
||||||
ok(IkiWiki::pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))"));
|
ok(pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))"));
|
||||||
|
|
||||||
$IkiWiki::links{foo}=[qw{bar baz}];
|
$links{foo}=[qw{bar baz}];
|
||||||
ok(IkiWiki::pagespec_match("foo", "link(bar)"));
|
ok(pagespec_match("foo", "link(bar)"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "link(quux)"));
|
ok(! pagespec_match("foo", "link(quux)"));
|
||||||
ok(IkiWiki::pagespec_match("bar", "backlink(foo)"));
|
ok(pagespec_match("bar", "backlink(foo)"));
|
||||||
ok(! IkiWiki::pagespec_match("quux", "backlink(foo)"));
|
ok(! pagespec_match("quux", "backlink(foo)"));
|
||||||
|
|
||||||
$IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
|
$IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
|
||||||
$IkiWiki::pagectime{bar}=1154532695; # after
|
$IkiWiki::pagectime{bar}=1154532695; # after
|
||||||
ok(IkiWiki::pagespec_match("foo", "created_before(bar)"));
|
ok(pagespec_match("foo", "created_before(bar)"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "created_after(bar)"));
|
ok(! pagespec_match("foo", "created_after(bar)"));
|
||||||
ok(! IkiWiki::pagespec_match("bar", "created_before(foo)"));
|
ok(! pagespec_match("bar", "created_before(foo)"));
|
||||||
ok(IkiWiki::pagespec_match("bar", "created_after(foo)"));
|
ok(pagespec_match("bar", "created_after(foo)"));
|
||||||
ok(IkiWiki::pagespec_match("foo", "creation_year(2006)"), "year");
|
ok(pagespec_match("foo", "creation_year(2006)"), "year");
|
||||||
ok(! IkiWiki::pagespec_match("foo", "creation_year(2005)"), "other year");
|
ok(! pagespec_match("foo", "creation_year(2005)"), "other year");
|
||||||
ok(IkiWiki::pagespec_match("foo", "creation_month(8)"), "month");
|
ok(pagespec_match("foo", "creation_month(8)"), "month");
|
||||||
ok(! IkiWiki::pagespec_match("foo", "creation_month(9)"), "other month");
|
ok(! pagespec_match("foo", "creation_month(9)"), "other month");
|
||||||
ok(IkiWiki::pagespec_match("foo", "creation_day(2)"), "day");
|
ok(pagespec_match("foo", "creation_day(2)"), "day");
|
||||||
ok(! IkiWiki::pagespec_match("foo", "creation_day(3)"), "other day");
|
ok(! pagespec_match("foo", "creation_day(3)"), "other day");
|
||||||
|
|
||||||
# old style globlists
|
# old style globlists
|
||||||
ok(IkiWiki::pagespec_match("foo", "foo bar"), "simple list");
|
ok(pagespec_match("foo", "foo bar"), "simple list");
|
||||||
ok(IkiWiki::pagespec_match("bar", "foo bar"), "simple list 2");
|
ok(pagespec_match("bar", "foo bar"), "simple list 2");
|
||||||
ok(IkiWiki::pagespec_match("foo", "f?? !foz"));
|
ok(pagespec_match("foo", "f?? !foz"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "f?? !foo"));
|
ok(! pagespec_match("foo", "f?? !foo"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "* !foo"));
|
ok(! pagespec_match("foo", "* !foo"));
|
||||||
ok(! IkiWiki::pagespec_match("foo", "foo !foo"));
|
ok(! pagespec_match("foo", "foo !foo"));
|
||||||
ok(! IkiWiki::pagespec_match("foo.png", "* !*.*"));
|
ok(! pagespec_match("foo.png", "* !*.*"));
|
||||||
|
|
|
@ -3,20 +3,20 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use Test::More tests => 25;
|
use Test::More tests => 25;
|
||||||
|
|
||||||
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
|
|
||||||
sub same {
|
sub same {
|
||||||
my $a=shift;
|
my $a=shift;
|
||||||
my $b=shift;
|
my $b=shift;
|
||||||
my $match=shift;
|
my $match=shift;
|
||||||
|
|
||||||
my $imatch=(IkiWiki::pagespec_match($match, $a) ||
|
my $imatch=(pagespec_match($match, $a) ||
|
||||||
IkiWiki::pagespec_match($match, $b));
|
pagespec_match($match, $b));
|
||||||
my $cmatch=IkiWiki::pagespec_match($match, IkiWiki::pagespec_merge($a, $b));
|
my $cmatch=pagespec_match($match, IkiWiki::pagespec_merge($a, $b));
|
||||||
|
|
||||||
return $imatch == $cmatch;
|
return $imatch == $cmatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
|
||||||
|
|
||||||
ok(same("foo", "bar", "foo"), "basic match 1");
|
ok(same("foo", "bar", "foo"), "basic match 1");
|
||||||
ok(same("foo", "bar", "bar"), "basic match 2");
|
ok(same("foo", "bar", "bar"), "basic match 2");
|
||||||
ok(same("foo", "bar", "foobar"), "basic failed match");
|
ok(same("foo", "bar", "foobar"), "basic failed match");
|
||||||
|
@ -36,7 +36,7 @@ ok(same("f?? !f??", "!bar", "bar"), "matching glob and matching inverted glob");
|
||||||
ok(same("b??", "!b?z", "bar"), "matching glob and non-matching inverted glob");
|
ok(same("b??", "!b?z", "bar"), "matching glob and non-matching inverted glob");
|
||||||
ok(same("f?? !f?z", "!bar", "bar"), "matching glob and non-matching inverted glob");
|
ok(same("f?? !f?z", "!bar", "bar"), "matching glob and non-matching inverted glob");
|
||||||
ok(same("!foo bar baz", "!bar", "bar"), "matching list and matching inversion");
|
ok(same("!foo bar baz", "!bar", "bar"), "matching list and matching inversion");
|
||||||
ok(IkiWiki::pagespec_match("foo/Discussion",
|
ok(pagespec_match("foo/Discussion",
|
||||||
IkiWiki::pagespec_merge("* !*/Discussion", "*/Discussion")), "should match");
|
IkiWiki::pagespec_merge("* !*/Discussion", "*/Discussion")), "should match");
|
||||||
ok(same("* !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1");
|
ok(same("* !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1");
|
||||||
ok(same("*/Discussion", "* !*/Discussion", "foo/Discussion"), "Discussion merge 2");
|
ok(same("*/Discussion", "* !*/Discussion", "foo/Discussion"), "Discussion merge 2");
|
||||||
|
|
|
@ -7,6 +7,6 @@ use Encode;
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
|
|
||||||
# should read files as utf8
|
# should read files as utf8
|
||||||
ok(Encode::is_utf8(IkiWiki::readfile("t/test1.mdwn"), 1));
|
ok(Encode::is_utf8(readfile("t/test1.mdwn"), 1));
|
||||||
is(IkiWiki::readfile("t/test1.mdwn"),
|
is(readfile("t/test1.mdwn"),
|
||||||
Encode::decode_utf8('![o](../images/o.jpg "ó")'."\n".'óóóóó'."\n"));
|
Encode::decode_utf8('![o](../images/o.jpg "ó")'."\n".'óóóóó'."\n"));
|
||||||
|
|
|
@ -15,6 +15,7 @@ condgstep: 2
|
||||||
dotfidf: true
|
dotfidf: true
|
||||||
scancheck: false
|
scancheck: false
|
||||||
smplphrase: true
|
smplphrase: true
|
||||||
|
phraseform: 2
|
||||||
candetail: true
|
candetail: true
|
||||||
smlrvnum: 0
|
smlrvnum: 0
|
||||||
smlrtune: 16 1024 4096
|
smlrtune: 16 1024 4096
|
||||||
|
|
Loading…
Reference in New Issue