4 * Copyright 1999,2000,2001,2002,2007 $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 * Rewritten for recursive array support by ReiniUrban.
42 require_once('lib/plugin/_BackendInfo.php');
44 class WikiPlugin_EditMetaData
45 extends WikiPlugin__BackendInfo
48 return _("EditMetaData");
51 function getDescription () {
52 return sprintf(_("Edit metadata for %s"), '[pagename]');
55 function getVersion() {
56 return preg_replace("/[Revision: $]/", '',
60 function getDefaultArguments() {
61 return array('page' => '[pagename]'
65 function run($dbi, $argstr, &$request, $basepage) {
66 $this->_args = $this->getArgs($argstr, $request);
67 extract($this->_args);
71 $this->hidden_pagemeta = array ('_cached_html');
72 $this->readonly_pagemeta = array ('hits', 'passwd');
73 $dbi = $request->getDbh();
74 $p = $dbi->getPage($page);
75 $pagemeta = $p->getMetaData();
76 $this->chunk_split = false;
78 // Look at arguments to see if submit was entered. If so,
79 // process this request before displaying.
81 if ($request->isPost()
82 and $request->_user->isAdmin()
83 and $request->getArg('metaedit'))
85 $metafield = trim($request->getArg('metafield'));
86 $metavalue = trim($request->getArg('metavalue'));
87 $meta = $request->getArg('meta');
89 // meta[__global[_upgrade][name]] => 1030.13
90 foreach ($meta as $key => $val) {
91 if ($val != $pagemeta[$key]
92 and !in_array($key, $this->readonly_pagemeta))
98 if ($metafield and !in_array($metafield, $this->readonly_pagemeta)) {
99 // __global[_upgrade][name] => 1030.13
100 if (preg_match('/^(.*?)\[(.*?)\]$/', $metafield, $matches)) {
101 list(, $array_field, $array_key) = $matches;
102 $array_value = $pagemeta[$array_field];
103 $array_value[$array_key] = $metavalue;
104 if ($pagemeta[$array_field] != $array_value) {
106 $p->set($array_field, $array_value);
108 } elseif ($pagemeta[$metafield] != $metavalue) {
110 $p->set($metafield, $metavalue);
115 $url = $request->getURLtoSelf(false,
116 array('meta','metaedit','metafield','metavalue'));
117 $request->redirect($url);
118 // The rest of the output will not be seen due to the
124 // Now we show the meta data and provide entry box for new data.
126 //$html->pushContent(HTML::h3(fmt("Existing page-level metadata for %s:",
128 //$dl = $this->_display_values('', $pagemeta);
129 //$html->pushContent($dl);
131 // FIXME: invalid HTML
132 $html->pushContent(HTML::p(fmt("No metadata for %s", $page)));
136 $table = HTML::table(array('border' => 1,
138 'cellspacing' => 0));
139 $this->_fixupData($pagemeta);
140 $table->pushContent($this->_showhash("MetaData('$page')", $pagemeta));
143 if ($request->_user->isAdmin()) {
144 $action = $request->getPostURL();
145 $hiddenfield = HiddenInputs($request->getArgs());
146 $instructions = _("Add or change a page-level metadata 'key=>value' pair. Note that you can remove a key by leaving the value-box empty.");
147 $keyfield = HTML::input(array('name' => 'metafield'), '');
148 $valfield = HTML::input(array('name' => 'metavalue'), '');
149 $button = Button('submit:metaedit', _("Submit"), false);
150 $form = HTML::form(array('action' => $action,
152 'accept-charset' => $GLOBALS['charset']),
154 // edit existing fields
157 $instructions, HTML::br(),
158 $keyfield, ' => ', $valfield,
159 HTML::raw(' '), $button
162 $html->pushContent($form);
164 $html->pushContent(HTML::em(_("Requires WikiAdmin privileges to edit.")));
169 function _showvalue ($key, $val, $prefix='') {
170 if (is_array($val) or is_object($val)) return $val;
171 if (in_array($key, $this->hidden_pagemeta)) return '';
173 $fullkey = $prefix . '[' . $key . ']';
174 if (substr($fullkey,0,1) == '[') {
175 $meta = "meta".$fullkey;
176 $fullkey = preg_replace("/\]\[/", "[", substr($fullkey, 1), 1);
178 $meta = preg_replace("/^([^\[]+)\[/", "meta[$1][", $fullkey, 1);
182 $meta = "meta[".$key."]";
184 //$meta = "meta[".$fullkey."]";
185 $arr = array('name' => $meta, 'value' => $val);
186 if (strlen($val) > 20)
187 $arr['size'] = strlen($val);
188 if (in_array($key, $this->readonly_pagemeta)) {
189 $arr['readonly'] = 'readonly';
190 return HTML::input($arr);
192 return HTML(HTML::em($fullkey), HTML::br(),
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil