Posted 1253109038|%O ago by leiger
Based on graphmastur's very ambitious weneed:102, this is the beginnings of a design document for the theoretical If module.
[[module If attributes]]
Code to be generated if the attribute requirements are met
[[/module]]
When a page is saved, the position in the page that holds the module will display either the specified code, or nothing at all if the attribute requirements are not met.
More than one of these may be activated within the same instance of the module. For example:
[[module If user="anonymous" localtime="9.5"]]
You are an **anonymous** user that is located in **Central Australia**
[[/module]]
Most of these can be interpreted as a list, and are additive. However, this should also be supported:
[[module If browser="-firefox -opera -chrome -safari -ie"]]
I have no idea what browser you're using!!
[[/module]]
Name | Options | Description |
---|---|---|
index | index="valid positive integer list" index="1 2 3 7 8 9 13 14 15" index="odd|even" |
One of the most powerful uses of the If module, this should work within ListPages and will check the value of the 'index' variable |
member_role | member_role="anonymous" member_role="registered" member_role="member" member_role="moderator" member_role="administrator" |
Another of the most powerful uses of the If module, this allows to check what type of user is currently viewing the page!! |
member_flags | member_flags="member_flags-identifier" | See Ed Johnson's post for further details |
tags | tags="list of tags" | To replace the current [[iftags tags]] syntax |
browser | browser="browser-identifier" | Is the specified browser being used? |
os | os="os-identifier" | Is the specified Operating System being used? |
localtime | localtime="GMT modifier" localtime="-5" localtime="0" localtime=+5" |
Checks what the local time is for the current user's computer clock. localtime=+5 represents a time five hours ahead of Greenwich Mean Time. |
I just read this post by pieterh saying that logic within wikidot isn't possible.
Does this mean that we'll never be able to show something different depending on whether a user is anon/member/mod/admin ?
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
It is complex enough that I don't understand it all. Modules are mostly dynamic but operate on cached data - so parts of the screen are assembled from cached data whenever possible.
The page URL also determines caching, so e.g. a single ListPages can produce different cached results if the URL is different each time.
Things like iftags work by invalidating the cache when the page tags change.
It would thus be possible to show different things for different users IF that was being produced by a module which held different cached displays. We do cache the current user role for the site.
So this gives you the parameters, more or less. A module that shows different content depending on the user role is (afaics) feasible. A module that shows different content depending on the time of day is not feasible. Random conditions won't work: only those which can be cached and which change relatively slowly, and which have relatively few combinations.
Portfolio
Relating to this post, if the %%user%% variable ends up working, then you will be able to target what anonymous users see compared to normal users.
What will work (afaics):
For playing with the index, it may get too complex technically. I was thinking that what would work are variables like %%parity%% which resolve to "odd" or "even" and allow different styles for odd and even rows.
Portfolio
I would modify the user levels like so:
I would also like to see an additional set of "flags" for site members, i.e. "member_flags", that we could assign. Even a single integer (4 bytes) along with this functionality could be very powerful. This is really a separate wish, but would be pretty useless without the If module.
Peeking at the table structure in WDOS shows these fields in the member table:This would give us 32 attributes we could assign to site members.
Then, we could do bitwise (AND, OR, XOR and NOT) testing like:
This would be huge for me from a business wiki perspective. A simple example would be to use this for keeping track of employee status information.
etc.
With 4 bytes to play with we'd get 4 sets of 8 bits.
0000 0000 0000 0000 0000 0000 0000 0000
Being able to display selected content based on one or more of these "flags" would be very slick (if this employee is full-time and salaried and on company insurance, then show content). It would allow me to maintain a single wiki instead of multiple private wikis.
-Ed
Community Admin
That would definitely be useful.
If we could manage separate CSS for different users in this way by showing a different [[code type="css"]]…. that'd also be useful ;-) (more wishful thinking)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
I've changed the levels to single words (always nicer IMO).
Regarding flags and such, remember that caching constrains us significantly. You need to view Wikidot as an engine that generates pages but stores them in various cached versions, in memory and on disk as HTML, and only re-renders them when there is a serious reason (something changed). Trying to render every page, every time, would multiple the server load by 100 or 1,000 times.
It is possible to store different versions of a page depending on the user status. Thus, one view for anonymous visitors, one for logged-in visitors, perhaps one for each of the user roles.
It is possible to store different versions depending on the URL, since caching works by URL. This is how we manage multiple ListPages views in (e.g.) the page manage.
Generating different views of the page on the fly depending on anything more complex is not feasible and won't happen at least in this generation of the product.
IMO if you really need database integration, the best solution would be to iframe a foreign app.
Portfolio
Well, it was a nice idea while it lasted! Even adding the "trusted member" role as discussed elsewhere, would be a nice addition. Having as many extra member roles as is reasonably possible without over-burdening the server would be nice.
;)
-Ed
Community Admin
LOL =)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
Wait, ambitious?
I think it would be really good to test if someone was logged in and see a different CSS based on that.
What would you use this for? (Not saying it's not useful, but asking for examples…)
Portfolio
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
Reason for my question: this would be clumsy on a per-site basis but could play nicely with per-page CSS (CSS module).
Portfolio