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.