A page so you can try out my mw-code extension. --Push-f (talk) 18:30, 2 December 2022 (UTC)

Try out a block:

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P31|wdt:P279 wd:Q146. # Notice how the | doesn't have to be escaped
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

run embed

Check out a code page: /Subpage.rq (notice the .rq file extension, which automatically changes the default content model of the page).

Page actions of a code page can be linked via Special:CodeAction, e.g.

Special:CodeAction/run/Code/Subpage.rq or Special:CodeAction/embed/Code/Subpage.rq.

Also note that with the tags the parameters of mw:Extension:SyntaxHighlight are supported e.g.

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P31|wdt:P279 wd:Q146. # Notice how the | doesn't have to be escaped
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

run embed

Embedding resultsEdit

This is a just a demonstration to show that the extension can be used to embed query results if there is a Lua API for the Wikidata Query Service. (This demo currently relies on mw:Extension:UnlinkedWikibase)

The logic for this is not part of the extension but provided via the Lua module Module:QueryCode.

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P31|wdt:P279 wd:Q146. # Notice how the | doesn't have to be escaped
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} LIMIT 10

run embed

itemitemLabel
http://www.wikidata.org/entity/Q147kitten
http://www.wikidata.org/entity/Q7338Kurilian Bobtail
http://www.wikidata.org/entity/Q7295Egyptian Mau
http://www.wikidata.org/entity/Q7303Donskoy cat
http://www.wikidata.org/entity/Q7323Toyger
http://www.wikidata.org/entity/Q7874American Bobtail
http://www.wikidata.org/entity/Q7955Abyssinian
http://www.wikidata.org/entity/Q7329Cheetoh
http://www.wikidata.org/entity/Q7308Serengeti cat
http://www.wikidata.org/entity/Q7334Dragon Li

LocalizationEdit

Since the actions are configurable my extension cannot provide translation for the action labels, however wikis can easily do that themselves since the labels are embedded via MediaWiki:codeaction-label. So e.g. wikidata.org could embed a template in the MediaWiki message to allow regular users to contribute translations via wikidata:Template:LangSwitch.

Config that makes this possibleEdit

Note that all the config that is necessary for this is:

wfLoadExtension( 'Code' );

$wgCode_namespacesWithCodePages[NS_MAIN] = true;

$wgCode_languages[] = [
        'tag' => 'query',
        'pygmentsLexer' => 'sparql',
        'actions' => [
                'run' => 'https://query.wikidata.org/#$code',
                'embed' => 'https://query.wikidata.org/embed.html#$code',
        ],
        'suffix' => '.rq',
        'codePrefix' => '# This query is from $url',
        'scribuntoModule' => 'QueryCode',
];

along with Module:QueryCode