]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminDeleteAcl.php
Remove unused variables
[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             setPagePermissions($page, $perm);
59             $result->setAttr('class', 'feedback');
60             $result->pushContent(HTML::p(fmt("ACL deleted for page ā€œ%sā€", $pagename)));
61             $current = $page->getCurrentRevision();
62             $version = $current->getVersion();
63             $meta = $current->_data;
64             $text = $current->getPackedContent();
65             $meta['summary'] = sprintf(_("ACL deleted for page ā€œ%sā€"), $pagename);
66             $meta['is_minor_edit'] = 1;
67             $meta['author'] = $request->_user->UserName();
68             unset($meta['mtime']); // force new date
69             $page->save($text, $version + 1, $meta);
70             $count++;
71         }
72         if ($count) {
73             $dbi->touch();
74             $result->setAttr('class', 'feedback');
75             if ($count > 1) {
76                 $result->pushContent(HTML::p(fmt("%d pages have been changed.", $count)));
77             }
78         } else {
79             $result->setAttr('class', 'error');
80             $result->pushContent(HTML::p(_("No pages changed.")));
81         }
82         return $result;
83     }
84
85     function run($dbi, $argstr, &$request, $basepage)
86     {
87         if ($request->getArg('action') != 'browse') {
88             if ($request->getArg('action') != _("PhpWikiAdministration/AdminAclDelete")) {
89                 return $this->disabled(_("Plugin not run: not in browse mode"));
90             }
91         }
92         if (!ENABLE_PAGEPERM) {
93             return $this->disabled("ENABLE_PAGEPERM = false");
94         }
95
96         $args = $this->getArgs($argstr, $request);
97         $this->_args = $args;
98         $this->preSelectS($args, $request);
99
100         $p = $request->getArg('p');
101         $post_args = $request->getArg('admin_deleteacl');
102         $pages = array();
103         if ($p && !$request->isPost())
104             $pages = $p;
105         elseif ($this->_list)
106             $pages = $this->_list;
107         $header = HTML::fieldset();
108         if ($p && $request->isPost()) {
109             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
110                 $request->_notAuthorized(WIKIAUTH_ADMIN);
111                 $this->disabled("! user->isAdmin");
112             }
113             return $this->deleteaclPages($request, array_keys($p));
114         }
115         if (empty($pages)) {
116             // List all pages to select from.
117             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
118         }
119         $pagelist = new PageList_Selectable($args['info'],
120             $args['exclude'],
121             array('types' => array(
122                 'acl'
123                 => new _PageList_Column_acl('acl', _("ACL")))));
124
125         $pagelist->addPageList($pages);
126         $button_label_delete_acl = _("Delete ACL");
127         $header = $this->deleteaclForm($header, $pages);
128         $header->pushContent(HTML::legend(_("Select the pages where to delete access rights")));
129
130         $buttons = HTML::p(Button('submit:admin_deleteacl', $button_label_delete_acl, 'wikiadmin'));
131         $header->pushContent($buttons);
132
133         return HTML::form(array('action' => $request->getPostURL(),
134                 'method' => 'post'),
135             $header,
136             $pagelist->getContent(),
137             HiddenInputs($request->getArgs(),
138                 false,
139                 array('admin_deleteacl')),
140             ENABLE_PAGEPERM
141                 ? ''
142                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
143     }
144
145     function deleteaclForm(&$header, $pagehash)
146     {
147
148         $pages = array();
149         foreach ($pagehash as $name => $checked) {
150             if ($checked) $pages[] = $name;
151         }
152
153         $header->pushContent(HTML::strong(_("Selected Pages: ")), HTML::tt(join(', ', $pages)), HTML::br());
154         return $header;
155     }
156 }
157
158 // Local Variables:
159 // mode: php
160 // tab-width: 8
161 // c-basic-offset: 4
162 // c-hanging-comment-ender-p: nil
163 // indent-tabs-mode: nil
164 // End: