74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* WikiNewPagePostHandler
|
|
*
|
|
* @package Panacea
|
|
* @subpackage Wiki
|
|
* @author Tommy Montgomery
|
|
* @since 2008-10-21
|
|
*/
|
|
|
|
/** Bootstraps the NowhereConcave framework */
|
|
require_once 'NowhereConcave/bootstrap.php';
|
|
|
|
/**
|
|
* Object for handling POST requests for creating a new page
|
|
*
|
|
* @package Panacea
|
|
* @subpackage Wiki
|
|
* @author Tommy Montgomery
|
|
* @since 2008-10-21
|
|
*/
|
|
class WikiNewPagePostHandler extends PostHandler {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* Creates a new wiki page and its first revision.
|
|
*
|
|
* @author Tommy Montgomery
|
|
* @since 2008-10-21
|
|
*
|
|
* @param DatabaseVendor $vendor Database connection
|
|
* @throws {@link InvalidTypeException}
|
|
* @return int
|
|
*/
|
|
public function execute(DatabaseVendor $vendor = null) {
|
|
if (!($vendor instanceof DatabaseVendor)) {
|
|
throw new InvalidTypeException(1, 'DatabaseVendor', $vendor);
|
|
}
|
|
|
|
if (!isset($this->data['wikitext'])) {
|
|
throw new InvalidPostDataException('wikitext', $this->data);
|
|
}
|
|
|
|
//create row in wiki.pages
|
|
$page = new WikiPage();
|
|
$fields = WikiPage::getFields($vendor);
|
|
foreach ($this->data as $key => $value) {
|
|
if (!isset($fields[$key])) {
|
|
continue;
|
|
}
|
|
|
|
settype($value, $fields[$key]['type']);
|
|
$page->$key = $value;
|
|
}
|
|
|
|
$page->created_user_id = 1;
|
|
$page->category_id = 1;
|
|
$pageId = $page->insert($vendor);
|
|
|
|
//create first revision in wiki.history
|
|
$history = new WikiHistory();
|
|
WikiHistory::getFields($vendor);
|
|
$history->page_id = $pageId;
|
|
$history->revision = 1;
|
|
$history->wikitext = $this->data['wikitext'];
|
|
$history->created_user_id = 1;
|
|
return $history->insert($vendor);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|