BibliographicExtension/bibliography.php
From PeacockWiki
(Difference between revisions)
Revision as of 01:05, 27 August 2006 (edit) Trevorp (Talk | contribs) ← Previous diff |
Current revision (03:00, 17 October 2006) (edit) 137.166.127.86 (Talk) |
||
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 39: | Line 39: | ||
} | } | ||
- | function cssBibliography() | + | function cssBibliography(&$css) |
{ | { | ||
global $wgScriptPath; | global $wgScriptPath; | ||
- | $css = "/*<![CDATA[*/". | + | $css.= "/*<![CDATA[*/". |
- | " @import \"$wgScriptPath/?file=bibliography.css\"; ". | + | " @import \"$wgScriptPath/?bibfile=bibliography.css\"; "; |
- | "/*]]>*/"; | + | if(isset($_GET['printable']) && $_GET['printable']=='yes') |
+ | $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrint.css\"; "; | ||
+ | if(isset($_GET['final']) && $_GET['printable']=='yes') | ||
+ | $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrintFinal.css\"; "; | ||
+ | $css.= "/*]]>*/"; | ||
return true; | return true; | ||
} | } | ||
- | function renderRefrence($str, $argv, $parser) | + | function renderReference($str, $argv, $parser) |
{ | { | ||
$text=$this->renderWikiText($str, $parser); | $text=$this->renderWikiText($str, $parser); | ||
+ | $this->mBibliography=BibliographyFormat::orderReferences($this->mBibliography); | ||
# var_dump($this->mBibliography); | # var_dump($this->mBibliography); | ||
while(preg_match('/<'.$this->citeTag.' (.*?)\/>/ms', $text, $match, PREG_OFFSET_CAPTURE)) | while(preg_match('/<'.$this->citeTag.' (.*?)\/>/ms', $text, $match, PREG_OFFSET_CAPTURE)) | ||
Line 77: | Line 82: | ||
$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; | ||
Line 112: | Line 117: | ||
foreach($this->mCite as $item=>$note) | foreach($this->mCite as $item=>$note) | ||
{ | { | ||
+ | $item=BibliographyFormat::getArticleName($item); | ||
$text.=" article=\"".$item."\""; | $text.=" article=\"".$item."\""; | ||
if ($note!='') | if ($note!='') | ||
Line 146: | Line 152: | ||
header("Content-type: text/css"); | header("Content-type: text/css"); | ||
?> | ?> | ||
- | //CSS here | + | p { |
+ | text-indent: 10px; | ||
+ | } | ||
+ | |||
+ | h1 { | ||
+ | page-break-before: always; | ||
+ | } | ||
+ | |||
+ | h1.firstHeading { | ||
+ | page-break-before: avoid; | ||
+ | } | ||
+ | |||
+ | p.bibliographicReference, | ||
+ | .bibliographicReference p { | ||
+ | padding-left: 20px; | ||
+ | text-indent: -20px; | ||
+ | line-height: 2em; | ||
+ | } | ||
+ | |||
+ | .bibliographicReferences{ | ||
+ | } | ||
+ | <?php | ||
+ | die(); | ||
+ | case "bibliographyPrint.css": | ||
+ | header("Content-type: text/css"); | ||
+ | ?> | ||
+ | .firstHeading, | ||
+ | .printfooter, | ||
+ | #footer, | ||
+ | #catlinks { | ||
+ | display: none; | ||
+ | } | ||
+ | <?php | ||
+ | die(); | ||
+ | case "bibliographyPrintFinal.css": | ||
+ | header("Content-type: text/css"); | ||
+ | ?> | ||
+ | p { | ||
+ | margin: .5em 0 .5em 0; | ||
+ | line-height: 2em; | ||
+ | } | ||
<?php | <?php | ||
die(); | die(); |
Current revision
<?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(&$css) { global $wgScriptPath; $css.= "/*<![CDATA[*/". " @import \"$wgScriptPath/?bibfile=bibliography.css\"; "; if(isset($_GET['printable']) && $_GET['printable']=='yes') $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrint.css\"; "; if(isset($_GET['final']) && $_GET['printable']=='yes') $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrintFinal.css\"; "; $css.= "/*]]>*/"; return true; } function renderReference($str, $argv, $parser) { $text=$this->renderWikiText($str, $parser); $this->mBibliography=BibliographyFormat::orderReferences($this->mBibliography); # 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) { $item=BibliographyFormat::getArticleName($item); $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"); ?> p { text-indent: 10px; } h1 { page-break-before: always; } h1.firstHeading { page-break-before: avoid; } p.bibliographicReference, .bibliographicReference p { padding-left: 20px; text-indent: -20px; line-height: 2em; } .bibliographicReferences{ } <?php die(); case "bibliographyPrint.css": header("Content-type: text/css"); ?> .firstHeading, .printfooter, #footer, #catlinks { display: none; } <?php die(); case "bibliographyPrintFinal.css": header("Content-type: text/css"); ?> p { margin: .5em 0 .5em 0; line-height: 2em; } <?php die(); } } ?>