|
|
| (31 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| − | <?php
| + | {{svn|http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/PdfBook}} |
| − | # Extension:PdfBook{{Category:Extensions|PdfBook}}{{php}}{{Category:Extensions created with Template:Extension}}
| |
| − | # - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
| |
| − | # - Author: [http://www.organicdesign.co.nz/nad User:Nad]
| |
| − | # - Started: 2007-08-08
| |
| | | | |
| − | if (!defined('MEDIAWIKI')) die('Not an entry point.');
| + | == Other free PDF libraries == |
| − | | + | *[http://www.tcpdf.org/ TCPDF] |
| − | define('PDFBOOK_VERSION','0.0.0, 2007-08-08');
| + | *[http://www.mpdf1.com mPDF] |
| − | | |
| − | $wgPdfBookMagic = "book";
| |
| − | $wgExtensionFunctions[] = 'wfSetupPdfBook';
| |
| − | $wgHooks['LanguageGetMagic'][] = 'wfPdfBookLanguageGetMagic';
| |
| − | | |
| − | $wgExtensionCredits['parserhook'][] = array(
| |
| − | 'name' => 'Pdf Book',
| |
| − | 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]',
| |
| − | 'description' => 'Composes a book from articles in a category and exports as a PDF book',
| |
| − | 'url' => 'http://www.mediawiki.org/wiki/Extension:Pdf_Book',
| |
| − | 'version' => PDFBOOK_VERSION
| |
| − | );
| |
| − | | |
| − | class PdfBook {
| |
| − | | |
| − | # Constructor
| |
| − | function PdfBook() {
| |
| − | global $wgHooks,$wgParser,$wgPdfBookMagic;
| |
| − | $wgParser->setFunctionHook($wgPdfBookMagic,array($this,'magicBook'));
| |
| − | }
| |
| − | | |
| − | # Expand the book-magic
| |
| − | function magicBook(&$parser) {
| |
| − | | |
| − | # Populate $argv with both named and numeric parameters
| |
| − | $argv = array();
| |
| − | foreach (func_get_args() as $arg) if (!is_object($arg)) {
| |
| − | if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg;
| |
| − | }
| |
| − | | |
| − | # Build text of expanded result
| |
| − | $args = '';
| |
| − | foreach ($argv as $k => $v) $args .= "*'''$k:''' ''$v''\n";
| |
| − | $text = "=== magicBook(): ===\n$args";
| |
| − | | |
| − | # Return result with available parser flags
| |
| − | return array(
| |
| − | $text,
| |
| − | found => true,
| |
| − | nowiki => false,
| |
| − | noparse => false,
| |
| − | noargs => false,
| |
| − | isHTML => false
| |
| − | );
| |
| − | | |
| − | }
| |
| − | | |
| − | # Needed in some versions to prevent Special:Version from breaking
| |
| − | function __toString() { return 'PdfBook'; }
| |
| − | }
| |
| − | | |
| − | # Called from $wgExtensionFunctions array when initialising extensions
| |
| − | function wfSetupPdfBook() {
| |
| − | global $wgPdfBook;
| |
| − | $wgPdfBook = new PdfBook();
| |
| − | }
| |
| − | | |
| − | # Needed in MediaWiki >1.8.0 for magic word hooks to work properly
| |
| − | function wfPdfBookLanguageGetMagic(&$magicWords,$langCode = 0) {
| |
| − | global $wgPdfBookMagic;
| |
| − | $magicWords[$wgPdfBookMagic] = array(0,$wgPdfBookMagic);
| |
| − | return true;
| |
| − | }
| |
| − | ?>
| |