hiddenpages.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (C) 2015 Matt Adams <opensource@radicaldynamic.com>
  2. # Copyright (C) 2006 Matthias Dietrich <md (at) plusw (.) de>
  3. # Copyright (C) 2005 Mathias Dahl <mathias . dahl at gmail dot com>
  4. # Copyright (C) 2005 Alex Schroeder <alex@emacswiki.org>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the
  18. # Free Software Foundation, Inc.
  19. # 59 Temple Place, Suite 330
  20. # Boston, MA 02111-1307 USA
  21. # This module offers the possibility to restrict viewing of "hidden"
  22. # pages to only editors or admins. The restriction may be based
  23. # on a pattern matching the page id or to a membership to a certain
  24. # page cluster.
  25. use strict;
  26. use v5.10;
  27. AddModuleDescription('hiddenpages.pl', 'Hidden Pages Extension');
  28. our ($HiddenCluster, $HideEditorPages, $HideAdminPages, $HideRegExEditor, $HideRegExAdmin);
  29. # $HiddenCluster is a cluster name for hidden pages. Default
  30. # is pages in the cluster "HiddenPage". You can override this
  31. # value in your config file.
  32. $HiddenCluster = 'HiddenPage';
  33. # $Hide*Pages sets the access level to hidden pages:
  34. # 0 = Hidden pages visible to all
  35. # 1 = Password required
  36. # You can override this value in your config file.
  37. # NOTE: Pages for Editors are also visible to Admins!
  38. $HideEditorPages = 1;
  39. $HideAdminPages = 1;
  40. # $HideRegEx* are regular expressions to find hidden pages. Default is pages
  41. # ending with "HiddenE" for editors and "Hidden" for admins. You can override
  42. # this value in your config file.
  43. $HideRegExEditor = 'HiddenE$';
  44. $HideRegExAdmin = 'Hidden$';
  45. *OldOpenPage = \&OpenPage;
  46. *OpenPage = \&NewOpenPage;
  47. sub NewOpenPage {
  48. # Get page id/name sent in to OpenPage
  49. my ($id) = @_;
  50. # Shield the Private pages
  51. my $hidden = 0;
  52. # Check for match of HiddenPages
  53. if ($id and $id =~ /$HideRegExEditor/) {
  54. $hidden = "edi";
  55. } elsif ($id and $id =~ /$HideRegExAdmin/) {
  56. $hidden = "adi";
  57. }
  58. my $action = lc(GetParam('action', ''));
  59. if ($action ne 'rc' && $action ne 'search') {
  60. # Check the different levels of access
  61. if ($hidden eq "edi" && $HideEditorPages == 1 && (!UserIsEditor() && !UserIsAdmin())) {
  62. ReportError(T("Only Editors are allowed to see this hidden page."), "401 Not Authorized");
  63. } elsif ($hidden eq "adi" && $HideAdminPages == 1 && !UserIsAdmin()) {
  64. ReportError(T("Only Admins are allowed to see this hidden page."), "401 Not Authorized");
  65. }
  66. }
  67. # Give control back to OpenPage()
  68. OldOpenPage(@_);
  69. }