]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminMarkup.php
Set author and modification time
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminMarkup.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  Copyright 2005 $ThePhpWikiProgrammingTeam
5  Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
6
7  This file is part of PhpWiki.
8
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.
13
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.
18
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
22  */
23
24 /**
25  * Usage:   <?plugin WikiAdminMarkup s||=* ?> or called via WikiAdminSelect
26  * @author:  Reini Urban <rurban@x-ray.at>
27  *
28  * KNOWN ISSUES:
29  * Requires PHP 4.2 so far.
30  */
31 require_once('lib/PageList.php');
32 require_once('lib/plugin/WikiAdminSelect.php');
33
34 class WikiPlugin_WikiAdminMarkup
35 extends WikiPlugin_WikiAdminSelect
36 {
37     function getName() {
38         return _("WikiAdminMarkup");
39     }
40
41     function getDescription() {
42         return _("Change the markup type of selected pages.");
43     }
44
45     function getVersion() {
46         return preg_replace("/[Revision: $]/", '',
47                             "\$Revision$");
48     }
49
50     function getDefaultArguments() {
51         return array_merge 
52             (
53              PageList::supportedArgs(),
54              array(
55                    's'          => false,
56                    'markup'     => 2,
57                    /* Columns to include in listing */
58                    'info'     => 'pagename,markup,mtime',
59                    ));
60     }
61
62     function chmarkupPages(&$dbi, &$request, $pages, $newmarkup) {
63         $ul = HTML::ul();
64         $count = 0;
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'.",
72                                                   WikiLink($name))));
73                 } else {
74                     $version = $current->getVersion();
75                     $meta = $current->_data;
76                     $meta['markup'] = $newmarkup;
77                     // convert text?
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)));
88                         $count++;
89                     } else {
90                         $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.", 
91                                                       WikiLink($name), $newmarkup)));
92                     }
93                 }
94             }
95         }
96         if ($count) {
97             $dbi->touch();
98             return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
99                                          $count)));
100         } else {
101             return HTML($ul, HTML::p(fmt("No pages changed.")));
102         }
103     }
104     
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')");
109         
110         $args = $this->getArgs($argstr, $request);
111         $this->_args = $args;
112         $this->preSelectS($args, $request);
113
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';
120         $pages = array();
121         if ($p && !$request->isPost())
122             $pages = $p;
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");
129             }
130             // DONE: error message if not allowed.
131             if ($post_args['action'] == 'verify') {
132                 // Real action
133                 return $this->chmarkupPages($dbi, $request, array_keys($p), 
134                                             $post_args['markup']);
135             }
136             if ($post_args['action'] == 'select') {
137                 if (!empty($post_args['markup']))
138                     $next_action = 'verify';
139                 foreach ($p as $name => $c) {
140                     $pages[$name] = 1;
141                 }
142             }
143         }
144         if ($next_action == 'select' and empty($pages)) {
145             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], 
146                                          $args['exclude']);
147         }
148         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
149         $pagelist->addPageList($pages);
150
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);
158         }
159         else {
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);
163         }
164
165         $buttons = HTML::p(Button('submit:admin_markup[button]', $button_label, 'wikiadmin'),
166                            Button('submit:admin_markup[cancel]', _("Cancel"), 'button'));
167
168         return HTML::form(array('action' => $request->getPostURL(),
169                                 'method' => 'post'),
170                           $header,
171                           $buttons,
172                           $pagelist->getContent(),
173                           HiddenInputs($request->getArgs(),
174                                         false,
175                                         array('admin_markup')),
176                           HiddenInputs(array('admin_markup[action]' => $next_action)),
177                           ENABLE_PAGEPERM
178                           ? ''
179                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
180     }
181
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());
188         return $header;
189     }
190 }
191
192 // Local Variables:
193 // mode: php
194 // tab-width: 8
195 // c-basic-offset: 4
196 // c-hanging-comment-ender-p: nil
197 // indent-tabs-mode: nil
198 // End:
199 ?>