views:

153

answers:

5

What I mean by autolinking is the process by which wiki links inlined in page content are generated into either a hyperlink to the page (if it does exist) or a create link (if the page doesn't exist).

With the parser I am using, this is a two step process - first, the page content is parsed and all of the links to wiki pages from the source markup are extracted. Then, I feed an array of the existing pages back to the parser, before the final HTML markup is generated.

What is the best way to handle this process? It seems as if I need to keep a cached list of every single page on the site, rather than having to extract the index of page titles each time. Or is it better to check each link separately to see if it exists? This might result in a lot of database lookups if the list wasn't cached. Would this still be viable for a larger wiki site with thousands of pages?

+1  A: 

In my own wiki I check all the links (without caching), but my wiki is only used by a few people internally. You should benchmark stuff like this.

Peter Stuifzand
+1  A: 

In my own wiki system my caching system is pretty simple - when the page is updated it checks links to make sure they are valid and applies the correct formatting/location for those that aren't. The cached page is saved as a HTML page in my cache root.

Pages that are marked as 'not created' during the page update are inserted into the a table of the database that holds the page and then a csv of pages that link to it.

When someone creates that page it initiates a scan to look through each linking page and re-caches the linking page with the correct link and formatting.

If you weren't interested in highlighting non-created pages however you could just have a checker to see if the page is created when you attempt to access it - and if not redirect to the creation page. Then just link to pages as normal in other articles.

Ross
A: 

My idea would be to query the titles like SELECT title FROM articles and simply check if each wikilink is in that array of strings. If it is you link to the page, if not, you link to the create page.

palotasb
+1  A: 

I tried to do this once and it was a nightmare! My solution was a nasty loop in a SQL procedure, and I don't recommend it.

One thing that gave me trouble was deciding what link to use on a multi-word phrase. Say you had some text saying "I am using Stack Overflow" and your wiki had 3 pages called "stack", "overflow" and "stack overflow"....which part of your phrase gets linked to where? It will happen!

Magnus Smith
A: 

In a personal project I made with Sinatra (link text) after I run the content through Markdown, I do a gsub to replace wiki words and other things (like [[Here is my link]] and whatnot) with proper links, on each checking if the page exists and linking to create or view depending.

It's not the best, but I didn't build this app with caching/speed in mind. It's a low resource simple wiki.

If speed was more important, you could wrap the app in something to cache it. For example, sinatra can be wrapped with the Rack caching.

Daniel Huckstep