From: Carsten K. <car...@us...> - 2003-01-04 02:30:15
|
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory sc8-pr-cvs1:/tmp/cvs-serv30585 Modified Files: PluginManager.php Log Message: 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. Index: PluginManager.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/PluginManager.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -2 -b -p -d -r1.2 -r1.3 --- PluginManager.php 30 Dec 2002 23:49:35 -0000 1.2 +++ PluginManager.php 4 Jan 2003 02:30:12 -0000 1.3 @@ -1,5 +1,23 @@ <?php // -*-php-*- rcs_id('$Id$'); + /** + Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam + + This file is part of PhpWiki. + + PhpWiki is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PhpWiki is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PhpWiki; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -12,5 +30,5 @@ extends WikiPlugin function getDescription () { - return _("Overview of the available PhpWikiPlugins"); + return _("Provides a list of plugins on this wiki."); } @@ -21,33 +39,75 @@ extends WikiPlugin function getDefaultArguments() { - return array(); + return array('info' => '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()) { - return $msg; // early return + if ($request->_user->isadmin()) { + $h->pushContent(HTML::h2(_("Plugins"))); + + $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 = "<? plugin " . /*"WikiPlugin_" .*/ $pname . " ?>"; + $temppluginclass = "<? plugin $pname ?>"; // 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(); @@ -56,45 +116,69 @@ extends WikiPlugin $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$ + Revision 1.3 2003/01/04 02:30:12 carstenklapp + 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. + + */ // Local Variables: |