]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSetExternal.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSetExternal.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
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
20  * along with PhpWiki; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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         return _("WikiAdminSetExternal");
36     }
37
38     function getDescription() {
39         return _("Mark selected pages as external.");
40     }
41
42     function getDefaultArguments() {
43         return array_merge
44             (
45              WikiPlugin_WikiAdminSelect::getDefaultArguments(),
46              array(
47                    'external'         => 1,
48                    /* Columns to include in listing */
49                    'info'     => 'pagename,external,mtime',
50                    ));
51     }
52
53     function setExternalPages(&$dbi, &$request, $pages) {
54         $result = HTML::div();
55         $ul = HTML::ul();
56         $count = 0;
57         foreach ($pages as $name) {
58             $page = $dbi->getPage($name);
59             $current = $page->getCurrentRevision();
60             $external = $current->get('external');
61             if (!$external) $external = 0;
62             $external = (bool)$external;
63             if (!$external) {
64                 if (!mayAccessPage('change', $name)) {
65                     $result->setAttr('class', 'error');
66                     $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.",
67                                                   WikiLink($name))));
68                 } else {
69                     $version = $current->getVersion();
70                     $page->set('external', (bool)1);
71                     $ul->pushContent(HTML::li(fmt("change page '%s' to external.", WikiLink($name))));
72                     $count++;
73                 }
74             }
75         }
76         if ($count) {
77             $dbi->touch();
78             $result->setAttr('class', 'feedback');
79             if ($count == 1) {
80                 $result->pushContent(HTML::p("One page has been permanently changed:"));
81             } else {
82                 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
83             }
84             $result->pushContent($ul);
85             return $result;
86         } else {
87             $result->setAttr('class', 'error');
88             $result->pushContent(HTML::p("No pages changed."));
89             return $result;
90         }
91     }
92
93     function run($dbi, $argstr, &$request, $basepage) {
94         if ($request->getArg('action') != 'browse')
95             if (!$request->getArg('action') == _("PhpWikiAdministration/SetExternal"))
96                 return $this->disabled("(action != 'browse')");
97
98         $args = $this->getArgs($argstr, $request);
99         $this->_args = $args;
100         $this->preSelectS($args, $request);
101
102         $p = $request->getArg('p');
103         if (!$p) $p = $this->_list;
104         $post_args = $request->getArg('admin_external');
105         if (!$request->isPost() and empty($post_args['external']))
106             $post_args['external'] = $args['external'];
107         $pages = array();
108         if ($p && !$request->isPost())
109             $pages = $p;
110         if ($p && $request->isPost() &&
111             !empty($post_args['button']) && empty($post_args['cancel'])) {
112             // without individual PagePermissions:
113             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
114                 $request->_notAuthorized(WIKIAUTH_ADMIN);
115                 $this->disabled("! user->isAdmin");
116             }
117             // Real action
118             return $this->setExternalPages($dbi, $request, array_keys($p));
119         }
120         $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
121         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
122         $pagelist->addPageList($pages);
123
124         $header = HTML::fieldset();
125         $button_label = _("Set pages to external");
126         $header->pushContent(HTML::legend(_("Select the pages to set as external")));
127
128         $buttons = HTML::p(Button('submit:admin_external[button]', $button_label, 'wikiadmin'),
129                            Button('submit:admin_external[cancel]', _("Cancel"), 'button'));
130         $header->pushContent($buttons);
131
132         return HTML::form(array('action' => $request->getPostURL(),
133                                 'method' => 'post'),
134                           $header,
135                           $pagelist->getContent(),
136                           HiddenInputs($request->getArgs(),
137                                         false,
138                                         array('admin_external')),
139                           ENABLE_PAGEPERM
140                           ? ''
141                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
142     }
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:
153 ?>