For
WikkaWiki.
This hack will turn a link to a jpg, png, or gif into an image on the page. When using the forced link notation ([[ ]]), anything typed after the link becomes the alt text for the image.
Replace the Link() function in libs/Wakka.class.php with the following (only the "by jpd" commented lines are changes from the original)
/**
* Link
*
* Beware of the $title parameter: quotes and backslashes should be previously escaped before passed to
* this method.
*
* @param mixed $tag
* @param string $method
* @param string $text
* @param boolean $track
* @param boolean $escapeText
* @param string $title
* @access public
* @return string
*/
function Link($tag,
$method=
'',
$text=
'',
$track=
TRUE,
$escapeText=
TRUE,
$title=
'') {
if (!
$text) $text =
$tag;
// escape text?
if ($escapeText) $text =
$this->
htmlspecialchars_ent($text);
$tag =
$this->
htmlspecialchars_ent($tag);
#142 & #148
$method =
$this->
htmlspecialchars_ent($method);
$title_attr =
$title ?
' title="'.
$this->
htmlspecialchars_ent($title).
'"' :
'';
$url =
'';
$img =
'';
// added by jpd
// is this an interwiki link?
if (preg_match("/^([A-ZÄÖÜ][A-Za-zÄÖÜßäöü]+)[:](\S*)$/",
$tag,
$matches)) # before the : should be a WikiName; anything after can be (nearly) anything that's allowed in a URL
{
$url =
$this->
GetInterWikiUrl($matches[1],
$matches[2]);
}
elseif (preg_match("/^(http|https|ftp):\/\/([^\\s\"<>]+)$/",
$tag))
{
$url =
$tag;
// this is a valid external URL
// following lines added by jpd - find out if this is a link to an image
$endname =
substr(rtrim($tag),
-4);
if ( (!
strcasecmp($endname,
".gif")) ||
(!
strcasecmp($endname,
".png")) ||
(!
strcasecmp($endname,
".jpg")) )
{
$img =
$tag;
// this is a valid external image
$url =
'';
}
// end added by jpd
}
// is this a full link? ie, does it contain alpha-numeric characters?
elseif (preg_match("/[^[:alnum:],ÄÖÜ,ßäöü]/",
$tag))
{
// check for email addresses
if (preg_match("/^.+\@.+$/",
$tag))
{
$url =
"mailto:".
$tag;
}
// check for protocol-less URLs
else if (!
preg_match("/:/",
$tag))
{
$url =
"http://".
$tag;
}
}
else
{
// it's a wiki link
if ($_SESSION["linktracking"] &&
$track) $this->
TrackLinkTo($tag);
$linkedPage =
$this->
LoadPage($tag);
// return ($linkedPage ? "<a href=\"".$this->Href($method, $linkedPage['tag'])."\">".$text."</a>" : "<span class=\"missingpage\">".$text."</span><a href=\"".$this->Href("edit", $tag)."\" title=\"Create this page\">?</a>");
return ($linkedPage ?
"<a href=\"".
$this->
Href($method,
$linkedPage['tag']).
"\"$title_attr>".
$text.
"</a>" :
"<a class=\"missingpage\" href=\"".
$this->
Href("edit",
$tag).
"\" title=\"Create this page\">".
$text.
"</a>");
}
$external_link_tail =
$this->
GetConfigValue("external_link_tail");
// Return condition rewritten by jpd
if ($url) {
return "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail";
} elseif ($img) {
return "<img src=\"$img\" alt=\"$text\" />";
} else {
return $text;
}
}
There are no comments on this page. [Add comment]