Revision history for LinkUsingPageTitle
Additions:
>>Working for 1.3.6 (and probably prior versions)>>With the advent of the new pagetitle column in table pages it's now a lot easier to patch this functionality.
In ##libs/Wakka.class.php## change the beginning of function Link() from
function Link($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
$get_title = 0;
if (!$text) {
$text = $tag;
to
function Link($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
$get_title = 0;
if (!$text) {
$text = $tag;
if ($this->GetConfigValue('link_using_page_title') == 1) $text = $this->PageTitle($tag);
====Older versions====
===Additions===
In ##libs/Wakka.class.php## change the beginning of function Link() from
function Link($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
$get_title = 0;
if (!$text) {
$text = $tag;
to
function Link($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
$get_title = 0;
if (!$text) {
$text = $tag;
if ($this->GetConfigValue('link_using_page_title') == 1) $text = $this->PageTitle($tag);
====Older versions====
===Additions===
Deletions:
Revision [20998]
Edited on 2010-01-13 13:55:02 by GregorLindner [works. But needs better documentation on this page]Additions:
>>Working for 1.1.6.0 to 1.2
Deletions:
Additions:
Positions of changes in code have changed. #%CTRL+F#% is your friend.>>One of the things I was immediately annoyed with was the fact that Wiki links used the tag, and not the page title, when a link is created, unless you specified the link text yourself. It is much better, imho, to automatically fetch the page title, and use that as the link text. And so I went to work on this. It's not too hard to implement this, and only required you to edit parts of wikka.php.
Deletions:
Additions:
>>Working for 1.1.6.0 to 1.1.6.4
Positions of changes in code have changed. STRG+F is your friend.>>One of the things I was immediately annoyed with was the fact that Wiki links used the tag, and not the page title, when a link is created, unless you specified the link text yourself. It is much better, imho, to automatically fetch the page title, and use that as the link text. And so I went to work on this. It's not too hard to implement this, and only required you to edit parts of wikka.php.
Positions of changes in code have changed. STRG+F is your friend.>>One of the things I was immediately annoyed with was the fact that Wiki links used the tag, and not the page title, when a link is created, unless you specified the link text yourself. It is much better, imho, to automatically fetch the page title, and use that as the link text. And so I went to work on this. It's not too hard to implement this, and only required you to edit parts of wikka.php.
Deletions:
Revision [18892]
Edited on 2008-01-28 00:13:02 by MasinAlDujaili [Modified links pointing to docs server]No Differences
Additions:
~-++rewrite PageTitle() to strip page titles of every formatting string like ""//"", ""**"" and so on -- is there any function doing just that?.++
~-The fix for forced links doesn't work with this implementation. Further investigation showed, that pagetitles containig links to the page itself result in endless loops. This might also happen if two or more pages refer to another in circular fashion. Circular references need to be detected. See http://gio.larp-bb.de/SandBox
~-The fix for forced links doesn't work with this implementation. Further investigation showed, that pagetitles containig links to the page itself result in endless loops. This might also happen if two or more pages refer to another in circular fashion. Circular references need to be detected. See http://gio.larp-bb.de/SandBox
Deletions:
Revision [14664]
Edited on 2006-06-21 12:38:13 by MasinAlDujaili [updated to 1.1.6.2, made linking using page titles configurable]Additions:
Put into ##wikka.config.php## the following line:
"link_using_page_title" => "1",
function Link($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
$get_title = 0;
if (!$text) {
$text = $tag;
if ($this->GetConfigValue('link_using_page_title') == 1) $get_title = 1;
$tag = $this->htmlspecialchars_ent($tag); #142 & #148
$method = $this->htmlspecialchars_ent($method);
$title = $this->htmlspecialchars_ent($title);
if($get_title && $linkedPage) {
$text = $this->PageTitle($linkedPage['body'], 'yes');
function PageTitle($text='', $link='no') {
$title = "";
// Edit by Stefan Koopmanschap: argument should be possible
if($text=='') {
$pagecontent = $this->page["body"];
} else {
$pagecontent = $text;
if (ereg( "(=){3,5}([^=\n]+)(=){3,5}", $pagecontent, $title)) {
$formatting_tags = array("**", "//", "__", "##", "''", "++", "#%", "@@", "\"\"");
$title = str_replace($formatting_tags, "", $title[2]);
// if ($title) return strip_tags($this->Format($title)); # fix for forced links in heading
if ($title) return $title;
else {
if($link=='no') {
return $this->GetPageTag();
} else {
return '';
~-rewrite PageTitle() to strip page titles of every formatting string like ""//"", ""**"" and so on -- is there any function doing just that?. The fix for forced links doesn't work with this implementation. See http://gio.larp-bb.de/SandBox
Find the following lines (check in the vicinity of line 270) in ##formatters/wakka.php##:
"link_using_page_title" => "1",
function Link($tag, $method='', $text='', $track=TRUE, $escapeText=TRUE, $title='') {
$get_title = 0;
if (!$text) {
$text = $tag;
if ($this->GetConfigValue('link_using_page_title') == 1) $get_title = 1;
$tag = $this->htmlspecialchars_ent($tag); #142 & #148
$method = $this->htmlspecialchars_ent($method);
$title = $this->htmlspecialchars_ent($title);
if($get_title && $linkedPage) {
$text = $this->PageTitle($linkedPage['body'], 'yes');
function PageTitle($text='', $link='no') {
$title = "";
// Edit by Stefan Koopmanschap: argument should be possible
if($text=='') {
$pagecontent = $this->page["body"];
} else {
$pagecontent = $text;
if (ereg( "(=){3,5}([^=\n]+)(=){3,5}", $pagecontent, $title)) {
$formatting_tags = array("**", "//", "__", "##", "''", "++", "#%", "@@", "\"\"");
$title = str_replace($formatting_tags, "", $title[2]);
// if ($title) return strip_tags($this->Format($title)); # fix for forced links in heading
if ($title) return $title;
else {
if($link=='no') {
return $this->GetPageTag();
} else {
return '';
~-rewrite PageTitle() to strip page titles of every formatting string like ""//"", ""**"" and so on -- is there any function doing just that?. The fix for forced links doesn't work with this implementation. See http://gio.larp-bb.de/SandBox
Find the following lines (check in the vicinity of line 270) in ##formatters/wakka.php##:
Deletions:
if (!$linktext)
$text = $tag;
$text = $linktext;
}
// Edit by Stefan Koopmanship, re-edit by Masin Al-Dujaili, get link text
if($linktext=='' && $linkedPage) {
$text = $this->PageTitle($linkedPage['body'], 'yes');
}
%%(php) function PageTitle($text='', $link='no') {
$title = "";
// Edit by Stefan Koopmanschap: argument should be possible
if($text=='') {
$pagecontent = $this->page["body"];
} else {
$pagecontent = $text;
if (ereg( "(=){3,5}([^=\n]+)(=){3,5}", $pagecontent, $title)) {
$formatting_tags = array("**", "//", "__", "##", "''", "++", "#%", "@@", "\"\"");
$title = str_replace($formatting_tags, "", $title[2]);
if ($title!='') { return $title; }
else {
if($link=='no') {
return $this->GetPageTag();
} else {
return '';
}
}%%
~-rewrite PageTitle() to strip page titles of every formatting string like ""//"", ""**"" and so on -- is there any function doing just that?
Find the following lines (check in the vicinity of line 250) in ##formatters/wakka.php##:
Additions:
%%(php)
function Link($tag, $method='', $linktext='', $track=TRUE, $escapeText=TRUE, $title='') {
if($linktext=='' && $linkedPage) {
$text = $this->htmlspecialchars_ent($text);
~-++check if wakka.php can be modified to call Link() the same way for wiki links and forced links (see comment)++
====Additions====
Find the following lines (check in the vicinity of line 250) in ##formatters/wakka.php##:
%%(php)
list (, $url, , $text) = $matches;
if ($url)
//if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>";
if (!$text) $text = $url;
//$text=preg_replace("/@@|££|\[\[/","",$text);
return $result.$wakka->Link($url, "", $text);
Comment out ##if(!text) $text = $url;## to let the function Link() in ##wikka.php## decide which text to use as link text:
%%(php)
list (, $url, , $text) = $matches;
if ($url)
//if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>";
//if (!$text) $text = $url;
//$text=preg_replace("/@@|££|\[\[/","",$text);
return $result.$wakka->Link($url, "", $text);
function Link($tag, $method='', $linktext='', $track=TRUE, $escapeText=TRUE, $title='') {
if($linktext=='' && $linkedPage) {
$text = $this->htmlspecialchars_ent($text);
~-++check if wakka.php can be modified to call Link() the same way for wiki links and forced links (see comment)++
====Additions====
Find the following lines (check in the vicinity of line 250) in ##formatters/wakka.php##:
%%(php)
list (, $url, , $text) = $matches;
if ($url)
//if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>";
if (!$text) $text = $url;
//$text=preg_replace("/@@|££|\[\[/","",$text);
return $result.$wakka->Link($url, "", $text);
Comment out ##if(!text) $text = $url;## to let the function Link() in ##wikka.php## decide which text to use as link text:
%%(php)
list (, $url, , $text) = $matches;
if ($url)
//if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>";
//if (!$text) $text = $url;
//$text=preg_replace("/@@|££|\[\[/","",$text);
return $result.$wakka->Link($url, "", $text);
Deletions:
if($linktext=='') {
else $text = $this->htmlspecialchars_ent($text);
~-check if wakka.php can be modified to call Link() the same way for wiki links and forced links (see comment)
Additions:
The PageTitle() method now does not automatically take the current page content, but instead also allows for arguments to be passed. The first argument is, obviously, the full body text of the linked page, from which the title should be extracted. The second argument is there to ensure backward compatibility: If there is no page title in the passed text, I'd want it to pass back an empty value instead of the PageTag of the current page. Thus, when called in the Link() method, the second argument is passed a 'yes' value (but this could be anything other than 'no'). By default this is a 'no' value, which will result in the PageTag of the current page being passed back.
To do:
~-rewrite PageTitle() to strip page titles of every formatting string like ""//"", ""**"" and so on -- is there any function doing just that?
~-check if wakka.php can be modified to call Link() the same way for wiki links and forced links (see comment)
To do:
~-rewrite PageTitle() to strip page titles of every formatting string like ""//"", ""**"" and so on -- is there any function doing just that?
~-check if wakka.php can be modified to call Link() the same way for wiki links and forced links (see comment)
Deletions:
Additions:
%%(php) function Link($tag, $method='', $linktext='', $track=TRUE, $escapeText=TRUE, $title='') {
if (!$linktext)
{
$text = $tag;
}
else
{
$text = $linktext;
if ($escapeText) $text = $this->htmlspecialchars_ent($text);
$url = '';
// 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
}
// 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);
// Edit by Stefan Koopmanship, re-edit by Masin Al-Dujaili, get link text
if($linktext=='') {
$text = $this->PageTitle($linkedPage['body'], 'yes');
if($text=='') $text = $tag;
else $text = $this->htmlspecialchars_ent($text);
// 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=\"$title\">".$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 $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
if (!$linktext)
{
$text = $tag;
}
else
{
$text = $linktext;
if ($escapeText) $text = $this->htmlspecialchars_ent($text);
$url = '';
// 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
}
// 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);
// Edit by Stefan Koopmanship, re-edit by Masin Al-Dujaili, get link text
if($linktext=='') {
$text = $this->PageTitle($linkedPage['body'], 'yes');
if($text=='') $text = $tag;
else $text = $this->htmlspecialchars_ent($text);
// 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=\"$title\">".$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 $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
Deletions:
if (!$text) $text = $tag;
if ($escapeText) $text = $this->htmlspecialchars_ent($text);
$url = '';
// 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
// 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
// Edit by Stefan Koopmanschap, get link text
$page = $this->loadPage($tag);
$text = $this->PageTitle($page['body'], 'yes');
$text = $tag;
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=\"$title\">".$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 $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
}
The main change to this function is right after my comment:
%%(php) // Edit by Stefan Koopmanschap, get link text
$page = $this->loadPage($tag);
$text = $this->PageTitle($page['body'], 'yes');
$text = $tag;
}%%
Revision [13119]
Edited on 2006-02-09 07:07:06 by OwenKelly [Stefan's change was in the wrong place. he has placed it at the start of the function with the conse]Additions:
// escape text?
// Edit by Stefan Koopmanschap, get link text
Deletions:
// escape text?
Revision [10425]
Edited on 2005-08-04 08:54:25 by StefanKoopmanschap [Stefan's change was in the wrong place. he has placed it at the start of the function with the conse]Additions:
CategoryUserContributions