<p>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).</p>

<p>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.</p>

<p>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?</p>

[{'answer_id': 14679, 'author': 'Peter Stuifzand', 'author_id': 1633, 'author_profile': 'https://Stackoverflow.com/users/1633', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 22060, 'author': 'Ross', 'author_id': 2025, 'author_profile': 'https://Stackoverflow.com/users/2025', 'pm_score': 1, 'selected': False, 'text': "<p>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.</p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 31864, 'author': 'palotasb', 'author_id': 3063, 'author_profile': 'https://Stackoverflow.com/users/3063', 'pm_score': 0, 'selected': False, 'text': '<p>My idea would be to query the titles like <code>SELECT title FROM articles</code> 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.</p>\n'}, {'answer_id': 204044, 'author': 'Magnus Smith', 'author_id': 11461, 'author_profile': 'https://Stackoverflow.com/users/11461', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n\n<p>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!</p>\n'}, {'answer_id': 561476, 'author': 'Daniel Huckstep', 'author_id': 4657, 'author_profile': 'https://Stackoverflow.com/users/4657', 'pm_score': 0, 'selected': False, 'text': '<p>In a personal project I made with Sinatra (<a href="https://github.com/darkhelmet/swiki/tree" rel="nofollow noreferrer">link text</a>) 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.</p>\n\n<p>It\'s not the best, but I didn\'t build this app with caching/speed in mind. It\'s a low resource simple wiki.</p>\n\n<p>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.</p>\n'}, {'answer_id': 7264969, 'author': 'Fumisky Wells', 'author_id': 921859, 'author_profile': 'https://Stackoverflow.com/users/921859', 'pm_score': 0, 'selected': False, 'text': '<p>Based on my experience developing <a href="http://sourceforge.net/projects/jjjuli/" rel="nofollow">Juli</a>, which is an offline personal wiki with autolink, generating static HTML approach may fix your issue.</p>\n\n<p>As you think, it takes long time to generate autolinked Wiki page.  However, in generating static HTML situation, regenerating autolinked Wiki page happens only when a wikipage is newly added or deleted (in other words, it doesn\'t happen when updating wikipage) and the \'regenerating\' can be done in background so that usually I don\'t matter how it take long time.  User will see only the generated static HTML.</p>\n'}]
['https://Stackoverflow.com/questions/14545', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14446/']