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.