Extension:HTML Profiles
From MediaWiki.org
|
Release status: stable |
|
|---|---|
| Implementation | Parser function |
| Description | |
| Author(s) | Toby Inkster |
| Last Version | 1.0 (2009-03-09) |
| MediaWiki | tested on 1.14.0 |
| License | GPL |
| Download | see below |
|
check usage (experimental) |
|
This extension adds support for the <head profile> attribute in (X)HTML.
On any pages where you wish to use a custom profile, include the following code:
{{#profile:http://example.com/my-profile}}
Multiple profiles can be included in each page.
[edit] Installation
Add the following to LocalSettings.php:
require_once("extensions/html_profiles.php");
Copy and paste the following as extensions/html_profiles.php:
<?php /** * HTML Profiles - support for <head profile> in (X)HTML. * * @author Toby Inkster <http://tobyinkster.co.uk/> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ /** * Protect against register_globals vulnerabilities. * This line must be present before any global variable is referenced. */ if( !defined( 'MEDIAWIKI' ) ) { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); } // Extension credits that will show up on Special:Version $wgExtensionCredits['parserhook'][] = array( 'name' => 'HTML Profiles', 'version' => '1.0', 'author' => 'Toby Inkster', 'url' => 'http://www.mediawiki.org/wiki/Extension:HTML_Profiles', 'description' => 'Support for <head profile> in (X)HTML' ); class HTMLProfileList { private static $_instance; private $list; private function __construct () { $this->list = array('http://www.w3.org/1999/xhtml/vocab'); } private function __clone() { throw new Exception(); } public static function getInstance () { if (is_null(self::$_instance)) self::$_instance = new HTMLProfileList(); return self::$_instance; } public function add ($uri) { $uri = str_replace(' ', '%20', $uri); if (array_search($uri, $this->list)===FALSE) { $this->list[] = $uri; return "Loaded profile $uri"; } else { return "Duplicate profile $uri"; } } public function attribute () { return htmlentities(implode(' ', $this->list)); } public function uri_array () { return $this->list; } } $wgExtensionFunctions[] = 'htmlprofileParserFunction_Setup'; $wgHooks['LanguageGetMagic'][] = 'htmlprofileParserFunction_Magic'; function htmlprofileParserFunction_Setup() { global $wgParser; $wgParser->setFunctionHook( 'profile', 'htmlprofileParserFunction_Render' ); } function htmlprofileParserFunction_Magic( &$magicWords, $langCode ) { $magicWords['profile'] = array( 0, 'profile' ); return true; } function htmlprofileParserFunction_Render(&$parser, $u='') { $parser->disableCache(); if (strlen($u)) { $plist = HTMLProfileList::getInstance(); $status = $plist->add($u); return array("<!-- HTML PROFILE: $status -->", 'isHTML'=>true, 'noparse'=>true); } else { return array("''#profile needs to be given a URI!''", 'isHTML'=>false); } }
Your skin(s) will also need modification. Find the part of the skin code that outputs the <head profile> attribute and modify it like this:
<head profile="<?php if (class_exists('HTMLProfileList')) { $pl = HTMLProfileList::getInstance(); echo $pl->attribute(); } ?>">