2 rcs_id('$Id: EditMetaData.php,v 1.9 2004-02-17 12:11:36 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is 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
26 * This plugin shows the current page-level metadata and gives an
27 * entry box for adding a new field or changing an existing one. (A
28 * field can be deleted by specifying a blank value.) Certain fields,
29 * such as 'hits' cannot be changed.
31 * If there is a reason to do so, I will add support for revision-
32 * level metadata as well.
34 * Access by restricted to ADMIN_USER
36 * Written by MichaelVanDam, to test out some ideas about
37 * PagePermissions and PageTypes.
39 * Array support added by ReiniUrban.
41 class WikiPlugin_EditMetaData
45 return _("EditMetaData");
48 function getDescription () {
49 return sprintf(_("Edit metadata for %s"), '[pagename]');
52 function getVersion() {
53 return preg_replace("/[Revision: $]/", '',
59 // page - page whose metadata is editted
62 function getDefaultArguments() {
63 return array('page' => '[pagename]'
68 function run($dbi, $argstr, &$request, $basepage) {
69 $this->_args = $this->getArgs($argstr, $request);
70 extract($this->_args);
74 $hidden_pagemeta = array ('_cached_html');
75 $readonly_pagemeta = array ('hits');
76 $dbi = $request->getDbh();
77 $p = $dbi->getPage($page);
78 $pagemeta = $p->getMetaData();
80 // Look at arguments to see if submit was entered. If so,
81 // process this request before displaying.
84 if ($request->getArg('metaedit')) {
86 $metafield = trim($request->getArg('metafield'));
87 $metavalue = trim($request->getArg('metavalue'));
89 if (!in_array($metafield, $readonly_pagemeta)) {
90 if (preg_match('/^(.*?)\[(.*?)\]$/', $metafield, $matches)) {
91 list(,$array_field, $array_key) = $matches;
92 $array_value = $pagemeta[$array_field];
93 $array_value[$array_key] = $metavalue;
94 $p->set($array_field, $array_value);
96 $p->set($metafield, $metavalue);
100 $url = $request->getURLtoSelf('', array('metaedit', 'metafield',
102 $request->redirect($url);
104 // The rest of the output will not be seen due to the
109 // Now we show the meta data and provide entry box for new data.
113 $html->pushContent(fmt("Existing page-level metadata for %s:",
117 foreach ($pagemeta as $key => $val) {
118 if (is_string($val) and (substr($val,0,2) == 'a:')) {
119 $dl->pushContent(HTML::dt("\n$key => $val\n",
121 foreach (unserialize($val) as $akey => $aval) {
122 $dl1->pushContent(HTML::dt(HTML::strong("$key" . '['
127 $dl->pushContent($dl1);
128 } elseif (is_array($val)) {
129 $dl->pushContent(HTML::dt("\n$key:\n", $dl1 = HTML::dl()));
130 foreach ($val as $akey => $aval) {
131 $dl1->pushContent(HTML::dt(HTML::strong("$key" . '['
136 $dl->pushContent($dl1);
137 } elseif (in_array($key,$hidden_pagemeta)) {
139 } elseif (in_array($key,$readonly_pagemeta)) {
140 $dl->pushContent(HTML::dt(array('style' => 'background: #dddddd'),
143 $dl->pushContent(HTML::dt(HTML::strong("$key => $val\n")));
146 $html->pushContent($dl);
148 if ($request->_user->isAdmin()) {
149 $action = $request->getPostURL();
150 $hiddenfield = HiddenInputs($request->getArgs());
151 $instructions = _("Add or change a page-level metadata 'key=>value' pair. Note that you can remove a key by leaving value-box empty.");
152 $keyfield = HTML::input(array('name' => 'metafield'), '');
153 $valfield = HTML::input(array('name' => 'metavalue'), '');
154 $button = Button('submit:metaedit', _("Submit"), false);
155 $form = HTML::form(array('action' => $action,
157 'accept-charset' => CHARSET),
159 $instructions, HTML::br(),
160 $keyfield, ' => ', $valfield,
161 HTML::raw(' '), $button
164 $html->pushContent(HTML::br(), $form);
166 $html->pushContent(HTML::em(_("Requires WikiAdmin privileges to edit.")));
172 // $Log: not supported by cvs2svn $
173 // Revision 1.8 2003/11/27 17:05:41 carstenklapp
174 // Update: Omit page cache object ('_cached_html') from metadata display.
176 // Revision 1.7 2003/11/22 17:41:42 carstenklapp
177 // Minor internal change: Removed redundant call to gettext within
178 // fmt(). (locale make: EditMetaData.php:113: warning: keyword nested in
181 // Revision 1.6 2003/02/26 01:56:52 dairiki
182 // Tuning/fixing of POST action URLs and hidden inputs.
184 // Revision 1.5 2003/02/21 04:17:13 dairiki
185 // Delete now irrelevant comment.
187 // Revision 1.4 2003/01/18 21:41:01 carstenklapp
189 // Reformatting & tabs to spaces;
190 // Added copyleft, getVersion, getDescription, rcs_id.
198 // c-hanging-comment-ender-p: nil
199 // indent-tabs-mode: nil