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