Jump to content

ICT:Automatic IDs: Difference between revisions

From Costa Sano MediaWiki
Created page with "{{#set:Description=Documentation for generating and querying automatic IDs using Page Forms and Cargo.}} = Automatic ID Generation for Cargo Tables = This page documents the workflow for generating automatic, composite IDs using the Page Forms and Cargo extensions. == Overview == While Page Forms does not have a "native" ID generator button, unique IDs can be constructed by: # Combining user-input attributes in the storage..."
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#set:Description=Documentation for generating and querying automatic IDs using Page Forms and Cargo.}}
'''Description:''' Documentation for generating and querying automatic IDs using Page Forms and Cargo, including Protected Namespace management.


= Automatic ID Generation for Cargo Tables =
= Automatic ID Generation & Namespace Control =


This page documents the workflow for generating automatic, composite IDs using the [[Extension:Page Forms|Page Forms]] and [[Extension:Cargo|Cargo]] extensions.
This page documents the workflow for creating unique, automatic IDs and ensuring pages are saved within a specific Protected Namespace using [[Extension:Page Forms|Page Forms]] and [[Extension:Cargo|Cargo]].


== Overview ==
== 1. Template Logic (Automatic ID Generation) ==
While Page Forms does not have a "native" ID generator button, unique IDs can be constructed by:
The best practice is to construct your ID inside the storage template. This allows you to combine multiple attributes and system values (like timestamps) before storing them in Cargo.
# Combining user-input attributes in the storage template.
# Using the form's '''page name''' formula to ensure uniqueness.
# Enforcing uniqueness via form validation.


== 1. Template Logic (The "Store" Method) ==
=== Example Cargo Store ===
To create an ID from a combination of attributes, logic is placed inside the `{{#cargo_store}}` function.
In your data template's <includeonly> section:
 
=== Example Cargo Declaration ===
Define your table in your Schema template:
<pre>
<pre>
{{#cargo_declare:
&#123;&#123;#cargo_store:
_table = Projects
_table = Projects
|ProjectID = String
&#124;ProjectID = &#123;&#123;&#123;Category&#124;&#125;&#125;&#125;-&#123;&#123;&#123;Year&#124;&#125;&#125;&#125;-&#123;&#123;#time:U&#125;&#125;
|Category = String
&#124;Category = &#123;&#123;&#123;Category&#124;&#125;&#125;&#125;
|Year = Integer
&#124;Year = &#123;&#123;&#123;Year&#124;&#125;&#125;&#125;
}}
&#125;&#125;
</pre>
</pre>


=== Example Cargo Store ===
== 2. Form Definition (Namespace & Page Naming) ==
In your data template, concatenate the fields to create the `ProjectID`:
By defining the `page name` formula in the form, you can force all new pages into a specific namespace and ensure the URL itself acts as a unique identifier.
 
=== Forcing a Protected Namespace ===
In the &lt;info&gt; tag, prefix your formula with the name of your protected namespace.
<pre>
<pre>
<includeonly>
&#123;&#123;&#123;info&#124;page name=Archive:&lt;Projects[Category]&gt;-&lt;Projects[Year]&gt;-&lt;unique number;start=001&gt;&#125;&#125;&#125;
{{#cargo_store:
_table = Projects
|ProjectID = {{{Category|}}}-{{{Year|}}}-{{#time:U}} <!-- Category-Year-UnixTimestamp -->
|Category = {{{Category|}}}
|Year = {{{Year|}}}
}}
</includeonly>
</pre>
</pre>


== 2. Form Definition ==
=== Validation for Uniqueness ===
To ensure the user doesn't create a duplicate ID, use the `unique` and `page name` parameters in [[Extension:Page Forms|Page Forms]].
To prevent manual ID collisions, use the `unique` parameter on a hidden field:
<pre>
&#123;&#123;&#123;field&#124;ProjectID&#124;unique&#124;input type=text&#124;hidden&#125;&#125;&#125;
</pre>


=== Page Name Formula ===
== 3. Querying Protected Data ==
In the `{{{info}}}` tag, define how the page is named automatically:
When querying pages in a specific namespace, Cargo's `_pageName` will include the namespace prefix (e.g., `Archive:Project-101`).
<syntaxhighlight lang="mediawiki">
{{{info|page name=<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}}
</syntaxhighlight>


=== Field Validation ===
=== Query Example ===
Force the form to check if an ID already exists:
<pre>
<syntaxhighlight lang="mediawiki">
&#123;&#123;#cargo_query:
{{{field|ProjectID|unique|input type=text|hidden}}}
&#124;tables = Projects
</syntaxhighlight>
&#124;fields = _pageName=ID, Category
 
&#124;where = _pageNamespace = 102
== 3. Querying Records ==
&#124;format = table
To retrieve data using your custom ID, use the `{{#cargo_query}}` function as documented on [https://www.mediawiki.org MediaWiki.org].
&#125;&#125;
 
</pre>
=== Filter by Composite ID ===
<syntaxhighlight lang="mediawiki">
{{#cargo_query:
|tables = Projects
|fields = _pageName=Page, Category, Year
|where = ProjectID = 'Hardware-2024-171523421'
|format = table
}}
</syntaxhighlight>
 
=== Filter using Wildcards ===
To find all projects from a specific category using the ID prefix:
<syntaxhighlight lang="mediawiki">
{{#cargo_query:
|tables = Projects
|fields = ProjectID, Year
|where = ProjectID LIKE 'Hardware-%'
|format = ul
}}
</syntaxhighlight>


== Extensions Used ==
== Comparison: Page Forms vs. Page Schemas ==
* [[Extension:Page Forms|Page Forms]]: Handles the user interface and page naming.
| Feature | Page Schemas | Manual Page Forms |
* [[Extension:Cargo|Cargo]]: Handles data storage and querying.
| :--- | :--- | :--- |
* [[Extension:ParserFunctions|ParserFunctions]]: Used for string manipulation and date formatting.
| **Namespace Control** | Limited / Hardcoded | Full (Dynamic via `page name`) |
| **Custom ID Logic** | Difficult to customize | Unlimited (via ParserFunctions) |


[[Category:Help]]
[[Category:Help]]
[[Category:Cargo]]
[[Category:Cargo]]

Latest revision as of 16:44, 29 January 2026

Description: Documentation for generating and querying automatic IDs using Page Forms and Cargo, including Protected Namespace management.

Automatic ID Generation & Namespace Control

This page documents the workflow for creating unique, automatic IDs and ensuring pages are saved within a specific Protected Namespace using Page Forms and Cargo.

1. Template Logic (Automatic ID Generation)

The best practice is to construct your ID inside the storage template. This allows you to combine multiple attributes and system values (like timestamps) before storing them in Cargo.

Example Cargo Store

In your data template's <includeonly> section:

{{#cargo_store:
_table = Projects
|ProjectID = {{{Category|}}}-{{{Year|}}}-{{#time:U}}
|Category = {{{Category|}}}
|Year = {{{Year|}}}
}}

2. Form Definition (Namespace & Page Naming)

By defining the `page name` formula in the form, you can force all new pages into a specific namespace and ensure the URL itself acts as a unique identifier.

Forcing a Protected Namespace

In the <info> tag, prefix your formula with the name of your protected namespace.

{{{info|page name=Archive:<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}}

Validation for Uniqueness

To prevent manual ID collisions, use the `unique` parameter on a hidden field:

{{{field|ProjectID|unique|input type=text|hidden}}}

3. Querying Protected Data

When querying pages in a specific namespace, Cargo's `_pageName` will include the namespace prefix (e.g., `Archive:Project-101`).

Query Example

{{#cargo_query:
|tables = Projects
|fields = _pageName=ID, Category
|where = _pageNamespace = 102
|format = table
}}

Comparison: Page Forms vs. Page Schemas

| Feature | Page Schemas | Manual Page Forms | | :--- | :--- | :--- | | **Namespace Control** | Limited / Hardcoded | Full (Dynamic via `page name`) | | **Custom ID Logic** | Difficult to customize | Unlimited (via ParserFunctions) |