Abstract Wikipedia/Error messages on ZObjects
|Notes, drafts, discussions|
|Examples & mockups|
Currently, we evaluate, construct, and validate the entire ZObject within the PHP code of the WikiLambda extension from the JSON serialization stored in the wiki.
There are two main reasons for that:
- It validates the JSON serialization: if the serialization does not represent a valid object, the object construction will fail. This way we prevent invalid content from entering the wiki, which means we can treat all content as valid and may assume that certain conditions hold.
- For some of the tasks the wiki needs to perform, such as getting labels, later aliases, and some of the specific views on the wiki, the object *has* to fulfill certain conditions, or else the wiki cannot actually provide certain fundamental features, such as search or display.
This has a number of drawbacks:
- We expect most of the wiki, including its types and validations, to eventually be editable by the community. This means that what is valid and what is not will change over time, and what was valid at some point might not be at another point. We need to cope with invalid content, because content, at least in older revision, will ultimately become invalid — otherwise basic features of the wiki, just as history or view on old revisions may break.
- Checking validity can be very expensive, especially if we check the validity using user-provided type definition and validation functions.
Here is a suggestion to remedy the issue:
- We introduce a new PHP class (probably similar to the current ZRecord) that holds a well-formed JSON-representation of any arbitrary ZObject, but is not a full blown PHP mirror of the type of that ZObject.
- Unless needed for the wiki to work, we don’t construct full PHP objects out of the ZObjects. Even the ZObjects that we need, we only construct them partially — the parts that we actually need for the wiki to work. Each of these PHP objects also has a member where it holds the well-formed JSON-representation of itself.
- Everything stored in the wiki is guaranteed to be well-formed and canonicalized.
- Everything stored in the wiki is guaranteed to follow the inalienable truths; these are hardcoded in the wiki and cannot be changed on wiki. These include that every object must be a Z2/Persistent object, that every Z2 has labels, etc.
- Both 3 and 4 are supposed to be stable-ish in the longer term.
- Beyond 3 and 4, we don’t do any other validation.
- When displaying stored or previewed content, we do validation, and display the errors.
- Before storing, the contributor can either preview, or call validation, or validation is called automatically, and the contributor will see a list of errors. The “publish” button might be grayed out or not displayed if there are errors.
- But once the API gets invoked to store, we will do so even in face of validation errors — but not in face of well-formedness errors or errors against inalienable truths.
- Invalid ZObjects *always* use the generic viewer and editor, not the specific one (as the requirements for the specific viewer might be violated).
- The generic viewer also shows a list of all validation errors if any.