Date: Fri, 10 Sep 2010 13:46:13 +0000
Mime-Version: 1.0 (Produced by PhpWiki 1.4.0RC1)
X-Rcs-Id: $Id: Help%2FHelloWorldPlugin 7682 2010-09-10 12:03:36Z vargenau $
Content-Type: application/x-phpwiki;
  pagename=Help%2FHelloWorldPlugin;
  flags=PAGE_LOCKED%2CEXTERNAL_PAGE;
  markup=2;
  charset=UTF-8
Content-Transfer-Encoding: binary

A simple example plugin.

<<HelloWorld salutation="Hello," name="Wiki User" >>

From the source of this page:

{{{
<<HelloWorld salutation="Hello," name="Wiki User" >>
}}}

----
~PhpWiki's plugin architecture allows you to add custom page elements to your wiki. All you have to do is extend (subclass) the ~WikiPlugin class and create your output via the run() method, dependend on the Wiki- or Request arguments,

* either with the predefined HTML classes to create valid XHTML,
* or by using templates, which are easier customizable, but generally more a mess to use and easier to create invalid XHTML.

<<PhpHighlight

/**
 * A simple demonstration WikiPlugin.
 *
 * Usage:
 * <<HelloWorld> >
 * <<HelloWorld
 *          salutation="Greetings, "
 *          name=Wikimeister
 * > >
 * <<HelloWorld salutation=Hi > >
 * <<HelloWorld name=WabiSabi > >
 */

// Constants are defined before the class.
if (!defined('THE_END'))
    define('THE_END', "!");

class WikiPlugin_HelloWorld
extends WikiPlugin
{
    // Five required functions in a WikiPlugin.

    function getName () {
        return _("HelloWorld");
    }

    function getDescription () {
        return _("Simple Sample Plugin");

    }

    // Establish default values for each of this plugin's arguments.
    function getDefaultArguments() {
        return array('salutation' => "Hello,",
                     'name'       => "World");
    }

    function run($dbi, $argstr, $request) {
        extract($this->getArgs($argstr, $request));

        // Any text that is returned will not be further transformed,
        // so use html where necessary.
        $html = HTML::tt(fmt('%s: %s', $salutation, WikiLink($name, 'auto')),
                         THE_END);
        return $html;
    }
};
>>

<noinclude>
----
[[PhpWikiDocumentation]] [[CategoryWikiPlugin]]
</noinclude>
