Extension:DNASeq/V20100808

modified version (proposed by Niklas Laxström) <?php /** Author: Pierre Lindenbaum PhD Mail: plindenbaum@yahoo.fr

Installation: install this file in		${MWROOT}/extensions/dnaseq/dnaseq.php and add the following line at the end of ${MWROOT}/LocalSettings.php : require_once("$IP/extensions/dnaseq/dnaseq.php");

/** * 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); }

/** * An array of extension types and inside that their names, versions, authors * and urls. This credit information gets added to the wiki's Special:Version * page, allowing users to see which extensions are installed, and to find more * information about them. */ $wgExtensionCredits['parserhook'][] = array(	'name'       => 'dnaseq',	'version'     => '0.2',	'author'      => 'Pierre Lindenbaum',	'url'         => 'http://code.google.com/p/lindenb/source/browse/trunk/proj/mediawiki/extensions/dnaseq/dnaseq.php',	'description' => 'Displays a DNA sequence' );

$wgHooks['ParserFirstCallInit'][] = 'myDnaSequence';

function myDnaSequence( $parser ) {	$parser->setHook( 'dnaseq', 'myRenderDnaSequence' ); return true; }

function myRenderDnaSequence( $input, $args, $parser ) {	if($input==null) return ""; $len= mb_strlen($input); $n=0; $html=""; for($i=0;$i< $len;$i++) {		$c = mb_substr( $input, $i, 1 ); if(ctype_space($c) || ctype_digit($c)) continue; if($n % 60 == 0) {			if($n!=0) $html.=" "; $html.= sprintf("%06d ",($n+1)); }		else if($n % 10 ==0) {			$html.=" "; }		$n++; switch(strtolower($c)) {			case "a": $html.=" ".$c." "; break; case "c": $html.=" ".$c." "; break; case "g": $html.=" ".$c." "; break; case "t": case "u": $html.=" ".$c." "; break; default: $html.=" ".$c." "; break; }		if($n % 60 == 0) {			$html.= sprintf(" %06d",($n)); }		}	$html .= " "; return $html; }