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 getVersion() {
46 return preg_replace("/[Revision: $]/", '',
50 function getDefaultArguments() {
53 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
56 /* Columns to include in listing */
57 'info' => 'pagename,markup,mtime',
61 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup) {
62 $result = HTML::div();
65 foreach ($pages as $name) {
66 $page = $dbi->getPage($name);
67 $current = $page->getCurrentRevision();
68 $markup = $current->get('markup');
69 if ( !$markup or $newmarkup != $markup ) {
70 if (!mayAccessPage('change', $name)) {
71 $result->setAttr('class', 'error');
72 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.",
75 $version = $current->getVersion();
76 $meta = $current->_data;
77 $meta['markup'] = $newmarkup;
79 $text = $current->getPackedContent();
80 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
81 $meta['is_minor_edit'] = 1;
82 $meta['author'] = $request->_user->UserName();
83 unset($meta['mtime']); // force new date
84 $page->save($text, $version + 1, $meta);
85 $current = $page->getCurrentRevision();
86 if ($current->get('markup') === $newmarkup) {
87 $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.",
88 WikiLink($name), $newmarkup)));
91 $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.",
92 WikiLink($name), $newmarkup)));
99 $result->setAttr('class', 'feedback');
101 $result->pushContent(HTML::p("One page has been permanently changed:"));
103 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
105 $result->pushContent($ul);
108 $result->setAttr('class', 'error');
109 $result->pushContent(HTML::p("No pages changed."));
114 function run($dbi, $argstr, &$request, $basepage) {
115 if ($request->getArg('action') != 'browse')
116 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup"))
117 return $this->disabled("(action != 'browse')");
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'])) {
134 // without individual PagePermissions:
135 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
136 $request->_notAuthorized(WIKIAUTH_ADMIN);
137 $this->disabled("! user->isAdmin");
139 // DONE: error message if not allowed.
140 if ($post_args['action'] == 'verify') {
142 return $this->chmarkupPages($dbi, $request, array_keys($p),
143 $post_args['markup']);
145 if ($post_args['action'] == 'select') {
146 if (!empty($post_args['markup']))
147 $next_action = 'verify';
148 foreach ($p as $name => $c) {
153 if ($next_action == 'select' and empty($pages)) {
154 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
158 if ($next_action == 'select') {
159 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
161 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
163 $pagelist->addPageList($pages);
165 $header = HTML::fieldset();
166 if ($next_action == 'verify') {
167 $button_label = _("Yes");
168 $header->pushContent(
169 HTML::p(HTML::strong(
170 _("Are you sure you want to permanently change the markup type of the selected files?"))));
171 $header = $this->chmarkupForm($header, $post_args);
174 $button_label = _("Change markup type");
175 $header->pushContent(HTML::legend(_("Select the pages to change the markup type")));
176 $header = $this->chmarkupForm($header, $post_args);
179 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
180 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
181 $header->pushContent($buttons);
183 return HTML::form(array('action' => $request->getPostURL(),
186 $pagelist->getContent(),
187 HiddenInputs($request->getArgs(),
189 array('admin_markup')),
190 HiddenInputs(array('admin_markup[action]' => $next_action)),
193 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
196 function chmarkupForm(&$header, $post_args) {
197 $header->pushContent(_("Change markup")." ");
198 $header->pushContent(' '._("to").': ');
199 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
200 'value' => $post_args['markup'])));
209 // c-hanging-comment-ender-p: nil
210 // indent-tabs-mode: nil