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) {
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 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
74 $version = $current->getVersion();
75 $meta = $current->_data;
76 $meta['markup'] = $newmarkup;
78 $text = $current->getPackedContent();
79 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
80 $meta['is_minor_edit'] = 0;
81 $meta['author'] = $request->_user->UserName();
82 unset($meta['mtime']); // force new date
83 $page->save($text, $version + 1, $meta);
84 $current = $page->getCurrentRevision();
85 if ($current->get('markup') === $newmarkup) {
86 $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.",
87 WikiLink($name), $newmarkup)));
90 $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.",
91 WikiLink($name), $newmarkup)));
98 return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
101 return HTML($ul, HTML::p(fmt("No pages changed.")));
105 function run($dbi, $argstr, &$request, $basepage) {
106 if ($request->getArg('action') != 'browse')
107 if (!$request->getArg('action') == _("PhpWikiAdministration/Markup"))
108 return $this->disabled("(action != 'browse')");
110 $args = $this->getArgs($argstr, $request);
111 $this->_args = $args;
112 $this->preSelectS($args, $request);
114 $p = $request->getArg('p');
115 if (!$p) $p = $this->_list;
116 $post_args = $request->getArg('admin_markup');
117 if (!$request->isPost() and empty($post_args['markup']))
118 $post_args['markup'] = $args['markup'];
119 $next_action = 'select';
121 if ($p && !$request->isPost())
123 if ($p && $request->isPost() &&
124 !empty($post_args['button']) && empty($post_args['cancel'])) {
125 // without individual PagePermissions:
126 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
127 $request->_notAuthorized(WIKIAUTH_ADMIN);
128 $this->disabled("! user->isAdmin");
130 // DONE: error message if not allowed.
131 if ($post_args['action'] == 'verify') {
133 return $this->chmarkupPages($dbi, $request, array_keys($p),
134 $post_args['markup']);
136 if ($post_args['action'] == 'select') {
137 if (!empty($post_args['markup']))
138 $next_action = 'verify';
139 foreach ($p as $name => $c) {
144 if ($next_action == 'select' and empty($pages)) {
145 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
148 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
149 $pagelist->addPageList($pages);
151 $header = HTML::div();
152 if ($next_action == 'verify') {
153 $button_label = _("Yes");
154 $header->pushContent(
155 HTML::p(HTML::strong(
156 _("Are you sure you want to permanently change the markup type of the selected files?"))));
157 $header = $this->chmarkupForm($header, $post_args);
160 $button_label = _("Change markup type");
161 $header->pushContent(HTML::p(_("Select the pages to change the markup type:")));
162 $header = $this->chmarkupForm($header, $post_args);
165 $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
166 Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
168 return HTML::form(array('action' => $request->getPostURL(),
172 $pagelist->getContent(),
173 HiddenInputs($request->getArgs(),
175 array('admin_markup')),
176 HiddenInputs(array('admin_markup[action]' => $next_action)),
179 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
182 function chmarkupForm(&$header, $post_args) {
183 $header->pushContent(_("Change markup")." ");
184 $header->pushContent(' '._("to").': ');
185 $header->pushContent(HTML::input(array('name' => 'admin_markup[markup]',
186 'value' => $post_args['markup'])));
187 $header->pushContent(HTML::p());
196 // c-hanging-comment-ender-p: nil
197 // indent-tabs-mode: nil