blob: c9f554f1cbe577eefeea1199d19419d543d3a22d [file] [log] [blame]
version=pmwiki-2.0.beta31 ordered=1
newline=²
agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.6) Gecko/20050321 Firefox/1.0.2
author=HansB
host=84.67.245.201
name=PmWiki.ConditionalMarkup
rev=25
targets=PmWiki.PmWiki,PmWiki.RecentChanges
text=!!Syntax²->The generic form of the [@(:if:)@] directive is²²-->[@(:if cond param:)@] body [@(:if:)@]²²->where "[@cond@]" names a condition to be tested from the $Conditions array, and "[@param@]" is a parameter or other argument held in $condparm in the test. For example, the following (in config.php) adds [@(:if group GroupName:)@] as a markup:²²-->[@$Conditions['group'] = "FmtPageName('\$Group',\$pagename)==\$condparm";@]²²->One could then use the following markup:²²-->[@(:if group PmWiki:)@] This text only appears in the group "PmWiki"[@(:if:)@]²²->The negated form of [@(:if:)@] is automatically handled as well, thus:²²-->[@(:if ! group PmWiki:)@] This text appears everywhere *but* in group "PmWiki"[@(:if:)@]²²²->Any [@(:if:)@] automatically terminates the previous one, thus markup can be easily cased:²²-->[@(:if group PmWiki:)@] Do this in PmWiki group²-->[@(:if group Main:)@] Do something else for Main²-->[@(:if:)@] This happens in all groups²²->See also Cookbook:ExpandingMenus for an example to use this to create compact Sidebar menus.²²->All that remains now is to come up with a good set of [@$Conditions@]. Testing for group membership is a good one, we might also want to create something for generic pagename pattern matches²²-->[@(:if match ^PmWiki\. :)@] Only appears in the PmWiki group²-->[@(:if match RecentChanges$ :)@] Everywhere except RecentChanges pages²-->[@(:if ! match ^(Main|PmWiki)\. :)@] All groups except Main and PmWiki²-->[@(:if:)@]again - all groups²²->There is an [=(:if auth ...:)=] conditional markup available for processing depending on the current authorizations in effect. For example, one can create a bullet list with²²-->[@(:if auth read:)* [[View page -> {$Name}?action=browse]]@]²-->[@(:if auth edit:)* [[Edit page -> {$Name}?action=edit]]@]²-->[@(:if auth upload:)* [[Attachments -> {$Name}?action=upload]]@]²-->[@(:if auth attr:)* [[Page Attributes -> {$Name}?action=attr]]@]²-->[@(:if auth admin:)* You're logged in as admin@]²-->[@(:ifend:)@]²²->and only those items corresponding to the user's current authorizations will appear. This should be very useful in creating action buttons.²²->[@$Conditions@] could also be conditional on other items; e.g., date or time, day of week, etc.²²!!Default `PmWiki Conditions²The following are defined in pmwiki.php, so would not need to be defined in config.php:² [=² $Conditions['false'] = 'false';² $Conditions['true'] = 'true';² $Conditions['group'] = "FmtPageName('\$Group',\$pagename)==\$condparm";² $Conditions['name'] = "FmtPageName('\$Name',\$pagename)==\$condparm";² $Conditions['match'] = 'preg_match("!$condparm!",$pagename)';² $Conditions['auth'] = '@$GLOBALS["PCache"][$GLOBALS["pagename"]]["=auth"][trim($condparm)]';² $Conditions['authid'] = '@$GLOBALS["AuthId"] > ""';²=]²²!!Samples for if-markups / [@$Conditions@]:²²->[@(:if group GROUPNAME:)@] - display following text only, if group = specified groupname:²-->[@$Conditions['group'] = "FmtPageName('\$Group',\$pagename)==\$condparm";@]²²->[@(:if author AUTHORNAME:)@] - display following text only, if author = specified authorname:²-->[@$Conditions['author'] = "\$GLOBALS['Author']==\$condparm";@]²-->will only work, if Author is "logged" on or has already put his name into the author-field while editing a page, i.e. the global variable $Author must be set²²->[@(:if enabled VARIABLE:)@] - display following text only, if VARIABLE defined in config.php or a skin's php script is set to 1 or some string value. If set to zero (0), or not set, the condition is not true and the following text will not display: ²-->[@$Conditions['enabled'] = "(boolean)\$GLOBALS[\$condparm]";@]²²-->This is useful for instance to have a skin display something, which will be hidden in other skins, by setting a variable in the skin.php file to 1, and checking if the variable is set in the if condition.²²!!Caveat²Q: what happens to these kind of things when someone looks at such a page and presses "Show Source"?² [=(:if ! auth admin:)² code seen by other than admins² (:if auth admin:)² code seen by admins² (:if:)=]²²If someone views the HTML source in the browser, then the text²isn't even there -- it's removed from the output entirely by²the conditional markup.²²However, if someone has read permission to the page and uses ²?action=source, they'll see the entire source including the²conditional markups. As per my earlier [[http://www.pmichaud.com/pipermail/pmwiki-users/2005-April/012494.html |note]], I ²think I'm going to take the position that PmWiki's smallest ²atom of security is the page, and not individual pieces of the page.²In other words, (:if ...) is a useful way for suppressing parts of²a page '''but not for protecting it'''.²²Pm²²->see also: [[Cookbook:MultiLanguage]]²
time=1113662556