Major Refactoring
This is a major refactoring of the plugin's code base with the goal to make it easier to maintain and extend. The monolithic architecture has been broken into several classes with clearly separated concerns.
All PDF generation is now decoupled from the environment. This is in preparation to add a a command line or remote API component in the future.
MPDF has been updated to version 8.2.
Service classes:
-
PdfExportService.php: PDF generation and delivery service
- Extracted PDF generation logic from action plugin
- Handles PDF output, caching, and HTTP response
- Clean separation between event handling and business logic
-
Config.php: Centralized configuration management
- Encapsulates plugin configuration and input variables
- Generates mPDF configuration arrays
- Provides clean API for accessing settings
-
DokuPdf.php: mPDF wrapper (replaces DokuPDF.class.php)
- Thin wrapper around mPDF with DokuWiki-specific defaults
- Custom HttpClient and LocalContentLoader integration
- has a few todo markers for future improvements in language handling
-
Writer.php: Main PDF composition orchestrator
- Composites Config, Template, DokuPdf, and Styles
- Handles TOC generation, internal link rewriting, and debug output
- Manages the overall PDF writing workflow
-
Template.php: Template file handling
- Loads header/footer/cover templates
- Applies placeholder substitution
-
Styles.php: CSS and styling management
- Loads styles from plugins and templates
- Handles CSS compilation and processing
-
Cache.php: Caching layer
- Implements DokuWiki cache integration
- Manages cache validation and retrieval
New collector architecture is responsible to collect the pages to be added to the PDF.
-
AbstractCollector.php: Base class for all collectors
- Common functionality for page collection
- Checks ACLs
- extracts title and language info
-
PageCollector.php: Single page export
- No longer relies on global $ID
- Clean dependency injection via Config
-
NamespaceCollector.php: Namespace export
- Recursive page collection from namespaces
- provides new event
DW2PDF_NAMESPACEEXPORT_SORTwhere plugins could influence the sorting (or even filter out pages)
-
BookCreatorLiveSelectionCollector.php: Live BookCreator selections
- Handles temporary book selections
-
BookCreatorSavedSelectionCollector.php: Saved BookCreator selections
- Handles saved book collections
-
CollectorFactory.php: Factory for instantiating collectors
- Determines correct collector based on request parameters
Media Handling #527
-
MediaLinkResolver.php: Media link resolution (replaces old ImageDecorator)
- Resolves DokuWiki media links to filesystem paths
- Integration point for custom image processing
-
HttpClient.php: Custom HTTP client for mPDF
- Implements mPDF HttpClient interface
- Integrates MediaLinkResolver for proper media handling
-
LocalContentLoader.php: Custom local content loader
- Implements mPDF LocalContentLoaderInterface
- Integrates MediaLinkResolver for proper media handling
Link rewriting is now done outside the (cached) rendering. The plugin requires the DOM and XML extension for this.
A bunch of tests have been added but they are far from comprehensive. Help in manually testing this branch would be very welcome
In theory, bookcreator integration should remain unchanged, but has not been tested. I did however change a lot of the Exception handling regarding the bookcreator integration so this part might behave different.
Issues addressed in this PR: #528 #527 #526 #508 #455 #140 (could be implemented via the new event now)
This refactoring has been largely financed by the DokuWiki Business Plugin Partner Program. Please consider joining the program to support future work like this.
Impressive refactoring! Thanks for the work! I start reviewing today, but it will take some time as I have limit time per day/week.
Just a first small observation. The tpl url-parameter seems now not supported anymore? Is that intended? I have reports that people seem to use it. I was still considering to add a dropdown or something like that for it in the Bookcreator.
Doc change: seems debug output can now directly be requested with debug url parameter, it is not needed to enable $conf['allowdebug'] first before using &debughtml=text|html
it is not needed to enable $conf['allowdebug']
Hmm you're right. Do you think this is a security issue? Might be a SEO issue at least if debug links end up on the web (duplicate content).
BTW. I am not 100% happy with how debugging currently works anyway (just suddenly dumping HTML and exiting). I might work on it a bit more.
it is not needed to enable $conf['allowdebug']
Hmm you're right. Do you think this is a security issue? Might be a SEO issue at least if debug links end up on the web (duplicate content).
I do not expect it will expose css or html people could otherwise not find It is also less processing, so load on server is probably not that heavy. So for me it does not matter that much.
BTW. I am not 100% happy with how debugging currently works anyway (just suddenly dumping HTML and exiting). I might work on it a bit more.
Its purpose is to have a way to grab the entire input that is given to mPDF, to enable debugging pdf creation itself. Since we add page for page to mPDF this workaround with buffering html is added. Of course, it is not the literal input to mPDF.
Merged the attributes PR, added a whole bunch of tests, fixed issues with numbered headers in the renderer.