function getArgs($argstr, $request, $defaults = false) { if (!$defaults) { $defaults = $this->getDefaultArguments(); } $args = WikiPlugin::getArgs($argstr, $request, $defaults); $action = $request->getArg('action'); if ($action != 'browse' && !isActionPage($action)) { $args['format'] = false; } // default -> HTML if ($args['format'] == 'rss' && empty($args['limit'])) { $args['limit'] = 15; } // Fix default value for RSS. if ($args['format'] == 'rss2' && empty($args['limit'])) { $args['limit'] = 15; } // Fix default value for RSS2. if ($args['format'] == 'sidebar' && empty($args['limit'])) { $args['limit'] = 10; } // Fix default value for sidebar. return $args; }
function CheckPgsrcUpdate(&$request, $checkonly = false) { echo "<h3>", _("check for necessary pgsrc updates"), "</h3>\n"; $dbi = $request->getDbh(); $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); // fixme: verification, ... $isHomePage = false; foreach ($pgsrc->getFiles() as $filename) { if (substr($filename, -1, 1) == '~') { continue; } $pagename = urldecode($filename); // don't ever update the HomePage if (defined(HOME_PAGE)) { if ($pagename == HOME_PAGE) { $isHomePage = true; } else { if ($pagename == _("HomePage")) { $isHomePage = true; } } } if ($pagename == "HomePage") { $isHomePage = true; } if ($isHomePage) { echo "{$path}/{$pagename}: ", _("always skip the HomePage."), _(" skipped"), ".<br />\n"; $isHomePage = false; continue; } if (!isActionPage($filename)) { doPgsrcUpdate($request, $pagename, $path, $filename, $checkonly); } } return; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); $user =& $request->_user; $user->_request = $request; if (isa($request, 'MockRequest')) { return ''; } if (defined('FUSIONFORGE') and FUSIONFORGE) { if (!$user->isAuthenticated()) { return HTML::div(array('class' => 'errors'), _("Error: You are not logged in, cannot display UserPreferences.")); } } if (!isActionPage($request->getArg('pagename')) and (!isset($user->_prefs->_method) or !in_array($user->_prefs->_method, array('ADODB', 'SQL', 'PDO'))) or in_array($request->getArg('action'), array('zip', 'ziphtml', 'dumphtml')) or isa($user, '_ForbiddenUser')) { $no_args = $this->getDefaultArguments(); $no_args['errmsg'] = HTML::div(array('class' => 'errors'), _("Error: The user HomePage must be a valid WikiWord. Sorry, UserPreferences cannot be saved.")); $no_args['isForm'] = false; return Template('userprefs', $no_args); } $userid = $user->UserName(); if ($user->isAuthenticated() and !empty($userid)) { $pref =& $request->_prefs; $args['isForm'] = true; if ($request->isPost()) { $errmsg = ''; $delete = $request->getArg('delete'); if ($delete and $request->getArg('verify')) { // deleting prefs, verified $default_prefs = $pref->defaultPreferences(); $default_prefs['userid'] = $user->UserName(); $user->setPreferences($default_prefs); $request->_setUser($user); $request->setArg("verify", false); $request->setArg("delete", false); $errmsg .= _("Your UserPreferences have been successfully reset to default."); $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg)); return Template('userprefs', $args); } elseif ($delete and !$request->getArg('verify')) { return HTML::fieldset(HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), HiddenInputs(array('verify' => 1)), HiddenInputs($request->getArgs()), HTML::p(_("Do you really want to reset all your UserPreferences?")), HTML::p(Button('submit:delete', _("Yes"), 'delete'), HTML::Raw(' '), Button('cancel', _("Cancel"))))); } elseif ($rp = $request->getArg('pref')) { // replace only changed prefs in $pref with those from request if (!empty($rp['passwd']) and $rp['passwd2'] != $rp['passwd']) { $errmsg = _("Wrong password. Try again."); } else { if (empty($rp['passwd'])) { unset($rp['passwd']); } // fix to set system pulldown's. empty values don't get posted if (empty($rp['theme'])) { $rp['theme'] = ''; } if (empty($rp['lang'])) { $rp['lang'] = ''; } $num = $user->setPreferences($rp); if (!empty($rp['passwd'])) { $passchanged = false; if ($user->mayChangePass()) { if (method_exists($user, 'storePass')) { $passchanged = $user->storePass($rp['passwd']); } if (!$passchanged and method_exists($user, 'changePass')) { $passchanged = $user->changePass($rp['passwd']); } if ($passchanged) { $errmsg = _("Password updated."); } else { $errmsg = _("Password was not changed."); } } else { $errmsg = _("Password cannot be changed."); } } if (!$num) { $errmsg .= " " . _("No changes."); } else { $request->_setUser($user); $pref = $user->_prefs; if ($num == 1) { $errmsg .= _("One UserPreferences field successfully updated."); } else { $errmsg .= sprintf(_("%d UserPreferences fields successfully updated."), $num); } } } $args['errmsg'] = HTML::div(array('class' => 'feedback'), HTML::p($errmsg)); } } $args['available_themes'] = listAvailableThemes(); $args['available_languages'] = listAvailableLanguages(); return Template('userprefs', $args); } else { // wrong or unauthenticated user return $request->_notAuthorized(WIKIAUTH_BOGO); } }
function findActionPage($action) { static $cache; if (!$action) { return false; } // check for translated version, as per users preferred language // (or system default in case it is not en) $translation = gettext($action); if (isset($cache) and isset($cache[$translation])) { return $cache[$translation]; } // check for cached translated version if ($translation and isActionPage($translation)) { return $cache[$action] = $translation; } // Allow for, e.g. action=LikePages if (!isWikiWord($action)) { return $cache[$action] = false; } // check for translated version (default language) global $LANG; if ($LANG != "en") { require_once "lib/WikiPlugin.php"; require_once "lib/plugin/_WikiTranslation.php"; $trans = new WikiPlugin__WikiTranslation(); $trans->lang = $LANG; $default = $trans->translate_to_en($action, $LANG); if ($default and isActionPage($default)) { return $cache[$action] = $default; } } else { $default = $translation; } // check for english version if ($action != $translation and $action != $default) { if (isActionPage($action)) { return $cache[$action] = $action; } } trigger_error("{$action}: Cannot find action page", E_USER_NOTICE); return $cache[$action] = false; }
function displayPage(&$request, $template = false) { global $WikiTheme; global $robots; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } /* Tell Google (and others) to ignore old versions of pages */ $robots = "noindex,nofollow"; $toks['ROBOTS_META'] = $robots; } else { $revision = $page->getCurrentRevision(); } $format = $request->getArg('format'); if ($format == 'xml') { // fast ajax: include page content asynchronously global $charset; header("Content-Type: text/xml"); echo "<", "?xml version=\"1.0\" encoding=\"{$charset}\"?", ">\n"; // DOCTYPE html needed to allow unencoded entities like without !CDATA[] echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n"; if ($page->exists()) { header("Last-Modified: " . Rfc1123DateTime($revision->get('mtime'))); $request->cacheControl(); $request->setArg('format', ''); $page_content = $revision->getTransformedContent(); $page_content->printXML(); $request->_is_buffering_output = false; // avoid wrong Content-Length with errors $request->finish(); } else { $request->cacheControl(); echo '<div style="display:none;" />'; $request->_is_buffering_output = false; // avoid wrong Content-Length with errors $request->finish(); exit; } } if (isSubPage($pagename)) { $pages = explode(SUBPAGE_SEPARATOR, $pagename); $last_page = array_pop($pages); // deletes last element from array as side-effect $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR))); $first_pages = $pages[0] . SUBPAGE_SEPARATOR; array_shift($pages); foreach ($pages as $p) { $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); $first_pages .= $p . SUBPAGE_SEPARATOR; } $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); $pageheader->pushContent($backlink); } else { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); if ($request->getArg('frame')) { $pageheader->setAttr('target', '_top'); } } $pagetitle = SplitPagename($pagename); if ($redirect_from = $request->getArg('redirectfrom')) { $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from))); // abuse the $redirected template var for some status update notice } elseif ($request->getArg('errormsg')) { $redirect_message = $request->getArg('errormsg'); $request->setArg('errormsg', false); } $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); /* // FIXME: This is also in the template... if ($request->getArg('action') != 'pdf' and !headers_sent()) { // FIXME: enable MathML/SVG/... support if (ENABLE_XHTML_XML and (!isBrowserIE() and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml'))) header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); else header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } */ $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; // On external searchengine (google) referrer, highlight the searchterm and // pass through the Searchhighlight actionpage. if ($result = isExternalReferrer($request)) { if (!empty($result['query'])) { if (ENABLE_SEARCHHIGHLIGHT) { $request->_searchhighlight = $result; $request->appendValidators(array('%mtime' => time())); // force no cache(?) // Should be changed to check the engine and search term only // $request->setArg('nocache', 1); $page_content = new TransformedText($revision->getPage(), $revision->getPackedContent(), $revision->getMetaData()); /* Now add the SearchHighlight plugin to the top of the page, in memory only. You can parametrize this by changing the SearchHighlight action page. */ if ($actionpage = $request->findActionPage('SearchHighlight')) { $actionpage = $request->getPage($actionpage); $actionrev = $actionpage->getCurrentRevision(); $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(), $WikiTheme->linkExistingWikiWord($pagename, false, $version))); $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(), '%mtime' => $actionrev->get('mtime'))); $toks['SEARCH_ENGINE'] = $result['engine']; $toks['SEARCH_ENGINE_URL'] = $result['engine_url']; $toks['SEARCH_TERM'] = $result['query']; //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink $actioncontent = new TransformedText($actionrev->getPage(), $actionrev->getPackedContent(), $actionrev->getMetaData()); // prepend the actionpage in front of the hightlighted content $toks['CONTENT'] = HTML($actioncontent, $page_content); } } } else { $page_content = $revision->getTransformedContent(); } } else { $page_content = $revision->getTransformedContent(); } /* Check for special pagenames, which are no actionpages. */ /* if ( $pagename == _("RecentVisitors")) { $robots = "noindex,follow"; $toks['ROBOTS_META'] = $robots; } else */ if ($pagename == _("SandBox")) { $robots = "noindex,nofollow"; $toks['ROBOTS_META'] = $robots; } else { if (isActionPage($pagename)) { // AllPages must not be indexed, but must be followed to get all pages $robots = "noindex,follow"; $toks['ROBOTS_META'] = $robots; } else { if (!isset($toks['ROBOTS_META'])) { $robots = "index,follow"; $toks['ROBOTS_META'] = $robots; } } } if (!isset($toks['CONTENT'])) { $toks['CONTENT'] = new Template('browse', $request, $page_content); } if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } // Massive performance problem parsing at run-time into all xml objects // looking for p's. Should be optional, if not removed at all. //$toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } // Handle other formats: So far we had html only. // xml is requested by loaddump, rss is handled by RecentChanges, // pdf is a special action, but should be a format to dump multiple pages // if the actionpage plugin returns a pagelist. // rdf, owl, kbmodel, daml, ... are handled by SemanticWeb. /* Only single page versions. rss only if not already handled by RecentChanges. */ if (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') { $template->printExpansion($toks); } else { // No pagelist here. Single page version only require_once "lib/PageList.php"; $pagelist = new PageList(); $pagelist->addPage($page); if ($format == 'pdf') { require_once "lib/pdf.php"; $request->setArg('format', ''); ConvertAndDisplayPdfPageList($request, $pagelist); // time-sorted rdf a la RecentChanges } elseif (in_array($format, array("rss91", "rss2", "rss", "atom"))) { //$request->setArg('format',''); if ($pagename == _("RecentChanges")) { $template->printExpansion($toks); } else { require_once "lib/plugin/RecentChanges.php"; $plugin = new WikiPlugin_RecentChanges(); $args = $request->getArgs(); return $plugin->format($plugin->getChanges($request->_dbi, $args), $args); } } elseif ($format == 'rdf') { // all semantic relations and attributes require_once "lib/SemanticWeb.php"; $rdf = new RdfWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'owl') { // or daml? require_once "lib/SemanticWeb.php"; $rdf = new OwlWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'json') { // include page content asynchronously $request->setArg('format', ''); if ($page->exists()) { $content = $page_content->asXML(); } else { $content = ''; } $req_args = $request->args; unset($req_args['format']); // no meta-data so far, just the content $json = array('content' => $content, 'args' => $req_args, 'phpwiki-version' => PHPWIKI_VERSION); if (loadPhpExtension('json')) { $json_enc = json_encode($json); } else { require_once "lib/pear/JSON.php"; $j = new Services_JSON(); $json_enc = $j->encode($json); } header("Content-Type: application/json"); die($json_enc); } else { if (!in_array($pagename, array(_("LinkDatabase")))) { trigger_error(sprintf(_("Unsupported argument: %s=%s"), "format", $format), E_USER_WARNING); } $template->printExpansion($toks); } } $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); flush(); } return ''; }
function CheckPgsrcUpdate() { // Check some theme specific pgsrc files (blog, wikilens, fusionforge, custom). // We check theme specific pgsrc first in case the page is present in both // theme specific and global pgsrc global $WikiTheme; $path = $WikiTheme->file("pgsrc"); // TBD: the call to fileSet prints a warning: // Notice: Unable to open directory 'themes/MonoBook/pgsrc' for reading $pgsrc = new fileSet($path); if ($pgsrc->getFiles()) { echo "<h3>", sprintf(_("Check for necessary theme %s updates"), "pgsrc"), "</h3>\n"; foreach ($pgsrc->getFiles() as $filename) { if (substr($filename, -1, 1) == '~') { continue; } if (substr($filename, -5, 5) == '.orig') { continue; } $pagename = urldecode($filename); $this->doPgsrcUpdate($pagename, $path, $filename); } } echo "<h3>", sprintf(_("Check for necessary %s updates"), "pgsrc"), "</h3>\n"; if ($this->db_version < 1030.12200612) { echo "<h4>", _("rename to Help: pages"), "</h4>\n"; } $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); // fixme: verification, ... foreach ($pgsrc->getFiles() as $filename) { if (substr($filename, -1, 1) == '~') { continue; } if (substr($filename, -5, 5) == '.orig') { continue; } $pagename = urldecode($filename); if (!isActionPage($filename)) { // There're a lot of now unneeded pages around. // At first rename the BlaPlugin pages to Help/<pagename> and then to the update. if ($this->db_version < 1030.12200612) { $this->_rename_to_help_page($pagename); } $this->doPgsrcUpdate($pagename, $path, $filename); } } }