There's been calls for footnotes [[m:Footnotes]], and it is an ability
that I've wanted for my own wiki for a while, so I hacked up some changes
to Parser.php and Skin.php (from CVS about three weeks ago). I used the
formatHeading function as a template and I am not even a PHP novice, but
the code works okay.
I used [note:foo] as the syntax. There are, I'm sure better choices.
Known issues
* When you have section editing turned on, you can click on editing the
Notes section. You shouldn't be
able to do that because there is nothing really there.
* Double quotes in the note break the hovering behavior of the in text
reference
Thanks for MediaWiki!
-Forest Gregg
$text = preg_replace( '/(^|\n)-----*/',
'\\1<hr />', $text );
+ $text = $this->formatFootnotes( $text );
$text = $this->doHeadings( $text );
/*
*
* This function accomplishes several tasks:
* 1) Auto-number footnotes
* 3) Add a Notes section on the bottom
* 4) Auto-anchor footnotes
*
* It loops through all footnotes, collects the necessary data, then
* splits up the
* string and re-inserts the newly formatted headlines.
*
*/
/* private */ function formatFootnotes( $text, $isMain=true )
{
# numMatches is only used to test if there are footnotes,
#should be better way
$numMatches = preg_match_all( '/\[note:(.*?)\]/i', $text,
$matches );
#check if there are any notes
if ($numMatches) {
# To perform operations on the HTML
$sk =& $this->mOptions->getSkin();
#footnote counter
$footnoteCount = 0;
foreach ( $matches[1] as $footnote ) {
$footnoteCount = $footnoteCount + 1;
#format notes that appear in bottom note section
$footnotes .= $sk->footLine($footnoteCount, $footnote);
#format footnote and hold it in refer
$refer[$footnoteCount] = $sk->footNum($footnoteCount,
$footnote);
}
#format endnotes section
$footnotes = $sk->endNotes($footnotes);
$blocks = preg_split( '/\[note:(.*?)\]/i', $text );
$i = 0;
foreach( $blocks as $block ) {
$full .= $block;
if( !empty( $refer[$i+1] ) ) {
$full .= $refer[$i+1];
}
$i++;
}
$full .= '<br />'.$footnotes;
return $full;
}
else {
return $text;
}
}
[edit]
Skin.php
function footLine( $number, $footnote ) {
$foot = '<a name="endnote'.$number.'"
id="endnote'.$number.'"
title="Return to text"></a><a
href="#note'.$number.'">'.$number.'.</a>
'.$footnote.'<br />';
return $foot;
}
function footNum( $number, $footnote ) {
return '<a
name="note'.$number.'"id="note'.$number.'"></a><sup><a
href="#endnote'.$number.'"
title="'.$footnote.'">'.$number.'</a></sup>';
}
function endNotes ( $footnotes ) {
return
"\n".
'==Notes=='
."\n".
$footnotes;
}