/** * Renders this page in display mode. * * @param string $searchtext The title to search for. * * @return string The content. * @throws Wicked_Exception */ public function display($searchtext) { global $injector, $notification, $page_output, $wicked; $view = $injector->createInstance('Horde_View'); if (!$searchtext) { return $view->render('pagelist/search') . $view->render('pagelist/footer'); } /* Prepare exact match section */ $exact = array(); $page = new Wicked_Page_StandardPage($searchtext); if ($wicked->pageExists($searchtext)) { $exact[] = $page->toView(); } else { $exact[] = (object) array('author' => '', 'context' => Wicked::url($searchtext, false)->link(array('title' => sprintf(_("Create %s"), $searchtext))) . sprintf(_("%s does not exist. You can create it now."), '<strong>' . htmlspecialchars($searchtext) . '</strong>') . '</a>', 'date' => '', 'name' => htmlspecialchars($searchtext), 'timestamp' => 0, 'version' => '', 'url' => Wicked::url($searchtext, false)); } /* Prepare page title matches */ $titles = array(); foreach ($this->_results['titles'] as $page) { if (!empty($page['page_history'])) { $page = new Wicked_Page_StandardHistoryPage($page); } else { $page = new Wicked_Page_StandardPage($page); } $titles[] = $page->toView(); } /* Prepare page text matches */ $pages = array(); foreach ($this->_results['pages'] as $page) { if (!empty($page['page_history'])) { $page = new Wicked_Page_StandardHistoryPage($page); } else { $page = new Wicked_Page_StandardPage($page); } $object = $page->toView(); $object->context = $this->getContext($page, $searchtext); $pages[] = $object; } $page_output->addScriptFile('tables.js', 'horde'); $header = $injector->createInstance('Horde_View'); $header->th_page = _("Page"); $header->th_version = _("Current Version"); $header->th_author = _("Last Author"); $header->th_updated = _("Last Update"); $view = $injector->createInstance('Horde_View'); // Show search form and page header. $content = $view->render('pagelist/search'); // Show exact match. $header->title = _("Exact Match"); $content .= $header->render('pagelist/results_header') . $view->renderPartial('pagelist/page', array('collection' => $exact)) . $view->render('pagelist/results_footer'); // Show page title matches. $header->title = _("Page Title Matches"); $content .= $header->render('pagelist/results_header') . $view->renderPartial('pagelist/page', array('collection' => $titles)) . $view->render('pagelist/results_footer'); // Show page text matches. $header->title = _("Page Text Matches"); $content .= $header->render('pagelist/results_header') . $view->renderPartial('pagelist/page', array('collection' => $pages)) . $view->render('pagelist/results_footer'); return $content; }
/** */ public function menu($menu) { global $conf, $page; if (@count($conf['menu']['pages'])) { $pages = array('Wiki/Home' => _("_Home"), 'Wiki/Usage' => _("_Usage"), 'RecentChanges' => _("_Recent Changes"), 'AllPages' => _("_All Pages"), 'MostPopular' => _("Most Popular"), 'LeastPopular' => _("Least Popular")); foreach ($conf['menu']['pages'] as $pagename) { /* Determine who we should say referred us. */ $curpage = isset($page) ? $page->pageName() : null; $referrer = Horde_Util::getFormData('referrer', $curpage); /* Determine if we should depress the button. We have to do * this on our own because all the buttons go to the same .php * file, just with different args. */ if (!strstr($_SERVER['PHP_SELF'], 'prefs.php') && $curpage === $pagename) { $cellclass = 'current'; } else { $cellclass = '__noselection'; } $url = Wicked::url($pagename)->add('referrer', $referrer); $menu->add($url, $pages[$pagename], 'wicked-' . str_replace('/', '', $pagename), null, null, null, $cellclass); } } }
/** * Renders this page in display mode. * * @throws Wicked_Exception */ public function display() { global $injector, $page_output, $wicked; $view = $injector->createInstance('Horde_View'); $view->action = Wicked::url('NewPage'); $view->formInput = Horde_Util::formInput(); $view->referrer = $this->referrer(); $view->name = $this->pageName(); if ($this->_results) { $page_output->addScriptFile('tables.js', 'horde'); $view->pages = array(); foreach ($this->_results as $page) { if (!empty($page['page_history'])) { $page = new Wicked_Page_StandardHistoryPage($page); } else { $page = new Wicked_Page_StandardPage($page); } $view->pages[] = $page->toView(); } } $view->templates = $wicked->getMatchingPages('Template', Wicked_Page::MATCH_ENDS); $view->help = Horde_Help::link('wicked', 'Templates'); return $view->render('edit/create'); }
public function handleAction() { global $notification; $page = Wicked_Page::getPage($this->referrer()); if ($page->allows(Wicked::MODE_EDIT)) { $version = Horde_Util::getPost('version'); if (empty($version)) { $notification->push(sprintf(_("Can't revert to an unknown version.")), 'horde.error'); Wicked::url($this->referrer(), true)->redirect(); } $oldpage = Wicked_Page::getPage($this->referrer(), $version); $page->updateText($oldpage->getText(), 'Revert'); $notification->push(sprintf(_("Reverted to version %s of \"%s\"."), $version, $page->pageName())); Wicked::url($page->pageName(), true)->redirect(); } $notification->push(sprintf(_("You don't have permission to edit \"%s\"."), $page->pageName()), 'horde.warning'); Wicked::url($this->referrer(), true)->redirect(); }
public function handleAction() { $pagename = $this->referrer(); $page = Wicked_Page::getPage($pagename); if ($page->allows(Wicked::MODE_REMOVE)) { $version = Horde_Util::getFormData('version'); if (empty($version)) { $GLOBALS['wicked']->removeAllVersions($pagename); $GLOBALS['notification']->push(sprintf(_("Successfully deleted \"%s\"."), $pagename), 'horde.success'); Wicked::mail("Deleted page: {$pagename}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename)); Wicked::url('Wiki/Home', true)->redirect(); } $GLOBALS['wicked']->removeVersion($pagename, $version); $GLOBALS['notification']->push(sprintf(_("Deleted version %s of \"%s\"."), $version, $pagename), 'horde.success'); Wicked::mail("Deleted version: {$version} of {$pagename}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename . ' [' . $version . ']')); Wicked::url($pagename, true)->redirect(); } $GLOBALS['notification']->push(sprintf(_("You don't have permission to delete \"%s\"."), $pagename), 'horde.warning'); Wicked::url($this->referrer(), true)->redirect(); }
/** * Retrieve the form fields and process the merge or rename. */ public function handleAction() { global $wicked, $notification, $registry; if (Horde_Util::getFormData('submit') == _("Cancel")) { Wicked::url($this->referrer(), true)->redirect(); } $referrer = $this->referrer(); $new_name = Horde_Util::getFormData('new_name'); if (empty($new_name)) { $this->_errors['new_name'] = _("This is a required field."); } elseif ($new_name == $referrer) { $this->_errors['new_name'] = _("New name is the same as old name."); } $collision = Horde_Util::getFormData('collision'); if (empty($collision)) { $this->_errors['collision'] = _("This is a required field."); } if (count($this->_errors)) { return; } $sourcePage = Wicked_Page::getPage($referrer); if (!$this->allows(Wicked::MODE_EDIT)) { throw new Wicked_Exception(sprintf(_("You do not have permission to edit \"%s\""), $referrer)); } $destPage = Wicked_Page::getPage($new_name); if (!$destPage instanceof Wicked_Page_AddPage) { // Destination page exists. if ($collision != 'merge') { // We don't want to overwrite. throw new Wicked_Exception(sprintf(_("Page \"%s\" already exists."), $new_name)); } if (!$destPage->allows(Wicked::MODE_EDIT)) { throw new Wicked_Exception(sprintf(_("You do not have permission to edit \"%s\""), $new_name)); } // Merge the two pages. $newText = $destPage->getText() . "\n----\n" . $sourcePage->getText(); $changelog = sprintf(_("Merged from %s"), $referrer); $wicked->updateText($new_name, $newText, $changelog); $wicked->removeAllVersions($referrer); $notification->push(sprintf(_("Merged \"%s\" into \"%s\"."), $referrer, $new_name), 'horde.success'); $url = Wicked::url($new_name, true, -1); $message = sprintf(_("Merged \"%s\" into \"%s\". New page: %s\n"), $referrer, $new_name, $url); Wicked::mail($message, array('Subject' => '[' . $registry->get('name') . '] merged: ' . $referrer . ', ' . $new_name)); } else { // Rename the page. $wicked->renamePage($referrer, $new_name); $notification->push(sprintf(_("Renamed \"%s\" to \"%s\"."), $referrer, $new_name), 'horde.success'); $url = Wicked::url($new_name, true, -1); $message = sprintf(_("Renamed \"%s\" to \"%s\". New page: %s\n"), $referrer, $new_name, $url); Wicked::mail($message, array('Subject' => '[' . $registry->get('name') . '] renamed: ' . $referrer . ', ' . $new_name)); } $wikiWord = '/^' . Wicked::REGEXP_WIKIWORD . '$/'; // We don't check permissions on these pages since we want references // to be fixed even if the user doing the editing couldn't fix that // page, and fixing references is likely to never be a destructive // action, and the user can't supply their own data for it. $references = Horde_Util::getFormData('ref', array()); foreach ($references as $name => $value) { $page_name = quoted_printable_decode($name); // Fix up for self-references. if ($page_name == $referrer) { $page_name = $new_name; } try { $refPage = $wicked->retrieveByName($page_name); } catch (Wicked_Exception $e) { $notification->push(sprintf(_("Error retrieving %s: %s"), $page_name, $e->getMessage()), 'horde.error'); continue; } $changelog = sprintf(_("Changed references from %s to %s"), $referrer, $new_name); if (preg_match($wikiWord, $new_name)) { $replaceWith = $new_name; } else { $replaceWith = '((' . $new_name . '))'; } $from = array('/\\(\\(' . preg_quote($referrer, '/') . '\\)\\)/'); $to = array($replaceWith); // If this works as a bare wiki word, replace that, too. if (preg_match($wikiWord, $referrer)) { $from[] = '/\\b' . preg_quote($referrer, '/') . '\\b/'; $to[] = $replaceWith; } $newText = preg_replace($from, $to, $refPage['page_text']); $wicked->updateText($page_name, $newText, $changelog); } Wicked::url($new_name, true)->redirect(); }
public function pageUrl($linkpage = null, $actionId = null) { $params = array('page' => $this->pageName()); if ($this->referrer()) { $params['referrer'] = $this->referrer(); } if ($actionId) { $params['actionID'] = $actionId; } if (!$linkpage) { $url = Wicked::url($this->pageName()); unset($params['page']); } else { $url = Horde::url($linkpage); } return $url->add($params); }
/** * Retrieves the form fields and processes the attachment. */ public function handleAction() { global $notification, $wicked, $registry, $conf; // Only allow POST commands. $cmd = Horde_Util::getPost('cmd'); $version = Horde_Util::getFormData('version'); $is_update = (bool) Horde_Util::getFormData('is_update'); $filename = Horde_Util::getFormData('filename'); $change_log = Horde_Util::getFormData('change_log'); // See if we're supposed to delete an attachment. if ($cmd == 'delete' && $filename && $version) { if (!$this->allows(Wicked::MODE_REMOVE)) { $notification->push(_("You do not have permission to delete attachments from this page."), 'horde.error'); return; } try { $wicked->removeAttachment($wicked->getPageId($this->referrer()), $filename, $version); $notification->push(sprintf(_("Successfully deleted version %s of \"%s\" from \"%s\""), $version, $filename, $this->referrer()), 'horde.success'); } catch (Wicked_Exception $e) { $notification->push($result->getMessage(), 'horde.error'); } return; } if (empty($filename)) { $filename = Horde_Util::dispelMagicQuotes($_FILES['attachment_file']['name']); } try { $GLOBALS['browser']->wasFileUploaded('attachment_file', _("attachment")); } catch (Horde_Browser_Exception $e) { $notification->push($e, 'horde.error'); return; } if (strpos($filename, ' ') !== false) { $notification->push(_("Attachments with spaces can't be embedded into a page."), 'horde.warning'); } $data = file_get_contents($_FILES['attachment_file']['tmp_name']); if ($data === false) { $notification->push(_("Can't read uploaded file."), 'horde.error'); return; } if (!$this->allows(Wicked::MODE_EDIT)) { $notification->push(sprintf(_("You do not have permission to edit \"%s\""), $this->referrer()), 'horde.error'); return; } if ($conf['wicked']['require_change_log'] && empty($change_log)) { $notification->push(_("You must enter a change description to attach this file."), 'horde.error'); return; } $referrer_id = $wicked->getPageId($this->referrer()); try { $attachments = $wicked->getAttachedFiles($referrer_id); } catch (Wicked_Exception $e) { $notification->push(sprintf(_("Error retrieving attachments: %s"), $e->getMessage()), 'horde.error'); return; } $found = false; foreach ($attachments as $attach) { if ($filename == $attach['attachment_name']) { $found = true; break; } } if ($is_update) { if (!$found) { $notification->push(sprintf(_("Can't update \"%s\": no such attachment."), $filename), 'horde.error'); return; } } else { if ($found) { $notification->push(sprintf(_("There is already an attachment named \"%s\"."), $filename), 'horde.error'); return; } } $file = array('page_id' => $referrer_id, 'attachment_name' => $filename, 'change_log' => $change_log); try { $wicked->attachFile($file, $data); } catch (Wicked_Exception $e) { $notification->push($e); Horde::log($e); throw $e; } if ($is_update) { $message = sprintf(_("Updated attachment \"%s\" on page \"%s\"."), $filename, $this->referrer()); } else { $message = sprintf(_("New attachment \"%s\" to page \"%s\"."), $filename, $this->referrer()); } $notification->push($message, 'horde.success'); $url = Wicked::url($this->referrer(), true, -1); Wicked::mail($message . ' ' . _("View page: ") . $url . "\n", array('Subject' => '[' . $registry->get('name') . '] attachment: ' . $this->referrer() . ', ' . $filename)); }
if ($page->allows(Wicked::MODE_HISTORY)) { /* Redirect to history page. */ Horde::url('history.php')->add('page', $page->pageName())->redirect(); } $notification->push(_("This page does not have a history"), 'horde.error'); break; case 'special': $page->handleAction(); break; case 'export': if (!$page->allows(Wicked::MODE_DISPLAY)) { $notification->push(_("You don't have permission to view this page."), 'horde.error'); if ($page->pageName() == 'Wiki/Home') { throw new Horde_Exception(_("You don't have permission to view this page.")); } Wicked::url('Wiki/Home', true)->redirect(); } switch (Horde_Util::getGet('format')) { case 'html': $format = 'Xhtml'; $ext = '.html'; $mime = 'text/html'; break; case 'tex': $format = 'Latex'; $ext = '.tex'; $mime = 'text/x-tex'; break; case 'rst': $format = 'Rst'; $ext = '';
/** * @throws Wicked_Exception */ public function updateText($newtext, $changelog) { $version = $this->version(); $result = $GLOBALS['wicked']->updateText($this->pageName(), $newtext, $changelog); $url = Wicked::url($this->pageName(), true, -1); $new_page = $this->getPage($this->pageName()); $message = "Modified page: {$url}\n" . 'New Revision: ' . $new_page->version() . "\n" . ($changelog ? 'Change log: ' . $changelog . "\n" : '') . "\n" . $new_page->getDiff($version); Wicked::mail($message, array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] changed: ' . $this->pageName())); $this->_page['page_text'] = $newtext; }
/** * Returns the list of a page's sub pages. * * @param string $name A page name with slashes for directory separators. * * @return string A list of sub pages. */ public function subPages($name) { $children = array(); foreach ($this->_getSubPages($name) as $page) { $name = $page['page_name']; $children[$name] = '<li>' . Wicked::url($name)->link() . $this->h($name) . '</a></li>'; } if (!$children) { return ''; } uksort($children, 'strcoll'); return '<ul>' . implode('', $children) . '</ul>'; }
public function handleAction() { global $notification, $conf; $page = Wicked_Page::getPage($this->referrer()); if (!$this->allows(Wicked::MODE_EDIT)) { $notification->push(sprintf(_("You don't have permission to edit \"%s\"."), $page->pageName())); } else { if (!empty($GLOBALS['conf']['wicked']['captcha']) && !$GLOBALS['registry']->getAuth() && Horde_String::lower(Horde_Util::getFormData('wicked_captcha')) != Horde_String::lower(Wicked::getCAPTCHA())) { $notification->push(_("Random string did not match."), 'horde.error'); return; } $text = Horde_Util::getFormData('page_text'); $changelog = Horde_Util::getFormData('changelog'); if ($conf['wicked']['require_change_log'] && empty($changelog)) { $notification->push(_("You must provide a change log."), 'horde.error'); $GLOBALS['page_output']->addInlineScript(array('if (document.editform && document.editform.changelog) document.editform.changelog.focus()'), true); return; } if (trim($text) == trim($page->getText())) { $notification->push(_("No changes made"), 'horde.warning'); } else { $page->updateText($text, $changelog); $notification->push(_("Page Saved"), 'horde.success'); } if ($page->allows(Wicked::MODE_UNLOCKING)) { $page->unlock(); } } // Show the newly saved page. Wicked::url($this->referrer(), true)->redirect(); }
* to be non-empty. */ if (!$v1 && !$v2) { Horde::url('history.php', true)->add('page', Horde_Util::getFormData('page'))->redirect(); } /* Make sure that $v2 is a higher version than $v1. Empty string is * the current version of the page, so is always highest. Also, '?' is a * wildcard for the previous version, so it's always the lowest. */ if (!$v1 || $v2 && version_compare($v1, $v2) > 0 || $v2 == '?') { $tmp = $v1; $v1 = $v2; $v2 = $tmp; } try { $page = Wicked_Page::getPage(Horde_Util::getFormData('page'), $v2); } catch (Wicked_Exception $e) { $notification->push(sprintf(_("Internal error viewing requested page: %s"), $e->getMessage()), 'horde.error'); Wicked::url('Wiki/Home', true)->redirect(); } if ($v1 == '?') { $v1 = $page->previousVersion(); } /* Kick back to the display page if we're not allowed to diff this * page. */ if (!$page->allows(Wicked::MODE_DIFF)) { Wicked::url($page->pageName(), true)->add('actionID', 'diff')->redirect(); } Wicked::setTopbar(); $page_output->header(array('title' => sprintf(_("Diff for %s between %s and %s"), $page->pageName(), $v1, $page->version()))); $notification->notify(array('listeners' => 'status')); $page->render(Wicked::MODE_DIFF, $v1); $page_output->footer();
public function handleAction() { global $notification, $wicked; if (!$this->allows(Wicked::MODE_EDIT)) { $notification->push(sprintf(_("You don't have permission to create \"%s\"."), $this->referrer())); } else { if (!empty($GLOBALS['conf']['wicked']['captcha']) && !$GLOBALS['registry']->getAuth() && Horde_String::lower(Horde_Util::getFormData('wicked_captcha')) != Horde_String::lower(Wicked::getCAPTCHA())) { $notification->push(_("Random string did not match."), 'horde.error'); return; } $text = Horde_Util::getPost('page_text'); if (empty($text)) { $notification->push(_("Pages cannot be empty."), 'horde.error'); return; } try { $result = $wicked->newPage($this->referrer(), $text); $notification->push(_("Page Created"), 'horde.success'); } catch (Wicked_Exception $e) { $notification->push(sprintf(_("Create Failed: %s"), $e->getMessage()), 'horde.error'); } } // Show the newly created page. Wicked::url($this->referrer(), true)->redirect(); }
/** * Creates a new page. * * @param string $pagename The new page's name. * @param string $text The new page's text. * * @throws Wicked_Exception */ public function newPage($pagename, $text) { if (!strlen($pagename)) { throw new Wicked_Exception(_("Page name must not be empty")); } if ($GLOBALS['browser']->isRobot()) { throw new Wicked_Exception(_("Robots are not allowed to create pages")); } $author = $GLOBALS['registry']->getAuth(); if ($author === false) { $author = null; } /* Attempt the insertion/update query. */ try { $page_id = $this->_db->insert('INSERT INTO ' . $this->_params['table'] . ' (page_name, page_text, version_created, page_version,' . ' page_hits, change_author) VALUES (?, ?, ?, 1, 0, ?)', array($this->_convertToDriver($pagename), $this->_convertToDriver($text), time(), $author)); } catch (Horde_Db_Exception $e) { throw new Wicked_Exception($e); } /* Send notification. */ $url = Wicked::url($pagename, true, -1); Wicked::mail("Created page: {$url}\n\n{$text}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] created: ' . $pagename)); /* Call getPages with no caching so that the new list of pages is * read in. */ $this->getPages(true, true); return $page_id; }