~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to extensions/Footnote.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
# Copyright (C) 2005 Anders Wegge Jakobsen <awegge@gmail.com>
3
 
# http://www.mediawiki.org/
4
 
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.
9
 
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.
14
 
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
19
 
 
20
 
/**
21
 
 
22
 
* Extension to add footnotes to the wiki pages. 
23
 
*
24
 
* Use with:
25
 
*
26
 
* <footnote>This text is placed at the end of the page.</footnote>
27
 
*
28
 
* @author Anders Wegge Jakobsen <awegge@gmail.com>
29
 
* @addtogroup Extensions
30
 
 */
31
 
 
32
 
if( !defined( 'MEDIAWIKI' ) ) {
33
 
        die();
34
 
}
35
 
 
36
 
 
37
 
$wgExtensionFunctions[] = "wfFootnote";
38
 
 
39
 
function wfFootnote() {
40
 
  global $wgParser, $wgHooks ;
41
 
        $wgParser->setHook( "footnote" , 'parse_footnote' ) ;
42
 
        $wgHooks['ParserBeforeTidy'][] = 'insert_endnotes' ;
43
 
}
44
 
 
45
 
$footnoteNotes = array() ;
46
 
$footnoteCount = 1 ;
47
 
$footnoteRecursionGuard = false;
48
 
 
49
 
function insert_endnotes( &$parser, &$text ) {
50
 
        global $footnoteNotes , $footnoteCount, $footnoteRecursionGuard ;
51
 
        
52
 
        wfDebug("insert_endnotes:\n<<<$text>>>\n");
53
 
 
54
 
        if( $footnoteRecursionGuard ) return true;
55
 
        if( count( $footnoteNotes ) == 0 ) return true;
56
 
        
57
 
        $ret = "" ;
58
 
        foreach( $footnoteNotes AS $num => $entry ) {
59
 
                $x = " <a name='footnote{$num}'></a>\n";
60
 
                $x = $x . "<li>$entry <a href='#footnoteback{$num}'>&uarr;</a></li>\n" ;
61
 
                $ret .= $x ;
62
 
        }
63
 
        $ret = "<hr /><ol>" . $ret . "</ol>" ;
64
 
        
65
 
        $text .= $ret ;
66
 
 
67
 
        /* Clear global array after rendering */
68
 
        $footnoteNotes = array();
69
 
        $footnoteCount = 1 ;
70
 
        
71
 
        return true;
72
 
}
73
 
 
74
 
function parse_footnote( $text, $params, &$parser ) {
75
 
        $ret = "" ;
76
 
 
77
 
        global $footnoteNotes , $footnoteCount, $footnoteRecursionGuard ;
78
 
        global $footnoteParserObj;
79
 
 
80
 
        if( !isset( $footnoteParserObj )) {
81
 
                $footnoteParserObj = new Parser ;
82
 
        }
83
 
 
84
 
        $footnoteRecursionGuard = true;
85
 
        $ret = $footnoteParserObj->parse( $text , $parser->getTitle() , $parser->getOptions(), false ) ;
86
 
        $ret = $ret->getText();
87
 
        $footnoteRecursionGuard = false;
88
 
 
89
 
        $footnoteNotes[$footnoteCount] = $ret;
90
 
 
91
 
        $ret = "<a href='#footnote{$footnoteCount}' name='footnoteback{$footnoteCount}'><sup>$footnoteCount</sup></a>" ;
92
 
        
93
 
        $footnoteCount++ ;
94
 
        if( $footnoteCount == 2 ) {
95
 
                global $wgHooks;
96
 
                $wgHooks['ParserBeforeTidy'][] = 'insert_endnotes' ;
97
 
        }
98
 
 
99
 
        return $ret ;
100
 
}
101