[pmwiki-users] Q:ZAP setting attr

The Editor editor at fast.st
Tue Apr 3 05:37:38 CDT 2007


On 4/3/07, Jiri Hladůvka / OBUTEX <admin at obutex.com> wrote:
> Hi,
>
> I set attributes of Test.10 page and the file contains metadata like
> ...
> name=Test.10
> passwdattr=id:Jiri
> passwdedit=id:Jiri
> passwdread=id:Jiri
> passwdremovecomment=id:Jiri
> passwdupload=id:Jiri
> passwdzap=id:Jiri
> rev=2
> targets=
> text=testing page%0a%0a
> ...
>
> Can ZAP change/add such data using some markup?
> Can zap replace function replace these data ?
> If zap replace can do this how can I do it while the page doesn't exists
> yet ?
>
> Regards,
> Jiri


I just added a new ZAPX command that looks like this (just to show how
easy it is to build custom ZAPextensions.

function ZAPXattr($value, $field) {
	global $m;
	$v = explode("|", $value);
	$oldpage = ReadPage($v[0]);
	$newpage = $oldpage;
	$newpage[$v[1]] = $v[2];
	UpdatePage($v[0], $oldpage, $newpage);
	$m .= "Attributes have been updated. ";
	return $value;
	}

Because this is so useful, I will add it to ZAPextend momentarily.
But you can add to a config file now (like any other ZAPextension) and
it will work right just fine. Remember, config editing junkies never
have to enable ZAPextend.  Just copy the command you want to a config
file for the page with the form...

Basically you do

(:zap attr="Group.Name|passwdedit|id:Jiri":)

If page doesn't exist, it creates it. As with many ZAP functions, this
is quite powerful, because you can reset anything, including text or
ctime, or whatever.

As for titles however (your other post) I would recommend forgetting
about them!  You can set it with this command, but unless (:title
Text:) is in the page text PmWiki erases it again.  I've worked with
titles on various occasions and find them just a bit too buggy for my
taste.

Besides, because it's not a text var (no :), it can't be edited, etc.
I just create my own $:title text var and it works for my purposes.  I
said goodbye to the title directive a long time ago. (Personally, I
think Pm should drop it from PmWiki, now that we have these awesome
text vars). Are you sure you can't use a text variable?

Of course, you could rewrite the extension above to look like this:

function ZAPXattr($value, $field) {
	global $m, $ZAParray;
	$v = explode("|", $value);
	$oldpage = ReadPage($v[0]);
	$newpage = $oldpage;
	$newpage[$v[1]] = $v[2];
                if($v[1] == 'title') $newpage['text'] =
$newpage['text'] . "\n(:title $ZAParray[title]:)";
	UpdatePage($v[0], $oldpage, $newpage);
	$m .= "Attributes have been updated. ";
	return $value;
	}

And it works fine.  You can even change the title.  But every time you
do it just appends the title...  But of course you could do this:

function ZAPXattr($value, $field) {
	global $m, $ZAParray;
	$v = explode("|", $value);
	$oldpage = ReadPage($v[0]);
	$newpage = $oldpage;
	$newpage[$v[1]] = $v[2];
	if ($v[1] == 'title') {
		if (strpos($newpage[text], "(:title ")) $newpage['text'] =
preg_replace('/\\(\\:title (.*?)\\:\\)/s', "(:title
$ZAParray[title]:)", $newpage['text']);
		else $newpage['text'] = $newpage['text'] . "\n(:title $ZAParray[title]:)";
		}
	UpdatePage($v[0], $oldpage, $newpage);
	$m .= "Attributes have been updated. ";
	return $value;
	}

And you got something that takes care of that.  Hmmm.  Works pretty
good.  Guess I'll put this whole thing in ZAPextend.  So you can use
it to reset passwords (for pages or groups btw) and/or page titles.
Pretty cool.

BTW, I also added a {(attr Group.Page|attr)} which can be put in a
pagelist template to retrieve any page attributes you want.  So for a
list of all edit passwords, you might put this in your template

* {=$FullName} = {(attr {=$FullName}|passwdedit)}

For obvious security reasons, (passwords are not asterisked) this
markup only works when a user has admin privileges on the page with
the markup.

Note:  this markup is a very simple one--as it doesn't check
hierarchical settings (like Hg uses) nor does it return any default
passwords, or anything.  Just what's set for that one page.

Cheers,
Dan


More information about the pmwiki-users mailing list