Gazelle/sections/wiki/takecreate.php

69 lines
1.8 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
2013-04-20 08:01:01 +00:00
$P = array();
$P = db_array($_POST);
2011-03-28 14:21:28 +00:00
2013-05-27 08:00:58 +00:00
include(SERVER_ROOT.'/classes/validate.class.php');
2011-03-28 14:21:28 +00:00
$Val = new VALIDATE;
2013-11-05 08:01:12 +00:00
$Val->SetFields('title', '1', 'string', 'The title must be between 3 and 100 characters', array('maxlength' => 100, 'minlength' => 3));
//$Val->SetFields('alias', '1', 'string', 'Please include at least 1 alias, the entire string should be between 2 and 100 characters.', array('maxlength' => 100, 'minlength' => 2));
2011-03-28 14:21:28 +00:00
$Err = $Val->ValidateForm($_POST);
2013-04-20 08:01:01 +00:00
if (!$Err) {
2013-06-06 08:01:03 +00:00
$DB->query("
SELECT ID
FROM wiki_articles
2013-11-05 08:01:12 +00:00
WHERE Title = '$P[title]'");
2013-07-10 00:08:53 +00:00
if ($DB->has_results()) {
2011-03-28 14:21:28 +00:00
list($ID) = $DB->next_record();
2012-09-09 08:00:26 +00:00
$Err = 'An article with that name already exists <a href="wiki.php?action=article&amp;id='.$ID.'">here</a>.';
2011-03-28 14:21:28 +00:00
}
}
2013-04-20 08:01:01 +00:00
if ($Err) {
2011-03-28 14:21:28 +00:00
error($Err);
}
2013-04-20 08:01:01 +00:00
if (check_perms('admin_manage_wiki')) {
$Read = $_POST['minclassread'];
$Edit = $_POST['minclassedit'];
if (!is_number($Read)) {
error(0); //int?
}
if (!is_number($Edit)) {
error(0);
}
if ($Edit > $LoggedUser['EffectiveClass']) {
error('You can\'t restrict articles above your own level');
}
if ($Edit < $Read) {
$Edit = $Read; //Human error fix.
}
2011-03-28 14:21:28 +00:00
} else {
2013-06-06 08:01:03 +00:00
$Read = 100;
$Edit = 100;
2011-03-28 14:21:28 +00:00
}
2013-06-06 08:01:03 +00:00
$DB->query("
INSERT INTO wiki_articles
(Revision, Title, Body, MinClassRead, MinClassEdit, Date, Author)
VALUES
('1', '$P[title]', '$P[body]', '$Read', '$Edit', '".sqltime()."', '$LoggedUser[ID]')");
2011-03-28 14:21:28 +00:00
$ArticleID = $DB->inserted_id();
2013-12-24 08:00:55 +00:00
$TitleAlias = Wiki::normalize_alias($_POST['title']);
$Dupe = Wiki::alias_to_id($_POST['title']);
if ($TitleAlias != '' && $Dupe === false) {
2013-06-06 08:01:03 +00:00
$DB->query("
INSERT INTO wiki_aliases (Alias, ArticleID)
VALUES ('".db_string($TitleAlias)."', '$ArticleID')");
2013-12-24 08:00:55 +00:00
Wiki::flush_aliases();
2011-03-28 14:21:28 +00:00
}
2013-06-06 08:01:03 +00:00
Misc::write_log("Wiki article $ArticleID (".$_POST['title'].") was created by ".$LoggedUser['Username']);
2011-03-28 14:21:28 +00:00
2013-11-05 08:01:12 +00:00
header("Location: wiki.php?action=article&id=$ArticleID");