summaryrefslogtreecommitdiff
path: root/perl/IkiWiki/Plugin/copyright.pm
blob: 0eda81c1c2c0f7cb98497ed2724d387a05b5d2e8 (plain)
  1. # A plugin for ikiwiki to implement adding a footer with copyright information
  2. # based on a default value taken out of a file.
  3. # Copyright © 2007 Thomas Schwinge <tschwinge@gnu.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the
  7. # Free Software Foundation; either version 2, or (at your option) any later
  8. # version.
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License along
  14. # with this program; if not, write to the Free Software Foundation, Inc.,
  15. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. # A footer with copyright information will be added to every rendered page if
  17. # (a) such a footer isn't present already (see the `meta' plugin's
  18. # ``copyright'' facility) and (b) a file `copyright.html' is found (using the
  19. # same rules as for the sidebar plugin).
  20. #
  21. # The state which page's copyright text was gathered from which source is not
  22. # tracked, so you'll need a full wiki-rebuild if (b)'s files are changed.
  23. #
  24. # You can use wiki links in `copyright.html'.
  25. package IkiWiki::Plugin::copyright;
  26. use warnings;
  27. use strict;
  28. use IkiWiki 2.00;
  29. sub import
  30. {
  31.     hook (type => "pagetemplate"id => "copyright"call => \&pagetemplate,
  32.       # Run last, as to have the `meta' plugin do its work first.
  33.       last => 1);
  34. }
  35. sub pagetemplate (@)
  36. {
  37.     my %params @_;
  38.     my $page $params{page};
  39.     my $destpage $params{destpage};
  40.     my $template $params{template};
  41.     if ($template->query (name => "copyright") &&
  42.     defined $template->param ('copyright'))
  43.     {
  44.     my $content;
  45.     my $copyright_page bestlink ($page"copyright") || return;
  46.     my $copyright_file $pagesources{$copyright_page} || return;
  47.     #my $pagetype = pagetype ($copyright_file);
  48.     # Check if ``$pagetype eq 'html'''?
  49.     $content readfile (srcfile ($copyright_file));
  50.     if (defined $content && length $content)
  51.     {
  52.         $template->param (copyright =>
  53.           IkiWiki::linkify ($page$destpage$content));
  54.     }
  55.     }
  56. }
  57. 1