<commit_before><?php

// $Id: /cvsroot/tikiwiki/tiki/tiki-admin_structures.php,v 1.36.2.3 2008-03-19 01:44:52 luciash Exp $

// Copyright (c) 2002-2007, <NAME>, <NAME>, <NAME>, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.

// Initialization
$section = 'wiki page';
require_once ('tiki-setup.php');

include_once ('lib/structures/structlib.php');
include_once ('lib/categories/categlib.php');
include_once ("lib/ziplib.php");

if ($tiki_p_view != 'y') {
// This allows tiki_p_view in, in order to see structure tree - security hardening for editing features below.
	$smarty->assign('errortype', 401);
	$smarty->assign('msg', tra("You do not have permission to use this feature"));

	$smarty->display("error.tpl");
	die;
}

if($prefs['feature_wiki'] != 'y') {
    $smarty->assign('msg', tra('This feature is disabled').': feature_wiki');
    $smarty->display('error.tpl');
    die;  
}

if($prefs['feature_wiki_structure'] != 'y') {
    $smarty->assign('msg', tra('This feature is disabled').': feature_wiki_structure');
    $smarty->display('error.tpl');
    die;  
}

// start security hardened section
if ($tiki_p_edit_structures == 'y') {

if (isset($_REQUEST['rremove'])) {
  $area = 'delstruct';
  $structure_info = $structlib->s_get_structure_info($_REQUEST['rremove']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_edit', 'tiki_p_edit_categorized')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg', tra("Permission denied you cannot edit this page"));
		$smarty->display("error.tpl");
		die;		
	}
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
    key_check($area);
	$structlib->s_remove_page($_REQUEST["rremove"], false, empty($_REQUEST['page'])? '': $_REQUEST['page']);		
	} else {
		key_get($area);
	}
}

if (isset($_REQUEST['rremovex'])) {
  $area = 'delstructandpages';
  $structure_info = $structlib->s_get_structure_info($_REQUEST['rremovex']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_edit', 'tiki_p_edit_categorized')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg', tra("Permission denied you cannot edit this page"));
		$smarty->display("error.tpl");
		die;		
	}
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
    key_check($area);
	$structlib->s_remove_page($_REQUEST["rremovex"], true, empty($_REQUEST['page'])? '': $_REQUEST['page']);
	} else {
		key_get($area);
	}
}

if (isset($_REQUEST['export'])) {
	check_ticket('admin-structures');
	$structure_info = $structlib->s_get_structure_info($_REQUEST['export']);
	if ($prefs['feature_wiki_export'] != 'y' || $tiki_p_admin_wiki != 'y' || !$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_view')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg',tra('Permission denied you cannot view this page'));
		$smarty->display("error.tpl");
		die;
	}
	$structlib->s_export_structure($_REQUEST['export']);
}
if (isset($_REQUEST['zip']) && $tiki_p_admin == 'y') {
	check_ticket('admin-structures');
	include_once('lib/wiki/xmllib.php');
	$xmllib = new XmlLib();
	$zipFile = 'dump/xml.zip';
	$config['debug'] = false;
	if ($xmllib->export_pages(null, $_REQUEST['zip'], $zipFile, $config)) {
		if (!$config['debug']) {
			header("location: $zipFile");
			die;
		}
	} else {
		$smarty->assign('error', $xmllib->get_error());
	}
}

if (isset($_REQUEST['export_tree'])) {
	check_ticket('admin-structures');
	$structure_info = $structlib->s_get_structure_info($_REQUEST['export_tree']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_view')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg',tra('Permission denied you cannot view this page'));
		$smarty->display("error.tpl");
		die;
	}
	header ("content-type: text/plain");

	$structlib->s_export_structure_tree($_REQUEST['export_tree']);
	die;
}

$smarty->assign('askremove', 'n');

if (isset($_REQUEST['remove'])) {
	check_ticket('admin-structures');
	$structure_info = $structlib->s_get_structure_info($_REQUEST['remove']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_edit', 'tiki_p_edit_categorized')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg', tra("Permission denied you cannot edit this page"));
		$smarty->display("error.tpl");
		die;		
	}
	$smarty->assign('askremove', 'y');
	$smarty->assign('removename', $structure_info["pageName"]);
	$smarty->assign('remove', $_REQUEST['remove']);
}

$alert_in_st = array();
$alert_categorized = array();
$alert_to_remove_cats = array();
$alert_to_remove_extra_cats = array();
$smarty->assign('just_created', 'n');
if (isset($_REQUEST["create"])) {
	check_ticket('admin-structures');
	if ((empty($_REQUEST['name']))) {
		$smarty->assign('msg', tra("You must specify a page name, it will be created if it doesn't exist."));<commit_msg>[FIX]structure: to have some categories when creating a new structure<commit_after><?php

// $Id: /cvsroot/tikiwiki/tiki/tiki-admin_structures.php,v 1.36.2.3 2008-03-19 01:44:52 luciash Exp $

// Copyright (c) 2002-2007, <NAME>, <NAME>, <NAME>, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.

// Initialization
$section = 'wiki page';
require_once ('tiki-setup.php');

include_once ('lib/structures/structlib.php');
include_once ('lib/categories/categlib.php');
include_once ("lib/ziplib.php");

if ($tiki_p_view != 'y') {
// This allows tiki_p_view in, in order to see structure tree - security hardening for editing features below.
	$smarty->assign('errortype', 401);
	$smarty->assign('msg', tra("You do not have permission to use this feature"));

	$smarty->display("error.tpl");
	die;
}

if($prefs['feature_wiki'] != 'y') {
    $smarty->assign('msg', tra('This feature is disabled').': feature_wiki');
    $smarty->display('error.tpl');
    die;  
}

if($prefs['feature_wiki_structure'] != 'y') {
    $smarty->assign('msg', tra('This feature is disabled').': feature_wiki_structure');
    $smarty->display('error.tpl');
    die;  
}

// start security hardened section
if ($tiki_p_edit_structures == 'y') {

if (isset($_REQUEST['rremove'])) {
  $area = 'delstruct';
  $structure_info = $structlib->s_get_structure_info($_REQUEST['rremove']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_edit', 'tiki_p_edit_categorized')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg', tra("Permission denied you cannot edit this page"));
		$smarty->display("error.tpl");
		die;		
	}
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
    key_check($area);
	$structlib->s_remove_page($_REQUEST["rremove"], false, empty($_REQUEST['page'])? '': $_REQUEST['page']);		
	} else {
		key_get($area);
	}
}

if (isset($_REQUEST['rremovex'])) {
  $area = 'delstructandpages';
  $structure_info = $structlib->s_get_structure_info($_REQUEST['rremovex']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_edit', 'tiki_p_edit_categorized')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg', tra("Permission denied you cannot edit this page"));
		$smarty->display("error.tpl");
		die;		
	}
  if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
    key_check($area);
	$structlib->s_remove_page($_REQUEST["rremovex"], true, empty($_REQUEST['page'])? '': $_REQUEST['page']);
	} else {
		key_get($area);
	}
}

if (isset($_REQUEST['export'])) {
	check_ticket('admin-structures');
	$structure_info = $structlib->s_get_structure_info($_REQUEST['export']);
	if ($prefs['feature_wiki_export'] != 'y' || $tiki_p_admin_wiki != 'y' || !$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_view')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg',tra('Permission denied you cannot view this page'));
		$smarty->display("error.tpl");
		die;
	}
	$structlib->s_export_structure($_REQUEST['export']);
}
if (isset($_REQUEST['zip']) && $tiki_p_admin == 'y') {
	check_ticket('admin-structures');
	include_once('lib/wiki/xmllib.php');
	$xmllib = new XmlLib();
	$zipFile = 'dump/xml.zip';
	$config['debug'] = false;
	if ($xmllib->export_pages(null, $_REQUEST['zip'], $zipFile, $config)) {
		if (!$config['debug']) {
			header("location: $zipFile");
			die;
		}
	} else {
		$smarty->assign('error', $xmllib->get_error());
	}
}

if (isset($_REQUEST['export_tree'])) {
	check_ticket('admin-structures');
	$structure_info = $structlib->s_get_structure_info($_REQUEST['export_tree']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_view')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg',tra('Permission denied you cannot view this page'));
		$smarty->display("error.tpl");
		die;
	}
	header ("content-type: text/plain");

	$structlib->s_export_structure_tree($_REQUEST['export_tree']);
	die;
}

$smarty->assign('askremove', 'n');

if (isset($_REQUEST['remove'])) {
	check_ticket('admin-structures');
	$structure_info = $structlib->s_get_structure_info($_REQUEST['remove']);
	if (!$tikilib->user_has_perm_on_object($user,$structure_info["pageName"],'wiki page','tiki_p_edit', 'tiki_p_edit_categorized')) {
		$smarty->assign('errortype', 401);
		$smarty->assign('msg', tra("Permission denied you cannot edit this page"));
		$smarty->display("error.tpl");
		die;		
	}
	$smarty->assign('askremove', 'y');
	$smarty->assign('removename', $structure_info["pageName"]);
	$smarty->assign('remove', $_REQUEST['remove']);
}

$alert_in_st = array();
$alert_categorized = array();
$alert_to_remove_cats = array();
$alert_to_remove_extra_cats = array();
$cat_type='wiki page';
$cat_objid = '';
$smarty->assign('just_created', 'n');
if (isset($_REQUEST["create"])) {
	check_ticket('admin-structures');
	if ((empty($_REQUEST['name']))) {
		$smarty->assign('msg', tra("You must specify a page name, it will be created if it doesn't exist."));
{'fraction_non_alphanumeric': 0.20680728667305848, 'fraction_numerical': 0.009012464046021093, 'mean_word_length': 6.498921639108555, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4768346', 'n_tokens_mistral': 3821, 'n_tokens_neox': 3657, 'n_words': 657}