Source for file plugins_lib.php
Documentation is available at plugins_lib.php
* A port of PhpWiki WikiPlugin class
* Principal use is port PhpWiki plugins, but can be used to make new ones.
* - Extends PluginsLib with your class
* include "pluginslib.php";
* function wikiplugin_backlinks($data, $params) {
* $plugin = new BackLinks();
* return $plugin->run($data, $params);
* function wikiplugin_backlinks_help() {
* $plugin = new BackLinks();
* return $plugin->getDescription();
* Array of params to be expanded as arrays. Explode the string with {@link $separator}
* Separator used to explote params listed on {@link $expanded_params}
* List of fields retrieved from {@link BitBase::list_pages()}
* Keys are the name of the fields and values the names for tra();
"hits" => "Hits", "last_modified" => "Last mod", "user" => "Last author", "len" => "Size", "comment" => "Com", "creator" => "Creator", "version" => "Last ver", "flag" => "Status", "versions" => "Vers", "links" => "Links", "backlinks" => "Backlinks");
* Process the params, in this order:
* - default values, asigned on {@link PluginsLib::getDefaultArguments()}
* - request values, sended by GET or POST method, if $request is put to true
* - explicit values, asigned on the Wiki
* @param array sended to wikiplugin_name($data, $params)
* @param bool if set to true, accept values from $_REQUEST
* @param bool if set to true, assign default values from {@link PluginsLib::getDefaultArguments()}
* @return array list of params
function getParams($params, $request = false, $defaults = false) {
if ($defaults === false) {
foreach ($defaults as $arg => $default_val) {
if (isset ($params[$arg])) {
$args[$arg] = $params[$arg];
} elseif(isset ($_REQUEST[$arg])) {
$args[$arg] = $_REQUEST[$arg];
// maybe this kind of transformation can be grouped on a external function
if ($default_val=== "[pagename]") {
$default_val= $_REQUEST["page"];
$args[$arg] = $default_val;
foreach($args[$arg] as $id=> $value) {
$args[$arg][$id]= trim($value);
* Returns the name of the Plugin
* By default, erase the first 'WikiPlugin'
* Returns a description of the Plugin
* Returns the version of the version
return tra("No version indicated");
//return preg_replace("/[Revision: $]/", '',
* Returns the default arguments for the plugin
* Use keys as the arguments and values as ... the default values
* For sake of God, overload it!
function run ($data, $params) {
return $this->error("PluginsLib::run: pure virtual function. Don't be so lazy!");
function error ($message) {
return "~np~<span class='warn'>Plugin ". $this->getName(). " ". tra("failed"). " : ". tra($message). "</span>~/np~";
* Class with utilities for Plugins
* Create a table with information from pages
* @param array list of keys to show.
* @param array definition of the principal field. By default:
* array("field"=>"title","name"=>"Page")
function createTable($aData,$aInfo= false,$aPrincipalField= false) {
if (!$aPrincipalField or !is_array($aPrincipalField)) {
$aPrincipalField= array("field"=> "title","name"=> "Page");
$iNumCol= count($aInfo)+ 1;
$sStyle= " style='width:". (floor(100/ $iNumCol)). "%' ";
$sOutput .= "<table class='normal'><tr><td class='heading' $sStyle>". tra($aPrincipalField["name"]). "</td>";
foreach($aInfo as $iInfo => $sHeader) {
$sOutput .= "<td class='heading' $sStyle >". tra($sHeader). "</td>";
foreach($aData as $aPage) {
$sClass= ($iCounter% 2)? "odd": "even";
$sOutput .= "*((". $aPage[$aPrincipalField["field"]]. "))\n";
$sOutput .= "<tr><td class='$sClass'>((". $aPage[$aPrincipalField["field"]]. "))</td>";
foreach($aInfo as $sInfo) {
if (isset ($aPage[$sInfo])) {
$sOutput .= "<td class='$sClass'>". $aPage[$sInfo]. "</td>";
|