Commit f33dc38a authored by Marijn van Wezel's avatar Marijn van Wezel
Browse files

Add mw.slots.slotContent

parent 3cf5cbc2
Pipeline #3067 passed with stages
in 47 seconds
......@@ -19,12 +19,38 @@ class ScribuntoLuaLibrary extends \Scribunto_LuaLibraryBase {
*/
public function register(): void {
$interfaceFuncs = [
'slotContent' => [ $this, 'slotContent' ],
'slotTemplates' => [ $this, 'slotTemplates' ]
];
$this->getEngine()->registerInterface( __DIR__ . '/' . 'mw.wsslots.lua', $interfaceFuncs, [] );
}
/**
* This mirrors the functionality of the #slot parser function and makes it available in Lua.
*
* @param string $slotName
* @param string|null $pageName
* @return array
* @throws MWException
*/
public function slotContent( string $slotName, ?string $pageName = null ): array {
$wikiPage = $this->getWikiPage( $pageName );
if ( !$wikiPage ) {
return [ null ];
}
$contentObject = WSSlots::getSlotContent( $wikiPage, $slotName );
if ( !$contentObject instanceof TextContent ) {
return [ null ];
}
return [ $contentObject->serialize() ];
}
/**
* This mirrors the functionality of the #slottemplates parser function and makes it available
* in Lua.
......
......@@ -24,10 +24,18 @@ function slots.setupInterface()
package.loaded['mw.slots'] = slots
end
function slots.slotContent( slotName, pageName )
if not type( slotName ) == 'string' or not type( pageName ) == 'string' or not type( pageName ) == 'nil' then
error( 'Invalid parameter type supplied to mw.slots.slotContent()' )
end
return php.slotContent( slotName, pageName )
end
-- slotTemplates
function slots.slotTemplates( slotName, pageName )
if not type( slotName ) == 'string' or not type( pageName ) == 'string' or not type( pageName ) == 'nil' then
error( 'Invalid parameter type supplied to slots.slotTemplates()' )
error( 'Invalid parameter type supplied to mw.slots.slotTemplates()' )
end
return php.slotTemplates( slotName, pageName )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment