Example #1
0
<?php

/*
 *	Cancel editing a page.
 */
include_once "{$lib}/class/page.php";
include_once "{$lib}/class/session.php";
include_once "{$lib}/class/locale.php";
include_once "{$lib}/share/auth.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/storage.php";
pieRequireUser();
pieHead();
$_REQUEST['page'] = pieGetOption(@$_REQUEST['page']);
$preview = pieTempName("_preview");
// Check permission:
$page = new Page();
if (!$page->isValidName(@$_REQUEST['page'])) {
    pieError("PageNameInvalid");
}
$page->name = $_REQUEST['page'];
if (!$page->lock($GLOBALS['pie']['user'])) {
    pieError("PageLockError");
}
// Clean up what has been set up while editing:
if (file_exists($preview)) {
    unlink($preview);
}
$page->unlock($GLOBALS['pie']['user']);
pieNotice("Cancelation");
pieTail();
Example #2
0
include_once "{$lib}/share/string.php";
include_once "{$lib}/compiler/html.php";
pieLoadLocale();
pieRequireUser();
pieHead("edit");
$_REQUEST['page'] = pieBeautifyName(pieGetOption(@$_REQUEST['page']));
$_REQUEST['section'] = intval(@$_REQUEST['section']);
$_REQUEST['stamp'] = intval(@$_REQUEST['stamp']);
if ($_REQUEST['stamp'] < 1) {
    $_REQUEST['stamp'] = 0;
}
$page = new Page();
$page->name = $_REQUEST['page'];
$preview = pieTempName("_preview");
// Check validity.
if (!$page->isValidName($page->name)) {
    pieError("PageNameInvalid");
}
if (!$page->lock($GLOBALS['pie']['user'])) {
    pieError("PageLockError");
}
// Prepare editing environment.
if ($GLOBALS['pie']['edit_timeout']) {
    pieExpireDirectory($GLOBALS['pie']['run_path'] . "/temp", $GLOBALS['pie']['edit_timeout']);
}
$_REQUEST['cols'] = 80;
$_REQUEST['rows'] = 20;
$_REQUEST['author'] = $GLOBALS['pie']['user'];
$pref = new UserPref();
if (($t = $pref->read($GLOBALS['pie']['user'], "cols")) !== false) {
    $_REQUEST['cols'] = $t;
Example #3
0
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieLoadLocale();
if (@$_REQUEST['create']) {
    pieRequireUser();
}
pieHead();
// Determine the state of operation depending on the provided input.
unset($original);
unset($alias);
if (@$_REQUEST['page']) {
    $_REQUEST['page'] = pieGetOption($_REQUEST['page']);
    $original = $_REQUEST['page'];
    $resource = new Page();
    if (!$resource->isValidName($original)) {
        pieError("PageNameInvalid");
    }
    $context = 'page';
} elseif (@$_REQUEST['file']) {
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $original = $_REQUEST['file'];
    $resource = new File();
    if (!$resource->isValidName($original)) {
        pieError("FileNameInvalid");
    }
    $context = 'file';
} else {
    pieError("ActionInvalid");
}
// Verify the alias:
Example #4
0
 *	Display the history of a page.
 */
include_once "{$lib}/class/locale.php";
include_once "{$lib}/class/page.php";
include_once "{$lib}/class/file.php";
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieLoadLocale();
pieHead();
if (@$_REQUEST['page']) {
    // Preparations for pages.
    $_REQUEST['page'] = pieGetOption($_REQUEST['page']);
    $resource = new Page();
    $resource->name = $_REQUEST['page'];
    if (!$resource->isValidName($_REQUEST['page'])) {
        pieError("PageNameInvalid");
    }
    if (!$resource->exists($_REQUEST['page'])) {
        pieError("PageNotFound");
    }
    if (!$resource->read($_REQUEST['page'], 0)) {
        pieError("SourceReadError");
    }
    if ($resource->meta['type'] == "alias") {
        pieError("AliasRedirect", array('page' => htmlspecialchars($resource->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
    }
    $context = 'page';
    $history = $resource->history($_REQUEST['page']);
} elseif (@$_REQUEST['file']) {
    // Preparations for files.
Example #5
0
 function writePage($name, $meta)
 {
     if (!$meta['stamp']) {
         $meta['stamp'] = time();
     }
     $page = new Page();
     if (!$page->isValidName($name)) {
         return false;
     }
     if (!$page->exists($name)) {
         return $this->_writeFullSource($name, $meta);
     }
     // Determine the current diff level.
     $work = $meta;
     $work['parent'] = 0;
     for ($level = 0; $work['type'] != 'full'; $level++) {
         if (!$page->read($name, $work['parent'])) {
             return false;
         }
         $work = $page->meta;
     }
     $max = intval($GLOBALS['pie']['max_diff_level']);
     if ($max > 0 && $level > $max) {
         return $this->_writeFullSource($name, $meta);
     }
     // Determine the version to be referred to as parent.
     if (!($current = $this->readPage($name, 0))) {
         return false;
     }
     $meta['parent'] = $current['stamp'];
     // Create a diff between the latest version and the new one.
     if (!($diff = $this->diff($current['source'], $meta['source']))) {
         return false;
     }
     if (strlen($meta['source']) - strlen($diff) < 100) {
         // The diff is not much smaller (or even larger)
         // than the original source.
         // Write a full version instead of just a diff.
         unset($meta['parent']);
         return $this->_writeFullSource($name, $meta);
     }
     // Note:
     // At this stage, it is decided to write a diff instead
     // of a full version.
     // If the current page is an alias, delete it altogether,
     // to be replaced by a real page with the current data.
     if ($current['type'] == 'alias') {
         if (!$page->delete($name)) {
             return false;
         }
     }
     // Replace the latest shadow, if any.
     $replace = false;
     if ($current['type'] == 'shadow') {
         $replace = true;
     }
     // Write a diff.
     $page->name = $name;
     $page->source = $diff;
     $full = $meta['source'];
     unset($meta['source']);
     $meta['type'] = 'diff';
     $page->meta = $meta;
     if (!$page->write($replace)) {
         return false;
     }
     // Create an additional shadow record including the full source.
     $page->source = $full;
     $page->meta['type'] = 'shadow';
     return $page->write(false);
 }
Example #6
0
pieHead();
if (@$_REQUEST['page'] && !@$_REQUEST['file']) {
    $_REQUEST['page'] = pieGetOption($_REQUEST['page']);
    $target = $_REQUEST['page'];
    $context = "page";
} elseif (@$_REQUEST['file'] && !@$_REQUEST['page']) {
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $target = $_REQUEST['file'];
    $context = "file";
} else {
    pieError("ActionInvalid");
}
// Page or file?
if ($context == "page") {
    $object = new Page();
    if (!$object->isValidName($target)) {
        pieError("PageNameInvalid");
    }
    if (!$object->exists($target)) {
        pieError("PageNotFound");
    }
    if (!$object->read($target, 0)) {
        pieError("SourceReadError");
    }
    // Lock the page.
    if (!$object->lock($GLOBALS['pie']['user'])) {
        pieError("PageLockError");
    }
} elseif ($context == "file") {
    $object = new File();
    if (!$object->isValidName($target)) {
Example #7
0
pieHead("edit");
if (@$_REQUEST['page'] && !@$_REQUEST['file']) {
    $_REQUEST['page'] = pieGetOption($_REQUEST['page']);
    $source = $_REQUEST['page'];
    $context = "page";
} elseif (@$_REQUEST['file'] && !@$_REQUEST['page']) {
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $source = $_REQUEST['file'];
    $context = "file";
} else {
    pieError("ActionInvalid");
}
// Validate the source: page or file?
if ($context == "page") {
    $object = new Page();
    if (!$object->isValidName($source)) {
        pieError("PageNameInvalid");
    }
    if (!$object->exists($source)) {
        pieError("PageNotFound");
    }
    if (!$object->read($source, 0)) {
        pieError("SourceReadError");
    }
    // Lock the page.
    if (!$object->lock($GLOBALS['pie']['user'])) {
        pieError("PageLockError");
    }
} elseif ($context == "file") {
    $object = new File();
    if (!$object->isValidName($source)) {
Example #8
0
 *	Display a list of pages that refer to the specified resource.
 */
include_once "{$lib}/class/file.php";
include_once "{$lib}/class/page.php";
include_once "{$lib}/class/locale.php";
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
include_once "{$lib}/share/referers.php";
pieLoadLocale();
pieHead();
// Verify the input.
if (@$_REQUEST['page'] && !@$_REQUEST['file']) {
    $resource = pieGetOption($_REQUEST['page']);
    $page = new Page();
    if (!$page->isValidName($resource)) {
        pieError("PageNameInvalid");
    }
    if (!$page->exists($resource)) {
        pieError("PageNotFound");
    }
    $context = "page";
} elseif (@$_REQUEST['file'] && !@$_REQUEST['page']) {
    $resource = pieGetOption($_REQUEST['file']);
    $file = new File();
    if (!$file->isValidName($resource)) {
        pieError("FileNameInvalid");
    }
    if (!$file->exists($resource)) {
        pieError("FileNotFound");
    }
Example #9
0
    }
    pieTail();
    exit;
}
// Start here:
if (@$_REQUEST['string']) {
    $string = pieBeautifyName(pieGetOption($_REQUEST['string']));
    $_REQUEST['page'] = $string;
} elseif (@$_REQUEST['page']) {
    $string = pieBeautifyName(pieGetOption($_REQUEST['page']));
} else {
    pieHead();
    pieError("GotoForm");
}
$page = new Page();
if (!$page->isValidName($string)) {
    pieHead();
    pieError("PageNameInvalid");
}
if ($GLOBALS['pie']['page_caching']) {
    $cache = new Cache();
    $cid = $cache->key('page', array('page' => $string));
    if ($cache->exists($cid)) {
        $output = file_get_contents($cache->file($cid));
        pieHead();
        if ($_REQUEST['referer']) {
            $_REQUEST['page'] = $string;
            if (substr($output, 0, 3) == "<h1") {
                list($header, $output) = explode("\n", $output, 2);
            }
            $output = "{$header}\n" . getReferer() . $output;