Extension:Logotipo

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
  1. logotipo

Release status: stable

Implementation Parser function
Description Example of function to change $wgLogo on a per-page basis
Author(s) Carl Austin Bennett
Version 1.0 (March 22, 2008)
MediaWiki 1.11 - 1.13
Download logotipo.php
Hooks used

LanguageGetMagic

A quite simple example of a parser function: #logotipo: takes one parameter (a URL pointing to an image) and copies that value to $wgLogo.

Any special characters are removed from the input and caching of the individual page from which this function was invoked is disabled. The function then returns an empty string.

One example of this extension in use is: http://desciclopedia.ws/wiki/Rede_Globo - that page jokingly replaces Desciclopédia's "batata" logo (a hollow potato) with a parody of Globo TV's network logo.

The extension code logotipo.php below must be stored as a file on the server, which is then invoked (using require_once()) from LocalSettings.php:

[edit] logotipo.php

<?php
/**
 * #logotipo - a crude and simple parser function used 
 * to set $wgLogo on a per-page basis
 *
 * @author Carl Austin Bennett
 * @copyright Copyright © Carl Austin Bennett
 * @link http://www.mediawiki.org/wiki/Extension:Logotipo
 */
 
#Extension credits that will show up on Special:Version
$wgExtensionCredits['other'][] = array(
        'name' => 'Logotipo',
        'version' => 1.0,
        'author' => 'Carl Austin Bennett',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Logotipo',
        'description' => 'Example of function to change $wgLogo on a per-page basis',
);
 
# Define a setup function
$wgExtensionFunctions[] = 'wfLogotipoFunction_Setup';
 
# Add a hook to initialise as a MediaWiki magic word
$wgHooks['LanguageGetMagic'][]       = 'wfLogotipoFunction_Magic';
 
# Setup functions
function wfLogotipoFunction_Setup() {
        global $wgParser;
        # Set a function hook associating the "logotipo" magic word with our function
        $wgParser->setFunctionHook( 'logotipo', 'wfLogotipoFunction_Render' );
}
 
function wfLogotipoFunction_Magic( &$magicWords, $langCode ) {
        # Add the magic word
        # The first array element is case sensitive, in this case it is not case sensitive
        # All remaining elements are synonyms for our parser function
        $magicWords['logotipo'] = array( 0, 'logotipo' );
        # return true, otherwise other parser function extensions won't load.
        return true;
}
 
# The #logotipo: parser function itself
# This merely sets $wgLogo to a user-supplied URL, special characters removed,
# for the currently-displayed MediaWiki page.
 
function wfLogotipoFunction_Render( &$parser, $param1 = '' ) {
        global $wgLogo;
 
        # The parser function itself
        # The input parameter is a full URL of the desired logo for display,
        # which is simply copied into $wgLogo; any special characters are
        # removed and page caching is disabled for this one page.
 
        $parser ->disableCache();
        $wgLogo = htmlspecialchars($param1);
        return "";
}
Personal tools