Jump to content

扩展:页面表单/快速开始指南

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

目前,您已经设置好了您的站点的所有软件。 之后呢?现在是时候创建用于保存、显示以及启用添加和编辑数据的结构了。值得庆幸的是,所有这些都可以通过创建各种Wiki页面来完成。

第一步,明晰您的数据结构。 您的网站有哪些类型的页面? 每个页面需要包含哪些数据? 您可以稍后再更改所有这些,但是您应该有一个开始计划。 一旦明晰了这些(最好是写下来),就可以开始创建必要的Wiki页面。 您将需要为模板和表单(可能还有分类)以及(如果使用语义MediaWiki)属性创建或修改页面。

您可以从头开始创建所有这些文件,尽管也存在帮助程序表单来帮助创建它们。 正确的方法取决于您使用的其他扩展:

使用Cargo

简单方法 - Special:CreateClass

页面Special:CreateClass(由页面表单定义)提供了一个助手表单,可以在一个页面内定义有关数据“类”的所有内容。 如果填写这些字段并单击“提交”,页面将自动创建必要的模板、表单和分类页面。 然后,您可以转到已创建的表单页面,并开始输入数据。

如果有些页面还未创建,则可能是您的作业队列缺少足够的内存。 有关如何添加更多内存的信息,请参见作业队列相关的项目

更全面的方法

您应该采取以下步骤:

  • 创建模板。模板决定了页面上数据的显示方式,包含了将数据存储在Cargo表中的标记,并且(通常)将页面定义为特定分类,从而具有特定页面类型。 每个页面类型通常会有一个模板,尽管有时一个页面类型会包含多个模板。 模板也可以用于汇总,显示与此页面有一定关系的所有其他页面的列表。 可以在Special:CreateTemplate页面创建模板。
  • 创建表单。现在您可以创建表单,以便用户增加和编辑各类型的页面。 每种页面类型应有一个表单;表单将填充此页面类型包含的一个或多个模板。 与之前相同,特殊页面Special:CreateForm用于创建新的表单。
  • 创建分类。每个表单中的一个模板应标记该表单创建的每一条文章,使其属于某个分类。 您应该为每个此种分类创建一个页面,并为其指定一个默认表单,以便可以使用与创建该表单相同的表单自动编辑每篇文章。 最简单的方法是使用Special:CreateCategory页面。
  • 添加到表单的链接。除了创建具有默认表单的类别之外,还应该执行其他步骤以使用户能够访问您创建的表单。 其中包括在侧栏或其他位置添加链接以便添加数据,并使用#formredlink来使指向不存在页面的红色链接指向用于创建它们的表单。 这些操作都在“链接到表单”页面中进行了说明。
  • 在侧栏或其他位置添加链接。您可以编辑侧栏(可以在“MediaWiki:Sidebar”页面上对其进行编辑)以容纳添加每种数据类型的链接。 您还可以添加指向Special:Drilldown的链接,该页面是Cargo定义的页面,它提供了一种轻松查看所有Wiki数据的简便方法。 您也可以在主页和其他位置添加此类链接。
  • 添加数据。现在您可以开始添加数据了! 只需转到表单页面,然后开始创建页面。
  • 自定义。当结构搭建完成后,您可以自定义所有内容:更改整个Wiki、各种模板以及表单的外观,添加和更改字段以及添加和更改查询。

使用语义MediaWiki

简单方法 - Special:CreateClass

页面Special:CreateClass(由页面表单定义)提供了一个助手表单,可以在一个页面内定义有关数据“类”的所有内容。 如果填写这些字段并单击“提交”,页面将自动创建必要的属性、模板、表单和分类页面。 然后,您可以转到已创建的表单页面,并开始输入数据。

如果有些页面还未创建,则可能是您的作业队列缺少足够的内存。 有关如何添加更多内存的信息,请参见作业队列相关的项目

更全面的方法

您应该采取以下步骤:

  • 创建属性。任何语义站点的基本构建块都是数据之间的连接,在语义MediaWiki中将其称为属性。 属性用于指定有关此页面主题的单个信息。 每个属性都应在您的Wiki上定义,并在“Property:”名字空间中包含一个页面。 可以在Special:CreateProperty页面创建属性。
  • 创建模板。模板决定了页面上数据的显示方式,包含了将数据存储在实际的语义信息中的标记,并且(通常)将页面定义为特定分类,从而具有特定页面类型。 每个页面类型通常会有一个模板,尽管有时一个页面类型会包含多个模板。 模板也可以用于汇总,显示与此页面有一定关系的所有其他页面的列表(参见内联查询以获取更多信息)。 可以在Special:CreateTemplate页面创建模板。
  • 创建表单。现在您可以创建表单,以便用户增加和编辑各类型的页面。 每种页面类型应有一个表单;表单将填充此页面类型包含的一个或多个模板。 与之前相同,特殊页面Special:CreateForm用于创建新的表单。
  • 创建分类。每个表单中的一个模板应标记该表单创建的每一条文章,使其属于某个分类。 您应该为每个此种分类创建一个页面,并为其指定一个默认表单,以便可以使用与创建该表单相同的表单自动编辑每篇文章。 最简单的方法是使用Special:CreateCategory页面。
  • 添加到表单的链接。除了创建具有默认表单的类别之外,还应该执行其他步骤以使用户能够访问您创建的表单。 其中包括在侧栏或其他位置添加链接以便添加数据,并使用#formredlink来使指向不存在页面的红色链接指向用于创建它们的表单。 这些操作都在“链接到表单”页面中进行了说明。
  • 在侧栏或其他位置添加链接。您可以编辑侧栏(可以在“MediaWiki:Sidebar”页面上对其进行编辑)以容纳添加每种数据类型的链接。 您也可以在主页和其他位置添加此类链接。
  • 添加数据。现在您可以开始添加数据了! 只需转到表单页面,然后开始创建页面。
  • 自定义。当结构搭建完成后,您可以自定义所有内容:更改整个Wiki、各种模板以及表单的外观,添加和更改字段以及添加和更改查询。

示例

让我们来看一个具体的示例,以“更全面的方式”从头开始建立基于页面表单的Wiki。 假设你想创建一个展示你家里所有藏书的wiki。 然后,我们将按照指定的先前步骤进行操作,其中“Cargo”与“语义MediaWiki”的某些部分有所不同。

1. 明细数据结构。 You want two kinds of pages on your wiki: one for books, and one for authors. Each book page should hold a title, an author name (or names), a genre (or genres), a year of publication, and a number of pages. Each author page should hold the author name, their country of origin, and a list of all the books they have written that you own.

2. 创建属性。

使用Cargo 使用语义MediaWiki
There is no equivalent step for Cargo. For books, there is no need to create a property for the title, since the title of each page representing a book will be the title of that book.

That leaves four fields:

  • Author(s) - using the "Create a property" page (at Special:CreateProperty), you create a property called "Was written by", of type "Page" (since each author will have their own page).
  • Genre - you create a property called "Has genre", of type "Text", and give it allowed values such as: "Art, Cookbook, Fiction, History, Poetry, Science".
  • Year of publication - you create a property called "Was published in year", of type "Number".
  • Number of pages - you create a property called "Has number of pages", of type "Number".

For author pages, you only need to create one more property:

  • Country of origin - you create a property called "Is from country", of type "Text".

3. 创建模板。 You need to create two templates, one for books and one for authors, both at the "Create a template" page at Special:CreateTemplate.

First, books:

使用Cargo 使用语义MediaWiki
At Special:CreateTemplate, set the template name to be "Book", and set the category name to be "Books".

You add to it four fields, and for each field you specify at least three values: its field name in the template source code, its display label on each page, and its type. There are a few other values you can set, but they will not be necessary for most of these fields.

  1. For the first field, set the field name to be "Authors", the label to be "Author(s)" and the type to be "Page".
You also need to check the box indicating that this field can hold a list of values (since a book can have more than one author).
  1. Click Add field and then, for the second field, the three values to be "Genres", "Genre(s)" and "String".
You again need to check the box indicating that this field can hold a list of values. You should then specify the set of allowed values; this can be done as either a simple list, or a hierarchy. You could set a simple list like "Art, Cookbook, Fiction, History, Poetry, Science", and so on; or you could set a complete hierarchy, which could look like:
* Fiction
** Science fiction
*** Cyberpunk
** Historical fiction
...and so on.
3. Click Add field and then, for the third field, set the values to be "Year", "Year of publication" and "Date" (a better choice than "Integer").
4. Click Add field and then, for the fourth field, set them to be "Number of pages", "Number of pages" and "Integer".
5. Click the Save page button.
At Special:CreateTemplate, set the template name to be "Book", and set the category name to be "Books".

You add to it four fields, and for each field you specify three values: its field name in the template source code, its display label on each page, and the semantic property it populates.

  1. For the first field, set the field name to be "Authors", the label to be "Author(s)" and the semantic property to be "Was written by", and check the box indicating that this field can hold a list of values (since a book can have more than one author);
  1. Click Add field and then, for the second field, set the three values to be "Genres", "Genre(s)" and "Has genre", and also check the box for a list of values;
  1. Click Add field and then, for the third field, set the values to be "Year", "Year of publication" and "Was published in year";
  1. Click Add field and then, for the fourth field, set the values to be "Number of pages", "Number of pages" and "Has number of pages".
  1. Click the Create button.

Next, create the template for Authors - using the "Create a template" page, you create a template called "Author", and set it to define the category "Authors".

使用Cargo 使用语义MediaWiki
  1. Just add to this template one field, for which you set the three values to be "Country", "Country of origin" and "Page".
  2. Click the Save page button.
  1. Just add to this template one field, for which you set the three values to be "Country", "Country of origin" and "Is from country".
  2. For this template, you also fill out the "Aggregation" fields in the form, since you want each author page to list all the books the author has written. Under "Semantic property", you select "Was written by", and for "Title for list" you put "Books by this author".
  3. Click the Save page button.

4. 创建表单。 You need to create two forms, one for books and one for authors:

  • Books - using the "Create a form" page (at Special:CreateForm), you make a form called "Book", select the template "Book" and click the Add button. You could also optionally add a section for the plot of the book - to do that, add a section (not a template) called "Plot". You do not do any further customizations on this form, but just save the form once you have created it.
  • Authors - using the "Create a form" page, you make a form called "Author", and add to it the template "Author". As before, you do not do any further customizations - you just save the page.

5. 创建分类。 You need to create two categories, one for books and one for authors; you have already specified these categories' names before:

  • Books - using the "Create a category" page (at Special:CreateCategory), you make a category called "Books", and give it the default form "Book".
  • Authors - using the "Create a category" page, you make a category called "Authors", and give it the default form "Author".

6. 添加到表单的链接。

使用Cargo 使用语义MediaWiki
In the text for the Book template (at Template:Book) find the portion of the display containing the tag:
{{{Authors|}}}

Replace this with something like:

{{#arraymap:{{{Authors|}}}|,|x|{{#formredlink:target=x|form=Author}} }}
The text for the Book template (at Template:Book) most likely has a portion that looks like
{{#arraymap:{{{Authors|}}}|,|x|[[Was written by::x]]}}

Replace this with something like

{{#arraymap:{{{Authors|}}}|,|x|{{#formredlink:target=x|form=Author}}{{#set:Was written by=x}}}}

This will make links to author pages that don't exist yet point to the form for creating those pages.

7. 添加数据。 Using the new "Book" form (at Form:Book), you create pages for some books; you check to make sure that both the form and the resulting pages look alright. Each book page will now have a red link to its author, that should point to the "Author" form for adding that author (you may need to refresh the page for the right link to show up). You can then add a few authors, either through these links or from the form page directly, to make sure that this setup works correctly too. Each created author's page should show a list of the books you've saved that have that person as the author.

8. 在侧栏或其他位置添加链接。 Your structures are now all set up, and you can add links to the sidebar for easy adding and viewing, by modifying the page MediaWiki:Sidebar (or its equivalent if you're using a language other than English). You can add links to the "Book" and "Author" forms to make it easy to add new ones. You could also link to Special:Drilldown (if you have Cargo installed), or Special:BrowseData (if you have the Semantic Drilldown extension installed), to let users view all the data at a glance.

页面使用模型

The Page Schemas extension is specifically intended for the automated creation of data structures, including forms. Its big advantage over the standard PF helper forms is that it can be used to create and modify these data structure pages many times, not just create them one time. It can be used with either Cargo or Semantic MediaWiki installed, or with neither one installed. If Cargo and/or SMW are installed, the Page Schemas form will include many additional form fields in order to create the additional tags needed. To create a page schema, you need to go to the category page (whether or not it has been created yet), go to the tab action for creating that page's schema, fill out the form, then go the tab action for generating pages based on that schema. 请参阅Page Schemas来获取更多信息。

快速参考指南

有两个适用于打印的快速参考指南,或称其为“备忘单”,其中包含有关页面表单的有用信息(尽管在两种情况下它们仍将其称为“语义表单”),以及其他扩展:

  • Cargo快速参考指南:PNGPDF格式
  • 语义MediaWiki快速参考指南:[$1 参见此处],PNG、PDF和SVG格式