Not logged in. · Lost password · Register
Forum: General Help and Support Development RSS
Parsing and storing plugin options/data
Avatar
og #1
Member since May 2006 · 437 posts · Location: Bayern
Group memberships: Members
Show profile · Link to this post
Subject: Parsing and storing plugin options/data
If i understand it right (please correct me if not) the plugin function handle() is called when a page is saved. It's purpose is to parse plugin syntax and store tokens of it somewhere where the render()-function can use them later to process output.

Is it preferred (or wise?) to put all parsing code inside the syntax.php instead of using functions stored inside an own lib. And if so, are there Dokuwiki-helpers for parsing? Most plugin-syntax uses concepts of keywords, key/value-pairs (assigned by '='), comments starting '#' and such. Maybe there is some generic lib or fx for this already included?
Oli...
Avatar
LarsDW223 #2
Member since Sep 2014 · 462 posts · Location: Paderborn
Group memberships: Members
Show profile · Link to this post
If i understand it right (please correct me if not) the plugin function handle() is called when a page is saved. It's purpose is to parse plugin syntax and store tokens of it somewhere where the render()-function can use them later to process output.

No, the handle() function is called when the page gets loaded/viewed. The function returns the data which shall be passed to the render() function as an array. Then with that data the render() function is called each time the page needs to get updated. So, if the page is cached the function is not called. Of course, if you save the page both functions will be called. But also if you have ~~NOCACHE~~ in the page, the render() function would be called every time you open a page or if you update the page in your browser.
Avatar
og #3
Member since May 2006 · 437 posts · Location: Bayern
Group memberships: Members
Show profile · Link to this post
Oh, then i completely misunderstood this. In Dokuwiki development at https://www.dokuwiki.org/devel:syntax_plugins#handle_method you can read:

handle() method

This is the part of your plugin which should do all the work. Before DokuWiki renders the wiki page it creates a list of instructions for the renderer. The plugin's handle() method generates the render instructions for the plugin's own syntax mode. At some later time, these will be interpreted by the plugin's render() method. The instruction list is cached and can be used many times, making it sensible to maximize the work done once by this function and minimize the work done many times by render().

For me it sounds as if the output of handle() is the "instruction-list" which are cached for multiple render()-calls. Caching of render-output itself seems another task for me. Normally, if the page is not changed, there is no need to reinterpret the source, nor to rebuild the HTML-page.

My own debugging shows, that handle() is only called after pagesave, whereas render() is called many times. Can i be so wrong?...
Oli...
Avatar
LarsDW223 #4
Member since Sep 2014 · 462 posts · Location: Paderborn
Group memberships: Members
Show profile · Link to this post
I think both is cached. Because if the instruction list does not change, then the output of the renderer will also normally be the same. Put something like this in a syntax plugin's render() function:

    $renderer->doc .= 'Now:'.time();

This outputs a timestamp which changes continuously. Each time you update your browser (e.g. F5 in Firefox) the timestamp should change. But it does not! Because the renderer output is cached to. As soon as you put ~~NOCACHE~~ into the wiki page, you will see the timestamp change with every page update.

Because the renderer output is cached too, plugins which generate dynamic content (e.g. filelist, cloud) usually disable the cache or give at least a config option which allows disabling of the cache.
Avatar
LarsDW223 #5
Member since Sep 2014 · 462 posts · Location: Paderborn
Group memberships: Members
Show profile · Link to this post
But we should also keep in mind that the render() function e.g. can be called multiple times for different modes: metadata, xhtml, text, pdf, odt... (if supported)
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2020-02-26, 15:36:26 (UTC +01:00)