Extension:LastFm

MediaWiki extensions manual
LastFm
Release status: unmaintained
Implementation Tag
Description Enables embedding the Last.fm player in a page with the <lastfm> tag.
Author(s) Guy Taylor (TheBigGuytalk)
Latest version 0.2 (2008-05-20)
MediaWiki
Database changes No
License No license specified
Download See the code section
‎<lastfm>

The LastFm extension enables embedding the Last.fm player in a page with the <lastfm> tag.

Usage edit

Now you can use the extension with <lastfm>Last.fm-Username</lastfm> in the wiki

Installation edit

  • Copy the code into a file and place the file(s) in a directory called LastFm in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    require_once "$IP/extensions/LastFm/LastFm.php";
    
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code edit

LastFm.php
<?php
/**
 * LastFm extension for MediaWiki
 *
 * @author Guy Taylor
 * @copyright © Guy Taylor
 * @version 0.2
 * @link https://www.mediawiki.org/wiki/Extension:LastFm
 */

if ( !defined( 'MEDIAWIKI' ) ) {
	die( 'This is not a valid entry point.' );
}

// Extension credits that show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'LastFm',
        'author' => 'Guy Taylor',
        'version' => '0.2',
        'url' => 'https://www.mediawiki.org/wiki/Extension:LastFm',
        'description' => 'Allows to adds the Last.fm player to a page with the <tt>&lt;lastfm&gt;</tt> tag'
);

$wgExtensionFunctions[] = 'wfLastFm';

function wfLastFm() {
    global $wgParser;
    $wgParser->setHook( 'lastfm', 'renderLastFm' );
}

# The callback function for converting the input text to HTML output
function renderLastFm( $input ) {
    $output = "<!-- Last.fm http://www.last.fm/ -->";
    $output = "<a href=\"http://www.last.fm/user/";
    $output .= htmlspecialchars($input);
    $output .= "/?chartstyle=tracks\">";
    $output .= "<img src=\"http://imagegen.last.fm/tracks/artists/";
    $output .= htmlspecialchars($input);
    $output .= ".gif\" border=\"0\" alt=\"";
    $output .= htmlspecialchars($input);
    $output .= "'s Last.fm Weekly Artists Chart\" /></a>";

    return $output;
}