Extension:PdfBook

From Organic Design wiki
Revision as of 00:10, 8 August 2007 by Nad (talk | contribs) (Make a start)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<?php

  1. Extension:PdfBook
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:PhpCategory:Extensions created with Template:Extension

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:Nad
  3. - Started: 2007-08-08

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('PDFBOOK_VERSION','0.0.0, 2007-08-08');

$wgPdfBookMagic = "book"; $wgPdfBookTag = "bar"; $wgExtensionFunctions[] = 'wfSetupPdfBook'; $wgHooks['LanguageGetMagic'][] = 'wfPdfBookLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'Pdf Book', 'author' => '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'; }

	}
  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupPdfBook() { global $wgPdfBook; $wgPdfBook = new PdfBook(); }

  1. 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; } ?>