[pmwiki-users] One more was Re: I want to use FmtPV from mackup to set Page Variable, but can't get it to work reliably

Christopher Cox ccox at endlessnow.com
Fri Jul 14 23:19:12 CDT 2017


Just some more detail.  What I have is an auth token.  It's retrieved via a web 
service.  Ideally, such things could go into some sort of session variable or 
cookie.  But the token is such that if you don't use it against the web service, 
it expires after 1 hour of non-use.  The token is unique per user and point of 
origination.

So, my implementation is a markup on the page, so that when a user hits the 
page, their credential (I already have this) is used to retrieve their 
token/ticket for the web service.  Depending on "who you are" operations on the 
page will succeed or fail based on your token, but the markup on the page is 
constant.

If you are not logged in (AuthUser with my credential saving technique), then 
the webservice prompts for login.  However if you are logged into the wiki, the 
token/ticket is generated and access can be determined in lieu of webservice login.

The following isn't the site, but screen grabs of the site which hopefully 
explain how it all works better.  I'm pretty ok with the implementation I've got 
right now.

https://endlessnow.com/wiki1/Test/Alfresco


On 07/14/2017 03:09 PM, Petko Yotov wrote:
> Oh, InterMap definitions are processed even before any markup rules, so your
> markup rule has not been able to set the PageVariable.
>
> Using a markup rule is not a great way to set a PageVariable. I'd use a $FmtPV
> function instead. See/check how other PageVariables are defined as functions in
> the core (pmwiki.php:123) eg $Groupspaced, $Title, $BaseName or $PasswdRead. See
> how the page group, name or another attribute is passed, and think how your
> variable will work for another page like {OtherGroup.OtherPage$mymarkupvar}. It
> is complex and resource intensive, but possible to RetrieveAuthPage the
> pagename, then to look for your markup in the $page['text'] entry.
>
> Or, piggyback on an existing PageVariable if it is never used, eg. (:keywords:)
> or (:description:), and have your markup to set this variable by a simple
> replacement:
>
>   # Convert (:mymarkup:) to (:keywords ccox:myvariable:).
>   # When a page is saved, "ccox:myvariable" will be in
>   # the 'keywords' property and in $page["keywords"]
>   Markup('mymarkupvar', '<keywords', '/\\(:mymarkup:\\)/', '(:keywords
> ccox:myvariable:)');
>
>   # a better way to set the PageVariable
>   $FmtPV['$mymarkupvar'] = 'CCGetVariable(@$page["keywords"])';
>
>   function CCGetVariable($keywords) {
>     if(preg_match('/ccox:myvariable/i', $keywords)) return 'hello';
>   }
>
> This will also populate the "meta keywords" tag in the HTML source of the page
> with "ccox:myvariable". If this is unacceptable, select a different way
> (see/copy how the keywords property is set in stdmarkup.php, and add an entry to
> $SaveProperties).
>
> Petko
>
> ---
> Change log     :  http://www.pmwiki.org/wiki/PmWiki/ChangeLog
> Release notes  :  http://www.pmwiki.org/wiki/PmWiki/ReleaseNotes
> If you upgrade :  http://www.pmwiki.org/wiki/PmWiki/Upgrades
>
>
> On 2017-07-14 20:45, Christopher Cox wrote:
>> Let's say I now want to use a InterMap on such a page with my page
>> variable populated via markup...
>>
>> such that I want to have
>>
>> myintermap:    http://example.com/$1?a={$mymarkupvar}
>>
>>
>> The variable doesn't populate in that one.  Is it possible?
>>
>>
>> On 07/14/2017 01:15 PM, Christopher Cox wrote:
>>> Bingo! Thanks Petko! '<{$var}'
>>>
>>>
>>> On 07/14/2017 12:59 PM, Petko Yotov wrote:
>>>> When the markup rules are processed one after another, PageVariables like
>>>> {$mymarkupvar} are replaced with their contents very early. Most other
>>>> markup rules are processed later, see pmwiki.php?action=ruleset. So your
>>>> page variable is not yet set when it is encountered in the page, and it is
>>>> replaced with nothing, empty string.
>>>>
>>>> MarkupMarkup, ie (:markup:) rules are processed before most other rules, and
>>>> before PageVariables. The content of a (:markup:) block is passed through
>>>> all markup rules one after another, like for the page, but before the page.
>>>> At that point, if you encounter your markup rule, it will set the page
>>>> variable (but not display it in the same block). However, later, when the
>>>> rest of the page is processed, the page variable value is already set so
>>>> when your markup is encountered, the variable is replaced with the value.
>>>>
>>>> If you must process your markup rule before {$PageVariables}, change the
>>>> "when" argument (second) on the Markup() call.
>>>>
>>>> Petko
>>>>
>>>> ---
>>>>
>>>> On 2017-07-14 19:45, Christopher Cox wrote:
>>>>> Ok.. this is weird.  If my (:mymarkup:) is embedded in
>>>>> (:markup:)(:markupend:) it works and my page variable is set. What am
>>>>> I missing?
>>>>>
>>>>>
>>>>> On 07/14/2017 11:45 AM, Christopher Cox wrote:
>>>>>> What I want is to have something like:
>>>>>>
>>>>>>
>>>>>> (:mymarkup:)
>>>>>>
>>>>>> {$mymarkupvar}
>>>>>>
>>>>>>
>>>>>> on a page.  Where mymarkup does inside it's function:
>>>>>>
>>>>>>
>>>>>> global $FmtPV;
>>>>>>
>>>>>>
>>>>>> $GLOBALS['myvar'] = 'hello';
>>>>>>
>>>>>> $FmtPV['$mymarkupvar'] = '$GLOBALS["myvar"]';
>>>>>>
>>>>>>
>
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>




More information about the pmwiki-users mailing list