plainsite.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright (C) 2005-2007 Fletcher T. Penney <fletcher@freeshell.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('plainsite.pl', 'PlainSite Module');
  21. our ($q, $OpenPageName, $HomePage, $CommentsPrefix, $RCName);
  22. our ($PlainSiteAllowCommentLink);
  23. *OldGetFooterLinks = \&GetFooterLinks;
  24. *GetFooterLinks = \&PlainSiteGetFooterLinks;
  25. sub PlainSiteGetFooterLinks {
  26. return if (GetParam('action','') eq 'static');
  27. if (UserIsAdmin() or UserIsEditor()) {
  28. return OldGetFooterLinks(@_);
  29. } else {
  30. if ($PlainSiteAllowCommentLink) {
  31. return CommentFooterLink(@_);
  32. } else {
  33. return;
  34. }
  35. }
  36. }
  37. sub CommentFooterLink {
  38. my ($id, $rev) = @_;
  39. my @elements;
  40. if ($id and $rev ne 'history' and $rev ne 'edit') {
  41. if ($CommentsPrefix) {
  42. if ($OpenPageName =~ /^$CommentsPrefix(.*)/) {
  43. push(@elements, GetPageLink($1, undef, 'original'));
  44. } else {
  45. push(@elements, GetPageLink($CommentsPrefix . $OpenPageName, undef, 'comment'));
  46. }
  47. }
  48. }
  49. return @elements ? $q->span({-class=>'edit bar'}, $q->br(), @elements) : '';
  50. }
  51. *OldGetFooterTimestamp = \&GetFooterTimestamp;
  52. *GetFooterTimestamp = \&PlainSiteGetFooterTimestamp;
  53. sub PlainSiteGetFooterTimestamp {
  54. return if (GetParam('action','') eq 'static');
  55. if (UserIsAdmin() or UserIsEditor()) {
  56. return OldGetFooterTimestamp(@_);
  57. } else {
  58. return;
  59. }
  60. }
  61. *OldGetRcRss = \&GetRcRss;
  62. *GetRcRss = \&PlainSiteGetRcRss;
  63. sub PlainSiteGetRcRss {
  64. # Have Rss point to HomePage rather than RecentChanges, since we want
  65. # to avoid drawing visitors to RecentChanges
  66. $RCName = $HomePage;
  67. OldGetRcRss(@_);
  68. }
  69. *GetNearLinksUsed = \&PlainSiteGetNearLinksUsed;
  70. sub PlainSiteGetNearLinksUsed {
  71. return;
  72. }
  73. # Disable the Recent Change function on cluster pages
  74. # Must load before clustermap module if that module is used
  75. *OldPrintRc = \&PrintRc;
  76. *PrintRc = \&PlainSitePrintRc;
  77. sub PlainSitePrintRc{
  78. my ($id, $standalone) = @_;
  79. if (!(UserIsAdmin() or UserIsEditor())) {
  80. DoRc(\&PlainSiteRcHtml);
  81. } else {
  82. return OldPrintRc($id, $standalone);
  83. }
  84. }
  85. sub PlainSiteRcHtml {
  86. my ($html, $inlist) = ('', 0);
  87. if (!(UserIsAdmin() or UserIsEditor())) {
  88. return;
  89. } else {
  90. *GetRcHtml = \&OldGetRcHtml;
  91. return OldGetRcHtml();
  92. }
  93. }