<commit_before><?php

$s['head'] = 'Admin page editor';
$s['description'] = 'Admin page editor.';

import_lib('common/admin');
if (is_null($s['admin']))
    return;

import_lib('interactive/Form');

$s['suburl'] = array('id');

$form = new Form();
$id = find_value('id');
$section_count = 0;
$sections = array();
if (isset($id)) {
    $id = (int)$id;
    $data = array();
    $result = query("SELECT * FROM `" . prefix('page') . "` WHERE `id`=$id LIMIT 1");
    if ($row = $result->fetch_array())
        $data = $row;
    $result = query("SELECT * FROM `" . prefix('content') . "` WHERE `page`=$id ORDER BY `ranking`");
    $section_count = $result->num_rows;
    if ($section_count == 0) {
        $data['section_0'] = '';
        query("INSERT INTO `" . prefix('content') . "` SET `page`=$id, `content`=''");
        $section_count++;
    }
    $i = 0;
    while ($row = $result->fetch_array()) {
        $sections[] = $row;
        $data['section_' . $i++] = $row['content'];
    }
    $form->setData($data);
}
$wanted = 1;
$form->add('URL', 'text', 'page', false);
$form->add('Short title', 'text', 'short_title', false);
$form->add('Head', 'text', 'head', false);
for ($i = 0; $i < $wanted; $i++)
    $form->add('Section ' . ($i + 1), 'textarea', 'section_' . $i, false);
$form->add('Title', 'text', 'title', false);
$form->add('Description', 'text', 'description', false);
if (isset($id))
    $form->add($id, 'hidden', 'id');
$form->add('Save', 'submit');
$form->add('Save and return', 'submit', 'return');
if ($form->received() && $form->check()) {
    $page = secure($form->get('page'));
    $head = secure($form->get('head'));
    $title = secure($form->get('title'));
    $short_title = secure($form->get('short_title'));
    $description = secure($form->get('description'));
    $query = " `" . prefix('page') . "` SET `page`='$page', `head`='$head', `title`='$title', `short_title`='$short_title', `description`='$description'";
    $insert = $wanted - $section_count;
    if ($section_count > $wanted) {
        $delete = -$insert;
        query("DELETE FROM `" . prefix('content') . "` WHERE `page`=$id ORDER BY `ranking` DESC, `id` DESC LIMIT $delete");
        $insert = 0;
    }
    $edit = $section_count;<commit_msg>Disallow staying when adding instead of editing<commit_after><?php

$s['head'] = 'Admin page editor';
$s['description'] = 'Admin page editor.';

import_lib('common/admin');
if (is_null($s['admin']))
    return;

import_lib('interactive/Form');

$s['suburl'] = array('id');

$form = new Form();
$id = find_value('id');
$section_count = 0;
$sections = array();
if (isset($id)) {
    $id = (int)$id;
    $data = array();
    $result = query("SELECT * FROM `" . prefix('page') . "` WHERE `id`=$id LIMIT 1");
    if ($row = $result->fetch_array())
        $data = $row;
    $result = query("SELECT * FROM `" . prefix('content') . "` WHERE `page`=$id ORDER BY `ranking`");
    $section_count = $result->num_rows;
    if ($section_count == 0) {
        $data['section_0'] = '';
        query("INSERT INTO `" . prefix('content') . "` SET `page`=$id, `content`=''");
        $section_count++;
    }
    $i = 0;
    while ($row = $result->fetch_array()) {
        $sections[] = $row;
        $data['section_' . $i++] = $row['content'];
    }
    $form->setData($data);
}
$wanted = 1;
$form->add('URL', 'text', 'page', false);
$form->add('Short title', 'text', 'short_title', false);
$form->add('Head', 'text', 'head', false);
for ($i = 0; $i < $wanted; $i++)
    $form->add('Section ' . ($i + 1), 'textarea', 'section_' . $i, false);
$form->add('Title', 'text', 'title', false);
$form->add('Description', 'text', 'description', false);
if (isset($id)) {
    $form->add($id, 'hidden', 'id');
    $form->add('Save', 'submit');
}
$form->add('Save and return', 'submit', 'return');
if ($form->received() && $form->check()) {
    $page = secure($form->get('page'));
    $head = secure($form->get('head'));
    $title = secure($form->get('title'));
    $short_title = secure($form->get('short_title'));
    $description = secure($form->get('description'));
    $query = " `" . prefix('page') . "` SET `page`='$page', `head`='$head', `title`='$title', `short_title`='$short_title', `description`='$description'";
    $insert = $wanted - $section_count;
    if ($section_count > $wanted) {
        $delete = -$insert;
        query("DELETE FROM `" . prefix('content') . "` WHERE `page`=$id ORDER BY `ranking` DESC, `id` DESC LIMIT $delete");
        $insert = 0;
    }
    $edit = $section_count;
{'fraction_non_alphanumeric': 0.256092157731502, 'fraction_numerical': 0.003987594151528578, 'mean_word_length': 3.8496240601503757, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '900055', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1558, 'n_words': 347}