plainsite.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 3 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, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('plainsite.pl', 'PlainSite Module');
  18. our ($q, $OpenPageName, $HomePage, $CommentsPrefix, $RCName);
  19. our ($PlainSiteAllowCommentLink);
  20. *OldGetFooterLinks = \&GetFooterLinks;
  21. *GetFooterLinks = \&PlainSiteGetFooterLinks;
  22. sub PlainSiteGetFooterLinks {
  23. return if (GetParam('action','') eq 'static');
  24. if (UserIsAdmin() or UserIsEditor()) {
  25. return OldGetFooterLinks(@_);
  26. } else {
  27. if ($PlainSiteAllowCommentLink) {
  28. return CommentFooterLink(@_);
  29. } else {
  30. return;
  31. }
  32. }
  33. }
  34. sub CommentFooterLink {
  35. my ($id, $rev) = @_;
  36. my @elements;
  37. if ($id and $rev ne 'history' and $rev ne 'edit') {
  38. if ($CommentsPrefix) {
  39. if ($OpenPageName =~ /^$CommentsPrefix(.*)/) {
  40. push(@elements, GetPageLink($1, undef, 'original'));
  41. } else {
  42. push(@elements, GetPageLink($CommentsPrefix . $OpenPageName, undef, 'comment'));
  43. }
  44. }
  45. }
  46. return @elements ? $q->span({-class=>'edit bar'}, $q->br(), @elements) : '';
  47. }
  48. *OldGetFooterTimestamp = \&GetFooterTimestamp;
  49. *GetFooterTimestamp = \&PlainSiteGetFooterTimestamp;
  50. sub PlainSiteGetFooterTimestamp {
  51. return if (GetParam('action','') eq 'static');
  52. if (UserIsAdmin() or UserIsEditor()) {
  53. return OldGetFooterTimestamp(@_);
  54. } else {
  55. return;
  56. }
  57. }
  58. *OldGetRcRss = \&GetRcRss;
  59. *GetRcRss = \&PlainSiteGetRcRss;
  60. sub PlainSiteGetRcRss {
  61. # Have Rss point to HomePage rather than RecentChanges, since we want
  62. # to avoid drawing visitors to RecentChanges
  63. $RCName = $HomePage;
  64. OldGetRcRss(@_);
  65. }
  66. *GetNearLinksUsed = \&PlainSiteGetNearLinksUsed;
  67. sub PlainSiteGetNearLinksUsed {
  68. return;
  69. }
  70. # Disable the Recent Change function on cluster pages
  71. # Must load before clustermap module if that module is used
  72. *OldPrintRc = \&PrintRc;
  73. *PrintRc = \&PlainSitePrintRc;
  74. sub PlainSitePrintRc{
  75. my ($id, $standalone) = @_;
  76. if (!(UserIsAdmin() or UserIsEditor())) {
  77. DoRc(\&PlainSiteRcHtml);
  78. } else {
  79. return OldPrintRc($id, $standalone);
  80. }
  81. }
  82. sub PlainSiteRcHtml {
  83. my ($html, $inlist) = ('', 0);
  84. if (!(UserIsAdmin() or UserIsEditor())) {
  85. return;
  86. } else {
  87. *GetRcHtml = \&OldGetRcHtml;
  88. return OldGetRcHtml();
  89. }
  90. }