summaryrefslogtreecommitdiff
path: root/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. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. # for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. # A footer with licensing information will be added to every rendered page if
  19. # (a) such a footer isn't present already (see the `meta' plugin's ``license''
  20. # facility) and (b) a file `license.html' is found (using the same rules as for
  21. # the sidebar plugin).
  22. #
  23. # The state which page's license text was gathered from which source is not
  24. # tracked, so you'll need a full wiki-rebuild if (b)'s files are changed.
  25. #
  26. # You can use wiki links in `license.html'.
  27. package IkiWiki::Plugin::license;
  28. use warnings;
  29. use strict;
  30. use IkiWiki 2.00;
  31. sub import
  32. {
  33. hook (type => "pagetemplate", id => "license", call => \&pagetemplate,
  34. # Run last, as to have the `meta' plugin do its work first.
  35. last => 1);
  36. }
  37. sub pagetemplate (@)
  38. {
  39. my %params = @_;
  40. my $page = $params{page};
  41. my $destpage = $params{destpage};
  42. my $template = $params{template};
  43. if ($template->query (name => "license") &&
  44. ! defined $template->param ('license'))
  45. {
  46. my $content;
  47. my $license_page = bestlink ($page, "license") || return;
  48. my $license_file = $pagesources{$license_page} || return;
  49. #my $pagetype = pagetype ($license_file);
  50. # Check if ``$pagetype eq 'html'''?
  51. $content = readfile (srcfile ($license_file));
  52. if (defined $content && length $content)
  53. {
  54. $template->param (license =>
  55. IkiWiki::linkify ($page, $destpage, $content));
  56. }
  57. }
  58. }
  59. 1