CINXE.COM
mediawiki/extensions/WikibaseQualityConstraints - Gitiles
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>mediawiki/extensions/WikibaseQualityConstraints - Gitiles</title><link rel="stylesheet" type="text/css" href="/r/plugins/gitiles/+static/base.css"><link rel="stylesheet" type="text/css" href="/r/plugins/gitiles/+static/doc.css"><!-- default customHeadTagPart --></head><body class="Site"><header class="Site-header"><div class="Header"><!-- default customHeader --><div class="Header-title">Gitiles</div><div class="Header-menu"> <a class="Header-menuItem" href="https://gerrit.wikimedia.org/r/">Code Review</a> <a class="Header-menuItem" href="https://gerrit.wikimedia.org/r/login/plugins%2Fgitiles%2Fmediawiki%2Fextensions%2FWikibaseQualityConstraints">Sign In</a> </div></div></header><div class="Site-content"><div class="Container "><div class="Breadcrumbs"><a class="Breadcrumbs-crumb" href="/r/plugins/gitiles/?format=HTML">gerrit.wikimedia.org</a> / <a class="Breadcrumbs-crumb" href="/r/plugins/gitiles/mediawiki/">mediawiki</a> / <a class="Breadcrumbs-crumb" href="/r/plugins/gitiles/mediawiki/extensions/">extensions</a> / <span class="Breadcrumbs-crumb">WikibaseQualityConstraints</span></div><h2 class="RepoDescription">QualityConstraints extension for Wikibase</h2><div class="CloneRepo"><div class="CloneRepo-title">Clone this repo:</div><input id="clone-repo-input" type="text" class="u-monospace CloneRepo-command" readonly="readonly" value="git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/WikibaseQualityConstraints"></div><div class="RepoShortlog"><div class="RepoShortlog-refs"><div class="RefList RefList--responsive"><h3 class="RefList-title">Branches</h3><ul class="RefList-items"><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/master">master</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/REL1_39">REL1_39</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/REL1_40">REL1_40</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/REL1_41">REL1_41</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/REL1_42">REL1_42</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/REL1_43">REL1_43</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/1.44.0-wmf.3">wmf/1.44.0-wmf.3</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/1.44.0-wmf.4">wmf/1.44.0-wmf.4</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/1.44.0-wmf.5">wmf/1.44.0-wmf.5</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/branch_cut_pretest">wmf/branch_cut_pretest</a></li></ul></div><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+refs">More...</a><div class="RefList RefList--responsive"><h3 class="RefList-title">Tags</h3><ul class="RefList-items"><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_38">REL1_38</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_37">REL1_37</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_36">REL1_36</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_35">REL1_35</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_34">REL1_34</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_33">REL1_33</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_32">REL1_32</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_31">REL1_31</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_30">REL1_30</a></li><li class="RefList-item"><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/tags/REL1_29">REL1_29</a></li></ul></div><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+refs">More...</a></div><div class="RepoShortlog-log"><ol class="CommitLog"><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/38c5316286984af3a9755b903155a38483304b22">38c5316</a> <a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/38c5316286984af3a9755b903155a38483304b22">build: Updating cross-spawn to 7.0.6</a> <span class="CommitLog-author" title="tools.libraryupgrader@tools.wmflabs.org">by libraryupgrader</span> <span class="CommitLog-time" title="Wed Nov 20 07:09:18 2024 +0000">· 8 days ago</span> <a class="CommitLog-branchLabel" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/master">master</a> <a class="CommitLog-branchLabel" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/1.44.0-wmf.5">wmf/1.44.0-wmf.5</a> <a class="CommitLog-branchLabel" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/branch_cut_pretest">wmf/branch_cut_pretest</a> <a class="CommitLog-branchLabel" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next">wmf/next</a></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/5f6fa357f494a3888bd9faae7ca084f6681f457c">5f6fa35</a> <a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/5f6fa357f494a3888bd9faae7ca084f6681f457c">Localisation updates from https://translatewiki.net.</a> <span class="CommitLog-author" title="l10n-bot@translatewiki.net">by Translation updater bot</span> <span class="CommitLog-time" title="Mon Nov 18 08:25:44 2024 +0100">· 10 days ago</span> <a class="CommitLog-branchLabel" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/1.44.0-wmf.4">wmf/1.44.0-wmf.4</a></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/f57861bc8b2a7a5f72e2a34080fdd5ba0e74ed0b">f57861b</a> <a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/f57861bc8b2a7a5f72e2a34080fdd5ba0e74ed0b">Merge "More narrow return type for DefaultConfig trait"</a> <span class="CommitLog-author" title="jenkins-bot@gerrit.wikimedia.org">by jenkins-bot</span> <span class="CommitLog-time" title="Tue Nov 12 16:01:59 2024 +0000">· 2 weeks ago</span></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/e482feea0660cb721a45ad4f331ee4e86005b8c3">e482fee</a> <a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/e482feea0660cb721a45ad4f331ee4e86005b8c3">composer.json: Upgrade wikimedia/purtle to 2.0.0</a> <span class="CommitLog-author" title="reedy@wikimedia.org">by Reedy</span> <span class="CommitLog-time" title="Mon Nov 11 02:01:51 2024 +0000">· 2 weeks ago</span> <a class="CommitLog-branchLabel" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/1.44.0-wmf.3">wmf/1.44.0-wmf.3</a></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/e387b88fca9121e454c561f58269b59b09c36afc">e387b88</a> <a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/e387b88fca9121e454c561f58269b59b09c36afc">Merge "Remove null default argument from some nullable parameters"</a> <span class="CommitLog-author" title="jenkins-bot@gerrit.wikimedia.org">by jenkins-bot</span> <span class="CommitLog-time" title="Thu Nov 07 21:03:54 2024 +0000">· 3 weeks ago</span></li></ol><nav class="LogNav"><a class="LogNav-next" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+log">More »</a></nav><div class="doc RepoIndexDoc"><h1><a class="h" name="Wikibase-Quality-Constraints" href="#Wikibase-Quality-Constraints"><span></span></a><a class="h" name="wikibase-quality-constraints" href="#wikibase-quality-constraints"><span></span></a>Wikibase Quality Constraints</h1><p><a href="https://scrutinizer-ci.com/g/wikimedia/mediawiki-extensions-WikibaseQualityConstraints/?branch=master"><img src="https://scrutinizer-ci.com/g/wikimedia/mediawiki-extensions-WikibaseQualityConstraints/badges/quality-score.png?b=master" alt="Scrutinizer Code Quality" /></a></p><p>Extension to Wikibase Repository that performs constraint checks.</p><h2><a class="h" name="Installation" href="#Installation"><span></span></a><a class="h" name="installation" href="#installation"><span></span></a>Installation</h2><ul><li><p>Clone <code class="code">WikibaseQualityConstraints</code> inside the <code class="code">extensions/</code> directory of your MediaWiki installations.</p><pre class="code"><span class="pln">cd </span><span class="pun">.../</span><span class="pln">extensions</span><span class="pun">/</span><span class="pln"> git clone https</span><span class="pun">://</span><span class="pln">gerrit</span><span class="pun">.</span><span class="pln">wikimedia</span><span class="pun">.</span><span class="pln">org</span><span class="pun">/</span><span class="pln">r</span><span class="pun">/</span><span class="pln">mediawiki</span><span class="pun">/</span><span class="pln">extensions</span><span class="pun">/</span><span class="typ">WikibaseQualityConstraints</span><span class="pln"> </span></pre></li><li><p>Install dependencies. The simplest way is to set up <a href="https://www.mediawiki.org/wiki/Composer#Using_composer-merge-plugin">composer-merge-plugin</a> and then run <code class="code">composer install</code> in the MediaWiki base directory; alternatively, you can run <code class="code">composer install</code> inside the <code class="code">WikibaseQualityConstraints</code> directory.</p></li><li><p>Load the extension.</p><pre class="code"><span class="pln">wfLoadExtension</span><span class="pun">(</span><span class="pln"> </span><span class="str">'WikibaseQualityConstraints'</span><span class="pln"> </span><span class="pun">);</span><span class="pln"> </span></pre></li><li><p>Run <code class="code">php maintenance/update.php --quick</code>.</p></li><li><p>Configure the extension. You can find the configuration settings with documentation in <code class="code">extension.json</code>. (Note that the variable name for <code class="code">LocalSettings.php</code> always begins with <code class="code">wg</code>, e. g. <code class="code">$wgWBQualityConstraintsClassId</code> for the <code class="code">WBQualityConstraintsClassId</code> setting.)</p><ul><li><p>Specify the entity IDs of entities that are used to define constraints. See the “Data import” section for an automatic way to do this.</p></li><li><p>If you have one or more SPARQL endpoints, configure the primary endpoint in <code class="code">WBQualityConstraintsSparqlEndpoint</code>, and any additional endpoints in <code class="code">WBQualityConstraintsAdditionalSparqlEndpoints</code>.</p></li><li><p>Alternatively, to check “format” constraints without running a full SPARQL server, you can use the <a href="https://github.com/lucaswerkmeister/minisparql">minisparql</a> server.</p></li></ul></li><li><p>Run <code class="code">php maintenance/run.php WikibaseQualityConstraints:ImportConstraintStatements.php</code>.</p></li></ul><h3><a class="h" name="Client_side-script" href="#Client_side-script"><span></span></a><a class="h" name="client_side-script" href="#client_side-script"><span></span></a>Client-side script</h3><p>The extension includes a client-side script that checks constraints on entity pages and displays violations on statements. It is loaded by default for all logged-in users; anonymous users can load it on a page by entering the following code into the web console:</p><pre class="code"><span class="pln">mw</span><span class="pun">.</span><span class="pln">loader</span><span class="pun">.</span><span class="pln">load</span><span class="pun">(</span><span class="pln"> </span><span class="str">'wikibase.quality.constraints.gadget'</span><span class="pln"> </span><span class="pun">);</span><span class="pln"> </span></pre><h3><a class="h" name="Data-import" href="#Data-import"><span></span></a><a class="h" name="data-import" href="#data-import"><span></span></a>Data import</h3><p>For local development, it’s easiest to import some data from Wikidata. You can use the <code class="code">ImportConstraintEntities</code> maintenance script script to do this; it will import all the required entities from Wikidata that don’t exist in your local wiki yet and then print a config snippet which you can append to your <code class="code">LocalSettings.php</code>.</p><pre class="code"><span class="com"># working directory should be the MediaWiki installation folder, i.e. where LocalSettings.php is</span><span class="pln"> php maintenance</span><span class="pun">/</span><span class="pln">run</span><span class="pun">.</span><span class="pln">php </span><span class="typ">WikibaseQualityConstraints</span><span class="pun">:</span><span class="typ">ImportConstraintEntities</span><span class="pun">.</span><span class="pln">php </span><span class="pun">|</span><span class="pln"> tee </span><span class="pun">-</span><span class="pln">a </span><span class="typ">LocalSettings</span><span class="pun">.</span><span class="pln">php </span></pre><p>(The new entities will not show up in your wiki’s recent changes until they have been processed in the job queue; try running the <code class="code">maintenance/runJobs.php</code> script if it doesn’t happen automatically.)</p><h3><a class="h" name="Running-the-tests" href="#Running-the-tests"><span></span></a><a class="h" name="running-the-tests" href="#running-the-tests"><span></span></a>Running the tests</h3><h4><a class="h" name="Installation-Running-the-tests-PHP" href="#Installation-Running-the-tests-PHP"><span></span></a><a class="h" name="installation-running-the-tests-php" href="#installation-running-the-tests-php"><span></span></a>PHP</h4><p>There are two ways to run the tests of this extension:</p><ul><li><p>Using the included configuration file:</p><pre class="code"><span class="com"># from the MediaWiki installation folder</span><span class="pln"> composer phpunit </span><span class="pun">--</span><span class="pln"> </span><span class="pun">-</span><span class="pln">c extensions</span><span class="pun">/</span><span class="typ">WikibaseQualityConstraints</span><span class="pun">/</span><span class="pln">phpunit</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">dist </span></pre><p>This creates test coverage reports (in <code class="code">tests/coverage/</code> and <code class="code">build/logs/clover.xml</code>) and is therefore fairly slow.</p></li><li><p>Without the configuration file:</p><pre class="code"><span class="com"># from the MediaWiki installation folder</span><span class="pln"> composer phpunit</span><span class="pun">:</span><span class="pln">entrypoint extensions</span><span class="pun">/</span><span class="typ">WikibaseQualityConstraints</span><span class="pun">/</span><span class="pln">tests</span><span class="pun">/</span><span class="pln">phpunit</span><span class="pun">/</span><span class="pln"> </span></pre><p>This runs the tests without coverage report and is therefore much faster.</p></li></ul><h4><a class="h" name="Javascript" href="#Javascript"><span></span></a><a class="h" name="javascript" href="#javascript"><span></span></a>Javascript</h4><p>You can run the tests, combined with linting and few other tools for asserting code quality by</p><pre class="code"><span class="pln"> </span><span class="com"># from this extension's folder</span><span class="pln"> npm install grunt test </span></pre><h3><a class="h" name="Adding-a-new-constraint-type" href="#Adding-a-new-constraint-type"><span></span></a><a class="h" name="adding-a-new-constraint-type" href="#adding-a-new-constraint-type"><span></span></a>Adding a new constraint type</h3><p>To add a new constraint type, the following steps are necessary:</p><ul><li>Define the constraint checker class.<ul><li>It should be defined in a new file in <code class="code">src/ConstraintCheck/Checker/</code>, named after the class name. It should be in the <code class="code">WikibaseQuality\ConstraintReport\ConstraintCheck\Checker</code> namespace.</li><li>The class name should follow the constraint type name (in English), ending in “Checker”.</li><li>The class must implement the <code class="code">ConstraintChecker</code> interface.</li><li>It should have at least the following class-level documentation comment:<pre class="code"><span class="com">/** * @author YOUR NAME HERE * @license GPL-2.0-or-later */</span><span class="pln"> </span></pre></li><li>Any services you need (<code class="code">Config</code>, <code class="code">EntityLookup</code>, …) should be injected as constructor parameters.</li><li>If the constraint has parameters, add support for parsing them to <code class="code">ConstraintParameterParser</code> (add a config setting for the associated property in <code class="code">extension.json</code> and a method to parse the parameter in <code class="code">ConstraintParameterParser</code>), and then add tests for them in <code class="code">ConstraintParameterParserTest</code>. This should be done in a separate commit.</li></ul></li><li>Define new messages (at least a violation message for the constraint type).<ul><li>Define the message in <code class="code">i18n/en.json</code>. A violation message should have a key like <code class="code">wbqc-violation-message-constraintType</code>.</li><li>Document the message in <code class="code">i18n/qqq.json</code>. Use the same message key, and insert the documentation in the same location where you also added the message in <code class="code">en.json</code> (that is, <code class="code">en.json</code> and <code class="code">qqq.json</code> should contain message keys in the same order).</li></ul></li><li>Add a configuration setting for the constraint type item ID.<ul><li>Configuration settings are defined in <code class="code">extension.json</code>, as members of the <code class="code">config</code> object.</li><li>It should be added right after the current last <code class="code">…ConstraintId</code> entry.</li><li>It should be named after the constraint type item’s English label, following the pattern <code class="code">WBQualityConstraints…ConstraintId</code>.</li><li>The default value should be the item ID on Wikidata, so that no extra configuration is required for Wikidata and importing the constraint type item (see “Data import” section) works.</li><li>The first part of the description can be copied from similar settings, the rest should contain a short description of the constraint type.</li><li>The ID can always be public (<code class="code">"public": true</code>).</li></ul></li><li>Register the new constraint type checker.<ul><li>In <code class="code">ConstraintCheckerServices.php</code>, add a constant like<pre class="code"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">const</span><span class="pln"> </span><span class="pun">…</span><span class="pln">_CHECKER </span><span class="pun">=</span><span class="pln"> </span><span class="str">'WBQC_…Checker'</span><span class="pun">;</span><span class="pln"> </span></pre>at the end of the list of constants. The value should be <code class="code">'WBQC_'</code> followed by the class name, and the constant name should be the class name converted to all caps separated by underscores.</li><li>Also in <code class="code">ConstraintCheckerServices.php</code>, add a method like<pre class="code"><span class="com">/** * @param MediaWikiServices|null $services * @return ConstraintChecker */</span><span class="pln"> </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">function</span><span class="pln"> </span><span class="kwd">get</span><span class="pun">…</span><span class="typ">Checker</span><span class="pun">(</span><span class="pln"> </span><span class="typ">MediaWikiServices</span><span class="pln"> $services </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">self</span><span class="pun">::</span><span class="pln">getService</span><span class="pun">(</span><span class="pln"> $services</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">self</span><span class="pun">::…</span><span class="pln">_CHECKER </span><span class="pun">);</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span></pre>at the end of the class.</li><li>In <code class="code">ServiceWiring-ConstraintCheckers.php</code>, append a new function like<pre class="code"><span class="typ">ConstraintCheckerServices</span><span class="pun">::…</span><span class="pln">_CHECKER </span><span class="pun">=></span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln"> </span><span class="typ">MediaWikiServices</span><span class="pln"> $services </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="pun">…</span><span class="typ">Checker</span><span class="pun">(</span><span class="pln"> </span><span class="com">// injected services</span><span class="pln"> </span><span class="pun">);</span><span class="pln"> </span><span class="pun">},</span><span class="pln"> </span></pre>to the array of services.</li><li>In <code class="code">ServiceWiring.php</code>, append a new entry like<pre class="code"><span class="pln">$config</span><span class="pun">-></span><span class="kwd">get</span><span class="pun">(</span><span class="pln"> </span><span class="str">'WBQualityConstraints…ConstraintId'</span><span class="pln"> </span><span class="pun">)</span><span class="pln"> </span><span class="pun">=></span><span class="pln"> </span><span class="typ">ConstraintCheckerServices</span><span class="pun">::</span><span class="kwd">get</span><span class="pun">…</span><span class="typ">Checker</span><span class="pun">(</span><span class="pln"> $services </span><span class="pun">),</span><span class="pln"> </span></pre>to the <code class="code">$checkerMap</code> array in the <code class="code">DELEGATING_CONSTRAINT_CHECKER</code> function.</li><li>In <code class="code">ServicesTest.php</code>, append a new entry like<pre class="code"><span class="pun">[</span><span class="pln"> </span><span class="pun">…</span><span class="typ">Checker</span><span class="pun">::</span><span class="kwd">class</span><span class="pln"> </span><span class="pun">],</span><span class="pln"> </span></pre>to the array in <code class="code">provideConstraintCheckerServiceClasses()</code>.</li></ul></li><li>Add tests for the new constraint checker.<ul><li>The test class name should be the same as the checker class name, with an additional suffix <code class="code">Test</code> (i. e., <code class="code">…CheckerTest</code>).</li><li>The test class should be placed somewhere in <code class="code">tests/phpunit/Checker/</code>, either in the most suitable subdirectory or directly in that directory if none of the subdirectories are suitable. (The division into subdirectories there is dubious anyways, and we may get rid of it in the future.)</li><li>It should have at least the following class-level documentation comment:<pre class="code"><span class="com">/** * @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\…Checker * * @group WikibaseQualityConstraints * * @author YOUR NAME HERE * @license GPL-2.0-or-later */</span><span class="pln"> </span></pre></li><li>It should have at least one test for compliance with a constraint, one test for a constraint violation, one test for behavior on a deprecated statement, and one test for the <code class="code">checkConstraintParameters</code> method.</li><li>Use the <code class="code">ResultAssertions</code> trait’s methods to check constraint check results.</li><li>Use the <code class="code">NewItem</code> and <code class="code">NewStatement</code> builders to construct test data.</li><li>If the checker uses a <code class="code">Config</code>, use the <code class="code">DefaultConfig</code> trait.</li><li>If the constraint has parameters, add methods for them to the <code class="code">ConstraintParameters</code> trait and use it in the tests.</li><li>You can copy+paste a <code class="code">getConstraintMock</code> function from one of the existing tests, adjusting the <code class="code">getConstraintTypeItemId</code> mocked return value. (Hopefully we’ll improve this in the future.)</li></ul></li><li>Update the tests for <code class="code">DelegatingConstraintChecker</code>.<ul><li>In <code class="code">DelegatingConstraintCheckerTest</code>, add an entry for your constraint type to the <code class="code">$constraints</code> array in <code class="code">addDBData()</code>.</li><li>The <code class="code">constraint_guid</code> should be <code class="code">P1$</code>, followed by a new UUID (e. g. <code class="code">cat /proc/sys/kernel/random/uuid</code> or <code class="code">journalctl --new-id128</code>).</li><li>The <code class="code">pid</code> should be <code class="code">1</code>. (Not <code class="code">'1'</code>!)</li><li>The <code class="code">constraint_type_qid</code> should be <code class="code">$this->getConstraintTypeItemId( '…' )</code>, where <code class="code">…</code> is just the <code class="code">…</code> part of the <code class="code">WBQualityConstraints…ConstraintId</code> <code class="code">extension.json</code> config key.</li><li>The <code class="code">constraint_parameters</code> should be a valid JSON serialization of constraint parameters. If the constraint type doesn’t have any parameters, you can pass <code class="code">{}</code>, otherwise there should ideally be methods to create the parameters in the <code class="code">ConstraintParameters</code> trait so that you can use <code class="code">json_encode( $this->…Parameter( … ) )</code> (perhaps with <code class="code">array_merge</code> if there are multiple parameters).</li></ul></li><li>Ask someone with grafana-admin access to update the “constraint types” panel in the <a href="https://grafana.wikimedia.org/dashboard/db/wikidata-quality">wikidata-quality board</a> to add the new constraint type.</li></ul><h3><a class="h" name="Adding-a-new-allowed-entity-type" href="#Adding-a-new-allowed-entity-type"><span></span></a><a class="h" name="adding-a-new-allowed-entity-type" href="#adding-a-new-allowed-entity-type"><span></span></a>Adding a new allowed entity type</h3><ul><li>Start by adding an Item reference to <code class="code">extension.json</code>. For example:<pre class="code"> "WBQualityConstraintsMediaInfoId": { "value": "Q3898244", "description": "The item ID of the 'MediaInfo' item, which represents the 'mediainfo' entity type for 'allowed entity types' constraints.", "public": true } </pre></li><li>The next step takes place inside <code class="code">src/ConstraintCheck/Helper/ConstraintParameterParser.php</code>. The new allowed entity type should be added to the switch/case within the method <code class="code">parseEntityTypeItem()</code>. Don't forget to add it to the default case as well!</li><li>To be able to test the newly added allowed entity type locally, please perform the steps described in section "Data import".</li></ul><h3><a class="h" name="Chore_Dependency-Updates" href="#Chore_Dependency-Updates"><span></span></a><a class="h" name="chore_dependency-updates" href="#chore_dependency-updates"><span></span></a>Chore: Dependency Updates</h3><h4><a class="h" name="NodeJS" href="#NodeJS"><span></span></a><a class="h" name="nodejs" href="#nodejs"><span></span></a>NodeJS</h4><p>You can see which dependencies have new releases by first running <code class="code">npm ci</code> to ensure your local dependencies are up-to-date, and then running <code class="code">npm outdated</code>.</p><ul><li><a href="https://github.com/sindresorhus/grunt-eslint">grunt-eslint</a> no longer supports "flat" eslint config files (i.e. <code class="code">.eslintrc.json</code>) since version 25.0.0 because of changes since eslint 9 (see issue <a href="https://github.com/sindresorhus/grunt-eslint/issues/176">#176</a>). See <a href="https://phabricator.wikimedia.org/T364065">T364065</a> for progress with our eslint 9 migration.</li><li><a href="https://github.com/wikimedia/grunt-stylelint">grunt-stylelint</a> switched to Stylelint 16+ in version 0.20.0, which no longer supports stylelint-stylistic, depended upon by <a href="https://github.com/wikimedia/stylelint-config-wikimedia">stylelint-config-wikimedia</a>. See issue <a href="https://github.com/wikimedia/stylelint-config-wikimedia/issues/225">#225</a></li></ul><h4><a class="h" name="Installation-Chore_Dependency-Updates-PHP" href="#Installation-Chore_Dependency-Updates-PHP"><span></span></a><a class="h" name="installation-chore_dependency-updates-php" href="#installation-chore_dependency-updates-php"><span></span></a>PHP</h4><p>Running <code class="code">composer update</code> and <code class="code">composer outdated --direct</code> will give you a list of any outdated PHP dependencies. There are currently no notes or restrictions on package updates.</p></div></div></div></div> <!-- Container --></div> <!-- Site-content --><!-- default customFooter --><footer class="Site-footer"><div class="Footer"><span class="Footer-poweredBy">Powered by <a href="https://gerrit.googlesource.com/gitiles/">Gitiles</a></span><span class="Footer-formats"><a class="u-monospace Footer-formatsItem" href="?format=TEXT">txt</a> <a class="u-monospace Footer-formatsItem" href="?format=JSON">json</a></span></div></footer></body></html><script>{let f = document.getElementById("clone-repo-input"); f.onclick = () => {f.focus(); if (f.selectionStart === f.selectionEnd) {f.select();}};}</script>