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 PageList::supportedArgs(),
57 /* Columns to include in listing */
58 'info' => 'pagename,markup,mtime',
62 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup) {
63 $result = HTML::div();
66 foreach ($pages as $name) {
67 $page = $dbi->getPage($name);
68 $current = $page->getCurrentRevision();
69 $markup = $current->get('markup');
70 if ( !$markup or $newmarkup != $markup ) {
71 if (!mayAccessPage('change', $name)) {
72 $result->setAttr('class', 'error');
73 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.",
76 $version = $current->getVersion();
77 $meta = $current->_data;
78 $meta['markup'] = $newmarkup;
80 $text = $current->getPackedContent();
81 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
82 $meta['is_minor_edit'] = 0;
83 $meta['author'] = $request->_user->UserName();
84 unset($meta['mtime']); // force new date
85 $page->save($text, $version + 1, $meta);
86 $current = $page->getCurrentRevision();
87 if ($current->get('markup') === $newmarkup) {
88 $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.",
89 WikiLink($name), $newmarkup)));
92 $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.",
93 WikiLink($name), $newmarkup)));
100 $result->setAttr('class', 'feedback');
101 $result->pushContent(HTML::p(fmt("%s pages have been permanently 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) {
112 if ($request->getArg('action') != 'browse')
113 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup"))
114 return $this->disabled("(action != 'browse')");
116 $args = $this->getArgs($argstr, $request);
117 $this->_args = $args;
118 $this->preSelectS($args, $request);
120 $p = $request->getArg('p');
121 if (!$p) $p = $this->_list;
122 $post_args = $request->getArg('admin_markup');
123 if (!$request->isPost() and empty($post_args['markup']))
124 $post_args['markup'] = $args['markup'];
125 $next_action = 'select';
127 if ($p && !$request->isPost())
129 if ($p && $request->isPost() &&
130 !empty($post_args['button']) && empty($post_args['cancel'])) {
131 // without individual PagePermissions:
132 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
133 $request->_notAuthorized(WIKIAUTH_ADMIN);
134 $this->disabled("! user->isAdmin");
136 // DONE: error message if not allowed.
137 if ($post_args['action'] == 'verify') {
139 return $this->chmarkupPages($dbi, $request, array_keys($p),
140 $post_args['markup']);
142 if ($post_args['action'] == 'select') {
143 if (!empty($post_args['markup']))
144 $next_action = 'verify';
145 foreach ($p as $name => $c) {
150 if ($next_action == 'select' and empty($pages)) {
151 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
154 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
155 $pagelist->addPageList($pages);
157 $header = HTML::fieldset();
158 if ($next_action == 'verify') {
159 $button_label = _("Yes");
160 $header->pushContent(
161 HTML::p(HTML::strong(
162 _("Are you sure you want to permanently change the markup type of the selected files?"))));
163 $header = $this->chmarkupForm($header, $post_args);
166 $button_label = _("Change markup type");
167 $header->pushContent(HTML::legend(_("Select the pages to change the markup type")));
168 $header = $this->chmarkupForm($header, $post_args);
171 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
172 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
173 $header->pushContent($buttons);
175 return HTML::form(array('action' => $request->getPostURL(),
178 $pagelist->getContent(),
179 HiddenInputs($request->getArgs(),
181 array('admin_markup')),
182 HiddenInputs(array('admin_markup[action]' => $next_action)),
185 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
188 function chmarkupForm(&$header, $post_args) {
189 $header->pushContent(_("Change markup")." ");
190 $header->pushContent(' '._("to").': ');
191 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
192 'value' => $post_args['markup'])));
201 // c-hanging-comment-ender-p: nil
202 // indent-tabs-mode: nil