4 Copyright 2005 $ThePhpWikiProgrammingTeam
6 This file is not yet part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Usage: <?plugin WikiAdminMarkup s||=* ?> or called via WikiAdminSelect
25 * @author: Reini Urban <rurban@x-ray.at>
28 * Requires PHP 4.2 so far.
30 require_once('lib/PageList.php');
31 require_once('lib/plugin/WikiAdminSelect.php');
33 class WikiPlugin_WikiAdminMarkup
34 extends WikiPlugin_WikiAdminSelect
37 return _("WikiAdminMarkup");
40 function getDescription() {
41 return _("Change the markup type of selected pages.");
44 function getVersion() {
45 return preg_replace("/[Revision: $]/", '',
49 function getDefaultArguments() {
52 PageList::supportedArgs(),
56 /* Columns to include in listing */
57 'info' => 'pagename,markup,mtime',
61 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup) {
64 foreach ($pages as $name) {
65 $page = $dbi->getPage($name);
66 $current = $page->getCurrentRevision();
67 $markup = $current->get('markup');
68 if ( !$markup or $newmarkup != $markup ) {
69 if (!mayAccessPage('change', $name)) {
70 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
73 $version = $current->getVersion();
74 $meta = $current->_data;
75 $meta['markup'] = $newmarkup;
77 $text = $current->getPackedContent();
78 $meta['summary'] = sprintf(_("WikiAdminMarkup from %s to %s"), $markup, $newmarkup);
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 return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
97 return HTML($ul, HTML::p(fmt("No pages changed.")));
101 function run($dbi, $argstr, &$request, $basepage) {
102 if ($request->getArg('action') != 'browse')
103 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup"))
104 return $this->disabled("(action != 'browse')");
106 $args = $this->getArgs($argstr, $request);
107 $this->_args = $args;
108 $this->preSelectS($args, $request);
110 $p = $request->getArg('p');
111 if (!$p) $p = $this->_list;
112 $post_args = $request->getArg('admin_markup');
113 if (!$request->isPost() and empty($post_args['markup']))
114 $post_args['markup'] = $args['markup'];
115 $next_action = 'select';
117 if ($p && !$request->isPost())
119 if ($p && $request->isPost() &&
120 !empty($post_args['button']) && empty($post_args['cancel'])) {
121 // without individual PagePermissions:
122 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
123 $request->_notAuthorized(WIKIAUTH_ADMIN);
124 $this->disabled("! user->isAdmin");
126 // DONE: error message if not allowed.
127 if ($post_args['action'] == 'verify') {
129 return $this->chmarkupPages($dbi, $request, array_keys($p),
130 $post_args['markup']);
132 if ($post_args['action'] == 'select') {
133 if (!empty($post_args['markup']))
134 $next_action = 'verify';
135 foreach ($p as $name => $c) {
140 if ($next_action == 'select' and empty($pages)) {
141 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
144 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
145 $pagelist->addPageList($pages);
148 if ($next_action == 'verify') {
149 $button_label = _("Yes");
150 $header->pushContent(
151 HTML::p(HTML::strong(
152 _("Are you sure you want to permanently change the markup type of the selected files?"))));
153 $header = $this->chmarkupForm($header, $post_args);
156 $button_label = _("Change markup type");
157 $header->pushContent(HTML::p(_("Select the pages to change the markup type:")));
158 $header = $this->chmarkupForm($header, $post_args);
161 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
162 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
164 return HTML::form(array('action' => $request->getPostURL(),
167 $pagelist->getContent(),
168 HiddenInputs($request->getArgs(),
170 array('admin_markup')),
171 HiddenInputs(array('admin_markup[action]' => $next_action)),
174 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
178 function chmarkupForm(&$header, $post_args) {
179 $header->pushContent(_("Change markup")." ");
180 $header->pushContent(' '._("to").': ');
181 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
182 'value' => $post_args['markup'])));
183 $header->pushContent(HTML::p());
188 // $Log: not supported by cvs2svn $
195 // c-hanging-comment-ender-p: nil
196 // indent-tabs-mode: nil