Jump to content

Extension:EmbedLrmi

From mediawiki.org
MediaWiki extensions manual
EmbedLrmi
Release status: stable
Implementation Parser function
Description Embeds Learning Resource Metadata Initiative (LRMI) data as JSON-LD metadata in wiki pages
Author(s) Uwe Schützenmeister (Filburttalk)
Latest version 1.0.0 (2025-12-11)
MediaWiki >= 1.43.0
Licence GNU General Public License 2.0 or later
Download

The EmbedLrmi extension is designed to embed Learning Resource Metadata Initiative (LRMI) data as JSON-LD metadata in wiki pages. The metadata is retrieved from an external LRMI-compatible repository, enabling better discoverability and interoperability of educational resources.

Features

[edit]
  1. Automatic embedding of LRMI metadata as JSON-LD in the `<head>` section of wiki pages.
  2. Dynamic retrieval of metadata from LRMI repositories via API.
  3. Configurable endpoint and URL transformations for flexible integration.
  4. Visual display of metadata via `?action=lrmi` and page for debugging and transparency.
  5. Toolbox link for easy access to LRMI data on each page.
  6. Caching mechanism to reduce API calls and improve performance.
  7. Cache management through a dedicated special page.

How does it work

[edit]

The extension hooks into MediaWiki's rendering pipeline and retrieves LRMI metadata for the current page from an external LRMI repository. The metadata is then embedded as a JSON-LD `<script>` tag in the page's HTML head.

The extension can replace parts of the page URL (e.g., domain or underscores) to match the format expected by your LRMI repository API.

Installation

[edit]
  • Download, extract and place the file(s) in a directory called EmbedLrmi in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'EmbedLrmi' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

[edit]

The extension works automatically for all content pages.

Viewing LRMI Data

[edit]
[edit]

A "Show LRMI data" link appears in the toolbox (sidebar) on all content pages. Clicking this link displays the LRMI metadata for the current page in a structured, human-readable format.

2. Action Parameter

[edit]

You can append ?action=lrmi to any page URL to view its LRMI metadata: https://your-wiki.example.com/wiki/Page_Name?action=lrmi

Cache Management

[edit]

The extensions comes with a new special page Special:PurgeLrmiCache Users with the purgelrmicache permission (by default: sysops and bureaucrats) can access Special:PurgeLrmiCache to clear all cached LRMI metadata. This forces the extension to fetch fresh data from the repository on the next page view.

Configuration

[edit]

The extension requires configuration in your LocalSettings.php:

Variable Description Required Default
$wgEmbedLrmiEndpoint The LRMI repository API endpoint URL. Yes -
$wgEmbedLrmiUrlReplacements An associative array to replace parts of the page URL before sending it to the API. No -
$wgEmbedLrmiCacheExpiry Cache duration in seconds. Set to 0 to disable caching. No 2592000 (30 days)

Example Configuration

[edit]
# EmbedLrmi Extension Configuration
wfLoadExtension( 'EmbedLrmi' );
$wgEmbedLrmiEndpoint = 'https://repository.example.org/api/v1/lrmi/search';

# Optional: Transform URLs before querying the API
$wgEmbedLrmiUrlReplacements = [
    'from' => ['internal-wiki.local', '_'],
    'to'   => ['public-wiki.org', '%20']
];

# Optional: Set cache expiry (default: 30 days)
$wgEmbedLrmiCacheExpiry = 604800; // 7 days

# Optional: Grant cache purge permission to additional user groups
$wgGroupPermissions['sysop']['purgelrmicache'] = true;
$wgGroupPermissions['bureaucrat']['purgelrmicache'] = true;

Configuration Notes

[edit]
  • $wgEmbedLrmiEndpoint: The API endpoint for fetching LRMI metadata. Must be accessible from your MediaWiki server. The endpoint should accept POST requests with a JSON body containing the page URL.
  • $wgEmbedLrmiUrlReplacements: Used to transform the page URL to match the format expected by your LRMI repository API. For example, replacing underscores (_) with %20 (URL-encoded spaces) or adjusting the domain for external repositories.
  • $wgEmbedLrmiCacheExpiry: Metadata is cached to reduce API calls. Adjust this value based on how frequently your LRMI data changes.


History

[edit]
  • 2025-12-11 Version 1.0.0 Initial commit