4 * Copyright 2005 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
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.
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.
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.
25 * Usage: <<WikiAdminMarkup s||=* >> or called via WikiAdminSelect
26 * @author: Reini Urban <rurban@x-ray.at>
29 require_once 'lib/PageList.php';
30 require_once 'lib/plugin/WikiAdminSelect.php';
32 class WikiPlugin_WikiAdminMarkup
33 extends WikiPlugin_WikiAdminSelect
35 function getDescription()
37 return _("Change the markup type of selected pages.");
40 function getDefaultArguments()
44 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
47 /* Columns to include in listing */
48 'info' => 'pagename,markup,mtime',
52 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
54 $result = HTML::div();
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”.",
67 $version = $current->getVersion();
68 $meta = $current->_data;
69 $meta['markup'] = $newmarkup;
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)));
83 $ul->pushContent(HTML::li(fmt("Couldn't change page “%s” to markup type “%s”.",
84 WikiLink($name), $newmarkup)));
91 $result->setAttr('class', 'feedback');
93 $result->pushContent(HTML::p(_("One page has been changed:")));
95 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
97 $result->pushContent($ul);
100 $result->setAttr('class', 'error');
101 $result->pushContent(HTML::p(_("No pages changed.")));
106 function run($dbi, $argstr, &$request, $basepage)
108 if ($request->getArg('action') != 'browse') {
109 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup")) {
110 return $this->disabled(_("Plugin not run: not in browse mode"));
114 $args = $this->getArgs($argstr, $request);
115 $this->_args = $args;
116 $this->preSelectS($args, $request);
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';
125 if ($p && !$request->isPost())
127 if ($p && $request->isPost() &&
128 !empty($post_args['button']) && empty($post_args['cancel'])
130 // without individual PagePermissions:
131 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
132 $request->_notAuthorized(WIKIAUTH_ADMIN);
133 $this->disabled("! user->isAdmin");
135 // DONE: error message if not allowed.
136 if ($post_args['action'] == 'verify') {
138 return $this->chmarkupPages($dbi, $request, array_keys($p),
139 $post_args['markup']);
141 if ($post_args['action'] == 'select') {
142 if (!empty($post_args['markup']))
143 $next_action = 'verify';
144 foreach ($p as $name => $c) {
149 if ($next_action == 'select' and empty($pages)) {
150 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
154 if ($next_action == 'select') {
155 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
157 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
159 $pagelist->addPageList($pages);
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);
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);
175 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
176 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
177 $header->pushContent($buttons);
179 return HTML::form(array('action' => $request->getPostURL(),
182 $pagelist->getContent(),
183 HiddenInputs($request->getArgs(),
185 array('admin_markup')),
186 HiddenInputs(array('admin_markup[action]' => $next_action)),
189 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
192 function chmarkupForm(&$header, $post_args)
194 $header->pushContent(_("Change markup to: "));
195 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
196 'value' => $post_args['markup'])));
205 // c-hanging-comment-ender-p: nil
206 // indent-tabs-mode: nil