Inhaltsverzeichnis

WvdS.DokuWiki.If Plugin

Plugin: wvdsif
Version: 1.0.0
Namespace: lib/plugins/wvdsif/
Author: Wolfgang van der Stille zeljko.petrusic@outlook.de
License: GPL 2


Definition

The wvdsif plugin enables conditional content display based on user groups or browser language. It provides two tag types: <ifgroup> for group-based display and <iflang> for language-based display.

Use Cases


Syntax

ifgroup - By User Group

<ifgroup groupname>Content for this group</ifgroup>
<ifgroup group1,group2>Content for multiple groups</ifgroup>

iflang - By Browser Language

<iflang languagecode>Content for this language</iflang>
<iflang code1,code2>Content for multiple languages</iflang>
<iflang *>Fallback content (always displayed)</iflang>

Parameters

ifgroup Parameters

Parameter Type Description
guest predefined Not logged-in visitors
user predefined All logged-in users
admin predefined Administrators
[groupname] custom Any group defined in DokuWiki

iflang Parameters

Parameter Type Description
de ISO 639-1 German
en ISO 639-1 English
sl ISO 639-1 Slovenian
fr ISO 639-1 French
es ISO 639-1 Spanish
it ISO 639-1 Italian
* Wildcard All languages (fallback)

Examples

Example 1: Guests vs. Logged-in

Requirement: Different greeting for guests and logged-in users.

<ifgroup guest>
===== Welcome! =====
Please [[?do=login|log in]] for full access.
</ifgroup>

<ifgroup user>
===== Welcome Back! =====
You have access to all documentation.
</ifgroup>

Result:

Example 2: Admin Section

Requirement: Admin links visible only to administrators.

<ifgroup admin>
===== Administration =====
  * [[admin:dashboard|Dashboard]]
  * [[admin:users|Manage Users]]
  * [[admin:plugins|Manage Plugins]]
  * [[admin:config|Configuration]]
</ifgroup>

Result:

Example 3: Multilingual Landing Page

Requirement: Greeting in the visitor's browser language.

<iflang de>
===== Willkommen =====
Dies ist unsere Wissensdatenbank auf Deutsch.
</iflang>

<iflang en>
===== Welcome =====
This is our knowledge base in English.
</iflang>

<iflang sl>
===== Dobrodošli =====
To je naša baza znanja v slovenščini.
</iflang>

<iflang *>
===== Welcome =====
Please select your language above.
</iflang>

Result:

Example 4: Multilingual Error Page

Requirement: 404 page in the visitor's language.

<iflang de>
===== Seite nicht gefunden =====
Die angeforderte Seite existiert nicht.
[[start|Zurück zur Startseite]]
</iflang>

<iflang en>
===== Page Not Found =====
The requested page does not exist.
[[start|Back to homepage]]
</iflang>

<iflang *>
===== Error 404 =====
Page not found.
[[start|Home]]
</iflang>

Example 5: VIP Content

Requirement: Premium content only for VIP members.

<ifgroup vip,premium>
===== Exclusive Area =====
Here you'll find premium documentation and advanced tutorials.
  * [[premium:advanced|Advanced Features]]
  * [[premium:tutorials|Exclusive Tutorials]]
</ifgroup>

<ifgroup guest,user>
===== Premium Area =====
This area is reserved for VIP members.
[[contact|Request Upgrade]]
</ifgroup>

Example 6: Combined Conditions

Requirement: Multiple groups in a sidebar.

~~NOCACHE~~
===== Navigation =====
  * [[start|Home]]
  * [[docs:index|Documentation]]

<ifgroup user,admin>
  * [[internal:index|Internal Area]]
</ifgroup>

<ifgroup admin>
  * [[admin:index|Administration]]
</ifgroup>

<ifgroup guest>
  * [[?do=login|Log In]]
</ifgroup>

How It Works

Processing Pipeline

1. Tag Detection
   └── Finds all <ifgroup>...</ifgroup> and <iflang>...</iflang> tags

2. Condition Check
   ├── ifgroup: Checks $_SERVER['REMOTE_USER'] and group membership
   └── iflang: Checks Accept-Language header

3. Content Filtering
   ├── Condition met: Content is displayed
   └── Condition not met: Content is removed

4. Wildcard Processing
   └── <iflang *> is checked last (only if no other language matches)

Language Detection

The language is detected from the Accept-Language HTTP header:

Accept-Language: de-DE,de;q=0.9,en;q=0.8
                 ^^
                 Primary language: "de"
Header Example Detected Language
de-DE,de;q=0.9 de
en-US,en;q=0.9 en
sl-SI,sl;q=0.9 sl
fr-FR,en;q=0.5 fr

Configuration

The plugin requires no special configuration. Group detection uses standard DokuWiki ACL groups.

Important Note

Pages with <ifgroup> or <iflang> tags should use so content is re-rendered on each request.

Error Handling

Scenario Behavior
Unknown group Block is not displayed
Invalid language code Block is not displayed
No Accept-Language header Only * wildcard is displayed
Nested tags Outer tag takes priority

Best Practices

Correct

<ifgroup admin>Admin content</ifgroup>
<ifgroup user>User content</ifgroup>

Incorrect

<ifgroup admin>
  <ifgroup user>Nested content</ifgroup>
</ifgroup>

Version History

Version Date Changes
1.0.0 2025-01-06 Initial release

See Also


Technical Reference

Class: syntax_plugin_wvdsif

File: lib/plugins/wvdsif/syntax.php

Method Description
getType() Returns substition
getSort() Returns 100
connectTo($mode) Registers ifgroup and iflang patterns
handle($match, …) Parses tag and extracts condition
render($mode, …) Returns content or empty

Helper Functions

Function Description
_checkGroup($groups) Checks group membership
_checkLang($langs) Checks language match
_getBrowserLang() Extracts language from Accept-Language

Variables Used

Variable Source Description
$_SERVER['REMOTE_USER'] PHP Logged-in username
$USERINFO['grps'] DokuWiki User groups array
$_SERVER['HTTP_ACCEPT_LANGUAGE'] HTTP Browser language setting