Example #1
0
function ParseAndLink($bracketlink) {
      global $ScriptUrl, $AllowedProtocols, $InlineImages;
           
      preg_match("/(\[\s*)(.+?)(\s*\])/", $bracketlink, $match);
      
      preg_match("/([^|]+)(\|)?([^|]+)?/", $match[2], $matches);

      if (isset($matches[3])) {
         
         $URL = trim($matches[3]);
         $linkname = htmlspecialchars(trim($matches[1]));
     $linktype = 'named';
      } else {
         
         $URL = trim($matches[1]);
     $linkname = '';
     $linktype = 'simple';
      }

      if (preg_match("#^($AllowedProtocols):#", $URL)) {
        // if it's an image, embed it; otherwise, it's a regular link
         if (preg_match("/($InlineImages)$/i", $URL)) {
        $link['type'] = "image-$linktype";
            $link['link'] = LinkImage($URL, $linkname);
         } else {
        $link['type'] = "url-$linktype";
            $link['link'] = LinkURL($URL, $linkname);
         }
      } elseif (preg_match("#^\d+$#", $URL)) {
         $link['type'] = "reference-$linktype";
     $link['link'] = $URL;
      } else {
     $link['type'] = "wiki-unknown-$linktype";
         $link['link'] = LinkUnknown($URL, $linkname);
      }

      return $link;
   }
Example #2
0
 function markup($match)
 {
     $page = substr($match, 2, -2);
     // Check for predefined icons.
     $predefinedicons = array(":)" => "ic_smile.png", ":(" => "ic_sad.png", ":P" => "ic_tongue.png", ":D" => "ic_biggrin.png", ";)" => "ic_wink.png", "(y)" => "ic_handyes.png", "(n)" => "ic_handno.png", "(i)" => "ic_info.png", "(/)" => "ic_check.png", "(x)" => "ic_cross.png", "(!)" => "ic_danger.png", "(+)" => "ic_plus.png", "(-)" => "ic_minus.png", "(?)" => "ic_help.png", "(on)" => "ic_lighton.png", "(off)" => "ic_lightoff.png", "(*)" => "ic_yellowstar.png", "(*r)" => "ic_redstar.png", "(*g)" => "ic_greenstar.png", "(*b)" => "ic_bluestar.png", "(*y)" => "ic_yellowstar.png");
     foreach ($predefinedicons as $ascii => $icon) {
         if (trim($page) == $ascii) {
             return LinkImage(DATA_PATH . "/themes/default/images/{$icon}", $page);
         }
     }
     if (strpos($page, "|") === false) {
         $imagename = $page;
         $alt = "";
     } else {
         $imagename = substr($page, 0, strpos($page, "|"));
         $alt = ltrim(strstr($page, "|"), "|");
     }
     // It's not a Mediawiki template, it's a Wikicreole image
     if (is_image($imagename)) {
         if ($imagename[0] == '/') {
             return LinkImage(DATA_PATH . '/' . $imagename, $alt);
         } else {
             return LinkImage(getUploadDataPath() . $imagename, $alt);
         }
     }
     // It's a video
     if (is_video($imagename)) {
         $s = '<' . '?plugin Video file="' . $imagename . '" ?' . '>';
         return new Cached_PluginInvocation($s);
     }
     $page = str_replace("\n", "", $page);
     $vars = '';
     if (preg_match('/^(\\S+?)\\|(.*)$/', $page, $_m)) {
         $page = $_m[1];
         $vars = '"' . preg_replace('/\\|/', '" "', $_m[2]) . '"';
         $vars = preg_replace('/"(\\S+)=([^"]*)"/', '\\1="\\2"', $vars);
     }
     // page may contain a version number
     // {{foo?version=5}}
     // in that case, output is "page=foo rev=5"
     if (strstr($page, "?")) {
         $page = str_replace("?version=", "\" rev=\"", $page);
     }
     if ($vars) {
         $s = '<' . '?plugin Template page="' . $page . '" ' . $vars . ' ?' . '>';
     } else {
         $s = '<' . '?plugin Template page="' . $page . '" ?' . '>';
     }
     return new Cached_PluginInvocation($s);
 }
Example #3
0
function LinkBracketLink($bracketlink)
{
    // $bracketlink will start and end with brackets; in between will
    // be either a page name, a URL or both separated by a pipe.
    // strip brackets and leading space
    // FIXME: \n inside [] will lead to errors
    preg_match('/(\\#?) \\[\\s* (?: (.*?) \\s* (?<!' . ESCAPE_CHAR . ')(\\|) )? \\s* (.+?) \\s*\\]/x', $bracketlink, $matches);
    if (count($matches) < 4) {
        trigger_error(_("Invalid [] syntax ignored") . ": " . $bracketlink, E_USER_WARNING);
        return new Cached_Link();
    }
    list(, $hash, $label, $bar, $rawlink) = $matches;
    $label = UnWikiEscape($label);
    /*
     * Check if the user has typed a explicit URL. This solves the
     * problem where the URLs have a ~ character, which would be stripped away.
     *   "[http:/server/~name/]" will work as expected
     *   "http:/server/~name/"   will NOT work as expected, will remove the ~
     */
    if (strstr($rawlink, "http://") or strstr($rawlink, "https://")) {
        $link = $rawlink;
        // Mozilla Browser URI Obfuscation Weakness 2004-06-14
        //   http://www.securityfocus.com/bid/10532/
        //   goodurl+"%2F%20%20%20."+badurl
        if (preg_match("/%2F(%20)+\\./i", $rawlink)) {
            $rawlink = preg_replace("/%2F(%20)+\\./i", "%2F.", $rawlink);
        }
    } else {
        $link = UnWikiEscape($rawlink);
    }
    /* Relatives links by Joel Schaubert.
     * Recognize [../bla] or [/bla] as relative links, without needing http://
     */
    /* if (preg_match('/^(\.\.\/|\/)/', $link)) {
           return new Cached_ExternalLink($link, $label);
       }*/
    // [label|link]
    // if label looks like a url to an image, we want an image link.
    if (isImageLink($label)) {
        $imgurl = $label;
        $intermap = getInterwikiMap();
        if (preg_match("/^" . $intermap->getRegexp() . ":/", $label)) {
            $imgurl = $intermap->link($label);
            $imgurl = $imgurl->getAttr('href');
        } elseif (!preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $imgurl)) {
            // local theme linkname like 'images/next.gif'.
            global $WikiTheme;
            $imgurl = $WikiTheme->getImageURL($imgurl);
        }
        $label = LinkImage($imgurl, $link);
    }
    if ($hash) {
        // It's an anchor, not a link...
        $id = MangleXmlIdentifier($link);
        return HTML::a(array('name' => $id, 'id' => $id), $bar ? $label : $link);
    }
    if (preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $link)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (isImageLink($link)) {
            return LinkImage($link, $label);
        } else {
            return new Cached_ExternalLink($link, $label);
        }
    } elseif (preg_match("/^phpwiki:/", $link)) {
        return new Cached_PhpwikiURL($link, $label);
    } elseif (strstr($link, ':') and $intermap = getInterwikiMap() and preg_match("/^" . $intermap->getRegexp() . ":/", $link)) {
        // trigger_error("label: $label link: $link", E_USER_WARNING);
        if (empty($label) and isImageLink($link)) {
            // if without label => inlined image [File:xx.gif]
            $imgurl = $intermap->link($link);
            return LinkImage($imgurl->getAttr('href'), $label);
        }
        return new Cached_InterwikiLink($link, $label);
    } else {
        // Split anchor off end of pagename.
        if (preg_match('/\\A(.*)(?<!' . ESCAPE_CHAR . ')#(.*?)\\Z/', $rawlink, $m)) {
            list(, $rawlink, $anchor) = $m;
            $pagename = UnWikiEscape($rawlink);
            $anchor = UnWikiEscape($anchor);
            if (!$label) {
                $label = $link;
            }
        } else {
            $pagename = $link;
            $anchor = false;
        }
        return new Cached_WikiLink($pagename, $label, $anchor);
    }
}
Example #4
0
 function expand($basepage, &$markup)
 {
     global $WikiTheme;
     $this->_basepage = $basepage;
     $label = isset($this->_label) ? $this->_label : false;
     if ($WikiTheme->DUMP_MODE) {
         // In case of static dumps we need to check if we should
         // inline the image or not: external: keep link, internal: copy locally
         return LinkImage($label);
     } else {
         return LinkImage($label);
     }
 }
Example #5
0
 function _match(&$input, $m)
 {
     $pos = $input->getPos();
     $pi = $m->postmatch;
     if ($pi[0] == '{') {
         return false;
     }
     while (!preg_match('/(?<!' . ESCAPE_CHAR . ')}}\\s*$/', $pi)) {
         if (($line = $input->nextLine()) === false) {
             $input->setPos($pos);
             return false;
         }
         $pi .= "\n{$line}";
     }
     $input->advance();
     $pi = trim($pi);
     $pi = trim($pi, "}}");
     if (strpos($pi, "|") === false) {
         $imagename = $pi;
         $alt = "";
     } else {
         $imagename = substr($pi, 0, strpos($pi, "|"));
         $alt = ltrim(strstr($pi, "|"), "|");
     }
     // It's not a Mediawiki template, it's a Wikicreole image
     if (is_image($imagename)) {
         $this->_element = LinkImage(getUploadDataPath() . $imagename, $alt);
         return true;
     }
     // It's a video
     if (is_video($imagename)) {
         $pi = '<' . '?plugin Video file="' . $pi . '" ?>';
         $this->_element = new Cached_PluginInvocation($pi);
         return true;
     }
     $pi = str_replace("\n", "", $pi);
     $vars = '';
     if (preg_match('/^(\\S+?)\\|(.*)$/', $pi, $_m)) {
         $pi = $_m[1];
         $vars = '"' . preg_replace('/\\|/', '" "', $_m[2]) . '"';
         $vars = preg_replace('/"(\\S+)=([^"]*)"/', '\\1="\\2"', $vars);
     }
     // pi may contain a version number
     // {{foo?version=5}}
     // in that case, output is "page=foo rev=5"
     if (strstr($pi, "?")) {
         $pi = str_replace("?version=", "\" rev=\"", $page);
     }
     if ($vars) {
         $pi = '<' . '?plugin Template page="' . $pi . '" ' . $vars . ' ?>';
     } else {
         $pi = '<' . '?plugin Template page="' . $pi . '" ?>';
     }
     $this->_element = new Cached_PluginInvocation($pi);
     return true;
 }
Example #6
0
    $new = '';
    while (preg_match("/^(.*?)({$pattern})/", $str, $matches)) {
        $linktoken = $FieldSeparator . $FieldSeparator . $ntokens++ . $FieldSeparator;
        $new .= $matches[1] . $linktoken;
        $orig[] = $matches[2];
        $str = substr($str, strlen($matches[0]));
    }
    $new .= $str;
    return $new;
}
// Prepare replacements for references [\d+]
for ($i = 1; $i < NUM_LINKS + 1; $i++) {
    if (!empty($pagehash['refs'][$i])) {
        if (preg_match("/({$InlineImages})\$/i", $pagehash['refs'][$i])) {
            // embed images
            $embedded[$i] = LinkImage($pagehash['refs'][$i]);
        } else {
            // ordinary link
            $embedded[$i] = LinkURL($pagehash['refs'][$i], "[{$i}]");
        }
    }
}
// Loop over all lines of the page and apply transformation rules
$numlines = count($pagehash["content"]);
for ($index = 0; $index < $numlines; $index++) {
    unset($tokens);
    unset($replacements);
    $ntokens = 0;
    $replacements = array();
    $tmpline = $pagehash['content'][$index];
    if (!strlen($tmpline) || $tmpline == "\r") {
Example #7
0
function ParseAndLink($bracketlink)
{
    global $dbi, $ScriptUrl, $AllowedProtocols, $InlineImages;
    // $bracketlink will start and end with brackets; in between
    // will be either a page name, a URL or both separated by a pipe.
    // strip brackets and leading space
    preg_match("/(\\[\\s*)(.+?)(\\s*\\])/", $bracketlink, $match);
    // match the contents
    preg_match("/([^|]+)(\\|)?([^|]+)?/", $match[2], $matches);
    if (isset($matches[3])) {
        // named link of the form  "[some link name | http://blippy.com/]"
        $URL = trim($matches[3]);
        $linkname = htmlspecialchars(trim($matches[1]));
        $linktype = 'named';
    } else {
        // unnamed link of the form "[http://blippy.com/] or [wiki page]"
        $URL = trim($matches[1]);
        $linkname = '';
        $linktype = 'simple';
    }
    if (IsWikiPage($dbi, $URL)) {
        $link['type'] = "wiki-{$linktype}";
        $link['link'] = LinkExistingWikiWord($URL, $linkname);
    } elseif (preg_match("#^({$AllowedProtocols}):#", $URL)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (preg_match("/({$InlineImages})\$/i", $URL)) {
            $link['type'] = "image-{$linktype}";
            $link['link'] = LinkImage($URL, $linkname);
        } else {
            $link['type'] = "url-{$linktype}";
            $link['link'] = LinkURL($URL, $linkname);
        }
    } elseif (preg_match("#^phpwiki:(.*)#", $URL, $match)) {
        $link['type'] = "url-wiki-{$linktype}";
        if (empty($linkname)) {
            $linkname = htmlspecialchars($URL);
        }
        $link['link'] = "<a href=\"{$ScriptUrl}{$match['1']}\">{$linkname}</a>";
    } elseif (preg_match("#^\\d+\$#", $URL)) {
        $link['type'] = "reference-{$linktype}";
        $link['link'] = $URL;
    } else {
        $link['type'] = "wiki-unknown-{$linktype}";
        $link['link'] = LinkUnknownWikiWord($URL, $linkname);
    }
    return $link;
}