From c7afc681dc4f38f8200fedbc63cd14f0ea9cfac4 Mon Sep 17 00:00:00 2001 From: carstenklapp Date: Sat, 4 Jan 2003 02:30:12 +0000 Subject: [PATCH] Added 'info' argument to show / hide plugin "Arguments" column. Improved row highlighting and error message when viewed by non-admin user. Code refactored. Added copyleft. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2483 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/PluginManager.php | 153 ++++++++++++++++++++++++++--------- 1 file changed, 116 insertions(+), 37 deletions(-) diff --git a/lib/plugin/PluginManager.php b/lib/plugin/PluginManager.php index 4c7d8b566..f30d1ce95 100644 --- a/lib/plugin/PluginManager.php +++ b/lib/plugin/PluginManager.php @@ -1,6 +1,24 @@ 'args'); } function run($dbi, $argstr, $request) { - //extract($this->getArgs($argstr, $request)); + extract($this->getArgs($argstr, $request)); - $msg = HTML::p("PluginManager provides the WikiAdmin the list of PhpWikiPlugin~s on this wiki."); + $h = HTML(); + $this->_generatePageheader($info, &$h); + + if ($request->_user->isadmin()) { + $h->pushContent(HTML::h2(_("Plugins"))); - if (! $request->_user->isadmin()) { - return $msg; // early return + $table = HTML::table(array('class' => "pagelist")); + $this->_generateColgroups($info, &$table); + $this->_generateColheadings($info, &$table); + $this->_generateTableBody($info, &$dbi, &$request, &$table); + $h->pushContent($table); + + //$h->pushContent(HTML::h2(_("Disabled Plugins"))); + } + else { + $h->pushContent(fmt("You must be an administrator to %s.", + _("use this plugin"))); } + return $h; + } + function _generatePageheader(&$info, &$html) { + $html->pushContent(HTML::p($this->getDescription())); + } - $pd = new fileSet(PHPWIKI_DIR . '/lib/plugin', '*.php'); - $plugins = $pd->getFiles(); + function _generateColgroups(&$info, &$table) { + // specify last two column widths + $colgroup = HTML::colgroup(); + $colgroup->pushContent(HTML::col(array('width' => '0*'))); + $colgroup->pushContent(HTML::col(array('width' => '0*', + 'align' => 'right'))); + $colgroup->pushContent(HTML::col(array('width' => '9*'))); + if ($info == 'args') + $colgroup->pushContent(HTML::col(array('width' => '2*'))); + $table->pushcontent($colgroup); + } - $h = HTML(); - $h->pushContent($msg); - $h->pushContent(HTML::h2(_("Plugins"))); - $row_no = 0; + function _generateColheadings(&$info, &$table) { + // table headings + $tr = HTML::tr(); + $headings = array(_("Plugin"), _("Version"), _("Description")); + if ($info == 'args') + $headings []= _("Arguments"); + foreach ($headings as $title) { + $tr->pushContent(HTML::td($title)); + } + $table->pushContent(HTML::thead($tr)); + } - $table = HTML::table(array('class' => "pagelist")); + function _generateTableBody(&$info, &$dbi, &$request, &$table) { + $row_no = 0; + $pd = new fileSet(PHPWIKI_DIR . '/lib/plugin', '*.php'); + $plugins = $pd->getFiles(); + // table body + $tbody = HTML::tbody(); global $WikiNameRegexp; foreach($plugins as $pname) { + // instantiate a plugin $pname = str_replace(".php", "", $pname); - $temppluginclass = ""; + $temppluginclass = ""; // hackish $w = new WikiPluginLoader; + // obtain plugin name & description $p = $w->getPlugin($pname); $desc = $p->getDescription(); + // obtain plugin version if (method_exists($p, 'getVersion')) { $ver = $p->getVersion(); } else { $ver = "--"; } - + // obtain plugin's default arguments + $arguments = HTML(); + $args = $p->getDefaultArguments(); + foreach ($args as $arg => $default) { + if (stristr($default, ' ')) + $default = "'$default'"; + $arguments->pushcontent("$arg=$default", HTML::br()); + } + // make a link if an actionpage exists $pnamelink = $pname; $plink = false; - if (preg_match("/^$WikiNameRegexp\$/", $pname) && $dbi->isWikiPage($pname)) + if (preg_match("/^$WikiNameRegexp\$/", $pname) + && $dbi->isWikiPage($pname)) $pnamelink = WikiLink($pname); - + // make another link if an XxxYyyPlugin page exists $ppname = $pname . "Plugin"; - if (preg_match("/^$WikiNameRegexp\$/", $ppname) && $dbi->isWikiPage($ppname)) + if (preg_match("/^$WikiNameRegexp\$/", $ppname) + && $dbi->isWikiPage($ppname)) $plink = WikiLink($ppname); else { - // exclude actionpages and plugins starting with _ from page list - if ( !preg_match("/^_/", $pname) && !(@$request->isActionPage($pname))) //FIXME + // don't link to actionpages and plugins starting with + // an _ from page list + if ( !preg_match("/^_/", $pname) + && !(@$request->isActionPage($pname)) ) //FIXME $plink = WikiLink($ppname, 'unknown'); else $plink = false; } + // highlight alternate rows $row_no++; - $group = (int)($row_no / 2); //_group_rows - $class = ($group % 2) ? 'oddrow' : 'evenrow'; - + $group = (int)($row_no / 1); //_group_rows + $class = ($group % 2) ? 'evenrow' : 'oddrow'; + // generate table row $tr = HTML::tr(array('class' => $class)); if ($plink) { - $tr->pushContent(HTML::td($plink), HTML::td($ver), HTML::td($desc)); - $tr2 = HTML::tr(array('class' => $class)); - $tr2->pushContent(HTML::td($pnamelink), HTML::td(" "), HTML::td(" ")); + // plugin has a XxxYyyPlugin page + $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink)); $plink = false; - $table->pushContent($tr, $tr2); - $row_no++; + //$row_no++; } else { - $tr->pushContent(HTML::td($pnamelink), HTML::td($ver), HTML::td($desc)); - $table->pushContent($tr); + // plugin just has an actionpage + $tr->pushContent(HTML::td($pnamelink)); + } + $tr->pushContent(HTML::td($ver), HTML::td($desc)); + if ($info == 'args') { + // add Arguments column + $style = array('style' + => 'font-family:monospace;font-size:smaller'); + $tr->pushContent(HTML::td($style, $arguments)); } + $tbody->pushContent($tr); } - $h->pushContent($table); - - //$h->pushContent(HTML::h2(_("Disabled Plugins"))); - - return $h; + $table->pushContent($tbody); } }; +/** + $Log: not supported by cvs2svn $ + */ + // Local Variables: // mode: php // tab-width: 8 -- 2.45.0