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 page link type.
11 */
12class plugin_strata_type_page extends plugin_strata_type {
13    function __construct() {
14    }
15
16    function normalize($value, $hint) {
17        global $ID;
18
19        // fragment reference special case
20        if(!empty($hint) && substr($hint,-1) == '#') {
21            $value = $hint.$value;
22            resolve_pageid(getNS($hint),$value,$exists);
23            return $value;
24        }
25
26        $base = ($hint?:getNS($ID));
27
28        // check for local link, and prefix full page id
29        // (local links don't get resolved by resolve_pageid)
30        if(preg_match('/^#.+/',$value)) {
31            $value = $ID.$value;
32        }
33
34        // resolve page id with respect to selected base
35        resolve_pageid($base,$value,$exists);
36
37        // if the value is empty after resolving, it is a reference to the
38        // root starting page. (We can not put the emtpy string into the
39        // database as a normalized reference -- this will create problems)
40        if($value == '') {
41            global $conf;
42            $value = $conf['start'];
43        }
44
45        return $value;
46    }
47
48    function render($mode, &$R, &$T, $value, $hint) {
49        // render internal link
50        // (':' is prepended to make sure we use an absolute pagename,
51        // internallink resolves page names, but the name is already resolved.)
52        $R->internallink(':'.$value);
53    }
54
55    function getInfo() {
56        return array(
57            'desc'=>'Links to a wiki page. The optional hint is treated as namespace for the link. If the hint ends with a #, all values will be treated as fragments.',
58            'hint'=>'namespace'
59        );
60    }
61}
62