Dictionary
Site Infrastructure / Dictionary

[read modes: view by_date search tools reverse]
[comment modes: add_entry add_tag inflection diachronics]
[edit modes: edit]

[begin mode inflection]
[
	search("manage", "parent", _id, "template", title2id("Inflection Scheme"));
	if(can_comment()) {
		<h2>Create new scheme</h2>
		[
			form(_id, "add_inflection", list(
				list("text", "title", "", "Name", "Name of the new scheme.")
			));
		]
	};
]
[end mode inflection]

[begin mode add_inflection]
[
	var $id = new_page(_params.title, _id);
	if($id) {
		[
			var e = import entry $id;
			e._template = title2id("Inflection Scheme");
			e._permissions = "cadrecadrecadre---r-";
			e._group = _group;
			refresh_to({./?id=[$id]}, 1);
		]
		Page creation successful. <a href="./?id=[$id]">Click here if you are not redirected</a>.
	} else {
		Page creation failed. <a href="./?id=[_id]&mode=inflection">Click here to go back</a>.
	};
]
[end mode add_inflection]

[begin mode diachronics]
[
	search("manage", "parent", _id, "template", title2id("Diachronic Scheme"));
	if(can_comment()) {
		<h2>Create new scheme</h2>
		[
			form(_id, "add_diachronics", list(
				list("text", "title", "", "Name", "Name of the new scheme.")
			));
		]
		<b>Diachronics support does not work yet. You may create schemes, but they do not do anything.</b>
	};
]
[end mode diachronics]

[begin mode add_diachronics]
[
	var $id = new_page(_params.title, _id);
	if($id) {
		[
			var e = import entry $id;
			e.template = title2id("Diachronic Scheme");
			e.permissions = "cadrecadrecadre---r-";
			refresh_to({./?id=[$id]}, 1);
		]
		Page creation successful. <a href="./?id=[$id]">Click here if you are not redirected</a>.
	} else {
		Page creation failed. <a href="./?id=[_id]&mode=diachronics">Click here to go back</a>.
	};
]
[end mode add_diachronics]

[begin mode reverse_blanks]
subpopulation: <a href="./?id=[_id]&mode=reverse_blanks">all</a>, <a href="./?id=[_id]&mode=reverse_blanks&set=1">easy</a>, <a href="./?id=[_id]&mode=reverse_blanks&set=2">medium</a>, <a href="./?id=[_id]&mode=reverse_blanks&set=0">hard</a><br>
[
o = retrieve("
	select a.num n, a.title t, a.c count
	from (select e.id num, title, count(d.id) c
	from `entries` e left join `data` d on e.id = d.id
	where e.parent = " & _id & "
	and e.template = " & title2id("Dictionary Entry") & "
	group by num) a where a.c = 0;
");
oc = count(o);
]

page: [

if(_params.page_num > 0) {<a href="./?id=[_id]&mode=reverse_blanks&page_num=[_params.page_num - 500]&set=[_params.set]">previous</a> };
if( (oc - (oc % 500)) > _params.page_num ) {<a href="./?id=[_id]&mode=reverse_blanks&page_num=[_params.page_num + 500]&set=[_params.set]">next</a> };

{<br>};

oc2 = 0;

o = slice(o, _params.page_num, 500);

o = process(o)
	(_data = page("reverse_simple", _data.n)) & (if(_data != "") oc2++);
]
<ol start="[_params.page_num]">[o]</ol>
<p>total count: [oc]</p>
<p>shown: [oc2]</p>
[if(trim("a" & o) == "a") "<p>Entries are indexed <i>before</i> filtering, so try checking another page if you have reason to believe this subpopulation shouldn't be empty.</p>";]
[end mode reverse_blanks]

[begin mode reverse]
[
if(_group != 0) {[
	gpid = get_group_profile_id(_group);
	if(gpid > 0) page("css", gpid);
]};

if(_params.term == "") {<div style="text-align: right; font-size: 80%"><a href="/?id=[_id]&mode=reverse_blanks">display entries with no reverse keywords</a></div><br><br>[
	override_title(_title, "Reverse Dictionary");
	override_parent({./?id=[_id]}, "normal listing of " & _title);

	concept_list = retrieve({
		select distinct(`name`) n from `data` d inner join `entries` e on d.id = e.id
			where e.parent = [_id]
			and e.template = [title2id("Dictionary Entry")]
			order by n
	});

	c = process(concept_list, " ") {[
		concept = _data.n;

		entries = retrieve({
			select e.* from `entries` e inner join `data` d on e.id = d.id
			where e.parent = [_id]
			and e.template = [title2id("Dictionary Entry")]
			and d.name = "[concept]"
			order by d.name
		});

		_data = "[b][/?id=" & _id & "&mode=reverse&term=" & concept & "|" & concept & "].[/b][style: display: block; margin-left: 20px; margin-bottom: 0px;]" & show("abbr", entries) & "[/style]";
	]};

	_wiki_format(c, "no toc");

]} else {[
	concept = _params.term;

	override_title(_title, "Reverse Lookup");
	override_parent({./?id=[_id]&mode=reverse}, "reverse listing of " & _title);

	entries = retrieve({
		select e.* from `entries` e inner join `data` d on e.id = d.id
		where e.parent = [_id]
		and e.template = [title2id("Dictionary Entry")]
		and d.name = "[concept]"
		order by d.name
	});

	{<h2>[concept].</h2>

	[show("view", entries, list("link"))]};
]};

]
[end mode reverse]

[begin mode tools]
[override_title(_title, "Tools and Utilities")]
<ul>
<li><b><a href="/?page=Dictionary Importer&dictionary=[_id]">import</a></b>: add words in bulk (from a spreadsheet or by hand)
<li><b><a href="/?id=[_id]&mode=export">export</a></b>: get a copy of the dictionary in importer format (also: sorted by date of <a href="/?id=[_id]&mode=export&sortby=id">creation</a> or <a href="/?id=[_id]&mode=export&sortby=id">last modification</a>)
<li><b><a href="/?id=[_id]&mode=export_headwords">export headwords</a></b>: get a bare list of headwords
<li><b><a href="/?id=[_id]&mode=fullview">full view</a></b>: view all words at once, normally formatted
<li><b><a href="/?id=[_id]&mode=printable">printable</a></b>: view all words at once in a printer-friendly format (this takes about 10 minutes per 1000 words, so go make a pot of tea)
<li><b><a href="/?page=Flash Cards&dict=[_id]">flash cards</a></b>: test your knowledge!
<li><b><a href="/?id=[_id]&mode=reverse_blanks">reverse blanks</a></b>: words that have no reverse lookup terms (yet)
<li><b><a href="/?id=[_id]&mode=tag_audit">tag audit</a></b>: all tags used in entries (including non-existent tags)
<li><b><a href="/?id=[_id]&mode=inflection">manage inflection schemes</a></b>: add, edit, and remove automatic inflection schemes
<li><b><a href="/?id=[_id]&mode=diachronics">diachronics</a></b>: add, edit, and remove diachronic schemes (for deriving words <u>from</u> this dictionary)
</ul>
[end mode tools]

[begin mode tag_audit]
[
real_tags = split(search("tag_names", "parent", _id, "template", title2id("Dictionary Tag")), {
});

// debug(real_tags);

dump = search("tag_query", "parent", _id, "template", title2id("Dictionary Entry"));
tags = list();

bads = "";

mute foreach(dump) {[
	word = substr(_data, 0, strpos(_data, ":"));
	items = substr(_data, strpos(_data, ":") + 1);
	items = split(items, ".");
	foreach(items) {[
		if((_data != "") && (_data != chr(13))) {[
			tags[_data] = tags[_data] + 1;
			if(find(real_tags, _data) == -1) {[
				bads &= {<a href="/?id=[word]">[get_title(word)]</a> has dead tag <i>[_data]</i><br>
};
			]};
		]};
	]};
]};

foreach(tags) _data = {[
	if(find(real_tags, _index) != -1)
		{<p><b>[_index]</b>: [_data] word(s)</p>}
	else
		{<p><i>[_index]</i>: [_data] word(s)</p>}
]};

bads;
]
[end mode tag_audit]

[begin preamble]

page("view", 278);

var searchlink = list();
searchlink.rel = "search";
searchlink.type = "application/opensearchdescription+xml";
searchlink.href = {/?id=[_id]&mode=opensearch};
searchlink.title = {[_title] Search};

[end preamble]

[begin mode opensearch]
[page("opensearch_atlas", _id)]
[end mode opensearch]

[begin mode opensearch_atlas][suppress_template()][override_mimetype({application/opensearchdescription+xml})]<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
	<ShortName>[_title]</ShortName>
	<Description>Search words from [_title] at Anthologica.</Description>
	<Tags>dictionary anthologica</Tags>
	<Contact>[getva("email", _owner.extended)]</Contact>
	<Image width="16" height="16" type="image/x-icon">http://anthologi.ca/theme/favicon.ico</Image>

	<moz:SearchForm>http://anthologi.ca/?id=[_id]&mode=search</moz:SearchForm>
	<Url type="text/html" template="http://anthologi.ca/?id=[_id]&mode=search&r=Search+Definitions&q={searchTerms}"/>
</OpenSearchDescription>[end mode opensearch_atlas]

[begin mode opensearch_memory][suppress_template()][override_mimetype({application/opensearchdescription+xml})]<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
	<ShortName>[_title]</ShortName>
	<Description>Search words from [_title] at the Memory of the City.</Description>
	<Tags>dictionary memory</Tags>
	<Contact>[getva("email", get_extended(_author))]</Contact>
	<Image width="16" height="16" type="image/x-icon">http://memory.rhetori.ca/theme/favicon.ico</Image>
	<Image width="16" height="16" type="image/vnd.microsoft.icon">http://memory.rhetori.ca/theme/favicon.ico</Image>
	<Image width="64" height="64" type="image/png">http://memory.rhetori.ca/theme/favicon.png</Image>

	<moz:SearchForm>http://memory.rhetori.ca/?id=[_id]&mode=search</moz:SearchForm>
	<Url type="text/html" 
        	template="http://memory.rhetori.ca/?id=[_id]&mode=search&r=Search+Definitions&q={searchTerms}"/>
</OpenSearchDescription>[end mode opensearch_memory]

[begin mode search]
[
if(_group != 0) {[
	gpid = get_group_profile_id(_group);
	if(gpid > 0) page("css", gpid);
]};

var collation = edit_display(getv("collation"));
if(collation == "") collation = "utf8mb4_unicode_ci";

header_link(searchlink);

override_parent({./?id=[$_id]}, $_title);

if($_params.r == "") {

<h2>Dictionary Search</h2>
<form method="get" action="/" style="text-align: center">
	<input type="hidden" name="id" value="[$_id]">
	<input type="hidden" name="mode" value="search">
	<input type="text" name="q" value="" accesskey="q" title="Query (Shift-Alt-Q)"[if($_args[0] == "") { autofocus="autofocus"}]>
	<input type="submit" value="Exact Search" name="r" accesskey="s" title="Search full text + headwords"> (<input type="number" name="l" value="3" style="width: 40px" title="# of acceptable typos" accesskey="t">
	<input type="submit" value="Fuzzy Search" name="r" accesskey="l" title="Search headwords only for similar spellings">)
	<br><br>
[if($_args[0] == "") {
	[$q = query("qc", 0, "title collate " & collation, "parent", $_id, "template", title2id("Dictionary Entry"));
	query_count($q);] entries.
}]
</form>

} else {
	[
	if((_params.r == "Search Definitions") || (_params.r == "Word Search") || (_params.r == "Exact Search")) {
	<h2>Dictionary Search Results</h2>
	<style type="text/css">
		ul.added {
			margin-top: 0px;
			margin-bottom: 0px;
		}
	</style>
	[
	target = list();
	target.value = {%[$_params.q]%};
	target.collate = collation;
	$q = query("searchresults", 0, "title collate " & collation, "template", title2id("Dictionary Entry"), "body", target, "parent", $_id);
	$qr = query_run("abbr", $q);
	$qr = replace(replace($qr, "<li>", {<ul class="added"><li>}), "</li>", "</li></ul>");
	]

	[
	target = list();
	target.value = {%[$_params.q]%};
	target.collate = collation;
	$q2 = query("searchresults", 0, "title collate " & collation, "template", title2id("Dictionary Entry"), "title", target, "parent", $_id);
	$qr2 = query_run("abbr", $q2);
	$qr2 = replace(replace($qr2, "<li>", {<ul class="added"><li>}), "</li>", "</li></ul>");
	if($qr2 != "") $qr = $qr & chr(10) & chr(10) & "[h2]Headwords[/h2]" & chr(10) & chr(10) & $qr2;

	if($qr != "") {
		[_wiki_format($qr, "no toc")]
		<br><br>
		[query_count($q) + query_count($q2)] result(s).
	} else {
		<i>No results. Try different synonyms for your search term.</i>
	};
	]

	} else {
		<h2>Levenshtein Matches</h2>
	[$q = query("cc", 0, "title collate " & collation, "parent", $_id, "template", title2id("Dictionary Entry"));
	$qr = query_run("compare", $q, list($_params.q, $_params.l));
	if($qr != "") {<ul>[_wiki_format($qr, "no toc")]</ul>} else {<i>No results. Try increasing your threshold or throwing in some typos.</i>};
	]
	}
	]
	<br><br><center><a href="/?id=[$_id]&mode=search">New Search</a></center>
}
]
[end mode search]

[begin mode printable][suppress_template(); time_limit(3600)]
<html>
<head>
<title>[$_title]</title>
<style type="text/css">
body {
	background: white;
	color: black;
	font-family: "Garamond", Palatino, "Palatino Linotype", "Book Antiqua", serif;
}
a {
	color: black !important;
}
</style>
</head>
<body>
<center>
<h1>[$_title]</h1>
<h2>[$_subtitle]</h2>
<i>as of:</i> [now()]
</center>
<br>
[
collation = edit_display(getv("collation"));
if(collation == "") collation = "utf8mb4_unicode_ci";
$q = query("dump", 0, "title collate " & collation, "parent", $_id, "template", title2id("Dictionary Entry"));

query_run("print", $q);
]
</body>
</html>
[end mode printable]

[begin mode export]
<pre>[
suppress_template();
$sortby = "title collate utf8mb4_unicode_ci";
if($_params.sortby != "") $sortby = $_params.sortby;
if($_params.q != "") $qstr = $_params.q;
if($qstr == "")
	$q = query("dump", 0, $sortby, "parent", $_id, "template", title2id("Dictionary Entry"))
else
	$q = query("dump", 0, $sortby, "parent", $_id, "template", title2id("Dictionary Entry"), "body", {%[$qstr]%});

$q.pagesize = query_count($q);

query_run("export", $q);
]</pre>
[end mode export]

[begin mode export_headwords]
<pre>[
suppress_template();

var collation = edit_display(getv("collation"));
if(collation == "") collation = "utf8mb4_unicode_ci";

q = retrieve({
	select title from entries
	where parent=[_id]
	and template=[title2id("Dictionary Entry")]
	order by title
		collate [collation]
});

// q = query("qc", 0, "title collate " & collation, "parent", _id, "template", title2id("Dictionary Entry"));
// query_run("title", q);

hws = each(q) ?(h) {[
	h.title
]};

concat(hws, chr(13) & chr(10));
]</pre>
[end mode export_headwords]

[begin mode table]
	<tr><th><nobr><a href="/?id=[$_id]">[$_title]</a></nobr>
	<td>[_subtitle]
[end mode table]

[begin mode index]
<li><a href="/?id=[$_id]"><b>[$_title]</b></a> <i>[$_subtitle]</i>
<span style="font-size: 70%; display: block">started by: [if(_owner.profile_id != 0) {<a href="/?id=[_owner.profile_id]">[_owner.name]</a>} else _owner.name]
<br>words: [query_count(query("e", 0, "title", "parent", _id, "template", title2id("Dictionary Entry")))]</span>
</li>
[end mode index]

[begin mode abbr]
<li><a href="/?id=[$_id]"><b>[$_title]</b></a>
<br><i>[$_subtitle]</i>
</li>
[end mode abbr]

[begin mode include]
<h2>[$_title;][$n = (substr($_viewer.permissions, 0, 1) == "c");
iif($_viewer.id == 0, $n = 0);
if($n) { · 
<a href="/?id=[$_id]&mode=add_entry">+</a> <a href="/?id=[$_id]&mode=add_tag">c</a> 
};]</h2>

<span style="font-size: 12pt">
[$n = (substr($_viewer.permissions, 3, 1) == "r");
iif($n, {[children("abbr", $_id);]}, "No read permission! Go away!");]
</span>
[end mode include]

[begin mode motd]
[
var collation = edit_display(getv("collation"));
if(collation == "") collation = "utf8mb4_unicode_ci";

var $sortmode = "title collate " & collation;

var $entries = query("dictionary", 100, $sortmode, "parent", $_id, "template", title2id("Dictionary Entry"));
var $c = query_count($entries);

if($c == 0) return {<i>No word of the day yet. Add some words!</i>};

$mangle = function {[
	$_args[0] * 997;
]};

$n = int($time / 86400);

$_params.motd_pagenum = mangle($n) % $c;

$q = query("motd", 1, $sortmode, "template", title2id("Dictionary Entry"), "parent", $_id);
$pid = query_run("id", $q);

$_params.motd_pagenum = mangle($n - 1) % $c;

$q = query("motd", 1, $sortmode, "template", title2id("Dictionary Entry"), "parent", $_id);
$ypid = query_run("id", $q);

$_params.motd_pagenum = mangle($n + 1) % $c;

$q = query("motd", 1, $sortmode, "template", title2id("Dictionary Entry"), "parent", $_id);
$tpid = query_run("id", $q);

if($pid != 0) {
<b>Word of the Day: <a href="/?id=[$pid]">[get_title($pid)]</a></b>
<hr>
<i>[page("part", $pid)]</i>. [page("desc", $pid)]
<hr>
<center>
<div style="display: inline-block; width: 50%; text-align: left;">
<i>yesterday</i><br>
<b><a href="/?id=[$ypid]">[get_title($ypid)]</a></b>
</div><div style="display: inline-block; width: 50%; text-align: right;">
<i>tomorrow</i><br>
<b><a href="/?id=[$tpid]">[get_title($tpid)]</a></b>
</div>
</center>
} else {<i>No word of the day yet. Add some words!</i>}]

[end mode motd]

[begin mode view]
[
if(_group != 0) {[
	gpid = get_group_profile_id(_group);
	if(gpid > 0) page("css", gpid);
]};

var collation = edit_display(getv("collation"));
if(collation == "") collation = "utf8mb4_unicode_ci";

header_link(searchlink);

var $sortmode = "title collate " & collation;

var $entries = query("dictionary", 100, $sortmode, "parent", $_id, "template", title2id("Dictionary Entry"));
var pl = page_list($entries, 6);
var entry_list = _wiki_format(query_view("abbr", $entries), "no toc");
]

<style type="text/css">
#plist {
	float: left;
	font-size: 70%;
	text-align: right;
	margin-right: 20px;
	width: 55px;
}
#plist a {
	display: block;
}
#elist {
	margin-left: 64px;
	padding-left: 9px;
	border-left: 4px rgba(216, 224, 255, 0.3) solid;
}
</style>

<div id="plist">
[pl]</div>

<div id="elist">
[
if(int($_params.dictionary_pagenum) == 0) {
<div style="float: right; max-width: 40%; margin-left: 10px; font-size: 90%;" class="mobile_nofloat mbox_parent">
	[page("motd", $_id)]
</div>[
if(getv("preface") != "") _wiki_format(getv("preface")) & "<br>";
]};
]

[entry_list]

</div>

<center>
<br>
[$np = next_page($entries);
$pp = previous_page($entries);

if($pp != "-1") {<a href="[$pp]">Previous Page</a> };
if($np != "-1") {<a href="[$np]">Next Page</a>};
]
<br>
[query_count($entries)] entries.
</center>

[page("search", $_id, list("no focus"))]

<div style="text-align: center;">
<br><b>Tags</b><br><br>
[search("tag_abbr", "parent", $_id, "template", title2id("Dictionary Tag"));]
</div>
[end mode view]

[begin mode autorepair]
[search("autorepair", "parent", $_id, "template", title2id("Dictionary Entry"));]
[end mode autorepair]

[begin mode validate]
[
	$s = search("validate", "parent", $_id, "template", title2id("Dictionary Entry"));
	if($s == "") {
		<i>No invalid entries were detected.</i>
	} else {[
		$s
	]};
]
[end mode validate]

[begin mode tidy]
[
	$s = search("tidy", "parent", $_id, "template", title2id("Dictionary Entry"));
	if($s == "") {
		<i>No untidy entries were detected.</i>
	} else {[
		$s
	]};
]
[end mode tidy]

[begin mode fullview]
[
if(_group != 0) {[
	gpid = get_group_profile_id(_group);
	if(gpid > 0) page("css", gpid);
]};

iif(can_read(), {
	[
		time_limit(300);
		_wiki_format(search("abbr", "parent", $_id, "template", title2id("Dictionary Entry")), "no toc");
	]

<div style="text-align: center;">
<br><b>Tags</b><br><br>
[search("tag_abbr", "parent", $_id, "template", title2id("Dictionary Tag"));]
</div>

}, "No read permission! Go away!");
]
[end mode fullview]

[begin mode by_date]
[
$sortmode = "date DESC, id";

$entries = query("dictionary", 100, $sortmode, "parent", $_id, "template", title2id("Dictionary Entry"));
]

<center>
Page: [page_list($entries, 1, "date");]<br><br></center>

[
if(int($_params.dictionary_pagenum) == 0) {
<div style="float: right; max-width: 40%; margin-left: 10px; font-size: 90%;" class="mobile_nofloat mbox_parent">
	[page("motd", $_id)]
</div>[
if(getv("preface") != "") _wiki_format(getv("preface")) & "<br>";
]};
]

[_wiki_format(query_view("abbr", $entries), "no toc");]

<center>
<br>
[$np = next_page($entries);
$pp = previous_page($entries);

if($pp != "-1") {<a href="[$pp]">Previous Page</a> };
if($np != "-1") {<a href="[$np]">Next Page</a>};
]
<br>
[query_count($entries)] entries.
</center>

[page("search", $_id, list("no focus"))]

<div style="text-align: center;">
<br><b>Tags</b><br><br>
[search("tag_abbr", "parent", $_id, "template", title2id("Dictionary Tag"));]
</div>
[end mode by_date]

[begin mode add_entry]
<form method="post" action="/" width="100%">
<input type="hidden" name="id" value="[$_id]">
<input type="hidden" name="mode" value="entry_submit">
<table width="100%">
<tr><th>Headword:</th><td><input type="text" class="textbox" name="title" value=""></td></tr>
<tr><th></th><td>
<span class="buttonbox"><input name="submitButton" class="submit" type="submit" value="Create"></span> <i>your permissions</i>: [summarize_permissions($_viewer.permissions)]<br>
To add a homophone, add <tt><b><!></b><i>number</i></tt> after the name.</td></tr></table>
</form> 
[end mode add_entry]

[begin mode entry_submit]
[
$e = new_page($_params.title, $_id);
if($e > 0) {
    [
    set_template($e, title2id("Dictionary Entry"));
    set_group($e, $_group);
    set_permissions($e, $_permissions);
    msg_start();
    page("edit", $e);
    msg_end();
    ]
} else {[
	if(search("id", "parent", _id, "title", _params.title) > 0) {
	    [msg_start();]
	    <p>The word <b>[_params.title]</b> or an identically-named category already exists in this dictionary. You should go back an add a homophone; just put "<!><i>number</i>" (typically number will be "2", but it can, actually, be anything) on the end of the title.</p>
            <p>Some day, there will be a slightly more informative disambiguation page here that helps you do this properly.</p>
	    [msg_end();]
	} else {
	    [msg_start();]
	    The word could not be created. Most likely, you do not have comment permissions on the dictionary.
	    [msg_end();]
	};
]};
]
[end mode entry_submit]

[begin mode add_tag]
<form method="post" action="/" width="100%">
<input type="hidden" name="id" value="[$_id]">
<input type="hidden" name="mode" value="tag_submit">
<table width="100%">
<tr><th>Tag name:</th><td><input type="text" class="textbox" name="title" value=""></td></tr>
<tr><th></th><td>
<span class="buttonbox"><input name="submitButton" class="submit" type="submit" value="Create"></span> <i>your permissions</i>: [summarize_permissions($_viewer.permissions)]</td></tr></table>
</form> 
[end mode add_tag]

[begin mode tag_submit]
[
$e = new_page($_params.title, $_id);
if($e > 0) {
    [
    set_template($e, title2id("Dictionary Tag"));
    set_group($e, $_group);
    set_permissions($e, $_permissions);
    set_priority($e, 1);
    msg_start();
    page("edit", $e);
    msg_end();
    ]
} else {
    [msg_start();]
    Disaster. It failed! Maybe you should check the error log.
    [msg_end();]
};
]
[end mode tag_submit]

[begin mode edit]
[
var collations = {utf8mb4_general_ci
utf8mb4_bin
utf8mb4_unicode_ci
utf8mb4_icelandic_ci
utf8mb4_latvian_ci
utf8mb4_romanian_ci
utf8mb4_slovenian_ci
utf8mb4_polish_ci
utf8mb4_estonian_ci
utf8mb4_spanish_ci
utf8mb4_swedish_ci
utf8mb4_turkish_ci
utf8mb4_czech_ci
utf8mb4_danish_ci
utf8mb4_lithuanian_ci
utf8mb4_slovak_ci
utf8mb4_spanish2_ci
utf8mb4_roman_ci
utf8mb4_persian_ci
utf8mb4_esperanto_ci
utf8mb4_hungarian_ci
utf8mb4_sinhala_ci
utf8mb4_german2_ci
utf8mb4_croatian_mysql561_ci
utf8mb4_unicode_520_ci
utf8mb4_vietnamese_ci
utf8mb4_croatian_ci
utf8mb4_myanmar_ci
utf8mb4_thai_520_w2
utf8mb4_general_nopad_ci
utf8mb4_nopad_bin
utf8mb4_unicode_nopad_ci
utf8mb4_unicode_520_nopad_ci};

iif(can_edit(), {
<style type="text/css">
th {
	vertical-align: top;
}
</style>
<form method="post" action="/" width="100%">
<input type="hidden" name="id" value="[$_id]">
<input type="hidden" name="mode" value="edit_submit">
<table width="100%">
        <tr><th>Dictionary Name:</th><td><input type="text" class="textbox" name="title" value="[edit_display($_title)]" style="width: 100%"></td></tr>
        <tr><th>Subtitle:</th><td><input type="text" class="textbox" name="subtitle" value="[edit_display($_subtitle)]" style="width: 100%"><br><small>This will appear underneath or beside the dictionary name.</small></td></tr>
<tr><th>Parent:</th><td><input type="text" class="textbox" name="parent" value="[$_parent]"><br><small>ID number of the language this dictionary belongs to.</small></td></tr>
<tr><th>Permissions:</th><td>[permissions_control($_permissions)]</td></tr>
<tr><th>Owner:</th><td>[users_dropdown("author", $_author)]</td></tr>
<tr><th>Group:</th><td>[groups_dropdown("group", $_group)]<br><small>This should normally be the universe's group.</small></td></tr>
<tr><th>Collation:</th><td>[_select(edit_display(getv("collation")), collations, "collation")]<br><small>If you don't know what this is, leave it at <tt>utf8mb4_general_ci</tt>.</small></td></tr>
<tr><th>Priority:</th><td><input type="text" class="textbox" name="priority" value="[$_priority]"><br><small>0 = default priority; use this to change sort order.</small></td></tr>
<tr><th>Preface:</th><td><textarea class="textbox" name="preface" style="width: 100%">[edit_display(getv("preface"))]</textarea>
<br><small>This will be shown at the top of the first page in both alphabetical and chronological sorting, and can be used to describe general information about reading the dictionary.</small></td></tr>
[
if(getv("parts") == "")
	putv("parts", {n	noun
v	verb
adj	adjective
adv	adverb
conj	conjunction
interj	interjection});
]
<tr><th>Parts of Speech:</th><td><textarea name="parts" style="width: 100%" rows=12>[replace(edit_display(getv("parts")), chr(9), ": ")]</textarea><br><span style="font-size: 80%">Define the language's lexical categories here. Format: <i>abbreviation</i><colon><space><i>name</i> (tabs are also accepted)</span></td></tr>
<tr><td></td><td>
<span class="buttonbox"><input name="submitButton" class="submit" type="submit" value="Submit"></span> <i>your permissions</i>: [summarize_permissions($_viewer.permissions)]</td></tr></table>

<script type="text/javascript">
document.querySelector("textarea").addEventListener('keydown',function(e) {
    if(e.keyCode === 9) { // tab was pressed
        // get caret position/selection
        var start = this.selectionStart;
        var end = this.selectionEnd;

        var target = e.target;
        var value = target.value;

        // set textarea value to: text before caret + tab + text after caret
        target.value = value.substring(0, start)
                    + "\t"
                    + value.substring(end);

        // put caret at right position again (add one for the tab)
        this.selectionStart = this.selectionEnd = start + 1;

        // prevent the focus lose
        e.preventDefault();
    }
},false);
</script>

</form>
<br><br>
<a href="/?id=[_id]&mode=delete">delete this dictionary</a> (and all of its words and categories)
}, "What are you doing? You don't even have edit permission.");]
[end mode edit]

[begin mode edit_submit]
[$_title = $_params.title]
[$_subtitle = $_params.subtitle]
[$_parent = $_params.parent]
[$_permissions = $_params.permissions]
[$_author = $_params.author]
[$_group = $_params.group]
[$_priority = $_params.priority]
[putv("preface", $_params.preface)]
[putv("collation", $_params.collation)]
[putv("parts", replace($_params.parts, ": ", chr(9)))]
<h2>It was updated.</h2>
<a href="/?[$_title]">Return to it.</a>
[refresh_to({./?id=[_id]}, 1)]
[end mode edit_submit]