2006-08-18 02:24:22 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Sidebar plugin.
|
|
|
|
# by Tuomo Valkonen <tuomov at iki dot fi>
|
|
|
|
|
|
|
|
package IkiWiki::Plugin::sidebar;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-08-18 02:24:22 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-04 01:35:35 +02:00
|
|
|
hook(type => "getsetup", id => "sidebar", call => \&getsetup);
|
2010-04-15 22:40:01 +02:00
|
|
|
hook(type => "preprocess", id => "sidebar", call => \&preprocess);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-08-18 02:24:22 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-04 01:35:35 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2010-04-15 23:31:50 +02:00
|
|
|
global_sidebars => {
|
|
|
|
type => "boolean",
|
2010-05-16 05:54:00 +02:00
|
|
|
example => 1,
|
2010-04-15 23:38:13 +02:00
|
|
|
description => "show sidebar page on all pages?",
|
2010-04-15 23:31:50 +02:00
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-04 01:35:35 +02:00
|
|
|
|
2010-04-15 22:40:01 +02:00
|
|
|
my %pagesidebar;
|
|
|
|
|
|
|
|
sub preprocess (@) {
|
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
my $page=$params{page};
|
|
|
|
return "" unless $page eq $params{destpage};
|
2010-04-15 23:38:13 +02:00
|
|
|
|
2010-04-15 23:50:43 +02:00
|
|
|
if (! defined $params{content}) {
|
2010-04-15 23:38:13 +02:00
|
|
|
$pagesidebar{$page}=undef;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $file = $pagesources{$page};
|
|
|
|
my $type = pagetype($file);
|
2010-04-15 22:40:01 +02:00
|
|
|
|
2010-04-15 23:38:13 +02:00
|
|
|
$pagesidebar{$page}=
|
|
|
|
IkiWiki::htmlize($page, $page, $type,
|
|
|
|
IkiWiki::linkify($page, $page,
|
remove unnecessary and troublesome filter calls
This better defines what the filter hook is passed, to only be the raw,
complete text of a page. Not some snippet, or data read in from an
unrelated template.
Several plugins that filtered text that originates from an (already
filtered) page were modified not to do that. Note that this was not
done very consistently before; other plugins that receive text from a
page called preprocess on it w/o first calling filter.
The template plugin gets text from elsewhere, and was also changed not to
filter it. That leads to one known regression -- the embed plugin cannot
be used to embed stuff in templates now. But that plugin is deprecated
anyway.
Later we may want to increase the coverage of what is filtered. Perhaps
a good goal would be to allow writing a filter plugin that filters
out unwanted words, from any input. We're not there yet; not only
does the template plugin load unfiltered text from its templates now,
but so can the table plugin, and other plugins that use templates (like
inline!). I think we can cross that bridge when we come to it. If I wanted
such a censoring plugin, I'd probably make it use a sanitize hook instead,
for the better coverage.
For now I am concentrating on the needs of the two non-deprecated users
of filter. This should fix bugs/po_vs_templates, and it probably fixes
an obscure bug around txt's use of filter for robots.txt.
2010-07-04 21:00:51 +02:00
|
|
|
IkiWiki::preprocess($page, $page, $params{content})));
|
2010-04-15 23:38:13 +02:00
|
|
|
}
|
2010-04-15 22:40:01 +02:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $oldfile;
|
|
|
|
my $oldcontent;
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub sidebar_content ($) {
|
2006-08-18 02:24:22 +02:00
|
|
|
my $page=shift;
|
|
|
|
|
2010-04-16 04:18:56 +02:00
|
|
|
return delete $pagesidebar{$page} if defined $pagesidebar{$page};
|
2010-04-15 22:40:01 +02:00
|
|
|
|
2010-04-15 23:38:13 +02:00
|
|
|
return if ! exists $pagesidebar{$page} &&
|
|
|
|
defined $config{global_sidebars} && ! $config{global_sidebars};
|
2010-04-15 23:31:50 +02:00
|
|
|
|
2006-09-10 00:50:27 +02:00
|
|
|
my $sidebar_page=bestlink($page, "sidebar") || return;
|
|
|
|
my $sidebar_file=$pagesources{$sidebar_page} || return;
|
|
|
|
my $sidebar_type=pagetype($sidebar_file);
|
2006-08-18 02:24:22 +02:00
|
|
|
|
|
|
|
if (defined $sidebar_type) {
|
2006-08-18 03:28:54 +02:00
|
|
|
# FIXME: This isn't quite right; it won't take into account
|
|
|
|
# adding a new sidebar page. So adding such a page
|
|
|
|
# currently requires a wiki rebuild.
|
2006-09-10 00:50:27 +02:00
|
|
|
add_depends($page, $sidebar_page);
|
2006-08-18 03:28:54 +02:00
|
|
|
|
2010-04-15 22:40:01 +02:00
|
|
|
my $content;
|
|
|
|
if (defined $oldfile && $sidebar_file eq $oldfile) {
|
|
|
|
$content=$oldcontent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$content=readfile(srcfile($sidebar_file));
|
|
|
|
$oldcontent=$content;
|
|
|
|
$oldfile=$sidebar_file;
|
|
|
|
}
|
|
|
|
|
2006-08-18 02:24:22 +02:00
|
|
|
return unless length $content;
|
2008-06-04 07:24:23 +02:00
|
|
|
return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type,
|
2006-08-18 02:44:46 +02:00
|
|
|
IkiWiki::linkify($sidebar_page, $page,
|
2006-08-23 22:23:57 +02:00
|
|
|
IkiWiki::preprocess($sidebar_page, $page,
|
2007-05-17 21:55:11 +02:00
|
|
|
IkiWiki::filter($sidebar_page, $page, $content))));
|
2006-08-18 02:24:22 +02:00
|
|
|
}
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-08-18 02:24:22 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub pagetemplate (@) {
|
2006-08-18 02:24:22 +02:00
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
my $template=$params{template};
|
2010-04-16 04:18:56 +02:00
|
|
|
if ($params{destpage} eq $params{page} &&
|
|
|
|
$template->query(name => "sidebar")) {
|
|
|
|
my $content=sidebar_content($params{destpage});
|
2006-08-18 02:24:22 +02:00
|
|
|
if (defined $content && length $content) {
|
|
|
|
$template->param(sidebar => $content);
|
|
|
|
}
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-08-18 02:24:22 +02:00
|
|
|
|
|
|
|
1
|