]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminDeleteAcl.php
Remove unused
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminDeleteAcl.php
1 <?php
2
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  * Copyright 2009-2010 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
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.
13  *
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.
18  *
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.
22  */
23
24 /**
25  * Set simple individual PagePermissions
26  *
27  * Usage:   <<WikiAdminAclDelete >> or called via WikiAdminSelect
28  * Author:  Marc-Etienne Vargenau, Alcatel-Lucent
29  *
30  */
31
32 require_once 'lib/PageList.php';
33 require_once 'lib/plugin/WikiAdminSelect.php';
34
35 class WikiPlugin_WikiAdminDeleteAcl
36     extends WikiPlugin_WikiAdminSelect
37 {
38     function getName()
39     {
40         return _("WikiDeleteAcl");
41     }
42
43     function getDescription()
44     {
45         return _("Delete page permissions.");
46     }
47
48     function deleteaclPages(&$request, $pages)
49     {
50         $result = HTML::div();
51         $count = 0;
52         $dbi =& $request->_dbi;
53         $perm = new PagePermission('');
54         $perm->sanify();
55         foreach ($pages as $pagename) {
56             // check if unchanged? we need a deep array_equal
57             $page = $dbi->getPage($pagename);
58             $oldperm = getPagePermissions($page);
59             setPagePermissions($page, $perm);
60             $result->setAttr('class', 'feedback');
61             $result->pushContent(HTML::p(fmt("ACL deleted for page ā€œ%sā€", $pagename)));
62             $current = $page->getCurrentRevision();
63             $version = $current->getVersion();
64             $meta = $current->_data;
65             $text = $current->getPackedContent();
66             $meta['summary'] = sprintf(_("ACL deleted for page ā€œ%sā€"), $pagename);
67             $meta['is_minor_edit'] = 1;
68             $meta['author'] = $request->_user->UserName();
69             unset($meta['mtime']); // force new date
70             $page->save($text, $version + 1, $meta);
71             $count++;
72         }
73         if ($count) {
74             $dbi->touch();
75             $result->setAttr('class', 'feedback');
76             if ($count > 1) {
77                 $result->pushContent(HTML::p(fmt("%d pages have been changed.", $count)));
78             }
79         } else {
80             $result->setAttr('class', 'error');
81             $result->pushContent(HTML::p(_("No pages changed.")));
82         }
83         return $result;
84     }
85
86     function run($dbi, $argstr, &$request, $basepage)
87     {
88         if ($request->getArg('action') != 'browse') {
89             if ($request->getArg('action') != _("PhpWikiAdministration/AdminAclDelete")) {
90                 return $this->disabled(_("Plugin not run: not in browse mode"));
91             }
92         }
93         if (!ENABLE_PAGEPERM) {
94             return $this->disabled("ENABLE_PAGEPERM = false");
95         }
96
97         $args = $this->getArgs($argstr, $request);
98         $this->_args = $args;
99         $this->preSelectS($args, $request);
100
101         $p = $request->getArg('p');
102         $post_args = $request->getArg('admin_deleteacl');
103         $pages = array();
104         if ($p && !$request->isPost())
105             $pages = $p;
106         elseif ($this->_list)
107             $pages = $this->_list;
108         $header = HTML::fieldset();
109         if ($p && $request->isPost()) {
110             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
111                 $request->_notAuthorized(WIKIAUTH_ADMIN);
112                 $this->disabled("! user->isAdmin");
113             }
114             return $this->deleteaclPages($request, array_keys($p));
115         }
116         if (empty($pages)) {
117             // List all pages to select from.
118             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
119         }
120         $pagelist = new PageList_Selectable($args['info'],
121             $args['exclude'],
122             array('types' => array(
123                 'acl'
124                 => new _PageList_Column_acl('acl', _("ACL")))));
125
126         $pagelist->addPageList($pages);
127         $button_label_delete_acl = _("Delete ACL");
128         $header = $this->deleteaclForm($header, $pages);
129         $header->pushContent(HTML::legend(_("Select the pages where to delete access rights")));
130
131         $buttons = HTML::p(Button('submit:admin_deleteacl', $button_label_delete_acl, 'wikiadmin'));
132         $header->pushContent($buttons);
133
134         return HTML::form(array('action' => $request->getPostURL(),
135                 'method' => 'post'),
136             $header,
137             $pagelist->getContent(),
138             HiddenInputs($request->getArgs(),
139                 false,
140                 array('admin_deleteacl')),
141             ENABLE_PAGEPERM
142                 ? ''
143                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
144     }
145
146     function deleteaclForm(&$header, $pagehash)
147     {
148
149         $pages = array();
150         foreach ($pagehash as $name => $checked) {
151             if ($checked) $pages[] = $name;
152         }
153
154         $header->pushContent(HTML::strong(_("Selected Pages: ")), HTML::tt(join(', ', $pages)), HTML::br());
155         return $header;
156     }
157 }
158
159 // Local Variables:
160 // mode: php
161 // tab-width: 8
162 // c-basic-offset: 4
163 // c-hanging-comment-ender-p: nil
164 // indent-tabs-mode: nil
165 // End: