Example #1
0
 /**
  * ページデータをコピーする
  * 
  * @param int $id ページID
  * @param array $data コピーしたいデータ
  * @param array $expected 期待値
  * @param string $message テストが失敗した時に表示されるメッセージ
  * @dataProvider copyDataProvider
  */
 public function testCopy($id, $data, $expected, $message = null)
 {
     $data = array('Page' => $data);
     $result = $this->Page->copy($id, $data);
     // コピーしたファイル存在チェック
     $path = getViewPath() . 'Pages' . $result['Page']['url'] . '.php';
     $this->assertFileExists($path, $message);
     @unlink($path);
     // DBに書き込まれているかチェック
     $exists = $this->Page->exists($result['Page']['id']);
     $this->assertTrue($exists);
 }
Example #2
0
 /**
  * ページデータをコピーする
  * 
  * @param int $id ページID
  * @param int $newParentId 新しい親コンテンツID
  * @param string $newTitle 新しいタイトル
  * @param int $newAuthorId 新しい作成者ID
  * @param int $newSiteId 新しいサイトID
  * @param string $message テストが失敗した時に表示されるメッセージ
  * @dataProvider copyDataProvider
  */
 public function testCopy($id, $newParentId, $newTitle, $newAuthorId, $newSiteId, $message = null)
 {
     $this->_loginAdmin();
     $result = $this->Page->copy($id, $newParentId, $newTitle, $newAuthorId, $newSiteId);
     // コピーしたファイル存在チェック
     $path = APP . 'View' . DS . 'Pages' . $result['Content']['url'] . '.php';
     $this->assertFileExists($path, $message);
     @unlink($path);
     // DBに書き込まれているかチェック
     $exists = $this->Page->exists($result['Page']['id']);
     $this->assertTrue($exists);
 }
Example #3
0
if ($_POST['source']) {
    // User provided input via HTTP request.
    $_REQUEST['source'] = pieCleanString($_REQUEST['source']);
    $_REQUEST['title'] = pieGetOption($_REQUEST['title']);
    $_REQUEST['comment'] = pieGetOption($_REQUEST['comment']);
} elseif (file_exists($preview)) {
    // Read source and meta data from temporary preview file.
    if (!($dump = file_get_contents($preview))) {
        pieError("SourceReadError");
    }
    $meta = pieExplodePage($dump);
    foreach (array('source', 'title', 'comment') as $i) {
        $_REQUEST[$i] = $meta[$i];
    }
    unset($meta);
} elseif ($page->exists($_REQUEST['page'])) {
    // The page already exists. Use and edit the existing source.
    $diff = new Increment();
    if (!($meta = $diff->readPage($_REQUEST['page'], $_REQUEST['stamp']))) {
        pieError("SourceVersionMissing");
    }
    $_REQUEST['source'] = $meta['source'];
    if ($_REQUEST['section'] > 0) {
        $section = new Section();
        // Extract the specified section.
        if (($_REQUEST['source'] = $section->extract($meta['source'], $_REQUEST['section'])) === false) {
            pieError('SectionNotFound');
        }
    }
    if ($meta['type'] == "alias") {
        // The existing page is an alias.
Example #4
0
        pieError('SourceWriteError');
    }
    fclose($f);
} elseif (file_exists($preview)) {
    // Read the data from the temporary preview file.
    if (!($dump = file_get_contents($preview))) {
        pieError("SourceReadError");
    }
    $meta = pieExplodePage($dump);
    $_REQUEST['source'] = trim($meta['source']);
} else {
    // No source available.
    pieError("SourceReadError");
}
// Handle partial updates.
if (@$_REQUEST['section'] > 0 && $page->exists(@$_REQUEST['page'])) {
    if (!$page->read($_REQUEST['page'], 0)) {
        pieError('SourceReadError');
    }
    if ($page->meta['type'] != 'full' && $page->meta['type'] != 'shadow') {
        pieError('SectionNotFound');
    }
    // Determine the text that come before and after the edited section.
    $section = new Section();
    if (($p = $section->offset($page->source, $_REQUEST['section'])) === false) {
        pieError('SectionNotFound');
    }
    if (($old = $section->extract($page->source, $_REQUEST['section'])) === false) {
        pieError('SectionNotFound');
    }
    $_REQUEST['source'] = substr($page->source, 0, $p) . rtrim($_REQUEST['source']) . "\n\n" . substr($page->source, $p + strlen($old));
Example #5
0
} elseif (@$_REQUEST['mode'] == "links") {
    // Walk all pages and examine their links.
    // Collect a list of _links_, i. e. destinations of broken links.
    $page = new Page();
    $file = new File();
    $deadpages = array();
    $deadfiles = array();
    for ($name = $page->first(); $name; $name = $page->next()) {
        if (!$page->read($name, 0)) {
            pieError("SourceReadError");
        }
        if ($page->meta['pages']) {
            // There are page links that are to be checked.
            $list = explode(" ", $page->meta['pages']);
            foreach ($list as $i) {
                if (!$page->exists($i)) {
                    $deadpages[$i]++;
                }
            }
        }
        if ($page->meta['files']) {
            // There are file links that are to be checked.
            $list = explode(" ", $page->meta['files']);
            foreach ($list as $i) {
                if (!$file->exists($i)) {
                    $deadfiles[$i]++;
                }
            }
        }
    }
    if (!count($deadpages) && !count($deadfiles)) {
Example #6
0
/*
 *	Display information about the current version of a page.
 */
include_once "{$lib}/class/page.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieHead();
$_REQUEST['page'] = pieGetOption(@$_REQUEST['page']);
$page = new Page();
$page->name = $_REQUEST['page'];
// Sanity check:
if (!$page->isValidName($_REQUEST['page'])) {
    pieError("PageNameInvalid");
}
if (!$page->exists($_REQUEST['page'])) {
    pieError("PageNotFound");
}
if (intval($_REQUEST['stamp']) > 0) {
    $stamp = $_REQUEST['stamp'];
} else {
    $stamp = 0;
}
$page->read($_REQUEST['page'], $stamp);
$stamp = $page->meta['stamp'];
// Check for alias:
if ($page->meta['type'] == "alias") {
    pieError("AliasRedirect", array('page' => htmlspecialchars($page->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
}
// Prepare output:
$data = array('page_count' => 0, 'file_count' => 0);
Example #7
0
     pieError("ImportError");
 }
 // Browse directory for the first time to check for pages
 // that already exist in the current name space.
 $total = 0;
 $count = 0;
 $page = new Page();
 while (($file = readdir($dh)) !== false) {
     if ($file == "." || $file == "..") {
         continue;
     }
     $name = decodeName($file);
     if (!$page->isValidName($name)) {
         pieError("InvalidName", array('page' => htmlspecialchars($name)));
     }
     if ($page->exists($name)) {
         pieError("PageExists", array('page' => htmlspecialchars($name)));
     }
     $total++;
 }
 // Walk directory for the second time. This time, encountered
 // files (and pages contained therein) are imported for real.
 rewinddir($dh);
 while (($file = readdir($dh)) !== false) {
     if ($file == "." || $file == "..") {
         continue;
     }
     if (!importFile($_REQUEST['path'] . "/{$file}")) {
         pieError("ImportError", array('page' => htmlspecialchars($file)));
     }
     $count++;
Example #8
0
 private function site_create_from_sitemap()
 {
     $db = DB::connect();
     $domain = parse_url($_POST['url'], PHP_URL_HOST);
     if (!Site::exists($domain)) {
         $pagerank = Google::get_pagerank($domain);
         $db->exec("INSERT INTO site VALUES('', '{$domain}', '{$pagerank}')");
     }
     if (!($xml = simplexml_load_file($_POST['url']))) {
         trigger_error('Unable to load sitemap at ' . $_POST['url'], E_USER_ERROR);
         header('HTTP/1.1 302 Found');
         header("Location: " . Options::get('base_url'));
         exit;
     }
     foreach ($xml->url as $url) {
         if (!Page::exists($url->loc)) {
             $db->exec("INSERT INTO page VALUES('', '{$url->loc}', '')");
             // @todo update page metrics
         }
     }
 }
Example #9
0
    // Read the source from a temporary preview file.
    if (!($meta = file_get_contents($preview))) {
        pieError("SourceReadError");
    }
    $meta = pieExplodePage($meta);
    foreach ($meta as $k => $v) {
        $_REQUEST[$k] = $v;
    }
} else {
    // No source available.
    pieError("SourceEmpty");
}
$_REQUEST['source'] = preg_replace('/\\x0a{3,}/s', "\n\n", @$_REQUEST['source']);
// Prepare the previous version for examination.
$current = new Page();
if ($page->exists($page->name)) {
    if (!$current->read($page->name, 0)) {
        pieError('SourceReadError');
    }
    if (trim($current->source) == $_REQUEST['source']) {
        // No changes have been made.
        pieError('NoChanges');
    }
}
// Handle section updates.
$_REQUEST['section'] = intval(@$_REQUEST['section']);
if ($_REQUEST['section'] > 0 && $page->exists($page->name)) {
    if ($current->meta['type'] == 'alias') {
        pieError('SectionNotFound');
    }
    // Determine the text chunks that come before and after the edited
Example #10
0
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.
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $resource = new File();
    $resource->name = $_REQUEST['file'];
Example #11
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 #12
0
    $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)) {
        pieError("FileNameInvalid");
    }
    if (!$object->exists($target)) {
 public static function onProtectionSave(Page $article, &$errorMsg)
 {
     global $wgUser, $wgRequest;
     if (!$article->exists()) {
         return true;
         // simple custom levels set for action=protect
     } elseif (!FlaggedRevs::inReviewNamespace($article->getTitle())) {
         return true;
         // not a reviewable page
     } elseif (wfReadOnly() || !$wgUser->isAllowed('stablesettings')) {
         return true;
         // user cannot change anything
     }
     $form = new PageStabilityProtectForm($wgUser);
     $form->setPage($article->getTitle());
     // target page
     $permission = $wgRequest->getVal('mwStabilityLevel');
     if ($permission == "none") {
         $permission = '';
         // 'none' => ''
     }
     $form->setAutoreview($permission);
     // protection level (autoreview restriction)
     $form->setWatchThis(null);
     // protection form already has a watch check
     $form->setReasonExtra($wgRequest->getText('mwProtect-reason'));
     // manual
     $form->setReasonSelection($wgRequest->getVal('wpProtectReasonSelection'));
     // dropdown
     $form->setExpiryCustom($wgRequest->getVal('mwStabilizeExpiryOther'));
     // manual
     $form->setExpirySelection($wgRequest->getVal('mwStabilizeExpirySelection'));
     // dropdown
     $form->ready();
     // params all set
     if ($wgRequest->wasPosted() && $form->isAllowed()) {
         $status = $form->submit();
         if ($status !== true) {
             $errorMsg = wfMsg($status);
             // some error message
         }
     }
     return true;
 }
Example #14
0
    $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)) {
        pieError("FileNameInvalid");
    }
    if (!$object->exists($source)) {
Example #15
0
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");
    }
    $context = "file";
} else {
    pieError("ActionInvalid");
Example #16
0
<?php

$res->edit = true;
if (isset($id) && Page::exists($id)) {
    $page = Page::find($id);
    $res->title = $page->title;
    $res->content = $page->content;
    $res->id = $page->id;
    if (isset($page->activity_id) && $page->activity_id > 0) {
        $res->edit = $res->user->id == $page->user_id;
    } else {
        $res->edit = 2;
    }
} else {
    $res->title = "";
    $res->content = "";
    $res->id = "";
}
if (isset($activity) && is_numeric($activity) && $res->user->id == Activity::find($activity)->id) {
    $res->activity = $activity;
}
$res->useTemplate();
Example #17
0
<?php

list($name, $representation) = name_and_representation_in_url();
$page = new Page($name);
$page_exists = $page->exists();
// Don't allow unsafe page names
if (!$page->has_safe_name()) {
    header('HTTP/1.0 404 Not Found');
    exit('The page name can only contain dashes, dots and alphanumerical characters.');
}
// /{pagename}.{representation}
if ($representation != '') {
    if (!$page_exists) {
        header('HTTP/1.0 404 Not Found');
        die("Page not found: <a href=" . EDITH_URI . "/" . $page->name . ">Create me!</a>");
    }
    if (!in_array($representation, $REPRESENTATIONS)) {
        header('HTTP/1.0 404 Not Found');
        die('Representation can only be one of: ' . implode($REPRESENTATIONS, ', '));
    }
    switch ($_SERVER['REQUEST_METHOD']) {
        case 'GET':
        case 'HEAD':
            $page->load();
            require "templates/{$representation}.php";
            exit;
        case 'POST':
        case 'PUT':
        case 'PATCH':
        case 'DELETE':
            header('HTTP/1.0 405 Method Not Allowed');
Example #18
0
    $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;
        }
        printOutput($output);
    }
}
// No cache available:
if (!$page->exists($string)) {
    // Requested page does not exist.
    // Try to find a page that looks, i. e. spells, similarly.
    pieHead();
    $data = array();
    for ($name = $page->first(); $name; $name = $page->next()) {
        if (stristr($name, $string)) {
            $data[] = $name;
        } elseif (stristr($string, $name)) {
            $data[] = $name;
        } elseif (levenshtein($string, $name) < 3) {
            $data[] = $name;
        }
    }
    if (!count($data)) {
        pieNotice('PageNotFound');