[Pmwiki-users] Re: Request for method to let plugins execute code after stdconfig.php

John Rankin john.rankin
Fri Jul 16 20:53:27 CDT 2004


On Saturday, 17 July 2004 8:45 AM, chr at home.se wrote:
>...
>Let me ask for a specific hook: We (I and John) would like to add a button
>to the edit page, how could we do this?  The button should probably be 
>next to the 'save','preview' and 'reset' buttons. It'd be labelled 
>something like "Delete draft" and it's purpose is hopefully
>self-evident.
>
>/Christian
>
>PS. I hope I'm not completely off about adding a button, I think that was
>the problem that caused me to initate this request.

<longReply>

There have been several problems, some of which have had obvious 
solutions once I thought about it.

1. I now have several places that use a custom FmtWikiLink function. 
It took me ages to realise that these could be independent using the 
following code:

    $FmtWikiLinkPreModuleXXX = $FmtWikiLink;
    $FmtWikiLink = 'FmtWikiLinkModuleXXX';
    ...
    function FmtWikiLinkModuleXXX( ... ) {
      global $FmtWikiLinkPreModuleXXX;

      ...

      return $FmtWikiLinkPreModuleXXX( ... );
    }

Otherwise either everything has to go into one local $FmtWikiLink 
function or the last one in wins.

2. We needed to change 'Editing $PageName' to 'Editing $PageName Draft' 
if we are editing the draft version of the page. But page drafts may be 
supported as a group-level customisation and another local customisation 
may change $PageEditFmt. So locally, what I do is include pgcust.php 
early in local/config.php and use

    $PageEditFmt = str_replace('[Editing $PageName]',
            '[Editing $PageName]'.$DraftTagFmt,$PageEditFmt);

There is nothing to stop some other local customisation from overwriting 
this. Since this is a wording change, that's probably OK; it just means 
you lose the reminder that you are editing a draft copy, not the original.

3. For reasons discussed elsewhere, 'Edit' always edits the draft copy. 
So how do you remove a draft and revert to the original? One option is 
to put another button next to the Reset button. It might say 
Edit Original Page; pressing it brings up the original version of the 
page and next time you press Preview it overwrites the existing draft.

Assuming the code behind the button is fairly trivial (which I think 
it is), what is the best way to add such a button from a local script, 
that has to co-exist with other scripts which may also wish to change 
the edit page format? Using the str_replace approach seems insufficiently 
robust. Redeclaring the entire $PageEditFmt variable seems unnecessary 
and selfish (the module is no longer a black box).

4. We have had to make changes to the page template. The smallest change 
I could think of was 2 extra variables:

- $DraftLinkFmt goes after the page title and contains whatever it needs 
to in any given context

- $DraftTagFmt goes after $[Edit Page] to let you know whether you are 
editing a draft or the original

I couldn't think of a way to implement this that didn't involve changing 
the template. If the page title and edit page links had both been system 
variables, then I could have written (for example):

    $PageTitleFmt .= $DraftlinkFmt;

What are the reasons for using physical code rather than logical building 
blocks in a template? It occurs to me that one could write large parts of 
the template using wiki markup and use the wiki engine to generate almost 
the entire thing. Indeed, the following probably already works:

<!--function:PrintText %newwin%[[ThisPage:?action=print Printable View]]-->

I wonder if it could be made simpler to use wiki markup in template pages. 
How about setting a design goal that the template can be written (almost) 
entirely in wiki markup? What would need to be added to wiki markup to 
achieve this? I'm not sure how this approch would affect i18n.

Thank you for your patience in reading to the end of this.

</longReply>

-- 
JR
--
John Rankin





More information about the pmwiki-users mailing list