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
37 return _("WikiAdminMarkup");
40 function getDescription()
42 return _("Change the markup type of selected pages.");
45 function getDefaultArguments()
49 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
52 /* Columns to include in listing */
53 'info' => 'pagename,markup,mtime',
57 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
59 $result = HTML::div();
62 foreach ($pages as $name) {
63 $page = $dbi->getPage($name);
64 $current = $page->getCurrentRevision();
65 $markup = $current->get('markup');
66 if (!$markup or $newmarkup != $markup) {
67 if (!mayAccessPage('change', $name)) {
68 $result->setAttr('class', 'error');
69 $result->pushContent(HTML::p(fmt("Access denied to change page “%s”.",
72 $version = $current->getVersion();
73 $meta = $current->_data;
74 $meta['markup'] = $newmarkup;
76 $text = $current->getPackedContent();
77 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
78 $meta['is_minor_edit'] = 1;
79 $meta['author'] = $request->_user->UserName();
80 unset($meta['mtime']); // force new date
81 $page->save($text, $version + 1, $meta);
82 $current = $page->getCurrentRevision();
83 if ($current->get('markup') === $newmarkup) {
84 $ul->pushContent(HTML::li(fmt("change page “%s” to markup type “%s”.",
85 WikiLink($name), $newmarkup)));
88 $ul->pushContent(HTML::li(fmt("Couldn't change page “%s” to markup type “%s”.",
89 WikiLink($name), $newmarkup)));
96 $result->setAttr('class', 'feedback');
98 $result->pushContent(HTML::p(_("One page has been changed:")));
100 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
102 $result->pushContent($ul);
105 $result->setAttr('class', 'error');
106 $result->pushContent(HTML::p(_("No pages changed.")));
111 function run($dbi, $argstr, &$request, $basepage)
113 if ($request->getArg('action') != 'browse') {
114 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup")) {
115 return $this->disabled(_("Plugin not run: not in browse mode"));
119 $args = $this->getArgs($argstr, $request);
120 $this->_args = $args;
121 $this->preSelectS($args, $request);
123 $p = $request->getArg('p');
124 if (!$p) $p = $this->_list;
125 $post_args = $request->getArg('admin_markup');
126 if (!$request->isPost() and empty($post_args['markup']))
127 $post_args['markup'] = $args['markup'];
128 $next_action = 'select';
130 if ($p && !$request->isPost())
132 if ($p && $request->isPost() &&
133 !empty($post_args['button']) && empty($post_args['cancel'])
135 // without individual PagePermissions:
136 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
137 $request->_notAuthorized(WIKIAUTH_ADMIN);
138 $this->disabled("! user->isAdmin");
140 // DONE: error message if not allowed.
141 if ($post_args['action'] == 'verify') {
143 return $this->chmarkupPages($dbi, $request, array_keys($p),
144 $post_args['markup']);
146 if ($post_args['action'] == 'select') {
147 if (!empty($post_args['markup']))
148 $next_action = 'verify';
149 foreach ($p as $name => $c) {
154 if ($next_action == 'select' and empty($pages)) {
155 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
159 if ($next_action == 'select') {
160 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
162 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
164 $pagelist->addPageList($pages);
166 $header = HTML::fieldset();
167 if ($next_action == 'verify') {
168 $button_label = _("Yes");
169 $header->pushContent(HTML::legend(_("Confirm markup change")));
170 $header->pushContent(
171 HTML::p(HTML::strong(
172 _("Are you sure you want to change the markup type of the selected files?"))));
173 $header = $this->chmarkupForm($header, $post_args);
175 $button_label = _("Change markup type");
176 $header->pushContent(HTML::legend(_("Select the pages to change the markup type")));
177 $header = $this->chmarkupForm($header, $post_args);
180 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
181 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
182 $header->pushContent($buttons);
184 return HTML::form(array('action' => $request->getPostURL(),
187 $pagelist->getContent(),
188 HiddenInputs($request->getArgs(),
190 array('admin_markup')),
191 HiddenInputs(array('admin_markup[action]' => $next_action)),
194 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
197 function chmarkupForm(&$header, $post_args)
199 $header->pushContent(_("Change markup to: "));
200 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
201 'value' => $post_args['markup'])));
210 // c-hanging-comment-ender-p: nil
211 // indent-tabs-mode: nil