Translations of this page?:

Plugin Cookbook

This page shall become a collection of common recipes for developing plugins. For each recipe, the problem or task to solve is described first and then followed by a solution and a small exemplary code snippet.

Please contribute!

Checking user-input text against the DokuWiki blacklist

You have some user input you want to validate using the internal blacklist (e.g. as an anti-spam measure for comments or anything like that).

Make a temporary backup of the current content of the internal $TEXT variable (which usually contains the wiki text of the displayed page), the put your text into $TEXT. A call to checkwordblock() should then yield a result of true if the processed text contains any blocked words, and false otherwise. Don't forget to restore the original content of $TEXT after you are done checking your user input by copying it back from the backup you made.

Example:

// backup and reset the current $TEXT variable
$backupText = $TEXT;
$TEXT = $userinput;
 
if (checkwordblock()) {
    // text contains blocked words ...
}
 
// restore $TEXT
$TEXT = $backupText;

Disabling syntax plugins in user comments

You have written a syntax plugin which will be used in a restricted environment were anonymous users are not allowed to edit pages but allowed to comment using the discussion plugin. You do not want to disable wiki syntax in comments completely, but want to disable the syntax provided by your plugin as it can become a risk in the wrong hands.

In your plugin's handle method, check whether $_REQUEST['comment'] is set – this indicates that the parsing process is working on a discussion comment.

Example:

// we are parsing a submitted comment...
if (isset($_REQUEST['comment']))
    return false;
 
devel/plugin_cookbook.txt · Last modified: 2008/10/28 00:59 by 70.103.232.219
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate