Search by

mwstake / mediawiki-component-datastash

dsavuljesku

Persistent key/value store for user data

Package info

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

pkg:composer/mwstake/mediawiki-component-datastash

Statistics

Installs: 2 016

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.0 2026-10-29 17:54 UTC

This package is auto-updated.

Last update: 2026-10-29 17:54:37 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.

Compatibility

  • >= 2.0.x -> MediaWiki 1.47
  • 1.0.x -> MediaWiki 1.43

Use in a MediaWiki extension

Require this component in the composer.json of your extension:

{
	"require": {
		"mwstake/mediawiki-component-datastash": "~2"
	}
}

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 = 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' );