2015-01-30 16:42:25 +01:00
|
|
|
# Copyright (C) 2015 Matt Adams <opensource@radicaldynamic.com>
|
2006-02-22 17:30:26 +00:00
|
|
|
# Copyright (C) 2006 Matthias Dietrich <md (at) plusw (.) de>
|
2005-08-25 06:18:14 +00:00
|
|
|
# Copyright (C) 2005 Mathias Dahl <mathias . dahl at gmail dot com>
|
|
|
|
|
# Copyright (C) 2005 Alex Schroeder <alex@emacswiki.org>
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2005-08-25 06:18:14 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-25 06:18:14 +00:00
|
|
|
|
|
|
|
|
# This module offers the possibility to restrict viewing of "hidden"
|
2006-02-22 17:30:26 +00:00
|
|
|
# pages to only editors or admins. The restriction may be based
|
2006-01-02 10:15:04 +00:00
|
|
|
# on a pattern matching the page id or to a membership to a certain
|
|
|
|
|
# page cluster.
|
2005-08-25 06:18:14 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('hiddenpages.pl', 'Hidden Pages Extension');
|
2005-08-25 06:18:14 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($HiddenCluster, $HideEditorPages, $HideAdminPages, $HideRegExEditor, $HideRegExAdmin);
|
2006-01-02 10:15:04 +00:00
|
|
|
|
2006-02-22 17:30:26 +00:00
|
|
|
# $HiddenCluster is a cluster name for hidden pages. Default
|
|
|
|
|
# is pages in the cluster "HiddenPage". You can override this
|
|
|
|
|
# value in your config file.
|
|
|
|
|
|
|
|
|
|
$HiddenCluster = 'HiddenPage';
|
2006-01-02 10:15:04 +00:00
|
|
|
|
2006-02-22 17:30:26 +00:00
|
|
|
# $Hide*Pages sets the access level to hidden pages:
|
2006-01-02 10:15:04 +00:00
|
|
|
# 0 = Hidden pages visible to all
|
2006-02-22 17:30:26 +00:00
|
|
|
# 1 = Password required
|
2006-01-02 10:15:04 +00:00
|
|
|
# You can override this value in your config file.
|
2006-02-22 17:30:26 +00:00
|
|
|
# NOTE: Pages for Editors are also visible to Admins!
|
2006-01-02 10:15:04 +00:00
|
|
|
|
2006-02-22 17:30:26 +00:00
|
|
|
$HideEditorPages = 1;
|
|
|
|
|
$HideAdminPages = 1;
|
2005-08-25 06:18:14 +00:00
|
|
|
|
2006-02-22 17:30:26 +00:00
|
|
|
# $HideRegEx* are regular expressions to find hidden pages. Default is pages
|
|
|
|
|
# ending with "HiddenE" for editors and "Hidden" for admins. You can override
|
|
|
|
|
# this value in your config file.
|
2005-08-25 06:18:14 +00:00
|
|
|
|
2006-02-22 17:30:26 +00:00
|
|
|
$HideRegExEditor = 'HiddenE$';
|
|
|
|
|
$HideRegExAdmin = 'Hidden$';
|
2005-08-25 06:18:14 +00:00
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldOpenPage = \&OpenPage;
|
|
|
|
|
*OpenPage = \&NewOpenPage;
|
2005-08-25 06:18:14 +00:00
|
|
|
|
|
|
|
|
sub NewOpenPage {
|
2006-02-22 17:30:26 +00:00
|
|
|
# Get page id/name sent in to OpenPage
|
|
|
|
|
my ($id) = @_;
|
|
|
|
|
|
|
|
|
|
# Shield the Private pages
|
|
|
|
|
my $hidden = 0;
|
|
|
|
|
|
|
|
|
|
# Check for match of HiddenPages
|
|
|
|
|
if ($id and $id =~ /$HideRegExEditor/) {
|
|
|
|
|
$hidden = "edi";
|
|
|
|
|
} elsif ($id and $id =~ /$HideRegExAdmin/) {
|
|
|
|
|
$hidden = "adi";
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 16:42:25 +01:00
|
|
|
my $action = lc(GetParam('action', ''));
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2015-01-30 16:42:25 +01:00
|
|
|
if ($action ne 'rc' && $action ne 'search') {
|
|
|
|
|
# Check the different levels of access
|
|
|
|
|
if ($hidden eq "edi" && $HideEditorPages == 1 && (!UserIsEditor() && !UserIsAdmin())) {
|
|
|
|
|
ReportError(T("Only Editors are allowed to see this hidden page."), "401 Not Authorized");
|
|
|
|
|
} elsif ($hidden eq "adi" && $HideAdminPages == 1 && !UserIsAdmin()) {
|
|
|
|
|
ReportError(T("Only Admins are allowed to see this hidden page."), "401 Not Authorized");
|
|
|
|
|
}
|
2006-02-22 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Give control back to OpenPage()
|
|
|
|
|
OldOpenPage(@_);
|
2005-08-25 06:18:14 +00:00
|
|
|
}
|