preview.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2015 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. use strict;
  15. use v5.10;
  16. =head1 Preview Extension
  17. This module allows you to preview changes in HTML output. Oddmuse keeps a cache
  18. of the HTML produced for each wiki page. If you install new modules, the HTML
  19. produced for a page can change, but visitors will not see the new HTML because
  20. the cache still contains the old HTML. Now you have two options: 1. clear the
  21. HTML cache (Oddmuse will regenerate it as visitors look at the old pages), or 2.
  22. edit each page in order to regenerate the HTML cache. What happens in practice
  23. is that you add new modules and you aren't sure whether this breaks old pages
  24. and so you do don't dare clear the HTML cache. Let sleeping dogs lie.
  25. The Preview Extension produces a list of all the pages where the cached HTML
  26. differs from the HTML produced by the current set of modules. If you agree with
  27. the new HTML, feel free to clear the HTML cache. That's the point of this
  28. extension.
  29. =cut
  30. our ($q, %Action, $UseCache, @MyAdminCode);
  31. AddModuleDescription('preview.pl', 'Preview Extension');
  32. $Action{preview} = \&DoPreview;
  33. sub DoPreview {
  34. print GetHeader('', T('Pages with changed HTML'));
  35. print $q->start_div({-class=>'content preview'}), $q->start_p();
  36. foreach my $id (AllPagesList()) {
  37. OpenPage($id);
  38. my $cache = ToString(\&PrintPageHtml);
  39. local $UseCache = 0;
  40. my $html = ToString(\&PrintPageHtml);
  41. if ($cache ne $html) {
  42. print GetPageLink($id), ' ',
  43. ScriptLink("action=browse;id=$id;cache=0", T('Preview')),
  44. $q->br();
  45. }
  46. }
  47. print $q->end_p(), $q->end_div();
  48. PrintFooter();
  49. }
  50. push(@MyAdminCode, \&PreviewMenu);
  51. sub PreviewMenu {
  52. my ($id, $menuref, $restref) = @_;
  53. push(@$menuref, ScriptLink('action=preview', T('Preview changes in HTML output'), 'preview'));
  54. }