BibliographicExtension/bibliography.php
From PeacockWiki
(Difference between revisions)
Revision as of 01:05, 27 August 2006 (edit) Trevorp (Talk | contribs) ← Previous diff |
Revision as of 01:10, 27 August 2006 (edit) Trevorp (Talk | contribs) Next diff → |
||
Line 26: | Line 26: | ||
{ | { | ||
global $wgParser, $wgHooks; | global $wgParser, $wgHooks; | ||
- | $wgParser->setHook("refrence", array( &$this, "renderRefrence")); | + | $wgParser->setHook("reference", array( &$this, "renderReference")); |
$wgParser->setHook($this->citeTag, array( &$this, "renderCite")); | $wgParser->setHook($this->citeTag, array( &$this, "renderCite")); | ||
$wgParser->setHook("bibliography", array( &$this, "renderBibliography")); | $wgParser->setHook("bibliography", array( &$this, "renderBibliography")); | ||
Line 48: | Line 48: | ||
} | } | ||
- | function renderRefrence($str, $argv, $parser) | + | function renderReference($str, $argv, $parser) |
{ | { | ||
$text=$this->renderWikiText($str, $parser); | $text=$this->renderWikiText($str, $parser); | ||
Line 77: | Line 77: | ||
$start=$match[0][1]; | $start=$match[0][1]; | ||
$len=strlen($match[0][0]); | $len=strlen($match[0][0]); | ||
- | $refrence=BibliographyFormat::intextcite($params); | + | $reference=BibliographyFormat::intextcite($params); |
- | $text=substr_replace($text, $refrence, $start, $len); | + | $text=substr_replace($text, $reference, $start, $len); |
} | } | ||
- | $refrence=null; | + | $reference=null; |
while(preg_match('/<bibliography\/>/ms', $text, $match, PREG_OFFSET_CAPTURE)) | while(preg_match('/<bibliography\/>/ms', $text, $match, PREG_OFFSET_CAPTURE)) | ||
{ | { | ||
$start=$match[0][1]; | $start=$match[0][1]; | ||
$len=strlen($match[0][0]); | $len=strlen($match[0][0]); | ||
- | if(!isset($refrence)) $refrence=BibliographyFormat::referenceList($this->mBibliography); | + | if(!isset($reference)) $reference=BibliographyFormat::referenceList($this->mBibliography); |
- | $text=substr_replace($text, $refrence, $start, $len); | + | $text=substr_replace($text, $reference, $start, $len); |
} | } | ||
return $text; | return $text; |
Revision as of 01:10, 27 August 2006
<?php require('extensions/bibliographyformat.php'); if(isset($_GET['bibfile'])) doFileBib(); $wgExtensionCredits["parserhook"][]=array( 'name' => 'Bibliographic Extension', 'version' => '0.1', 'url' => 'http://wiki.peacocktech.com/wiki/BibliographicExtension', 'author' => '[http://about.peacocktech.com/trevorp/ Trevor Peacock]', 'description' => 'Adds a bibliographic engine' ); $wgExtensionFunctions[] = "BibliographicExtension"; function BibliographicExtension() { global $wgParser; class Bibliography { var $mBibliography = array(); var $citeTag="bcite"; function Bibliography() { global $wgParser, $wgHooks; $wgParser->setHook("reference", array( &$this, "renderReference")); $wgParser->setHook($this->citeTag, array( &$this, "renderCite")); $wgParser->setHook("bibliography", array( &$this, "renderBibliography")); $wgHooks['SkinTemplateSetupPageCss'][] = array( &$this, 'cssBibliography'); #$wgHooks['OutputPageBeforeHTML'][] = array( &$this, 'PostProcess'); } function renderWikiText($input, &$parser) { return $parser->parse($input, $parser->mTitle, $parser->mOptions, false, false)->getText(); } function cssBibliography() { global $wgScriptPath; $css = "/*<![CDATA[*/". " @import \"$wgScriptPath/?file=bibliography.css\"; ". "/*]]>*/"; return true; } function renderReference($str, $argv, $parser) { $text=$this->renderWikiText($str, $parser); # var_dump($this->mBibliography); while(preg_match('/<'.$this->citeTag.' (.*?)\/>/ms', $text, $match, PREG_OFFSET_CAPTURE)) { preg_match_all('/(.*?)=\"(.*?)\"/ms', $match[1][0], $match2); # var_dump($match2); $params=array(); foreach($match2[1] as $key=>$item) { if(trim($item)=='article') { if(!key_exists('articles', $params)) $params['articles']=array(); $params['articles'][$match2[2][$key]]=array('article'=>$this->mBibliography[$match2[2][$key]]); $lastarticle=$match2[2][$key]; } else { if(trim($item)=='note') $params['articles'][$lastarticle]['note']=$match2[2][$key]; else $params[trim($item)]=$match2[2][$key]; } } # var_dump($params); $start=$match[0][1]; $len=strlen($match[0][0]); $reference=BibliographyFormat::intextcite($params); $text=substr_replace($text, $reference, $start, $len); } $reference=null; while(preg_match('/<bibliography\/>/ms', $text, $match, PREG_OFFSET_CAPTURE)) { $start=$match[0][1]; $len=strlen($match[0][0]); if(!isset($reference)) $reference=BibliographyFormat::referenceList($this->mBibliography); $text=substr_replace($text, $reference, $start, $len); } return $text; } var $mCite; function renderCite($str, $argv, $parser) { if(!isset($this->mCite)) { $this->mCite=array(); } else { if(key_exists('article', $argv)) $this->mCite[$argv['article']]=key_exists('note', $argv)?$argv['note']:''; $this->renderWikiText($str, $parser); return; } if(key_exists('article', $argv)) $this->mCite[$argv['article']]=key_exists('note', $argv)?$argv['note']:''; $this->renderWikiText($str, $parser); $text="<".$this->citeTag." type=\"".(key_exists('type', $argv)?$argv['type']:'normal')."\""; foreach($this->mCite as $item=>$note) { $text.=" article=\"".$item."\""; if ($note!='') $text.=" note=\"".$note."\""; if(!key_exists($item, $this->mBibliography)) $this->mBibliography[$item]=new BibliographyFormat($item); } $text.="/>"; unset($this->mCite); return $text; } function renderBibliography($str, $argv, $parser) { return "<bibliography/>"; } function PostProcess($parserOutput, $text) { $text=$text; } } new Bibliography(); } function doFileBib() { switch ($_GET['bibfile']) { case "bibliography.css": header("Content-type: text/css"); ?> //CSS here <?php die(); } } ?>