I’m looking at XWiki#getUserPreference() and I’m not sure I really understand how it’s meant to be used.
The issue I see is that it’ll start looking for the asked preference in the current user profile, in the
XWiki.XWikiUsers xobject. And if not found it’ll look for that preference in the current space’s
WebPreferences document (in a
XWikiPreferences xobject), and then in the wiki’s
XWikiPreferences document (in a
So the xobject in which we look for are from different xclasses so it seems weird we’re looking for a given preference xproperty in different xclasses. It would mean that XWiki users would need to modify their
XWikiPreferences xclass in their wiki to add the xproperty, which seems a bit weird.
If we were looking for a
XWiki.XWikiUsers xobject in the current space’s
WebPreferences document or in the current wiki’s
XWikiPreferences document , then it would make more sense to me.
What could also make sense would be the opposite (but then the
getUserPreference() name is not good), would be to look for the property in a user profile’s
So do you agree that the current situation is weird and doesn’t make much sense?
FYI, ATM we use
XWiki#getUserPreference() in 21 places right now in platform.
Example 1 (using a preference belonging to a user):
## Build and run the Solr query. #set ($suggestionsQuery = $services.query.createQuery($suggestionsQueryString, "solr")) #set ($filterQuery = ['type:"DOCUMENT"', "locale:(""$xcontext.locale"" OR """")"]) #if ($xwiki.getUserPreference('displayHiddenDocuments') != 1) #set ($discard = $filterQuery.add('hidden:false')) #end
Example 2 (using a preference belonging to a XWikiPreferences):
#set($leftPanels = $xwiki.getUserPreference("leftPanels")) #if($leftPanels == "") #set($leftPanels = $xwiki.getSpacePreference("leftPanels")) #end
(side note: the fallback here is not needed since it’s done by default in