I suspect the problem may be this query: SELECT cur_title FROM cur WHERE cur_title LIKE "%:$n"
Wow! This is a pig. Linear search (with regular expression) through the whole database for every single page served :-)
There should not be any LIKE operators in the code whatsoever, since they cannot use the index. The quick and dirty fix would be to explicitly search for the page in other namespaces, like:
SELECT cur_title FROM cur WHERE cur_title = "wikipedia:$n" OR cur_title="user:$n" OR ...
this uses the index on cur_title and is quick. A much cleaner solution would be to have an additional field "namespace" in the database. Encoding namespaces in the article title is a kludge.
Axel