Extension:CommonTag
From MediaWiki.org
|
Release status: beta |
|
|---|---|
| [[Image:File:Commontag.jpg|220px]] | |
| Implementation | Tag |
| Description | Inserts Common Tag (RDFa) information on page |
| Author(s) | Jamie Taylor |
| Last Version | 0.1 (June 11, 2009) |
| License | CC-BY |
| Download | no link |
|
check usage (experimental) |
|
Contents |
[edit] What can this extension do?
Creates Common Tag (RDFa) markup on a page when it renders.
[edit] Usage
To create a Common Tag, add a <ctag/> in your wiki text. The <ctag> takes the following attributes:
- means: (required) the full URI that identifies the concept represented by this tag
- label: (optional) a human readable label for the tag
- about: (optional) the URI for the resource (web page) being tagged. If omitted, the current page is assumed to be the item being tagged.
Examples:
To indicate that this page is about Common Tags:
<ctag means="http://rdf.freebase.com/ns/en.commontag" label="common tag"/>
To indicate that a book at Amazon is about Semantic Technologies and the string "semantic technologies" can be used when displaying the tag (in something like a bookmark system):
<ctag about="http://www.amazon.com/gp/product/0596153813"
means="http://rdf.freebase.com/ns/en.semantic_technology"
label="semantic technology"/>
Note, you may have multiple Common Tags on a page.
[edit] Download instructions
Please cut and paste the code found below and place it in $IP/extensions/commontag.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
To install this extension, add the following to LocalSettings.php:
require_once("$IP/extensions/commontag.php");
[edit] Code
<?php /* * A very simple tag extension for generating Common Tag (RDFa) markup in a MediaWiki CMS * * Don't use this code to guide nuclear submarines or perform medical procedures. * It's bad code. You have been warned. But you are welcome to use it anyway you want. * Please don't tell anyone where you got this code; remember it's bad code. * * To create a Common Tag embed a <ctag> in your wiki markup. * The tag has one manditory attribute "means" which takes a URI as a value - defaults to current page URI * You may also specify an "about" attribute (with a URI as value) to set the subject of the tag. * You may also specify a "label" attribute (with a literal value) as the human readable name for the tag. * * You may place as many <ctag> elements as you want on a page. Example: * <ctag means="http://rdf.freebase.com/ns/en.commontag"/> * <ctag means="http://rdf.freebase.com/ns/en.mediawiki" label="mediawiki"/> * * Original hack by Jamie Taylor (jamie/metaweb.com) - June 11, 2009 */ if (defined('MW_SUPPORTS_PARSERFIRSTCALLINIT')){ $wgHooks['ParserFirstCallInit'][] = 'efCtagSetup'; }else{ //old way $wgExtensionFunctions[] = 'efCtagSetup'; } function efCtagSetup() { global $wgParser; $wgParser->setHook( 'ctag', 'efCtagRender' ); return true; } function efCtagRender( $input, $args, $parser ){ //attempt to generate a common tag from the input $valid = false; $result = "<span xmlns:ctag='http://commontag.org/ns#' rel='ctag:tagged' "; if(array_key_exists('about', $args)){ $result .= "about='" . htmlspecialchars($args['about']) . "'"; } $result .= "><span typeof='ctag:Tag' "; if(array_key_exists('means', $args)){ $result .= "rel='ctag:means' resource='" . htmlspecialchars($args['means']) . "' "; $valid = true; } if(array_key_exists('label', $args)){ $result .= "property='ctag:label' content='" . htmlspecialchars($args['label']) . "' "; } $result .= "/></span>"; if($valid){ return $result; } }