Jump to content

ICT:Automatic IDs: Difference between revisions

From Costa Sano MediaWiki
No edit summary
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:


=== Example Cargo Store ===
=== Example Cargo Store ===
In your data template's `<includeonly>` section:
In your data template's &lt;includeonly&gt; section:
<pre>
<pre>
<nowiki>
&#123;&#123;#cargo_store:
{{#cargo_store:
_table = Projects
_table = Projects
|ProjectID = {{{Category|}}}-{{{Year|}}}-{{#time:U}}
&#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 = {{{Category|}}}
&#124;Category = &#123;&#123;&#123;Category&#124;&#125;&#125;&#125;
|Year = {{{Year|}}}
&#124;Year = &#123;&#123;&#123;Year&#124;&#125;&#125;&#125;
}}
&#125;&#125;
</nowiki>
</pre>
</pre>


Line 25: Line 23:


=== Forcing a Protected Namespace ===
=== Forcing a Protected Namespace ===
In the <nowiki>{{{info}}}</nowiki> tag, prefix your formula with the name of your protected namespace.  
In the &lt;info&gt; tag, prefix your formula with the name of your protected namespace.
* '''Note:''' Use the exact name of the namespace (e.g., `Archive:`, `Internal:`, or `Data:`).
 
<pre>
<pre>
<nowiki>
&#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;
{{{info|page name=Archive:<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}}
</nowiki>
</pre>
</pre>


=== Validation for Uniqueness ===
=== Validation for Uniqueness ===
To prevent manual ID collisions, use the `unique` parameter on a hidden field in your form definition:
To prevent manual ID collisions, use the `unique` parameter on a hidden field:
<pre>
<pre>
<nowiki>
&#123;&#123;&#123;field&#124;ProjectID&#124;unique&#124;input type=text&#124;hidden&#125;&#125;&#125;
{{{field|ProjectID|unique|input type=text|hidden}}}
</nowiki>
</pre>
</pre>


Line 47: Line 39:
=== Query Example ===
=== Query Example ===
<pre>
<pre>
<nowiki>
&#123;&#123;#cargo_query:
{{#cargo_query:
&#124;tables = Projects
|tables = Projects
&#124;fields = _pageName=ID, Category
|fields = _pageName=ID, Category
&#124;where = _pageNamespace = 102
|where = _pageNamespace = 102 <!-- Use the ID of your Protected Namespace -->
&#124;format = table
|format = table
&#125;&#125;
}}
</nowiki>
</pre>
</pre>


Line 60: Line 50:
| Feature | Page Schemas | Manual Page Forms |
| Feature | Page Schemas | Manual Page Forms |
| :--- | :--- | :--- |
| :--- | :--- | :--- |
| **Ease of Use** | High (Visual) | Medium (Markup) |
| **Namespace Control** | Limited / Hardcoded | Full (Dynamic via `page name`) |
| **Namespace Control** | Limited / Hardcoded | Full (Dynamic via `page name`) |
| **Custom ID Logic** | Difficult to customize | Unlimited (via ParserFunctions) |
| **Custom ID Logic** | Difficult to customize | Unlimited (via ParserFunctions) |
| **Maintenance** | Auto-generates code | Manual template updates |


[[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) |