mwstake/mediawiki-component-datastash

Persistent key/value store for user data

Maintainers

Package info

github.com/hallowelt/mwstake-mediawiki-component-datastash

pkg:composer/mwstake/mediawiki-component-datastash

Statistics

Installs: 52

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.3 2026-06-26 06:08 UTC

This package is auto-updated.

Last update: 2026-06-26 06:09:16 UTC


README

Datastash - persistent key/value store for user data

This code is meant to be executed within the MediaWiki application context. No standalone usage is intended.

Usage

Data can be stashed for current wiki or globally, accessible across wikis in the same cluster. The API is simple:

/** @var \MWStake\MediaWiki\Component\DataStash\StashManager $stash */
$stash = \MediaWiki\MediaWikiServices::getInstance()->getService( 'MWStake.DataStash' );
$user = \RequestContext::getMain()->getUser();

$stash->stash( 'myKey', [ 'some' => 'value' ], $user );

// or globally
$stash->stashGlobal( 'myKeyGlobal', [ 'some' => 'value' ], $user );

var_dump( $stash->get( 'myKey', $user ) );
// outputs: [ 'some' => 'value' ]

var_dump( $stash->getGlobal( 'myKeyGlobal', $user ) );
// outputs: [ 'some' => 'value' ]

It is possible to store same key both globally and locally, although not recommended.

REST

Values over REST API are only for current user, so no ability to set/get data for other users.

GET rest.php/mws/v1/data-stash/{key} - get stashed data for current user.

  • key - key of the stashed data
  • query param global - if set to 1, global stash will be returned, otherwise local stash for current wiki

POST rest.php/mws/v1/data-stash/{key} - stash data for current user.

  • key - key of the stashed data
  • body
{
    "data": { "some": "value" },
    "global": true
}

Client side integration

// mw.loader.load( 'ext.mws.datastash' )

await mws.dataStash.set( 'foo', { some: 'value' } );
await mws.dataStash.setGlobal( 'fooGlobal', { some: 'value' } );

const value = await mws.dataStash.get( 'foo' );
const valueGlobal = await mws.dataStash.getGlobal( 'fooGlobal' );