Extension:Cargo/Quick start guide/es

From mediawiki.org
This page is a translated version of the page Extension:Cargo/Quick start guide and the translation is 50% complete.

Digamos que quieres crear una wiki que muestre todos los libros que tienes en casa. Quieres dos tipos de páginas en tu wiki: una para libros y otra para autores. Cada página del libro debe contener un título, un nombre (o nombres) del autor, un género (o géneros), un año de publicación y un número de páginas. Cada página de autor debe contener el nombre del autor, su país de origen y una lista de todos los libros que han escrito que posees.

Creando las plantillas

Lo principal que debes hacer es crear dos plantillas, una para libros y otra para autores. Si tiene instalada la extensión de formularios de página, puede usar cualquiera de sus páginas auxiliares Special:CreateTemplate o Special:CreateClass para crear estas plantillas. Y si también tienes instalada la extensión Page Schemas, puedes utilizar su estándar "crear/editar esquema" para crear y recrear plantillas basadas en Cargo.

Sin embargo, también puedes crear estas plantillas manualmente. Aquí tienes cómo podrían lucir las dos plantillas:

Template:Book

<noinclude>
Esta es la plantilla "Book".

{{#cargo_declare:_table=Books
|Authors=List (,) of Page
|Genres=List (,) of String
|YearOfPublication=Date
|NumberOfPages=Integer}}
</noinclude>
<includeonly>
{{#cargo_store:_table=Books}}
{|
! Autor(es)
| {{#arraymap:{{{Authors|}}}|,|x|{{#formredlink:form=Author|target=x}} }}
|-
! Género (s)
| {{{Genres|}}}
|-
! Fecha de publicación
| {{{YearOfPublication|}}}
|-
! Número de páginas
| {{{NumberOfPages|}}}
|}
</includeonly>

Template:Author

<noinclude>
This is the "Author" template.

{{#cargo_declare:_table=Authors
|Country=String}}
</noinclude>
<includeonly>
{{#cargo_store:_table=Authors}}
{|
! Country of origin
| {{{Country|}}}
|-
! Books
| {{#cargo_query:tables=Books|where=Authors HOLDS '{{PAGENAME}}'}}
|}
</includeonly>

Eso es todo lo que necesitas hacer para tener plantillas estilo infobox que definan una estructura de datos y almacenen sus datos de una manera fácilmente consultable.

Puedes ver en esta plantilla ejemplos de llamadas a las tres funciones principales del analizador de Cargo: #cargo_declare, #cargo_store, #cargo_query; y, con suerte, cómo interactúan las tres entre sí. Note especially the placement of #cargo_declare, #cargo_store: the former in the ‎<noinclude> tag, the latter in the ‎<includeonly> tag.

A few other notes on these templates:

  • For both templates, the name of the entity, i.e the name of the book or author, is not stored in the template. That is because the name of the page itself will hold the name of that book or author -- and will also be stored in those two tables, in a field named "_pageName".
  • The "Author" template contains, at the end, what is known as an aggregating query, which queries the "Books" table (defined by the other template) and gets the names of all the pages that have the current page among its values for the "Authors" field. (It will then, by default, display that information in a comma-separated list.) This is a very common type of query; it means that you don't need to store the same data in two different pages, because one page can simply query the data.
  • There is one line of this sample code that requires another extension to work: the line in Template:Book which includes calls to both #arraymap and #formredlink, both of which are defined by the Page Forms extension. This line does a rather complex operation: it separates the value of "{{{Authors|}}}" into one or more sub-values (splitting by comma), then, for each value, either links directly to that page, if a page with that name already exists; or links to the form for creating that page, using the form definition at "Form:Author". Thus, this template presupposes not only that the Page Forms extension is installed, but that an "Author" form has been created. If you don't have Page Forms installed, you could replace that line with something a lot simpler, like:
| {{{Authors|}}}
However, Page Forms is strongly recommended for any wiki that uses Cargo.

Creating the Cargo tables

Once the templates are created, there's only one more simple step, which is to create the Cargo database tables for each template. This is not done automatically when the template is saved. Instead, there are two options:

  • For each template, go that template's page, select the "Create data table" tab option (or append ?action=recreatedata to the URL), then click the "OK" button.
  • From the command line, go to Cargo's /maintenance directory and run "php cargoRecreateData.php".

After doing either of these, a table will be created holding the data for each relevant template; and you will be able to see that table's contents at any time by clicking the "View table" link on the template's page.