History of Wiki Plugin Tutorial
Version 11 | Current version | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IntroductionIn this tutorial, I am going to try to explain what a Wiki Plugin is, how to use them, how they work, and what is needed to create or modify them.Why should I learn this?By creating a Wiki Plugin, an administrator or developer is adding functionality to his site. This functionality has a lot of bang for the buck because Wiki Plugins work in Wiki Pages, Articles, Blogs, and in the WikiForum (to my knowledge, Plugins are not available in PhpBB Forums at this time).Wiki Plugins are also fairly simple and provide a good place for beginners to “play”. All that is required is a little knowledge of HTML and the PHP language or the ability to look things up. -= The Wiki Plugin “DIV” will be used for this tutorial =-So what does this Plugin do?The DIV Plugin creates a division block so that text inside it can have a different background color, width, and alignment.How is a Plugin used?Our DIV Plugin (like most Plugins) operates on specific text. That text is encased in a pair of code blocks. A code block is the name of the Wiki Plugin to be used inside a pair of curly brackets “{“ and “}” like this:{DIV} Text Inside the Block {DIV} Please Note: the name of the Plugin has to be capitalized. To make Plugins more functional, additional information (parameters) may be passed to them. This is done by adding parameters to the first code block in normal brackets - “(“ and “)”. Each parameter name is given – followed by the Equal and Greater-Than characters “=>” – and then a value. Each parameter must be separated from the others with a comma character “,”. Our DIV Plugin uses 3 parameters named bg, width and align.
Some Examples:{DIV(bg=>red,width=>25%,align=>left)} An old poem {DIV} {DIV(bg=>red,width=>25%,align=>left)} An old poem Who’s fleece was white as snow Everywhere that Mary went The lamb was sure to go {DIV} {DIV(bg=>cyan,width=>50%,align=>center)} Mary had a little lamb Who’s fleece was white as snow Everywhere that Mary went The lamb was sure to go {DIV(bg=>green,width=>25%,align=>right)} Written by: somebody nobody remembers {DIV} {DIV(bg=>green,width=>25%,align=>right)} Written by: somebody nobody remembers {DIV} Where do I find these Plugins?The best way to become fluent with Wiki Plugins is to use them. A complete listing of Plugins can be found at the bottom of the Wiki Page Editor. Selecting Plugins will display this listing. Selecting “More details” will show all of the parameters for that Plugin as well as an example or two.The actual files are stored in the Wiki/Plugins directory. The files use a strict file naming convention that must be adhered to. For our DIV Plugin, the filename is “wikiplugin_div.php”. A Little HistoryThere are 2 different kinds of Wiki Plugins. Originally, a few Plugins were imported into TikiWiki using a very simple structure. The idea was later expanded on to provide Object Oriented Plugins. The original Non-Object Oriented variety will be discussed first.At first a Plugin only required a single function to operate - the executable function. There were only a few Plugins at the time so it wasn’t a problem. Calling {DIV} would execute the div function in the div.php file. Later, a file / function naming standard was established. This allowed each Plugin to maintain it’s own documentation and provide an explanation of what it did – and what it needed - to the user. This was done in a catch-as-catch-can manner and most of the information was only partially available. In the Bonnie version of bitweaver, all of the Wiki Plugins had a face-lift. The main help function was rewritten to provide a general description of the Plugin and another function was added to provide information about the parameters as well as some examples. The File Name / Function Name StandardSince only part of the file name is given, a routine in the wiki/wiki_lib.php file joins our {DIV} statements into a file name so that the correct Plugin is called. In this case it is “wikiplugin_div.php”. The same method is used to determine which functions are called. The naming convention is:
The Help Function - wikiplugin_div_help(){CODE(in=>1)}function wikiplugin_div_help() {$back = tra("This plugin insert a division block in the page. This allows you to control the location and background color of text with the block.\n"); $back.= tra("Syntax: ") . " " . tra("Text Inside The Block")." ";return $back; }{CODE} NOTE: The removal of an NP statement was required to allow this to code to be displayed properly -= When the routine is run it should look something like this =-DIV - This plugin insert a division block in the page. This allows you to control the location and background color of text with the block. Please Note: Wiki Syntax is used in the Help Routines to control their appearance.Syntax: {DIV(bg=> ,width=> ,align=> )} Text Inside The Block {DIV} The Extended Help Function - wikiplugin_div_extended_help(){CODE(in=>1)}function wikiplugin_div_extended_help() {$back = tra(" Parameter Syntax: ") . "{BOX(Key=>value)} \n"; ");$back.= tra("
$back.= tra(" Example: ") . "{DIV(bg=>#FFDDFF,align=>left)}" . tra("Text Inside The Div") . "{DIV} \n"; ");$back.= tra("This creates an area with a pinkish background. Because the width was not specified it will be the entire pages width. The text is left alligned. $back.= tra(" Note: Plugin's are case sensitive. The Name of the plugin MUST be UPPERCASE. The Key(s) are always lowercase. Some Values are mixed-case but most require lowercase. When in doubt - look at the Example.\n"); ");$back.= tra("Note 2: One useful place for obtaining HTML colors is ") . "" . tra("The Color Picker II return $back; }{CODE}NOTE: The removal of 2 NP statements was required to allow this to code to display properly -= When the routine is run it should look something like this =-Parameter Syntax: BOX(Key=>value)}
Example: {DIV(bg=>#FFDDFF,align=>left)} Text Inside The Div {DIV} This creates an area with a pinkish background. Because the width was not specified it will be the entire pages width. The text is left aligned. Note: Plugin's are case sensitive. The Name of the plugin MUST be UPPERCASE. The Key(s) are always lowercase. Some Values are mixed-case but most require lowercase. When in doubt - look at the Example. Please Note: Wiki Syntax is used in the Help Routines to control their appearance.Note 2: One useful place for obtaining HTML colors is The Color Picker II The Executed Function - wikiplugin_div($data, $params){CODE(in=>1)}function wikiplugin_div($data, $params) {/* set default values for some args */ $align = "left"; extract ($params); $w = (isset($width)) ? " width: $width;" : ""; $bg = (isset($bg)) ? " background: $bg;" : ""; $al = (isset($align) && ($align == 'right'
key | value | Comments \n");$back.= " page " . tra(" | pagename | any wiki page. The default is the current page.\n");$back.= " info " . tra(" | option | defines what is to be displayed. Allows multiple columns if joined with the character |. Available choices are: ") . "hits, lastModif, user, ip, len, comment, creator, version, flag, versions, links, backlinks.\n";$back.= " exclude " . tra(" | pagename(s) | any wiki page. Allows multiple pagenames if joined with the character |. Like this: ") . "HomePage|SandBox.\n";$back.= " include_self " . tra(" | number | The default is ") . "False" . tra(" - use 1 to enable.\n");$back.= " noheader " . tra(" | number | The default is ") . "False" . tra(" - use 1 to enable.||$back.= tra(" Example: ") . "{BACKLINKS(page=>MyHomePage,info=>hits|user,exclude=>HomePage|SandBox,include_self=>1,noheader=>1)}{BACKLINKS} ";$back.= tra(" Note: Plugin's are case sensitive. The Name of the plugin MUST be UPPERCASE. The Key(s) are always lowercase. Some Values are mixed-case but most require lowercase. When in doubt - look at the Example. ");return $back; } function getVersion() { return preg_replace("/Revision: $/", '', "\$Revision: 1.3.2.5 $"); } function run ($data, $params) { global $wikilib; $params = $this->getParams($params, true); $aInfoPreset = array_keys($this->aInfoPresetNames); extract ($params); ///////////////////////////////// // Create a valid list for $info ///////////////////////////////// // if ($info) { $info_temp = array(); foreach($info as $sInfo) { if (in_array(trim($sInfo), $aInfoPreset)) { $info_temp[] = trim($sInfo); } $info = $info_temp?$info_temp: false; } } $sOutput = ""; // Verify if the page exists if (!$wikilib->page_exists($page)) { return $this->error(tra("Page cannot be found")." : $page"); } // ///////////////////////////////// // Process backlinks ///////////////////////////////// // $aBackRequest = array(); $aBackLinks = $wikilib->get_backlinks($page); foreach($aBackLinks as $backlink) { if (!in_array($backlink"fromPage", $exclude)) { $aBackRequest[] = $backlink"fromPage"; } } if ($include_self) { $aBackRequest[] = $page; } if (!$aBackRequest) { return tra("No pages link to")." (($page))"; } else { $aPages = $this->list_pages(0, -1, 'pageName_desc', $aBackRequest); } // ///////////////////////////////// // Start of Output ///////////////////////////////// // if (!$noheader) { // Create header $count = $aPages"cant"; if ($count == 1) { $sOutput .= tra("One page links to")." (($page))"; } else { $sOutput = "$count ".tra("pages link to")." (($page))"; } $sOutput .= "\n"; } $sOutput .= PluginsLibUtil::createTable($aPages"data", $info); return $sOutput; } } function wikiplugin_backlinks($data, $params) { $plugin = new WikiPluginBackLinks(); return $plugin->run($data, $params); } function wikiplugin_backlinks_help() { $plugin = new WikiPluginBackLinks(); return $plugin->getDescription(); } function wikiplugin_backlinks_extended_help() { $plugin = new WikiPluginBackLinks(); return $plugin->getBiggerDescription(); } ?>{CODE} First - The three functions mentioned earlier are still included at the bottom of the file on lines 121, 125, and 129. Second - Because this Plugin is object oriented, each of these functions first has to create an instance of the object and then call the proper method. The names of the help method can be anything at this time – as this example shows. Third - The methods that the two help routines call (getDescription on line 37 and getBiggerDescription on line 42) are almost identical to the non-object oriented functions. Forth - The executable method should always be named run. While this is not manditory, there are several other methods that are called by other routines. These include: getName on line 34 and getVersion on line 54. While these methods do not seem to be used - they are. One place where they are used is by the plugin PLUGINMANAGER. Unfortunatly, that plugin does not work all that well with non-object oriented plugins. Fifth - The run method in most ways is identical to a non-object oriented executable function. Converting all of the non-object oriented plugins to object oriented plugins (or vice-versa) should not be a major undertaking. The only question is - why do it at all. Good Luck and Happy Programming (:biggrin:) | IntroductionIn this tutorial, I am going to try to explain what a Wiki Plugin is, how to use them, how they work, and what is needed to create or modify them.Why should I learn this?By creating a Wiki Plugin, an administrator or developer is adding functionality to his site. This functionality has a lot of bang for the buck because Wiki Plugins work in Wiki Pages, Articles, Blogs, and in the WikiForum (to my knowledge, Plugins are not available in PhpBB Forums at this time).Wiki Plugins are also fairly simple and provide a good place for beginners to “play”. All that is required is a little knowledge of HTML and the PHP language or the ability to look things up. -= The Wiki Plugin “DIV” will be used for this tutorial =-So what does this Plugin do?The DIV Plugin creates a division block so that text inside it can have a different background color, width, and alignment.How is a Plugin used?Our DIV Plugin (like most Plugins) operates on specific text. That text is encased in a pair of code blocks. A code block is the name of the Wiki Plugin to be used inside a pair of curly brackets “{“ and “}” like this:{DIV} Text Inside the Block {DIV} Please Note: the name of the Plugin has to be capitalized. To make Plugins more functional, additional information (parameters) may be passed to them. This is done by adding parameters to the first code block in normal brackets - “(“ and “)”. Each parameter name is given – followed by the Equal and Greater-Than characters “=>” – and then a value. Each parameter must be separated from the others with a comma character “,”. Our DIV Plugin uses 3 parameters named bg, width and align.
Some Examples:{DIV(bg=>red,width=>25%,align=>left)} An old poem {DIV} {DIV(bg=>red,width=>25%,align=>left)} An old poem Who’s fleece was white as snow Everywhere that Mary went The lamb was sure to go {DIV} {DIV(bg=>cyan,width=>50%,align=>center)} Mary had a little lamb Who’s fleece was white as snow Everywhere that Mary went The lamb was sure to go {DIV(bg=>green,width=>25%,align=>right)} Written by: somebody nobody remembers {DIV} {DIV(bg=>green,width=>25%,align=>right)} Written by: somebody nobody remembers {DIV} Where do I find these Plugins?The best way to become fluent with Wiki Plugins is to use them. A complete listing of Plugins can be found at the bottom of the Wiki Page Editor. Selecting Plugins will display this listing. Selecting “More details” will show all of the parameters for that Plugin as well as an example or two.The actual files are stored in the Wiki/Plugins directory. The files use a strict file naming convention that must be adhered to. For our DIV Plugin, the filename is “wikiplugin_div.php”. A Little HistoryThere are 2 different kinds of Wiki Plugins. Originally, a few Plugins were imported into TikiWiki using a very simple structure. The idea was later expanded on to provide Object Oriented Plugins. The original Non-Object Oriented variety will be discussed first.At first a Plugin only required a single function to operate - the executable function. There were only a few Plugins at the time so it wasn’t a problem. Calling {DIV} would execute the div function in the div.php file. Later, a file / function naming standard was established. This allowed each Plugin to maintain it’s own documentation and provide an explanation of what it did – and what it needed - to the user. This was done in a catch-as-catch-can manner and most of the information was only partially available. In the Bonnie version of bitweaver, all of the Wiki Plugins had a face-lift. The main help function was rewritten to provide a general description of the Plugin and another function was added to provide information about the parameters as well as some examples. The File Name / Function Name StandardSince only part of the file name is given, a routine in the wiki/wiki_lib.php file joins our {DIV} statements into a file name so that the correct Plugin is called. In this case it is “wikiplugin_div.php”. The same method is used to determine which functions are called. The naming convention is:
The Help Function - wikiplugin_div_help(){CODE(in=>1)}function wikiplugin_div_help() {$back = tra("This plugin insert a division block in the page. This allows you to control the location and background color of text with the block.\n"); $back.= tra("Syntax: ") . " " . tra("Text Inside The Block")." ";return $back; }{CODE} NOTE: The removal of an NP statement was required to allow this to code to be displayed properly -= When the routine is run it should look something like this =-DIV - This plugin insert a division block in the page. This allows you to control the location and background color of text with the block. Please Note: Wiki Syntax is used in the Help Routines to control their appearance.Syntax: {DIV(bg=> ,width=> ,align=> )} Text Inside The Block {DIV} The Extended Help Function - wikiplugin_div_extended_help(){CODE(in=>1)}function wikiplugin_div_extended_help() {$back = tra(" Parameter Syntax: ") . "{BOX(Key=>value)} \n"; ");$back.= tra("
$back.= tra(" Example: ") . "{DIV(bg=>#FFDDFF,align=>left)}" . tra("Text Inside The Div") . "{DIV} \n"; ");$back.= tra("This creates an area with a pinkish background. Because the width was not specified it will be the entire pages width. The text is left alligned. $back.= tra(" Note: Plugin's are case sensitive. The Name of the plugin MUST be UPPERCASE. The Key(s) are always lowercase. Some Values are mixed-case but most require lowercase. When in doubt - look at the Example.\n"); ");$back.= tra("Note 2: One useful place for obtaining HTML colors is ") . "" . tra("The Color Picker II return $back; }{CODE}NOTE: The removal of 2 NP statements was required to allow this to code to display properly -= When the routine is run it should look something like this =-Parameter Syntax: BOX(Key=>value)}
Example: {DIV(bg=>#FFDDFF,align=>left)} Text Inside The Div {DIV} This creates an area with a pinkish background. Because the width was not specified it will be the entire pages width. The text is left aligned. Note: Plugin's are case sensitive. The Name of the plugin MUST be UPPERCASE. The Key(s) are always lowercase. Some Values are mixed-case but most require lowercase. When in doubt - look at the Example. Please Note: Wiki Syntax is used in the Help Routines to control their appearance.Note 2: One useful place for obtaining HTML colors is The Color Picker II The Executed Function - wikiplugin_div($data, $params){CODE(in=>1)}function wikiplugin_div($data, $params) {/* set default values for some args */ $align = "left"; extract ($params); $w = (isset($width)) ? " width: $width;" : ""; $bg = (isset($bg)) ? " background: $bg;" : ""; $al = (isset($align) && ($align == 'right'
key | value | Comments \n");$back.= " page " . tra(" | pagename | any wiki page. The default is the current page.\n");$back.= " info " . tra(" | option | defines what is to be displayed. Allows multiple columns if joined with the character |. Available choices are: ") . "hits, lastModif, user, ip, len, comment, creator, version, flag, versions, links, backlinks.\n";$back.= " exclude " . tra(" | pagename(s) | any wiki page. Allows multiple pagenames if joined with the character |. Like this: ") . "HomePage|SandBox.\n";$back.= " include_self " . tra(" | number | The default is ") . "False" . tra(" - use 1 to enable.\n");$back.= " noheader " . tra(" | number | The default is ") . "False" . tra(" - use 1 to enable.||$back.= tra(" Example: ") . "{BACKLINKS(page=>MyHomePage,info=>hits|user,exclude=>HomePage|SandBox,include_self=>1,noheader=>1)}{BACKLINKS} ";$back.= tra(" Note: Plugin's are case sensitive. The Name of the plugin MUST be UPPERCASE. The Key(s) are always lowercase. Some Values are mixed-case but most require lowercase. When in doubt - look at the Example. ");return $back; } function getVersion() { return preg_replace("/Revision: $/", '', "\$Revision: 1.3.2.5 $"); } function run ($data, $params) { global $wikilib; $params = $this->getParams($params, true); $aInfoPreset = array_keys($this->aInfoPresetNames); extract ($params); ///////////////////////////////// // Create a valid list for $info ///////////////////////////////// // if ($info) { $info_temp = array(); foreach($info as $sInfo) { if (in_array(trim($sInfo), $aInfoPreset)) { $info_temp[] = trim($sInfo); } $info = $info_temp?$info_temp: false; } } $sOutput = ""; // Verify if the page exists if (!$wikilib->page_exists($page)) { return $this->error(tra("Page cannot be found")." : $page"); } // ///////////////////////////////// // Process backlinks ///////////////////////////////// // $aBackRequest = array(); $aBackLinks = $wikilib->get_backlinks($page); foreach($aBackLinks as $backlink) { if (!in_array($backlink"fromPage", $exclude)) { $aBackRequest[] = $backlink"fromPage"; } } if ($include_self) { $aBackRequest[] = $page; } if (!$aBackRequest) { return tra("No pages link to")." (($page))"; } else { $aPages = $this->list_pages(0, -1, 'pageName_desc', $aBackRequest); } // ///////////////////////////////// // Start of Output ///////////////////////////////// // if (!$noheader) { // Create header $count = $aPages"cant"; if ($count == 1) { $sOutput .= tra("One page links to")." (($page))"; } else { $sOutput = "$count ".tra("pages link to")." (($page))"; } $sOutput .= "\n"; } $sOutput .= PluginsLibUtil::createTable($aPages"data", $info); return $sOutput; } } function wikiplugin_backlinks($data, $params) { $plugin = new WikiPluginBackLinks(); return $plugin->run($data, $params); } function wikiplugin_backlinks_help() { $plugin = new WikiPluginBackLinks(); return $plugin->getDescription(); } function wikiplugin_backlinks_extended_help() { $plugin = new WikiPluginBackLinks(); return $plugin->getBiggerDescription(); } ?>{CODE} First - The three functions mentioned earlier are still included at the bottom of the file on lines 121, 125, and 129. Second - Because this Plugin is object oriented, each of these functions first has to create an instance of the object and then call the proper method. The names of the help method can be anything at this time – as this example shows. Third - The methods that the two help routines call (getDescription on line 37 and getBiggerDescription on line 42) are almost identical to the non-object oriented functions. Forth - The executable method should always be named run. While this is not manditory, there are several other methods that are called by other routines. These include: getName on line 34 and getVersion on line 54. While these methods do not seem to be used - they are. One place where they are used is by the plugin PLUGINMANAGER. Unfortunatly, that plugin does not work all that well with non-object oriented plugins. Fifth - The run method in most ways is identical to a non-object oriented executable function. Converting all of the non-object oriented plugins to object oriented plugins (or vice-versa) should not be a major undertaking. The only question is - why do it at all. Good Luck and Happy Programming (:biggrin:) |