]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminMarkup.php
Remove LC_MESSAGES/phpwiki.php
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminMarkup.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:   <<WikiAdminMarkup s||=* >> or called via WikiAdminSelect
26  * @author:  Reini Urban <rurban@x-ray.at>
27  *
28  */
29 require_once 'lib/PageList.php';
30 require_once 'lib/plugin/WikiAdminSelect.php';
31
32 class WikiPlugin_WikiAdminMarkup
33     extends WikiPlugin_WikiAdminSelect
34 {
35     function getDescription()
36     {
37         return _("Change the markup type of selected pages.");
38     }
39
40     function getDefaultArguments()
41     {
42         return array_merge
43         (
44             WikiPlugin_WikiAdminSelect::getDefaultArguments(),
45             array(
46                 'markup' => 2,
47                 /* Columns to include in listing */
48                 'info' => 'pagename,markup,mtime',
49             ));
50     }
51
52     function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
53     {
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             $markup = $current->get('markup');
61             if (!$markup or $newmarkup != $markup) {
62                 if (!mayAccessPage('change', $name)) {
63                     $result->setAttr('class', 'error');
64                     $result->pushContent(HTML::p(fmt("Access denied to change page “%s”.",
65                         WikiLink($name))));
66                 } else {
67                     $version = $current->getVersion();
68                     $meta = $current->_data;
69                     $meta['markup'] = $newmarkup;
70                     // convert text?
71                     $text = $current->getPackedContent();
72                     $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
73                     $meta['is_minor_edit'] = 1;
74                     $meta['author'] = $request->_user->UserName();
75                     unset($meta['mtime']); // force new date
76                     $page->save($text, $version + 1, $meta);
77                     $current = $page->getCurrentRevision();
78                     if ($current->get('markup') === $newmarkup) {
79                         $ul->pushContent(HTML::li(fmt("change page “%s” to markup type “%s”.",
80                             WikiLink($name), $newmarkup)));
81                         $count++;
82                     } else {
83                         $ul->pushContent(HTML::li(fmt("Couldn't change page “%s” to markup type “%s”.",
84                             WikiLink($name), $newmarkup)));
85                     }
86                 }
87             }
88         }
89         if ($count) {
90             $dbi->touch();
91             $result->setAttr('class', 'feedback');
92             if ($count == 1) {
93                 $result->pushContent(HTML::p(_("One page has been changed:")));
94             } else {
95                 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
96             }
97             $result->pushContent($ul);
98             return $result;
99         } else {
100             $result->setAttr('class', 'error');
101             $result->pushContent(HTML::p(_("No pages changed.")));
102             return $result;
103         }
104     }
105
106     function run($dbi, $argstr, &$request, $basepage)
107     {
108         if ($request->getArg('action') != 'browse') {
109             if (!$request->getArg('action') == __("PhpWikiAdministration")."/".__("Markup")) {
110                 return $this->disabled(_("Plugin not run: not in browse mode"));
111             }
112         }
113
114         $args = $this->getArgs($argstr, $request);
115         $this->_args = $args;
116         $this->preSelectS($args, $request);
117
118         $p = $request->getArg('p');
119         if (!$p) $p = $this->_list;
120         $post_args = $request->getArg('admin_markup');
121         if (!$request->isPost() and empty($post_args['markup']))
122             $post_args['markup'] = $args['markup'];
123         $next_action = 'select';
124         $pages = array();
125         if ($p && !$request->isPost())
126             $pages = $p;
127         if ($p && $request->isPost() &&
128             !empty($post_args['button']) && empty($post_args['cancel'])
129         ) {
130             // without individual PagePermissions:
131             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
132                 $request->_notAuthorized(WIKIAUTH_ADMIN);
133                 $this->disabled("! user->isAdmin");
134             }
135             // DONE: error message if not allowed.
136             if ($post_args['action'] == 'verify') {
137                 // Real action
138                 return $this->chmarkupPages($dbi, $request, array_keys($p),
139                     $post_args['markup']);
140             }
141             if ($post_args['action'] == 'select') {
142                 if (!empty($post_args['markup']))
143                     $next_action = 'verify';
144                 foreach ($p as $name => $c) {
145                     $pages[$name] = 1;
146                 }
147             }
148         }
149         if ($next_action == 'select' and empty($pages)) {
150             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
151                 $args['exclude']);
152         }
153
154         if ($next_action == 'select') {
155             $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
156         } else {
157             $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
158         }
159         $pagelist->addPageList($pages);
160
161         $header = HTML::fieldset();
162         if ($next_action == 'verify') {
163             $button_label = _("Yes");
164             $header->pushContent(HTML::legend(_("Confirm markup change")));
165             $header->pushContent(
166                 HTML::p(HTML::strong(
167                     _("Are you sure you want to change the markup type of the selected files?"))));
168             $header = $this->chmarkupForm($header, $post_args);
169         } else {
170             $button_label = _("Change markup type");
171             $header->pushContent(HTML::legend(_("Select the pages to change the markup type")));
172             $header = $this->chmarkupForm($header, $post_args);
173         }
174
175         $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
176             Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
177         $header->pushContent($buttons);
178
179         return HTML::form(array('action' => $request->getPostURL(),
180                 'method' => 'post'),
181             $header,
182             $pagelist->getContent(),
183             HiddenInputs($request->getArgs(),
184                 false,
185                 array('admin_markup')),
186             HiddenInputs(array('admin_markup[action]' => $next_action)),
187             ENABLE_PAGEPERM
188                 ? ''
189                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
190     }
191
192     function chmarkupForm(&$header, $post_args)
193     {
194         $header->pushContent(_("Change markup to: "));
195         $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
196             'value' => $post_args['markup'])));
197         return $header;
198     }
199 }
200
201 // Local Variables:
202 // mode: php
203 // tab-width: 8
204 // c-basic-offset: 4
205 // c-hanging-comment-ender-p: nil
206 // indent-tabs-mode: nil
207 // End: