Open main menu

Extension:CommonTag

MediaWiki extensions manual
OOjs UI icon advanced.svg
Common Tag
Release status: beta
Implementation Tag
Description Inserts Common Tag (RDFa) information on page
Author(s) Jamie Taylor
Latest version 0.1.1 (2014-04-12)
License CC BY
Download No link
Translate the CommonTag extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?Edit

Creates Common Tag (RDFa) markup on a page when it renders.

UsageEdit

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.

Download instructionsEdit

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.

InstallationEdit

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/commontag.php");

CodeEdit

<?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';
}
 
// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
   'path' => __FILE__,
   'name' => 'CommonTag',
   'version' => '0.1.1',
   'author' => array( 'Jamie Taylor',  ),
   'description' => 'Inserts Common Tag (RDFa) information on page',
   'url' => 'https://www.mediawiki.org/wiki/Extension:CommonTag',
);

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;
	}
}
English  • Nederlands