hiddenpages.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 3 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, see <http://www.gnu.org/licenses/>.
  18. # This module offers the possibility to restrict viewing of "hidden"
  19. # pages to only editors or admins. The restriction may be based
  20. # on a pattern matching the page id or to a membership to a certain
  21. # page cluster.
  22. use strict;
  23. use v5.10;
  24. AddModuleDescription('hiddenpages.pl', 'Hidden Pages Extension');
  25. our ($HiddenCluster, $HideEditorPages, $HideAdminPages, $HideRegExEditor, $HideRegExAdmin);
  26. # $HiddenCluster is a cluster name for hidden pages. Default
  27. # is pages in the cluster "HiddenPage". You can override this
  28. # value in your config file.
  29. $HiddenCluster = 'HiddenPage';
  30. # $Hide*Pages sets the access level to hidden pages:
  31. # 0 = Hidden pages visible to all
  32. # 1 = Password required
  33. # You can override this value in your config file.
  34. # NOTE: Pages for Editors are also visible to Admins!
  35. $HideEditorPages = 1;
  36. $HideAdminPages = 1;
  37. # $HideRegEx* are regular expressions to find hidden pages. Default is pages
  38. # ending with "HiddenE" for editors and "Hidden" for admins. You can override
  39. # this value in your config file.
  40. $HideRegExEditor = 'HiddenE$';
  41. $HideRegExAdmin = 'Hidden$';
  42. *OldOpenPage = \&OpenPage;
  43. *OpenPage = \&NewOpenPage;
  44. sub NewOpenPage {
  45. # Get page id/name sent in to OpenPage
  46. my ($id) = @_;
  47. # Shield the Private pages
  48. my $hidden = 0;
  49. # Check for match of HiddenPages
  50. if ($id and $id =~ /$HideRegExEditor/) {
  51. $hidden = "edi";
  52. } elsif ($id and $id =~ /$HideRegExAdmin/) {
  53. $hidden = "adi";
  54. }
  55. my $action = lc(GetParam('action', ''));
  56. if ($action ne 'rc' && $action ne 'search') {
  57. # Check the different levels of access
  58. if ($hidden eq "edi" && $HideEditorPages == 1 && (!UserIsEditor() && !UserIsAdmin())) {
  59. ReportError(T("Only Editors are allowed to see this hidden page."), "401 Not Authorized");
  60. } elsif ($hidden eq "adi" && $HideAdminPages == 1 && !UserIsAdmin()) {
  61. ReportError(T("Only Admins are allowed to see this hidden page."), "401 Not Authorized");
  62. }
  63. }
  64. # Give control back to OpenPage()
  65. OldOpenPage(@_);
  66. }