Merge remote branch 'davrieb/autotag' into autotag
Conflicts: IkiWiki.pm IkiWiki/Plugin/tag.pmmaster
commit
54f600af14
29
IkiWiki.pm
29
IkiWiki.pm
|
@ -14,7 +14,8 @@ use open qw{:utf8 :std};
|
||||||
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
|
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
|
||||||
%pagestate %wikistate %renderedfiles %oldrenderedfiles
|
%pagestate %wikistate %renderedfiles %oldrenderedfiles
|
||||||
%pagesources %destsources %depends %depends_simple %hooks
|
%pagesources %destsources %depends %depends_simple %hooks
|
||||||
%forcerebuild %loaded_plugins %typedlinks %oldtypedlinks};
|
%forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
|
||||||
|
%autofiles %del_hash};
|
||||||
|
|
||||||
use Exporter q{import};
|
use Exporter q{import};
|
||||||
our @EXPORT = qw(hook debug error template htmlpage deptype
|
our @EXPORT = qw(hook debug error template htmlpage deptype
|
||||||
|
@ -22,7 +23,7 @@ our @EXPORT = qw(hook debug error template htmlpage deptype
|
||||||
htmllink readfile writefile pagetype srcfile pagename
|
htmllink readfile writefile pagetype srcfile pagename
|
||||||
displaytime will_render gettext ngettext urlto targetpage
|
displaytime will_render gettext ngettext urlto targetpage
|
||||||
add_underlay pagetitle titlepage linkpage newpagefile
|
add_underlay pagetitle titlepage linkpage newpagefile
|
||||||
inject add_link
|
inject add_link add_autofile
|
||||||
%config %links %pagestate %wikistate %renderedfiles
|
%config %links %pagestate %wikistate %renderedfiles
|
||||||
%pagesources %destsources %typedlinks);
|
%pagesources %destsources %typedlinks);
|
||||||
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
|
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
|
||||||
|
@ -2020,6 +2021,30 @@ sub sortspec_translate ($$) {
|
||||||
return eval 'sub { '.$code.' }';
|
return eval 'sub { '.$code.' }';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub add_autofile ($$) {
|
||||||
|
my $autofile=shift;
|
||||||
|
my $plugin=shift;
|
||||||
|
|
||||||
|
if (srcfile($autofile, 1)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir});
|
||||||
|
|
||||||
|
if ((!defined $file) ||
|
||||||
|
(exists $pagestate{$page}{$plugin}{autofile_deleted})) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists $del_hash{$file}) {
|
||||||
|
$pagestate{$page}{$plugin}{autofile_deleted}=1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$autofiles{$file}=$plugin;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
sub pagespec_translate ($) {
|
sub pagespec_translate ($) {
|
||||||
my $spec=shift;
|
my $spec=shift;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,13 @@ sub getsetup () {
|
||||||
safe => 1,
|
safe => 1,
|
||||||
rebuild => 1,
|
rebuild => 1,
|
||||||
},
|
},
|
||||||
|
tag_autocreate => {
|
||||||
|
type => "boolean",
|
||||||
|
example => 0,
|
||||||
|
description => "Autocreate new tag pages",
|
||||||
|
safe => 1,
|
||||||
|
rebuild => 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sub tagpage ($) {
|
sub tagpage ($) {
|
||||||
|
@ -57,6 +64,22 @@ sub taglink ($$$;@) {
|
||||||
return htmllink($page, $destpage, tagpage($tag), %opts);
|
return htmllink($page, $destpage, tagpage($tag), %opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub gentag ($) {
|
||||||
|
my $tag=shift;
|
||||||
|
if (defined $config{tag_autocreate} && $config{tag_autocreate}) {
|
||||||
|
my $tagfile = newpagefile(tagpage($tag), $config{default_pageext});
|
||||||
|
$tagfile=~s/^\///;
|
||||||
|
|
||||||
|
return if (! add_autofile($tagfile, "tag"));
|
||||||
|
|
||||||
|
debug(sprintf(gettext("creating tag page %s"), $tag));
|
||||||
|
|
||||||
|
my $template=template("autotag.tmpl");
|
||||||
|
$template->param(tag => $tag);
|
||||||
|
writefile($tagfile, $config{srcdir}, $template->output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub preprocess_tag (@) {
|
sub preprocess_tag (@) {
|
||||||
if (! @_) {
|
if (! @_) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -69,8 +92,12 @@ sub preprocess_tag (@) {
|
||||||
|
|
||||||
foreach my $tag (keys %params) {
|
foreach my $tag (keys %params) {
|
||||||
$tag=linkpage($tag);
|
$tag=linkpage($tag);
|
||||||
|
|
||||||
# hidden WikiLink
|
# hidden WikiLink
|
||||||
add_link($page, tagpage($tag), 'tag');
|
add_link($page, tagpage($tag), 'tag');
|
||||||
|
|
||||||
|
# add tagpage if necessary
|
||||||
|
gentag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -281,6 +281,27 @@ sub srcdir_check () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub verify_src_file ($$) {
|
||||||
|
my $file=decode_utf8(shift);
|
||||||
|
my $dir=shift;
|
||||||
|
|
||||||
|
return if -l $file || -d _;
|
||||||
|
$file=~s/^\Q$dir\E\/?//;
|
||||||
|
return if ! length $file;
|
||||||
|
my $page = pagename($file);
|
||||||
|
if (! exists $pagesources{$page} &&
|
||||||
|
file_pruned($file)) {
|
||||||
|
$File::Find::prune=1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
my ($file_untainted) = $file =~ /$config{wiki_file_regexp}/; # untaint
|
||||||
|
if (! defined $file_untainted) {
|
||||||
|
warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
|
||||||
|
}
|
||||||
|
return ($file_untainted, $page);
|
||||||
|
}
|
||||||
|
|
||||||
sub find_src_files () {
|
sub find_src_files () {
|
||||||
my @files;
|
my @files;
|
||||||
my %pages;
|
my %pages;
|
||||||
|
@ -289,22 +310,9 @@ sub find_src_files () {
|
||||||
find({
|
find({
|
||||||
no_chdir => 1,
|
no_chdir => 1,
|
||||||
wanted => sub {
|
wanted => sub {
|
||||||
my $file=decode_utf8($_);
|
my ($file, $page) = verify_src_file($_, $config{srcdir});
|
||||||
$file=~s/^\Q$config{srcdir}\E\/?//;
|
if (defined $file) {
|
||||||
return if -l $_ || -d _ || ! length $file;
|
push @files, $file;
|
||||||
my $page = pagename($file);
|
|
||||||
if (! exists $pagesources{$page} &&
|
|
||||||
file_pruned($file)) {
|
|
||||||
$File::Find::prune=1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
|
|
||||||
if (! defined $f) {
|
|
||||||
warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
push @files, $f;
|
|
||||||
if ($pages{$page}) {
|
if ($pages{$page}) {
|
||||||
debug(sprintf(gettext("%s has multiple possible source pages"), $page));
|
debug(sprintf(gettext("%s has multiple possible source pages"), $page));
|
||||||
}
|
}
|
||||||
|
@ -316,27 +324,14 @@ sub find_src_files () {
|
||||||
find({
|
find({
|
||||||
no_chdir => 1,
|
no_chdir => 1,
|
||||||
wanted => sub {
|
wanted => sub {
|
||||||
my $file=decode_utf8($_);
|
my ($file, $page) = verify_src_file($_, $dir);
|
||||||
$file=~s/^\Q$dir\E\/?//;
|
if (defined $file) {
|
||||||
return if -l $_ || -d _ || ! length $file;
|
|
||||||
my $page=pagename($file);
|
|
||||||
if (! exists $pagesources{$page} &&
|
|
||||||
file_pruned($file)) {
|
|
||||||
$File::Find::prune=1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
|
|
||||||
if (! defined $f) {
|
|
||||||
warn(sprintf(gettext("skipping bad filename %s"), $file)."\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# avoid underlaydir override
|
# avoid underlaydir override
|
||||||
# attacks; see security.mdwn
|
# attacks; see security.mdwn
|
||||||
if (! -l "$config{srcdir}/$f" &&
|
if (! -l "$config{srcdir}/$file" &&
|
||||||
! -e _) {
|
! -e _) {
|
||||||
if (! $pages{$page}) {
|
if (! $pages{$page}) {
|
||||||
push @files, $f;
|
push @files, $file;
|
||||||
$pages{$page}=1;
|
$pages{$page}=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -694,11 +689,28 @@ sub refresh () {
|
||||||
my ($changed, $internal_changed)=find_changed($files);
|
my ($changed, $internal_changed)=find_changed($files);
|
||||||
run_hooks(needsbuild => sub { shift->($changed) });
|
run_hooks(needsbuild => sub { shift->($changed) });
|
||||||
my $oldlink_targets=calculate_old_links($changed, $del);
|
my $oldlink_targets=calculate_old_links($changed, $del);
|
||||||
|
%del_hash = map { $_ => 1 } @{$del};
|
||||||
|
|
||||||
foreach my $file (@$changed) {
|
foreach my $file (@$changed) {
|
||||||
scan($file);
|
scan($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (my $autofile = shift @{[keys %autofiles]}) {
|
||||||
|
my $plugin=$autofiles{$autofile};
|
||||||
|
my $page=pagename($autofile);
|
||||||
|
if ($pages->{$page}) {
|
||||||
|
debug(sprintf(gettext("%s has multiple possible source pages"), $page));
|
||||||
|
}
|
||||||
|
$pages->{$page}=1;
|
||||||
|
|
||||||
|
push @{$files}, $autofile;
|
||||||
|
push @{$new}, $autofile if find_new_files([$autofile]);
|
||||||
|
push @{$changed}, $autofile if find_changed([$autofile]);
|
||||||
|
|
||||||
|
scan($autofile);
|
||||||
|
delete $autofiles{$autofile};
|
||||||
|
}
|
||||||
|
|
||||||
calculate_links();
|
calculate_links();
|
||||||
|
|
||||||
remove_del(@$del, @$internal_del);
|
remove_del(@$del, @$internal_del);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
## Pages tagged <TMPL_VAR TAG> ##
|
||||||
|
|
||||||
|
[[!inline pages="tagged(<TMPL_VAR TAG>)" actions="no" archive="yes"]]
|
Loading…
Reference in New Issue