[pmwiki-users] Getting an URL from a cookbook recipe

Dominique Faure dominique.faure at gmail.com
Wed Jan 25 10:39:50 CST 2006


2006/1/25, Patrick R. Michaud <pmichaud at pobox.com>:
> On Wed, Jan 25, 2006 at 04:52:40PM +0100, Dominique Faure wrote:
> > 2006/1/25, Patrick R. Michaud <pmichaud at pobox.com>:
> > > On Wed, Jan 25, 2006 at 04:17:42PM +0100, Dominique Faure wrote:
> > > > I often need to catch urls from cookbook recipe's markup extensions,
> > > > whatever form it could have (according to PmWiki syntax). For now, the
> > > > easiest way I found to do that was to "regexp" clean the MakeLink
> > > > function output:
> > > >
> > > > Markup('mymarkup', 'directives',
> > > >   "/\\(:mymarkup\\s+(.*)\\s*:\\)/e",
> > > >   "MyMarkupFunc(\$pagename, PSS('$1'))");
> > > >
> > > > function MyMarkupFunc($pagename, $target) {
> > > >   $link = preg_replace("/.*href='([^']+)'.*/", '\1',
> > > > MakeLink($pagename, $target, ''));
> > > >
> > > >   # ...
> > > > }
> > > >
> > > > This working solution has several drawbacks, as for example not
> > > > allowing to know if the given url needs approbation or not.
> > > >
> > > > Any better idea would be appreciated.
> > >
> > > I think I need a fuller description of what you're trying to
> > > accomplish -- perhaps a more concrete example.
> > >
> >
> > As a concrete example you may refer to the
> > http://www.pmwiki.org/wiki/Cookbook/PTViewer recipe which take a
> > file=... parameter. This param should allow all PmWiki standards to
> > refer to an image file. In fact, the problem arise everywhere you want
> > to address external resources.
>
> Oh!  You're wanting to use PmWiki markup to obtain urls rather than
> require the author to explicitly name the url.
>
> The MakeLink function already allows this via its $fmt parameter...
> just do:
>
>     $url = MakeLink($pagename, $target, '', '', '$LinkUrl');
>
> I'm including a fuller description of the MakeLink function below.
>
> Pm
>
>
>
> MakeLink
> --------
>
> The general form of MakeLink is
>
>     MakeLink($pagename, $target, $txt, $suffix, $fmt)
>
> where
>
>     $pagename is the source page
>     $target is where the link should go
>     $txt is the value to use for '$LinkText' in the output
>     $suffix is any suffix string to be added to $txt
>     $fmt is a format string to use
>
> If $txt is NULL or not specified, then it is automatically computed
> from $target.
>
> If $fmt is NULL or not specified, then MakeLink uses the default
> format as specified by the type of link.  For page links this
> means the $LinkPageExistsFmt and $LinkPageCreateFmt variables,
> for intermap-style links it comes from either the $IMapLinkFmt
> array or from $UrlLinkFmt.  Inside of the formatting strings,
> $LinkUrl is replaced by the resolved url for the link, $LinkText
> is replaced with the appropriate text, and $LinkAlt is replaced
> by any "title" (alternate text) information associated with the
> link.
>

As usual, you solved it efficiently, thanks.

Sorry to let you make my homework, but is there a mean to detect an
unapproved link (without having to test for the presence of
"action=approvesites") ?




More information about the pmwiki-users mailing list