My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?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);
}

/* Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions */
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
$wgHooks['ParserFirstCallInit'][] = 'myDnaSequence';
} else {
$wgExtensionFunctions[] = 'myDnaSequence';
}


/**
* 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.1',
'author' => '[http://plindenbaum.blogspot.com Pierre Lindenbaum]',
'url' => 'http://code.google.com/p/lindenb/source/browse/trunk/proj/mediawiki/extensions/dnaseq/dnaseq.php',
'description' => 'Displays a DNA sequence'
);

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

function myRenderDnaSequence( $input, $args, $parser )
{
if($input==null) return "";
$len= strlen($input);
$n=0;
$html="<div style='padding: 10px; font-size:10px; border-width: thin; border: 1px black solid; white-space: pre;background-color: white;font-family: courier, monospace;line-height:13px; font-size:12px;'>";
for($i=0;$i< $len;$i++)
{
$c = $input[$i];
if(ctype_space($c) || ctype_digit($c)) continue;
if($n % 60 == 0)
{
if($n!=0) $html.="<br/>";
$html.= sprintf("%06d ",($n+1));
}
else if($n % 10 ==0)
{
$html.=" ";
}
$n++;
switch(strtolower($c))
{
case "a":
$html.="<span style='color:green;'>".$c."</span>";
break;
case "c":
$html.="<span style='color:blue;'>".$c."</span>";
break;
case "g":
$html.="<span style='color:black;'>".$c."</span>";
break;
case "t":
case "u":
$html.="<span style='color:red'>".$c."</span>";
break;
default:
$html.="<span style='text-decoration: blink;color:gray'>".$c."</span>";
break;
}
if($n % 60 == 0)
{
$html.= sprintf(" %06d",($n));
}
}
$html .= "</div>";
return $html;
}

?>
Show details Hide details

Change log

r212 by plindenbaum on Jan 04, 2009   Diff
url
Go to: 
Project members, sign in to write a code review

Older revisions

r211 by plindenbaum on Jan 04, 2009   Diff
mediawiki project
All revisions of this file

File info

Size: 2725 bytes, 100 lines
Hosted by Google Code