====== WvdS.DokuWiki.Cond Plugin ====== **Plugin:** wvdscond\\ **Version:** 1.0.0\\ **Namespace:** ''lib/plugins/wvdscond/''\\ **Author:** Wolfgang van der Stille \\ **License:** GPL 2 ---- **Migration from wvdsif:** This plugin replaces the old ''wvdsif'' plugin and extends it with redirect functionality. The existing syntax '''', '''' and '''' remains fully compatible. ---- ===== Definition ===== The **wvdscond** plugin combines conditional content display and server-side redirects in one plugin. It provides: * **Conditional tags** - '''', '''', '''' * **Redirects** - ''{{wvds:redirect target="..."}}'' with variable support * **Negation** - '''' or '''' ===== Use Cases ===== * **Permission-based content** - Different content for guests, users, admins * **Multilingual start pages** - Language-specific greetings and content * **Automatic language redirect** - Redirect based on browser language * **Login redirects** - Redirect after login * **Conditional redirects** - Redirects only for specific groups ---- ===== Syntax ===== ==== ifgroup - By User Group ==== Content for this group Content for multiple groups Content for NON-guests ==== ifnotgroup - Negation ==== Content for logged-in users Content for non-admins ==== iflang - By Browser Language ==== Content for this language Content for multiple languages Fallback content (always shown) ==== wvds:redirect - Server-side Redirect ==== {{wvds:redirect target="de:start"}} {{wvds:redirect target="{lang}:start"}} {{wvds:redirect target="int:home" ifgroup="user"}} {{wvds:redirect target="{lang}:pub:start" ifnotgroup="user"}} ---- ===== Redirect Variables ===== ^ Variable ^ Replaced by ^ Example ^ | ''{lang}'' | Browser language | de, en, sl | | ''{group}'' | First user group | user, admin, vip | | ''{user}'' | Username | wvds | | ''{ns}'' | Current namespace | de:docs | ---- ===== Redirect Parameters ===== ^ Parameter ^ Type ^ Description ^ | ''target'' | Required | Target page (Page-ID or with variables) | | ''ifgroup'' | Optional | Redirect only for this group(s) | | ''ifnotgroup'' | Optional | Redirect only if NOT in group(s) | ---- ===== Group Parameters ===== ^ Parameter ^ Type ^ Description ^ | ''guest'' | predefined | Non-logged-in visitors | | ''user'' | predefined | All logged-in users | | ''admin'' | predefined | Administrators | | ''[groupname]'' | user-defined | Any group defined in DokuWiki | ---- ===== Examples ===== ==== Example 1: Language-based Redirect ==== **Requirement:** Start page automatically redirects to browser language. {{wvds:redirect target="{lang}:start"}} **Result:** * Browser in German: Redirect to ''de:start'' * Browser in English: Redirect to ''en:start'' * Browser in Slovenian: Redirect to ''sl:start'' ==== Example 2: Login Redirect ==== **Requirement:** Guests are redirected to a public page, logged-in users stay. {{wvds:redirect target="pub:start" ifnotgroup="user"}} **Result:** * Guest: Redirect to ''pub:start'' * Logged in: No redirect ==== Example 3: VIP Area ==== **Requirement:** Non-VIPs are redirected to info page. {{wvds:redirect target="info:upgrade" ifnotgroup="vip,premium"}} ===== VIP Area ===== Welcome to the exclusive area! ==== Example 4: Multilingual Start Page ==== **Requirement:** Greetings in different languages. ~~NOCACHE~~ ===== Willkommen ===== Dies ist unsere Wissensdatenbank auf Deutsch. ===== Welcome ===== This is our knowledge base in English. ===== Welcome ===== Please select your language. ==== Example 5: Admin Navigation ==== **Requirement:** Admin links only visible for admins. ~~NOCACHE~~ ===== Navigation ===== * [[.:start|Start Page]] * [[.:docs:index|Documentation]] * [[.:intern:index|Internal Area]] * [[.:admin:index|Administration]] ---- ===== How It Works ===== ==== Redirect Processing ==== 1. Pattern Recognition └── Finds {{wvds:redirect ...}} 2. Condition Check (if present) ├── ifgroup: Checks group membership └── ifnotgroup: Checks NON-membership 3. Variable Replacement ├── {lang} → Browser language ├── {user} → Username ├── {group} → First group └── {ns} → Current namespace 4. Redirect Execution ├── HTTP 301/302 header (preferred) ├── Meta-Refresh (fallback) └── JavaScript (fallback) ==== Security Notes ==== * Redirects use **wl()** for internal URLs (Open Redirect Prevention) * External URLs not allowed (CWE-601 protection) * All output escaped with **hsc()** (XSS protection) ---- ===== Configuration ===== The plugin requires no special configuration. Group detection uses standard DokuWiki ACL groups. ==== Important Note ==== Pages with conditional tags should use ''~~NOCACHE~~'' so content is re-rendered on each request. ---- ===== Migration from wvdsif ===== ^ Old (wvdsif) ^ New (wvdscond) ^ Status ^ | '''' | '''' | Compatible | | '''' | '''' | Compatible | | - | '''' | NEW | | - | ''{{wvds:redirect}}'' | NEW | ---- ===== Version Notes ===== ^ Version ^ Date ^ Changes ^ | 1.0.0 | 2026-01-29 | Initial release | ---- ===== See Also ===== * [[.:wvdsi18n]] - Translation plugin (successor to wvdslang) * [[.:wvdssnippet]] - Reusable HTML building blocks * [[.:flat]] - Template with language switcher ---- ===== Technical Reference ===== ==== Class: syntax_plugin_wvdscond ==== **File:** ''lib/plugins/wvdscond/syntax.php'' ^ Method ^ Description ^ | ''getType()'' | Returns ''substition'' | | ''getSort()'' | Returns ''100'' | | ''connectTo($mode)'' | Registers ifgroup, ifnotgroup, iflang, redirect patterns | | ''handle($match, ...)'' | Parses tag and extracts condition | | ''render($mode, ...)'' | Returns content, redirect, or empty | ==== Class: helper_plugin_wvdscond ==== **File:** ''lib/plugins/wvdscond/helper.php'' ^ Method ^ Description ^ | ''getUserGroups()'' | Returns all user groups | | ''checkGroup($groups)'' | Checks if user is in group | | ''checkNotGroup($groups)'' | Checks if user is NOT in group | | ''detectBrowserLang()'' | Detects browser language | | ''checkLang($langs)'' | Checks language match | | ''replaceVariables($target)'' | Replaces {lang}, {user}, etc. | ---- [x][x][x][x] [x][x][x][x][x] [x][x][x][x][x] ~~DISCUSSION~~