====== Externallink Plugin ====== ---- plugin ---- description: Add links to pages in same host, but outside wiki author : Otto Vainio email : otto@valjakko.net type : Syntax lastupdate : 2005-08-01 compatible : depends : conflicts : similar : tags : links downloadurl: http://koti.mbnet.fi/oiv/pubtest/externallink.zip ---- ===== 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 ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. ''lib/plugins/externallink/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/plugin:externallink', ); } /** * 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, Doku_Handler $handler){ $match = substr($match,3,-2); //strip [[@ from start and ]] from end $match = explode("|",$match); return $match; } /** * Create output */ function render($mode, Doku_Renderer $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 [[plugin:baselink]] plugin? > Well in someway yes. The format is different, and [[plugin:baselink]] gives you more options. Choice is yours ;-) --- //[[otto@valjakko.net|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@valjakko.net|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@rollerorgans.com]] 2007-02-26 >> Fixed. --- //[[otto@valjakko.net|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@ringlogic.com|Bering]] 2009-11-13 10:31// ---- Plugin doesn't work on Release 2012-10-13 "Adora Belle" Url leads to Dokuwiki basedir, but not web server root dir ---- Fix functions arguments in ''externallink/syntax.php'' is enough to run this plugin under 2020-07-29 "Hogfather". function handle($match, $state, $pos, Doku_Handler $handler) {} function render($mode, Doku_Renderer $renderer, $data) {} -- //[[robert.kalinowski@sharkbits.com|rysson]] 2020-10-04 15:52//