sidebar.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2004 Tilmann Holst
  2. # Copyright (C) 2004, 2005, 2007 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use strict;
  17. use v5.10;
  18. AddModuleDescription('sidebar.pl', 'Sidebar Extension');
  19. our ($OpenPageName, @MyInitVariables, %AdminPages);
  20. our ($SidebarName);
  21. # Include this page on every page:
  22. $SidebarName = 'SideBar';
  23. # do this later so that the user can customize $SidebarName
  24. push(@MyInitVariables, \&SidebarInit);
  25. sub SidebarInit {
  26. $SidebarName = FreeToNormal($SidebarName); # spaces to underscores
  27. $AdminPages{$SidebarName} = 1;
  28. }
  29. *OldSideBarGetHeader = \&GetHeader;
  30. *GetHeader = \&NewSideBarGetHeader;
  31. # this assumes that *all* calls to GetHeader will print!
  32. sub NewSideBarGetHeader {
  33. my ($id) = @_;
  34. print OldSideBarGetHeader(@_);
  35. # While rendering, OpenPageName must point to the sidebar, so that
  36. # the form extension which checks whether the current page is locked
  37. # will check the SideBar lock and not the real page's lock.
  38. local $OpenPageName = $SidebarName;
  39. print '<div class="sidebar">';
  40. # This makes sure that $Page{text} remains undisturbed.
  41. PrintWikiToHTML(GetPageContent($SidebarName));
  42. print '</div>';
  43. return '';
  44. }