function _print($val) { if (isa($val, 'Template')) { $this->_expandSubtemplate($val); } else { PrintXML($val); } }
function finish($errormsg = false) { static $in_exit = 0; if ($in_exit) { exit; } // just in case CloseDataBase calls us $in_exit = true; global $ErrorManager; $ErrorManager->flushPostponedErrors(); if (!empty($errormsg)) { PrintXML(HTML::br(), HTML::hr(), HTML::h2(_("Fatal PhpWiki Error")), $errormsg); // HACK: echo "\n</body></html>"; } if (is_object($this->_user)) { $this->_user->page = $this->getArg('pagename'); $this->_user->action = $this->getArg('action'); unset($this->_user->_HomePagehandle); unset($this->_user->_auth_dbi); } Request::finish(); exit; }
function addWords($words, $tag = '') { if ($tag != $this->_tag) { $this->_flushGroup($tag); } foreach ($words as $word) { // new-line should only come as first char of word. if (!$word) { continue; } if ($word[0] == "\n") { $this->_group .= PrintXML(HTML::raw(' ')); $this->_flushLine($tag); $word = substr($word, 1); } assert(!strstr($word, "\n")); $this->_group .= $word; } }
function LoadDir(&$request, $dirname, $files = false, $exclude = false) { $fileset = new LimitedFileSet($dirname, $files, $exclude); if (!$files and $skiplist = $fileset->getSkippedFiles()) { PrintXML(HTML::dt(HTML::strong(_("Skipping")))); $list = HTML::ul(); foreach ($skiplist as $file) { $list->pushContent(HTML::li(WikiLink($file))); } PrintXML(HTML::dd($list)); } // Defer HomePage loading until the end. If anything goes wrong // the pages can still be loaded again. $files = $fileset->getFiles(); if (in_array(HOME_PAGE, $files)) { $files = array_diff($files, array(HOME_PAGE)); $files[] = HOME_PAGE; } $timeout = !$request->getArg('start_debug') ? 20 : 120; foreach ($files as $file) { longer_timeout($timeout); // longer timeout per page if (substr($file, -1, 1) != '~') { // refuse to load backup files LoadFile($request, "{$dirname}/{$file}"); } } }
function _match($text, $regexps, $repeat) { // If one of the regexps is an empty string, php will crash here: // sf.net: Fatal error: Allowed memory size of 8388608 bytes exhausted // (tried to allocate 634 bytes) if (_INLINE_OPTIMIZATION) { // disabled, wrong // So we try to minize memory usage, by looping explicitly, // and storing only those regexp which actually match. // There may be more than one, so we have to find the longest, // and match inside until the shortest is empty. $matched = array(); $matched_ind = array(); for ($i = 0; $i < count($regexps); $i++) { if (!trim($regexps[$i])) { trigger_error("empty regexp {$i}", E_USER_WARNING); continue; } $pat = "/ ( . {$repeat} ) ( " . $regexps[$i] . " ) /x"; if (preg_match($pat, $text, $_m)) { $m = $_m; // FIXME: prematch, postmatch is wrong $matched[] = $regexps[$i]; $matched_ind[] = $i; $regexp_ind = $i; } } // To overcome ANCHORED: // We could sort by longest match and iterate over these. if (empty($matched)) { return false; } } $match = new RegexpSet_match(); // Optimization: if the matches are only "$" and another, then omit "$" if (!_INLINE_OPTIMIZATION or count($matched) > 2) { assert(!empty($repeat)); assert(!empty($regexps)); // We could do much better, if we would know the matching markup for the // longest regexp match: $hugepat = "/ ( . {$repeat} ) ( (" . join(')|(', $regexps) . ") ) /Asx"; // Proposed premature optimization 1: //$hugepat= "/ ( . $repeat ) ( (" . join(')|(', array_values($matched)) . ") ) /Asx"; if (!preg_match($hugepat, $text, $m)) { return false; } // Proposed premature optimization 1: //$match->regexp_ind = $matched_ind[count($m) - 4]; $match->regexp_ind = count($m) - 4; } else { $match->regexp_ind = $regexp_ind; } $match->postmatch = substr($text, strlen($m[0])); $match->prematch = $m[1]; $match->match = $m[2]; /* DEBUGGING */ if (DEBUG & _DEBUG_PARSER) { static $_already_dumped = 0; if (!$_already_dumped) { var_dump($regexps); if (_INLINE_OPTIMIZATION) { var_dump($matched); } var_dump($matched_ind); } $_already_dumped = 1; PrintXML(HTML::dl(HTML::dt("input"), HTML::dd(HTML::pre($text)), HTML::dt("regexp"), HTML::dd(HTML::pre($match->regexp_ind, ":", $regexps[$match->regexp_ind])), HTML::dt("prematch"), HTML::dd(HTML::pre($match->prematch)), HTML::dt("match"), HTML::dd(HTML::pre($match->match)), HTML::dt("postmatch"), HTML::dd(HTML::pre($match->postmatch)))); } return $match; }
function _do_syncwiki(&$request, $args) { global $charset; longer_timeout(240); if (!function_exists('wiki_xmlrpc_post')) { include_once "lib/XmlRpcClient.php"; } $userid = $request->_user->_userid; $dbh = $request->getDbh(); $merge_point = $dbh->get('mergepoint'); if (empty($merge_point)) { $page = $dbh->getPage("ReleaseNotes"); // this is usually the latest official page $last = $page->getCurrentRevision(false); $merge_point = $last->get("mtime"); // for testing: 1160396075 $dbh->set('mergepoint', $merge_point); } //TODO: remote auth, set session cookie $pagelist = wiki_xmlrpc_post('wiki.getRecentChanges', iso8601_encode($merge_point, 1), $args['url'], $args); $html = HTML(); //$html->pushContent(HTML::div(HTML::em("check RPC2 interface..."))); if (gettype($pagelist) === "array") { //$request->_deferredPageChangeNotification = array(); $request->discardOutput(); StartLoadDump($request, _("Syncing this PhpWiki")); PrintXML(HTML::strong(fmt("Download all externally changed sources."))); echo "<br />\n"; PrintXML(fmt("Retrieving from external url %s wiki.getRecentChanges(%s)...", $args['url'], iso8601_encode($merge_point, 1))); echo "<br />\n"; $ouriter = $dbh->mostRecent(array('since' => $merge_point)); //$ol = HTML::ol(); $done = array(); foreach ($pagelist as $ext) { $reaction = _("<unknown>"); // compare existance and dates with local page $extdate = iso8601_decode($ext['lastModified']->scalar, 1); // TODO: urldecode ??? $name = utf8_decode($ext['name']); $our = $dbh->getPage($name); $done[$name] = 1; $ourrev = $our->getCurrentRevision(false); $rel = '<=>'; if (!$our->exists()) { // we might have deleted or moved it on purpose? // check date of latest revision if there's one, and > mergepoint if ($ourrev->getVersion() > 1 and $ourrev->get('mtime') > $merge_point) { // our was deleted after sync, and changed after last sync. $this->_addConflict('delete', $args, $our, $extdate); $reaction = _(" skipped") . " (" . "locally deleted or moved" . ")"; } else { $reaction = $this->_import($args, $our, $extdate); } } else { $ourdate = $ourrev->get('mtime'); if ($extdate > $ourdate and $ourdate < $merge_point) { $rel = '>'; $reaction = $this->_import($args, $our, $extdate); } elseif ($extdate > $ourdate and $ourdate >= $merge_point) { $rel = '>'; // our is older then external but newer than last sync $reaction = $this->_addConflict('import', $args, $our, $extdate); } elseif ($extdate < $ourdate and $extdate < $merge_point) { $rel = '>'; $reaction = $this->_export($args, $our); } elseif ($extdate < $ourdate and $extdate >= $merge_point) { $rel = '>'; // our is newer and external is also newer $reaction = $this->_addConflict('export', $args, $our, $extdate); } else { $rel = '=='; $reaction = _("same date"); } } /*$ol->pushContent(HTML::li(HTML::strong($name)," ", $extdate,"<=>",$ourdate," ", HTML::strong($reaction))); */ PrintXML(HTML::strong($name), " ", $extdate, " {$rel} ", $ourdate, " ", HTML::strong($reaction), HTML::br()); $request->chunkOutput(); } //$html->pushContent($ol); } else { $html->pushContent("xmlrpc error: wiki.getRecentChanges returned " . "(" . gettype($pagelist) . ") " . $pagelist); trigger_error("xmlrpc error: wiki.getRecentChanges returned " . "(" . gettype($pagelist) . ") " . $pagelist, E_USER_WARNING); EndLoadDump($request); return $this->error($html); } if (empty($args['noexport'])) { PrintXML(HTML::strong(fmt("Now upload all locally newer pages."))); echo "<br />\n"; PrintXML(fmt("Checking all local pages newer than %s...", iso8601_encode($merge_point, 1))); echo "<br />\n"; while ($our = $ouriter->next()) { $name = $our->getName(); if ($done[$name]) { continue; } $reaction = _(" skipped"); $ext = wiki_xmlrpc_post('wiki.getPageInfo', $name, $args['url']); if (is_array($ext)) { $extdate = iso8601_decode($ext['lastModified']->scalar, 1); $ourdate = $our->get('mtime'); if ($extdate < $ourdate and $extdate < $merge_point) { $reaction = $this->_export($args, $our); } elseif ($extdate < $ourdate and $extdate >= $merge_point) { // our newer and external newer $reaction = $this->_addConflict($args, $our, $extdate); } } else { $reaction = 'xmlrpc error'; } PrintXML(HTML::strong($name), " ", $extdate, " < ", $ourdate, " ", HTML::strong($reaction), HTML::br()); $request->chunkOutput(); } PrintXML(HTML::strong(fmt("Now upload all locally newer uploads."))); echo "<br />\n"; PrintXML(fmt("Checking all local uploads newer than %s...", iso8601_encode($merge_point, 1))); echo "<br />\n"; $this->_fileList = array(); $prefix = getUploadFilePath(); $this->_dir($prefix); $len = strlen($prefix); foreach ($this->_fileList as $path) { // strip prefix $file = substr($path, $len); $ourdate = filemtime($path); $oursize = filesize($path); $reaction = _(" skipped"); $ext = wiki_xmlrpc_post('wiki.getUploadedFileInfo', $file, $args['url']); if (is_array($ext)) { $extdate = iso8601_decode($ext['lastModified']->scalar, 1); $extsize = $ext['size']; if (empty($extsize) or $extdate < $ourdate) { $timeout = $oursize * 0.0002; // assume 50kb/sec upload speed $reaction = $this->_upload($args, $path, $timeout); } } else { $reaction = 'xmlrpc error wiki.getUploadedFileInfo not supported'; } PrintXML(HTML::strong($name), " ", "{$extdate} ({$extsize}) < {$ourdate} ({$oursize})", HTML::strong($reaction), HTML::br()); $request->chunkOutput(); } } $dbh->set('mergepoint', time()); EndLoadDump($request); return ''; //$html; }
function output($template, $title_fs) { $selected =& $this->selected; $current =& $this->current; if ($selected && $selected->getVersion() != $current->getVersion()) { $rev = $selected; $pagelink = WikiLink($selected); } else { $rev = $current; $pagelink = WikiLink($this->page); } //$title = new FormattedText ($title_fs, $pagelink); $template = Template($template, $this->tokens); //GeneratePage($template, $title, $rev); PrintXML($template); return true; }
/** * Print an HTMLified version of this error. * @see asXML() */ function printXML() { PrintXML($this->_getDetail()); }
/** * 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 * - Todo: ask for existing old index.php to convert to config/config.ini * - Todo: theme-specific pages: * blog - HomePage, ADMIN_USER/Blogs */ function SetupWiki(&$request) { global $GenericPages, $LANG; //FIXME: This is a hack (err, "interim solution") // This is a bogo-bogo-login: Login without // saving login information in session state. // This avoids logging in the unsuspecting // visitor as ADMIN_USER // // This really needs to be cleaned up... // (I'm working on it.) $real_user = $request->_user; if (ENABLE_USER_NEW) { $request->_user = new _BogoUser(ADMIN_USER); } else { $request->_user = new WikiUser($request, ADMIN_USER, WIKIAUTH_BOGO); } StartLoadDump($request, _("Loading up virgin wiki")); $pgsrc = FindLocalizedFile(WIKI_PGSRC); $default_pgsrc = FindFile(DEFAULT_WIKI_PGSRC); $request->setArg('overwrite', true); if ($default_pgsrc != $pgsrc) { LoadAny($request, $default_pgsrc, $GenericPages); } $request->setArg('overwrite', false); LoadAny($request, $pgsrc); $dbi =& $request->_dbi; // Ensure that all mandatory pages are loaded $finder = new FileFinder(); if (!FUSIONFORGE) { $mandatory = explode(':', 'SandBox:Template/Category:Template/Talk:SpecialPages:CategoryCategory:CategoryActionPage:Help/OldTextFormattingRules:Help/TextFormattingRules:PhpWikiAdministration'); } else { if (WIKI_NAME == "help") { $mandatory = explode(':', 'SandBox:Template/Category:Template/Talk:SpecialPages:CategoryCategory:CategoryActionPage:Help/TextFormattingRules:PhpWikiAdministration'); } else { $mandatory = explode(':', 'SandBox:Template/UserPage:Template/Category:Template/Talk:SpecialPages:CategoryCategory:CategoryActionPage:TextFormattingRules:PhpWikiAdministration'); } } foreach (array_merge($mandatory, $GLOBALS['AllActionPages'], array(constant('HOME_PAGE'))) as $f) { $page = gettext($f); $epage = urlencode($page); if (!$dbi->isWikiPage($page)) { // translated version provided? if ($lf = FindLocalizedFile($pgsrc . $finder->_pathsep . $epage, 1)) { LoadAny($request, $lf); } else { // load english version of required action page LoadAny($request, FindFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f))); $page = $f; } } if (!$dbi->isWikiPage($page)) { trigger_error(sprintf("Mandatory file %s couldn't be loaded!", $page), E_USER_WARNING); } } $pagename = _("InterWikiMap"); $map = $dbi->getPage($pagename); $map->set('locked', true); PrintXML(HTML::p(HTML::em(WikiLink($pagename)), HTML::strong(" locked"))); EndLoadDump($request); }
function PrintXML($val) { if (func_num_args() > 1) { foreach (func_get_args() as $arg) { PrintXML($arg); } } elseif (is_object($val)) { if (method_exists($val, 'printXML')) { $val->printXML(); } elseif (method_exists($val, 'asXML')) { echo $val->asXML(); } elseif (method_exists($val, 'asString')) { echo XmlContent_quote($val->asString()); } else { printf("==Object(%s)==", get_class($val)); } } elseif (is_array($val)) { // DEPRECATED: // Use XmlContent objects instead of arrays for collections of XmlElements. trigger_error("Passing arrays to PrintXML() is deprecated: (" . AsXML($val, true) . ")", E_USER_NOTICE); foreach ($val as $x) { PrintXML($x); } } else { echo (string) XmlContent_quote((string) $val); } }
function printXML() { PrintXML($this->getContent()); }
function ExitWiki($errormsg = false) { global $request; static $in_exit = 0; if (is_object($request) and method_exists($request, "finish")) { $request->finish($errormsg); } // NORETURN if ($in_exit) { exit; } $in_exit = true; global $ErrorManager; $ErrorManager->flushPostponedErrors(); if (!empty($errormsg)) { PrintXML(HTML::br(), $errormsg); print "\n</body></html>"; } exit; }
function output($template, $title_fs) { $selected =& $this->selected; $current =& $this->current; if ($selected && $selected->getVersion() != $current->getVersion()) { $rev = $selected; $pagelink = WikiLink($selected); } else { $rev = $current; $pagelink = WikiLink($this->page); } $title = new FormattedText($title_fs, $pagelink); $this->tokens['HEADER'] = $title; //hack! there's no TITLE in editpage, but in the previous top template if (empty($this->tokens['PAGE_LOCKED_MESSAGE'])) { $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML::h3($title); } else { $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML(HTML::h3($title), $this->tokens['PAGE_LOCKED_MESSAGE']); } $template = Template($template, $this->tokens); //GeneratePage($template, $title, $rev); PrintXML($template); return true; }