4
* This file contains the main include file for the Inputbox extension of
7
* Usage: require_once("path/to/inputbox.php"); in LocalSettings.php
9
* This extension requires MediaWiki 1.5 or higher.
11
* @author Erik Moeller <moeller@scireview.de>
12
* namespaces search improvements partially by
13
* Leonardo Pimenta <leo.lns@gmail.com>
14
* @copyright Public domain
15
* @license Public domain
16
* @package MediaWikiExtensions
21
* Register the Inputbox extension with MediaWiki
23
$wgExtensionFunctions[] = 'registerInputboxExtension';
24
$wgExtensionCredits['parserhook'][] = array(
26
'author' => 'Erik Moeller',
27
'url' => 'http://meta.wikimedia.org/wiki/Help:Inputbox',
31
* Sets the tag that this extension looks for and the function by which it
34
function registerInputboxExtension()
37
$wgParser->setHook('inputbox', 'renderInputbox');
44
* Renders an inputbox based on information provided by $input.
46
function renderInputbox($input, $params, &$parser)
48
$inputbox=new Inputbox( $parser );
49
getBoxOption($inputbox->type,$input,'type');
50
getBoxOption($inputbox->width,$input,'width',true);
51
getBoxOption($inputbox->preload,$input,'preload');
52
getBoxOption($inputbox->editintro,$input,'editintro');
53
getBoxOption($inputbox->defaulttext,$input,'default');
54
getBoxOption($inputbox->bgcolor,$input,'bgcolor');
55
getBoxOption($inputbox->buttonlabel,$input,'buttonlabel');
56
getBoxOption($inputbox->searchbuttonlabel,$input,'searchbuttonlabel');
57
getBoxOption($inputbox->namespaces,$input,'namespaces');
58
getBoxOption($inputbox->id,$input,'id');
59
getBoxOption($inputbox->labeltext,$input,'labeltext');
60
getBoxOption($inputbox->br, $input, 'break');
61
getBoxOption($inputbox->hidden, $input, 'hidden');
62
$inputbox->lineBreak();
63
$inputbox->checkWidth();
65
$boxhtml=$inputbox->render();
66
# Maybe support other useful magic words here
67
$boxhtml=str_replace("{{PAGENAME}}",$parser->mTitle->getText(),$boxhtml);
71
return "<br /> <font color='red'>Input box '{$inputbox->type}' not defined.</font>";
76
function getBoxOption(&$value,&$input,$name,$isNumber=false) {
78
if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
80
$value=intval($matches[1]);
82
$value=htmlspecialchars($matches[1]);
88
var $type,$width,$preload,$editintro, $br;
89
var $defaulttext,$bgcolor,$buttonlabel,$searchbuttonlabel;
92
function InputBox( &$parser ) {
93
$this->parser =& $parser;
97
if($this->type=='create' || $this->type=='comment') {
98
return $this->getCreateForm();
99
} elseif($this->type=='search') {
100
return $this->getSearchForm();
101
} elseif($this->type=='search2') {
102
return $this->getSearchForm2();
107
function getSearchForm() {
108
global $wgUser, $wgContLang;
110
$sk=$wgUser->getSkin();
111
$searchpath = $sk->escapeSearchLink();
112
if(!$this->buttonlabel) {
113
$this->buttonlabel = wfMsgHtml( 'tryexact' );
115
if(!$this->searchbuttonlabel) {
116
$this->searchbuttonlabel = wfMsgHtml( 'searchfulltext' );
120
$type = $this->hidden ? 'hidden' : 'text';
121
$searchform=<<<ENDFORM
122
<table border="0" width="100%" cellspacing="0" cellpadding="0">
124
<td align="center" bgcolor="{$this->bgcolor}">
125
<form name="searchbox" action="$searchpath" class="searchbox">
126
<input class="searchboxInput" name="search" type="{$type}"
127
value="{$this->defaulttext}" size="{$this->width}" />{$this->br}
130
// disabled when namespace filter active
132
<input type='submit' name="go" class="searchboxGoButton" value="{$this->buttonlabel}" />
134
// Determine namespace checkboxes
135
$namespaces = $wgContLang->getNamespaces();
136
$namespacesarray = explode(",",$this->namespaces);
138
// Test if namespaces requested by user really exist
140
if ($this->namespaces) {
141
foreach ($namespacesarray as $usernamespace) {
143
// Namespace needs to be checked if flagged with "**" or if it's the only one
144
if (strstr($usernamespace,'**') || count($namespacesarray)==1) {
145
$usernamespace = str_replace("**","",$usernamespace);
146
$checked =" checked";
148
foreach ( $namespaces as $i => $name ) {
154
if ($usernamespace == $name) {
155
$searchform2 .= "<input type=checkbox name=\"ns{$i}\" value=\"1\"{$checked}>{$usernamespace}";
160
$searchform2 .= $this->br;
161
//If namespaces are defined remove the go button
162
//because go button doesn't accept namespaces parameters
165
$searchform3=<<<ENDFORM2
167
<input type='submit' name="searchx" class="searchboxSearchButton" value="{$this->searchbuttonlabel}" />
174
return $searchform . $searchform2 . $searchform3;
177
function getSearchForm2() {
180
$sk=$wgUser->getSkin();
181
$searchpath = $sk->escapeSearchLink();
182
if(!$this->buttonlabel) {
183
$this->buttonlabel = wfMsgHtml( 'tryexact' );
186
$output = $this->parser->parse( $this->labeltext,
187
$this->parser->mTitle, $this->parser->mOptions, false, false );
188
$this->labeltext = $output->getText();
189
$this->labeltext = str_replace('<p>', '', $this->labeltext);
190
$this->labeltext = str_replace('</p>', '', $this->labeltext);
192
$type = $this->hidden ? 'hidden' : 'text';
193
$searchform=<<<ENDFORM
194
<form action="$searchpath" class="bodySearch" id="bodySearch{$this->id}"><div class="bodySearchWrap"><label for="bodySearchIput{$this->id}">{$this->labeltext}</label><input type="{$type}" name="search" size="{$this->width}" class="bodySearchIput" id="bodySearchIput{$this->id}" /><input type="submit" name="go" value="{$this->buttonlabel}" class="bodySearchBtnGo" />
197
if ( !empty( $this->fulltextbtn ) ) // this is wrong...
198
$searchform .= '<input type="submit" name="fulltext" class="bodySearchBtnSearch" value="{$this->searchbuttonlabel}" />';
200
$searchform .= '</div></form>';
206
function getCreateForm() {
209
$action = htmlspecialchars( $wgScript );
210
if($this->type=="comment") {
211
$comment='<input type="hidden" name="section" value="new" />';
212
if(!$this->buttonlabel) {
213
$this->buttonlabel = wfMsgHtml( "postcomment" );
217
if(!$this->buttonlabel) {
218
$this->buttonlabel = wfMsgHtml( "createarticle" );
221
$type = $this->hidden ? 'hidden' : 'text';
222
$createform=<<<ENDFORM
223
<table border="0" width="100%" cellspacing="0" cellpadding="0">
225
<td align="center" bgcolor="{$this->bgcolor}">
226
<form name="createbox" action="$action" method="get" class="createbox">
227
<input type='hidden' name="action" value="edit" />
228
<input type="hidden" name="preload" value="{$this->preload}" />
229
<input type="hidden" name="editintro" value="{$this->editintro}" />
231
<input class="createboxInput" name="title" type="{$type}"
232
value="{$this->defaulttext}" size="{$this->width}" />{$this->br}
233
<input type='submit' name="create" class="createboxButton"
234
value="{$this->buttonlabel}" />
243
function lineBreak() {
244
# Should we be inserting a <br /> tag?
245
$cond = ( strtolower( $this->br ) == "no" );
246
$this->br = $cond ? '' : '<br />';
250
* If the width is not supplied, set it to 50
252
function checkWidth() {
253
if( !$this->width || trim( $this->width ) == '' )