Release status: stable
|Description||Defines a tag,
|Author(s)||Yaron Koren and Ankit Garg|
|Latest version||0.5.2 (May 2021)|
|Compatibility policy||Master maintains backwards compatibility.|
|MediaWiki 1.36||Not formally tested|
|MediaWiki 1.34||Not formally tested|
|MediaWiki 1.32||Not formally tested|
|License||GNU General Public License 2.0 or later|
|Translate the Page Schemas extension if it is available at translatewiki.net|
|Issues||Open tasks · Report a bug|
Page Schemas is a MediaWiki extension that allows for defining all the schema information about a "class", or data type - for naming, display, data input, and browsing - within a single piece of XML contained within a category page. This XML then is used to generate all the necessary additional pages needed to put the schema into effect, such as template pages and, if Page Forms is installed, form pages. The XML can be created and edited via a helper form, preventing users from having to generate or modify it manually.
Page Schemas allows other extensions to define their own fields to add to the XML, using hooks. Currently, the following extensions hook into Page Schemas:
Page Schemas defines two pages that can show up as tabs on category pages: "Edit schema" (which appears as "Create schema" if no schema exists yet) and "Generate pages". "Edit schema" allows for creating or editing the XML via the helper form, while "Generate pages" provides a button that lets the administrator create the template(s), semantic properties, form etc. automatically from the XML definition. "Generate pages" also includes checkboxes for each of the pages to be generated, to let administrators choose not to override certain wiki pages that already exist.
Any user who is allowed to edit a certain category page will see the "Edit schema/Create schema" tab for that category, and will be allowed to use that page to modify the schema.
In order to generate pages, a user must have the 'generatepages' permission. By default, this permission is given only to members of the 'sysop' user group. You can add to or modify the set of allowed users, though, by modifying the $wgGroupPermissions array in LocalSettings.php. To enable all registered users to generate pages from the schema, for instance, you would add the following:
$wgGroupPermissions['user']['generatepages'] = true;
Code and download
You can download the Page Schemas code, in .zip format, here.
You can also download the code via Git from the MediaWiki source code repository. From a command line, you can call the following:
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PageSchemas.git
To view the code online, including version history for each file, go here.
After you've obtained a 'PageSchemas' directory, place this directory within the main MediaWiki 'extensions' directory. Then, in the file 'LocalSettings.php' in the main MediaWiki directory, add either one of the following lines:
wfLoadExtension( "PageSchemas" );
include_once( "$IP/extensions/PageSchemas/PageSchemas.php" );
Visit a category page and click 'Edit schema'. See the tutorial below for more information.
Sample XML structure
Here is some sample XML, to be contained within a page called "Category:Cities", used to define the schema for pages within that category. This section defines the name of the form, and information for a single field of that class, "Population".
<PageSchema> <pageforms_Form name="City"> <standardInputs/> </pageforms_Form> <Template name="City" format="standard"> <Field name="Population"> <Label>Pop.</Label> <semanticmediawiki_Property name="Has population"> <Type>Number</Type> </semanticmediawiki_Property> <pageforms_FormInput> <InputType>text</InputType> <Parameter name="size">20</Parameter> <Parameter name="mandatory"/> </pageforms_FormInput> </Field> ... </Template> ... <Section name="History" level="2"> <pageforms_PageSection> <Parameter name="rows">10</Parameter> <Parameter name="mandatory"/> </pageforms_PageSection> </Section> ... </PageSchema>
Importing into Page Schemas
The following utilities can import data structures (both MediaWiki-based and external) into the Page Schemas format:
- db-to-smw-page-schemas, a script in Node.js that queries a database's schema and generates corresponding category pages with Page Schemas XML.
- A Java Library that allows to read and write PageSchemas directly to a wiki using the MediaWiki API. Feel free to contact the author via his github account if you'd like to learn more details or give feedback.
- The generating of pages is done via MediaWiki "jobs", to ensure that the system is not overloaded if many pages are generated at the same time. This means that the pages might not be generated immediately, and may take minutes, hours or even longer to complete. Normally, jobs get activated every time a page is viewed on the wiki; to speed up the process (or slow it down), you can change the number of jobs run when a page is viewed; the default is 1. For information on how to change it, see the $wgJobRunRate page. To force the wiki to run all jobs immediately, execute the script runJobs.php.
- Page Schemas uses XML tag names starting with
<pageforms_FormInput>) while earlier versions used tag names starting with
<semanticforms_FormInput>) since the Page Forms extension was formerly known as Semantic Forms. If you upgrade from previous versions then you should manually change all occurrences of
pageforms_. An easy way to do that if there are lots of pages would be with the Replace Text extension.
Page Schemas was created by Ankit Garg as part of the 2011 Google Summer of Code, and was mentored by Yaron Koren. It was later modified significantly, and is currently maintained, by Yaron Koren. Parts of it are based on the TemplateInfo extension, by Yaron Koren and Roan Kattouw.
Page Schemas is currently at version 0.5.2.
The version history for Page Schemas is:
- 0.1 - August 23, 2011 - initial version
- 0.2 - October 13, 2011 - overhaul; many changes to display and code structure
- 0.3 - October 25, 2011 - extensions hook into Page Schemas via a single hook and a subclass, instead of a variety of hooks; various other changes
- 0.3.1 - August 24, 2012 - template display format can be selected; various small fixes and improvements
- 0.4 - October 7, 2013 - handling added for page sections; "Generate pages" UI improved; handling added for MW 1.21
- 0.4.1 - December 9, 2013 - template-specific attributes appear only for multiple-instance templates; handling removed for MW 1.16
- 0.4.2 - February 11, 2014 - "namespace" attribute added for fields; handling removed for MW 1.17
- 0.4.3 - May 8, 2014 - fix for <PageSchema> tag when called from within a script; i18n changed to use JSON files
- 0.4.5 - February 17, 2015 - support added for template attributes for non-multiple-instance templates
- 0.4.6 - February 3, 2016 - improved handling of bad XML; improved handling for recent MW versions; other fixes
- 0.4.7 - May 23, 2018 - extension.json added; more directories added; handling removed for MW 1.18 - 1.22; various fixes
- 0.4.8 - June 8, 2018 - fix for schema saving bug introduced in version 0.4.7
- 0.4.9 - January 17, 2019 - bug fixes
- 0.5 - December 9, 2019 - handling removed for 1.23 - 1.27; handling improved for PHP 7
- 0.5.1 - July 29, 2020 - re-added Page Forms fields in "edit schema", missing since 2016; improved handling for MW 1.32+; fixed permission checking for MW < 1.33
- 0.5.2 - May 6, 2021 - changed some inputs to use OOUI; code improvements
Features and improvements that it would be great to add to Page Schemas include:
- Allowing Page Forms to use the Page Schemas XML directly when generating a form, instead of requiring a separate form definition.
- More tools to export/import data structure files in formats such as UML and SQL to/from the Page Schemas XML format.
- Making use of the ContentHandler to store each XML schema in its own page, instead of as part of a category page.