function PurgePage(&$request) { global $WikiTheme; $page = $request->getPage(); $pagelink = WikiLink($page); if ($request->getArg('cancel')) { $request->redirect(WikiURL($page)); // noreturn } $current = $page->getCurrentRevision(); if (!$current or !($version = $current->getVersion())) { $html = HTML::p(array('class' => 'error'), _("Sorry, this page does not exist.")); } elseif (!$request->isPost() || !$request->getArg('verify')) { $purgeB = Button('submit:verify', _("Purge Page"), 'wikiadmin'); $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look $fieldset = HTML::fieldset(HTML::p(fmt("You are about to purge '%s'!", $pagelink)), HTML::form(array('method' => 'post', 'action' => $request->getPostURL()), HiddenInputs(array('currentversion' => $version, 'pagename' => $page->getName(), 'action' => 'purge')), HTML::div(array('class' => 'toolbar'), $purgeB, $WikiTheme->getButtonSeparator(), $cancelB))); $sample = HTML::div(array('class' => 'transclusion')); // simple and fast preview expanding only newlines foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) { $sample->pushContent($s, HTML::br()); } $html = HTML($fieldset, HTML::div(array('class' => 'wikitext'), $sample)); } elseif ($request->getArg('currentversion') != $version) { $html = HTML(HTML::p(array('class' => 'error'), _("Someone has edited the page!")), HTML::p(fmt("Since you started the purge process, someone has saved a new version of %s. Please check to make sure you still want to permanently purge the page from the database.", $pagelink))); } else { // Real purge. $pagename = $page->getName(); $dbi = $request->getDbh(); $dbi->purgePage($pagename); $dbi->touch(); $html = HTML::div(array('class' => 'feedback'), fmt("Purged page '%s' successfully.", $pagename)); } GeneratePage($html, _("Purge Page")); }
function run($dbi, $argstr, &$request, $basepage) { $request->setArg('action', false); $args = $this->getArgs($argstr, $request); extract($args); if ($goto = $request->getArg('goto')) { // The user has pressed 'Go'; process request $request->setArg('goto', false); $target = $goto['target']; if ($dbi->isWikiPage($target)) { $url = WikiURL($target, 0, 1); } else { $url = WikiURL($target, array('action' => 'edit'), 1); } $request->redirect($url); // User should see nothing after redirect return ''; } $action = $request->getURLtoSelf(); $form = HTML::form(array('action' => $action, 'method' => 'post')); $form->pushContent(HiddenInputs($request->getArgs())); $textfield = HTML::input(array('type' => 'text', 'size' => $size, 'name' => 'goto[target]')); $button = Button('submit:goto[go]', _("Go"), false); $form->pushContent($textfield, $button); return $form; }
function makeActionButton($action, $label = false, $page_or_rev = false, $options = false) { extract($this->_get_name_and_rev($page_or_rev)); if (is_array($action)) { $attr = $action; $action = isset($attr['action']) ? $attr['action'] : 'browse'; } else { $attr['action'] = $action; } $class = is_safe_action($action) ? 'new' : 'wikiadmin'; /* if selected action is current then prepend selected */ global $request; if ($request->getArg("action") == $action) { $class = "selected {$class}"; } //$class = "selected"; if (!empty($options['class'])) { $class = $options['class']; } if (!$label) { $label = $this->_labelForAction($action); } if ($version) { $attr['version'] = $version; } if ($action == 'browse') { unset($attr['action']); } $options = $this->fixAccesskey($options); return $this->makeButton($label, WikiURL($pagename, $attr), $class, $options); }
function linkUnknownWikiWord($wikiword, $linktext = '') { global $request; // Get rid of anchors on unknown wikiwords if (isa($wikiword, 'WikiPageName')) { $default_text = $wikiword->shortName; $wikiword = $wikiword->name; } else { $default_text = $wikiword; } $url = WikiURL($wikiword, array('action' => 'create')); //$link = HTML::span(HTML::a(array('href' => $url), '?')); $button = $this->makeButton('?', $url); $button->addTooltip(sprintf(_("Create: %s"), $wikiword)); $link = HTML::span($button); if (!empty($linktext)) { $link->unshiftContent(HTML::u($linktext)); $link->setAttr('class', 'named-wikiunknown'); } else { $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($default_text))); $link->setAttr('class', 'wikiunknown'); } if ($request->getArg('frame')) { $link->setAttr('target', '_top'); } return $link; }
function RemovePage(&$request) { global $WikiTheme; $page = $request->getPage(); $pagelink = WikiLink($page); if ($request->getArg('cancel')) { $request->redirect(WikiURL($page)); // noreturn } $current = $page->getCurrentRevision(); if (!$current or !($version = $current->getVersion())) { $html = HTML(HTML::h2(_("Already deleted")), HTML::p(_("Sorry, this page is not in the database."))); } elseif (!$request->isPost() || !$request->getArg('verify')) { $removeB = Button('submit:verify', _("Remove Page"), 'wikiadmin'); $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look $html = HTML(HTML::h2(fmt("You are about to remove '%s'!", $pagelink)), HTML::form(array('method' => 'post', 'action' => $request->getPostURL()), HiddenInputs(array('currentversion' => $version, 'pagename' => $page->getName(), 'action' => 'remove')), HTML::div(array('class' => 'toolbar'), $removeB, $WikiTheme->getButtonSeparator(), $cancelB)), HTML::hr()); $sample = HTML::div(array('class' => 'transclusion')); // simple and fast preview expanding only newlines foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) { $sample->pushContent($s, HTML::br()); } $html->pushContent(HTML::div(array('class' => 'wikitext'), $sample)); } elseif ($request->getArg('currentversion') != $version) { $html = HTML(HTML::h2(_("Someone has edited the page!")), HTML::p(fmt("Since you started the deletion process, someone has saved a new version of %s. Please check to make sure you still want to permanently remove the page from the database.", $pagelink))); } else { // Codendi specific: remove the deleted wiki page from ProjectWantedPages $projectPageName = 'ProjectWantedPages'; $pagename = $page->getName(); $dbi = $request->getDbh(); require_once PHPWIKI_DIR . "/lib/loadsave.php"; $pagehandle = $dbi->getPage($projectPageName); if ($pagehandle->exists()) { // don't replace default contents $current = $pagehandle->getCurrentRevision(); $version = $current->getVersion(); $text = $current->getPackedContent(); $meta = $current->_data; } $text = str_replace("* [{$pagename}]", "", $text); $meta['summary'] = $GLOBALS['Language']->getText('wiki_lib_wikipagewrap', 'page_added', array($pagename)); $meta['author'] = user_getname(); $pagehandle->save($text, $version + 1, $meta); //Codendi specific: remove permissions for this page @codenditodo: may be transferable otherwhere. require_once 'common/wiki/lib/WikiPage.class.php'; $wiki_page = new WikiPage(GROUP_ID, $_REQUEST['pagename']); $wiki_page->resetPermissions(); // Real delete. //$pagename = $page->getName(); $dbi = $request->getDbh(); $dbi->deletePage($pagename); $dbi->touch(); $link = HTML::a(array('href' => 'javascript:history.go(-2)'), _("Back to the previous page.")); $html = HTML(HTML::h2(fmt("Removed page '%s' successfully.", $pagename)), HTML::div($link), HTML::hr()); } GeneratePage($html, _("Remove Page")); }
function getFormElements() { $el = array(); if (!$this->request->getSessionVar('captcha_ok')) { $el['CAPTCHA_INPUT'] = HTML::input(array('type' => 'text', 'class' => 'wikitext', 'id' => 'edit:captcha_input', 'name' => 'edit[captcha_input]', 'size' => $this->length + 2, 'maxlength' => 256)); $url = WikiURL("", array("action" => "captcha", "id" => time()), false); $el['CAPTCHA_IMAGE'] = "<img src=\"{$url}\" alt=\"captcha\" />"; $el['CAPTCHA_LABEL'] = '<label for="edit:captcha_input">' . _("Type word above:") . ' </label>'; } return $el; }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $args = $this->getArgs($argstr, $request); extract($args); if ($request->getArg('action') != 'browse') { return $this->disabled("(action != 'browse')"); } if (!$request->isGetOrHead()) { return $this->disabled("(method != 'GET')"); } if (!$src and $page) { if ($page == $request->get('pagename')) { return $this->error(sprintf(_("recursive inclusion of page %s"), $page)); } $src = WikiURL($page); } if (!$src) { return $this->error(sprintf(_("%s or %s parameter missing"), 'src', 'page')); } // FIXME: How to normalize url's to compare against recursion? if ($src == $request->getURLtoSelf()) { return $this->error(sprintf(_("recursive inclusion of url %s"), $src)); } static $noframes = false; if ($noframes) { // Content for noframes version of page. return HTML::p(fmt("See %s", HTML::a(array('href' => $src), $src))); } $noframes = true; if ($which = $request->getArg('frame')) { // Generate specialized frame output (header, footer, etc...) $request->discardOutput(); displayPage($request, new Template("frame-{$which}", $request)); $request->finish(); //noreturn } // Generate the outer frameset $frame = HTML::frame(array('name' => $name, 'src' => $src, 'title' => $title, 'frameborder' => (int) $frameborder, 'scrolling' => (string) $scrolling, 'noresize' => (bool) $noresize)); if ($marginwidth) { $frame->setArg('marginwidth', $marginwidth); } if ($marginheight) { $frame->setArg('marginheight', $marginheight); } $tokens = array('CONTENT_FRAME' => $frame, 'ROWS' => $rows, 'COLS' => $cols, 'FRAMEARGS' => sprintf('frameborder="%d"', $frameborder)); // Produce the frameset. $request->discardOutput(); displayPage($request, new Template('frameset', $request, $tokens)); $request->finish(); //noreturn }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); // fix deprecated arg if (is_integer($pages)) { $numpages = $pages; $pages = false; // fix new pages handling in arg preprozessor. } elseif (is_array($pages)) { $numpages = (int) $pages[0]; if ($numpages > 0 and !$dbi->isWikiPage($numpages)) { $pages = false; } else { $numpages = 1; } } $allpages = $dbi->getAllPages(false, $sortby, $limit, $exclude); $pagearray = $allpages->asArray(); better_srand(); // Start with a good seed. if ($numpages == 1 && $pagearray) { $page = $pagearray[array_rand($pagearray)]; $pagename = $page->getName(); if ($redirect) { $request->redirect(WikiURL($pagename, false, 'absurl')); } // noreturn if ($hidename) { return WikiLink($pagename, false, _("RandomPage")); } else { return WikiLink($pagename); } } $numpages = min(max(1, (int) $numpages), 20, count($pagearray)); $pagelist = new PageList($info, $exclude, $args); $shuffle = array_rand($pagearray, $numpages); if (is_array($shuffle)) { foreach ($shuffle as $i) { if (isset($pagearray[$i])) { $pagelist->addPage($pagearray[$i]); } } } else { // if $numpages = 1 if (isset($pagearray[$shuffle])) { $pagelist->addPage($pagearray[$shuffle]); } } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); $href = $args['href']; $page = $args['page']; if ($href) { // If URL is urlencoded, decode it. if (strpos('%', $href) !== false) { $href = urldecode($href); } $url = strip_tags($href); if ($url != $href) { // URL contains tags return $this->disabled(_("Illegal characters in external URL.")); } $thispage = $request->getPage(); if (!$thispage->get('locked')) { return $this->disabled(_("Redirect to an external URL is only allowed in locked pages.")); } } else { if ($page) { $url = WikiURL($page, array('redirectfrom' => $request->getArg('pagename')), 'abs_path'); } else { return $this->error(_("'href' or 'page' parameter missing.")); } } if ($page == $request->getArg('pagename')) { return $this->error(fmt("Recursive redirect to self: '%s'", $url)); } if ($request->getArg('action') != 'browse') { return $this->disabled("(action != 'browse')"); } $redirectfrom = $request->getArg('redirectfrom'); if ($redirectfrom !== false) { if ($redirectfrom) { return $this->disabled(_("Double redirect not allowed.")); } else { // Got here by following the "Redirected from ..." link // on a browse page. return $this->disabled(_("Viewing redirecting page.")); } } return $request->redirect($url); }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); $href = $args['href']; $page = $args['page']; if ($href) { /* * Use quotes on the href argument value, like: * <?plugin RedirectTo href="http://funky.com/a b \" c.htm" ?> * * Do we want some checking on href to avoid malicious * uses of the plugin? Like stripping tags or hexcode. */ $url = preg_replace('/%\\d\\d/', '', strip_tags($href)); $thispage = $request->getPage(); if (!$thispage->get('locked')) { return $this->disabled(fmt("%s is only allowed in locked pages.", _("Redirect to an external url"))); } } else { if ($page) { $url = WikiURL($page, array('redirectfrom' => $request->getArg('pagename')), 'abs_path'); } else { return $this->error(fmt("%s or %s parameter missing", "'href'", "'page'")); } } if ($page == $request->getArg('pagename')) { return $this->error(fmt("Recursive redirect to self: '%s'", $url)); } if ($request->getArg('action') != 'browse') { return $this->disabled("(action != 'browse')"); } $redirectfrom = $request->getArg('redirectfrom'); if ($redirectfrom !== false) { if ($redirectfrom) { return $this->disabled(_("Double redirect not allowed.")); } else { // Got here by following the "Redirected from ..." link // on a browse page. return $this->disabled(_("Viewing redirecting page.")); } } return $request->redirect($url); }
function linkUnknownWikiWord($wikiword, $linktext = '') { global $request; if (isa($wikiword, 'WikiPageName')) { $default_text = $wikiword->shortName; $wikiword = $wikiword->name; } else { $default_text = $wikiword; } $url = WikiURL($wikiword, array('action' => 'create')); $link = HTML::span(HTML::a(array('href' => $url, 'rel' => 'nofollow'), '?')); if (!empty($linktext)) { $link->unshiftContent(HTML::u($linktext)); $link->setAttr('class', 'named-wikiunknown'); } else { $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($default_text))); $link->setAttr('class', 'wikiunknown'); } return $link; }
function makeActionButton($action, $label = false, $page_or_rev = false) { extract($this->_get_name_and_rev($page_or_rev)); if (is_array($action)) { $attr = $action; $action = isset($attr['action']) ? $attr['action'] : 'browse'; } else { $attr['action'] = $action; } $class = is_safe_action($action) ? 'named-wiki' : 'wikiadmin'; if (!$label) { $label = $this->_labelForAction($action); } if ($version) { $attr['version'] = $version; } if ($action == 'browse') { unset($attr['action']); } return $this->makeButton($label, WikiURL($pagename, $attr), $class); }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $args = $this->getArgs($argstr, $request, false); $page =& $args['page']; if (ENABLE_AJAX) { if ($args['state']) { $html = WikiPlugin_IncludePage::run($dbi, $argstr, $request, $basepage); } else { $html = HTML(HTML::p(array('class' => 'transclusion-title'), fmt(" %s :", WikiLink($page))), HTML::div(array('class' => 'transclusion'), '')); } $ajaxuri = WikiURL($page, array('format' => 'xml')); } else { $html = WikiPlugin_IncludePage::run($dbi, $argstr, $request, $basepage); } $header = $html->_content[0]; $body = $html->_content[1]; $id = 'DynInc-' . MangleXmlIdentifier($page); $body->setAttr('id', $id . '-body'); $png = $WikiTheme->_findData('images/folderArrow' . ($args['state'] ? 'Open' : 'Closed') . '.png'); $icon = HTML::img(array('id' => $id . '-img', 'src' => $png, 'onclick' => ENABLE_AJAX ? "showHideAsync('" . $ajaxuri . "','{$id}')" : "showHideFolder('{$id}')", 'alt' => _("Click to hide/show"), 'title' => _("Click to hide/show"))); $header = HTML::p(array('class' => 'transclusion-title', 'style' => "text-decoration: none;"), $icon, fmt(" %s :", WikiLink($page))); if ($args['state']) { // show base $body->setAttr('style', 'display:block'); return HTML($header, $body); } else { // do not show base $body->setAttr('style', 'display:none'); if (ENABLE_AJAX) { return HTML($header, $body); } else { return HTML($header, $body); } // sync (load but display:none) } }
function channel_properties() { global $request; $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl'); return array('title' => WIKI_NAME, 'link' => $rc_url, 'description' => _("RecentChanges"), 'dc:date' => Iso8601DateTime(time()), 'dc:language' => $GLOBALS['LANG']); /* FIXME: other things one might like in <channel>: * sy:updateFrequency * sy:updatePeriod * sy:updateBase * dc:subject * dc:publisher * dc:language * dc:rights * rss091:language * rss091:managingEditor * rss091:webmaster * rss091:lastBuildDate * rss091:copyright */ }
function linkExistingWikiWord($wikiword, $linktext = '', $version = false) { global $request; if ($version !== false and !$this->HTML_DUMP_SUFFIX) { $url = WikiURL($wikiword, array('version' => $version)); } else { $url = WikiURL($wikiword); } // Extra steps for dumping page to an html file. if ($this->HTML_DUMP_SUFFIX) { $url = preg_replace('/^\\./', '%2e', $url); // dot pages } $link = HTML::a(array('href' => $url)); if (isa($wikiword, 'WikiPageName')) { $default_text = $wikiword->shortName; } else { $default_text = $wikiword; } if (!empty($linktext)) { $link->pushContent($linktext); $link->setAttr('class', 'named-wiki'); $link->setAttr('title', $this->maybeSplitWikiWord($default_text)); } else { //TODO: check if wikiblog $link->pushContent($this->maybeSplitWikiWord($default_text)); $link->setAttr('class', 'wiki'); } return $link; }
function format($text) { include_once 'lib/Template.php'; global $request; $tokens['page'] = $this->_page; $tokens['CONTENT'] = $this->_transform($text); $pagename = $this->_page->getName(); // This is a XmlElement tree, which must be converted to PDF // We can make use of several pdf extensions. This one - fpdf // - is pure php and very easy, but looks quite ugly and has a // terrible interface, as terrible as most of the othes. // The closest to HTML is htmldoc which needs an external cgi // binary. // We use a custom HTML->PDF class converter from PHPWebthings // to be able to use templates for PDF. require_once 'lib/fpdf.php'; require_once 'lib/pdf.php'; $pdf = new PDF(); $pdf->SetTitle($pagename); $pdf->SetAuthor($this->_page->get('author')); $pdf->SetCreator(WikiURL($pagename, false, 1)); $pdf->AliasNbPages(); $pdf->AddPage(); //TODO: define fonts $pdf->SetFont('Times', '', 12); //$pdf->SetFont('Arial','B',16); // PDF pagelayout from a special template $template = new Template('pdf', $request, $tokens); $pdf->ConvertFromHTML($template); // specify filename, destination $pdf->Output($pagename . ".pdf", 'I'); // I for stdin or D for download // Output([string name [, string dest]]) return $pdf; }
/** Side-effect on email changes: * Send a verification mail or for now just a notification email. * For true verification (value = 2), we'd need a mailserver hook. */ function update($value) { if (!empty($this->_init)) { return; } $verified = $this->getraw('emailVerified'); // hack! if (($value == 1 or $value === true) and $verified) { return; } if (!empty($value) and !$verified) { list($ok, $msg) = ValidateMail($value); if ($ok and mail($value, "[" . WIKI_NAME . "] " . _("Email Verification"), sprintf(_("Welcome to %s!\nYour email account is verified and\nwill be used to send page change notifications.\nSee %s"), WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'), '', true)))) { $this->set('emailVerified', 1); } } }
function run($dbi, $argstr, &$request, $basepage) { //if ($request->getArg('action') != 'browse') // return $this->disabled("(action != 'browse')"); $args = $this->getArgs($argstr, $request); $this->_args = $args; extract($args); $this->preSelectS($args, $request); $info = $args['info']; $this->debug = $args['debug']; // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC); $pagename = $request->getArg('pagename'); // GetUrlToSelf() with all given params //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better. //$uri = $request->getURLtoSelf();//false, array('verify')); $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST')); if ($request->getArg('WikiAdminSelect') == _("Go")) { $p = false; } else { $p = $request->getArg('p'); } //$p = @$GLOBALS['HTTP_POST_VARS']['p']; $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "), HTML::input(array('type' => 'text', 'name' => 's', 'value' => $args['s'])), HTML::input(array('type' => 'submit', 'name' => 'WikiAdminSelect', 'value' => _("Go"))))); if ($request->isPost() && !$request->getArg('wikiadmin') && !empty($p)) { $this->_list = array(); // List all selected pages again. foreach ($p as $page => $name) { $this->_list[$name] = 1; } } elseif ($request->isPost() and $request->_user->isAdmin() and !empty($p) and $request->getArg('action') == 'WikiAdminSelect' and $request->getArg('wikiadmin')) { // handle external plugin $loader = new WikiPluginLoader(); $a = array_keys($request->getArg('wikiadmin')); $plugin_action = $a[0]; $single_arg_plugins = array("Remove"); if (in_array($plugin_action, $single_arg_plugins)) { $plugin = $loader->getPlugin($plugin_action); $ul = HTML::ul(); foreach ($p as $page => $name) { $plugin_args = "run_page={$name}"; $request->setArg($plugin_action, 1); $request->setArg('p', array($page => $name)); // if the plugin requires more args than the pagename, // then this plugin will not return. (Rename, SearchReplace, ...) $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage); $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.", $name, $select))); $ul->pushContent(HTML::ul(HTML::li($action_result))); } } else { // redirect to the plugin page. // in which page is this plugin? $plugin_action = preg_replace("/^WikiAdmin/", "", $plugin_action); $args = array(); foreach ($p as $page => $x) { $args["p[{$page}]"] = 1; } header("Location: " . WikiURL(_("PhpWikiAdministration") . "/" . _($plugin_action), $args, 1)); exit; } } elseif (empty($args['s'])) { // List all pages to select from. $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']); } $pagelist = new PageList_Selectable($info, $args['exclude'], $args); $pagelist->addPageList($this->_list); $form->pushContent($pagelist->getContent()); foreach ($args as $k => $v) { if (!in_array($k, array('s', 'WikiAdminSelect', 'action', 'verify'))) { $form->pushContent(HiddenInputs(array($k => $v))); } // plugin params } /* foreach ($_GET as $k => $v) { if (!in_array($k,array('s','WikiAdminSelect','action'))) $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ... } */ if (!$request->getArg('verify')) { $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'verify'))); $form->pushContent(Button('submit:verify', _("Select pages"), 'wikiadmin'), Button('submit:cancel', _("Cancel"), 'button')); } else { global $WikiTheme; $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'WikiAdminSelect'))); // Add the Buttons for all registered WikiAdmin plugins $plugin_dir = 'lib/plugin'; if (defined('PHPWIKI_DIR')) { $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}"; } $fs = new fileSet($plugin_dir, 'WikiAdmin*.php'); $actions = $fs->getFiles(); foreach ($actions as $f) { $f = preg_replace('/.php$/', '', $f); $s = preg_replace('/^WikiAdmin/', '', $f); if (!in_array($s, array("Select", "Utils"))) { // disable Select and Utils $form->pushContent(Button("submit:wikiadmin[{$f}]", _($s), "wikiadmin")); $form->pushContent($WikiTheme->getButtonSeparator()); } } $form->pushContent(Button('submit:cancel', _("Cancel"), 'button')); } if (!$request->getArg('select')) { return $form; } else { //return $action_result; } }
function run($dbi, $argstr, $request, $basepage) { global $WikiTheme; $args = $this->getArgs($argstr, $request); $caption = _("All pages with all links in this wiki (%d total):"); if (!empty($args['owner'])) { $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'], $args['sortby'], $args['limit']); if ($args['owner']) { $caption = fmt("List of pages owned by [%s] (%d total):", WikiLink($args['owner'], 'if_known'), count($pages)); } } elseif (!empty($args['author'])) { $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'], $args['sortby'], $args['limit']); if ($args['author']) { $caption = fmt("List of pages last edited by [%s] (%d total):", WikiLink($args['author'], 'if_known'), count($pages)); } } elseif (!empty($args['creator'])) { $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'], $args['sortby'], $args['limit']); if ($args['creator']) { $caption = fmt("List of pages created by [%s] (%d total):", WikiLink($args['creator'], 'if_known'), count($pages)); } } else { if (!$request->getArg('count')) { $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']); } else { $args['count'] = $request->getArg('count'); } $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit'], $args['exclude_from']); } if ($args['format'] == 'html') { $args['types']['links'] = new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left'); $pagelist = new PageList($args['info'], $args['exclude_from'], $args); if (!$args['noheader']) { $pagelist->setCaption($caption); } return $pagelist; } elseif ($args['format'] == 'text') { $request->discardOutput(); $request->buffer_output(false); if (!headers_sent()) { header("Content-Type: text/plain"); } $request->checkValidators(); while ($page = $pages->next()) { echo $page->getName(); $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']); while ($link = $links->next()) { echo " ", $link->getName(); } echo "\n"; } flush(); if (empty($WikiTheme->DUMP_MODE)) { $request->finish(); } } elseif ($args['format'] == 'xml') { // For hypergraph.jar. Best dump it to a local sitemap.xml periodically global $WikiTheme, $charset; $currpage = $request->getArg('pagename'); $request->discardOutput(); $request->buffer_output(false); if (!headers_sent()) { header("Content-Type: text/xml"); } $request->checkValidators(); echo "<?xml version=\"1.0\" encoding=\"{$charset}\"?>"; // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot. $dtd = $WikiTheme->_findData("GraphXML.dtd"); echo "<!DOCTYPE GraphXML SYSTEM \"{$dtd}\">\n"; echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"; echo "<graph id=\"", MangleXmlIdentifier(WIKI_NAME), "\">\n"; echo '<style><line tag="node" class="main" colour="#ffffff"/><line tag="node" class="child" colour="blue"/><line tag="node" class="relation" colour="green"/></style>', "\n\n"; while ($page = $pages->next()) { $pageid = MangleXmlIdentifier($page->getName()); $pagename = $page->getName(); echo "<node name=\"{$pageid}\""; if ($pagename == $currpage) { echo " class=\"main\""; } echo "><label>{$pagename}</label>"; echo "<dataref><ref xlink:href=\"", WikiURL($pagename, '', true), "\"/></dataref></node>\n"; $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']); while ($link = $links->next()) { $edge = MangleXmlIdentifier($link->getName()); echo "<edge source=\"{$pageid}\" target=\"{$edge}\" />\n"; } echo "\n"; } echo "</graph>\n"; echo "</GraphXML>\n"; if (empty($WikiTheme->DUMP_MODE)) { unset($GLOBALS['ErrorManager']->_postponed_errors); $request->finish(); } } else { return $this->error(fmt("Unsupported format argument %s", $args['format'])); } }
/** * Send mail to user and store the cookie in the db * wikiurl?action=ConfirmEmail&id=bla */ function sendEmailConfirmation($email, $userid) { $id = rand_ascii_readable(16); $wikidb = $GLOBALS['request']->getDbh(); $data = $wikidb->get('ConfirmEmail'); while (!empty($data[$id])) { // id collision $id = rand_ascii_readable(16); } $subject = _("E-Mail address confirmation"); $ip = $request->get('REMOTE_HOST'); $expire_date = time() + 7 * 86400; $content = fmt("Someone, probably you from IP address %s, has registered an\naccount \"%s\" with this e-mail address on %s.\n\nTo confirm that this account really does belong to you and activate\ne-mail features on %s, open this link in your browser:\n\n%s\n\nIf this is *not* you, don't follow the link. This confirmation code\nwill expire at %s.", $ip, $userid, WIKI_NAME, WIKI_NAME, WikiURL(HOME_PAGE, array('action' => 'ConfirmEmail', 'id' => $id), true), CTime($expire_date)); $this->sendMail($subject, $content, "", true); $data[$id] = array('email' => $email, 'userid' => $userid, 'expire' => $expire_date); $wikidb->set('ConfirmEmail', $data); return ''; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); return HTML::a(array('href' => WikiURL($link), 'target' => "_blank", 'onclick' => ($close == "yes" ? "window.close()" : "window.open('" . WikiURL($link) . "', '" . ($title == "" ? $text == "" ? $link : $text : $title) . "', '" . "width={$width}," . "height={$height}," . "resizable={$resizable}," . "scrollbars={$scrollbars}," . "toolbar={$toolbar}," . "location={$location}," . "directories={$directories}," . "status={$status}," . "menubar={$menubar}," . "copyhistory={$copyhistory}')") . ";return false;"), $text == "" ? $close == "yes" ? "Close window" : $link : $text); }
function displayPage(&$request, $template = false) { global $WikiTheme, $pv; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } } else { $revision = $page->getCurrentRevision(); } 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) { if ($pv != 2) { //Add the Backlink in page title $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); } else { // Remove Backlinks $pageheader->pushContent(HTML::h1($pagename)); } $first_pages .= $p . SUBPAGE_SEPARATOR; } if ($pv != 2) { $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); } else { $backlink = HTML::h1($pagename); } $pageheader->pushContent($backlink); } else { if ($pv != 2) { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); } else { $pageheader = HTML::h1($pagename); //Remove Backlinks } if ($request->getArg('frame')) { $pageheader->setAttr('target', '_top'); } } // {{{ Codendi hook to insert stuff between navbar and header $eM =& EventManager::instance(); $ref_html = ''; $crossref_fact = new CrossReferenceFactory($pagename, ReferenceManager::REFERENCE_NATURE_WIKIPAGE, GROUP_ID); $crossref_fact->fetchDatas(); if ($crossref_fact->getNbReferences() > 0) { $ref_html .= '<h3>' . $GLOBALS['Language']->getText('cross_ref_fact_include', 'references') . '</h3>'; $ref_html .= $crossref_fact->getHTMLDisplayCrossRefs(); } $additional_html = false; $eM->processEvent('wiki_before_content', array('html' => &$additional_html, 'group_id' => GROUP_ID, 'wiki_page' => $pagename)); if ($additional_html) { $beforeHeader = HTML(); $beforeHeader->pushContent($additional_html); $beforeHeader->pushContent(HTML::raw($ref_html)); $toks['BEFORE_HEADER'] = $beforeHeader; } else { $beforeHeader = HTML(); $beforeHeader->pushContent(HTML::raw($ref_html)); $toks['BEFORE_HEADER'] = $beforeHeader; } // }}} /Codendi hook $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']); } */ $page_content = $revision->getTransformedContent(); // if external searchengine (google) referrer, highlight the searchterm // FIXME: move that to the transformer? // OR: add the searchhightplugin line to the content? if ($result = isExternalReferrer($request)) { if (DEBUG and !empty($result['query'])) { //$GLOBALS['SearchHighlightQuery'] = $result['query']; /* simply add the SearchHighlight plugin to the top of the page. This just parses the wikitext, and doesn't highlight the markup */ include_once 'lib/WikiPlugin.php'; $loader = new WikiPluginLoader(); $xml = $loader->expandPI('<' . '?plugin SearchHighlight s="' . $result['query'] . '"?' . '>', $request, $markup); if ($xml and is_array($xml)) { foreach (array_reverse($xml) as $line) { array_unshift($page_content->_content, $line); } array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query']))); } if (0) { /* Parse the transformed (mixed HTML links + strings) lines? This looks like overkill. */ require_once "lib/TextSearchQuery.php"; $query = new TextSearchQuery($result['query']); $hilight_re = $query->getHighlightRegexp(); //$matches = preg_grep("/$hilight_re/i", $revision->getContent()); // FIXME! for ($i = 0; $i < count($page_content->_content); $i++) { $found = false; $line = $page_content->_content[$i]; if (is_string($line)) { while (preg_match("/^(.*?)({$hilight_re})/i", $line, $m)) { $found = true; $line = substr($line, strlen($m[0])); $html[] = $m[1]; // prematch $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match } } if ($found) { $html[] = $line; // postmatch $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html); } } } } } $toks['CONTENT'] = new Template('browse', $request, $page_content); $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } $toks['ROBOTS_META'] = 'index,follow'; $toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } $template->printExpansion($toks); $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); } flush(); }
function action_search() { // This is obsolete: reformulate URL and redirect. // FIXME: this whole section should probably be deleted. if ($this->getArg('searchtype') == 'full') { $search_page = _("FullTextSearch"); } else { $search_page = _("TitleSearch"); } $this->redirect(WikiURL($search_page, array('s' => $this->getArg('searchterm')), 'absolute_url')); }
function LinkPhpwikiURL($url, $text = '', $basepage = false) { $args = array(); if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) { return HTML::span(array('class' => 'error'), _("BAD phpwiki: URL")); } if ($m[1]) { $pagename = urldecode($m[1]); } $qargs = $m[2]; if (empty($pagename) && preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) { // Convert old style links (to not break diff links in // RecentChanges). $pagename = urldecode($m[2]); $args = array("action" => $m[1]); } else { $args = SplitQueryArgs($qargs); } if (empty($pagename)) { $pagename = $GLOBALS['request']->getArg('pagename'); } if (isset($args['action']) && $args['action'] == 'browse') { unset($args['action']); } /*FIXME: if (empty($args['action'])) $class = 'wikilink'; else if (is_safe_action($args['action'])) $class = 'wikiaction'; */ if (empty($args['action']) || is_safe_action($args['action'])) { $class = 'wikiaction'; } else { // Don't allow administrative links on unlocked pages. $dbi = $GLOBALS['request']->getDbh(); $page = $dbi->getPage($basepage ? $basepage : $pagename); if (!$page->get('locked')) { return HTML::span(array('class' => 'wikiunsafe'), HTML::u(_("Lock page to enable link"))); } $class = 'wikiadmin'; } if (!$text) { $text = HTML::span(array('class' => 'rawurl'), $url); } $wikipage = new WikiPageName($pagename); if (!$wikipage->isValid()) { global $WikiTheme; return $WikiTheme->linkBadWikiWord($wikipage, $url); } return HTML::a(array('href' => WikiURL($pagename, $args), 'class' => $class), $text); }
function channel_properties() { global $request; $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl'); return array('title' => WIKI_NAME, 'description' => _("RecentChanges"), 'link' => $rc_url, 'language' => 'en-US'); /* FIXME: language should come from $LANG (or other config variable). */ /* FIXME: other things one might like in <channel>: * managingEditor * webmaster * lastBuildDate * copyright */ }
function RatingWidgetJavascript() { global $WikiTheme; if (!empty($this->imgPrefix)) { $imgPrefix = $this->imgPrefix; } elseif (defined("RATEIT_IMGPREFIX")) { $imgPrefix = RATEIT_IMGPREFIX; } else { $imgPrefix = ''; } if ($imgPrefix and !$WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk0.png", 1)) { $imgPrefix = ''; } $img = substr($WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk0.png"), 0, -7); $urlprefix = WikiURL("", 0, 1); // TODO: check actions USE_PATH_INFO=false $js = "\nfunction displayRating(imgPrefix, ratingvalue, pred) {\n var cancel = imgPrefix + 'Cancel';\n for (i=1; i<=10; i++) {\n var imgName = imgPrefix + i;\n var imgSrc = '" . $img . "'; \n document[imgName].title = '" . _("Your rating ") . "'+ratingvalue;\n var imgType = 'N';\n if (pred) {\n imgType = 'R';\n } else if (i<=(ratingvalue*2)) {\n imgType = 'O';\n }\n document[imgName].src = imgSrc + imgType + ((i%2) ? 'k1' : 'k0') + '.png';\n }\n //document[cancel].src = imgSrc + 'Cancel.png';\n}\nfunction click(actionImg, pagename, version, imgPrefix, dimension, rating) {\n if (rating == 'X') {\n deleteRating(actionImg, pagename, dimension);\n displayRating(imgPrefix, 0, 0);\n } else {\n submitRating(actionImg, pagename, version, dimension, rating);\n displayRating(imgPrefix, rating, 0);\n }\n}\nfunction submitRating(actionImg, page, version, dimension, rating) {\n var myRand = Math.round(Math.random()*(1000000));\n var imgSrc = '" . $urlprefix . "' + escape(page) + '?version=' + version + '&action=" . urlencode(_("RateIt")) . "&mode=add&rating=' + rating + '&dimension=' + dimension + '&nopurge=1&rand=' + myRand" . (!empty($_GET['start_debug']) ? "+'&start_debug=1'" : '') . ";\n " . (DEBUG ? '' : '//') . "alert('submitRating(\"'+actionImg+'\", \"'+page+'\", '+version+', '+dimension+', '+rating+') => '+imgSrc);\n document[actionImg].src = imgSrc;\n}\nfunction deleteRating(actionImg, page, dimension) {\n var myRand = Math.round(Math.random()*(1000000));\n var imgSrc = '" . $urlprefix . "' + escape(page) + '?action=" . urlencode(_("RateIt")) . "&mode=delete&dimension=' + dimension + '&nopurge=1&rand=' + myRand" . (!empty($_GET['start_debug']) ? "+'&start_debug=1'" : '') . ";\n " . (DEBUG ? '' : '//') . "alert('deleteRating(\"'+actionImg+'\", \"'+page+'\", '+version+', '+dimension+')');\n document[actionImg].src = imgSrc;\n}\n"; return JavaScript($js); }
function format($changes) { global $request; include_once 'lib/RssWriter.php'; $rss = new AtomFeed(); // "channel" is called "feed" in atom $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl'); extract($this->_args); $title = WIKI_NAME; $description = $this->title(); if ($category) { $title = $category; } elseif ($pagematch) { $title = $pagematch; } $feed_props = array('title' => $description, 'link' => array('rel' => "alternate", 'type' => "text/html", 'href' => $rc_url), 'id' => md5($rc_url), 'modified' => Iso8601DateTime(time()), 'generator' => 'PhpWiki-' . PHPWIKI_VERSION, 'tagline' => ''); $rss->feed($feed_props); $first = true; while ($rev = $changes->next()) { // enforce view permission if (mayAccessPage('view', $rev->_pagename)) { $props = $this->item_properties($rev); $rss->addItem($props, false, $this->pageURI($rev)); if ($first) { $this->setValidators($rev); } $first = false; } } $request->discardOutput(); $rss->finish(); //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']); printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION); // Flush errors in comment, otherwise it's invalid XML. global $ErrorManager; if ($errors = $ErrorManager->getPostponedErrorsAsHTML()) { printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors)); } $request->finish(); // NORETURN!!!! }
/** support mass rename / remove (not yet tested) */ function sendPageRenameNotification($to, &$meta, $emails, $userids) { global $request; if (@is_array($request->_deferredPageRenameNotification)) { $request->_deferredPageRenameNotification[] = array($this->_pagename, $to, $meta, $emails, $userids); } else { $oldname = $this->_pagename; // Codendi specific $subject = sprintf(_("Page rename %s to %s"), $oldname, $to); $from = user_getemail(user_getid()); $body = $subject . "\n" . sprintf(_("Edited by: %s"), $from) . "\n" . WikiURL($to, array(), true); $m = new Mail(); $m->setFrom($from); $m->setSubject("[" . WIKI_NAME . "] " . $subject); $m->setBcc(join(',', $emails)); $m->setBody($body); if ($m->send()) { trigger_error(sprintf(_("PageChange Notification of %s sent to %s"), $oldname, join(',', $userids)), E_USER_NOTICE); } else { trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"), $oldname, join(',', $userids)), E_USER_WARNING); } } }
/** Side-effect on email changes: * Send a verification mail or for now just a notification email. * For true verification (value = 2), we'd need a mailserver hook. */ function update($value) { // e-mail address is already checked by FusionForge if (FUSIONFORGE) { return $value; } if (!empty($this->_init)) { return; } $verified = $this->getraw('emailVerified'); // hack! if (($value == 1 or $value === true) and $verified) { return; } if (!empty($value) and !$verified) { list($ok, $msg) = ValidateMail($value); if ($ok and mail($value, "[" . WIKI_NAME . "] " . _("Email Verification"), sprintf(_("Welcome to %s!\nYour email account is verified and\nwill be used to send page change notifications.\nSee %s"), WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'), '', true)))) { $this->set('emailVerified', 1); } else { trigger_error($msg, E_USER_WARNING); } } }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $this->_supported_operators = array(':=', '<', '<=', '>', '>=', '!=', '==', '=~'); $args = $this->getArgs($argstr, $request); $posted = $request->getArg('semsearch'); $request->setArg('semsearch', false); if ($request->isPost() and isset($posted['help'])) { $request->redirect(WikiURL(_("Help/SemanticSearchAdvancedPlugin"), array('redirectfrom' => $basepage), true)); } $allrelations = $dbi->listRelations(); $form = $this->showForm($dbi, $request, $args, $allrelations); if (isset($this->_norelations_warning)) { $form->pushContent(HTML::div(array('class' => 'warning'), _("Warning:") . $this->_norelations_warning)); } extract($args); // For convenience, peace and harmony we allow GET requests also. if (!$args['s']) { // check for good GET request return $form; } // nobody called us, so just display our form // In reality we have to iterate over all found pages. // To makes things shorter extract the next AND required expr and // iterate only over this, then recurse into the next AND expr. // => Split into an AND and OR expression tree. $parsed_relations = $this->detectRelationsAndAttributes($args['s']); $regex = ''; if ($parsed_relations) { $regex = preg_grep("/[\\*\\?]/", $parsed_relations); } else { $this->error("Invalid query: No relations or attributes in the query {$s} found"); } $pagelist = new PageList($args['info'], $args['exclude'], $args); if (!$noheader) { $pagelist->setCaption(HTML($noform ? '' : HTML($form, HTML::hr()), fmt("Semantic %s Search Result for \"%s\" in pages \"%s\"", '', $s, $page))); } if (!$regex and $missing = array_diff($parsed_relations, $allrelations)) { return $pagelist; } $relquery = new TextSearchQuery(join(" ", $parsed_relations)); if (!$relquery->match(join(" ", $allrelations))) { return $pagelist; } $pagequery = new TextSearchQuery($page, $args['case_exact'], $args['regex']); // if we have only numeric or text ops we can optimize. //$parsed_attr_ops = $this->detectAttrOps($args['s']); //TODO: writeme $linkquery = new TextSearchQuery($s, $args['case_exact'], $args['regex']); $links = $dbi->linkSearch($pagequery, $linkquery, 'relation', $relquery); $pagelist->_links = array(); while ($link = $links->next()) { $pagelist->addPage($link['pagename']); $pagelist->_links[] = $link; } $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('relation', _("Relation"), $pagelist)); $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('link', _("Link"), $pagelist)); return $pagelist; }