summaryrefslogtreecommitdiff
path: root/perl/IkiWiki/Plugin/license.pm
blob: 2375c22eba0c78336aff489bfbc842c4835a2da6 (plain)
  1. # A plugin for ikiwiki to implement adding a footer with licensing 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 licensing information will be added to every rendered page if
  17. # (a) such a footer isn't present already (see the `meta' plugin's ``license''
  18. # facility) and (b) a file `license.html' is found (using the same rules as for
  19. # the sidebar plugin).
  20. #
  21. # The state which page's license 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 `license.html'.
  25. package IkiWiki::Plugin::license;
  26. use warnings;
  27. use strict;
  28. use IkiWiki 2.00;
  29. sub import
  30. {
  31.     hook (type => "pagetemplate"id => "license"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 => "license") &&
  42.     defined $template->param ('license'))
  43.     {
  44.     my $content;
  45.     my $license_page bestlink ($page"license") || return;
  46.     my $license_file $pagesources{$license_page} || return;
  47.     #my $pagetype = pagetype ($license_file);
  48.     # Check if ``$pagetype eq 'html'''?
  49.     $content readfile (srcfile ($license_file));
  50.     if (defined $content && length $content)
  51.     {
  52.         $template->param (license =>
  53.           IkiWiki::linkify ($page$destpage$content));
  54.     }
  55.     }
  56. }
  57. 1