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