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: <?plugin WikiAdminMarkup s||=* ?> or called via WikiAdminSelect
26 * @author: Reini Urban <rurban@x-ray.at>
29 * Requires PHP 4.2 so far.
31 require_once('lib/PageList.php');
32 require_once('lib/plugin/WikiAdminSelect.php');
34 class WikiPlugin_WikiAdminMarkup
35 extends WikiPlugin_WikiAdminSelect
38 return _("WikiAdminMarkup");
41 function getDescription() {
42 return _("Change the markup type of selected pages.");
45 function getDefaultArguments() {
48 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
51 /* Columns to include in listing */
52 'info' => 'pagename,markup,mtime',
56 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup) {
57 $result = HTML::div();
60 foreach ($pages as $name) {
61 $page = $dbi->getPage($name);
62 $current = $page->getCurrentRevision();
63 $markup = $current->get('markup');
64 if ( !$markup or $newmarkup != $markup ) {
65 if (!mayAccessPage('change', $name)) {
66 $result->setAttr('class', 'error');
67 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.",
70 $version = $current->getVersion();
71 $meta = $current->_data;
72 $meta['markup'] = $newmarkup;
74 $text = $current->getPackedContent();
75 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
76 $meta['is_minor_edit'] = 1;
77 $meta['author'] = $request->_user->UserName();
78 unset($meta['mtime']); // force new date
79 $page->save($text, $version + 1, $meta);
80 $current = $page->getCurrentRevision();
81 if ($current->get('markup') === $newmarkup) {
82 $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.",
83 WikiLink($name), $newmarkup)));
86 $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.",
87 WikiLink($name), $newmarkup)));
94 $result->setAttr('class', 'feedback');
96 $result->pushContent(HTML::p("One page has been permanently changed:"));
98 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
100 $result->pushContent($ul);
103 $result->setAttr('class', 'error');
104 $result->pushContent(HTML::p("No pages changed."));
109 function run($dbi, $argstr, &$request, $basepage) {
110 if ($request->getArg('action') != 'browse')
111 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup"))
112 return $this->disabled("(action != 'browse')");
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'])) {
129 // without individual PagePermissions:
130 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
131 $request->_notAuthorized(WIKIAUTH_ADMIN);
132 $this->disabled("! user->isAdmin");
134 // DONE: error message if not allowed.
135 if ($post_args['action'] == 'verify') {
137 return $this->chmarkupPages($dbi, $request, array_keys($p),
138 $post_args['markup']);
140 if ($post_args['action'] == 'select') {
141 if (!empty($post_args['markup']))
142 $next_action = 'verify';
143 foreach ($p as $name => $c) {
148 if ($next_action == 'select' and empty($pages)) {
149 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
153 if ($next_action == 'select') {
154 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
156 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
158 $pagelist->addPageList($pages);
160 $header = HTML::fieldset();
161 if ($next_action == 'verify') {
162 $button_label = _("Yes");
163 $header->pushContent(
164 HTML::p(HTML::strong(
165 _("Are you sure you want to permanently change the markup type of the selected files?"))));
166 $header = $this->chmarkupForm($header, $post_args);
169 $button_label = _("Change markup type");
170 $header->pushContent(HTML::legend(_("Select the pages to change the markup type")));
171 $header = $this->chmarkupForm($header, $post_args);
174 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
175 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
176 $header->pushContent($buttons);
178 return HTML::form(array('action' => $request->getPostURL(),
181 $pagelist->getContent(),
182 HiddenInputs($request->getArgs(),
184 array('admin_markup')),
185 HiddenInputs(array('admin_markup[action]' => $next_action)),
188 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
191 function chmarkupForm(&$header, $post_args) {
192 $header->pushContent(_("Change markup")." ");
193 $header->pushContent(' '._("to").': ');
194 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
195 'value' => $post_args['markup'])));
204 // c-hanging-comment-ender-p: nil
205 // indent-tabs-mode: nil