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.

Put into wikka.config.php the following line:
    "link_using_page_title" => "1",


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

Working for 1.1.6.0 to 1.2
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.

Put into wikka.config.php the following line:
    "link_using_page_title" => "1",


The base of the change occurs, obviously, in the Link() method. My new Link() method looks like this:

    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;
        }
        // escape text?
        if ($escapeText) $text = $this->htmlspecialchars_ent($text);
        $tag = $this->htmlspecialchars_ent($tag); #142 & #148
        $method = $this->htmlspecialchars_ent($method);
        $title = $this->htmlspecialchars_ent($title);
        $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);
            if($get_title && $linkedPage) {
                $text = $this->PageTitle($linkedPage['body'], 'yes');
                if($text=='') $text = $tag;
                $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;
    }

I load the page content into $page, and pass on the text to the PageTitle() method for further processing. To be sure that there's always a title, I then check if $text is empty (which could be, if the linked page does not have a formatted page title) and then I end up using the tag anyway.

To accomplish this, I needed to slightly alter the PageTitle() method.

    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 '';
            }
        }
    }


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.

These small changes result in a functioning version of links that contain the PageTitle as linktext, instead of the PageTag. Now all you need to do is create useful PageTitles ;)

A working version of this system can be found on the Electronic Music World Wiki

To do:

Additions

Find the following lines (check in the vicinity of line 270) in formatters/wakka.php:

            list (, $url, , $text) = $matches;
            if ($url)
            {
                //if ($url!=($url=(preg_replace("/@@|&pound;&pound;||\[\[/","",$url))))$result="</span>";
                if (!$text) $text = $url;
                //$text=preg_replace("/@@|&pound;&pound;|\[\[/","",$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:

            list (, $url, , $text) = $matches;
            if ($url)
            {
                //if ($url!=($url=(preg_replace("/@@|&pound;&pound;||\[\[/","",$url))))$result="</span>";
                //if (!$text) $text = $url;
                //$text=preg_replace("/@@|&pound;&pound;|\[\[/","",$text);
                return $result.$wakka->Link($url, "", $text);
            }


CategoryUserContributions
Comments
Comment by DarTar
2005-08-04 11:06:34
Hi Stefan, and welcome to Wikka. Looking at your EMW website you might want to prevent your modified Link method from formatting links to page handlers like /history or /revisions, otherwise RecentChanges becomes a total mess. Nice contribution, though.
Glad to see BTW that the Dutch Wikka community is growing :) You can create your userpage and tell us more about you and your Wikka hacks if you wish.
Comment by StefanKoopmanschap
2005-08-04 11:10:34
Right, the history and revisions titles are now making things a bit awkward. I'll have a look at this later on, see if I can make something out of that.

I'll definately create my userpage later on, when I have a bit more time to burn.
Comment by 128.164.229.250
2005-08-04 16:23:30
Welcome Stefan! :)
Here's another approach -- http://wikka.jsnx.com/UncamelAction.
Best wishes,
Denny
Comment by 193.167.35.217
2006-01-25 03:08:45
Hi, I think this is great. Like you the use of pageTags was something I instantly wanted to change in favour of pageTitles :) I have installed it!

Two points you might want to look at.
1. Links to pages that have not been created yet all show the name of the page they are on, rather than the tag of the unmade page;
2. It would be nice if forced links still worked so that I could use the word "Dylan" in a sentence and have it link to BobDylan, for example.

Great work
Owen
Comment by 193.167.35.217
2006-01-25 04:33:02
Oh and one more :)

3. The links in the footer are replaced by the current page title.
I shall try to find time to poke around and see if a workaround suggests itself :)

Owen
Comment by OwenKelly
2006-02-09 07:09:37
I fixed at least one of the above problems. External links now work properly. All I did was move Stefan's alteration from the top of the function to inside the final "else", where we have already established that we are dealing with a wiki-link.
Comment by MasinAlDujaili
2006-05-19 02:09:05
Okay, more results. In wakka.php, forced links (line 240) and wiki links (line 332) are handled differently. While wiki links get passed to function Link() just with the $tag parameter (line 335), forced links get passed with $tag and $text parameters (line 251). Is there any real reason why it's that way? In function Link(), file wikka.php, line 624 already is an assignment of $tag to $text in case no $text was passed by caller.

Currently, with this extension forced links keep their link text while wiki links don't, because it's only checked for an empty $linktext. I //could// check for equality but that's not what everyone wants in case someone consciently put the name of the forced link as link text -- in which case the forced link's link text would be replaced by the linked page's titel.

Is it safe to remove the $text = $tag assignment in file wakka.php[249]?
Comment by MasinAlDujaili
2006-06-21 12:40:26
Uhm, anybody knows how to get the forced link thingy done correctly?
Comment by DarTar
2006-06-21 20:17:09
> forced links get passed with $tag and $text parameters (line 251). Is there any real reason why it's that way?

Because this is *the* way forced links work: forced links have an optional link text. CamelCase links - by definition - don't.
Comment by MasinAlDujaili
2006-06-22 04:56:08
DarTar - thank you for the explanation. Do you want to take a look at http://gio.larp-bb.de/SandBox
currently the following extensions are installed:
*SmartyPants
*LinkUsingPageTitle
*SideNoteAction
*CommentFormatting

BTW: The problem I had on 2006-05-19 is solved meanwhile. I was to stupid to recognise, that not every forced link is just [[Link]] -- there's still [[Link text]] :-).

What bothers me right now is that forced links in headings don't get their markup stripped. In 1.1.6.2 there's a fix for this, but it seems to send the script in an endless loop when I use PageTitles for links on pages that reference themselves in the heading (e.g.SandBox). So I commented out the fix and use a more primitive version. I think, I have to implement a circular reference detection. I guess there is something like this in include.php, so I'll take a look at this.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki