diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d83ec2e43..dd19300b7 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -6,10 +6,14 @@ - fix: purge old asset revisions could purge the most recent revision if the database had some referential integrity probems - Wiki autolinks prefer longest title match + http://www.webgui.org/bugs/tracker/wiki-automatic-link-creator-not-greedy-enough + - Wiki pages no longer autolink themselves + http://www.webgui.org/bugs/tracker/wrong-an-unnecessary-links-in-wiki - fix: Recover Password by Profile Field can now work with subclasses of WebGUI::Auth::WebGUI and with custom WebGUI::Form::Controls as profile fields. + 7.4.0 - api: Form Controls and Workflow Activities may now include web based helper subroutines directly in their files. See diff --git a/lib/WebGUI/Asset/WikiPage.pm b/lib/WebGUI/Asset/WikiPage.pm index ab51fd0fe..5154da906 100644 --- a/lib/WebGUI/Asset/WikiPage.pm +++ b/lib/WebGUI/Asset/WikiPage.pm @@ -343,7 +343,10 @@ sub view { historyUrl => $self->getUrl("func=getHistory"), editContent => $self->getEditForm, allowsAttachments => $self->getWiki->get("allowAttachments"), - content => $self->getWiki->autolinkHtml($self->scrubContent), + content => $self->getWiki->autolinkHtml( + $self->scrubContent, + {skipTitles => [$self->get('title')]}, + ), }; return $self->processTemplate($var, $self->getWiki->get("pageTemplateId")); } diff --git a/lib/WebGUI/Asset/Wobject/WikiMaster.pm b/lib/WebGUI/Asset/Wobject/WikiMaster.pm index 914651b4d..1176af6e3 100644 --- a/lib/WebGUI/Asset/Wobject/WikiMaster.pm +++ b/lib/WebGUI/Asset/Wobject/WikiMaster.pm @@ -90,14 +90,22 @@ sub appendSearchBoxVars { sub autolinkHtml { my $self = shift; my $html = shift; - # TODO: ignore caching for now, but maybe do it later. + # opts is always the last parameter, and a hash ref + my %opts = ref $_[-1] eq 'HASH' ? %{pop @_} : (); + my $skipTitles = $opts{skipTitles} || []; + # TODO: ignore caching for now, but maybe do it later. my %mapping = $self->session->db->buildHash("SELECT LOWER(d.title), d.url FROM asset AS i INNER JOIN assetData AS d ON i.assetId = d.assetId WHERE i.parentId = ? and className='WebGUI::Asset::WikiPage'", [$self->getId]); return $html unless %mapping; foreach my $key (keys %mapping) { + if (grep {lc $_ eq $key} @$skipTitles) { + delete $mapping{$key}; + next; + } $key =~ s{\(}{\\\(}gxms; # escape parens $key =~ s{\)}{\\\)}gxms; # escape parens $mapping{$key} = $self->session->url->gateway($mapping{$key}); } + # sort by length so it prefers matching longer titles my $matchString = join('|', map{quotemeta} sort {length($b) <=> length($a)} keys %mapping); my $regexp = qr/($matchString)/i; my @acc = (); @@ -121,7 +129,6 @@ sub autolinkHtml { $p->handler(default => sub { push @acc, $_[0] }, 'text'); $p->parse($html); $p->eof; - undef $p; # Just in case there might be reference loops. return join '', @acc; }