]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSetExternal.php
private --> protected
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSetExternal.php
1 <?php
2
3 /*
4  * Copyright 2005 $ThePhpWikiProgrammingTeam
5  * Copyright 2008-2009 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  * Usage:   <<WikiAdminSetExternal s||=* >> or called via WikiAdminSelect
26  * @author:  Marc-Etienne Vargenau, Alcatel-Lucent
27  */
28 require_once 'lib/PageList.php';
29 require_once 'lib/plugin/WikiAdminSelect.php';
30
31 class WikiPlugin_WikiAdminSetExternal
32     extends WikiPlugin_WikiAdminSelect
33 {
34     function getName()
35     {
36         return _("WikiAdminSetExternal");
37     }
38
39     function getDescription()
40     {
41         return _("Mark selected pages as external.");
42     }
43
44     function getDefaultArguments()
45     {
46         return array_merge
47         (
48             WikiPlugin_WikiAdminSelect::getDefaultArguments(),
49             array(
50                 'external' => 1,
51                 /* Columns to include in listing */
52                 'info' => 'pagename,external,mtime',
53             ));
54     }
55
56     function setExternalPages(&$dbi, &$request, $pages)
57     {
58         $result = HTML::div();
59         $ul = HTML::ul();
60         $count = 0;
61         foreach ($pages as $name) {
62             $page = $dbi->getPage($name);
63             $current = $page->getCurrentRevision();
64             $external = $current->get('external');
65             if (!$external) $external = 0;
66             $external = (bool)$external;
67             if (!$external) {
68                 if (!mayAccessPage('change', $name)) {
69                     $result->setAttr('class', 'error');
70                     $result->pushContent(HTML::p(fmt("Access denied to change page ā€œ%sā€.",
71                         WikiLink($name))));
72                 } else {
73                     $page->set('external', (bool)1);
74                     $ul->pushContent(HTML::li(fmt("change page ā€œ%sā€ to external.", WikiLink($name))));
75                     $count++;
76                 }
77             }
78         }
79         if ($count) {
80             $dbi->touch();
81             $result->setAttr('class', 'feedback');
82             if ($count == 1) {
83                 $result->pushContent(HTML::p(_("One page has been changed:")));
84             } else {
85                 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
86             }
87             $result->pushContent($ul);
88             return $result;
89         } else {
90             $result->setAttr('class', 'error');
91             $result->pushContent(HTML::p(_("No pages changed.")));
92             return $result;
93         }
94     }
95
96     function run($dbi, $argstr, &$request, $basepage)
97     {
98         if ($request->getArg('action') != 'browse') {
99             if (!$request->getArg('action') == _("PhpWikiAdministration/SetExternal")) {
100                 return $this->disabled(_("Plugin not run: not in browse mode"));
101             }
102         }
103
104         $args = $this->getArgs($argstr, $request);
105         $this->_args = $args;
106         $this->preSelectS($args, $request);
107
108         $p = $request->getArg('p');
109         if (!$p) $p = $this->_list;
110         $post_args = $request->getArg('admin_external');
111         if (!$request->isPost() and empty($post_args['external']))
112             $post_args['external'] = $args['external'];
113         $pages = array();
114         if ($p && !$request->isPost())
115             $pages = $p;
116         if ($p && $request->isPost() &&
117             !empty($post_args['button']) && empty($post_args['cancel'])
118         ) {
119             // without individual PagePermissions:
120             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
121                 $request->_notAuthorized(WIKIAUTH_ADMIN);
122                 $this->disabled("! user->isAdmin");
123             }
124             // Real action
125             return $this->setExternalPages($dbi, $request, array_keys($p));
126         }
127         $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
128         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
129         $pagelist->addPageList($pages);
130
131         $header = HTML::fieldset();
132         $button_label = _("Set pages to external");
133         $header->pushContent(HTML::legend(_("Select the pages to set as external")));
134
135         $buttons = HTML::p(Button('submit:admin_external[button]', $button_label, 'wikiadmin'),
136             Button('submit:admin_external[cancel]', _("Cancel"), 'button'));
137         $header->pushContent($buttons);
138
139         return HTML::form(array('action' => $request->getPostURL(),
140                 'method' => 'post'),
141             $header,
142             $pagelist->getContent(),
143             HiddenInputs($request->getArgs(),
144                 false,
145                 array('admin_external')),
146             ENABLE_PAGEPERM
147                 ? ''
148                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
149     }
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: