Automated Values
Define rules to automatically set labels or aliases based on Statement values
On this page
External links
Automated Values for Wikibase
Professional Wiki created Automated Values. We are Wikibase developers that provide professional Wikibase software development and Wikibase hosting.
We thank the Luxembourg Ministry of Culture for funding initial development.
Usage documentation
The core building block of this extension are so-called "Rules".
You can read the bellow step-by-step explanation or look immediately at example.json.
A Rule consists of zero or more Entity Criteria, which allow you to specify which Wikibase entities the Rule applies to. For instance "all entities where P1 is Q1", which might translate to "all entities instanceof Person".
{
"when": [
{
"statement": "P1",
"equalTo": "Q1"
}
]
}
A rule can also have zero or more Build Specifications. These describe how to automatically build values on matching Entities, and which languages to update. They are available both for Labels and Aliases.
{
"buildLabel": {
"en": {
"P2": "$"
}
},
"buildAliases": {
"*": {
"P5.P3": "President ",
"P5": "$",
"P5.P4": ", $"
}
}
}
Rules can be defined on page MediaWiki:AutomatedValues
.
Alternatively they can be defined in LocalSettings.php,
see the Configuration section.
To define rules for your wiki, simply head over to MediaWiki:AutomatedValues
and create the page.
This page only accepts JSON that adheres to the JSON Schema.
If you enter invalid JSON, the page will refuse to save your changes.
Editing of pages in the MediaWiki
namespace, which includes MediaWiki:AutomatedValues
,
is likely restricted to users with elevated permissions. By default, MediaWiki restricts editing in this namespace
to people with the editinterface
right. For more information, go to the page
Special:ListGroupRights#Namespace_restrictions
on your wiki.
You can find a complete and valid example of a list of Rules,
that could be placed on MediaWiki:AutomatedValues
,
at example.json.
Supported Entity Criteria
At the moment it is only possible to check equality of statement main values, and only for Properties of type String or EntityId.
A Rule can contain multiple Entity Criteria, in which case they all need to match for the Rule to be applied. A Rule can also contain no Entity Criteria, in which case it will be applied to all Entities.
Build Specifications
Build Specifications are essentially templates that describe how to build the values.
You can have different Build Specifications for different languages:
{
"buildLabel": {
"en": {
"P2": "$"
},
"de": {
"P3": "$"
}
}
}
You can also specify *
instead of a language code,
in which case the Build Specification will be applied to all default languages.
See the Configuration section for how to set the default languages.
If the default languages are not set, *
will be ignored.
{
"buildLabel": {
"*": {
"P2": "$"
},
"de": {
"P3": "$"
}
}
}
The $
symbol is replaced by the Main Value of the first Statement with the specified Property.
Currently only strings are supported. Preferred Statements will be used over those with a Normal rank.
If there is no matching Statement, that part of the value is omitted.
If the resulting value is an empty string, it will be ignored.
It is possible to combine multiple values and to include whitespace and other characters.
{
"de": {
"P3": "$ ",
"P4": "$",
"P5": ", $"
}
}
Assuming P4 is foo
, P5 is bar
and there not being a P3 Statement,
the above would result in foo, bar
.
You can also get the value of Qualifiers. This is done via the P1.P2
notation,
where P1
is the Property of the Statement, and P2
is the Property of the Qualifier.
{
"de": {
"P3": "$ ",
"P3.P10": "$",
"P3.P11": ", $"
}
}
In case of Aliases, all matching Statements will be used, possibly resulting in multiple Aliases. The above snippet would create two Aliases, if there are two Statements with Property P3. This is only supported for Build Specifications that use a single Statement-level Property. The below snippet would result in only a single Alias, even if there are many Statements.
{
"de": {
"P3": "$",
"P4": "$"
}
}
When Rules are applied
Rules are applied on every edit. They are not applied outside of edits. So if you are importing a dataset and wish the Rules to be applied, you need to first define the Rules and then do the import. Alternatively you can trigger an edit of each page with some MediaWiki script, though this functionality is not provided by the Automated Values extension.
Rules are applied in order. In other words, the second Rule can override values set by the first Rule.
Limitations
- When editing an Entity, the UI will not immediately show the updated generated values. A page reload is needed.
- You can only filter Entities based on Statement Main Values of type String or Entity ID.
- You can only generate Labels and Aliases.
- Rules are only applied to Entities on edit. Changing a rule will not automatically apply it everywhere.
- The editing UI is still present for automatically generated values, possibly causing confusion.
Installation
Requirements
- PHP 7.4 or later
- MediaWiki 1.35 or later
- Wikibase Repository
Load and enable
Load the extension using Composer:
COMPOSER=composer.local.json composer require --no-update professional-wiki/automated-values:~1.0
Enable the extension by adding the following to your LocalSettings.php:
wfLoadExtension( 'AutomatedValues' );
You can verify the installation by checking your wiki's Special:Version page.
To enable more convenient editing of MediaWiki:AutomatedValues
,
you can optionally install the CodeMirror extension.
Configuration
Configuration can be changed via LocalSettings.php.
Default languages
List of languages to create values for via *
build specifications.
Variable:
$wgAutomatedValuesDefaultLanguages
Default:
[]
Example:
$wgAutomatedValuesDefaultLanguages = [ 'en', 'de', 'nl' ];
Rules
List of rules applied to the wiki. In JSON format,
following the JSON Schema at schema.json.
Gets combined with rules defined on page MediaWiki:AutomatedValues
.
Variable:
$wgAutomatedValuesRules
Default:
""
Example:
$wgAutomatedValuesRules = '
[
{
"buildLabel": {
"en": {
"P2": "$"
}
}
}
]
';
Caution: invalid JSON will be ignored. No error will be shown, the intended rules will just not be applied.
Enable in-wiki rules
If it should be possible to define rules via MediaWiki:AutomatedValues.
Variable:
$wgAutomatedValuesEnableInWikiRules
Default:
true
Example:
false
The page MediaWiki:AutomatedValues
will always be available.
If this configuration is set to false
, its contents will be ignored.
Wikibase Hosting
Check out our
tailored Wikibase hosting
and
Wikibase cloud hosting
services.
Both include Automated Values and many other MediaWiki extensions.

More MediaWiki Extensions
Professional MediaWiki Services
MediaWiki services by the authors of Automated Values

Get superior results from the best MediaWiki developers with a proven track record of creating MediaWiki extensions & integrations.

Make your wiki look great! Use a time-tested responsive MediaWiki theme, or have us create a custom MediaWiki skin for you.

Let us take care of your wiki. We are MediaWiki hosting experts and provide cloud hosting, dedicated hosting, and on-premise hosting.

Bring your wiki to the next level by leveraging our MediaWiki expertise. From strategic planning to wikitext, we have you covered.

Migrate your wiki with confidence. We move your MediaWiki to a new home, or we help you migrate from another system to MediaWiki.

Keep your MediaWiki up-to-date and secure. We offer MediaWiki maintenance services to keep your wiki running smoothly.