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