[Pmwiki-users] Author shortcuts (was: Replace text on save?)
Thomas -Balu- Walter
list+pmwiki-users
Mon Mar 15 17:39:54 CST 2004
On Sun, Mar 14, 2004 at 08:11:29PM -0700, Patrick R. Michaud wrote:
> On Mon, Mar 15, 2004 at 03:36:15AM +0100, Thomas -Balu- Walter wrote:
> > is there a way to replace parts of the text when an author saves the
> > page?
>
> So far I've avoided adding a built-in "modify text on save" feature
> because I think it has the potential for all sorts of nastiness and
> abuse. I like it when the text that is saved is exactly what was
> specified.
I am not really sure what kind of abuse you are expecting here. If we
tell users that ~~~ will get replaced with their name or similar they
should expect it. What kind of nastiness are you thinking of e.g.?
[...]
> I have no idea what sorts of side effects, if any, something like
> this might generate, so YMMV. Let us know how/if it works.
One problem I've encountered was that if I simply replace the
placeholder on preview the author might change the author-field and this
would not respect the new value of the field, because it already got replaced...
So I had create two ways - one for preview and the other one for save.
I've added this to a local copy of scripts/author.php, because I thought it
might belong there... (original file got disabled).
// for previews use $DoubleBrackets
if ($preview && $Author!='') {
$DoubleBrackets['/^~~~/'] = "'''{{".$AuthorGroup."/".$Author."}}''':";
$DoubleBrackets['/~~~/'] = "'' -- {{".$AuthorGroup."/".$Author."}}''";
} else {
$DoubleBrackets['/^~~~\s/'] = ""; // also remove whitespace to avoid...
$DoubleBrackets['/~~~/'] = ""; // having space at beginning of a line
}
// on save replace the values
if (@$_POST['post'] && @$_POST['text']) {
if (isset($Author) && $Author!='') {
$_POST['text'] = preg_replace('/^~~~/m', "'''{{~$Author}}''':", $_POST['text']);
$_POST['text'] = str_replace('~~~', "''-- {{~$Author}}''", $_POST['text']);
} else {
$_POST['text'] = preg_replace('/^~~~\s/m', "", $_POST['text']);
$_POST['text'] = str_replace('~~~', "", $_POST['text']);
}
}
I have this setup active right now on http://www.b-a-l-u.de/, feel free to test
it in the WikiSandbox.
One thing left is that this replacement can not be disabled e.g. using
something like [=~~~=]. This will work on preview, but not on save.
Another one is that the preview uses {{Profiles/Author}} while the save
replacement does {{~Author}}, but I was not able to do the second in
$DoubleBrackets :)
-- Balu (2004-03-16)
PS: Why I am doing this? Because I know this feature from
http://wiki.beyondunreal.com/wiki/Wiki_Markup and it really makes it easier to
discuss or comment on things...
More information about the pmwiki-users
mailing list