4 * Copyright 2004 $ThePhpWikiProgrammingTeam
5 * Copyright 2009-2010 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Set simple individual PagePermissions
27 * Usage: <<WikiAdminSetAclSimple >> or called via WikiAdminSelect
28 * Author: Marc-Etienne Vargenau, Alcatel-Lucent
32 require_once('lib/plugin/WikiAdminSetAcl.php');
34 class WikiPlugin_WikiAdminSetAclSimple
35 extends WikiPlugin_WikiAdminSetAcl
38 return _("WikiAdminSetAclSimple");
41 function getDescription() {
42 return _("Set simple individual page permissions.");
45 function run($dbi, $argstr, &$request, $basepage) {
46 if ($request->getArg('action') != 'browse') {
47 if ($request->getArg('action') != _("PhpWikiAdministration/SetAclSimple")) {
48 return $this->disabled(_("Plugin not run: not in browse mode"));
51 if (!ENABLE_PAGEPERM) {
52 return $this->disabled("ENABLE_PAGEPERM = false");
55 $args = $this->getArgs($argstr, $request);
57 $this->preSelectS($args, $request);
59 $p = $request->getArg('p');
60 $post_args = $request->getArg('admin_setacl');
62 if ($p && !$request->isPost())
65 $pages = $this->_list;
66 $header = HTML::fieldset();
67 if ($p && $request->isPost() &&
68 (!empty($post_args['aclliberal']) || !empty($post_args['aclrestricted']))) {
69 // without individual PagePermissions:
70 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
71 $request->_notAuthorized(WIKIAUTH_ADMIN);
72 $this->disabled("! user->isAdmin");
74 if (!empty($post_args['aclliberal'])) {
75 return $this->setaclPages($request, array_keys($p), $this->liberalPerms());
76 } elseif (!empty($post_args['aclrestricted'])) {
77 return $this->setaclPages($request, array_keys($p), $this->restrictedPerms());
81 // List all pages to select from.
82 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
84 $pagelist = new PageList_Selectable($args['info'],
86 array('types' => array(
88 => new _PageList_Column_acl('acl', _("ACL")))));
90 $pagelist->addPageList($pages);
91 $button_label_liberal = _("Set Liberal Access Rights");
92 $button_label_restrictive = _("Set Restrictive Access Rights");
93 $header = $this->setaclForm($header, $pages);
94 $header->pushContent(HTML::legend(_("Select the pages where to change access rights")));
96 $buttons = HTML::p(Button('submit:admin_setacl[aclliberal]', $button_label_liberal, 'wikiadmin'),
97 Button('submit:admin_setacl[aclrestricted]', $button_label_restrictive, 'wikiadmin'));
98 $header->pushContent($buttons);
100 return HTML::form(array('action' => $request->getPostURL(),
103 $pagelist->getContent(),
104 HiddenInputs($request->getArgs(),
106 array('admin_setacl')),
109 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
113 * acces rights where everyone can edit
114 * _EVERY: view edit list create;
115 * _ADMIN: remove purge dump change;
116 * _OWNER: remove purge dump change;
119 function liberalPerms() {
121 $perm = array('view' => array(ACL_EVERY => true),
122 'edit' => array(ACL_EVERY => true),
123 'create' => array(ACL_EVERY => true),
124 'list' => array(ACL_EVERY => true),
125 'remove' => array(ACL_ADMIN => true,
127 'purge' => array(ACL_ADMIN => true,
129 'dump' => array(ACL_ADMIN => true,
131 'change' => array(ACL_ADMIN => true,
137 * acces rights where only authenticated users can see pages
138 * _AUTHENTICATED: view edit list create;
139 * _ADMIN: remove purge dump change;
140 * _OWNER: remove purge dump change;
141 * _EVERY: -view -edit -list -create;
144 function restrictedPerms() {
146 $perm = array('view' => array(ACL_AUTHENTICATED => true,
148 'edit' => array(ACL_AUTHENTICATED => true,
150 'create' => array(ACL_AUTHENTICATED => true,
152 'list' => array(ACL_AUTHENTICATED => true,
154 'remove' => array(ACL_ADMIN => true,
156 'purge' => array(ACL_ADMIN => true,
158 'dump' => array(ACL_ADMIN => true,
160 'change' => array(ACL_ADMIN => true,
165 function setaclForm(&$header, $pagehash) {
168 foreach ($pagehash as $name => $checked) {
169 if ($checked) $pages[] = $name;
172 $header->pushContent(HTML::strong(_("Selected Pages: ")), HTML::tt(join(', ',$pages)), HTML::br());
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil