improve support for internal pages

This makes it a lot quicker to deal with lots of recentchanges pages
appearing and disappearing. It avoids needing to clutter up pagespecs with
exclusions for those pages, by making normal pagespecs not match them.
master
Joey Hess 2008-01-29 15:05:49 -05:00
parent 2bfd2e9841
commit 47ee266163
9 changed files with 80 additions and 39 deletions

View File

@ -260,6 +260,12 @@ sub pagetype ($) { #{{{
return;
} #}}}
sub isinternal ($) { #{{{
my $page=shift;
return exists $pagesources{$page} &&
$pagesources{$page} =~ /\._([^.]+)$/;
} #}}}
sub pagename ($) { #{{{
my $file=shift;
@ -1287,13 +1293,22 @@ sub match_glob ($$;@) { #{{{
$glob=~s/\\\?/./g;
if ($page=~/^$glob$/i) {
return IkiWiki::SuccessReason->new("$glob matches $page");
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}
else {
return IkiWiki::FailReason->new("$glob matches $page, but the page is an internal page");
}
}
else {
return IkiWiki::FailReason->new("$glob does not match $page");
}
} #}}}
sub match_internal ($$;@) { #{{{
return match_glob($_[0], $_[1], @_, internal => 1)
} #}}}
sub match_link ($$;@) { #{{{
my $page=shift;
my $link=lc(shift);
@ -1389,19 +1404,4 @@ sub match_creation_year ($$;@) { #{{{
}
} #}}}
sub match_user ($$;@) { #{{{
shift;
my $user=shift;
my %params=@_;
return IkiWiki::FailReason->new('cannot match user')
unless exists $params{user};
if ($user eq $params{user}) {
return IkiWiki::SuccessReason->new("user is $user")
}
else {
return IkiWiki::FailReason->new("user is not $user");
}
} #}}}
1

View File

@ -319,15 +319,19 @@ sub refresh () { #{{{
}, $dir);
};
my %rendered;
my (%rendered, @add, @del, @internal);
# check for added or removed pages
my @add;
foreach my $file (@files) {
my $page=pagename($file);
$pagesources{$page}=$file;
if (! $pagemtime{$page}) {
push @add, $file;
if (isinternal($page)) {
push @internal, $file;
}
else {
push @add, $file;
}
$pagecase{lc $page}=$page;
if ($config{getctime} && -e "$config{srcdir}/$file") {
$pagectime{$page}=rcs_getctime("$config{srcdir}/$file");
@ -337,11 +341,15 @@ sub refresh () { #{{{
}
}
}
my @del;
foreach my $page (keys %pagemtime) {
if (! $exists{$page}) {
debug(sprintf(gettext("removing old page %s"), $page));
push @del, $pagesources{$page};
if (isinternal($page)) {
push @internal, $pagesources{$page};
}
else {
debug(sprintf(gettext("removing old page %s"), $page));
push @del, $pagesources{$page};
}
$links{$page}=[];
$renderedfiles{$page}=[];
$pagemtime{$page}=0;
@ -366,7 +374,12 @@ sub refresh () { #{{{
$mtime > $pagemtime{$page} ||
$forcerebuild{$page}) {
$pagemtime{$page}=$mtime;
push @needsbuild, $file;
if (isinternal($page)) {
push @internal, $file;
}
else {
push @needsbuild, $file;
}
}
}
run_hooks(needsbuild => sub { shift->(\@needsbuild) });
@ -382,6 +395,15 @@ sub refresh () { #{{{
render($file);
$rendered{$file}=1;
}
foreach my $file (@internal) {
# internal pages are not rendered
my $page=pagename($file);
delete $depends{$page};
foreach my $old (@{$renderedfiles{$page}}) {
delete $destsources{$old};
}
$renderedfiles{$page}=[];
}
# rebuild pages that link to added or removed pages
if (@add || @del) {
@ -397,13 +419,17 @@ sub refresh () { #{{{
}
}
if (%rendered || @del) {
if (%rendered || @del || @internal) {
my @changed=(keys %rendered, @del);
# rebuild dependant pages
foreach my $f (@files) {
next if $rendered{$f};
my $p=pagename($f);
if (exists $depends{$p}) {
foreach my $file (keys %rendered, @del) {
# only consider internal files
# if the page explicitly depends on such files
foreach my $file (@changed, $depends{$p}=~/internal\(/ ? @internal : ()) {
next if $f eq $file;
my $page=pagename($file);
if (pagespec_match($page, $depends{$p}, location => $p)) {
@ -419,7 +445,7 @@ sub refresh () { #{{{
# handle backlinks; if a page has added/removed links,
# update the pages it links to
my %linkchanged;
foreach my $file (keys %rendered, @del) {
foreach my $file (@changed) {
my $page=pagename($file);
if (exists $links{$page}) {
@ -441,6 +467,7 @@ sub refresh () { #{{{
}
}
}
foreach my $link (keys %linkchanged) {
my $linkfile=$pagesources{$link};
if (defined $linkfile) {

6
debian/changelog vendored
View File

@ -22,13 +22,15 @@ ikiwiki (2.21) UNRELEASED; urgency=low
* prettydate,ddate: Don't ignore time formats passed to displaytime
function.
* Pages with extensions starting with "_" are internal-use, and will
not be rendered or web-edited.
not be rendered or web-edited, or matched by normal pagespecs.
* Add "internal()" pagespec that matches internal-use pages.
* RecentChanges is now a static html page, that's updated whenever a commit
is made to the wiki. It's built as a blog using inline, so it can have
an rss feed that users can subscribe to.
* Removed support for sending commit notification mails. Along with it went
the svnrepo and notify settings, though both will be ignored if left in
setup files.
setup files. Also gone with it is the "user()" pagespec.
* Add refresh hook.
-- Joey Hess <joeyh@debian.org> Fri, 11 Jan 2008 15:09:37 -0500

View File

@ -33,8 +33,10 @@ functions:
was created
* "`created_before(page)`" - match only pages created before the given page
was created
* "`user(name)`" - only available in page subscription preferences, match
only changes made by this user
* "`glob(foo)`" - match pages that match the given glob `foo`. Just writing
the glob by itself is actually a shorthand for this function.
* "`internal(foo)`" - like `glob()`, but matches even internal-use
pages that globs do not usually match.
For example, to match all pages in a blog that link to the page about music
and were written in 2005:

View File

@ -10,4 +10,4 @@ pages to search for broken links, default is search them all.
If this plugin is turned on, here's a list of broken links on this wiki:
[[brokenlinks pages="* and !recentchanges/change_* and !recentchanges"]]
[[brokenlinks pages="* and !recentchanges"]]

View File

@ -15,6 +15,6 @@ orphans.
Here's a list of orphaned pages on this wiki:
[[orphans pages="* and !news/* and !todo/* and !bugs/* and !users/* and
!recentchanges/change_* and !recentchanges and !examples/* and !tips/* and
!sandbox/* and !wikiicons/* and !plugins/*"]]
!recentchanges and !examples/* and !tips/* and !sandbox/* and
!wikiicons/* and !plugins/*"]]
"""]]

View File

@ -10,5 +10,5 @@ pages to count, default is to count them all.
This plugin is included in ikiwiki, but is not enabled by default.
If it is turned on it can tell us that this wiki includes
[[pagecount pages="* and !recentchanges/change_* and !recentchanges"]]
[[pagecount pages="* and !recentchanges"]]
pages, of which [[pagecount pages="*/Discussion"]] are discussion pages.

View File

@ -9,6 +9,8 @@ Typically only the RecentChanges page will use the plugin, but you can
use it elsewhere too if you like. It's used like this:
\[[recentchanges pages="*" num=100 template=change]]
\[[inline pages="internal(recentchanges/change_*)"
template=recentchanges show=0]]
The pages describing recent changes will be created as [[subpages|subpage]]
of the page where the `recentchanges` directive is placed.

View File

@ -151,11 +151,6 @@ specifies the filename extension that a file must have to be htmlized using
this plugin. This is how you can add support for new and exciting markup
languages to ikiwiki.
Note that if you choose a filename extension that starts with "_",
ikiwiki will not render the page, or allow the page to be edited with the
web interface. This is useful for certian types of internal-use pages, but
should generally be avoided.
The function is passed named parameters: "page" and "content" and should
return the htmlized content.
@ -536,6 +531,19 @@ destination file, as registered by `will_render`.
Passed a page and an extension, returns the filename that page will be
rendered to.
## Internal use pages
Sometimes it's useful to put pages in the wiki without having them be
rendered to individual html files. Such internal use pages are collected
together to form the RecentChanges page, for example.
To make an internal use page, register a filename extension that starts
with "_". Internal use pages cannot be edited with the web interface, are
not scanned for wikilinks (though wikilinks and preprocessor directives can
still appear on them, this is rarely a good idea), and are not matched by
regular PageSpecs glob patterns, but instead only by a special `internal()`
[[ikiwiki/PageSpec]].
## RCS plugins
ikiwiki's support for [[revision_control_systems|rcs]] also uses pluggable