1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Brend Wanders <b.wanders@utwente.nl>
5 */
6// must be run within Dokuwiki
7if(!defined('DOKU_INC')) die('Meh.');
8
9/**
10 * The reference link type.
11 */
12class plugin_strata_type_ref extends plugin_strata_type_page {
13    function __construct() {
14        $this->util =& plugin_load('helper', 'strata_util');
15        parent::__construct();
16    }
17
18    function render($mode, &$R, &$T, $value, $hint) {
19        $heading = null;
20
21        // only use heading if allowed by configuration
22        if(useHeading('content')) {
23            $titles = $T->fetchTriples($value, $this->util->getTitleKey());
24            if($titles) {
25                $heading = $titles[0]['object'];
26            }
27        }
28
29        // render internal link
30        // (':' is prepended to make sure we use an absolute pagename,
31        // internallink resolves page names, but the name is already resolved.)
32        $R->internallink(':'.$value, $heading);
33    }
34
35    function getInfo() {
36        return array(
37            'desc'=>'References another piece of data or wiki page, and creates a link. The optional hint is used as namespace for the link. If the hint ends with a #, all values will be treated as fragments.',
38            'hint'=>'namespace'
39        );
40    }
41}
42