]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - pgsrc/Help%2FHelloWorldPlugin
Update PHP Doc
[SourceForge/phpwiki.git] / pgsrc / Help%2FHelloWorldPlugin
1 Date: Fri, 10 Sep 2010 13:46:13 +0000
2 Mime-Version: 1.0 (Produced by PhpWiki 1.4.0)
3 Content-Type: application/x-phpwiki;
4   pagename=Help%2FHelloWorldPlugin;
5   flags=PAGE_LOCKED%2CEXTERNAL_PAGE;
6   charset=UTF-8
7 Content-Transfer-Encoding: binary
8
9 A simple example plugin.
10
11 <<HelloWorld salutation="Hello," name="Wiki User" >>
12
13 From the source of this page:
14
15 {{{
16 <<HelloWorld salutation="Hello," name="Wiki User" >>
17 }}}
18
19 ----
20 ~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,
21
22 * either with the predefined HTML classes to create valid XHTML,
23 * or by using templates, which are easier customizable, but generally more a mess to use and easier to create invalid XHTML.
24
25 <<PhpHighlight
26
27 /**
28  * A simple demonstration WikiPlugin.
29  *
30  * Usage:
31  * <<HelloWorld> >
32  * <<HelloWorld
33  *          salutation="Greetings, "
34  *          name=Wikimeister
35  * > >
36  * <<HelloWorld salutation=Hi > >
37  * <<HelloWorld name=WabiSabi > >
38  */
39
40 // Constants are defined before the class.
41 if (!defined('THE_END'))
42     define('THE_END', "!");
43
44 class WikiPlugin_HelloWorld
45 extends WikiPlugin
46 {
47     // Five required functions in a WikiPlugin.
48
49     function getName () {
50         return _("HelloWorld");
51     }
52
53     function getDescription () {
54         return _("Simple Sample Plugin");
55
56     }
57
58     // Establish default values for each of this plugin's arguments.
59     function getDefaultArguments() {
60         return array('salutation' => "Hello,",
61                      'name'       => "World");
62     }
63
64     function run($dbi, $argstr, $request) {
65         extract($this->getArgs($argstr, $request));
66
67         // Any text that is returned will not be further transformed,
68         // so use html where necessary.
69         $html = HTML::tt(fmt('%s: %s', $salutation, WikiLink($name, 'auto')),
70                          THE_END);
71         return $html;
72     }
73 };
74 >>
75
76 <noinclude>
77 ----
78 [[PhpWikiDocumentation]] [[CategoryWikiPlugin]]
79 </noinclude>