2
# Copyright (C) 2005 Anders Wegge Jakobsen <awegge@gmail.com>
3
# http://www.mediawiki.org/
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program; if not, write to the Free Software Foundation, Inc.,
17
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
# http://www.gnu.org/copyleft/gpl.html
22
* Extension to add footnotes to the wiki pages.
26
* <footnote>This text is placed at the end of the page.</footnote>
28
* @author Anders Wegge Jakobsen <awegge@gmail.com>
29
* @addtogroup Extensions
32
if( !defined( 'MEDIAWIKI' ) ) {
37
$wgExtensionFunctions[] = "wfFootnote";
39
function wfFootnote() {
40
global $wgParser, $wgHooks ;
41
$wgParser->setHook( "footnote" , 'parse_footnote' ) ;
42
$wgHooks['ParserBeforeTidy'][] = 'insert_endnotes' ;
45
$footnoteNotes = array() ;
47
$footnoteRecursionGuard = false;
49
function insert_endnotes( &$parser, &$text ) {
50
global $footnoteNotes , $footnoteCount, $footnoteRecursionGuard ;
52
wfDebug("insert_endnotes:\n<<<$text>>>\n");
54
if( $footnoteRecursionGuard ) return true;
55
if( count( $footnoteNotes ) == 0 ) return true;
58
foreach( $footnoteNotes AS $num => $entry ) {
59
$x = " <a name='footnote{$num}'></a>\n";
60
$x = $x . "<li>$entry <a href='#footnoteback{$num}'>↑</a></li>\n" ;
63
$ret = "<hr /><ol>" . $ret . "</ol>" ;
67
/* Clear global array after rendering */
68
$footnoteNotes = array();
74
function parse_footnote( $text, $params, &$parser ) {
77
global $footnoteNotes , $footnoteCount, $footnoteRecursionGuard ;
78
global $footnoteParserObj;
80
if( !isset( $footnoteParserObj )) {
81
$footnoteParserObj = new Parser ;
84
$footnoteRecursionGuard = true;
85
$ret = $footnoteParserObj->parse( $text , $parser->getTitle() , $parser->getOptions(), false ) ;
86
$ret = $ret->getText();
87
$footnoteRecursionGuard = false;
89
$footnoteNotes[$footnoteCount] = $ret;
91
$ret = "<a href='#footnote{$footnoteCount}' name='footnoteback{$footnoteCount}'><sup>$footnoteCount</sup></a>" ;
94
if( $footnoteCount == 2 ) {
96
$wgHooks['ParserBeforeTidy'][] = 'insert_endnotes' ;