xref: /dokuwiki/inc/parser/xhtml.php (revision 64159a61e94d0ce680071c8890e144982c3a8cbe)
10cecf9d5Sandi<?php
2b625487dSandi/**
3b625487dSandi * Renderer for XHTML output
4b625487dSandi *
5b4f2363aSAndreas Gohr * This is DokuWiki's main renderer used to display page content in the wiki
6b4f2363aSAndreas Gohr *
7b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
8b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
93dd5c225SAndreas Gohr *
100cecf9d5Sandi */
11ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer {
123dd5c225SAndreas Gohr    /** @var array store the table of contents */
133dd5c225SAndreas Gohr    public $toc = array();
140cecf9d5Sandi
153dd5c225SAndreas Gohr    /** @var array A stack of section edit data */
163dd5c225SAndreas Gohr    protected $sectionedits = array();
174bde2196Slisps    var $date_at = '';    // link pages and media against this revision
18c5a8fd96SAndreas Gohr
193dd5c225SAndreas Gohr    /** @var int last section edit id, used by startSectionEdit */
203dd5c225SAndreas Gohr    protected $lastsecid = 0;
210cecf9d5Sandi
223dd5c225SAndreas Gohr    /** @var array the list of headers used to create unique link ids */
233dd5c225SAndreas Gohr    protected $headers = array();
243dd5c225SAndreas Gohr
2516ec3e37SAndreas Gohr    /** @var array a list of footnotes, list starts at 1! */
263dd5c225SAndreas Gohr    protected $footnotes = array();
277764a90aSandi
283dd5c225SAndreas Gohr    /** @var int current section level */
293dd5c225SAndreas Gohr    protected $lastlevel = 0;
303dd5c225SAndreas Gohr    /** @var array section node tracker */
313dd5c225SAndreas Gohr    protected $node = array(0, 0, 0, 0, 0);
323dd5c225SAndreas Gohr
333dd5c225SAndreas Gohr    /** @var string temporary $doc store */
343dd5c225SAndreas Gohr    protected $store = '';
353dd5c225SAndreas Gohr
363dd5c225SAndreas Gohr    /** @var array global counter, for table classes etc. */
373dd5c225SAndreas Gohr    protected $_counter = array(); //
383dd5c225SAndreas Gohr
393dd5c225SAndreas Gohr    /** @var int counts the code and file blocks, used to provide download links */
403dd5c225SAndreas Gohr    protected $_codeblock = 0;
413dd5c225SAndreas Gohr
423dd5c225SAndreas Gohr    /** @var array list of allowed URL schemes */
433dd5c225SAndreas Gohr    protected $schemes = null;
44b5742cedSPierre Spring
4590df9a4dSAdrian Lang    /**
4690df9a4dSAdrian Lang     * Register a new edit section range
4790df9a4dSAdrian Lang     *
4842ea7f44SGerrit Uitslag     * @param int    $start  The byte position for the edit start
49ec57f119SLarsDW223     * @param array  $data   Associative array with section data:
50ec57f119SLarsDW223     *                       Key 'name': the section name/title
51ec57f119SLarsDW223     *                       Key 'target': the target for the section edit,
52ec57f119SLarsDW223     *                                     e.g. 'section' or 'table'
53ec57f119SLarsDW223     *                       Key 'hid': header id
54ec57f119SLarsDW223     *                       Key 'codeblockOffset': actual code block index
55ec57f119SLarsDW223     *                       Key 'start': set in startSectionEdit(),
56ec57f119SLarsDW223     *                                    do not set yourself
57ec57f119SLarsDW223     *                       Key 'range': calculated from 'start' and
58ec57f119SLarsDW223     *                                    $key in finishSectionEdit(),
59ec57f119SLarsDW223     *                                    do not set yourself
6090df9a4dSAdrian Lang     * @return string  A marker class for the starting HTML element
6142ea7f44SGerrit Uitslag     *
6290df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
6390df9a4dSAdrian Lang     */
64ec57f119SLarsDW223    public function startSectionEdit($start, $data) {
65ec57f119SLarsDW223        if (!is_array($data)) {
66ac025fdfSAndreas Gohr            msg(
67ac025fdfSAndreas Gohr                sprintf(
68ac025fdfSAndreas Gohr                    'startSectionEdit: $data "%s" is NOT an array! One of your plugins needs an update.',
69ac025fdfSAndreas Gohr                    hsc((string) $data)
70ac025fdfSAndreas Gohr                ), -1
71ac025fdfSAndreas Gohr            );
72ac025fdfSAndreas Gohr
73ac025fdfSAndreas Gohr            // @deprecated 2018-04-14, backward compatibility
74ac025fdfSAndreas Gohr            $args = func_get_args();
75ac025fdfSAndreas Gohr            $data = array();
76ac025fdfSAndreas Gohr            if(isset($args[1])) $data['target'] = $args[1];
77ac025fdfSAndreas Gohr            if(isset($args[2])) $data['name'] = $args[2];
78ac025fdfSAndreas Gohr            if(isset($args[3])) $data['hid'] = $args[3];
79ec57f119SLarsDW223        }
80ec57f119SLarsDW223        $data['secid'] = ++$this->lastsecid;
81ec57f119SLarsDW223        $data['start'] = $start;
82ec57f119SLarsDW223        $this->sectionedits[] = $data;
83ec57f119SLarsDW223        return 'sectionedit'.$data['secid'];
8490df9a4dSAdrian Lang    }
8590df9a4dSAdrian Lang
8690df9a4dSAdrian Lang    /**
8790df9a4dSAdrian Lang     * Finish an edit section range
8890df9a4dSAdrian Lang     *
8942ea7f44SGerrit Uitslag     * @param int  $end     The byte position for the edit end; null for the rest of the page
9042ea7f44SGerrit Uitslag     *
9190df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
9290df9a4dSAdrian Lang     */
932571786cSLarsDW223    public function finishSectionEdit($end = null, $hid = null) {
94ec57f119SLarsDW223        $data = array_pop($this->sectionedits);
95ec57f119SLarsDW223        if(!is_null($end) && $end <= $data['start']) {
9600c13053SAdrian Lang            return;
9700c13053SAdrian Lang        }
982571786cSLarsDW223        if(!is_null($hid)) {
99ec57f119SLarsDW223            $data['hid'] .= $hid;
1002571786cSLarsDW223        }
101ec57f119SLarsDW223        $data['range'] = $data['start'].'-'.(is_null($end) ? '' : $end);
102ec57f119SLarsDW223        unset($data['start']);
103ada0d779SMichael Hamann        $this->doc .= '<!-- EDIT'.hsc(json_encode ($data)).' -->';
10490df9a4dSAdrian Lang    }
10590df9a4dSAdrian Lang
1063dd5c225SAndreas Gohr    /**
1073dd5c225SAndreas Gohr     * Returns the format produced by this renderer.
1083dd5c225SAndreas Gohr     *
1093dd5c225SAndreas Gohr     * @return string always 'xhtml'
1103dd5c225SAndreas Gohr     */
1115f70445dSAndreas Gohr    function getFormat() {
1125f70445dSAndreas Gohr        return 'xhtml';
1135f70445dSAndreas Gohr    }
1145f70445dSAndreas Gohr
1153dd5c225SAndreas Gohr    /**
1163dd5c225SAndreas Gohr     * Initialize the document
1173dd5c225SAndreas Gohr     */
1180cecf9d5Sandi    function document_start() {
119c5a8fd96SAndreas Gohr        //reset some internals
120c5a8fd96SAndreas Gohr        $this->toc     = array();
121c5a8fd96SAndreas Gohr        $this->headers = array();
1220cecf9d5Sandi    }
1230cecf9d5Sandi
1243dd5c225SAndreas Gohr    /**
1253dd5c225SAndreas Gohr     * Finalize the document
1263dd5c225SAndreas Gohr     */
1270cecf9d5Sandi    function document_end() {
12890df9a4dSAdrian Lang        // Finish open section edits.
12990df9a4dSAdrian Lang        while(count($this->sectionedits) > 0) {
130ec57f119SLarsDW223            if($this->sectionedits[count($this->sectionedits) - 1]['start'] <= 1) {
13190df9a4dSAdrian Lang                // If there is only one section, do not write a section edit
13290df9a4dSAdrian Lang                // marker.
13390df9a4dSAdrian Lang                array_pop($this->sectionedits);
13490df9a4dSAdrian Lang            } else {
135d9e36cbeSAdrian Lang                $this->finishSectionEdit();
13690df9a4dSAdrian Lang            }
13790df9a4dSAdrian Lang        }
13890df9a4dSAdrian Lang
1390cecf9d5Sandi        if(count($this->footnotes) > 0) {
140a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
141d74aace9Schris
14216ec3e37SAndreas Gohr            foreach($this->footnotes as $id => $footnote) {
143d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
144d74aace9Schris                if(substr($footnote, 0, 5) != "@@FNT") {
145d74aace9Schris
146d74aace9Schris                    // open the footnote and set the anchor and backlink
147d74aace9Schris                    $this->doc .= '<div class="fn">';
14816cc7ed7SAnika Henke                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">';
14929bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
150d74aace9Schris
151d74aace9Schris                    // get any other footnotes that use the same markup
152d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
153d74aace9Schris
154d74aace9Schris                    if(count($alt)) {
155d74aace9Schris                        foreach($alt as $ref) {
156d74aace9Schris                            // set anchor and backlink for the other footnotes
15716ec3e37SAndreas Gohr                            $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">';
15816ec3e37SAndreas Gohr                            $this->doc .= ($ref).')</a></sup> '.DOKU_LF;
159d74aace9Schris                        }
160d74aace9Schris                    }
161d74aace9Schris
162d74aace9Schris                    // add footnote markup and close this footnote
163694afa06SAnika Henke                    $this->doc .= '<div class="content">'.$footnote.'</div>';
164d74aace9Schris                    $this->doc .= '</div>'.DOKU_LF;
165d74aace9Schris                }
1660cecf9d5Sandi            }
167a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
1680cecf9d5Sandi        }
169c5a8fd96SAndreas Gohr
170b8595a66SAndreas Gohr        // Prepare the TOC
171851f2e89SAnika Henke        global $conf;
172*64159a61SAndreas Gohr        if(
173*64159a61SAndreas Gohr            $this->info['toc'] &&
174*64159a61SAndreas Gohr            is_array($this->toc) &&
175*64159a61SAndreas Gohr            $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']
176*64159a61SAndreas Gohr        ) {
177b8595a66SAndreas Gohr            global $TOC;
178b8595a66SAndreas Gohr            $TOC = $this->toc;
1790cecf9d5Sandi        }
1803e55d035SAndreas Gohr
1813e55d035SAndreas Gohr        // make sure there are no empty paragraphs
18227918226Schris        $this->doc = preg_replace('#<p>\s*</p>#', '', $this->doc);
183e41c4da9SAndreas Gohr    }
1840cecf9d5Sandi
1853dd5c225SAndreas Gohr    /**
1863dd5c225SAndreas Gohr     * Add an item to the TOC
1873dd5c225SAndreas Gohr     *
1883dd5c225SAndreas Gohr     * @param string $id       the hash link
1893dd5c225SAndreas Gohr     * @param string $text     the text to display
1903dd5c225SAndreas Gohr     * @param int    $level    the nesting level
1913dd5c225SAndreas Gohr     */
192e7856beaSchris    function toc_additem($id, $text, $level) {
193af587fa8Sandi        global $conf;
194af587fa8Sandi
195c5a8fd96SAndreas Gohr        //handle TOC
196c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) {
1977d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level - $conf['toptoclevel'] + 1);
198c5a8fd96SAndreas Gohr        }
199e7856beaSchris    }
200e7856beaSchris
2013dd5c225SAndreas Gohr    /**
2023dd5c225SAndreas Gohr     * Render a heading
2033dd5c225SAndreas Gohr     *
2043dd5c225SAndreas Gohr     * @param string $text  the text to display
2053dd5c225SAndreas Gohr     * @param int    $level header level
2063dd5c225SAndreas Gohr     * @param int    $pos   byte position in the original source
2073dd5c225SAndreas Gohr     */
208e7856beaSchris    function header($text, $level, $pos) {
20990df9a4dSAdrian Lang        global $conf;
21090df9a4dSAdrian Lang
211f515db7fSAndreas Gohr        if(blank($text)) return; //skip empty headlines
212e7856beaSchris
213e7856beaSchris        $hid = $this->_headerToLink($text, true);
214e7856beaSchris
215e7856beaSchris        //only add items within configured levels
216e7856beaSchris        $this->toc_additem($hid, $text, $level);
217c5a8fd96SAndreas Gohr
21891459163SAnika Henke        // adjust $node to reflect hierarchy of levels
21991459163SAnika Henke        $this->node[$level - 1]++;
22091459163SAnika Henke        if($level < $this->lastlevel) {
22191459163SAnika Henke            for($i = 0; $i < $this->lastlevel - $level; $i++) {
22291459163SAnika Henke                $this->node[$this->lastlevel - $i - 1] = 0;
22391459163SAnika Henke            }
22491459163SAnika Henke        }
22591459163SAnika Henke        $this->lastlevel = $level;
22691459163SAnika Henke
22790df9a4dSAdrian Lang        if($level <= $conf['maxseclevel'] &&
22890df9a4dSAdrian Lang            count($this->sectionedits) > 0 &&
229ec57f119SLarsDW223            $this->sectionedits[count($this->sectionedits) - 1]['target'] === 'section'
2303dd5c225SAndreas Gohr        ) {
2316c1f778cSAdrian Lang            $this->finishSectionEdit($pos - 1);
23290df9a4dSAdrian Lang        }
23390df9a4dSAdrian Lang
234c5a8fd96SAndreas Gohr        // write the header
23590df9a4dSAdrian Lang        $this->doc .= DOKU_LF.'<h'.$level;
23690df9a4dSAdrian Lang        if($level <= $conf['maxseclevel']) {
237ec57f119SLarsDW223            $data = array();
238ec57f119SLarsDW223            $data['target'] = 'section';
239ec57f119SLarsDW223            $data['name'] = $text;
240ec57f119SLarsDW223            $data['hid'] = $hid;
241ec57f119SLarsDW223            $data['codeblockOffset'] = $this->_codeblock;
242ec57f119SLarsDW223            $this->doc .= ' class="'.$this->startSectionEdit($pos, $data).'"';
24390df9a4dSAdrian Lang        }
24416cc7ed7SAnika Henke        $this->doc .= ' id="'.$hid.'">';
245a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
24616cc7ed7SAnika Henke        $this->doc .= "</h$level>".DOKU_LF;
2470cecf9d5Sandi    }
2480cecf9d5Sandi
2493dd5c225SAndreas Gohr    /**
2503dd5c225SAndreas Gohr     * Open a new section
2513dd5c225SAndreas Gohr     *
2523dd5c225SAndreas Gohr     * @param int $level section level (as determined by the previous header)
2533dd5c225SAndreas Gohr     */
2540cecf9d5Sandi    function section_open($level) {
2559864e7b1SAdrian Lang        $this->doc .= '<div class="level'.$level.'">'.DOKU_LF;
2560cecf9d5Sandi    }
2570cecf9d5Sandi
2583dd5c225SAndreas Gohr    /**
2593dd5c225SAndreas Gohr     * Close the current section
2603dd5c225SAndreas Gohr     */
2610cecf9d5Sandi    function section_close() {
262a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
2630cecf9d5Sandi    }
2640cecf9d5Sandi
2653dd5c225SAndreas Gohr    /**
2663dd5c225SAndreas Gohr     * Render plain text data
2673dd5c225SAndreas Gohr     *
2683dd5c225SAndreas Gohr     * @param $text
2693dd5c225SAndreas Gohr     */
2700cecf9d5Sandi    function cdata($text) {
271a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
2720cecf9d5Sandi    }
2730cecf9d5Sandi
2743dd5c225SAndreas Gohr    /**
2753dd5c225SAndreas Gohr     * Open a paragraph
2763dd5c225SAndreas Gohr     */
2770cecf9d5Sandi    function p_open() {
27859869a4bSAnika Henke        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
2790cecf9d5Sandi    }
2800cecf9d5Sandi
2813dd5c225SAndreas Gohr    /**
2823dd5c225SAndreas Gohr     * Close a paragraph
2833dd5c225SAndreas Gohr     */
2840cecf9d5Sandi    function p_close() {
28559869a4bSAnika Henke        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
2860cecf9d5Sandi    }
2870cecf9d5Sandi
2883dd5c225SAndreas Gohr    /**
2893dd5c225SAndreas Gohr     * Create a line break
2903dd5c225SAndreas Gohr     */
2910cecf9d5Sandi    function linebreak() {
292a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
2930cecf9d5Sandi    }
2940cecf9d5Sandi
2953dd5c225SAndreas Gohr    /**
2963dd5c225SAndreas Gohr     * Create a horizontal line
2973dd5c225SAndreas Gohr     */
2980cecf9d5Sandi    function hr() {
2994beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
3000cecf9d5Sandi    }
3010cecf9d5Sandi
3023dd5c225SAndreas Gohr    /**
3033dd5c225SAndreas Gohr     * Start strong (bold) formatting
3043dd5c225SAndreas Gohr     */
3050cecf9d5Sandi    function strong_open() {
306a2d649c4Sandi        $this->doc .= '<strong>';
3070cecf9d5Sandi    }
3080cecf9d5Sandi
3093dd5c225SAndreas Gohr    /**
3103dd5c225SAndreas Gohr     * Stop strong (bold) formatting
3113dd5c225SAndreas Gohr     */
3120cecf9d5Sandi    function strong_close() {
313a2d649c4Sandi        $this->doc .= '</strong>';
3140cecf9d5Sandi    }
3150cecf9d5Sandi
3163dd5c225SAndreas Gohr    /**
3173dd5c225SAndreas Gohr     * Start emphasis (italics) formatting
3183dd5c225SAndreas Gohr     */
3190cecf9d5Sandi    function emphasis_open() {
320a2d649c4Sandi        $this->doc .= '<em>';
3210cecf9d5Sandi    }
3220cecf9d5Sandi
3233dd5c225SAndreas Gohr    /**
3243dd5c225SAndreas Gohr     * Stop emphasis (italics) formatting
3253dd5c225SAndreas Gohr     */
3260cecf9d5Sandi    function emphasis_close() {
327a2d649c4Sandi        $this->doc .= '</em>';
3280cecf9d5Sandi    }
3290cecf9d5Sandi
3303dd5c225SAndreas Gohr    /**
3313dd5c225SAndreas Gohr     * Start underline formatting
3323dd5c225SAndreas Gohr     */
3330cecf9d5Sandi    function underline_open() {
33402e51121SAnika Henke        $this->doc .= '<em class="u">';
3350cecf9d5Sandi    }
3360cecf9d5Sandi
3373dd5c225SAndreas Gohr    /**
3383dd5c225SAndreas Gohr     * Stop underline formatting
3393dd5c225SAndreas Gohr     */
3400cecf9d5Sandi    function underline_close() {
34102e51121SAnika Henke        $this->doc .= '</em>';
3420cecf9d5Sandi    }
3430cecf9d5Sandi
3443dd5c225SAndreas Gohr    /**
3453dd5c225SAndreas Gohr     * Start monospace formatting
3463dd5c225SAndreas Gohr     */
3470cecf9d5Sandi    function monospace_open() {
348a2d649c4Sandi        $this->doc .= '<code>';
3490cecf9d5Sandi    }
3500cecf9d5Sandi
3513dd5c225SAndreas Gohr    /**
3523dd5c225SAndreas Gohr     * Stop monospace formatting
3533dd5c225SAndreas Gohr     */
3540cecf9d5Sandi    function monospace_close() {
355a2d649c4Sandi        $this->doc .= '</code>';
3560cecf9d5Sandi    }
3570cecf9d5Sandi
3583dd5c225SAndreas Gohr    /**
3593dd5c225SAndreas Gohr     * Start a subscript
3603dd5c225SAndreas Gohr     */
3610cecf9d5Sandi    function subscript_open() {
362a2d649c4Sandi        $this->doc .= '<sub>';
3630cecf9d5Sandi    }
3640cecf9d5Sandi
3653dd5c225SAndreas Gohr    /**
3663dd5c225SAndreas Gohr     * Stop a subscript
3673dd5c225SAndreas Gohr     */
3680cecf9d5Sandi    function subscript_close() {
369a2d649c4Sandi        $this->doc .= '</sub>';
3700cecf9d5Sandi    }
3710cecf9d5Sandi
3723dd5c225SAndreas Gohr    /**
3733dd5c225SAndreas Gohr     * Start a superscript
3743dd5c225SAndreas Gohr     */
3750cecf9d5Sandi    function superscript_open() {
376a2d649c4Sandi        $this->doc .= '<sup>';
3770cecf9d5Sandi    }
3780cecf9d5Sandi
3793dd5c225SAndreas Gohr    /**
3803dd5c225SAndreas Gohr     * Stop a superscript
3813dd5c225SAndreas Gohr     */
3820cecf9d5Sandi    function superscript_close() {
383a2d649c4Sandi        $this->doc .= '</sup>';
3840cecf9d5Sandi    }
3850cecf9d5Sandi
3863dd5c225SAndreas Gohr    /**
3873dd5c225SAndreas Gohr     * Start deleted (strike-through) formatting
3883dd5c225SAndreas Gohr     */
3890cecf9d5Sandi    function deleted_open() {
390a2d649c4Sandi        $this->doc .= '<del>';
3910cecf9d5Sandi    }
3920cecf9d5Sandi
3933dd5c225SAndreas Gohr    /**
3943dd5c225SAndreas Gohr     * Stop deleted (strike-through) formatting
3953dd5c225SAndreas Gohr     */
3960cecf9d5Sandi    function deleted_close() {
397a2d649c4Sandi        $this->doc .= '</del>';
3980cecf9d5Sandi    }
3990cecf9d5Sandi
4003fd0b676Sandi    /**
4013fd0b676Sandi     * Callback for footnote start syntax
4023fd0b676Sandi     *
4033fd0b676Sandi     * All following content will go to the footnote instead of
404d74aace9Schris     * the document. To achieve this the previous rendered content
4053fd0b676Sandi     * is moved to $store and $doc is cleared
4063fd0b676Sandi     *
4073fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
4083fd0b676Sandi     */
4090cecf9d5Sandi    function footnote_open() {
4107764a90aSandi
4117764a90aSandi        // move current content to store and record footnote
4127764a90aSandi        $this->store = $this->doc;
4137764a90aSandi        $this->doc   = '';
4140cecf9d5Sandi    }
4150cecf9d5Sandi
4163fd0b676Sandi    /**
4173fd0b676Sandi     * Callback for footnote end syntax
4183fd0b676Sandi     *
4193fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
4203fd0b676Sandi     * content is restored from $store again
4213fd0b676Sandi     *
4223fd0b676Sandi     * @author Andreas Gohr
4233fd0b676Sandi     */
4240cecf9d5Sandi    function footnote_close() {
42516ec3e37SAndreas Gohr        /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */
42616ec3e37SAndreas Gohr        static $fnid = 0;
42716ec3e37SAndreas Gohr        // assign new footnote id (we start at 1)
42816ec3e37SAndreas Gohr        $fnid++;
4297764a90aSandi
430d74aace9Schris        // recover footnote into the stack and restore old content
431d74aace9Schris        $footnote    = $this->doc;
4327764a90aSandi        $this->doc   = $this->store;
4337764a90aSandi        $this->store = '';
434d74aace9Schris
435d74aace9Schris        // check to see if this footnote has been seen before
436d74aace9Schris        $i = array_search($footnote, $this->footnotes);
437d74aace9Schris
438d74aace9Schris        if($i === false) {
439d74aace9Schris            // its a new footnote, add it to the $footnotes array
44016ec3e37SAndreas Gohr            $this->footnotes[$fnid] = $footnote;
441d74aace9Schris        } else {
44216ec3e37SAndreas Gohr            // seen this one before, save a placeholder
44316ec3e37SAndreas Gohr            $this->footnotes[$fnid] = "@@FNT".($i);
444d74aace9Schris        }
445d74aace9Schris
4466b379cbfSAndreas Gohr        // output the footnote reference and link
44716ec3e37SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>';
4480cecf9d5Sandi    }
4490cecf9d5Sandi
4503dd5c225SAndreas Gohr    /**
4513dd5c225SAndreas Gohr     * Open an unordered list
4520c4c0281SGerrit Uitslag     *
4537d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
4543dd5c225SAndreas Gohr     */
4550c4c0281SGerrit Uitslag    function listu_open($classes = null) {
4560c4c0281SGerrit Uitslag        $class = '';
4570c4c0281SGerrit Uitslag        if($classes !== null) {
4582e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
4590c4c0281SGerrit Uitslag            $class = " class=\"$classes\"";
4600c4c0281SGerrit Uitslag        }
4610c4c0281SGerrit Uitslag        $this->doc .= "<ul$class>".DOKU_LF;
4620cecf9d5Sandi    }
4630cecf9d5Sandi
4643dd5c225SAndreas Gohr    /**
4653dd5c225SAndreas Gohr     * Close an unordered list
4663dd5c225SAndreas Gohr     */
4670cecf9d5Sandi    function listu_close() {
468a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
4690cecf9d5Sandi    }
4700cecf9d5Sandi
4713dd5c225SAndreas Gohr    /**
4723dd5c225SAndreas Gohr     * Open an ordered list
4730c4c0281SGerrit Uitslag     *
4747d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
4753dd5c225SAndreas Gohr     */
4760c4c0281SGerrit Uitslag    function listo_open($classes = null) {
4770c4c0281SGerrit Uitslag        $class = '';
4780c4c0281SGerrit Uitslag        if($classes !== null) {
4792e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
4800c4c0281SGerrit Uitslag            $class = " class=\"$classes\"";
4810c4c0281SGerrit Uitslag        }
4820c4c0281SGerrit Uitslag        $this->doc .= "<ol$class>".DOKU_LF;
4830cecf9d5Sandi    }
4840cecf9d5Sandi
4853dd5c225SAndreas Gohr    /**
4863dd5c225SAndreas Gohr     * Close an ordered list
4873dd5c225SAndreas Gohr     */
4880cecf9d5Sandi    function listo_close() {
489a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
4900cecf9d5Sandi    }
4910cecf9d5Sandi
4923dd5c225SAndreas Gohr    /**
4933dd5c225SAndreas Gohr     * Open a list item
4943dd5c225SAndreas Gohr     *
4953dd5c225SAndreas Gohr     * @param int $level the nesting level
496e3a24861SChristopher Smith     * @param bool $node true when a node; false when a leaf
4973dd5c225SAndreas Gohr     */
498e3a24861SChristopher Smith    function listitem_open($level, $node=false) {
499e3a24861SChristopher Smith        $branching = $node ? ' node' : '';
500e3a24861SChristopher Smith        $this->doc .= '<li class="level'.$level.$branching.'">';
5010cecf9d5Sandi    }
5020cecf9d5Sandi
5033dd5c225SAndreas Gohr    /**
5043dd5c225SAndreas Gohr     * Close a list item
5053dd5c225SAndreas Gohr     */
5060cecf9d5Sandi    function listitem_close() {
507a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
5080cecf9d5Sandi    }
5090cecf9d5Sandi
5103dd5c225SAndreas Gohr    /**
5113dd5c225SAndreas Gohr     * Start the content of a list item
5123dd5c225SAndreas Gohr     */
5130cecf9d5Sandi    function listcontent_open() {
51490db23d7Schris        $this->doc .= '<div class="li">';
5150cecf9d5Sandi    }
5160cecf9d5Sandi
5173dd5c225SAndreas Gohr    /**
5183dd5c225SAndreas Gohr     * Stop the content of a list item
5193dd5c225SAndreas Gohr     */
5200cecf9d5Sandi    function listcontent_close() {
52159869a4bSAnika Henke        $this->doc .= '</div>'.DOKU_LF;
5220cecf9d5Sandi    }
5230cecf9d5Sandi
5243dd5c225SAndreas Gohr    /**
5253dd5c225SAndreas Gohr     * Output unformatted $text
5263dd5c225SAndreas Gohr     *
5273dd5c225SAndreas Gohr     * Defaults to $this->cdata()
5283dd5c225SAndreas Gohr     *
5293dd5c225SAndreas Gohr     * @param string $text
5303dd5c225SAndreas Gohr     */
5310cecf9d5Sandi    function unformatted($text) {
532a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
5330cecf9d5Sandi    }
5340cecf9d5Sandi
5350cecf9d5Sandi    /**
5363fd0b676Sandi     * Execute PHP code if allowed
5373fd0b676Sandi     *
538d9764001SMichael Hamann     * @param  string $text      PHP code that is either executed or printed
5395d568b99SChris Smith     * @param  string $wrapper   html element to wrap result if $conf['phpok'] is okff
5405d568b99SChris Smith     *
5413fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
5420cecf9d5Sandi     */
5435d568b99SChris Smith    function php($text, $wrapper = 'code') {
54435a56260SChris Smith        global $conf;
54535a56260SChris Smith
546d86d5af0SChris Smith        if($conf['phpok']) {
547bad0b545Sandi            ob_start();
5484de671bcSandi            eval($text);
5493fd0b676Sandi            $this->doc .= ob_get_contents();
550bad0b545Sandi            ob_end_clean();
551d86d5af0SChris Smith        } else {
5525d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
553d86d5af0SChris Smith        }
5540cecf9d5Sandi    }
5550cecf9d5Sandi
5563dd5c225SAndreas Gohr    /**
5573dd5c225SAndreas Gohr     * Output block level PHP code
5583dd5c225SAndreas Gohr     *
5593dd5c225SAndreas Gohr     * If $conf['phpok'] is true this should evaluate the given code and append the result
5603dd5c225SAndreas Gohr     * to $doc
5613dd5c225SAndreas Gohr     *
5623dd5c225SAndreas Gohr     * @param string $text The PHP code
5633dd5c225SAndreas Gohr     */
56407f89c3cSAnika Henke    function phpblock($text) {
5655d568b99SChris Smith        $this->php($text, 'pre');
56607f89c3cSAnika Henke    }
56707f89c3cSAnika Henke
5680cecf9d5Sandi    /**
5693fd0b676Sandi     * Insert HTML if allowed
5703fd0b676Sandi     *
571d9764001SMichael Hamann     * @param  string $text      html text
5725d568b99SChris Smith     * @param  string $wrapper   html element to wrap result if $conf['htmlok'] is okff
5735d568b99SChris Smith     *
5743fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
5750cecf9d5Sandi     */
5765d568b99SChris Smith    function html($text, $wrapper = 'code') {
57735a56260SChris Smith        global $conf;
57835a56260SChris Smith
579d86d5af0SChris Smith        if($conf['htmlok']) {
580a2d649c4Sandi            $this->doc .= $text;
581d86d5af0SChris Smith        } else {
5825d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
583d86d5af0SChris Smith        }
5844de671bcSandi    }
5850cecf9d5Sandi
5863dd5c225SAndreas Gohr    /**
5873dd5c225SAndreas Gohr     * Output raw block-level HTML
5883dd5c225SAndreas Gohr     *
5893dd5c225SAndreas Gohr     * If $conf['htmlok'] is true this should add the code as is to $doc
5903dd5c225SAndreas Gohr     *
5913dd5c225SAndreas Gohr     * @param string $text The HTML
5923dd5c225SAndreas Gohr     */
59307f89c3cSAnika Henke    function htmlblock($text) {
5945d568b99SChris Smith        $this->html($text, 'pre');
59507f89c3cSAnika Henke    }
59607f89c3cSAnika Henke
5973dd5c225SAndreas Gohr    /**
5983dd5c225SAndreas Gohr     * Start a block quote
5993dd5c225SAndreas Gohr     */
6000cecf9d5Sandi    function quote_open() {
60196331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
6020cecf9d5Sandi    }
6030cecf9d5Sandi
6043dd5c225SAndreas Gohr    /**
6053dd5c225SAndreas Gohr     * Stop a block quote
6063dd5c225SAndreas Gohr     */
6070cecf9d5Sandi    function quote_close() {
60896331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
6090cecf9d5Sandi    }
6100cecf9d5Sandi
6113dd5c225SAndreas Gohr    /**
6123dd5c225SAndreas Gohr     * Output preformatted text
6133dd5c225SAndreas Gohr     *
6143dd5c225SAndreas Gohr     * @param string $text
6153dd5c225SAndreas Gohr     */
6163d491f75SAndreas Gohr    function preformatted($text) {
617c9250713SAnika Henke        $this->doc .= '<pre class="code">'.trim($this->_xmlEntities($text), "\n\r").'</pre>'.DOKU_LF;
6183d491f75SAndreas Gohr    }
6193d491f75SAndreas Gohr
6203dd5c225SAndreas Gohr    /**
6213dd5c225SAndreas Gohr     * Display text as file content, optionally syntax highlighted
6223dd5c225SAndreas Gohr     *
6233dd5c225SAndreas Gohr     * @param string $text     text to show
6243dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6253dd5c225SAndreas Gohr     * @param string $filename file path label
626e2d88156SLarsDW223     * @param array  $options  assoziative array with additional geshi options
6273dd5c225SAndreas Gohr     */
628e2d88156SLarsDW223    function file($text, $language = null, $filename = null, $options=null) {
629e2d88156SLarsDW223        $this->_highlight('file', $text, $language, $filename, $options);
6303d491f75SAndreas Gohr    }
6313d491f75SAndreas Gohr
6323dd5c225SAndreas Gohr    /**
6333dd5c225SAndreas Gohr     * Display text as code content, optionally syntax highlighted
6343dd5c225SAndreas Gohr     *
6353dd5c225SAndreas Gohr     * @param string $text     text to show
6363dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6373dd5c225SAndreas Gohr     * @param string $filename file path label
638e2d88156SLarsDW223     * @param array  $options  assoziative array with additional geshi options
6393dd5c225SAndreas Gohr     */
640e2d88156SLarsDW223    function code($text, $language = null, $filename = null, $options=null) {
641e2d88156SLarsDW223        $this->_highlight('code', $text, $language, $filename, $options);
6423d491f75SAndreas Gohr    }
6433d491f75SAndreas Gohr
6440cecf9d5Sandi    /**
6453d491f75SAndreas Gohr     * Use GeSHi to highlight language syntax in code and file blocks
6463fd0b676Sandi     *
6473fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
6483dd5c225SAndreas Gohr     * @param string $type     code|file
6493dd5c225SAndreas Gohr     * @param string $text     text to show
6503dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6513dd5c225SAndreas Gohr     * @param string $filename file path label
652e2d88156SLarsDW223     * @param array  $options  assoziative array with additional geshi options
6530cecf9d5Sandi     */
654e2d88156SLarsDW223    function _highlight($type, $text, $language = null, $filename = null, $options = null) {
6553d491f75SAndreas Gohr        global $ID;
6563d491f75SAndreas Gohr        global $lang;
657ec57f119SLarsDW223        global $INPUT;
6583d491f75SAndreas Gohr
65956bd9509SPhy        $language = preg_replace(PREG_PATTERN_VALID_LANGUAGE, '', $language);
66056bd9509SPhy
6613d491f75SAndreas Gohr        if($filename) {
662190c56e8SAndreas Gohr            // add icon
66327bf7924STom N Harris            list($ext) = mimetype($filename, false);
664190c56e8SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
665190c56e8SAndreas Gohr            $class = 'mediafile mf_'.$class;
666190c56e8SAndreas Gohr
667ec57f119SLarsDW223            $offset = 0;
668ec57f119SLarsDW223            if ($INPUT->has('codeblockOffset')) {
669ec57f119SLarsDW223                $offset = $INPUT->str('codeblockOffset');
670ec57f119SLarsDW223            }
6713d491f75SAndreas Gohr            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
672*64159a61SAndreas Gohr            $this->doc .= '<dt><a href="' .
673*64159a61SAndreas Gohr                exportlink(
674*64159a61SAndreas Gohr                    $ID,
675*64159a61SAndreas Gohr                    'code',
676*64159a61SAndreas Gohr                    array('codeblock' => $offset + $this->_codeblock)
677*64159a61SAndreas Gohr                ) . '" title="' . $lang['download'] . '" class="' . $class . '">';
6783d491f75SAndreas Gohr            $this->doc .= hsc($filename);
6793d491f75SAndreas Gohr            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
6803d491f75SAndreas Gohr        }
6810cecf9d5Sandi
682d43aac1cSGina Haeussge        if($text{0} == "\n") {
683d43aac1cSGina Haeussge            $text = substr($text, 1);
684d43aac1cSGina Haeussge        }
685d43aac1cSGina Haeussge        if(substr($text, -1) == "\n") {
686d43aac1cSGina Haeussge            $text = substr($text, 0, -1);
687d43aac1cSGina Haeussge        }
688d43aac1cSGina Haeussge
689a056e285SPhy        if(empty($language)) { // empty is faster than is_null and can prevent '' string
6903d491f75SAndreas Gohr            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
6910cecf9d5Sandi        } else {
6923d491f75SAndreas Gohr            $class = 'code'; //we always need the code class to make the syntax highlighting apply
6933d491f75SAndreas Gohr            if($type != 'code') $class .= ' '.$type;
6943d491f75SAndreas Gohr
695*64159a61SAndreas Gohr            $this->doc .= "<pre class=\"$class $language\">" .
696*64159a61SAndreas Gohr                p_xhtml_cached_geshi($text, $language, '', $options) .
697*64159a61SAndreas Gohr                '</pre>' . DOKU_LF;
6980cecf9d5Sandi        }
6993d491f75SAndreas Gohr
7003d491f75SAndreas Gohr        if($filename) {
7013d491f75SAndreas Gohr            $this->doc .= '</dd></dl>'.DOKU_LF;
7023d491f75SAndreas Gohr        }
7033d491f75SAndreas Gohr
7043d491f75SAndreas Gohr        $this->_codeblock++;
7050cecf9d5Sandi    }
7060cecf9d5Sandi
7073dd5c225SAndreas Gohr    /**
7083dd5c225SAndreas Gohr     * Format an acronym
7093dd5c225SAndreas Gohr     *
7103dd5c225SAndreas Gohr     * Uses $this->acronyms
7113dd5c225SAndreas Gohr     *
7123dd5c225SAndreas Gohr     * @param string $acronym
7133dd5c225SAndreas Gohr     */
7140cecf9d5Sandi    function acronym($acronym) {
7150cecf9d5Sandi
7160cecf9d5Sandi        if(array_key_exists($acronym, $this->acronyms)) {
7170cecf9d5Sandi
718433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
7190cecf9d5Sandi
720940db3a3SAnika Henke            $this->doc .= '<abbr title="'.$title
721940db3a3SAnika Henke                .'">'.$this->_xmlEntities($acronym).'</abbr>';
7220cecf9d5Sandi
7230cecf9d5Sandi        } else {
724a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
7250cecf9d5Sandi        }
7260cecf9d5Sandi    }
7270cecf9d5Sandi
7283dd5c225SAndreas Gohr    /**
7293dd5c225SAndreas Gohr     * Format a smiley
7303dd5c225SAndreas Gohr     *
7313dd5c225SAndreas Gohr     * Uses $this->smiley
7323dd5c225SAndreas Gohr     *
7333dd5c225SAndreas Gohr     * @param string $smiley
7343dd5c225SAndreas Gohr     */
7350cecf9d5Sandi    function smiley($smiley) {
7360cecf9d5Sandi        if(array_key_exists($smiley, $this->smileys)) {
737f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
7388e38227fSAnika Henke                '" class="icon" alt="'.
739433bef32Sandi                $this->_xmlEntities($smiley).'" />';
7400cecf9d5Sandi        } else {
741a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
7420cecf9d5Sandi        }
7430cecf9d5Sandi    }
7440cecf9d5Sandi
7453dd5c225SAndreas Gohr    /**
7463dd5c225SAndreas Gohr     * Format an entity
7473dd5c225SAndreas Gohr     *
7483dd5c225SAndreas Gohr     * Entities are basically small text replacements
7493dd5c225SAndreas Gohr     *
7503dd5c225SAndreas Gohr     * Uses $this->entities
7513dd5c225SAndreas Gohr     *
7523dd5c225SAndreas Gohr     * @param string $entity
7534de671bcSandi     */
7540cecf9d5Sandi    function entity($entity) {
7550cecf9d5Sandi        if(array_key_exists($entity, $this->entities)) {
756a2d649c4Sandi            $this->doc .= $this->entities[$entity];
7570cecf9d5Sandi        } else {
758a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
7590cecf9d5Sandi        }
7600cecf9d5Sandi    }
7610cecf9d5Sandi
7623dd5c225SAndreas Gohr    /**
7633dd5c225SAndreas Gohr     * Typographically format a multiply sign
7643dd5c225SAndreas Gohr     *
7653dd5c225SAndreas Gohr     * Example: ($x=640, $y=480) should result in "640×480"
7663dd5c225SAndreas Gohr     *
7673dd5c225SAndreas Gohr     * @param string|int $x first value
7683dd5c225SAndreas Gohr     * @param string|int $y second value
7693dd5c225SAndreas Gohr     */
7700cecf9d5Sandi    function multiplyentity($x, $y) {
771a2d649c4Sandi        $this->doc .= "$x&times;$y";
7720cecf9d5Sandi    }
7730cecf9d5Sandi
7743dd5c225SAndreas Gohr    /**
7753dd5c225SAndreas Gohr     * Render an opening single quote char (language specific)
7763dd5c225SAndreas Gohr     */
7770cecf9d5Sandi    function singlequoteopening() {
77871b40da2SAnika Henke        global $lang;
77971b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
7800cecf9d5Sandi    }
7810cecf9d5Sandi
7823dd5c225SAndreas Gohr    /**
7833dd5c225SAndreas Gohr     * Render a closing single quote char (language specific)
7843dd5c225SAndreas Gohr     */
7850cecf9d5Sandi    function singlequoteclosing() {
78671b40da2SAnika Henke        global $lang;
78771b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
7880cecf9d5Sandi    }
7890cecf9d5Sandi
7903dd5c225SAndreas Gohr    /**
7913dd5c225SAndreas Gohr     * Render an apostrophe char (language specific)
7923dd5c225SAndreas Gohr     */
79357d757d1SAndreas Gohr    function apostrophe() {
79457d757d1SAndreas Gohr        global $lang;
795a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
79657d757d1SAndreas Gohr    }
79757d757d1SAndreas Gohr
7983dd5c225SAndreas Gohr    /**
7993dd5c225SAndreas Gohr     * Render an opening double quote char (language specific)
8003dd5c225SAndreas Gohr     */
8010cecf9d5Sandi    function doublequoteopening() {
80271b40da2SAnika Henke        global $lang;
80371b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
8040cecf9d5Sandi    }
8050cecf9d5Sandi
8063dd5c225SAndreas Gohr    /**
8073dd5c225SAndreas Gohr     * Render an closinging double quote char (language specific)
8083dd5c225SAndreas Gohr     */
8090cecf9d5Sandi    function doublequoteclosing() {
81071b40da2SAnika Henke        global $lang;
81171b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
8120cecf9d5Sandi    }
8130cecf9d5Sandi
8140cecf9d5Sandi    /**
8153dd5c225SAndreas Gohr     * Render a CamelCase link
8163dd5c225SAndreas Gohr     *
8173dd5c225SAndreas Gohr     * @param string $link       The link name
818122f2d46SAndreas Böhler     * @param bool   $returnonly whether to return html or write to doc attribute
8190c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
8200c4c0281SGerrit Uitslag     *
8213dd5c225SAndreas Gohr     * @see http://en.wikipedia.org/wiki/CamelCase
8220cecf9d5Sandi     */
823122f2d46SAndreas Böhler    function camelcaselink($link, $returnonly = false) {
824122f2d46SAndreas Böhler        if($returnonly) {
825122f2d46SAndreas Böhler          return $this->internallink($link, $link, null, true);
826122f2d46SAndreas Böhler        } else {
82711d0aa47Sandi          $this->internallink($link, $link);
8280cecf9d5Sandi        }
829122f2d46SAndreas Böhler    }
8300cecf9d5Sandi
8313dd5c225SAndreas Gohr    /**
8323dd5c225SAndreas Gohr     * Render a page local link
8333dd5c225SAndreas Gohr     *
8343dd5c225SAndreas Gohr     * @param string $hash       hash link identifier
8353dd5c225SAndreas Gohr     * @param string $name       name for the link
836122f2d46SAndreas Böhler     * @param bool   $returnonly whether to return html or write to doc attribute
8370c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
8383dd5c225SAndreas Gohr     */
839122f2d46SAndreas Böhler    function locallink($hash, $name = null, $returnonly = false) {
8400b7c14c2Sandi        global $ID;
8410b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
8420b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
843e260f93bSAnika Henke        $title = $ID.' ↵';
844122f2d46SAndreas Böhler
845122f2d46SAndreas Böhler        $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
846122f2d46SAndreas Böhler        $doc .= $name;
847122f2d46SAndreas Böhler        $doc .= '</a>';
848122f2d46SAndreas Böhler
849122f2d46SAndreas Böhler        if($returnonly) {
850122f2d46SAndreas Böhler          return $doc;
851122f2d46SAndreas Böhler        } else {
852122f2d46SAndreas Böhler          $this->doc .= $doc;
853122f2d46SAndreas Böhler        }
8540b7c14c2Sandi    }
8550b7c14c2Sandi
856cffcc403Sandi    /**
8573fd0b676Sandi     * Render an internal Wiki Link
8583fd0b676Sandi     *
859fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
860cffcc403Sandi     * elsewhere - no need to implement them in other renderers
8613fd0b676Sandi     *
8623dd5c225SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
863f23eef27SGerrit Uitslag     * @param string      $id         pageid
864f23eef27SGerrit Uitslag     * @param string|null $name       link name
865f23eef27SGerrit Uitslag     * @param string|null $search     adds search url param
866f23eef27SGerrit Uitslag     * @param bool        $returnonly whether to return html or write to doc attribute
867f23eef27SGerrit Uitslag     * @param string      $linktype   type to set use of headings
868f23eef27SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
869cffcc403Sandi     */
8700ea51e63SMatt Perry    function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
871ba11bd29Sandi        global $conf;
87237e34a5eSandi        global $ID;
873c4dda6afSAnika Henke        global $INFO;
87444653a53SAdrian Lang
8753d5e07d9SAdrian Lang        $params = '';
8763d5e07d9SAdrian Lang        $parts  = explode('?', $id, 2);
8773d5e07d9SAdrian Lang        if(count($parts) === 2) {
8783d5e07d9SAdrian Lang            $id     = $parts[0];
8793d5e07d9SAdrian Lang            $params = $parts[1];
88044653a53SAdrian Lang        }
88144653a53SAdrian Lang
882fda14ffcSIzidor Matušov        // For empty $id we need to know the current $ID
883fda14ffcSIzidor Matušov        // We need this check because _simpleTitle needs
884fda14ffcSIzidor Matušov        // correct $id and resolve_pageid() use cleanID($id)
885fda14ffcSIzidor Matušov        // (some things could be lost)
886fda14ffcSIzidor Matušov        if($id === '') {
887fda14ffcSIzidor Matušov            $id = $ID;
888fda14ffcSIzidor Matušov        }
889fda14ffcSIzidor Matušov
8900339c872Sjan        // default name is based on $id as given
8910339c872Sjan        $default = $this->_simpleTitle($id);
892ad32e47eSAndreas Gohr
8930339c872Sjan        // now first resolve and clean up the $id
89490bee600Slisps        resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true);
895fda14ffcSIzidor Matušov
89659bc3b48SGerrit Uitslag        $link = array();
897fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
8980e1c636eSandi        if(!$isImage) {
8990e1c636eSandi            if($exists) {
900ba11bd29Sandi                $class = 'wikilink1';
9010cecf9d5Sandi            } else {
902ba11bd29Sandi                $class       = 'wikilink2';
90344a6b4c7SAndreas Gohr                $link['rel'] = 'nofollow';
9040cecf9d5Sandi            }
9050cecf9d5Sandi        } else {
906ba11bd29Sandi            $class = 'media';
9070cecf9d5Sandi        }
9080cecf9d5Sandi
909a1685bedSandi        //keep hash anchor
9106d2af55dSChristopher Smith        @list($id, $hash) = explode('#', $id, 2);
911943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
912a1685bedSandi
913ba11bd29Sandi        //prepare for formating
914ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
915ba11bd29Sandi        $link['style']  = '';
916ba11bd29Sandi        $link['pre']    = '';
917ba11bd29Sandi        $link['suf']    = '';
91840eb54bbSjan        // highlight link to current page
919c4dda6afSAnika Henke        if($id == $INFO['id']) {
92092795d04Sandi            $link['pre'] = '<span class="curid">';
92192795d04Sandi            $link['suf'] = '</span>';
92240eb54bbSjan        }
9235e163278SAndreas Gohr        $link['more']   = '';
924ba11bd29Sandi        $link['class']  = $class;
9255c2eed9aSlisps        if($this->date_at) {
926912a6d48SPhy            $params = $params.'&at='.rawurlencode($this->date_at);
9275c2eed9aSlisps        }
92844653a53SAdrian Lang        $link['url']    = wl($id, $params);
929ba11bd29Sandi        $link['name']   = $name;
930ba11bd29Sandi        $link['title']  = $id;
931723d78dbSandi        //add search string
932723d78dbSandi        if($search) {
933546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&amp;';
934546d3a99SAndreas Gohr            if(is_array($search)) {
935546d3a99SAndreas Gohr                $search = array_map('rawurlencode', $search);
936546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=', $search);
937546d3a99SAndreas Gohr            } else {
938546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
939546d3a99SAndreas Gohr            }
940723d78dbSandi        }
941723d78dbSandi
942a1685bedSandi        //keep hash
943a1685bedSandi        if($hash) $link['url'] .= '#'.$hash;
944a1685bedSandi
945ba11bd29Sandi        //output formatted
946cffcc403Sandi        if($returnonly) {
947cffcc403Sandi            return $this->_formatLink($link);
948cffcc403Sandi        } else {
949a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
9500cecf9d5Sandi        }
951cffcc403Sandi    }
9520cecf9d5Sandi
9533dd5c225SAndreas Gohr    /**
9543dd5c225SAndreas Gohr     * Render an external link
9553dd5c225SAndreas Gohr     *
9563dd5c225SAndreas Gohr     * @param string       $url        full URL with scheme
9573dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
958122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
9590c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
9603dd5c225SAndreas Gohr     */
961122f2d46SAndreas Böhler    function externallink($url, $name = null, $returnonly = false) {
962b625487dSandi        global $conf;
9630cecf9d5Sandi
964433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
9656f0c5dbfSandi
966b52b1596SAndreas Gohr        // url might be an attack vector, only allow registered protocols
967b52b1596SAndreas Gohr        if(is_null($this->schemes)) $this->schemes = getSchemes();
968b52b1596SAndreas Gohr        list($scheme) = explode('://', $url);
969b52b1596SAndreas Gohr        $scheme = strtolower($scheme);
970b52b1596SAndreas Gohr        if(!in_array($scheme, $this->schemes)) $url = '';
971b52b1596SAndreas Gohr
972b52b1596SAndreas Gohr        // is there still an URL?
973b52b1596SAndreas Gohr        if(!$url) {
97449cef4fdSAndreas Böhler            if($returnonly) {
97549cef4fdSAndreas Böhler                return $name;
97649cef4fdSAndreas Böhler            } else {
977b52b1596SAndreas Gohr                $this->doc .= $name;
97849cef4fdSAndreas Böhler            }
979b52b1596SAndreas Gohr            return;
980b52b1596SAndreas Gohr        }
981b52b1596SAndreas Gohr
982b52b1596SAndreas Gohr        // set class
9830cecf9d5Sandi        if(!$isImage) {
984b625487dSandi            $class = 'urlextern';
9850cecf9d5Sandi        } else {
986b625487dSandi            $class = 'media';
9870cecf9d5Sandi        }
9880cecf9d5Sandi
989b625487dSandi        //prepare for formating
99059bc3b48SGerrit Uitslag        $link = array();
991b625487dSandi        $link['target'] = $conf['target']['extern'];
992b625487dSandi        $link['style']  = '';
993b625487dSandi        $link['pre']    = '';
994b625487dSandi        $link['suf']    = '';
9955e163278SAndreas Gohr        $link['more']   = '';
996b625487dSandi        $link['class']  = $class;
997b625487dSandi        $link['url']    = $url;
998914045f3SAndreas Gohr        $link['rel']    = '';
999e1c10e4dSchris
1000b625487dSandi        $link['name']  = $name;
1001433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
1002914045f3SAndreas Gohr        if($conf['relnofollow']) $link['rel'] .= ' nofollow';
1003914045f3SAndreas Gohr        if($conf['target']['extern']) $link['rel'] .= ' noopener';
10040cecf9d5Sandi
1005b625487dSandi        //output formatted
1006122f2d46SAndreas Böhler        if($returnonly) {
1007122f2d46SAndreas Böhler            return $this->_formatLink($link);
1008122f2d46SAndreas Böhler        } else {
1009a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
10100cecf9d5Sandi        }
1011122f2d46SAndreas Böhler    }
10120cecf9d5Sandi
10130cecf9d5Sandi    /**
10143dd5c225SAndreas Gohr     * Render an interwiki link
10153dd5c225SAndreas Gohr     *
10163dd5c225SAndreas Gohr     * You may want to use $this->_resolveInterWiki() here
10173dd5c225SAndreas Gohr     *
10183dd5c225SAndreas Gohr     * @param string       $match      original link - probably not much use
10193dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
10203dd5c225SAndreas Gohr     * @param string       $wikiName   indentifier (shortcut) for the remote wiki
10213dd5c225SAndreas Gohr     * @param string       $wikiUri    the fragment parsed from the original link
1022122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
10230c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
10240cecf9d5Sandi     */
1025122f2d46SAndreas Böhler    function interwikilink($match, $name = null, $wikiName, $wikiUri, $returnonly = false) {
1026b625487dSandi        global $conf;
10270cecf9d5Sandi
102897a3e4e3Sandi        $link           = array();
102997a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
103097a3e4e3Sandi        $link['pre']    = '';
103197a3e4e3Sandi        $link['suf']    = '';
10325e163278SAndreas Gohr        $link['more']   = '';
1033433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
1034914045f3SAndreas Gohr        $link['rel']    = '';
10350cecf9d5Sandi
103697a3e4e3Sandi        //get interwiki URL
10376496c33fSGerrit Uitslag        $exists = null;
10386496c33fSGerrit Uitslag        $url    = $this->_resolveInterWiki($wikiName, $wikiUri, $exists);
10390cecf9d5Sandi
104097a3e4e3Sandi        if(!$isImage) {
10419d2ddea4SAndreas Gohr            $class         = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName);
10429d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
10431c2d1019SAndreas Gohr        } else {
10441c2d1019SAndreas Gohr            $link['class'] = 'media';
104597a3e4e3Sandi        }
10460cecf9d5Sandi
104797a3e4e3Sandi        //do we stay at the same server? Use local target
10482345e871SGerrit Uitslag        if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) {
104997a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
105097a3e4e3Sandi        }
10516496c33fSGerrit Uitslag        if($exists !== null && !$isImage) {
10526496c33fSGerrit Uitslag            if($exists) {
10536496c33fSGerrit Uitslag                $link['class'] .= ' wikilink1';
10546496c33fSGerrit Uitslag            } else {
10556496c33fSGerrit Uitslag                $link['class'] .= ' wikilink2';
1056914045f3SAndreas Gohr                $link['rel'] .= ' nofollow';
10576496c33fSGerrit Uitslag            }
10586496c33fSGerrit Uitslag        }
1059914045f3SAndreas Gohr        if($conf['target']['interwiki']) $link['rel'] .= ' noopener';
10600cecf9d5Sandi
106197a3e4e3Sandi        $link['url']   = $url;
106297a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
106397a3e4e3Sandi
106497a3e4e3Sandi        //output formatted
1065122f2d46SAndreas Böhler        if($returnonly) {
1066122f2d46SAndreas Böhler            return $this->_formatLink($link);
1067122f2d46SAndreas Böhler        } else {
1068a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
10690cecf9d5Sandi        }
1070122f2d46SAndreas Böhler    }
10710cecf9d5Sandi
10720cecf9d5Sandi    /**
10733dd5c225SAndreas Gohr     * Link to windows share
10743dd5c225SAndreas Gohr     *
10753dd5c225SAndreas Gohr     * @param string       $url        the link
10763dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
1077122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
10780c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
10790cecf9d5Sandi     */
1080122f2d46SAndreas Böhler    function windowssharelink($url, $name = null, $returnonly = false) {
10811d47afe1Sandi        global $conf;
10823dd5c225SAndreas Gohr
10831d47afe1Sandi        //simple setup
108459bc3b48SGerrit Uitslag        $link = array();
10851d47afe1Sandi        $link['target'] = $conf['target']['windows'];
10861d47afe1Sandi        $link['pre']    = '';
10871d47afe1Sandi        $link['suf']    = '';
10881d47afe1Sandi        $link['style']  = '';
10890cecf9d5Sandi
1090433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
10910cecf9d5Sandi        if(!$isImage) {
10921d47afe1Sandi            $link['class'] = 'windows';
10930cecf9d5Sandi        } else {
10941d47afe1Sandi            $link['class'] = 'media';
10950cecf9d5Sandi        }
10960cecf9d5Sandi
1097433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
10981d47afe1Sandi        $url           = str_replace('\\', '/', $url);
10991d47afe1Sandi        $url           = 'file:///'.$url;
11001d47afe1Sandi        $link['url']   = $url;
11010cecf9d5Sandi
11021d47afe1Sandi        //output formatted
1103122f2d46SAndreas Böhler        if($returnonly) {
1104122f2d46SAndreas Böhler            return $this->_formatLink($link);
1105122f2d46SAndreas Böhler        } else {
1106a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
11070cecf9d5Sandi        }
1108122f2d46SAndreas Böhler    }
11090cecf9d5Sandi
11103dd5c225SAndreas Gohr    /**
11113dd5c225SAndreas Gohr     * Render a linked E-Mail Address
11123dd5c225SAndreas Gohr     *
11133dd5c225SAndreas Gohr     * Honors $conf['mailguard'] setting
11143dd5c225SAndreas Gohr     *
11153dd5c225SAndreas Gohr     * @param string       $address    Email-Address
11163dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
1117122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
11180c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
11193dd5c225SAndreas Gohr     */
1120122f2d46SAndreas Böhler    function emaillink($address, $name = null, $returnonly = false) {
112171352defSandi        global $conf;
112271352defSandi        //simple setup
112371352defSandi        $link           = array();
112471352defSandi        $link['target'] = '';
112571352defSandi        $link['pre']    = '';
112671352defSandi        $link['suf']    = '';
112771352defSandi        $link['style']  = '';
112871352defSandi        $link['more']   = '';
11290cecf9d5Sandi
1130c078fc55SAndreas Gohr        $name = $this->_getLinkTitle($name, '', $isImage);
11310cecf9d5Sandi        if(!$isImage) {
1132be96545cSAnika Henke            $link['class'] = 'mail';
11330cecf9d5Sandi        } else {
1134be96545cSAnika Henke            $link['class'] = 'media';
11350cecf9d5Sandi        }
11360cecf9d5Sandi
113707738714SAndreas Gohr        $address = $this->_xmlEntities($address);
113800a7b5adSEsther Brunner        $address = obfuscate($address);
113900a7b5adSEsther Brunner        $title   = $address;
11408c128049SAndreas Gohr
114171352defSandi        if(empty($name)) {
114200a7b5adSEsther Brunner            $name = $address;
114371352defSandi        }
11440cecf9d5Sandi
1145776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
1146776b36ecSAndreas Gohr
1147776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
114871352defSandi        $link['name']  = $name;
114971352defSandi        $link['title'] = $title;
11500cecf9d5Sandi
115171352defSandi        //output formatted
1152122f2d46SAndreas Böhler        if($returnonly) {
1153122f2d46SAndreas Böhler            return $this->_formatLink($link);
1154122f2d46SAndreas Böhler        } else {
1155a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
11560cecf9d5Sandi        }
1157122f2d46SAndreas Böhler    }
11580cecf9d5Sandi
11593dd5c225SAndreas Gohr    /**
11603dd5c225SAndreas Gohr     * Render an internal media file
11613dd5c225SAndreas Gohr     *
11623dd5c225SAndreas Gohr     * @param string $src       media ID
11633dd5c225SAndreas Gohr     * @param string $title     descriptive text
11643dd5c225SAndreas Gohr     * @param string $align     left|center|right
11653dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
11663dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
11673dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
11683dd5c225SAndreas Gohr     * @param string $linking   linkonly|detail|nolink
11693dd5c225SAndreas Gohr     * @param bool   $return    return HTML instead of adding to $doc
11700c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $return
11713dd5c225SAndreas Gohr     */
11720ea51e63SMatt Perry    function internalmedia($src, $title = null, $align = null, $width = null,
11733dd5c225SAndreas Gohr                           $height = null, $cache = null, $linking = null, $return = false) {
117437e34a5eSandi        global $ID;
11758f34cf3dSMichael Große        if (strpos($src, '#') !== false) {
117691df343aSAndreas Gohr            list($src, $hash) = explode('#', $src, 2);
11778f34cf3dSMichael Große        }
1178cdb5e961Slisps        resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true);
11790cecf9d5Sandi
1180d98d4540SBen Coburn        $noLink = false;
11818acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
1182b739ff0fSPierre Spring        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
11833685f775Sandi
11843dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src, false);
1185b739ff0fSPierre Spring        if(substr($mime, 0, 5) == 'image' && $render) {
1186*64159a61SAndreas Gohr            $link['url'] = ml(
1187*64159a61SAndreas Gohr                $src,
1188*64159a61SAndreas Gohr                array(
1189*64159a61SAndreas Gohr                    'id' => $ID,
1190*64159a61SAndreas Gohr                    'cache' => $cache,
1191*64159a61SAndreas Gohr                    'rev' => $this->_getLastMediaRevisionAt($src)
1192*64159a61SAndreas Gohr                ),
1193*64159a61SAndreas Gohr                ($linking == 'direct')
1194*64159a61SAndreas Gohr            );
1195f50634f0SAnika Henke        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
11962a2a2ba2SAnika Henke            // don't link movies
119744881bd0Shenning.noren            $noLink = true;
119855efc227SAndreas Gohr        } else {
11992ca14335SEsther Brunner            // add file icons
12009d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
12019d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
1202*64159a61SAndreas Gohr            $link['url'] = ml(
1203*64159a61SAndreas Gohr                $src,
1204*64159a61SAndreas Gohr                array(
1205*64159a61SAndreas Gohr                    'id' => $ID,
1206*64159a61SAndreas Gohr                    'cache' => $cache,
1207*64159a61SAndreas Gohr                    'rev' => $this->_getLastMediaRevisionAt($src)
1208*64159a61SAndreas Gohr                ),
1209*64159a61SAndreas Gohr                true
1210*64159a61SAndreas Gohr            );
121191328684SMichael Hamann            if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')';
121255efc227SAndreas Gohr        }
12133685f775Sandi
12148f34cf3dSMichael Große        if (!empty($hash)) $link['url'] .= '#'.$hash;
121591df343aSAndreas Gohr
12166fe20453SGina Haeussge        //markup non existing files
12174a24b459SKate Arzamastseva        if(!$exists) {
12186fe20453SGina Haeussge            $link['class'] .= ' wikilink2';
12194a24b459SKate Arzamastseva        }
12206fe20453SGina Haeussge
12213685f775Sandi        //output formatted
1222f50634f0SAnika Henke        if($return) {
1223f50634f0SAnika Henke            if($linking == 'nolink' || $noLink) return $link['name'];
1224f50634f0SAnika Henke            else return $this->_formatLink($link);
1225f50634f0SAnika Henke        } else {
1226dc673a5bSjoe.lapp            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
12272ca14335SEsther Brunner            else $this->doc .= $this->_formatLink($link);
12280cecf9d5Sandi        }
1229f50634f0SAnika Henke    }
12300cecf9d5Sandi
12313dd5c225SAndreas Gohr    /**
12323dd5c225SAndreas Gohr     * Render an external media file
12333dd5c225SAndreas Gohr     *
12343dd5c225SAndreas Gohr     * @param string $src     full media URL
12353dd5c225SAndreas Gohr     * @param string $title   descriptive text
12363dd5c225SAndreas Gohr     * @param string $align   left|center|right
12373dd5c225SAndreas Gohr     * @param int    $width   width of media in pixel
12383dd5c225SAndreas Gohr     * @param int    $height  height of media in pixel
12393dd5c225SAndreas Gohr     * @param string $cache   cache|recache|nocache
12403dd5c225SAndreas Gohr     * @param string $linking linkonly|detail|nolink
1241410ee62aSAnika Henke     * @param bool   $return  return HTML instead of adding to $doc
12420c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $return
12433dd5c225SAndreas Gohr     */
12440ea51e63SMatt Perry    function externalmedia($src, $title = null, $align = null, $width = null,
1245410ee62aSAnika Henke                           $height = null, $cache = null, $linking = null, $return = false) {
12466efc45a2SDmitry Katsubo        if(link_isinterwiki($src)){
12476efc45a2SDmitry Katsubo            list($shortcut, $reference) = explode('>', $src, 2);
12486efc45a2SDmitry Katsubo            $exists = null;
12496efc45a2SDmitry Katsubo            $src = $this->_resolveInterWiki($shortcut, $reference, $exists);
12506efc45a2SDmitry Katsubo        }
125191df343aSAndreas Gohr        list($src, $hash) = explode('#', $src, 2);
1252d98d4540SBen Coburn        $noLink = false;
12538acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
1254b739ff0fSPierre Spring        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
1255b739ff0fSPierre Spring
1256b739ff0fSPierre Spring        $link['url'] = ml($src, array('cache' => $cache));
12573685f775Sandi
12583dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src, false);
1259b739ff0fSPierre Spring        if(substr($mime, 0, 5) == 'image' && $render) {
12602ca14335SEsther Brunner            // link only jpeg images
126144881bd0Shenning.noren            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
1262f50634f0SAnika Henke        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
12632a2a2ba2SAnika Henke            // don't link movies
126444881bd0Shenning.noren            $noLink = true;
12652ca14335SEsther Brunner        } else {
12662ca14335SEsther Brunner            // add file icons
126727bf7924STom N Harris            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
126827bf7924STom N Harris            $link['class'] .= ' mediafile mf_'.$class;
12692ca14335SEsther Brunner        }
12702ca14335SEsther Brunner
127191df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
127291df343aSAndreas Gohr
12733685f775Sandi        //output formatted
1274410ee62aSAnika Henke        if($return) {
1275410ee62aSAnika Henke            if($linking == 'nolink' || $noLink) return $link['name'];
1276410ee62aSAnika Henke            else return $this->_formatLink($link);
1277410ee62aSAnika Henke        } else {
1278dc673a5bSjoe.lapp            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
12792ca14335SEsther Brunner            else $this->doc .= $this->_formatLink($link);
12800cecf9d5Sandi        }
1281410ee62aSAnika Henke    }
12820cecf9d5Sandi
12834826ab45Sandi    /**
12843db95becSAndreas Gohr     * Renders an RSS feed
1285b625487dSandi     *
12860c4c0281SGerrit Uitslag     * @param string $url    URL of the feed
12870c4c0281SGerrit Uitslag     * @param array  $params Finetuning of the output
12880c4c0281SGerrit Uitslag     *
1289b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
1290b625487dSandi     */
12913db95becSAndreas Gohr    function rss($url, $params) {
1292b625487dSandi        global $lang;
12933db95becSAndreas Gohr        global $conf;
12943db95becSAndreas Gohr
12953db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
12963db95becSAndreas Gohr        $feed = new FeedParser();
129700077af8SAndreas Gohr        $feed->set_feed_url($url);
1298b625487dSandi
1299b625487dSandi        //disable warning while fetching
13003dd5c225SAndreas Gohr        if(!defined('DOKU_E_LEVEL')) {
13013dd5c225SAndreas Gohr            $elvl = error_reporting(E_ERROR);
13023dd5c225SAndreas Gohr        }
13033db95becSAndreas Gohr        $rc = $feed->init();
13043dd5c225SAndreas Gohr        if(isset($elvl)) {
13053dd5c225SAndreas Gohr            error_reporting($elvl);
13063dd5c225SAndreas Gohr        }
1307b625487dSandi
130838c6f603SRobin H. Johnson        if($params['nosort']) $feed->enable_order_by_date(false);
130938c6f603SRobin H. Johnson
13103db95becSAndreas Gohr        //decide on start and end
13113db95becSAndreas Gohr        if($params['reverse']) {
13123db95becSAndreas Gohr            $mod   = -1;
13133db95becSAndreas Gohr            $start = $feed->get_item_quantity() - 1;
13143db95becSAndreas Gohr            $end   = $start - ($params['max']);
1315b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
13163db95becSAndreas Gohr        } else {
13173db95becSAndreas Gohr            $mod   = 1;
13183db95becSAndreas Gohr            $start = 0;
13193db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
1320d91ab76fSMatt Perry            $end   = ($end > $params['max']) ? $params['max'] : $end;
13213db95becSAndreas Gohr        }
13223db95becSAndreas Gohr
1323a2d649c4Sandi        $this->doc .= '<ul class="rss">';
13243db95becSAndreas Gohr        if($rc) {
13253db95becSAndreas Gohr            for($x = $start; $x != $end; $x += $mod) {
13261bde1582SAndreas Gohr                $item = $feed->get_item($x);
13273db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
1328d2ea3363SAndreas Gohr                // support feeds without links
1329d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
1330d2ea3363SAndreas Gohr                if($lnkurl) {
1331793361f8SAndreas Gohr                    // title is escaped by SimplePie, we unescape here because it
1332793361f8SAndreas Gohr                    // is escaped again in externallink() FS#1705
13333dd5c225SAndreas Gohr                    $this->externallink(
13343dd5c225SAndreas Gohr                        $item->get_permalink(),
13353dd5c225SAndreas Gohr                        html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8')
13363dd5c225SAndreas Gohr                    );
1337d2ea3363SAndreas Gohr                } else {
1338d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
1339d2ea3363SAndreas Gohr                }
13403db95becSAndreas Gohr                if($params['author']) {
13411bde1582SAndreas Gohr                    $author = $item->get_author(0);
13421bde1582SAndreas Gohr                    if($author) {
13431bde1582SAndreas Gohr                        $name = $author->get_name();
13441bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
1345163c2842SPhy                        if($name) $this->doc .= ' '.$lang['by'].' '.hsc($name);
13461bde1582SAndreas Gohr                    }
13473db95becSAndreas Gohr                }
13483db95becSAndreas Gohr                if($params['date']) {
13492e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
13503db95becSAndreas Gohr                }
13511bde1582SAndreas Gohr                if($params['details']) {
13523db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
1353173dccb7STom N Harris                    if($conf['htmlok']) {
13541bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
13553db95becSAndreas Gohr                    } else {
13561bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
13573db95becSAndreas Gohr                    }
13583db95becSAndreas Gohr                    $this->doc .= '</div>';
13593db95becSAndreas Gohr                }
13603db95becSAndreas Gohr
13613db95becSAndreas Gohr                $this->doc .= '</div></li>';
1362b625487dSandi            }
1363b625487dSandi        } else {
13643db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
1365a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
1366b625487dSandi            $this->externallink($url);
136745e147ccSAndreas Gohr            if($conf['allowdebug']) {
136845e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
136945e147ccSAndreas Gohr            }
13703db95becSAndreas Gohr            $this->doc .= '</div></li>';
1371b625487dSandi        }
1372a2d649c4Sandi        $this->doc .= '</ul>';
1373b625487dSandi    }
1374b625487dSandi
13753dd5c225SAndreas Gohr    /**
13763dd5c225SAndreas Gohr     * Start a table
13773dd5c225SAndreas Gohr     *
13783dd5c225SAndreas Gohr     * @param int $maxcols maximum number of columns
13793dd5c225SAndreas Gohr     * @param int $numrows NOT IMPLEMENTED
13803dd5c225SAndreas Gohr     * @param int $pos byte position in the original source
13817d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
13823dd5c225SAndreas Gohr     */
13830c4c0281SGerrit Uitslag    function table_open($maxcols = null, $numrows = null, $pos = null, $classes = null) {
1384b5742cedSPierre Spring        // initialize the row counter used for classes
1385b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
1386619736fdSAdrian Lang        $class                         = 'table';
13870c4c0281SGerrit Uitslag        if($classes !== null) {
13882e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
13890c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
13900c4c0281SGerrit Uitslag        }
1391619736fdSAdrian Lang        if($pos !== null) {
139206917fceSMichael Große            $hid = $this->_headerToLink($class, true);
1393ec57f119SLarsDW223            $data = array();
1394ec57f119SLarsDW223            $data['target'] = 'table';
1395ec57f119SLarsDW223            $data['name'] = '';
1396ec57f119SLarsDW223            $data['hid'] = $hid;
1397ec57f119SLarsDW223            $class .= ' '.$this->startSectionEdit($pos, $data);
1398619736fdSAdrian Lang        }
1399619736fdSAdrian Lang        $this->doc .= '<div class="'.$class.'"><table class="inline">'.
1400619736fdSAdrian Lang            DOKU_LF;
14010cecf9d5Sandi    }
14020cecf9d5Sandi
14033dd5c225SAndreas Gohr    /**
14043dd5c225SAndreas Gohr     * Close a table
14053dd5c225SAndreas Gohr     *
14063dd5c225SAndreas Gohr     * @param int $pos byte position in the original source
14073dd5c225SAndreas Gohr     */
1408619736fdSAdrian Lang    function table_close($pos = null) {
1409a8574918SAnika Henke        $this->doc .= '</table></div>'.DOKU_LF;
1410619736fdSAdrian Lang        if($pos !== null) {
141190df9a4dSAdrian Lang            $this->finishSectionEdit($pos);
14120cecf9d5Sandi        }
1413619736fdSAdrian Lang    }
14140cecf9d5Sandi
14153dd5c225SAndreas Gohr    /**
14163dd5c225SAndreas Gohr     * Open a table header
14173dd5c225SAndreas Gohr     */
1418f05a1cc5SGerrit Uitslag    function tablethead_open() {
1419f05a1cc5SGerrit Uitslag        $this->doc .= DOKU_TAB.'<thead>'.DOKU_LF;
1420f05a1cc5SGerrit Uitslag    }
1421f05a1cc5SGerrit Uitslag
14223dd5c225SAndreas Gohr    /**
14233dd5c225SAndreas Gohr     * Close a table header
14243dd5c225SAndreas Gohr     */
1425f05a1cc5SGerrit Uitslag    function tablethead_close() {
1426f05a1cc5SGerrit Uitslag        $this->doc .= DOKU_TAB.'</thead>'.DOKU_LF;
1427f05a1cc5SGerrit Uitslag    }
1428f05a1cc5SGerrit Uitslag
14293dd5c225SAndreas Gohr    /**
14305a93f869SAnika Henke     * Open a table body
14315a93f869SAnika Henke     */
14325a93f869SAnika Henke    function tabletbody_open() {
14335a93f869SAnika Henke        $this->doc .= DOKU_TAB.'<tbody>'.DOKU_LF;
14345a93f869SAnika Henke    }
14355a93f869SAnika Henke
14365a93f869SAnika Henke    /**
14375a93f869SAnika Henke     * Close a table body
14385a93f869SAnika Henke     */
14395a93f869SAnika Henke    function tabletbody_close() {
14405a93f869SAnika Henke        $this->doc .= DOKU_TAB.'</tbody>'.DOKU_LF;
14415a93f869SAnika Henke    }
14425a93f869SAnika Henke
14435a93f869SAnika Henke    /**
1444d2a99739SAndreas Gohr     * Open a table footer
1445d2a99739SAndreas Gohr     */
1446d2a99739SAndreas Gohr    function tabletfoot_open() {
144744f5d1c1SAndreas Gohr        $this->doc .= DOKU_TAB.'<tfoot>'.DOKU_LF;
1448d2a99739SAndreas Gohr    }
1449d2a99739SAndreas Gohr
1450d2a99739SAndreas Gohr    /**
1451d2a99739SAndreas Gohr     * Close a table footer
1452d2a99739SAndreas Gohr     */
1453d2a99739SAndreas Gohr    function tabletfoot_close() {
145444f5d1c1SAndreas Gohr        $this->doc .= DOKU_TAB.'</tfoot>'.DOKU_LF;
1455d2a99739SAndreas Gohr    }
1456d2a99739SAndreas Gohr
1457d2a99739SAndreas Gohr    /**
14583dd5c225SAndreas Gohr     * Open a table row
14590c4c0281SGerrit Uitslag     *
14607d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
14613dd5c225SAndreas Gohr     */
14620c4c0281SGerrit Uitslag    function tablerow_open($classes = null) {
1463b5742cedSPierre Spring        // initialize the cell counter used for classes
1464b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
1465b5742cedSPierre Spring        $class                          = 'row'.$this->_counter['row_counter']++;
14660c4c0281SGerrit Uitslag        if($classes !== null) {
14672e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
14680c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
14690c4c0281SGerrit Uitslag        }
1470b5742cedSPierre Spring        $this->doc .= DOKU_TAB.'<tr class="'.$class.'">'.DOKU_LF.DOKU_TAB.DOKU_TAB;
14710cecf9d5Sandi    }
14720cecf9d5Sandi
14733dd5c225SAndreas Gohr    /**
14743dd5c225SAndreas Gohr     * Close a table row
14753dd5c225SAndreas Gohr     */
14760cecf9d5Sandi    function tablerow_close() {
1477a2d649c4Sandi        $this->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
14780cecf9d5Sandi    }
14790cecf9d5Sandi
14803dd5c225SAndreas Gohr    /**
14813dd5c225SAndreas Gohr     * Open a table header cell
14823dd5c225SAndreas Gohr     *
14833dd5c225SAndreas Gohr     * @param int    $colspan
14843dd5c225SAndreas Gohr     * @param string $align left|center|right
14853dd5c225SAndreas Gohr     * @param int    $rowspan
14867d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
14873dd5c225SAndreas Gohr     */
14880c4c0281SGerrit Uitslag    function tableheader_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) {
1489b5742cedSPierre Spring        $class = 'class="col'.$this->_counter['cell_counter']++;
14900cecf9d5Sandi        if(!is_null($align)) {
1491b5742cedSPierre Spring            $class .= ' '.$align.'align';
14920cecf9d5Sandi        }
14930c4c0281SGerrit Uitslag        if($classes !== null) {
14942e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
14950c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
14960c4c0281SGerrit Uitslag        }
1497b5742cedSPierre Spring        $class .= '"';
1498b5742cedSPierre Spring        $this->doc .= '<th '.$class;
14990cecf9d5Sandi        if($colspan > 1) {
1500a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan - 1;
1501a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
15020cecf9d5Sandi        }
150325b97867Shakan.sandell        if($rowspan > 1) {
150425b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
150525b97867Shakan.sandell        }
1506a2d649c4Sandi        $this->doc .= '>';
15070cecf9d5Sandi    }
15080cecf9d5Sandi
15093dd5c225SAndreas Gohr    /**
15103dd5c225SAndreas Gohr     * Close a table header cell
15113dd5c225SAndreas Gohr     */
15120cecf9d5Sandi    function tableheader_close() {
1513a2d649c4Sandi        $this->doc .= '</th>';
15140cecf9d5Sandi    }
15150cecf9d5Sandi
15163dd5c225SAndreas Gohr    /**
15173dd5c225SAndreas Gohr     * Open a table cell
15183dd5c225SAndreas Gohr     *
15193dd5c225SAndreas Gohr     * @param int       $colspan
15203dd5c225SAndreas Gohr     * @param string    $align left|center|right
15213dd5c225SAndreas Gohr     * @param int       $rowspan
15227d769f75SAndreas Gohr     * @param string|string[]    $classes css classes - have to be valid, do not pass unfiltered user input
15233dd5c225SAndreas Gohr     */
15240c4c0281SGerrit Uitslag    function tablecell_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) {
1525b5742cedSPierre Spring        $class = 'class="col'.$this->_counter['cell_counter']++;
15260cecf9d5Sandi        if(!is_null($align)) {
1527b5742cedSPierre Spring            $class .= ' '.$align.'align';
15280cecf9d5Sandi        }
15290c4c0281SGerrit Uitslag        if($classes !== null) {
15302e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
15310c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
15320c4c0281SGerrit Uitslag        }
1533b5742cedSPierre Spring        $class .= '"';
1534b5742cedSPierre Spring        $this->doc .= '<td '.$class;
15350cecf9d5Sandi        if($colspan > 1) {
1536a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan - 1;
1537a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
15380cecf9d5Sandi        }
153925b97867Shakan.sandell        if($rowspan > 1) {
154025b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
154125b97867Shakan.sandell        }
1542a2d649c4Sandi        $this->doc .= '>';
15430cecf9d5Sandi    }
15440cecf9d5Sandi
15453dd5c225SAndreas Gohr    /**
15463dd5c225SAndreas Gohr     * Close a table cell
15473dd5c225SAndreas Gohr     */
15480cecf9d5Sandi    function tablecell_close() {
1549a2d649c4Sandi        $this->doc .= '</td>';
15500cecf9d5Sandi    }
15510cecf9d5Sandi
1552cea664bdSLarsDW223    /**
1553cea664bdSLarsDW223     * Returns the current header level.
1554cea664bdSLarsDW223     * (required e.g. by the filelist plugin)
1555cea664bdSLarsDW223     *
1556cea664bdSLarsDW223     * @return int The current header level
1557cea664bdSLarsDW223     */
1558cea664bdSLarsDW223    function getLastlevel() {
1559cea664bdSLarsDW223        return $this->lastlevel;
1560cea664bdSLarsDW223    }
1561cea664bdSLarsDW223
15623dd5c225SAndreas Gohr    #region Utility functions
15630cecf9d5Sandi
1564ba11bd29Sandi    /**
15653fd0b676Sandi     * Build a link
15663fd0b676Sandi     *
15673fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
1568ba11bd29Sandi     *
15690c4c0281SGerrit Uitslag     * @param array $link attributes of a link
15700c4c0281SGerrit Uitslag     * @return string
15710c4c0281SGerrit Uitslag     *
1572ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1573ba11bd29Sandi     */
1574433bef32Sandi    function _formatLink($link) {
1575ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
1576ba11bd29Sandi        if(substr($link['url'], 0, 7) != 'mailto:') {
1577ba11bd29Sandi            $link['url'] = str_replace('&', '&amp;', $link['url']);
1578ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;', '&amp;', $link['url']);
1579ba11bd29Sandi        }
1580ba11bd29Sandi        //remove double encodings in titles
1581ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;', '&amp;', $link['title']);
1582ba11bd29Sandi
1583453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
1584453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
1585453493f2SAndreas Gohr        $link['url']   = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22'));
1586453493f2SAndreas Gohr        $link['title'] = strtr($link['title'], array('>' => '&gt;', '<' => '&lt;', '"' => '&quot;'));
1587453493f2SAndreas Gohr
1588ba11bd29Sandi        $ret = '';
1589ba11bd29Sandi        $ret .= $link['pre'];
1590ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
1591bb4866bdSchris        if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"';
1592bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
1593bb4866bdSchris        if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"';
1594bb4866bdSchris        if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"';
1595914045f3SAndreas Gohr        if(!empty($link['rel'])) $ret .= ' rel="'.trim($link['rel']).'"';
1596bb4866bdSchris        if(!empty($link['more'])) $ret .= ' '.$link['more'];
1597ba11bd29Sandi        $ret .= '>';
1598ba11bd29Sandi        $ret .= $link['name'];
1599ba11bd29Sandi        $ret .= '</a>';
1600ba11bd29Sandi        $ret .= $link['suf'];
1601ba11bd29Sandi        return $ret;
1602ba11bd29Sandi    }
1603ba11bd29Sandi
1604ba11bd29Sandi    /**
16053fd0b676Sandi     * Renders internal and external media
16063fd0b676Sandi     *
16073fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
16083dd5c225SAndreas Gohr     * @param string $src       media ID
16093dd5c225SAndreas Gohr     * @param string $title     descriptive text
16103dd5c225SAndreas Gohr     * @param string $align     left|center|right
16113dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
16123dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
16133dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
16143dd5c225SAndreas Gohr     * @param bool   $render    should the media be embedded inline or just linked
16153dd5c225SAndreas Gohr     * @return string
16163fd0b676Sandi     */
16170ea51e63SMatt Perry    function _media($src, $title = null, $align = null, $width = null,
16180ea51e63SMatt Perry                    $height = null, $cache = null, $render = true) {
16193fd0b676Sandi
16203fd0b676Sandi        $ret = '';
16213fd0b676Sandi
16223dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src);
16233fd0b676Sandi        if(substr($mime, 0, 5) == 'image') {
1624b739ff0fSPierre Spring            // first get the $title
1625b739ff0fSPierre Spring            if(!is_null($title)) {
1626b739ff0fSPierre Spring                $title = $this->_xmlEntities($title);
1627b739ff0fSPierre Spring            } elseif($ext == 'jpg' || $ext == 'jpeg') {
1628b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
1629b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
163067f9913dSAndreas Gohr                $jpeg = new JpegMeta(mediaFN($src));
1631b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
16323dd5c225SAndreas Gohr                if(!empty($cap)) {
1633b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
1634b739ff0fSPierre Spring                }
1635b739ff0fSPierre Spring            }
1636b739ff0fSPierre Spring            if(!$render) {
1637b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
1638b739ff0fSPierre Spring                // return the title of the picture
1639b739ff0fSPierre Spring                if(!$title) {
1640b739ff0fSPierre Spring                    // just show the sourcename
16413009a773SAndreas Gohr                    $title = $this->_xmlEntities(utf8_basename(noNS($src)));
1642b739ff0fSPierre Spring                }
1643b739ff0fSPierre Spring                return $title;
1644b739ff0fSPierre Spring            }
16453fd0b676Sandi            //add image tag
1646*64159a61SAndreas Gohr            $ret .= '<img src="' . ml(
1647*64159a61SAndreas Gohr                    $src,
1648*64159a61SAndreas Gohr                    array(
1649*64159a61SAndreas Gohr                        'w' => $width, 'h' => $height,
1650*64159a61SAndreas Gohr                        'cache' => $cache,
1651*64159a61SAndreas Gohr                        'rev' => $this->_getLastMediaRevisionAt($src)
1652*64159a61SAndreas Gohr                    )
1653*64159a61SAndreas Gohr                ) . '"';
16543fd0b676Sandi            $ret .= ' class="media'.$align.'"';
16553fd0b676Sandi
1656b739ff0fSPierre Spring            if($title) {
1657b739ff0fSPierre Spring                $ret .= ' title="'.$title.'"';
1658b739ff0fSPierre Spring                $ret .= ' alt="'.$title.'"';
16593fd0b676Sandi            } else {
16603fd0b676Sandi                $ret .= ' alt=""';
16613fd0b676Sandi            }
16623fd0b676Sandi
16633fd0b676Sandi            if(!is_null($width))
16643fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
16653fd0b676Sandi
16663fd0b676Sandi            if(!is_null($height))
16673fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
16683fd0b676Sandi
16693fd0b676Sandi            $ret .= ' />';
16703fd0b676Sandi
167117954bb5SAnika Henke        } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) {
16722a2a2ba2SAnika Henke            // first get the $title
167317954bb5SAnika Henke            $title = !is_null($title) ? $this->_xmlEntities($title) : false;
16742a2a2ba2SAnika Henke            if(!$render) {
167517954bb5SAnika Henke                // if the file is not supposed to be rendered
167617954bb5SAnika Henke                // return the title of the file (just the sourcename if there is no title)
167717954bb5SAnika Henke                return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src)));
16782a2a2ba2SAnika Henke            }
16792a2a2ba2SAnika Henke
16802a2a2ba2SAnika Henke            $att          = array();
16812a2a2ba2SAnika Henke            $att['class'] = "media$align";
168217954bb5SAnika Henke            if($title) {
168317954bb5SAnika Henke                $att['title'] = $title;
168417954bb5SAnika Henke            }
16852a2a2ba2SAnika Henke
168617954bb5SAnika Henke            if(media_supportedav($mime, 'video')) {
168717954bb5SAnika Henke                //add video
168879e53fe5SAnika Henke                $ret .= $this->_video($src, $width, $height, $att);
1689b44a5dceSAnika Henke            }
169017954bb5SAnika Henke            if(media_supportedav($mime, 'audio')) {
1691b44a5dceSAnika Henke                //add audio
1692b44a5dceSAnika Henke                $ret .= $this->_audio($src, $att);
169317954bb5SAnika Henke            }
1694b44a5dceSAnika Henke
16953fd0b676Sandi        } elseif($mime == 'application/x-shockwave-flash') {
16961c882ba8SAndreas Gohr            if(!$render) {
16971c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
16981c882ba8SAndreas Gohr                // return the title of the flash
16991c882ba8SAndreas Gohr                if(!$title) {
17001c882ba8SAndreas Gohr                    // just show the sourcename
17013009a773SAndreas Gohr                    $title = utf8_basename(noNS($src));
17021c882ba8SAndreas Gohr                }
170307bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
17041c882ba8SAndreas Gohr            }
17051c882ba8SAndreas Gohr
170607bf32b2SAndreas Gohr            $att          = array();
170707bf32b2SAndreas Gohr            $att['class'] = "media$align";
170807bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
170907bf32b2SAndreas Gohr            if($align == 'left') $att['align'] = 'left';
17103dd5c225SAndreas Gohr            $ret .= html_flashobject(
17113dd5c225SAndreas Gohr                ml($src, array('cache' => $cache), true, '&'), $width, $height,
171207bf32b2SAndreas Gohr                array('quality' => 'high'),
171307bf32b2SAndreas Gohr                null,
171407bf32b2SAndreas Gohr                $att,
17153dd5c225SAndreas Gohr                $this->_xmlEntities($title)
17163dd5c225SAndreas Gohr            );
17170f428d7dSAndreas Gohr        } elseif($title) {
17183fd0b676Sandi            // well at least we have a title to display
17193fd0b676Sandi            $ret .= $this->_xmlEntities($title);
17203fd0b676Sandi        } else {
17215291ca3aSAndreas Gohr            // just show the sourcename
17223009a773SAndreas Gohr            $ret .= $this->_xmlEntities(utf8_basename(noNS($src)));
17233fd0b676Sandi        }
17243fd0b676Sandi
17253fd0b676Sandi        return $ret;
17263fd0b676Sandi    }
17273fd0b676Sandi
17283dd5c225SAndreas Gohr    /**
17293dd5c225SAndreas Gohr     * Escape string for output
17303dd5c225SAndreas Gohr     *
17313dd5c225SAndreas Gohr     * @param $string
17323dd5c225SAndreas Gohr     * @return string
17333dd5c225SAndreas Gohr     */
1734433bef32Sandi    function _xmlEntities($string) {
1735de117061Schris        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
17360cecf9d5Sandi    }
17370cecf9d5Sandi
17388a831f2bSAndreas Gohr    /**
17398a831f2bSAndreas Gohr     * Creates a linkid from a headline
1740c5a8fd96SAndreas Gohr     *
17413dd5c225SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
1742c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1743c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
17443dd5c225SAndreas Gohr     * @return string
17458a831f2bSAndreas Gohr     */
1746c5a8fd96SAndreas Gohr    function _headerToLink($title, $create = false) {
1747c5a8fd96SAndreas Gohr        if($create) {
17484ceab83fSAndreas Gohr            return sectionID($title, $this->headers);
17494ceab83fSAndreas Gohr        } else {
1750443d207bSAndreas Gohr            $check = false;
1751443d207bSAndreas Gohr            return sectionID($title, $check);
1752c5a8fd96SAndreas Gohr        }
17530cecf9d5Sandi    }
17540cecf9d5Sandi
1755af587fa8Sandi    /**
17563fd0b676Sandi     * Construct a title and handle images in titles
17573fd0b676Sandi     *
17580b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
17593dd5c225SAndreas Gohr     * @param string|array $title    either string title or media array
17603dd5c225SAndreas Gohr     * @param string       $default  default title if nothing else is found
17613dd5c225SAndreas Gohr     * @param bool         $isImage  will be set to true if it's a media file
17623dd5c225SAndreas Gohr     * @param null|string  $id       linked page id (used to extract title from first heading)
17633dd5c225SAndreas Gohr     * @param string       $linktype content|navigation
17643dd5c225SAndreas Gohr     * @return string      HTML of the title, might be full image tag or just escaped text
17653fd0b676Sandi     */
17660ea51e63SMatt Perry    function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') {
176744881bd0Shenning.noren        $isImage = false;
176829657f9eSAndreas Gohr        if(is_array($title)) {
176929657f9eSAndreas Gohr            $isImage = true;
177029657f9eSAndreas Gohr            return $this->_imageTitle($title);
177129657f9eSAndreas Gohr        } elseif(is_null($title) || trim($title) == '') {
1772fe9ec250SChris Smith            if(useHeading($linktype) && $id) {
177367c15eceSMichael Hamann                $heading = p_get_first_heading($id);
1774f515db7fSAndreas Gohr                if(!blank($heading)) {
1775433bef32Sandi                    return $this->_xmlEntities($heading);
1776bb0a59d4Sjan                }
1777bb0a59d4Sjan            }
1778433bef32Sandi            return $this->_xmlEntities($default);
177968c26e6dSMichael Klier        } else {
178068c26e6dSMichael Klier            return $this->_xmlEntities($title);
17810cecf9d5Sandi        }
17820cecf9d5Sandi    }
17830cecf9d5Sandi
17840cecf9d5Sandi    /**
17853dd5c225SAndreas Gohr     * Returns HTML code for images used in link titles
17863fd0b676Sandi     *
17873fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1788e0c26282SGerrit Uitslag     * @param array $img
17893dd5c225SAndreas Gohr     * @return string HTML img tag or similar
17900cecf9d5Sandi     */
1791433bef32Sandi    function _imageTitle($img) {
1792d9baf1a7SKazutaka Miyasaka        global $ID;
1793d9baf1a7SKazutaka Miyasaka
1794d9baf1a7SKazutaka Miyasaka        // some fixes on $img['src']
1795d9baf1a7SKazutaka Miyasaka        // see internalmedia() and externalmedia()
17963dd5c225SAndreas Gohr        list($img['src']) = explode('#', $img['src'], 2);
1797d9baf1a7SKazutaka Miyasaka        if($img['type'] == 'internalmedia') {
1798cdb5e961Slisps            resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true);
1799d9baf1a7SKazutaka Miyasaka        }
1800d9baf1a7SKazutaka Miyasaka
18013dd5c225SAndreas Gohr        return $this->_media(
18023dd5c225SAndreas Gohr            $img['src'],
18034826ab45Sandi            $img['title'],
18044826ab45Sandi            $img['align'],
18054826ab45Sandi            $img['width'],
18064826ab45Sandi            $img['height'],
18073dd5c225SAndreas Gohr            $img['cache']
18083dd5c225SAndreas Gohr        );
18090cecf9d5Sandi    }
1810b739ff0fSPierre Spring
1811b739ff0fSPierre Spring    /**
18123dd5c225SAndreas Gohr     * helperfunction to return a basic link to a media
18133dd5c225SAndreas Gohr     *
18143dd5c225SAndreas Gohr     * used in internalmedia() and externalmedia()
1815b739ff0fSPierre Spring     *
1816b739ff0fSPierre Spring     * @author   Pierre Spring <pierre.spring@liip.ch>
18173dd5c225SAndreas Gohr     * @param string $src       media ID
18183dd5c225SAndreas Gohr     * @param string $title     descriptive text
18193dd5c225SAndreas Gohr     * @param string $align     left|center|right
18203dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
18213dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
18223dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
18233dd5c225SAndreas Gohr     * @param bool   $render    should the media be embedded inline or just linked
18243dd5c225SAndreas Gohr     * @return array associative array with link config
1825b739ff0fSPierre Spring     */
1826d91ab76fSMatt Perry    function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) {
1827b739ff0fSPierre Spring        global $conf;
1828b739ff0fSPierre Spring
1829b739ff0fSPierre Spring        $link           = array();
1830b739ff0fSPierre Spring        $link['class']  = 'media';
1831b739ff0fSPierre Spring        $link['style']  = '';
1832b739ff0fSPierre Spring        $link['pre']    = '';
1833b739ff0fSPierre Spring        $link['suf']    = '';
1834b739ff0fSPierre Spring        $link['more']   = '';
1835b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1836bc3d2252SAndreas Gohr        if($conf['target']['media']) $link['rel'] = 'noopener';
1837b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1838b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1839b739ff0fSPierre Spring
1840b739ff0fSPierre Spring        return $link;
1841b739ff0fSPierre Spring    }
184291459163SAnika Henke
18432a2a2ba2SAnika Henke    /**
18442a2a2ba2SAnika Henke     * Embed video(s) in HTML
18452a2a2ba2SAnika Henke     *
18462a2a2ba2SAnika Henke     * @author Anika Henke <anika@selfthinker.org>
18470877a1f1SSchplurtz le Déboulonné     * @author Schplurtz le Déboulonné <Schplurtz@laposte.net>
18482a2a2ba2SAnika Henke     *
18492a2a2ba2SAnika Henke     * @param string $src         - ID of video to embed
18502a2a2ba2SAnika Henke     * @param int    $width       - width of the video in pixels
18512a2a2ba2SAnika Henke     * @param int    $height      - height of the video in pixels
18522a2a2ba2SAnika Henke     * @param array  $atts        - additional attributes for the <video> tag
1853f50634f0SAnika Henke     * @return string
18542a2a2ba2SAnika Henke     */
185579e53fe5SAnika Henke    function _video($src, $width, $height, $atts = null) {
18562a2a2ba2SAnika Henke        // prepare width and height
18572a2a2ba2SAnika Henke        if(is_null($atts)) $atts = array();
18582a2a2ba2SAnika Henke        $atts['width']  = (int) $width;
18592a2a2ba2SAnika Henke        $atts['height'] = (int) $height;
18602a2a2ba2SAnika Henke        if(!$atts['width']) $atts['width'] = 320;
18612a2a2ba2SAnika Henke        if(!$atts['height']) $atts['height'] = 240;
18622a2a2ba2SAnika Henke
1863410ee62aSAnika Henke        $posterUrl = '';
1864410ee62aSAnika Henke        $files = array();
18650877a1f1SSchplurtz le Déboulonné        $tracks = array();
1866410ee62aSAnika Henke        $isExternal = media_isexternal($src);
1867410ee62aSAnika Henke
1868410ee62aSAnika Henke        if ($isExternal) {
1869410ee62aSAnika Henke            // take direct source for external files
1870702e97d3SAnika Henke            list(/*ext*/, $srcMime) = mimetype($src);
1871410ee62aSAnika Henke            $files[$srcMime] = $src;
1872410ee62aSAnika Henke        } else {
18733d7a9e0aSAnika Henke            // prepare alternative formats
18743d7a9e0aSAnika Henke            $extensions   = array('webm', 'ogv', 'mp4');
1875410ee62aSAnika Henke            $files        = media_alternativefiles($src, $extensions);
187659bc3b48SGerrit Uitslag            $poster       = media_alternativefiles($src, array('jpg', 'png'));
18770877a1f1SSchplurtz le Déboulonné            $tracks       = media_trackfiles($src);
187899f943f6SAnika Henke            if(!empty($poster)) {
18792d338eabSAndreas Gohr                $posterUrl = ml(reset($poster), '', true, '&');
188099f943f6SAnika Henke            }
1881410ee62aSAnika Henke        }
18822a2a2ba2SAnika Henke
1883f50634f0SAnika Henke        $out = '';
188479e53fe5SAnika Henke        // open video tag
1885f50634f0SAnika Henke        $out .= '<video '.buildAttributes($atts).' controls="controls"';
18863641199aSAnika Henke        if($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"';
1887f50634f0SAnika Henke        $out .= '>'.NL;
18883641199aSAnika Henke        $fallback = '';
188979e53fe5SAnika Henke
189079e53fe5SAnika Henke        // output source for each alternative video format
1891410ee62aSAnika Henke        foreach($files as $mime => $file) {
1892410ee62aSAnika Henke            if ($isExternal) {
1893410ee62aSAnika Henke                $url = $file;
1894410ee62aSAnika Henke                $linkType = 'externalmedia';
1895410ee62aSAnika Henke            } else {
18962d338eabSAndreas Gohr                $url = ml($file, '', true, '&');
1897410ee62aSAnika Henke                $linkType = 'internalmedia';
1898410ee62aSAnika Henke            }
189917954bb5SAnika Henke            $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
19003d7a9e0aSAnika Henke
1901f50634f0SAnika Henke            $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
190279e53fe5SAnika Henke            // alternative content (just a link to the file)
1903*64159a61SAndreas Gohr            $fallback .= $this->$linkType(
1904*64159a61SAndreas Gohr                $file,
1905*64159a61SAndreas Gohr                $title,
1906*64159a61SAndreas Gohr                null,
1907*64159a61SAndreas Gohr                null,
1908*64159a61SAndreas Gohr                null,
1909*64159a61SAndreas Gohr                $cache = null,
1910*64159a61SAndreas Gohr                $linking = 'linkonly',
1911*64159a61SAndreas Gohr                $return = true
1912*64159a61SAndreas Gohr            );
19133d7a9e0aSAnika Henke        }
19142a2a2ba2SAnika Henke
19150877a1f1SSchplurtz le Déboulonné        // output each track if any
19160877a1f1SSchplurtz le Déboulonné        foreach( $tracks as $trackid => $info ) {
191723c61bbeSSchplurtz le Déboulonné            list( $kind, $srclang ) = array_map( 'hsc', $info );
191823c61bbeSSchplurtz le Déboulonné            $out .= "<track kind=\"$kind\" srclang=\"$srclang\" ";
191923c61bbeSSchplurtz le Déboulonné            $out .= "label=\"$srclang\" ";
19200877a1f1SSchplurtz le Déboulonné            $out .= 'src="'.ml($trackid, '', true).'">'.NL;
19210877a1f1SSchplurtz le Déboulonné        }
19220877a1f1SSchplurtz le Déboulonné
19232a2a2ba2SAnika Henke        // finish
19243641199aSAnika Henke        $out .= $fallback;
1925f50634f0SAnika Henke        $out .= '</video>'.NL;
1926f50634f0SAnika Henke        return $out;
19272a2a2ba2SAnika Henke    }
19282a2a2ba2SAnika Henke
1929b44a5dceSAnika Henke    /**
1930b44a5dceSAnika Henke     * Embed audio in HTML
1931b44a5dceSAnika Henke     *
1932b44a5dceSAnika Henke     * @author Anika Henke <anika@selfthinker.org>
1933b44a5dceSAnika Henke     *
1934b44a5dceSAnika Henke     * @param string $src       - ID of audio to embed
19356d4af72aSAnika Henke     * @param array  $atts      - additional attributes for the <audio> tag
1936f50634f0SAnika Henke     * @return string
1937b44a5dceSAnika Henke     */
193859bc3b48SGerrit Uitslag    function _audio($src, $atts = array()) {
1939702e97d3SAnika Henke        $files = array();
1940410ee62aSAnika Henke        $isExternal = media_isexternal($src);
1941b44a5dceSAnika Henke
1942410ee62aSAnika Henke        if ($isExternal) {
1943410ee62aSAnika Henke            // take direct source for external files
1944702e97d3SAnika Henke            list(/*ext*/, $srcMime) = mimetype($src);
1945410ee62aSAnika Henke            $files[$srcMime] = $src;
1946410ee62aSAnika Henke        } else {
1947b44a5dceSAnika Henke            // prepare alternative formats
1948b44a5dceSAnika Henke            $extensions   = array('ogg', 'mp3', 'wav');
1949410ee62aSAnika Henke            $files        = media_alternativefiles($src, $extensions);
1950410ee62aSAnika Henke        }
1951b44a5dceSAnika Henke
1952f50634f0SAnika Henke        $out = '';
1953b44a5dceSAnika Henke        // open audio tag
1954f50634f0SAnika Henke        $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL;
19553641199aSAnika Henke        $fallback = '';
1956b44a5dceSAnika Henke
1957b44a5dceSAnika Henke        // output source for each alternative audio format
1958410ee62aSAnika Henke        foreach($files as $mime => $file) {
1959410ee62aSAnika Henke            if ($isExternal) {
1960410ee62aSAnika Henke                $url = $file;
1961410ee62aSAnika Henke                $linkType = 'externalmedia';
1962410ee62aSAnika Henke            } else {
19632d338eabSAndreas Gohr                $url = ml($file, '', true, '&');
1964410ee62aSAnika Henke                $linkType = 'internalmedia';
1965410ee62aSAnika Henke            }
196617954bb5SAnika Henke            $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
1967b44a5dceSAnika Henke
1968f50634f0SAnika Henke            $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
1969b44a5dceSAnika Henke            // alternative content (just a link to the file)
1970*64159a61SAndreas Gohr            $fallback .= $this->$linkType(
1971*64159a61SAndreas Gohr                $file,
1972*64159a61SAndreas Gohr                $title,
1973*64159a61SAndreas Gohr                null,
1974*64159a61SAndreas Gohr                null,
1975*64159a61SAndreas Gohr                null,
1976*64159a61SAndreas Gohr                $cache = null,
1977*64159a61SAndreas Gohr                $linking = 'linkonly',
1978*64159a61SAndreas Gohr                $return = true
1979*64159a61SAndreas Gohr            );
1980b44a5dceSAnika Henke        }
1981b44a5dceSAnika Henke
1982b44a5dceSAnika Henke        // finish
19833641199aSAnika Henke        $out .= $fallback;
1984f50634f0SAnika Henke        $out .= '</audio>'.NL;
1985f50634f0SAnika Henke        return $out;
1986b44a5dceSAnika Henke    }
1987b44a5dceSAnika Henke
19885c2eed9aSlisps    /**
198952dc5eadSlisps     * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media()
19905c2eed9aSlisps     * which returns an existing media revision less or equal to rev or date_at
19915c2eed9aSlisps     *
19925c2eed9aSlisps     * @author lisps
19935c2eed9aSlisps     * @param string $media_id
19945c2eed9aSlisps     * @access protected
19955c2eed9aSlisps     * @return string revision ('' for current)
19965c2eed9aSlisps     */
199752dc5eadSlisps    function _getLastMediaRevisionAt($media_id){
199852dc5eadSlisps        if(!$this->date_at || media_isexternal($media_id)) return '';
199978b874e6Slisps        $pagelog = new MediaChangeLog($media_id);
200078b874e6Slisps        return $pagelog->getLastRevisionAt($this->date_at);
20015c2eed9aSlisps    }
20025c2eed9aSlisps
20033dd5c225SAndreas Gohr    #endregion
20040cecf9d5Sandi}
20050cecf9d5Sandi
2006e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
2007