Author: Tyler Colbert (tyler@colberts.us)
Example #1
0
 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();
 }
Example #2
0
 /**
  * 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();
 }
Example #3
0
 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();
 }
Example #4
0
 /**
  * Returns the current user's permissions for the referring page.
  *
  * @return integer  The permissions bitmask.
  */
 public function getPermissions()
 {
     return parent::getPermissions($this->referrer());
 }
Example #5
0
 /**
  * Returns the page we are currently on.
  *
  * @return Wicked_Page  The current page.
  * @throws Wicked_Exception
  */
 public static function getCurrentPage()
 {
     return Wicked_Page::getPage(rtrim(Horde_Util::getFormData('page'), '/'), Horde_Util::getFormData('version'), Horde_Util::getFormData('referrer'));
 }
Example #6
0
 /**
  * Returns if the page allows a mode. Access rights and user state
  * are taken into consideration.
  *
  * @see $supportedModes
  *
  * @param integer $mode  The mode to check for.
  *
  * @return boolean  True if the mode is allowed.
  */
 public function allows($mode)
 {
     switch ($mode) {
         case Wicked::MODE_EDIT:
             if ($this->isLocked()) {
                 return Wicked::lockUser() == $this->_lock['lock_owner'];
             }
             break;
         case Wicked::MODE_LOCKING:
             if ($GLOBALS['browser']->isRobot()) {
                 return false;
             }
             if ($GLOBALS['registry']->isAdmin()) {
                 return true;
             }
             if (($this->getPermissions() & Horde_Perms::EDIT) == 0) {
                 return false;
             }
             break;
         case Wicked::MODE_UNLOCKING:
             if ($GLOBALS['registry']->isAdmin()) {
                 return true;
             }
             if ($this->_lock) {
                 return Wicked::lockUser() == $this->_lock['lock_owner'];
             }
             return false;
     }
     return parent::allows($mode);
 }
Example #7
0
            echo $text;
            exit;
        } catch (Wicked_Exception $e) {
            $notification->push($e);
        }
        break;
    default:
        $wicked->logPageView($page->pageName());
        break;
}
if (!$page->allows(Wicked::MODE_DISPLAY)) {
    if ($page->pageName() == 'Wiki/Home') {
        throw new Wicked_Exception(_("You don't have permission to view this page."));
    }
    $notification->push(_("You don't have permission to view this page."), 'horde.error');
    $page = Wicked_Page::getPage('');
}
$params = Horde_Util::getFormData('params', Horde_Util::getFormData('searchfield'));
$page->preDisplay(Wicked::MODE_DISPLAY, $params);
if ($page->isLocked()) {
    $notification->push(sprintf(_("This page is locked by %s for %d Minutes."), $page->getLockRequestor(), $page->getLockTime()), 'horde.message');
}
$history = $session->get('wicked', 'history', Horde_Session::TYPE_ARRAY);
Horde::startBuffer();
echo $page->render(Wicked::MODE_DISPLAY, $params);
$content = Horde::endBuffer();
Wicked::addFeedLink();
Wicked::setTopbar();
$page_output->header(array('title' => $page->pageTitle()));
$notification->notify(array('listeners' => 'status'));
echo $content;
Example #8
0
<?php

/**
 * Copyright 2004-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Chuck Hagenbuch <*****@*****.**>
 */
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('wicked');
if (!($text = Horde_Util::getFormData('page_text'))) {
    exit;
}
$view = $injector->createInstance('Horde_View');
$page = new Wicked_Page();
$view->text = $page->getProcessor()->transform($text);
Wicked::setTopbar();
$page_output->header(array('title' => sprintf(_("Edit %s"), Horde_Util::getFormData('age'))));
$notification->notify(array('listeners' => 'status'));
echo $view->render('edit/preview');
$page_output->footer();
Example #9
0
 /**
  */
 protected function _content()
 {
     $page = Wicked_Page::getPage($this->_params['page']);
     return $page->render(Wicked::MODE_BLOCK);
 }
Example #10
0
 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();
 }
Example #11
0
File: Api.php Project: horde/horde
 /**
  * Get the wiki source of a page specified by its name.
  *
  * @param string $name     The name of the page to fetch
  * @param string $version  Page version
  *
  * @return string  Page data.
  * @throws Wicked_Exception
  */
 public function getPageSource($pagename, $version = null)
 {
     global $wicked;
     $page = Wicked_Page::getPage($pagename, $version);
     if (!$page->allows(Wicked::MODE_CONTENT)) {
         throw new Wicked_Exception(_("Permission denied."));
     }
     if (!$page->isValid()) {
         throw new Wicked_Exception(_("Invalid page requested."));
     }
     return $page->getText();
 }
Example #12
0
File: diff.php Project: horde/horde
$v2 = Horde_Util::getFormData('v2');
/* Bail out if we didn't get any versions - at least one of these has
 * 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'));
Example #13
0
<?php

/**
 * Copyright 2003-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Tyler Colbert <*****@*****.**>
 */
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('wicked');
try {
    $page = Wicked_Page::getCurrentPage();
} catch (Wicked_Exception $e) {
    $notification->push(_("Internal error viewing requested page"), 'horde.error');
    Wicked::url('Wiki/Home', true)->redirect();
}
if (!$page->allows(Wicked::MODE_HISTORY)) {
    /* Redirect to display page and force it to display an error. */
    Wicked::url($page->pageName(), true)->add('actionID', 'history')->redirect();
}
Wicked::setTopbar();
$page_output->header(array('title' => sprintf(_("History: %s"), $page->pageName())));
$notification->notify(array('listeners' => 'status'));
echo $page->render(Wicked::MODE_HISTORY);
$page_output->footer();
Example #14
0
 /**
  * Renders this page in display mode.
  *
  * @throws Wicked_Exception
  */
 public function display()
 {
     $GLOBALS['page_output']->addScriptFile('edit.js');
     $view = $GLOBALS['injector']->createInstance('Horde_View');
     $view->action = Wicked::url('NewPage');
     $view->formInput = Horde_Util::formInput();
     $view->referrer = $this->referrer();
     if (!empty($GLOBALS['conf']['wicked']['captcha']) && !$GLOBALS['registry']->getAuth()) {
         $figlet = new Text_Figlet();
         Horde_Exception_Pear::catchError($figlet->loadFont($GLOBALS['conf']['wicked']['figlet_font']));
         $view->captcha = $figlet->lineEcho(Wicked::getCAPTCHA(true));
     }
     if ($this->_template) {
         $view->text = Wicked_Page::getPage($this->_template)->getText();
     }
     return $view->render('edit/new');
 }