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