]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminDeleteAcl.php
function run: @return mixed
[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  * Delete 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     private 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     /**
81      * @param WikiDB $dbi
82      * @param string $argstr
83      * @param WikiRequest $request
84      * @param string $basepage
85      * @return mixed
86      */
87     function run($dbi, $argstr, &$request, $basepage)
88     {
89         if ($request->getArg('action') != 'browse') {
90             if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("AdminDeleteAcl")) {
91                 return $this->disabled(_("Plugin not run: not in browse mode"));
92             }
93         }
94         if (!ENABLE_PAGEPERM) {
95             return $this->disabled("ENABLE_PAGEPERM = false");
96         }
97
98         $args = $this->getArgs($argstr, $request);
99         $this->_args = $args;
100         $this->preSelectS($args, $request);
101
102         $p = $request->getArg('p');
103         $post_args = $request->getArg('admin_deleteacl');
104         $pages = array();
105         if ($p && !$request->isPost())
106             $pages = $p;
107         elseif ($this->_list)
108             $pages = $this->_list;
109         $header = HTML::fieldset();
110         if ($p && $request->isPost()) {
111             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
112                 $request->_notAuthorized(WIKIAUTH_ADMIN);
113                 $this->disabled("! user->isAdmin");
114             }
115             return $this->deleteaclPages($request, array_keys($p));
116         }
117         if (empty($pages)) {
118             // List all pages to select from.
119             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
120         }
121         $pagelist = new PageList_Selectable($args['info'],
122             $args['exclude'],
123             array('types' => array(
124                 'acl'
125                 => new _PageList_Column_acl('acl', _("ACL")))));
126
127         $pagelist->addPageList($pages);
128         $button_label_delete_acl = _("Delete ACL");
129         $header->pushContent(HTML::legend(_("Select the pages where to delete access rights")));
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
146 // Local Variables:
147 // mode: php
148 // tab-width: 8
149 // c-basic-offset: 4
150 // c-hanging-comment-ender-p: nil
151 // indent-tabs-mode: nil
152 // End: