Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set page context in Handler #3267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

set page context in Handler #3267

wants to merge 1 commit into from

Conversation

splitbrain
Copy link
Collaborator

Under some circumstances it is useful to know if the current parsing process is running in a page context or not.

One of the examples is the struct plugin's use of the PARSER_HANDLER_DONE event to automatically inject its own output instruction. Currently this instruction is injected in each and every processing and only on rendering is decided if there is anything to output.

This patch injects a page hint into the Handler when the handler was created from our p_wiki_xhtml() method (and only then). Plugins can use the getPage() method to check the context if needed.

Note: currently p_wiki_xhtml() also modifies the global $ID variable which might also used as context hint (but will also be set during on-the-fly renders, eg. the preview intro text).

It would probably be a good idea to check if it would be better when all handle methods rely on getPage() instead of global $ID instead. This would be a major change in parsing though and needs serious testing while this addition has basically no consequences currently.

Under some circumstances it is useful to know if the current parsing
process is running in a page context or not.

One of the examples is the struct plugin's use of the PARSER_HANDLER_DONE
event to automatically inject its own output instruction. Currently this
instruction is injected in each and every processing and only on rendering
is decided if there is anything to output.

This patch injects a page hint into the Handler when the handler was
created from our p_wiki_xhtml() method (and only then). Plugins can use
the getPage() method to check the context if needed.

Note: currently p_wiki_xhtml() also modifies the global $ID variable
which might also used as context hint (but will also be set during
on-the-fly renders, eg. the preview intro text).

It would probably be a good idea to check if it would be better when all
handle methods rely on getPage() instead of global $ID instead. This
would be a major change in parsing though and needs serious testing
while this addition has basically no consequences currently.
@lpaulsen93
Copy link
Collaborator

So getPage() will return null in any other context and the page name/ID in case of normal rendering?

@splitbrain
Copy link
Collaborator Author

Yes, that's the idea.

@ssahara
Copy link
Collaborator

ssahara commented Oct 1, 2020

  1. it may be possible to instantiate handler with $page argument in p_get_instructions(); $handler = new Doku_Handler($id) ?
  2. Doku_Handler has already $status[] property and setStatus() / getStatus() methods, and the new $page property could be simply $status['page'] ?

@michitux
Copy link
Collaborator

michitux commented Oct 1, 2020

Is there any reason why the id is not passed on in line 181 in p_cached_instructions, which should be the place where the parser is usually called for a page?

[Edit] Iirc there are also cases where p_cached_instructions is called without id, and then the id is also missing in the instruction cache event. This is why I added code to some plugins that handle the instruction cache event to check if the file is inside the pages directory and if yes, recover the id from the file's path. I cannot say if this is actually happening but it might not hurt to add similar code directly in p_cached_instructions to ensure that the id is always passed to the handler as otherwise the cache might be created somewhere where the id is not set (e.g., in some plugin) and then you have the wrong instructions in the cache.

@Klap-in
Copy link
Collaborator

Klap-in commented Dec 29, 2020

I have not yet looked in the details, but this looks like an other application of this: lpaulsen93/dokuwiki-plugin-odt#260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants