CargoAdmin, Bureaucrats, Moderators (CommentStreams), fileuploaders, Interface administrators, newuser, Push subscription managers, Suppressors, Administrators
14,662
edits
(→Options: expand) |
(→Sections: highlight) |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
Enter all the data here to create the properties, template, form and category for a single class. For more options, use the pages [[Special:CreateTemplate|Create a template]], [[Special:CreateForm|Create a form]] and [[Special:CreateCategory|Create a category]] instead. | Enter all the data here to create the properties, template, form and category for a single class. For more options, use the pages [[Special:CreateTemplate|Create a template]], [[Special:CreateForm|Create a form]] and [[Special:CreateCategory|Create a category]] instead. | ||
== | ==Data types== | ||
Cargo supports various data types including simple types like strings, dates, and numbers, to more complex ones like hierarchies, coordinates, and wikitext. | Cargo supports various data types including simple types like strings, dates, and numbers, to more complex ones like hierarchies, coordinates, and wikitext. | ||
Line 58: | Line 58: | ||
* Holds a short text that is meant to be parsed by the MediaWiki parser | * Holds a short text that is meant to be parsed by the MediaWiki parser | ||
* Default max size: 300 characters | * Default max size: 300 characters | ||
* Purpose | |||
** This data type is for storing strings that might contain wiki markup, but they are treated primarily as text strings rather than parsed wikitext when displayed. | |||
* Use Case | |||
** Use this when you want to store text that might include wiki syntax, but you don't need this text to be rendered as wiki content every time it's displayed. | |||
** It's useful for storing content where the wikitext might be relevant only in certain contexts or for archival purposes where the raw text with markup is preserved but not necessarily executed. | |||
=== <code>Wikitext</code> === | === <code>Wikitext</code> === | ||
* Holds longer text that is meant to be parsed by the MediaWiki parser | * Holds longer text that is meant to be parsed by the MediaWiki parser | ||
* Unindexed | * Unindexed | ||
** Purpose | |||
*** Designed to store content that includes MediaWiki markup, which should be parsed and rendered as wikitext when displayed. This means when you query this field in Cargo, the result will be formatted according to MediaWiki's parsing rules, turning wiki syntax into HTML. | |||
** Use Case | |||
*** Ideal for fields where the content is meant to be dynamic or formatted, like descriptions, bios, or any content that should appear with links, bold, italics, lists, etc., as intended by the wiki markup. | |||
=== <code>Searchtext</code> === | === <code>Searchtext</code> === | ||
* Holds text that can be searched on, using the [[Special:MyLanguage/Extension:Cargo/Querying data#The "MATCHES" commandMATCHES]] command (requires MySQL 5.6+ or MariaDB 5.6+) | * Holds text that can be searched on, using the [[Special:MyLanguage/Extension:Cargo/Querying data#The "MATCHES" commandMATCHES]] command (requires MySQL 5.6+ or MariaDB 5.6+) | ||
* Purpose | |||
** If there's a need to differentiate content for searching purposes, one might treat certain text fields as plain text for indexing, but this isn't a native Cargo data type; instead, it's more about how data might be processed or indexed for search functionality. | |||
* Use Case | |||
** You might design your database to store content in one form (like Wikitext) but ensure that for searching purposes, a plain text version (Wikitext string could serve this purpose if not intended for rendering) is used to improve search accuracy and performance by avoiding the complexities of wiki markup. | |||
=== <code>File</code> === | === <code>File</code> === | ||
Line 96: | Line 109: | ||
The options are: | The options are: | ||
* | Each of these formats can be customized further by using parameters like template, named args, or separator to control how data is displayed or separated within the result. Remember that the exact syntax and capabilities might depend on the version of Cargo you are using, so always check the latest documentation for the most current options and features. | ||
*Side [[infobox]] | |||
* | ==== Table ==== | ||
*Sections | * The table is the default output format for Cargo queries. | ||
* Results are displayed in a tabular format with each row representing a record and columns for each field of the record. | |||
Example: | |||
<syntaxhighlight lang="python">{{#cargo_query: | |||
|tables=ExampleTable | |||
|fields=Field1, Field2 | |||
}} | |||
</syntaxhighlight> | |||
==== Side Infobox ==== | |||
* Side [[infobox]] is designed for displaying information in a box typically positioned to the side of an article. | |||
* This format creates a box that can be floated to the right or left of content, useful for displaying metadata or summary information about a subject. | |||
Example: | |||
<syntaxhighlight lang="python">{{#cargo_query: | |||
|tables=ExampleTable | |||
|fields=Field1, Field2 | |||
|format=infobox | |||
}}</syntaxhighlight> | |||
==== Plain Text ==== | |||
* Use this when you need the output in plain text, without any HTML formatting. | |||
* This format removes all HTML tags and presents data in a straightforward text manner, which can be useful for embedding data in text or for custom formatting. | |||
==== Sections ==== | |||
* Sections are useful when you want to organize information into sections within a page. | |||
* Each record is displayed as a section, often with a header. This format is handy for creating detailed pages where each section represents different aspects or entries of a subject. | |||
Example: | |||
<syntaxhighlight lang="python">{{#cargo_query: | |||
|tables=ExampleTable | |||
|fields=Field1, Field2 | |||
|format=sections | |||
}}</syntaxhighlight> | |||
===Options=== | ===Options=== | ||
==== This template can be included multiple times on the page ==== | ==== This template can be included multiple times on the page ==== | ||
This feature leverages MediaWiki's templating system to iteratively display data stored via Cargo, enhancing the dynamic and flexible presentation of information stored in a structured manner within the wiki. | This feature leverages MediaWiki's templating system to iteratively display data stored via Cargo, enhancing the dynamic and flexible presentation of information stored in a structured manner within the wiki. | ||
In practice, this capability allows wiki editors to: | |||
* Create lists or galleries where each item follows the same format but displays different data (e.g., a list of events, publications, personnel bios, etc.). | |||
* Implement dynamic content sections where each section might focus on different aspects of similar data, like different product features or specifications, all on the same wiki page | |||
===== Data repetition ===== | |||
Cargo allows for storing structured data in MediaWiki pages. When you create templates to display this data, you might want to use the same template structure to show different sets of data. For example, if you have a template for displaying book information, you might want to use that template multiple times on one page to list several books. | |||
===== No conflict in data display ===== | |||
Each instance of the template should be able to pull and display different data sets without the instances interfering with each other. This means: | |||
* Unique Identifiers: If the template generates or uses any HTML IDs or JavaScript variables, they need to be unique for each instance to avoid conflicts in the DOM or in scripts. | |||
* Data Parameters: The template should be designed to accept parameters or use Cargo queries that can specify which piece of data (or which set of data) it should display each time it's called. | |||
===== Dynamic content handling ===== | |||
Since Cargo often involves querying data from wiki pages or databases: | |||
* Each template call might query different data. If the template uses #cargo_query, each instance can define different parameters for what data to fetch, allowing for different content in each template instance. | |||
* Scope of Variables: Variables used within the template for storing or manipulating data should not leak or overwrite each other between different template instances. | |||
===== Efficiency ===== | |||
Even though templates can be included multiple times, there should be considerations for: | |||
* Page Load Time: Multiple queries or complex template processing might slow down page loading if not optimized. | |||
* Cargo Query Optimization: Efficient use of Cargo's ability to limit, join, or filter data to reduce unnecessary database hits or compute overhead with each inclusion. | |||
===== Modular design ===== | |||
Such templates are usually designed to be modular and reusable, meaning they: | |||
* Are built with the idea that their content will change with each use, based on the parameters passed or the data queried. | |||
* Maintain Consistency: While they can show different data, the format and style remain consistent, which is useful for maintaining a uniform look across different content on the same page.. | |||
==== Use full wikitext instead of #template_display ==== | ==== Use full wikitext instead of #template_display ==== | ||
You need to manually write out how you want template data to appear using MediaWiki's language, rather than relying on the automated or semi-automated display mechanisms provided by extensions like Cargo. This approach is chosen for greater control, customization, or when the display logic provided by extensions does not meet the specific needs or design requirements of the page. | You need to manually write out how you want template data to appear using MediaWiki's language, rather than relying on the automated or semi-automated display mechanisms provided by extensions like Cargo. This approach is chosen for greater control, customization, or when the display logic provided by extensions does not meet the specific needs or design requirements of the page. | ||
Example Setup: | |||
Create a Template: Let's say you have a template named ExampleTemplate that you want to use for displaying data from a Cargo table called ExampleTable. | |||
Template Code (Template:ExampleTemplate): | |||
mediawiki | |||
<div class="example-box"> | |||
<h2>{{{name|}}}</h2> | |||
<p><strong>Description:</strong> {{{description|No description provided}}}</p> | |||
<p><strong>Year:</strong> {{{year|Unknown}}}</p> | |||
</div> | |||
Cargo Query with Full Wikitext: | |||
Wiki Code: | |||
sql | |||
<nowiki>{{#cargo_query: | |||
|tables=ExampleTable | |||
|fields=name, description, year | |||
|format=template | |||
|template=ExampleTemplate | |||
|use full wikitext=true | |||
}}</nowiki> | |||
By setting use full wikitext=true, the template parser will interpret all wikitext within the template, allowing for more complex layouts, headings, classes, etc., as defined in your template. | |||
Explanation: | |||
ExampleTable: This is your Cargo table containing fields like name, description, and year. | |||
ExampleTemplate: This template formats how each row from ExampleTable will be displayed. | |||
<nowiki>{{{name|}}}</nowiki> means it will display the name field, with an empty string if name is not provided. | |||
<nowiki>{{{description|No description provided}}}</nowiki> shows the description or a default message if none exists. | |||
<nowiki>{{{year|Unknown}}}</nowiki> similarly handles the year. | |||
Query Parameters: | |||
* format=template specifies that we're using a template for output. | |||
* template=ExampleTemplate tells Cargo which template to use. | |||
* use full wikitext=true enables the full wikitext interpretation within the template. | |||
This method allows for richer, more customized display options directly from your Cargo query results, integrating seamlessly with MediaWiki's text processing capabilities. | |||
The options are: | The options are: |
edits