RandomSec/extensions/wikidata/module/scripts/wikibase-manifest-schema-v1.js
Lu Liu 7d4e182c75
Extend Wikidata extension to support arbitrary Wikibase instances (#2810)
Closes #1640. All Wikibase-dependent parameters, which were previously hard-coded for Wikidata, are now described in a JSON manifest. The manifest is currently constructed by hand, but, in the future, will hopefully be published by each Wikibase instance at a standard location.

* setup the manifest framework

* add dependency mechanism to scrutinizers & update tests

* add json creators to constraint entities

* adapt the backend (units tests are to be updated)

* remove the call to prepareDependencies() in the constructor

* update code according to review feedback

* update scrutinizers tests

* fix typo & update ConstraintsV1

* log if a scrutinizer is skipped

* update versioning handling in the backend

* correct the order of "actual" and "expected" for assertEquals method

* use regex to check manifest versions

* 1. add wikibase-manager.js, wikibase-dialog.js, etc.
2. move dialog/schema-alignment-dialog.js -> schema-alignment.js
3. remove unused schema-alignment-dialog.html
4. change most mentions of "Wikidata" to "Wikibase"

* support saving cookies for different Wikibases & fix LoginCommandTest

* fix schema related tests

* removed unused WikibaseCredentials

* include MediaWiki API endpoint in the schema

* fetch language codes for different Wikibases

* fix lgtm-bot alerts

* keep a connection map (MediaWiki API endpoint => Connection) in ConnectionManager

* simplify the constraint configurations of the manifest and remove lots of unnecessary code.

* add slash to the end of mediawiki.root

* add manifest schema and use ajv to validate the manifest

* remove JSONP support (Wikibase manifest host should support CORS)

* save manifests on manifest update

* add unit tests for Manifest

* include the exception in logger.error() method to make it easier to debug

* include the message of ManifestException when calling respondError

* test multiple connections

* test no manifest & test invalid manifest

* adapt manage-account-dialog.js to support multiple Wikibase connections

* update instance/subclass of related translations

* beautify import-schema-dialog.html

* use "${lang}" variable in the reconciliation service endpoint of the manifest

* adapt schema-alignment.js after introducing "${lang}" variable in the reconciliation service endpoint

* use WikibaseManager.getSelectedWikibaseApi() in SchemaAlignment._getPropertyType

* replace more mentions of "Wikidata" to "Wikibase"

* use WikibaseManager.getSelectedWikibaseApi() in previewrenderer.js

* support fetching language codes of different Wikibases in the frontend

* skip EditInspector if missing 'property_constraint_pid' in the manifest

* improve unit tests for fetching lang codes

* skip scrutinizers depending on fetcher if 'property_constraint_pid' is missing in the manifest

* make sure the schema alignment panel is set up before rendering

* fix preview bug

* add getters of "instance of" and "subclass of" to the Manifest interface and use them in NewItemScrutinizer

* fix hardcode for Wikidata in WbItemVariable

* rename 'entity_prefix' to 'site_iri' and move it from 'manifest.wikibase.properties' to 'manifest.wikibase'

* include oauth configurations in the manifest & support logging in with owner-only consumer for Wikibases with the OAuth extension

* correct schema fallback logic

* select default wikibase according to the saved schema

* include maxlag in the manifest

* [backend] move maxlag setting from preferences to request parameter

* support setting maxlag when uploading edits

* rename "Manage Wikibase" to "Select Wikibase instance" and localize it

* fix manifest updating bug

* include EditGroups in the manifest

* add the reconciliation service from the manifest to standard services if it's not present yet when adding a new manifest

* update according to review feedback

1. use inherited color variable
2. rename 'gridwroks' to 'openrefine'
3. remove unnecessary 'async: true'
4. add 'format: url' validation to urls to the schema

* rename 'wikibasePrefix' to 'siteIri'
2020-08-22 11:58:56 -04:00

127 lines
5.2 KiB
JavaScript

const WikibaseManifestSchemaV1 = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "TBD",
"type": "object",
"description": "The schema validates Wikibase manifests with version 1.x. The manifest contains configurations of basic information (e.g. URL of the main page), extensions (e.g. OAuth extension) or external services (e.g. Reconciliation service) of a Wikibase",
"properties": {
"version": {
"type": "string",
"pattern": "^1\\.[0-9]+$",
"description": "The version of the Wikibase manifest, in the format of 1.x"
},
"mediawiki": {
"type": "object",
"description": "The configurations of the MediaWiki engine",
"properties": {
"name": {
"type": "string",
"description": "The name of the Wikibase, such as 'Wikidata'"
},
"root": {
"type": "string",
"format": "url",
"pattern": "^.*/$",
"description": "The URL of the root of the Wikibase, such as 'https://www.wikidata.org/wiki/'. The trailing slash cannot be omitted"
},
"main_page": {
"type": "string",
"format": "url",
"description": "The URL of the main page of the Wikibase, such as 'https://www.wikidata.org/wiki/Wikidata:Main_Page'"
},
"api": {
"type": "string",
"format": "url",
"description": "The MediaWiki API endpoint of the Wikibase, such as 'https://www.wikidata.org/w/api.php'"
}
},
"required": ["name", "root", "main_page", "api"]
},
"wikibase": {
"type": "object",
"description": "The configurations of the Wikibase extension",
"properties": {
"site_iri": {
"type": "string",
"format": "url",
"pattern": "^.*/$",
"description": "The IRI of the Wikibase, such as 'http://www.wikidata.org/entity/'. This should match the IRI prefixes used in RDF serialization. Be careful about using 'http' or 'https', because any variation will break comparisons at various places. The trailing slash cannot be omitted"
},
"maxlag": {
"type": "integer",
"description": "The default maxlag of this Wikibase. For Wikidata, the default value is 5 (seconds)"
},
"properties": {
"type": "object",
"properties": {
"instance_of": {
"type": "string",
"description": "The 'instance of' qid of the Wikibase ('P31' for Wikidata)"
},
"subclass_of": {
"type": "string",
"description": "The 'subclass of' qid of the Wikibase ('P279' for Wikidata)"
}
},
"required": ["instance_of", "subclass_of"]
},
"constraints": {
"type": "object",
"description": "Constraints related qids and pids, not required since the constraints extension may not be installed",
"properties": {
"property_constraint_pid": {
"type": "string",
"description": "The property constraint pid of the Wikibase ('P2302' for Wikidata)"
}
},
"patternProperties": {
"^.*$": {
"type": "string",
"description": "If a pid/qid is missing, constraint checks depending on it will be skipped"
}
},
"required": ["property_constraint_pid"]
}
},
"required": ["site_iri", "maxlag", "properties"]
},
"oauth": {
"type": "object",
"description": "The configurations of the OAuth extension. Not required. Configuring this if and only if the OAuth extension is installed",
"properties": {
"registration_page": {
"type": "string",
"format": "url",
"description": "The url of the OAuth consumer registration page, 'https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose' for Wikidata"
}
},
"required": ["registration_page"]
},
"reconciliation": {
"type": "object",
"description": "The configurations of the default reconciliation service of the Wikibase",
"properties": {
"endpoint": {
"type": "string",
"format": "url",
"pattern": "^.*\\${lang}.*$",
"description": "The default reconciliation API endpoint of the Wikibase, the endpoint should include the language variable '${lang}', such as 'https://wdreconcile.toolforge.org/${lang}/api'"
}
},
"required": ["endpoint"]
},
"editgroups": {
"type": "object",
"description": "The configurations of the EditGroups service of the Wikibase",
"properties": {
"url_schema": {
"type": "string",
"pattern": "^.*\\${batch_id}.*$",
"description": "The URL schema used in edits summary. This is used for EditGroups to extract the batch id from a batch of edits and for linking to the EditGroups page of the batch. The URL schema must contains the variable '${batch_id}', such as '([[:toollabs:editgroups/b/OR/${batch_id}|details]])' for Wikidata"
},
},
"required": ["url_schema"]
}
},
"required": ["version", "mediawiki", "wikibase", "reconciliation"]
};