This slowdown occurs because the longer an article is and the number of BB-Codes used make auto-link discovery more difficult. We intend to add an option to disable auto-links on a per-article basis, but not until VaultWiki 4.
I have devised this, which will improve auto-link speed by about 50%, but I cannot speak to the accuracy of the discovery mechanism after this change. Only time and testing will tell. I don't think it's possible to improve the speed much more without serious repercussions to accuracy (i.e. creating links where links don't belong).
In vault/class/bbcode/autolink.php, replace the complete
(Everything until the next function definition) with:
Code:
function process($text, $parent, $use_html = false)
{
global $vbulletin, $vault;
$pregfind = array();
$pregreplace = array();
$wiki_links = array();
$force_return = false;
if (
$parent == CATEGORY_SPACE OR
$parent == IMAGE_SPACE OR
$parent == TEMPLATE_SPACE
)
{
$force_return = true;
}
if (!$force_return)
{
$vault->fetch_instance('article');
if (!$vault->article->fetch('autolinks', $parent, VAULT_LANGUAGEID, 'count'))
{
$force_return = true;
}
}
if (!$force_return)
{
$this->init_tags();
$preg_no_auto = array();
if (!empty($this->skip_tags))
{
$preg_no_auto[] = '#\[(' . implode('|', $this->skip_tags) . ')\].*\[/\1\]#siUe';
}
$preg_no_auto[] = '#\[[^\[]*\]#sUe';
if ($use_html)
{
$preg_no_auto[] = '#<(a|script|code).*</\1>#siUe';
$preg_no_auto[] = '#<.*>#sUe';
}
if ($vbulletin->options['vault_legacy_enabled'] == 1)
{
$preg_no_auto[] = '#\{.*(\||\})#sUe';
}
}
($hook = vBulletinHook::fetch_hook('vault_autolinks_start')) ? eval($hook) : false;
if ($force_return)
{
return $text;
}
global $post;
static $redirects_to_skip;
$articles_to_skip = $vault->parser['autolink_articles_to_skip'];
$matching_articles = array();
$text = htmlspecialchars_uni($text);
$vault->fetch_instance('string');
$lowertext = $vault->string->tolower($text);
// empty this in case we somehow parse multiple articles on the same page
$vault->parser['autolink_articles_to_skip'] = array();
$linkids = $vault->article->fetch('autolinks', $parent, VAULT_LANGUAGEID, 'dump');
$entities = get_html_translation_table(HTML_ENTITIES);
if ($vbulletin->options['vault_autolink_stop'])
{
$ignore_list = preg_split('#[\r\n]+#s', $vault->string->tolower($vbulletin->options['vault_autolink_stop']), -1, PREG_SPLIT_NO_EMPTY);
}
if (empty($ignore_list))
{
$ignore_list = false;
}
// turn on UTF-8 mode?
$vault->fetch_instance('language');
$langid = $vault->language->get(0);
$modifiers = 'iU';
if ($vault->language->charset["$langid"] == 'U')
{
$modifiers .= 'u';
}
foreach ($linkids AS $linkid => $linktitle)
{
$linktitle = $linktitle[VAULT_LANGUAGEID];
if (!$linktitle)
{
continue;
}
$linktitle = $vault->string->tolower($linktitle);
if (
strlen($linktitle) < $vbulletin->options['vault_autolink_min'] OR
$linktitle == 'ces' OR
$linktitle == 'dol' OR
$linktitle == 'xst' OR
$linktitle == 'l' OR
$linktitle == 'autolink' OR
intval($linktitle) > 0 OR
(
$ignore_list AND
in_array($linktitle, $ignore_list)
) OR
strpos($lowertext, $linktitle) === false OR
(
in_array($linktitle, $entities) OR
(
$number = str_replace(array('#', 'x', 'u', ';'), '', $number) AND
intval($number) > 0
)
)
)
{
continue;
}
$matching_articles[strlen($linktitle)]["$linkid"] = preg_quote($linktitle, '#');
}
krsort($matching_articles);
$text = str_replace('$', '#!#CES-XST()DOL#L', $text);
$text = preg_replace($preg_no_auto, '\$this->save("\0")', $text);
if (
!empty($linkids) AND
!empty($articles_to_skip) AND
VAULT == 'true' AND
empty($redirects_to_skip[$post['threadid']])
)
{
$redirects_to_skip[$post['threadid']] = array();
$redirects = $vbulletin->db->query_read_slave("
SELECT thread.threadid
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "vault_link AS link ON (thread.firstpostid = link.postid)
WHERE thread.threadid IN (" . implode(',', array_keys($linkids)) . ")
AND link.redirect = 1
AND link.targetid IN (" . implode(',', array_keys($articles_to_skip)) . ")
GROUP BY thread.threadid
");
if ($vbulletin->db->num_rows($redirects))
{
while ($redirect = $vbulletin->db->fetch_array($redirects))
{
$redirects_to_skip[$post['threadid']][$redirect['threadid']] = $redirect['threadid'];
}
$vbulletin->db->free_result($redirects);
unset($redirect);
}
else
{
$redirects_to_skip[$post['threadid']] = true;
}
}
if (is_array($redirects_to_skip[$post['threadid']]))
{
// numerical keys aren't preserved with array_merge
foreach ($redirects_to_skip[$post['threadid']] AS $redkey => $redval)
{
$articles_to_skip["$redkey"] = $redval;
}
}
$i = 0;
$totallen = 0;
$search = array();
foreach ($matching_articles AS $article_group)
{
foreach ($articles_to_skip AS $linkid => $ditto)
{
unset($article_group["$linkid"]);
}
if (empty($article_group))
{
continue;
}
$search = array_merge($search, $article_group);
}
if (!empty($search))
{
$searchstring = '#((?:^|[^\&\w]){1})(' . implode('|', $search) . ')((?:$|[^\w]){1})#' . $modifiers;
$text = preg_replace($searchstring, "\\1[AUTOLINK]\\2[/AUTOLINK]\\3", $text);
}
$text = $this->save('', $text, 1);
$text = str_replace('#!#CES-XST()DOL#L', '$', $text);
$text = unhtmlspecialchars($text);
return $text;
}
Bookmarks