CINXE.COM

refs/heads/wmf/next - 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>refs/heads/wmf/next - 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"><link rel="stylesheet" type="text/css" href="/r/plugins/gitiles/+static/prettify/prettify.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%2F%2B%2Frefs%2Fheads%2Fwmf%2Fnext">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> / <a class="Breadcrumbs-crumb" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/">WikibaseQualityConstraints</a> / <span class="Breadcrumbs-crumb">refs/heads/wmf/next</span></div><div class="u-monospace Metadata"><table><tr><th class="Metadata-title">commit</th><td>38c5316286984af3a9755b903155a38483304b22</td><td><span>[<a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+log/refs/heads/wmf/next">log</a>]</span> <span>[<a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+archive/refs/heads/wmf/next.tar.gz">tgz</a>]</span></td></tr><tr><th class="Metadata-title">author</th><td>libraryupgrader &lt;tools.libraryupgrader@tools.wmflabs.org&gt;</td><td>Wed Nov 20 07:09:18 2024 +0000</td></tr><tr><th class="Metadata-title">committer</th><td>libraryupgrader &lt;tools.libraryupgrader@tools.wmflabs.org&gt;</td><td>Fri Nov 22 06:02:54 2024 +0000</td></tr><tr><th class="Metadata-title">tree</th><td><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/">ca9c2a0dcec04ae60f675f40b001e0c5f691e27b</a></td></tr><tr><th class="Metadata-title">parent</th><td><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next%5E">5f6fa357f494a3888bd9faae7ca084f6681f457c</a> <span>[<a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next%5E%21/">diff</a>]</span></td></tr></table></div><pre class="u-pre u-monospace MetadataMessage">build: Updating cross-spawn to 7.0.6 * <a href="https://github.com/advisories/GHSA-3xgq-45jj-v275">https://github.com/advisories/GHSA-3xgq-45jj-v275</a> Change-Id: <a href="https://gerrit.wikimedia.org/r/#/q/I55b2a4cf98d988386c8e7d6cc32cebba105e26dd">I55b2a4cf98d988386c8e7d6cc32cebba105e26dd</a> </pre><ul class="DiffTree"><li><a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/package-lock.json">package-lock.json</a><span class="DiffTree-action DiffTree-action--modify">[<a href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next%5E%21/#F0">diff</a>]</span></li></ul><div class="DiffSummary">1 file changed</div><div class="TreeDetail"><div class="u-sha1 u-monospace TreeDetail-sha1">tree: ca9c2a0dcec04ae60f675f40b001e0c5f691e27b</div><ol class="FileList"><li class="FileList-item FileList-item--gitTree" title="Tree - .github/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.github/">.github/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - .phan/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.phan/">.phan/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - i18n/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/i18n/">i18n/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - maintenance/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/maintenance/">maintenance/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - modules/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/modules/">modules/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - sql/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/sql/">sql/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - src/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/src/">src/</a></li><li class="FileList-item FileList-item--gitTree" title="Tree - tests/"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/tests/">tests/</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .coveralls.yml"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.coveralls.yml">.coveralls.yml</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .eslintrc.json"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.eslintrc.json">.eslintrc.json</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .gitignore"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.gitignore">.gitignore</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .gitreview"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.gitreview">.gitreview</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .mailmap"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.mailmap">.mailmap</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .phpcs.xml"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.phpcs.xml">.phpcs.xml</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - .stylelintrc.json"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/.stylelintrc.json">.stylelintrc.json</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - CODE_OF_CONDUCT.md"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/CODE_OF_CONDUCT.md">CODE_OF_CONDUCT.md</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - composer.json"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/composer.json">composer.json</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - COPYING"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/COPYING">COPYING</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - extension.json"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/extension.json">extension.json</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - Gruntfile.js"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/Gruntfile.js">Gruntfile.js</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - package-lock.json"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/package-lock.json">package-lock.json</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - package.json"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/package.json">package.json</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - phpunit.xml.dist"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/phpunit.xml.dist">phpunit.xml.dist</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - README.md"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/README.md">README.md</a></li><li class="FileList-item FileList-item--regularFile" title="Regular file - WikibaseQualityConstraints.alias.php"><a class="FileList-itemLink" href="/r/plugins/gitiles/mediawiki/extensions/WikibaseQualityConstraints/+/refs/heads/wmf/next/WikibaseQualityConstraints.alias.php">WikibaseQualityConstraints.alias.php</a></li></ol><div class="InlineReadme"><div class="InlineReadme-path">README.md</div><div class="doc"><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">&#39;WikibaseQualityConstraints&#39;</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">&#39;wikibase.quality.constraints.gadget&#39;</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&#39;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">&quot;public&quot;: 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">&#39;WBQC_…Checker&#39;</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">&#39;WBQC_&#39;</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">=&gt;</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">-&gt;</span><span class="kwd">get</span><span class="pun">(</span><span class="pln"> </span><span class="str">&#39;WBQualityConstraints…ConstraintId&#39;</span><span class="pln"> </span><span class="pun">)</span><span class="pln"> </span><span class="pun">=&gt;</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">&#39;1&#39;</code>!)</li><li>The <code class="code">constraint_type_qid</code> should be <code class="code">$this-&gt;getConstraintTypeItemId( &#39;…&#39; )</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-&gt;…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"> &quot;WBQualityConstraintsMediaInfoId&quot;: { &quot;value&quot;: &quot;Q3898244&quot;, &quot;description&quot;: &quot;The item ID of the &#39;MediaInfo&#39; item, which represents the &#39;mediainfo&#39; entity type for &#39;allowed entity types&#39; constraints.&quot;, &quot;public&quot;: 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&#39;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 &quot;Data import&quot;.</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 &quot;flat&quot; 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>

Pages: 1 2 3 4 5 6 7 8 9 10