BibliographicExtension/bibliography.php
From PeacockWiki
(Difference between revisions)
| Revision as of 15:17, 16 October 2006 (edit) 137.166.127.86 (Talk) ← Previous diff |
Revision as of 15:24, 16 October 2006 (edit) 137.166.127.86 (Talk) Next diff → |
||
| Line 1: | Line 1: | ||
| <pre><?php | <pre><?php | ||
| - | |||
| - | |||
| require('extensions/bibliographyformat.php'); | require('extensions/bibliographyformat.php'); | ||
| - | |||
| - | |||
| if(isset($_GET['bibfile'])) | if(isset($_GET['bibfile'])) | ||
| - | |||
| doFileBib(); | doFileBib(); | ||
| - | |||
| - | |||
| $wgExtensionCredits["parserhook"][]=array( | $wgExtensionCredits["parserhook"][]=array( | ||
| - | |||
| 'name' => 'Bibliographic Extension', | 'name' => 'Bibliographic Extension', | ||
| - | |||
| 'version' => '0.1', | 'version' => '0.1', | ||
| - | |||
| 'url' => 'http://wiki.peacocktech.com/wiki/BibliographicExtension', | 'url' => 'http://wiki.peacocktech.com/wiki/BibliographicExtension', | ||
| - | |||
| 'author' => '[http://about.peacocktech.com/trevorp/ Trevor Peacock]', | 'author' => '[http://about.peacocktech.com/trevorp/ Trevor Peacock]', | ||
| - | |||
| 'description' => 'Adds a bibliographic engine' ); | 'description' => 'Adds a bibliographic engine' ); | ||
| - | |||
| $wgExtensionFunctions[] = "BibliographicExtension"; | $wgExtensionFunctions[] = "BibliographicExtension"; | ||
| - | |||
| - | |||
| function BibliographicExtension() | function BibliographicExtension() | ||
| - | |||
| { | { | ||
| - | |||
| global $wgParser; | global $wgParser; | ||
| - | |||
| - | |||
| class Bibliography { | class Bibliography { | ||
| - | |||
| - | |||
| var $mBibliography = array(); | var $mBibliography = array(); | ||
| - | |||
| var $citeTag="bcite"; | var $citeTag="bcite"; | ||
| - | |||
| - | |||
| function Bibliography() | function Bibliography() | ||
| - | |||
| { | { | ||
| - | |||
| global $wgParser, $wgHooks; | global $wgParser, $wgHooks; | ||
| - | |||
| $wgParser->setHook("reference", array( &$this, "renderReference")); | $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")); | ||
| - | |||
| $wgHooks['SkinTemplateSetupPageCss'][] = array( &$this, 'cssBibliography'); | $wgHooks['SkinTemplateSetupPageCss'][] = array( &$this, 'cssBibliography'); | ||
| - | |||
| #$wgHooks['OutputPageBeforeHTML'][] = array( &$this, 'PostProcess'); | #$wgHooks['OutputPageBeforeHTML'][] = array( &$this, 'PostProcess'); | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| function renderWikiText($input, &$parser) | function renderWikiText($input, &$parser) | ||
| - | |||
| { | { | ||
| - | |||
| return $parser->parse($input, $parser->mTitle, $parser->mOptions, | return $parser->parse($input, $parser->mTitle, $parser->mOptions, | ||
| - | |||
| false, false)->getText(); | false, false)->getText(); | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| function cssBibliography(&$css) | function cssBibliography(&$css) | ||
| - | |||
| { | { | ||
| - | |||
| global $wgScriptPath; | global $wgScriptPath; | ||
| - | |||
| $css.= "/*<![CDATA[*/". | $css.= "/*<![CDATA[*/". | ||
| - | |||
| " @import \"$wgScriptPath/?bibfile=bibliography.css\"; "; | " @import \"$wgScriptPath/?bibfile=bibliography.css\"; "; | ||
| - | |||
| if(isset($_GET['printable']) && $_GET['printable']=='yes') | if(isset($_GET['printable']) && $_GET['printable']=='yes') | ||
| $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrint.css\"; "; | $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrint.css\"; "; | ||
| - | |||
| if(isset($_GET['final']) && $_GET['printable']=='yes') | if(isset($_GET['final']) && $_GET['printable']=='yes') | ||
| $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrintFinal.css\"; "; | $css.= " @import \"$wgScriptPath/?bibfile=bibliographyPrintFinal.css\"; "; | ||
| - | |||
| $css.= "/*]]>*/"; | $css.= "/*]]>*/"; | ||
| - | |||
| return true; | return true; | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| function renderReference($str, $argv, $parser) | function renderReference($str, $argv, $parser) | ||
| - | |||
| { | { | ||
| - | |||
| $text=$this->renderWikiText($str, $parser); | $text=$this->renderWikiText($str, $parser); | ||
| - | |||
| $this->mBibliography=BibliographyFormat::orderReferences($this->mBibliography); | $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)) | ||
| - | |||
| { | { | ||
| - | |||
| preg_match_all('/(.*?)=\"(.*?)\"/ms', $match[1][0], $match2); | preg_match_all('/(.*?)=\"(.*?)\"/ms', $match[1][0], $match2); | ||
| - | |||
| # var_dump($match2); | # var_dump($match2); | ||
| - | |||
| $params=array(); | $params=array(); | ||
| - | |||
| foreach($match2[1] as $key=>$item) | foreach($match2[1] as $key=>$item) | ||
| - | |||
| { | { | ||
| - | |||
| if(trim($item)=='article') | if(trim($item)=='article') | ||
| - | |||
| { | { | ||
| - | |||
| if(!key_exists('articles', $params)) | if(!key_exists('articles', $params)) | ||
| - | |||
| $params['articles']=array(); | $params['articles']=array(); | ||
| - | |||
| $params['articles'][$match2[2][$key]]=array('article'=>$this->mBibliography[$match2[2][$key]]); | $params['articles'][$match2[2][$key]]=array('article'=>$this->mBibliography[$match2[2][$key]]); | ||
| - | |||
| $lastarticle=$match2[2][$key]; | $lastarticle=$match2[2][$key]; | ||
| - | |||
| } | } | ||
| - | |||
| else | else | ||
| - | |||
| { | { | ||
| - | |||
| if(trim($item)=='note') | if(trim($item)=='note') | ||
| - | |||
| $params['articles'][$lastarticle]['note']=$match2[2][$key]; | $params['articles'][$lastarticle]['note']=$match2[2][$key]; | ||
| - | |||
| else | else | ||
| - | |||
| $params[trim($item)]=$match2[2][$key]; | $params[trim($item)]=$match2[2][$key]; | ||
| - | |||
| } | } | ||
| - | |||
| } | } | ||
| - | |||
| # var_dump($params); | # var_dump($params); | ||
| - | |||
| $start=$match[0][1]; | $start=$match[0][1]; | ||
| - | |||
| $len=strlen($match[0][0]); | $len=strlen($match[0][0]); | ||
| - | |||
| $reference=BibliographyFormat::intextcite($params); | $reference=BibliographyFormat::intextcite($params); | ||
| - | |||
| $text=substr_replace($text, $reference, $start, $len); | $text=substr_replace($text, $reference, $start, $len); | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| $reference=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($reference)) $reference=BibliographyFormat::referenceList($this->mBibliography); | if(!isset($reference)) $reference=BibliographyFormat::referenceList($this->mBibliography); | ||
| - | |||
| $text=substr_replace($text, $reference, $start, $len); | $text=substr_replace($text, $reference, $start, $len); | ||
| - | |||
| } | } | ||
| - | |||
| return $text; | return $text; | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| var $mCite; | var $mCite; | ||
| - | |||
| function renderCite($str, $argv, $parser) | function renderCite($str, $argv, $parser) | ||
| - | |||
| { | { | ||
| - | |||
| if(!isset($this->mCite)) | if(!isset($this->mCite)) | ||
| - | |||
| { | { | ||
| - | |||
| $this->mCite=array(); | $this->mCite=array(); | ||
| - | |||
| } | } | ||
| - | |||
| else | else | ||
| - | |||
| { | { | ||
| - | |||
| if(key_exists('article', $argv)) | if(key_exists('article', $argv)) | ||
| - | |||
| $this->mCite[$argv['article']]=key_exists('note', $argv)?$argv['note']:''; | $this->mCite[$argv['article']]=key_exists('note', $argv)?$argv['note']:''; | ||
| - | |||
| $this->renderWikiText($str, $parser); | $this->renderWikiText($str, $parser); | ||
| - | |||
| return; | return; | ||
| - | |||
| } | } | ||
| - | |||
| if(key_exists('article', $argv)) | if(key_exists('article', $argv)) | ||
| - | |||
| $this->mCite[$argv['article']]=key_exists('note', $argv)?$argv['note']:''; | $this->mCite[$argv['article']]=key_exists('note', $argv)?$argv['note']:''; | ||
| - | |||
| $this->renderWikiText($str, $parser); | $this->renderWikiText($str, $parser); | ||
| - | |||
| $text="<".$this->citeTag." type=\"".(key_exists('type', $argv)?$argv['type']:'normal')."\""; | $text="<".$this->citeTag." type=\"".(key_exists('type', $argv)?$argv['type']:'normal')."\""; | ||
| - | |||
| foreach($this->mCite as $item=>$note) | foreach($this->mCite as $item=>$note) | ||
| - | |||
| { | { | ||
| $item=BibliographyFormat::getArticleName($item); | $item=BibliographyFormat::getArticleName($item); | ||
| - | |||
| $text.=" article=\"".$item."\""; | $text.=" article=\"".$item."\""; | ||
| - | |||
| if ($note!='') | if ($note!='') | ||
| - | |||
| $text.=" note=\"".$note."\""; | $text.=" note=\"".$note."\""; | ||
| - | |||
| if(!key_exists($item, $this->mBibliography)) | if(!key_exists($item, $this->mBibliography)) | ||
| - | |||
| $this->mBibliography[$item]=new BibliographyFormat($item); | $this->mBibliography[$item]=new BibliographyFormat($item); | ||
| - | |||
| } | } | ||
| - | |||
| $text.="/>"; | $text.="/>"; | ||
| - | |||
| unset($this->mCite); | unset($this->mCite); | ||
| - | |||
| return $text; | return $text; | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| function renderBibliography($str, $argv, $parser) | function renderBibliography($str, $argv, $parser) | ||
| - | |||
| { | { | ||
| - | |||
| return "<bibliography/>"; | return "<bibliography/>"; | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| function PostProcess($parserOutput, $text) | function PostProcess($parserOutput, $text) | ||
| - | |||
| { | { | ||
| - | |||
| $text=$text; | $text=$text; | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| } | } | ||
| - | |||
| - | |||
| new Bibliography(); | new Bibliography(); | ||
| - | |||
| - | |||
| } | } | ||
| - | |||
| - | |||
| function doFileBib() | function doFileBib() | ||
| - | |||
| { | { | ||
| - | |||
| switch ($_GET['bibfile']) | switch ($_GET['bibfile']) | ||
| - | |||
| { | { | ||
| - | |||
| case "bibliography.css": | case "bibliography.css": | ||
| - | |||
| header("Content-type: text/css"); | header("Content-type: text/css"); | ||
| - | |||
| ?> | ?> | ||
| - | |||
| p { | p { | ||
| text-indent: 10px; | text-indent: 10px; | ||
| Line 323: | Line 174: | ||
| <?php | <?php | ||
| die(); | die(); | ||
| - | |||
| case "bibliographyPrint.css": | case "bibliographyPrint.css": | ||
| - | |||
| header("Content-type: text/css"); | header("Content-type: text/css"); | ||
| - | |||
| ?> | ?> | ||
| - | |||
| .firstHeading, | .firstHeading, | ||
| .printfooter, | .printfooter, | ||
| Line 338: | Line 185: | ||
| <?php | <?php | ||
| die(); | die(); | ||
| - | |||
| case "bibliographyPrintFinal.css": | case "bibliographyPrintFinal.css": | ||
| - | |||
| header("Content-type: text/css"); | header("Content-type: text/css"); | ||
| - | |||
| ?> | ?> | ||
| - | |||
| p { | p { | ||
| margin: .5em 0 .5em 0; | margin: .5em 0 .5em 0; | ||
| Line 351: | Line 194: | ||
| <?php | <?php | ||
| die(); | die(); | ||
| - | |||
| } | } | ||
| - | |||
| } | } | ||
| - | |||
| - | |||
| ?></pre> | ?></pre> | ||
Revision as of 15:24, 16 October 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(&$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 {
}
.bibliographicReferences{
padding-left: 20px;
text-indent: -20px;
line-height: 2em;
}
<?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();
}
}
?>
