/**
  * Render a wiki internal link.
  * In book export mode a local link with a name/test will be inserted if the
  * referenced page is included in the exported pages. Otherwise an external
  * link will be created.
  *
  * @param string       $id   page ID to link to. eg. 'wiki:syntax'
  * @param string|array $name name for the link, array for media file
  *
  * @author Andreas Gohr <*****@*****.**>, LarsDW223
  */
 function internallink($id, $name = NULL)
 {
     global $ID;
     // default name is based on $id as given
     $default = $this->_simpleTitle($id);
     // now first resolve and clean up the $id
     resolve_pageid(getNS($ID), $id, $exists);
     $name = $this->_getLinkTitle($name, $default, $isImage, $id);
     // build the absolute URL (keeping a hash if any)
     list($id, $hash) = explode('#', $id, 2);
     // Is the link a link to a page included in the book?
     $pages = $this->actioninstance->getExportedPages();
     if (in_array($id, $pages)) {
         // Yes, create a local link with a name
         parent::locallink_with_name($hash, $id, $name);
         return;
     }
     // No, create an external link
     $url = wl($id, '', true);
     if ($hash) {
         $url .= '#' . $hash;
     }
     if ($ID == $id) {
         $this->reference($hash, $name);
     } else {
         $this->_doLink($url, $name);
     }
 }
 /**
  * reformat links if needed
  */
 function _formatLink($link)
 {
     // for internal links contains the title the pageid
     if (in_array($link['title'], $this->actioninstance->getExportedPages())) {
         list(, $hash) = explode('#', $link['url'], 2);
         $check = false;
         $pid = sectionID($link['title'], $check);
         $link['url'] = "#" . $pid . '__' . $hash;
     }
     // prefix interwiki links with interwiki icon
     if ($link['name'][0] != '<' && preg_match('/\\binterwiki iw_(.\\w+)\\b/', $link['class'], $m)) {
         if (file_exists(DOKU_INC . 'lib/images/interwiki/' . $m[1] . '.png')) {
             $img = DOKU_BASE . 'lib/images/interwiki/' . $m[1] . '.png';
         } elseif (file_exists(DOKU_INC . 'lib/images/interwiki/' . $m[1] . '.gif')) {
             $img = DOKU_BASE . 'lib/images/interwiki/' . $m[1] . '.gif';
         } else {
             $img = DOKU_BASE . 'lib/images/interwiki.png';
         }
         $link['name'] = '<img src="' . $img . '" width="16" height="16" style="vertical-align: center" class="' . $link['class'] . '" />' . $link['name'];
     }
     return parent::_formatLink($link);
 }