Extension:DownloadBook
Release status: beta |
|
|---|---|
| Implementation | Special page |
| Description | Allows extension Collection to convert books/pages into PDF, etc. locally |
| Author(s) | Edward Chernenkotalk |
| Latest version | 0.1.1 |
| Compatibility policy | Master maintains backward compatibility. |
| MediaWiki | 1.43+ (master branch) 1.39-1.42 (REL1_39 branch) |
| Database changes | Yes |
| Tables | bookrenderingtask |
| License | GNU General Public License 2.0 or later |
| Download | GitHub: |
|
|
The DownloadBook extension allows extension Collection to generate PDF files without a local or external MWServe server.
It can use third-party utilities such as pandoc (for ePub, ODT, etc.) or WeasyPrint (for PDF). They exist as packages in many Linux distributions.
Installation
[edit]The Collection extension needs to be installed for this extension to work. Moreover, depending on which output formats are chosen also pandoc (for ePub, ODT, etc.) and/or WeasyPrint (for PDF).
- Check-out the sources with
git clone https://github.com/edwardspec/mediawiki-extension-DownloadBook.gitand place the file(s) in a directory calledDownloadBookin yourextensions/folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'Collection' ); $wgCollectionDisableDownloadSection = false; wfLoadExtension( 'DownloadBook' ); $wgCollectionMWServeURL = '<URL_OF_YOUR_WIKI_HERE>/wiki/Special:DownloadBook';
- Run the update script which will automatically create the necessary database tables that this extension needs.
- Further configure as required.
Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Installation for older versions of MediaWiki
[edit]For MediaWiki 1.39-1.42, replace the above-mentioned "git clone" command with the following:
git clone -b REL1_39 https://github.com/edwardspec/mediawiki-extension-DownloadBook.git
Advanced configuration
[edit]You can modify the conversion commands in "LocalSettings.php", for example:
$wgDownloadBookConvertCommand['epub'] = "pandoc --from=html --to=epub {INPUT} -o {OUTPUT}";
Please see the file "extension.json" for other configuration options. Also note that keys in $wgDownloadBookConvertCommand array are the same formats as in Collection (i.e. $wgDownloadBookConvertCommand['rl'] is the command for PDF).
Installing third-party conversion tool is your own risk and responsibility. This extension simply calls that tool, and then provides the result to extension Collection.
Using custom CSS when generating PDF
[edit]When using weasyprint to generate PDF, custom CSS can be specified with the --stylesheet parameter.
$wgDownloadBookConvertCommand['rl'] = "weasyprint --stylesheet \"https://example.com/wiki/MediaWiki:Print.css?action=raw&ctype=text/css\" --stylesheet \"https://example.com/load.php?lang=fr&modules=site.styles&only=styles&printable=1\" --encoding utf8 {INPUT} {OUTPUT}";
Document layout
[edit]To insert page breaks between wiki pages, use a custom CSS stylesheet and specify:
h1 {
break-before: page;
}
Troubleshooting
[edit]Add the following to your "LocalSettings.php":
$wgDebugLogGroups['DownloadBook'] = '/path/to/writable/logfile.txt';
