Translations of this page?:

Base Links

:!: The functionality provided by these modifications is now available via the baselink plugin.

In the file inc/parser/handler.php, locate the internallink() method of the Doku_Handler class (it starts around line 384) and make the following change:

        }elseif ( preg_match('/^\\\\\\\\[\w.:?\-;,]+?\\\\/u',$link[0]) ) {
        // Windows Share
            $this->_addCall(
                'windowssharelink',
                array($link[0],$link[1]),
                $pos
                );
// --8<--8<--8<--8<--8<--8<--8<-- code below is new --8<--8<--8<--8<--8<--8<--8<--
        }elseif ( preg_match('#^\@.+#i',$link[0]) ) {
        // relative external link
            $this->_addCall(
                    'externallink',
                    array(getBaseUrl(true).substr($link[0],1),$link[1]),
                    $pos
                    );
// --8<--8<--8<--8<--8<--8<--8<-- code above is new --8<--8<--8<--8<--8<--8<--8<--
        }elseif ( preg_match('#^([a-z0-9]+?)://#i',$link[0]) ) {
        // external link (accepts all protocols)
            $this->_addCall(
                    'externallink',
                    array($link[0],$link[1]),
                    $pos
                    );

You can now use base links style, with eg: [[@downloads/files|Download directory]] or [[@phpmyadmin]] or anything in that style. Just start the URL with a '@'. The url will transform into: http://www.yoursite.com/dokuwiki/downloads/files or http://www.yoursite.com/dokuwiki/phpmyadmin

A modified version

I would rather that unnamed links (those without a ”|name of link]]” at the end) be displayed simply as they were typed. Hence instead of displaying http://www.yourdomain.com/dokuwiki/namespace/page it would display /namespace/page. This can be done by the addition of a new line which checks if $link[1] is set, and updates $link[0] appropriately.

Also I prefer to use a leading '/' to mark one of these in the wiki syntax, and not the '@' of the above. I justify this change on the basis that '/' is the traditional way of marking a path relative to the site root, while ':' is the wiki way of doing things - I always use ':' in my inter-site wiki links already. This is done by swapping the '\@' in the regexp to a simple '/'. (Note two characters become one, as '/' does not require escaping).

Below is my version of the above modification.

        }elseif ( preg_match('#^/.+#i',$link[0]) ) {
        // relative external link
            if(!isset($link[1])){$link[1] = $link[0];}
            $this->_addCall(
                    'externallink',
                    array(getBaseUrl(true).substr($link[0],1),$link[1]),
                    $pos
                    );

Robert Meerman 2005/07/21 15:58

Note: '/' does not need to be escaped IF you use the '#' as the regex start/end marker as this expression does. The most common regex delimiter you will see is a '/' so the expression is is '/regex/options' and, in those cases. '/' does need to be escaped in the expression just as # would above. The best practice is to select the delimiter as something otherwise unused in your expression.

Puzzlers.org webmaster 2005/12/10

Using Dokuwiki in a sub folder

I run Dokuwiki in a subfolder and need “base links” to connect with other folders at the top of my website. I needed to change the creation of links so that I excluded the dokuwiki folder.

// --8<--8<--8<--8<--8<--8<--8<-- code below is new --8<--8<--8<--8<--8<--8<--8<--
        }elseif ( preg_match('#^/.+#i',$link[0]) ) {
        // relative external link -- starts with /
            if(!isset($link[1])){$link[1] = $link[0];}
            $this->_addCall(
                    'externallink',
                    //array(getBaseUrl(true).substr($link[0],1),$link[1]),   // getBaseURL returns "/dokuwiki/"
                    array('/'.substr($link[0],1),$link[1]),   // be sure to add the prefix '/' to start at the root
                    $pos
                    );
// --8<--8<--8<--8<--8<--8<--8<-- code above is new --8<--8<--8<--8<--8<--8<--8<--

Puzzlers.org webmaster 2005/12/10

 
wiki/tips/base_links.txt · Last modified: 2006/03/06 16:48 by 87.228.152.54
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate