]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSetExternal.php
getName should not translate
[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 getDescription()
35     {
36         return _("Mark selected pages as external.");
37     }
38
39     function getDefaultArguments()
40     {
41         return array_merge
42         (
43             WikiPlugin_WikiAdminSelect::getDefaultArguments(),
44             array(
45                 'external' => 1,
46                 /* Columns to include in listing */
47                 'info' => 'pagename,external,mtime',
48             ));
49     }
50
51     function setExternalPages(&$dbi, &$request, $pages)
52     {
53         $result = HTML::div();
54         $ul = HTML::ul();
55         $count = 0;
56         foreach ($pages as $name) {
57             $page = $dbi->getPage($name);
58             $current = $page->getCurrentRevision();
59             $external = $current->get('external');
60             if (!$external) $external = 0;
61             $external = (bool)$external;
62             if (!$external) {
63                 if (!mayAccessPage('change', $name)) {
64                     $result->setAttr('class', 'error');
65                     $result->pushContent(HTML::p(fmt("Access denied to change page ā€œ%sā€.",
66                         WikiLink($name))));
67                 } else {
68                     $page->set('external', (bool)1);
69                     $ul->pushContent(HTML::li(fmt("change page ā€œ%sā€ to external.", WikiLink($name))));
70                     $count++;
71                 }
72             }
73         }
74         if ($count) {
75             $dbi->touch();
76             $result->setAttr('class', 'feedback');
77             if ($count == 1) {
78                 $result->pushContent(HTML::p(_("One page has been changed:")));
79             } else {
80                 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
81             }
82             $result->pushContent($ul);
83             return $result;
84         } else {
85             $result->setAttr('class', 'error');
86             $result->pushContent(HTML::p(_("No pages changed.")));
87             return $result;
88         }
89     }
90
91     function run($dbi, $argstr, &$request, $basepage)
92     {
93         if ($request->getArg('action') != 'browse') {
94             if (!$request->getArg('action') == _("PhpWikiAdministration/SetExternal")) {
95                 return $this->disabled(_("Plugin not run: not in browse mode"));
96             }
97         }
98
99         $args = $this->getArgs($argstr, $request);
100         $this->_args = $args;
101         $this->preSelectS($args, $request);
102
103         $p = $request->getArg('p');
104         if (!$p) $p = $this->_list;
105         $post_args = $request->getArg('admin_external');
106         if (!$request->isPost() and empty($post_args['external']))
107             $post_args['external'] = $args['external'];
108         $pages = array();
109         if ($p && !$request->isPost())
110             $pages = $p;
111         if ($p && $request->isPost() &&
112             !empty($post_args['button']) && empty($post_args['cancel'])
113         ) {
114             // without individual PagePermissions:
115             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
116                 $request->_notAuthorized(WIKIAUTH_ADMIN);
117                 $this->disabled("! user->isAdmin");
118             }
119             // Real action
120             return $this->setExternalPages($dbi, $request, array_keys($p));
121         }
122         $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
123         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
124         $pagelist->addPageList($pages);
125
126         $header = HTML::fieldset();
127         $button_label = _("Set pages to external");
128         $header->pushContent(HTML::legend(_("Select the pages to set as external")));
129
130         $buttons = HTML::p(Button('submit:admin_external[button]', $button_label, 'wikiadmin'),
131             Button('submit:admin_external[cancel]', _("Cancel"), 'button'));
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_external')),
141             ENABLE_PAGEPERM
142                 ? ''
143                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
144     }
145
146 }
147
148 // Local Variables:
149 // mode: php
150 // tab-width: 8
151 // c-basic-offset: 4
152 // c-hanging-comment-ender-p: nil
153 // indent-tabs-mode: nil
154 // End: