Extension:Metadata

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Metadata
Release status: stable
Implementation Database
Description Provides two simple methods to set and get metadata about any wiki page
Author(s) Sophivorustalk
Latest version 1.0 (2019-05-23)
MediaWiki 1.32+
PHP 7.0+
Database changes Yes
License GNU General Public License 3.0 or later
Download
Translate the Metadata extension if it is available at translatewiki.net
Check usage and version matrix.

The Metadata extension provides two very simple methods Metadata::set and Metadata::get to save and retrieve metadata about any wiki page.

This is a general purpose extension and does nothing useful by itself. It's meant to be used by other extensions and pieces of code to save and retrieve their own metadata.

The metadata is stored in a new database table.

Installation[edit]

  • Download and place the file(s) in a directory called Metadata in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'Metadata' );
    
  • Run the update script which will automatically create the necessary database tables that this extension needs.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage[edit]

To save a simple key-value pair for a given page ID, use the following code:

Metadata::set( $pageID, 'key', 'value' );

You can also set several key-value pairs at once, like so:

Metadata::set( $pageID, [
	'key1' => 'value1',
	'key2' => 'value2',
	'key3' => 'etc',
]);

If a value for any of the keys already exists, it will be overwritten. Once set, you can retrieve the saved data for a given key with the following code:

$value = Metadata::get( $pageID, 'key' );

You can also retrieve all the key-value pairs for a given page at once, like so:

$data = Metadata::get( $pageID );
foreach ( $data as $key => $value ) {
	// Do something
}

See also[edit]