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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
<?php
/**
* This file contains the main include file for the Inputbox extension of
* MediaWiki.
*
* Usage: require_once("path/to/inputbox.php"); in LocalSettings.php
*
* This extension requires MediaWiki 1.5 or higher.
*
* @author Erik Moeller <moeller@scireview.de>
* namespaces search improvements partially by
* Leonardo Pimenta <leo.lns@gmail.com>
* @copyright Public domain
* @license Public domain
* @package MediaWikiExtensions
* @version 0.1.1
*/
/**
* Register the Inputbox extension with MediaWiki
*/
$wgExtensionFunctions[] = 'registerInputboxExtension';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Inputbox',
'author' => 'Erik Moeller',
'url' => 'http://meta.wikimedia.org/wiki/Help:Inputbox',
);
/**
* Sets the tag that this extension looks for and the function by which it
* operates
*/
function registerInputboxExtension()
{
global $wgParser;
$wgParser->setHook('inputbox', 'renderInputbox');
}
/**
* Renders an inputbox based on information provided by $input.
*/
function renderInputbox($input, $params, &$parser)
{
$inputbox=new Inputbox( $parser );
getBoxOption($inputbox->type,$input,'type');
getBoxOption($inputbox->width,$input,'width',true);
getBoxOption($inputbox->preload,$input,'preload');
getBoxOption($inputbox->editintro,$input,'editintro');
getBoxOption($inputbox->defaulttext,$input,'default');
getBoxOption($inputbox->bgcolor,$input,'bgcolor');
getBoxOption($inputbox->buttonlabel,$input,'buttonlabel');
getBoxOption($inputbox->searchbuttonlabel,$input,'searchbuttonlabel');
getBoxOption($inputbox->namespaces,$input,'namespaces');
getBoxOption($inputbox->id,$input,'id');
getBoxOption($inputbox->labeltext,$input,'labeltext');
getBoxOption($inputbox->br, $input, 'break');
getBoxOption($inputbox->hidden, $input, 'hidden');
$inputbox->lineBreak();
$inputbox->checkWidth();
$boxhtml=$inputbox->render();
# Maybe support other useful magic words here
$boxhtml=str_replace("{{PAGENAME}}",$parser->mTitle->getText(),$boxhtml);
if($boxhtml) {
return $boxhtml;
} else {
return "<br /> <font color='red'>Input box '{$inputbox->type}' not defined.</font>";
}
}
function getBoxOption(&$value,&$input,$name,$isNumber=false) {
if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
if($isNumber) {
$value=intval($matches[1]);
} else {
$value=htmlspecialchars($matches[1]);
}
}
}
class Inputbox {
var $type,$width,$preload,$editintro, $br;
var $defaulttext,$bgcolor,$buttonlabel,$searchbuttonlabel;
var $hidden;
function InputBox( &$parser ) {
$this->parser =& $parser;
}
function render() {
if($this->type=='create' || $this->type=='comment') {
return $this->getCreateForm();
} elseif($this->type=='search') {
return $this->getSearchForm();
} elseif($this->type=='search2') {
return $this->getSearchForm2();
} else {
return false;
}
}
function getSearchForm() {
global $wgUser, $wgContLang;
$sk=$wgUser->getSkin();
$searchpath = $sk->escapeSearchLink();
if(!$this->buttonlabel) {
$this->buttonlabel = wfMsgHtml( 'tryexact' );
}
if(!$this->searchbuttonlabel) {
$this->searchbuttonlabel = wfMsgHtml( 'searchfulltext' );
}
$type = $this->hidden ? 'hidden' : 'text';
$searchform=<<<ENDFORM
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="center" bgcolor="{$this->bgcolor}">
<form name="searchbox" action="$searchpath" class="searchbox">
<input class="searchboxInput" name="search" type="{$type}"
value="{$this->defaulttext}" size="{$this->width}" />{$this->br}
ENDFORM;
// disabled when namespace filter active
$gobutton=<<<ENDGO
<input type='submit' name="go" class="searchboxGoButton" value="{$this->buttonlabel}" />
ENDGO;
// Determine namespace checkboxes
$namespaces = $wgContLang->getNamespaces();
$namespacesarray = explode(",",$this->namespaces);
// Test if namespaces requested by user really exist
$searchform2 = '';
if ($this->namespaces) {
foreach ($namespacesarray as $usernamespace) {
$checked = '';
// Namespace needs to be checked if flagged with "**" or if it's the only one
if (strstr($usernamespace,'**') || count($namespacesarray)==1) {
$usernamespace = str_replace("**","",$usernamespace);
$checked =" checked";
}
foreach ( $namespaces as $i => $name ) {
if ($i < 0){
continue;
}elseif($i==0) {
$name='Main';
}
if ($usernamespace == $name) {
$searchform2 .= "<input type=checkbox name=\"ns{$i}\" value=\"1\"{$checked}>{$usernamespace}";
}
}
}
//Line feed
$searchform2 .= $this->br;
//If namespaces are defined remove the go button
//because go button doesn't accept namespaces parameters
$gobutton='';
}
$searchform3=<<<ENDFORM2
{$gobutton}
<input type='submit' name="searchx" class="searchboxSearchButton" value="{$this->searchbuttonlabel}" />
</form>
</td>
</tr>
</table>
ENDFORM2;
//Return form values
return $searchform . $searchform2 . $searchform3;
}
function getSearchForm2() {
global $wgUser;
$sk=$wgUser->getSkin();
$searchpath = $sk->escapeSearchLink();
if(!$this->buttonlabel) {
$this->buttonlabel = wfMsgHtml( 'tryexact' );
}
$output = $this->parser->parse( $this->labeltext,
$this->parser->mTitle, $this->parser->mOptions, false, false );
$this->labeltext = $output->getText();
$this->labeltext = str_replace('<p>', '', $this->labeltext);
$this->labeltext = str_replace('</p>', '', $this->labeltext);
$type = $this->hidden ? 'hidden' : 'text';
$searchform=<<<ENDFORM
<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" />
ENDFORM;
if ( !empty( $this->fulltextbtn ) ) // this is wrong...
$searchform .= '<input type="submit" name="fulltext" class="bodySearchBtnSearch" value="{$this->searchbuttonlabel}" />';
$searchform .= '</div></form>';
return $searchform;
}
function getCreateForm() {
global $wgScript;
$action = htmlspecialchars( $wgScript );
if($this->type=="comment") {
$comment='<input type="hidden" name="section" value="new" />';
if(!$this->buttonlabel) {
$this->buttonlabel = wfMsgHtml( "postcomment" );
}
} else {
$comment='';
if(!$this->buttonlabel) {
$this->buttonlabel = wfMsgHtml( "createarticle" );
}
}
$type = $this->hidden ? 'hidden' : 'text';
$createform=<<<ENDFORM
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="center" bgcolor="{$this->bgcolor}">
<form name="createbox" action="$action" method="get" class="createbox">
<input type='hidden' name="action" value="edit" />
<input type="hidden" name="preload" value="{$this->preload}" />
<input type="hidden" name="editintro" value="{$this->editintro}" />
{$comment}
<input class="createboxInput" name="title" type="{$type}"
value="{$this->defaulttext}" size="{$this->width}" />{$this->br}
<input type='submit' name="create" class="createboxButton"
value="{$this->buttonlabel}" />
</form>
</td>
</tr>
</table>
ENDFORM;
return $createform;
}
function lineBreak() {
# Should we be inserting a <br /> tag?
$cond = ( strtolower( $this->br ) == "no" );
$this->br = $cond ? '' : '<br />';
}
/**
* If the width is not supplied, set it to 50
*/
function checkWidth() {
if( !$this->width || trim( $this->width ) == '' )
$this->width = 50;
}
}
?>
|