Demo VisualData 1.0 / Dependent values

Dependent values: Difference between revisions

From Wikisphere
Jump to navigation Jump to search
No edit summary
Tag: 2017 source edit
No edit summary
Tag: 2017 source edit
Line 99: Line 99:
}}
}}
    
    
This is a page with an infobox that demonstrates the use of VisualData ([https://gerrit.wikimedia.org/r/c/mediawiki/extensions/VisualData/+/968230 latest version]) used as a [https://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD]
Click the button below to edit the article's metadata through a popup or the tab "Edit semantic" among the article's actions.
{{#visualdataform: Book
|title = edit infobox and page
|action = edit
|edit-page = {{FULLPAGENAME}}
|return-page =
|view = popup
|popup-size = medium
|css-class =
|pagename-formula =
|edit-freetext = true
|edit-categories = false
|edit-content-model = false
|default-categories =
|default-content-model = wikitext
|layout-align = top
|popup-help = true
|submit-button-text =
|layout = tabs
|submit-button-text =
|validate-button-text =
}}
The popup is rendered using the following code
<pre>
{{#visualdataform: Book
|title = edit infobox and page
|action = edit
|edit-page = {{FULLPAGENAME}}
|return-page =
|view = popup
|popup-size = medium
|css-class =
|pagename-formula =
|edit-freetext = true
|edit-categories = false
|edit-content-model = false
|default-categories =
|default-content-model = wikitext
|layout-align = top
|popup-help = true
|submit-button-text =
|layout = tabs
|submit-button-text =
|validate-button-text =
}}
</pre>
A VisualData' form can edit whatever page (through the parameter <code>edit-page</code>, and create new pages with user-defined title or using a pagename formula. It is [https://json-schema.org/ json/schema] compliant<ref>It does not yet support allOf, anyOf, oneOf, and $refs both in the editor and in the viewer</ref>  and can handle subitems, multiple fields and multiple sub items. It is deeply integrated with the Mediawiki's [https://doc.wikimedia.org/oojs-ui/master/demos/ OOUI library] and uses a lot or most of its features.
'''In the latest version can query properties and nested properties, as well as render them using templates and nested templates and does not rely on [https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki SemanticMediawiki]'''.
The infobox is rendered through the following code:
<pre>
{{#visualdataprint: {{FULLPAGENAME}}
|?cover
|?title
|?authors/name
|?authors/email
|schema=Book
|template=Book
|template?authors=Book authors
|format=template
}}
</pre>
This is a SemanticMediawiki-like parser function that can be used as a shorthand to invoke the more complex <code> {{#visualdataquery }} </code> parser function that can handle multi-page results and provides a basic query language. (more about this on the official page of the extension to be updated soon)
The results are rendered on the page using 2 templates, [[Template:Book]] and [[Template:Book authors]]. The second is used as a nested template rendered inside the parent template ([[Template:Book]]) entitled to render the properties with path <code>authors</code>. ''' Note that the parent template must include a reference to the name of the child template since both values and template's containers are passed as named parameters.'''
The form's schema(s) (a form can contain an arbitrary number of schemas, and a schema an arbitrary number of items and subitems) can be edited using this [[Special:ManageSchemas|Special page]] or [https://wikisphere.org/w/index.php?title=Test_visualdata_2.0&action=editsemantic this interface] (tab Edit semantic, edit icon on the right and then "Manage schemas")
The related [[VisualDataSchema:Book|schema]] created by the UI contains an hidden property "name" that is filled-in with the compounded value of the fields <code>first_name</code> and <code>last_name</code>.
Also, the cover file name contains a value-formula, that allows the file to be saved with the article-id as prefix (also for new articles) which is useful to easily upload on the wiki files with similar names.
Have fun with this extension !!





Revision as of 11:48, 4 February 2024

The following form demonstrates the use of VisualData to query and record dependent values (the classical case is the country-state-city relationship) and to easily create and store them on your wiki through a couple of maintenance scripts. It uses the schema VisualDataSchema:Dependent_values created through the Schema Builder (see special page Special:ManageSchemas then open the schema "Dependent values").


form is loading...


The first field (country) is a OOUI DropdownInputWidget with items taken from the template Template:Countries.

The second field (state) is a LookupElement with query

[[name::<country>]][[states/name::<value>~]]

where <country> is the name of the first field and <value> is the value being inserted in the input.. The requested printout is states/name that matches the path properties/states/items/properties/name in the schema VisualDataSchema:Country. (where only relevant property names have to be concatenated, leaving aside properties and items that belong to the schema structure). The query will search json data related to the schema "Country" with value of the property name equal to the value of the first field, and value of the property states/name equal to the state input value.

The third field (city) uses this query

[[name::<country>]][[states/name::<state>]][[states/cities/name::<value>~]]

The query as above will search json data related to the schema "Country" with value of the property name equal to the value of the first field, value of the property states/name equal to the second field, and value of the property states/cities/name equal to the city input value. The requested printout in this case is states/cities/name.


The query searches within a database of 250 wiki pages with json content model like Data:Countries/Afghanistan, containing more than 620,000 entries in total.

The database can been created downloading this data countries%2Bstates%2Bcities.json from github.com/dr5hn/countries-states-cities-database and then importing them on your wiki using the following maintenance command:

php extensions/VisualData/maintenance/ImportData.php --file "[path-to-the following-file]/countries+states+cities.json" --schema Country --pagename-formula "Data:countries/<name>" --main-slot

The script takes only a few minutes to create all the required entries (including the related schema if it does not exist) and the data can be rebuilt any time through the following command:

php extensions/VisualData/maintenance/RebuildData.php


This is the wikitext used to create the form itself:


{{#visualdataform: Dependent values
|title = Dependent values
|action = create
|edit-page = 
|return-page = 
|view = inline
|popup-size = medium
|css-class =
|pagename-formula = 
|edit-freetext = false
|edit-categories = false
|edit-content-model = false
|default-categories =
|default-content-model = json
|layout-align = top
|popup-help = true 
|submit-button-text =
|layout = tabs
|submit-button-text =
|validate-button-text =
}}


Have fun using your wiki as an open-source database management system !!




See also