Skip novalue/somevalue instead of reporting violation

Checkers that use the value of a statement previously reported a
violation for novalue/somevalue statements. This is rarely appropriate,
since semantically, those values should usually be accepted – the
constraints simply don’t apply in those cases. The checkers are updated
to return a compliance result in those cases instead of a violation, and
tests for the old behavior are updated to expect compliance instead.

DiffWithinRangeChecker also reported a violation if the statement of the
referenced property was novalue/somevalue; instead, it skips those
statements now, and either uses the first value statement it finds or
reports a violation due to missing statement otherwise. Tests are added
for this behavior.

Tests for CommonsLinkChecker and FormatChecker used to use novalue
statements to test that those checkers still check deprecated
statements; they have been changed to check actual statements that
violate constraints.

Two messages that are no longer used (generic “must have a value” and
DiffWithinRangeChecker-specific “referenced property must have a value”)
are removed.

Bug: T172130
Change-Id: I8bb33ead10770c938d04b00dd637924d4599a752
18 files changed
tree: 79c7b6ed647ec20ddaa943ed94cbe966aba7b443
  1. api/
  2. build/
  3. i18n/
  4. includes/
  5. maintenance/
  6. modules/
  7. specials/
  8. sql/
  9. tests/
  10. .coveralls.yml
  11. .eslintignore
  12. .eslintrc.json
  13. .gitignore
  14. .gitreview
  15. .jscsrc
  16. .jshintrc
  17. .mailmap
  18. .stylelintrc
  19. .travis.yml
  20. CODE_OF_CONDUCT.md
  21. composer.json
  22. COPYING
  23. extension.json
  24. Gruntfile.js
  25. package.json
  26. phpcs.xml
  27. phpunit.xml.dist
  28. README.md
  29. WikibaseQualityConstraints.alias.php
  30. WikibaseQualityConstraints.php
  31. WikibaseQualityConstraintsHooks.php
README.md

Wikibase Quality Constraints

Build Status Coverage Status Scrutinizer Code Quality

This is a complementary extension for the Wikibase Quality base extension. It performs constraint checks in Wikibase.

Installation

If you have already installed a complementary Wikibase Quality extension you can skip the first two steps and just add the repository (second entry in "repositories" and the required version (last entry in "require") to the composer.local.json.

  • Create the file composer.local.json in the directory of your mediawiki installation.

  • Add the following lines:

{
    "repositories": [
        {
            "type": "git",
            "url": "https://gerrit.wikimedia.org/r/mediawiki/extensions/WikibaseQuality"
        },
        {
            "type": "git",
            "url": "https://gerrit.wikimedia.org/r/mediawiki/extensions/WikibaseQualityConstraints"
        }
    ],
    "require": {
        "wikibase/quality": "@dev",
        "wikibase/wikibase": "@dev",
        "wikibase/constraints": "1.x-dev"
    }
}
  • Run composer install.

  • If not already done, add the following lines to your LocalSettings.php to enable Wikibase:

$wgEnableWikibaseRepo = true;
$wgEnableWikibaseClient = false;
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";
  • Run php maintenance/update.php --quick.

  • Last but not least, you need to fill the constraints table - for that you need the constraints from templates script.
    Follow the instruction in the README to create a csv file.
    Run php maintenance/runScript.php extensions/Constraints/maintenance/UpdateConstraintsTable.php --csv-file <path_to_csv_file>.

  • Optional: to enable importing constraints from statements on properties, add the following line to your LocalSettings.php:

    $wgWBQualityConstraintsEnableConstraintsImportFromStatements = true;
    

Gadget

The extension includes a gadget that checks constraints on entity pages and displays violations on statements. The gadget is loaded via ResourceLoader and can be used with the following definition in MediaWiki:Gadgets-definition:

* checkConstraints[ResourceLoader|dependencies=wikibase.quality.constraints.gadget]|checkConstraints.js

checkConstraints.js (page title: MediaWiki:Gadget-checkConstraints.js) is only required because the the Gadgets extension does not support gadgets without any JS files. It can be empty (or even nonexistent), but some explanatory comment is recommended, for example:

// this gadget resides in the wikibase.quality.constraints.gadget ResourceLoader module
// its source code is available in the gadget* files at https://github.com/wikimedia/mediawiki-extensions-WikibaseQualityConstraints/tree/master/modules

To make the gadget display nicely in the preferences and on Special:Gadget, MediaWiki:Gadget-checkConstraints should be created, e. g. with the following content:

''checkConstraints'': Shows property constraint reports for statements on an item or property page ([[Help:Property constraints portal|help]])

The gadget can also be loaded directly as a standalone script, e. g. as a user script, by simply including modules/gadget.js in common.js and modules/gadget.css in common.css.

Data import

For local development, it’s easiest to import some data from Wikidata. You can use the WikibaseImport extension to do this; once you have installed it, you can use the following command to import the essential entities that this extension needs (stuff like the “instance of” property):

# working directory should be the MediaWiki installation folder, i.e. where LocalSettings.php is
jq -r '.config | with_entries(select(.key | endswith("Id"))) | .[] | .value' extensions/WikibaseQualityConstraints/extension.json | php extensions/WikibaseImport/maintenance/importEntities.php --stdin

Afterwards, export the resulting entity IDs to your local config (since they’ll be different than on Wikidata):

# from the MediaWiki installation folder
extensions/WikibaseQualityConstraints/maintenance/exportEntityMapping
# or directly from the extension folder
maintenance/exportEntityMapping