From df523fb0c5115e9eb0f8eaa83fcb75f5ad25348c Mon Sep 17 00:00:00 2001 From: vargenau Date: Wed, 1 Apr 2015 08:04:48 +0000 Subject: [PATCH] Remove MockRequest git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@9634 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/MailNotify.php | 51 +++++----------- lib/WikiDB.php | 5 +- lib/loadsave.php | 108 ++++++++++++++++++--------------- lib/plugin/PasswordReset.php | 14 ++++- lib/plugin/UserPreferences.php | 2 - lib/plugin/WatchPage.php | 3 - 6 files changed, 87 insertions(+), 96 deletions(-) diff --git a/lib/MailNotify.php b/lib/MailNotify.php index 8e9cec4ad..eab381d3c 100644 --- a/lib/MailNotify.php +++ b/lib/MailNotify.php @@ -330,22 +330,15 @@ class MailNotify */ public function onChangePage(&$wikidb, &$wikitext, $version, &$meta) { - /** - * @var WikiRequest $request - */ - global $request; - - if (!is_a($request, 'MockRequest')) { - $notify = $wikidb->get('notify'); - /* Generate notification emails? */ - if (!empty($notify) and is_array($notify)) { - if (empty($this->pagename)) - $this->pagename = $meta['pagename']; - // TODO: Should be used for ModeratePage and RSS2 Cloud xml-rpc also. - $this->getPageChangeEmails($notify); - if (!empty($this->emails)) { - $this->sendPageChangeNotification($wikitext, $version, $meta); - } + $notify = $wikidb->get('notify'); + /* Generate notification emails? */ + if (!empty($notify) and is_array($notify)) { + if (empty($this->pagename)) + $this->pagename = $meta['pagename']; + // TODO: Should be used for ModeratePage and RSS2 Cloud xml-rpc also. + $this->getPageChangeEmails($notify); + if (!empty($this->emails)) { + $this->sendPageChangeNotification($wikitext, $version, $meta); } } } @@ -357,14 +350,9 @@ class MailNotify */ public function onDeletePage(&$wikidb, $pagename) { - /** - * @var WikiRequest $request - */ - global $request; - $result = true; /* Generate notification emails? */ - if (!$wikidb->isWikiPage($pagename) and !is_a($request, 'MockRequest')) { + if (!$wikidb->isWikiPage($pagename)) { $notify = $wikidb->get('notify'); if (!empty($notify) and is_array($notify)) { //TODO: deferr it (quite a massive load if you remove some pages). @@ -385,19 +373,12 @@ class MailNotify */ public function onRenamePage(&$wikidb, $oldpage, $new_pagename) { - /** - * @var WikiRequest $request - */ - global $request; - - if (!is_a($request, 'MockRequest')) { - $notify = $wikidb->get('notify'); - if (!empty($notify) and is_array($notify)) { - $this->getPageChangeEmails($notify); - if (!empty($this->emails)) { - $this->pagename = $oldpage; - $this->sendPageRenameNotification($new_pagename); - } + $notify = $wikidb->get('notify'); + if (!empty($notify) and is_array($notify)) { + $this->getPageChangeEmails($notify); + if (!empty($this->emails)) { + $this->pagename = $oldpage; + $this->sendPageRenameNotification($new_pagename); } } } diff --git a/lib/WikiDB.php b/lib/WikiDB.php index a1dd1e389..ca98c8d07 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -577,7 +577,7 @@ class WikiDB E_USER_WARNING); } /* Generate notification emails? */ - if ($result and ENABLE_MAILNOTIFY and !is_a($request, 'MockRequest')) { + if ($result and ENABLE_MAILNOTIFY) { $notify = $this->get('notify'); if (!empty($notify) and is_array($notify)) { include_once 'lib/MailNotify.php'; @@ -1083,7 +1083,6 @@ class WikiDB_Page $notify = $this->_wikidb->get('notify'); if (!empty($notify) and is_array($notify) - and !is_a($request, 'MockRequest') ) { include_once 'lib/MailNotify.php'; $MailNotify = new MailNotify($newrevision->getName()); @@ -1697,7 +1696,7 @@ class WikiDB_PageRevision $this->getMetaData()); if ($possibly_cache_results and !WIKIDB_NOCACHE_MARKUP) { - // If we're still the current version, cache the transfomed page. + // If we're still the current version, cache the transformed page. //$backend->lock(); if ($this->isCurrent()) { $page->set('_cached_html', $this->_transformedContent->pack()); diff --git a/lib/loadsave.php b/lib/loadsave.php index 03fc4d14c..5f24a7195 100644 --- a/lib/loadsave.php +++ b/lib/loadsave.php @@ -37,12 +37,14 @@ function _dump_error_handler($error) return true; // Ignore error } -function StartLoadDump(&$request, $title, $html = '') +/** + * @param WikiRequest $request + * @param string $title + * @param HTML $html + */ + +function StartLoadDump(&$request, $title, $html = null) { - // MockRequest is from the unit testsuite, a faked request. (may be cmd-line) - // We are silent on unittests. - if (is_a($request, 'MockRequest')) - return; // FIXME: This is a hack. This really is the worst overall hack in phpwiki. if ($html) $html->pushContent('%BODY%'); @@ -56,12 +58,13 @@ function StartLoadDump(&$request, $title, $html = '') $request->_deferredPageChangeNotification = array(); } +/** + * @param WikiRequest $request + */ function EndLoadDump(&$request) { global $WikiTheme; - if (is_a($request, 'MockRequest')) - return; $action = $request->getArg('action'); if ($action == 'browse') // loading virgin $pagelink = WikiLink(HOME_PAGE); @@ -140,6 +143,10 @@ function EndLoadDump(&$request) * (RFC 1521 has been superceeded by RFC 2045 & others). * * Also see http://www.faqs.org/rfcs/rfc2822.html +/* + * @param WikiDB_Page $page + * @param int $nversions + * @return string */ function MailifyPage($page, $nversions = 1) { @@ -215,6 +222,8 @@ function FilenameForPage($pagename, $action = '') * If $include_archive is false, only the current version of each page * is included in the zip file; otherwise all archived versions are * included as well. + * + * @param WikiRequest $request */ function MakeWikiZip(&$request) { @@ -304,6 +313,9 @@ function MakeWikiZip(&$request) exit; } +/** + * @param WikiRequest $request + */ function DumpToDir(&$request) { $directory = $request->getArg('directory'); @@ -352,16 +364,12 @@ function DumpToDir(&$request) longer_timeout($timeout); // Reset watchdog $pagename = $page->getName(); - if (!is_a($request, 'MockRequest')) { - PrintXML(HTML::br(), $pagename, ' ... '); - flush(); - } + PrintXML(HTML::br(), $pagename, ' ... '); + flush(); if (in_array($pagename, $excludeList)) { - if (!is_a($request, 'MockRequest')) { - PrintXML(_("Skipped.")); - flush(); - } + PrintXML(_("Skipped.")); + flush(); continue; } $filename = FilenameForPage($pagename); @@ -384,10 +392,8 @@ function DumpToDir(&$request) $num = fwrite($fd, $data, strlen($data)); $msg->pushContent(HTML::small(fmt("%s bytes written", $num))); - if (!is_a($request, 'MockRequest')) { - PrintXML($msg); - flush(); - } + PrintXML($msg); + flush(); assert($num == strlen($data)); fclose($fd); } @@ -397,12 +403,10 @@ function DumpToDir(&$request) function _copyMsg($page, $smallmsg) { - if (!is_a($GLOBALS['request'], 'MockRequest')) { - if ($page) $msg = HTML(HTML::br(), HTML($page), HTML::small($smallmsg)); - else $msg = HTML::small($smallmsg); - PrintXML($msg); - flush(); - } + if ($page) $msg = HTML(HTML::br(), HTML($page), HTML::small($smallmsg)); + else $msg = HTML::small($smallmsg); + PrintXML($msg); + flush(); } function mkdir_p($pathname, $permission = 0777) @@ -485,7 +489,8 @@ function DumpHtmlToDir(&$request) EndLoadDump($request); } -/* Known problem: any plugins or other code which echo()s text will +/** + * Known problem: any plugins or other code which echo()s text will * lead to a corrupted html zip file which may produce the following * errors upon unzipping: * @@ -494,7 +499,10 @@ function DumpHtmlToDir(&$request) * (attempting to re-compensate) * * However, the actual wiki page data should be unaffected. + * + * @param WikiRequest $request */ + function MakeWikiZipHtml(&$request) { global $WikiTheme; @@ -634,13 +642,11 @@ function _DumpHtmlToDir($target, $page_iter, $exclude = false, $zipname='', $tmp if ($page->get('locked')) $attrib['write_protected'] = 1; } elseif (!$silent) { - if (!is_a($request, 'MockRequest')) { - PrintXML(HTML::br(), $pagename, ' ... '); - flush(); - } + PrintXML(HTML::br(), $pagename, ' ... '); + flush(); } if (in_array($pagename, $excludeList)) { - if (!$silent and !is_a($request, 'MockRequest')) { + if (!$silent) { PrintXML(_("Skipped.")); flush(); } @@ -723,9 +729,7 @@ function _DumpHtmlToDir($target, $page_iter, $exclude = false, $zipname='', $tmp } $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n")); if (!$silent) { - if (!is_a($request, 'MockRequest')) { - PrintXML($msg); - } + PrintXML($msg); flush(); $request->chunkOutput(); } @@ -1019,10 +1023,8 @@ function SavePage(&$request, &$pageinfo, $source) if (!$skip) { // in case of failures print the culprit: - if (!is_a($request, 'MockRequest')) { - PrintXML(HTML::span(WikiLink($pagename))); - flush(); - } + PrintXML(HTML::span(WikiLink($pagename))); + flush(); $new = $page->save($content, WIKIDB_FORCE_CREATE, $versiondata); $dbi->touch(); $mesg->pushContent(' ', fmt("- saved to database as version %d", @@ -1065,13 +1067,11 @@ function SavePage(&$request, &$pageinfo, $source) } } - if (!is_a($request, 'MockRequest')) { - if ($skip) - PrintXML(HTML::em(WikiLink($pagename)), $mesg); - else - PrintXML($mesg); - flush(); - } + if ($skip) + PrintXML(HTML::em(WikiLink($pagename)), $mesg); + else + PrintXML($mesg); + flush(); } // action=revert (by diff) @@ -1169,9 +1169,7 @@ function _tryinsertInterWikiMap($content) if ($goback) return $content; - // if loading from virgin setup do echo, otherwise trigger_error E_USER_NOTICE - if (!is_a($GLOBALS['request'], 'MockRequest')) - echo sprintf(_("Loading InterWikiMap from external file %s."), $mapfile), "
"; + echo sprintf(_("Loading InterWikiMap from external file %s."), $mapfile), "
"; $fd = fopen($mapfile, "rb"); $data = fread($fd, filesize($mapfile)); @@ -1420,6 +1418,12 @@ function IsZipFile($filename_or_fd) return $magic == ZIP_LOCHEAD_MAGIC || $magic == ZIP_CENTHEAD_MAGIC; } +/** + * @param WikiRequest $request + * @param string $file_or_dir + * @param array $files + * @param array $exclude + */ function LoadAny(&$request, $file_or_dir, $files = array(), $exclude = array()) { // Try urlencoded filename for accented characters. @@ -1464,13 +1468,15 @@ function LoadAny(&$request, $file_or_dir, $files = array(), $exclude = array()) } } +/** + * @param WikiRequest $request + */ function LoadFileOrDir(&$request) { $source = $request->getArg('source'); $finder = new FileFinder; $source = $finder->slashifyPath($source); - StartLoadDump($request, - sprintf(_("Loading “%s”"), $source)); + StartLoadDump($request, sprintf(_("Loading “%s”"), $source)); LoadAny($request, $source); EndLoadDump($request); } @@ -1479,6 +1485,8 @@ function LoadFileOrDir(&$request) * HomePage was not found so first-time install is supposed to run. * - import all pgsrc pages. * - Todo: installer interface to edit config/config.ini settings + * + * @param WikiRequest $request */ function SetupWiki(&$request) { diff --git a/lib/plugin/PasswordReset.php b/lib/plugin/PasswordReset.php index b42503e8a..4a01a5a64 100644 --- a/lib/plugin/PasswordReset.php +++ b/lib/plugin/PasswordReset.php @@ -65,6 +65,10 @@ class WikiPlugin_PasswordReset $alert->show(); } + /** + * @param WikiRequest $request + * @param string $userid + */ private function doEmail(&$request, $userid) { @@ -87,6 +91,13 @@ class WikiPlugin_PasswordReset $alert->show(); } + /** + * @param WikiRequest $request + * @param string $userid + * @param string $header + * @param string $footer + * @return HtmlElement + */ private function doForm(&$request, $userid = '', $header = '', $footer = '') { if (!$header) { @@ -123,9 +134,6 @@ class WikiPlugin_PasswordReset function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); - if (is_a($request, 'MockRequest')) - return ''; - $user =& $request->_user; $post_args = $request->getArg('admin_reset'); $userid = $args['user']; diff --git a/lib/plugin/UserPreferences.php b/lib/plugin/UserPreferences.php index f4b5690bc..efb0472de 100644 --- a/lib/plugin/UserPreferences.php +++ b/lib/plugin/UserPreferences.php @@ -73,8 +73,6 @@ class WikiPlugin_UserPreferences $args = $this->getArgs($argstr, $request); $user =& $request->_user; $user->_request = $request; - if (is_a($request, 'MockRequest')) - return ''; if (defined('FUSIONFORGE') && FUSIONFORGE) { if (!($user->isAuthenticated())) { return HTML::p(array('class' => 'error'), diff --git a/lib/plugin/WatchPage.php b/lib/plugin/WatchPage.php index 178b10afa..f7197297b 100644 --- a/lib/plugin/WatchPage.php +++ b/lib/plugin/WatchPage.php @@ -104,10 +104,7 @@ class WikiPlugin_WatchPage */ function run($dbi, $argstr, &$request, $basepage) { - $args = $this->getArgs($argstr, $request); - if (is_a($request, 'MockRequest')) - return ''; $user =& $request->_user; $userid = $user->UserName(); $page = $args['page']; -- 2.45.2