Page MenuHomePhabricator

ApiQuerySiteinfo should provide known and defined slot roles
Open, Needs TriagePublicFeature

Description

Feature summary:
ApiQuerySiteinfo should add a siprop 'slotroles' to provide known and defined slot roles including content_model and layout hints.
Example response:

{
    "batchcomplete": "",
    "query": {
        "slotroles": {
            "main": {
                "defined": "",
                "slot_role_layout": {
                    "display": "section",
                    "region": "center",
                    "placement": "append"
                },
                "content_model": "wikitext"
            },
            "jsondata": {
                "defined": "",
                "slot_role_layout": {
                    "display": "details",
                    "region": "footer",
                    "placement": "append"
                },
                "content_model": "json"
            },
            "deprecated": {
                "slot_role_layout": {
                    "display": "section",
                    "region": "center",
                    "placement": "append"
                },
                "content_model": "unknown"
            }
        }
    }
}

Example implementation

$result = $module->getResult();
$data = [];

$slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
$definedRoles = $slotRoleRegistry->getDefinedRoles();
$knownRoles = $slotRoleRegistry->getKnownRoles();

foreach ( $knownRoles as $slotName ) {
	$defined = in_array( $slotName, $definedRoles );
	$slotRoleHandler = $slotRoleRegistry->getRoleHandler( $slotName );
	$data[$slotName]['defined'] = $defined;
	$data[$slotName]['slot_role_layout'] = $slotRoleHandler->getOutputLayoutHints();
	$data[$slotName]['content_model'] = $slotRoleHandler->getDefaultModel(Title::newFromDBkey(  "Main_Page" ));
}

$result->addValue(['query'], 'slots', $data);

Use case(s):
Enable bots to check if a slot role is defined and to retrieve it's content model

Benefits:
Currently there's (to my knowledge) no option to direct access this information via API. Fetching revisions of a page only provides access to slot roles already used within a page.

Related Objects

StatusSubtypeAssignedTask
Declineddchen
OpenNone
OpenNone
DuplicateNone
OpenFeatureNone
OpenBUG REPORTNone
OpenNone
StalledNone
OpenFeatureNone
DuplicateNone
ResolvedNone
OpenNone
OpenNone
OpenFeatureNone
OpenNone
ResolvedNone
ResolvedNone
OpenFeatureNone
OpenNone
OpenFeatureNone
StalledNone
OpenNone
OpenNone
OpenFeatureSimontaurus

Event Timeline

Reedy subscribed.

Your code looks fine (bar some very minor code style issues that CI will flag)...

Would you be able to submit it as a patch to gerrit?

Change 927324 had a related patch set uploaded (by Simon Stier; author: Simon Stier):

[mediawiki/core@master] api: add known and defined slot roles to siteinfo

https://gerrit.wikimedia.org/r/927324

Not sure how to update the documentation - directly in API:Siteinfo?

Not sure how to update the documentation - directly in API:Siteinfo?

Which documentation are you referring to?

Certainly, that page on mediawiki.org wouldn't be updated until the patch is actually merged :)

Certainly, that page on mediawiki.org wouldn't be updated until the patch is actually merged :)

Makes sense... =D

I was wondering how the api/i18n/qqq.json works, e. g.

{{doc-apihelp-param|query+siteinfo|slotrolestitle}}

Is this autogenerating a doc string?

I was wondering how the api/i18n/qqq.json works, e. g.

{{doc-apihelp-param|query+siteinfo|slotrolestitle}}

Is this autogenerating a doc string?

https://translatewiki.net/wiki/Template:Doc-apihelp-param