Details
-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
18.4.3, 18.6.0-rc-1
-
None
-
Unknown
-
Description
Context
Several places need to know how the stored content of a document or of an object property is executed when it is viewed: the text, the syntax it's parsed with, the author whose rights apply and whether the execution is restricted. Each of them currently computes this on its own:
- TextAreaClass#displayView / #displayEdit (content type, document syntax, isRestricted() || ownerDocument.isRestricted())
- ObjectPropertyRequiredRightAnalyzer (content type with the same wiki text default, isRestricted(), owner document syntax)
- WysiwygEditorScriptService#toAnnotatedXHTML (stored author when the converted text is the stored content)
- RenderingScriptService#convert (same, used by the BlockNote editor)
Modules that don't depend on oldcore, like xwiki-platform-rendering-xwiki, can't access the needed information at all: DocumentAccessBridge exposes the value of an object property but none of its class metadata (e.g., the restricted flag of a TextArea property).
RenderingScriptService#convert is meant to become the standard way for editors to render stored content, so it should apply the same rules as the view: use the author of the stored content only when the content is executed as it is when viewed, i.e., same text, same syntax, and at least the same restrictions (document restricted flag and, for object properties, the restricted flag of the TextArea property).
Proposal
Add a component role in an API module that doesn't depend on oldcore (e.g., the bridge module, as a separate role rather than new methods on DocumentAccessBridge), implemented in oldcore:
@Role @Unstable public interface StoredContentResolver { /** * @return the stored executable content at the given reference, or empty if the referenced entity doesn't hold * executable content (e.g. a non text area property or a pure text one) */ Optional<StoredContent> resolve(EntityReference reference) throws StoredContentException; } public record StoredContent(String content, Syntax syntax, UserReference author, boolean restricted) { }
- DocumentReference: the document content, the document syntax, the content author and document.isRestricted().
- ObjectPropertyReference: only TextArea properties with wiki text content: the property value, the document syntax, the effective metadata author and textAreaClass.isRestricted() || document.isRestricted(). Other properties resolve to empty.
Then:
- Use it in RenderingScriptService#convert: use the stored author only if the converted text and the source syntax match the stored content, and make the transformation context restricted if the stored content is restricted.
- Use it in WysiwygEditorScriptService instead of the logic based on XWikiDocument.
- Consider using it in TextAreaClass and ObjectPropertyRequiredRightAnalyzer so that the rules are defined in a single place.
A general read-only API for class and property metadata (mirroring TextAreaClass and the other property classes) would be useful too, but is a much larger design question that should be discussed separately; the API proposed here could later be implemented on top of it.
This issue was created with the help of an AI assistant (Claude) and reviewed by the reporter.