From 88c6e2891593fd508701d728602515e47284180c Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sat, 9 Jan 2010 22:53:45 +0100 Subject: moved selflink test to its own isselflink (overridable) sub --- IkiWiki.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'IkiWiki.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index b8e599928..5d5c7f0d0 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1026,6 +1026,13 @@ sub urlto ($$;$) { return beautify_urlpath($link); } +sub isselflink ($$) { + my $page=shift; + my $link=shift; + + return $page eq $link; +} + sub htmllink ($$$;@) { my $lpage=shift; # the page doing the linking my $page=shift; # the page that will contain the link (different for inline) @@ -1051,7 +1058,7 @@ sub htmllink ($$$;@) { } return "$linktext" - if length $bestlink && $page eq $bestlink && + if length $bestlink && isselflink($page, $bestlink) && ! defined $opts{anchor}; if (! $destsources{$bestlink}) { -- cgit v1.2.3 From dcd57dd5c9f3265bb7a78a5696b90976698c43aa Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 29 Jun 2010 15:13:23 +0200 Subject: Add a fullpage arg to filter. Set it to true every time IkiWiki::filter is called on a full page's content. This is a much nicer solution, for the po plugin, than previous whitelisting using caller(). --- IkiWiki.pm | 6 ++++-- IkiWiki/Plugin/editpage.pm | 2 +- IkiWiki/Plugin/inline.pm | 4 ++-- IkiWiki/Plugin/po.pm | 6 ++---- IkiWiki/Plugin/sidebar.pm | 2 +- IkiWiki/Render.pm | 4 ++-- doc/plugins/write.mdwn | 4 +++- 7 files changed, 15 insertions(+), 13 deletions(-) (limited to 'IkiWiki.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index 0457a6c61..7b5fd283d 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1396,14 +1396,16 @@ sub preprocess ($$$;$$) { return $content; } -sub filter ($$$) { +sub filter ($$$;$) { my $page=shift; my $destpage=shift; my $content=shift; + my $fullpage=shift; + $fullpage = 0 unless defined $fullpage; run_hooks(filter => sub { $content=shift->(page => $page, destpage => $destpage, - content => $content); + content => $content, fullpage => $fullpage); }); return $content; diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index 1a04a72b5..706630203 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -187,7 +187,7 @@ sub cgi_editpage ($$) { my $preview=htmlize($page, $page, $type, linkify($page, $page, preprocess($page, $page, - filter($page, $page, $content), 0, 1))); + filter($page, $page, $content, 'fullpage'), 0, 1))); run_hooks(format => sub { $preview=shift->( page => $page, diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 715a3d652..a04dd6630 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -403,7 +403,7 @@ sub preprocess_inline (@) { linkify($page, $params{destpage}, preprocess($page, $params{destpage}, filter($page, $params{destpage}, - readfile(srcfile($file))))); + readfile(srcfile($file)), 'fullpage'))); } else { $ret.="\n". @@ -474,7 +474,7 @@ sub get_inline_content ($$) { linkify($page, $destpage, preprocess($page, $destpage, filter($page, $destpage, - readfile(srcfile($file)))))); + readfile(srcfile($file)), 'fullpage')))); $nested--; if (isinternal($page)) { # make inlined text of internal pages searchable diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index ac4401e48..93cf6bbdf 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -259,11 +259,9 @@ sub filter (@) { my $page = $params{page}; my $destpage = $params{destpage}; my $content = $params{content}; + my $fullpage = $params{fullpage}; - my @caller = caller(4); - # FIXME: need to whitelist inline as well? - unless ($caller[3] eq "IkiWiki::render" || - $caller[3] eq 'IkiWiki::Plugin::sidebar::sidebar_content') { + unless ($fullpage) { return $content; } diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 2d495db2c..100015cee 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -89,7 +89,7 @@ sub sidebar_content ($) { return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type, IkiWiki::linkify($sidebar_page, $page, IkiWiki::preprocess($sidebar_page, $page, - IkiWiki::filter($sidebar_page, $page, $content)))); + IkiWiki::filter($sidebar_page, $page, $content, 'fullpage')))); } } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index a653ab2da..233d093ed 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -232,7 +232,7 @@ sub render ($$) { linkify($page, $page, preprocess($page, $page, filter($page, $page, - readfile($srcfile))))); + readfile($srcfile), 'fullpage')))); my $output=htmlpage($page); writefile($output, $config{destdir}, genpage($page, $content)); @@ -837,7 +837,7 @@ sub commandline_render () { my $content=readfile($srcfile); my $page=pagename($file); $pagesources{$page}=$file; - $content=filter($page, $page, $content); + $content=filter($page, $page, $content, 'fullpage'); $content=preprocess($page, $page, $content); $content=linkify($page, $page, $content); $content=htmlize($page, $page, $type, $content); diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index a921b9a02..15ed08d82 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -200,7 +200,9 @@ value is ignored. 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", -"destpage", and "content". It should return the filtered content. +"destpage", "content" and "fullpage". "fullpage" is a true value if, +and only if, a full page's content is being filtered, e.g. as opposed +to a directive parameter. It should return the filtered content. ### preprocess -- cgit v1.2.3 From 4a1cb092baabda6182fd291dfc9810f6c8efb17e Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 11 Jul 2010 11:00:43 +0200 Subject: Revert po vs. template kludges. This reverts commits dcd57dd5c9f3265bb7a78a5696b90976698c43aa, d4136aea8aa8968d2cd87b40e8d85301a3549323 and d877b9644bcfbbfc5eaf3f7fc13cb96ecda946c9. --- IkiWiki.pm | 6 ++---- IkiWiki/Plugin/editpage.pm | 2 +- IkiWiki/Plugin/inline.pm | 4 ++-- IkiWiki/Plugin/po.pm | 6 ------ IkiWiki/Plugin/sidebar.pm | 2 +- IkiWiki/Render.pm | 4 ++-- doc/plugins/write.mdwn | 4 +--- 7 files changed, 9 insertions(+), 19 deletions(-) (limited to 'IkiWiki.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index f9a30a202..cd9c40795 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1403,16 +1403,14 @@ sub preprocess ($$$;$$) { return $content; } -sub filter ($$$;$) { +sub filter ($$$) { my $page=shift; my $destpage=shift; my $content=shift; - my $fullpage=shift; - $fullpage = 0 unless defined $fullpage; run_hooks(filter => sub { $content=shift->(page => $page, destpage => $destpage, - content => $content, fullpage => $fullpage); + content => $content); }); return $content; diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index 706630203..1a04a72b5 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -187,7 +187,7 @@ sub cgi_editpage ($$) { my $preview=htmlize($page, $page, $type, linkify($page, $page, preprocess($page, $page, - filter($page, $page, $content, 'fullpage'), 0, 1))); + filter($page, $page, $content), 0, 1))); run_hooks(format => sub { $preview=shift->( page => $page, diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index a04dd6630..715a3d652 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -403,7 +403,7 @@ sub preprocess_inline (@) { linkify($page, $params{destpage}, preprocess($page, $params{destpage}, filter($page, $params{destpage}, - readfile(srcfile($file)), 'fullpage'))); + readfile(srcfile($file))))); } else { $ret.="\n". @@ -474,7 +474,7 @@ sub get_inline_content ($$) { linkify($page, $destpage, preprocess($page, $destpage, filter($page, $destpage, - readfile(srcfile($file)), 'fullpage')))); + readfile(srcfile($file)))))); $nested--; if (isinternal($page)) { # make inlined text of internal pages searchable diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index cadc13ba1..ecfbb6f78 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -259,12 +259,6 @@ sub filter (@) { my $page = $params{page}; my $destpage = $params{destpage}; my $content = $params{content}; - my $fullpage = $params{fullpage}; - - unless ($fullpage) { - return $content; - } - if (istranslation($page) && ! alreadyfiltered($page, $destpage)) { $content = po_to_markup($page, $content); setalreadyfiltered($page, $destpage); diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 100015cee..2d495db2c 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -89,7 +89,7 @@ sub sidebar_content ($) { return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type, IkiWiki::linkify($sidebar_page, $page, IkiWiki::preprocess($sidebar_page, $page, - IkiWiki::filter($sidebar_page, $page, $content, 'fullpage')))); + IkiWiki::filter($sidebar_page, $page, $content)))); } } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 233d093ed..a653ab2da 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -232,7 +232,7 @@ sub render ($$) { linkify($page, $page, preprocess($page, $page, filter($page, $page, - readfile($srcfile), 'fullpage')))); + readfile($srcfile))))); my $output=htmlpage($page); writefile($output, $config{destdir}, genpage($page, $content)); @@ -837,7 +837,7 @@ sub commandline_render () { my $content=readfile($srcfile); my $page=pagename($file); $pagesources{$page}=$file; - $content=filter($page, $page, $content, 'fullpage'); + $content=filter($page, $page, $content); $content=preprocess($page, $page, $content); $content=linkify($page, $page, $content); $content=htmlize($page, $page, $type, $content); diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 8071f323e..bb8012342 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -200,9 +200,7 @@ value is ignored. 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", -"destpage", "content" and "fullpage". "fullpage" is a true value if, -and only if, a full page's content is being filtered, e.g. as opposed -to a directive parameter. It should return the filtered content. +"destpage", and "content". It should return the filtered content. ### preprocess -- cgit v1.2.3 From ff8f6cd6b23f6b1e727649d5e5abaabea7bcf6c5 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 11 Jul 2010 11:35:37 +0200 Subject: Make the rationale clearer. --- IkiWiki.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'IkiWiki.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index cd9c40795..1dc989b39 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1082,6 +1082,8 @@ sub urlto ($$;$) { } sub isselflink ($$) { + # Plugins can override this function to support special types + # of selflinks. my $page=shift; my $link=shift; -- cgit v1.2.3