This is an old revision of the document!
Table of Contents
Externallink plugin
Compatible with DokuWiki
No compatibility info given!
The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Description
With this plugin you can easily insert a link to pages on same server, but outside DokuWiki.
Format
[[@/somewhere/somepage.html|And possibly some title]]
The link naming follows normal HTML hyperlink naming. If it starts with a slash, then the link is absolute. Without a slash the link is relative.
If your dokuwiki is in http://localhost:88/dokuwiki/doku.php Then links
[[@page|name]] links to http://localhost:88/dokuwiki/doku.php/page [[@/page|name]] links to http://localhost:88/page [[@?do=recent|name]] links to http://localhost:88/dokuwiki/doku.php/?do=recent
Installation
Install with Plugin Manager from here (new version without svchk call)
Or manually
Create a new folder lib/plugins/externallink/
and place the following file in it: syntax.php
.
lib/plugins/externallink/syntax.php
:
<?php /** * Plugin bookmark: Creates a bookmark to your document. * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Otto Vainio <plugins@valjakko.net> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_externallink extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Otto Vainio', 'email' => 'plugins@valjakko.net', 'date' => '2007-02-26', 'name' => 'externallink', 'desc' => 'Inserts a link to a page outside your wiki, but on your server with a style of wikilink. Format is [[@/pagename|optional title]]', 'url' => 'http://www.dokuwiki.org/wiki:plugins', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } // Just before build in links function getSort(){ return 299; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\[\[\@.*?\]\]',$mode,'plugin_externallink'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ $match = substr($match,3,-2); //strip [[@ from start and ]] from end $match = explode("|",$match); return $match; } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ $text=$this->_externallink($renderer, $data[0], $data[1]); $renderer->doc .= $text; return true; } return false; } function _externallink(&$renderer, $url, $name = NULL) { global $conf; // Just some basic cleaning if(substr($url,0,7) == 'http://') { list($foo,$url) = explode("/",substr($url,7),2); } if(substr($url,0,5) == 'ftp://') { list($foo,$url) = explode("/",substr($url,6),2); } if (!isset($name)) { if (substr($url,0,1)=="/") { $name=$_SERVER['HTTP_HOST'] . $url; } elseif (substr($url,0,1)=="?") { $name=$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $url; } else { $name=$_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $url; } } // $name = $renderer->_xmlEntities($renderer->_getLinkTitle($name, $url, $isImage)); $name = $renderer->_getLinkTitle($name, $url, $isImage); $class='wikilink1'; $link['target'] = $conf['target']['wiki']; $link['style'] = ''; $link['pre'] = ''; $link['suf'] = ''; $link['more'] = ''; $link['class'] = $class; $link['url'] = $url; $link['name'] = $name; $link['title'] = $renderer->_xmlEntities($url); //output formatted return $renderer->_formatLink($link); } } ?>
Versions
11.1.2006 Initial version
Discussion
Is this plugin superseded by the baselink plugin?
Well in someway yes. The format is different, and baselink gives you more options. Choice is yours — Otto Vainio 2006-04-05 18:51
I think, the use of _xmlEntities() is not necessary and in fact leads to problems.
Example:
[[@/someurl|This & that]]
This will always render as: This & that
Why? Well - when entering such text, special characters, like ampersand or “<” and “>” are already stored as “&”, “<” and so on. In fact all special characters are stored in a form, which never needs any conversion. A conversion may only be necessary, when editing the text files manually without DokuWiki - but who does this?
BTW: DokuWiki itself does it correct: A link like
[[somepage|This & that]]
will render correct as: This & that
Ok. Thanks for reporting that. I have now fixed the source above and the zip package for pluginmanager. — Otto Vainio 2006-04-11 09:40
Note that the JavaScript function “svchk()” no longer exists (and is now unnecessary) in DokuWiki, and does cause JavaScript errors, so references should be removed.
– todd [at] rollerorgans [dot] com 2007-02-26
Fixed. — Otto Vainio 2007-02-26 21:56
I configured my Wiki to open external links in new pages by setting the external links target to _blank using the configuration manager. So I noticed that the plugin does not use the right setting. I had to change line 93 from
$conf["target"]["wiki"];
to
$conf["target"]["extern"];
And it's working like a charm now.
– Bering 2009-11-13 10:31