3 package IkiWiki
::Plugin
::tag
;
10 hook
(type
=> "checkconfig", id
=> "tag", call
=> \
&checkconfig
);
11 hook
(type
=> "getopt", id
=> "tag", call
=> \
&getopt
);
12 hook
(type
=> "getsetup", id
=> "tag", call
=> \
&getsetup
);
13 hook
(type
=> "preprocess", id
=> "tag", call
=> \
&preprocess_tag
, scan
=> 1);
14 hook
(type
=> "preprocess", id
=> "taglink", call
=> \
&preprocess_taglink
, scan
=> 1);
15 hook
(type
=> "pagetemplate", id
=> "tag", call
=> \
&pagetemplate
);
17 IkiWiki
::loadplugin
("transient");
21 eval q{use Getopt::Long};
23 Getopt
::Long
::Configure
('pass_through');
24 GetOptions
("tagbase=s" => \
$config{tagbase
});
36 description
=> "parent page tags are located under",
43 description
=> "autocreate new tag pages?",
47 tag_autocreate_commit
=> {
51 description
=> "commit autocreated tag pages",
58 if (! defined $config{tag_autocreate_commit
}) {
59 $config{tag_autocreate_commit
} = 1;
67 defined $config{tagbase
}) {
68 $tag="/".$config{tagbase
}."/".$tag;
69 $tag=~y
#/#/#s; # squash dups
75 # Returns a tag name from a tag link
78 if (defined $config{tagbase
}) {
79 $tag =~ s!^/\Q$config{tagbase}\E/!!;
83 return pagetitle
($tag, 1);
86 sub htmllink_tag
($$$;@
) {
92 return htmllink
($page, $destpage, taglink
($tag), %opts);
98 if ($config{tag_autocreate
} ||
99 ($config{tagbase
} && ! defined $config{tag_autocreate
})) {
100 my $tagpage=taglink
($tag);
101 if ($tagpage=~/^\.\/(.*)/) {
108 my $tagfile = newpagefile
($tagpage, $config{default_pageext
});
110 add_autofile
($tagfile, "tag", sub {
111 my $message=sprintf(gettext
("creating tag page %s"), $tagpage);
114 my $template=template
("autotag.tmpl");
115 $template->param(tagname
=> tagname
($tag));
116 $template->param(tag
=> $tag);
118 my $dir = $config{srcdir
};
119 if (! $config{tag_autocreate_commit
}) {
120 $dir = $IkiWiki::Plugin
::transient
::transientdir
;
123 writefile
($tagfile, $dir, $template->output);
124 if ($config{rcs
} && $config{tag_autocreate_commit
}) {
125 IkiWiki
::disable_commit_hook
();
126 IkiWiki
::rcs_add
($tagfile);
127 IkiWiki
::rcs_commit_staged
(message
=> $message);
128 IkiWiki
::enable_commit_hook
();
134 sub preprocess_tag
(@
) {
139 my $page = $params{page
};
140 delete $params{page
};
141 delete $params{destpage
};
142 delete $params{preview
};
144 foreach my $tag (keys %params) {
148 add_link
($page, taglink
($tag), 'tag');
156 sub preprocess_taglink
(@
) {
161 return join(" ", map {
163 my $tag=linkpage
($2);
164 add_link
($params{page
}, taglink
($tag), 'tag');
166 return htmllink_tag
($params{page
}, $params{destpage
}, $tag,
167 linktext
=> pagetitle
($1));
170 my $tag=linkpage
($_);
171 add_link
($params{page
}, taglink
($tag), 'tag');
173 return htmllink_tag
($params{page
}, $params{destpage
}, $tag);
177 $_ ne 'page' && $_ ne 'destpage' && $_ ne 'preview'
181 sub pagetemplate
(@
) {
183 my $page=$params{page
};
184 my $destpage=$params{destpage
};
185 my $template=$params{template
};
187 my $tags = $typedlinks{$page}{tag
};
189 $template->param(tags
=> [
191 link => htmllink_tag
($page, $destpage, $_,
192 rel
=> "tag", linktext
=> tagname
($_))
194 ]) if defined $tags && %$tags && $template->query(name
=> "tags");
196 if ($template->query(name
=> "categories")) {
197 # It's an rss/atom template. Add any categories.
198 if (defined $tags && %$tags) {
199 $template->param(categories
=> [map { category
=> tagname
($_) },
205 package IkiWiki
::PageSpec
;
207 sub match_tagged
($$;@
) {
209 my $glob=IkiWiki
::Plugin
::tag
::taglink
(shift);
210 return match_link
($page, $glob, linktype
=> 'tag', @_);