Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

AutomaticLinks

Summary: How to automatically create Crosslinks for use in, e.g., a glossary
Version: 2006-02-24
Prerequisites:
Status:
Maintainer: Klonk
Categories: Links

Question

How to automatically create Crosslinks for use in e.g. a glossary?

Answer

Use the script autolink.phpΔ . Insert the following line in your config.php:

  include_once("$FarmD/cookbook/autolink.php");

Notes

This script takes the titles of all files in a specific group and saves them together with the filename in a file called ".autolink-<groupname>" in the wiki.d directory. This file is dynamically created as soon a file in the group is deleted or changed, the corresponding information is changed also. This file is saved in a compressed format.

The first call will create a new file. Thus the loading time of the page for the initial creation of that file might be a little bit longer (up to some seconds), depends on the amount of files within the group though.

By default all titles which are shorter than two characters are ignored. This is controlled by the variable $AutoLinkMinSize which defaults to '2'.

The effect the user can see is that the wikipage contains some links that are not marked as links in the wikitext source. E.g the text "Start Page" is converted to e.g. Start Page automatically.

Activation of automatic links is currently only possible in the config files. I suggest to only activate it for the desired group. See PerGroupCustomizations for details.

Insert the following line:

  AutoLinkActivate($groups);

where the string $groups contains a string with the desired source groups seperated by a space character, e.g.

  AutoLinkActivate("PmWiki Main");
  • This recipe was last tested on PmWiki version: 2.1 beta26
  • This recipe requires at least PmWiki version: and (any other recipes)
  • This recipe, version...... was installed here the...(date)

Releases

  • 2006-02-17 initial release.
  • 2006-02-17 fixed bug with corrupting Attach: markup with some help of Pm
  • 2006-02-24 fixed warning messages when SearchPatterns['default'] was not set

Comments

This script adds noticably to the creation time of a wikipage. In my tests on a windows machine with around 1000 crossreferences added around 0.4 secs to the page creation. I'll try to improve that after the first release.

BTW: hints for improving speed are highly appreciated.

'' Hi, I installed the recipe as you described it (at least I think so... the line with the AutoLinkActivate("PmWiki Main"); was supposed to be put into the config.php?). The good news: it works, the links are correct, even between the different groups and I'm quite glad about it, but whenever I open my wiki, I get at the top a lot (2-3 screens)of lines saying "Warning: Invalid argument supplied for foreach() in /usr/export/www/vhosts/funnetwork/hosting/martha/testwiki/cookbook/autolink.php on line 70" and the last one is "Warning: Cannot modify header information - headers already sent by (output started at /usr/export/www/vhosts/funnetwork/hosting/martha/testwiki/cookbook/autolink.php:70) in /usr/export/www/vhosts/funnetwork/hosting/martha/testwiki/pmwiki.php on line 727". Those error-messages are followed by the normal wiki pages. What could be the cause of this? Thx, Martha. ''

  • I have no such error message here. I'm using PHP 4.3.10 currently - Klonk February 23, 2006, at 01:53 AM
  • Maybe something went wrong during up/- or download please re-download the script. - Klonk February 23, 2006, at 02:23 AM
I tried redownloading the scripts, and I even used a completely new Installation of pmwiki, in case something was wrong with my version. I also tested it both with the Xampp-lite-Server and my webspace (PHP-Version(approve links). But still those error messages kept on occuring, althoug the scripts really seems to work apart from that. Ah, and there was one more thing I noticed: the more groups I added to the "AutoLinkActivate"-string, the more error lines showed up. Martha, same day.
  • Found the problem, should work now - Klonk February 24, 2006, at 09:00 AM

Hallo, could there be a way to change this dynamic autolinking to a static one?
It means, a word like a pagename will formattet to a link to this pagename already by saving a page. This could safe a lot of performance. May be - as an alternative - a PHP-script, to run from time to time, that collects all pagenames in an array and then formats all these found words in contents of all page files.
Thx and sorry for bad Eng.,
Hartmut

You mean when saving the page e.g. "word" is changed automatically to "[[word]]"? If yes this would require a totally different approach and a complete rewrite of the script. Would make more sense in an own cookbook reciepe - Klonk April 04, 2006, at 01:04 AM

i kept e-mailing and pestering, i sussed how to get it to do cross links on two seperate groups, jsut make a copy of Autolink, name is "autolink2" do a find and replace on "autolink" replace with "autolink2" and change the "sortsize" to "sortsize2"

Normally you don't need to do that as for each group you refer to a list of pages is created seperately. The easiest way to achieve this is by placing the autolink in a group header or sidebar, which could be changed per group (depends on the skin you're using) - Klonk April 04, 2006, at 01:04 AM

then do the include and set a nother group for Autolink2 and you are sorted.. obviously will work further on . Chritian


Hello. I installed the script and it really works fine for my purpose of a glossary. The only remaining problems are Glossary-Entries which are no possible PageNames (c.t. for example). Any ideas to cope with that?


Hi there, thanks for this great add-on. How could I adapt it so that it so that it isn't case sensitive? I've been trying various ways but no luck as yet. thanks for any help you can give! John


Hey. Installed this one and it works almost fine. Problem is, that part of the recipe works outside of the specified group too. For example the word 'RecentChanges' in the PmWikiFaq now is a link to 'thatonegroup.RecentChanges'. The recipe looks farly easy and small, but I don't know php really so I can't say what to change how. Any ideas out there? peter 3/8/2008

See Also

Contributors

Klonk

Edit - History - Print - Recent Changes - Search
Page last modified on March 07, 2008, at 06:17 PM