-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleInputBox.php
executable file
·100 lines (66 loc) · 2.41 KB
/
SimpleInputBox.php
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
<?php
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__, // Magic so that svn revision number can be shown
'name' => "Simple Input Box Extension",
'description' => "Simple Input Box extension", // Should be using descriptionmsg instead so that i18n is supported (but this is a simple example).
'version' => 1,
'author' => "Toniher",
'url' => "http://labservice.biocore.crg.cat",
);
$wgExtensionFunctions[] = "sinputExtension";
function sinputExtension() {
global $wgParser;
$wgParser->setHook( "sinputbox", "sinputfunc" );
$wgParser->setHook( "sselectbox", "sselectfunc" );
}
function sinputfunc( $input, $argv, $parser, $frame ) {
$value = $parser->recursiveTagParse( $input, $frame );
$extra = "";
if ( isset( $argv['id'] ) ) {
$extra .=" id='".$parser->recursiveTagParse( $argv['id'], $frame )."'";
}
if ( isset( $argv['size'] ) ) {
$extra .=" size='".$parser->recursiveTagParse( $argv['size'], $frame )."'";
}
if ( isset( $argv['class'] ) ) {
$extra .=" class='".$parser->recursiveTagParse( $argv['class'], $frame )."'";
}
if ( isset( $argv['name'] ) ) {
$extra .=" name='".$parser->recursiveTagParse( $argv['name'], $frame )."'";
}
if ( isset( $argv['template'] ) ) {
$extra .=" data-template='".$parser->recursiveTagParse( $argv['template'], $frame )."'";
}
return "<input type='text' $extra value='".$value."' />";
}
function sselectfunc( $input, $argv, $parser, $frame ) {
$id = $parser->recursiveTagParse( $argv['id'], $frame );
$value = $parser->recursiveTagParse( $input, $frame );
$defaultval = "";
if ( isset( $argv['default'] ) ) {
$defaultval = trim($parser->recursiveTagParse( $argv['default'], $frame ));
}
$extra = "";
if ( isset( $argv['class'] ) ) {
$extra .=" class='".$parser->recursiveTagParse( $argv['class'], $frame )."'";
}
if ( isset( $argv['name'] ) ) {
$extra .=" name='".$parser->recursiveTagParse( $argv['name'], $frame )."'";
}
$valuearr = explode(",", $value);
$out = "<select id='".$id."' $extra>";
if ( isset( $argv['empty'] ) ) {
$out.="<option></option>";
}
if ( count( $valuearr ) > 0) {
foreach ( $valuearr as $val ) {
$extra = "";
if ( trim($val) == $defaultval ) {
$extra = "selected='selected'";
}
$out.="<option ".$extra.">".trim($val)."</option>";
}
}
$out.= "</select>";
return $parser->insertStripItem( $out, $parser->mStripState );
}