Page MenuHomePhabricator

[patch] Attributes with Links
Closed, ResolvedPublic

Description

Author: Smylers

Description:
Currently in Semantic MediaWiki an attribute value can't contain links to other
pages in their text, such as:

[[flavour:=tastes like [[chicken]]]]

It displays correctly in the page text, exactly as though it had simply been
written:

tastes like [[chicken]]

with 'chicken' being a link to that page.

However the attribute is assigned the text:

tastes like [[chicken

and that's how it displays in the 'Facts' box and other places.

The problem is that the pattern matching attribute declarations stops at the
first ']]'. The below patch fixes this so that it will skip over any matching
pairs of '[[' and ']]' in the attribute value.

Basically where the pattern had this, to match all characters up to the next
pipe or closing square bracket (and store them):

([^|\]]*)

I've changed it to this:

((?:[^|\]]|\[\[[[^]]*\]\])*)

which says that you can have as many repetitions as you want of either of these
in any combination:

  • a sequence of characters which doesn't include a pipe or closing square bracket
  • '[[' then a sequence of characters which doesn't include a closing square bracket, then ']]'

So when it reaches the '[[' of chicken the second of those alternatives is
chosen and it gobbles up everything up to and including the ']]' at the end of
chicken, leaving the final ']]' to terminate the attribute declaration.

I hope this is helpful, and that it can be incorporated into a forthcoming
release of Semantic MediaWiki. Please let me know if you have any questions.

Smylers

  • SMW_Hooks.php.orig Wed Feb 28 15:51:54 2007

+++ SMW_Hooks.php Wed Feb 28 15:52:24 2007
@@ -34,7 +34,7 @@

		$text = preg_replace_callback($semanticLinkPattern,

'smwfParseRelationsCallback', $text);

		// Parse links to extract attribute values
  • $semanticLinkPattern = '(\[\[(([^:][^]]*):=)+([^\|\]]*)(\|([^]]*))?\]\])';

+ $semanticLinkPattern =
'(\[\[(([^:][^]]*):=)+((?:[^|\[\]]|\[\[[^]]*\]\])*)(\|([^]]*))?\]\])';

		$text = preg_replace_callback($semanticLinkPattern,

'smwfParseAttributesCallback', $text);

		// print the results if enabled (we have to parse them in any case, in order to

Version: unspecified
Severity: normal

Details

Reference
bz9129

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:41 PM
bzimport set Reference to bz9129.
bzimport added a subscriber: Unknown Object (MLST).

Smylers wrote:

fix

Patch attached; I only inlined in the original message because I couldn't see
anywhere to upload it.

Attached:

info wrote:

Hey Smylers, thanks for the patch, it works for me but it changes the behavior
of edge cases like [[flavor:=tastes like [pigeon]]]. So I'm comfortable
checking it in without review from someone else.

I assume you know you could also have a relation, [[tastes like::chicken]].

info wrote:

Hey Smylers, thanks for the patch, it works for me but it changes the behavior
of edge cases like [[flavor:=tastes like [pigeon]]]. So I'm not comfortable
checking it in without review from someone else.

I assume you know you could also have a relation, [[tastes like::chicken]].

OK, I have applied this patch, and links in attribute texts work now. However,
the quick search is disabled for those cases, since it is not possible to create
an internal link which contains symbols like [ and ]. This is probably not very
problematic, since attribute values containing links should be long passages,
for which one normally does not search. One could still fix this detail if needed.

Also, the attribut contents is stored as wiki code internally, and will be
exported in this way.