From 77b23bf6a002042df9eebcdc0e471cc45551b724 Mon Sep 17 00:00:00 2001 From: rurban Date: Sun, 13 Jun 2004 13:54:25 +0000 Subject: [PATCH] Catch fatals on the four dump calls (as file and zip, as html and mimified) FoafViewer: Check against external requirements, instead of fatal. Change output for xhtmldumps: using file:// urls to the local fs. Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@3673 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/Google.php | 13 +++++---- lib/IniConfig.php | 18 ++++++++----- lib/loadsave.php | 53 +++++++++++++++++++++++++++++++------ lib/main.php | 6 ++++- lib/plugin/FoafViewer.php | 33 +++++++++++++++++++---- lib/plugin/GooglePlugin.php | 15 ++++++++--- lib/stdlib.php | 9 +++++-- 7 files changed, 115 insertions(+), 32 deletions(-) diff --git a/lib/Google.php b/lib/Google.php index e41374516..dc09985e9 100644 --- a/lib/Google.php +++ b/lib/Google.php @@ -156,11 +156,12 @@ class Google { function Google($maxResults=10,$license_key=false,$proxy=false) { if ($license_key) $this->license_key = $license_key; - elseif (!defined('GOOGLE_LICENSE_KEY')) - return HTML::div(array('class' => 'errors'), - fmt("You must first obtain a license key at %s to be able to use the Google API.", - WikiLink("http://www.google.com/apis/")), - fmt("It's free however.")); + elseif (!defined('GOOGLE_LICENSE_KEY')) { + trigger_error("\nYou must first obtain a license key at http://www.google.com/apis/" + ."\nto be able to use the Google API.". + "\nIt's free however.", E_USER_WARNING); + return false; + } else $this->license_key = GOOGLE_LICENSE_KEY; require_once("lib/nusoap/nusoap.php"); @@ -219,6 +220,8 @@ class Google { function doGoogleSearch($query, $startIndex=1, $maxResults=10, $filter = "false", $restrict='', $safeSearch='false', $lr='', $inputencoding='UTF-8', $outputencoding='UTF-8') { + if (!defined("GOOGLE_LICENSE_KEY")) + return false; // doGoogleSearch() gets created automatically!! (some eval'ed code from the soap request) $result = $this->doGoogleSearch(GOOGLE_LICENSE_KEY, // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $query, diff --git a/lib/IniConfig.php b/lib/IniConfig.php index 05bdcd1fa..1136067b5 100644 --- a/lib/IniConfig.php +++ b/lib/IniConfig.php @@ -1,5 +1,5 @@ isFatal()) { + $error->errno = E_USER_WARNING; + return true; + } + return false; // let the message come through: call the remaining handlers: + /* + if (preg_match('/Plugin/',$error->errstr)) + return true; // Ignore error + */ +} + function StartLoadDump(&$request, $title, $html = '') { // FIXME: This is a hack @@ -32,10 +47,16 @@ function StartLoadDump(&$request, $title, $html = '') 'HEADER' => $title, 'CONTENT' => '%BODY%')); echo ereg_replace('%BODY%.*', '', $tmpl->getExpansion($html)); + + /* ignore fatals in plugins */ + global $ErrorManager; + $ErrorManager->pushErrorHandler(new WikiFunctionCb('_ignore_fatal_plugin_error_handler')); } function EndLoadDump(&$request) { + global $ErrorManager; + $ErrorManager->popErrorHandler(); // FIXME: This is a hack $pagelink = WikiLink($request->getPage()); @@ -135,9 +156,12 @@ function MakeWikiZip (&$request) } - $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); + /* ignore fatals in plugins */ + global $ErrorManager; + $ErrorManager->pushErrorHandler(new WikiFunctionCb('_ignore_fatal_plugin_error_handler')); + $dbi = $request->getDbh(); $pages = $dbi->getAllPages(); while ($page = $pages->next()) { @@ -166,6 +190,7 @@ function MakeWikiZip (&$request) $content, $attrib); } $zip->finish(); + $ErrorManager->popErrorHandler(); } function DumpToDir (&$request) @@ -265,11 +290,6 @@ function DumpHtmlToDir (&$request) $msg = HTML(HTML::br(), $pagename, ' ... '); - if($page->getName() != $filename) { - $msg->pushContent(HTML::small(fmt("saved as %s", $filename)), - " ... "); - } - $revision = $page->getCurrentRevision(); $transformedContent = $revision->getTransformedContent(); $template = new Template('browse', $request, @@ -283,8 +303,17 @@ function DumpHtmlToDir (&$request) "$directory/$filename"))); $request->finish($msg); } - $num = fwrite($fd, $data, strlen($data)); + if($page->getName() != $filename) { + $prefix = ''; + if (isWindows()) { + // drive where apache is installed + $prefix = '/' . substr($_SERVER["DOCUMENT_ROOT"],0,2); + } + $link = LinkURL("file://".$prefix.$directory."/".$filename, + $filename); + $msg->pushContent(HTML::small(_("saved as "), $link, " ... ")); + } $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n")); PrintXML($msg); @@ -350,6 +379,10 @@ function MakeWikiZipHtml (&$request) if (defined('HTML_DUMP_SUFFIX')) $Theme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX; + /* ignore fatals in plugins */ + global $ErrorManager; + $ErrorManager->pushErrorHandler(new WikiFunctionCb('_ignore_fatal_plugin_error_handler')); + while ($page = $pages->next()) { if (! $request->getArg('start_debug')) @set_time_limit(30); // Reset watchdog. @@ -380,6 +413,7 @@ function MakeWikiZipHtml (&$request) } // FIXME: Deal with images here. $zip->finish(); + $ErrorManager->popErrorHandler(); $Theme->$HTML_DUMP_SUFFIX = ''; } @@ -916,6 +950,9 @@ function LoadPostFile (&$request) /** $Log: not supported by cvs2svn $ + Revision 1.105 2004/06/08 19:48:16 rurban + fixed foreign setup: no ugly skipped msg for the GenericPages, load english actionpages if translated not found + Revision 1.104 2004/06/08 13:51:57 rurban some comments only diff --git a/lib/main.php b/lib/main.php index ab5b1ec39..bc7a4d07c 100644 --- a/lib/main.php +++ b/lib/main.php @@ -1,5 +1,5 @@ version = phpwiki_version(); function _isActionPage ($pagename) { $dbi = $this->getDbh(); $page = $dbi->getPage($pagename); + if (!$page) return false; $rev = $page->getCurrentRevision(); // FIXME: more restrictive check for sane plugin? if (strstr($rev->getPackedContent(), 'errstr,"Failed opening required 'XML/FOAF/Parser.php'")) + return true; + elseif (strstr($error->errstr,'No such file or directory')) + return true; + return false; + } + function getName() { return _("FoafViewer"); } @@ -51,7 +58,7 @@ extends WikiPlugin function getVersion() { return preg_replace("/[Revision: $]/", '', - "\$Revision: 1.1 $"); + "\$Revision: 1.2 $"); } function getDefaultArguments() { @@ -62,6 +69,19 @@ extends WikiPlugin } function run($dbi, $argstr, $request, $basepage) { + + /* ignore fatal on loading */ + /* + global $ErrorManager; + $ErrorManager->pushErrorHandler(new WikiMethodCb($this,'_error_handler')); + */ + // Require the XML_FOAF_Parser class. This is a pear library not included with phpwiki. + //if (findFile('XML/FOAF/Parser.php','missing_ok')) + require_once 'XML/FOAF/Parser.php'; + //$ErrorManager->popErrorHandler(); + if (!class_exists('XML_FOAF_Parser')) + return $this->error(_("required pear library XML/FOAF/Parser.php not found in include_path")); + extract($this->getArgs($argstr, $request)); // Get our FOAF File from the foaf plugin argument or $_GET['foaf'] if (empty($foaf)) $foaf = $request->getArg('foaf'); @@ -197,6 +217,9 @@ extends WikiPlugin // $Log: not supported by cvs2svn $ +// Revision 1.1 2004/06/08 21:38:21 rurban +// based on dans version 0.0.2 - simplified +// // For emacs users // Local Variables: diff --git a/lib/plugin/GooglePlugin.php b/lib/plugin/GooglePlugin.php index cc178fce2..5a7b26556 100644 --- a/lib/plugin/GooglePlugin.php +++ b/lib/plugin/GooglePlugin.php @@ -1,5 +1,5 @@ isPost()) { + // prevent from dump + if ($q and $request->isPost()) { require_once("lib/Google.php"); $google = new Google(); + if (!$google) return ''; switch ($mode) { case 'search': $result = $google->doGoogleSearch($q); break; case 'cache': $result = $google->doGetCachedPage($q); break; @@ -107,13 +109,18 @@ extends WikiPlugin 'size' => $formsize))); $form->pushContent(HTML::input(array('type' => 'submit', 'class' => 'button', - 'value' => $mode + 'value' => gettext($mode) ))); return HTML($html,$form); } }; // $Log: not supported by cvs2svn $ +// Revision 1.2 2004/04/18 01:11:52 rurban +// more numeric pagename fixes. +// fixed action=upload with merge conflict warnings. +// charset changed from constant to global (dynamic utf-8 switching) +// // Revision 1.1 2004/02/29 01:37:59 rurban // New experimental feature: use the Google API directly // Needs a free license key and the soap library nosoap, diff --git a/lib/stdlib.php b/lib/stdlib.php index ee866006d..d40514a1a 100644 --- a/lib/stdlib.php +++ b/lib/stdlib.php @@ -1,4 +1,4 @@ -