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
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
36 return _("WikiAdminMarkup");
39 function getDescription() {
40 return _("Change the markup type of selected pages.");
43 function getDefaultArguments() {
46 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
49 /* Columns to include in listing */
50 'info' => 'pagename,markup,mtime',
54 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup) {
55 $result = HTML::div();
58 foreach ($pages as $name) {
59 $page = $dbi->getPage($name);
60 $current = $page->getCurrentRevision();
61 $markup = $current->get('markup');
62 if ( !$markup or $newmarkup != $markup ) {
63 if (!mayAccessPage('change', $name)) {
64 $result->setAttr('class', 'error');
65 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.",
68 $version = $current->getVersion();
69 $meta = $current->_data;
70 $meta['markup'] = $newmarkup;
72 $text = $current->getPackedContent();
73 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
74 $meta['is_minor_edit'] = 1;
75 $meta['author'] = $request->_user->UserName();
76 unset($meta['mtime']); // force new date
77 $page->save($text, $version + 1, $meta);
78 $current = $page->getCurrentRevision();
79 if ($current->get('markup') === $newmarkup) {
80 $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.",
81 WikiLink($name), $newmarkup)));
84 $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.",
85 WikiLink($name), $newmarkup)));
92 $result->setAttr('class', 'feedback');
94 $result->pushContent(HTML::p("One page has been permanently changed:"));
96 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
98 $result->pushContent($ul);
101 $result->setAttr('class', 'error');
102 $result->pushContent(HTML::p("No pages changed."));
107 function run($dbi, $argstr, &$request, $basepage) {
108 if ($request->getArg('action') != 'browse')
109 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup"))
110 return $this->disabled("(action != 'browse')");
112 $args = $this->getArgs($argstr, $request);
113 $this->_args = $args;
114 $this->preSelectS($args, $request);
116 $p = $request->getArg('p');
117 if (!$p) $p = $this->_list;
118 $post_args = $request->getArg('admin_markup');
119 if (!$request->isPost() and empty($post_args['markup']))
120 $post_args['markup'] = $args['markup'];
121 $next_action = 'select';
123 if ($p && !$request->isPost())
125 if ($p && $request->isPost() &&
126 !empty($post_args['button']) && empty($post_args['cancel'])) {
127 // without individual PagePermissions:
128 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
129 $request->_notAuthorized(WIKIAUTH_ADMIN);
130 $this->disabled("! user->isAdmin");
132 // DONE: error message if not allowed.
133 if ($post_args['action'] == 'verify') {
135 return $this->chmarkupPages($dbi, $request, array_keys($p),
136 $post_args['markup']);
138 if ($post_args['action'] == 'select') {
139 if (!empty($post_args['markup']))
140 $next_action = 'verify';
141 foreach ($p as $name => $c) {
146 if ($next_action == 'select' and empty($pages)) {
147 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
151 if ($next_action == 'select') {
152 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
154 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
156 $pagelist->addPageList($pages);
158 $header = HTML::fieldset();
159 if ($next_action == 'verify') {
160 $button_label = _("Yes");
161 $header->pushContent(
162 HTML::p(HTML::strong(
163 _("Are you sure you want to permanently change the markup type of the selected files?"))));
164 $header = $this->chmarkupForm($header, $post_args);
167 $button_label = _("Change markup type");
168 $header->pushContent(HTML::legend(_("Select the pages to change the markup type")));
169 $header = $this->chmarkupForm($header, $post_args);
172 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
173 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
174 $header->pushContent($buttons);
176 return HTML::form(array('action' => $request->getPostURL(),
179 $pagelist->getContent(),
180 HiddenInputs($request->getArgs(),
182 array('admin_markup')),
183 HiddenInputs(array('admin_markup[action]' => $next_action)),
186 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
189 function chmarkupForm(&$header, $post_args) {
190 $header->pushContent(_("Change markup")." ");
191 $header->pushContent(' '._("to").': ');
192 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
193 'value' => $post_args['markup'])));
202 // c-hanging-comment-ender-p: nil
203 // indent-tabs-mode: nil