Page MenuHomePhabricator

Use mw.config variables where possible in the WikiLambda App.
Open, LowPublicFeature

Description

Feature summary
At this time, the WikiLambda app is tightly tied to external variables such as the search parameters in the browser location (window.location.href). This makes it very difficult or impossible to mount the app in other contexts. I propose using MediaWiki's built-in solution to store variables - mw.config - which would increase the level of interoperability of the app.

For example, instead of using oldid from the URL:

// Set current Zid
this.setCurrentZid( zId );
const revision = getParameterByName( 'oldid' );
// Calling the API without language parameter so that we get
// the unfiltered multilingual object
return fetchZObjects( {
    zids: zId,
    revisions: revision || undefined
} )

We can use a variable wgRevisionId from the mw.config:

// Set current Zid
this.setCurrentZid( zId );
const revision = mw.config.get( 'wgRevisionId' );
// Calling the API without language parameter so that we get
// the unfiltered multilingual object
return fetchZObjects( {
    zids: zId,
    revisions: revision || undefined
} )

Use case(s)
I have written code to require and embed the WikiLambda app in my gadget:

function restoreWikiLambda( $container ) {
    if ( !$container || $container.length === 0 ) return;

    mw.loader.using( [ '@wikimedia/codex', 'ext.wikilambda.app' ] ).then( require => {
        const { createMwApp } = require( 'vue' );
        const { createPinia } = require( 'pinia' );
        const { useMainStore, App } = require( 'ext.wikilambda.app' );

        // Conditionally mount App.vue:
        // If wgWikilambda config variable is available, we want to mount WikiLambda App.
        if ( mw.config.get( 'wgWikiLambda' ) ) {
            const pinia = createPinia();
            const store = useMainStore( pinia );
            window.vueInstance = createMwApp( Object.assign( {
                provide: () => ( {
                    viewmode: store.getViewMode,
                } ),
            }, App ) )
                .use( pinia )
                .mount( $container.get( 0 ) );
        }
    } );
}

And it works almost perfectly, except the WikiLambda app requires only the latest revision or whatever is in the browser address bar.