Index: trunk/extensions/inputbox/inputbox.php |
— | — | @@ -9,10 +9,12 @@ |
10 | 10 | * This extension requires MediaWiki 1.5 or higher. |
11 | 11 | * |
12 | 12 | * @author Erik Moeller <moeller@scireview.de> |
| 13 | + * namespaces search improvements partially by |
| 14 | + * Leonardo Pimenta <leo.lns@gmail.com> |
13 | 15 | * @copyright Public domain |
14 | 16 | * @license Public domain |
15 | 17 | * @package MediaWikiExtensions |
16 | | - * @version 0.1 |
| 18 | + * @version 0.1.1 |
17 | 19 | */ |
18 | 20 | |
19 | 21 | /** |
— | — | @@ -36,6 +38,8 @@ |
37 | 39 | } |
38 | 40 | |
39 | 41 | |
| 42 | + |
| 43 | + |
40 | 44 | /** |
41 | 45 | * Renders an inputbox based on information provided by $input. |
42 | 46 | */ |
— | — | @@ -50,11 +54,12 @@ |
51 | 55 | getBoxOption($inputbox->bgcolor,$input,'bgcolor'); |
52 | 56 | getBoxOption($inputbox->buttonlabel,$input,'buttonlabel'); |
53 | 57 | getBoxOption($inputbox->searchbuttonlabel,$input,'searchbuttonlabel'); |
| 58 | + getBoxOption($inputbox->namespaces,$input,'namespaces'); |
54 | 59 | getBoxOption($inputbox->id,$input,'id'); |
55 | 60 | getBoxOption($inputbox->labeltext,$input,'labeltext'); |
56 | | - getBoxOption( $inputbox->br, $input, 'break' ); |
| 61 | + getBoxOption($inputbox->br, $input, 'break'); |
57 | 62 | $inputbox->lineBreak(); |
58 | | - $inputbox->checkWidth(); |
| 63 | + $inputbox->checkWidth(); |
59 | 64 | |
60 | 65 | $boxhtml=$inputbox->render(); |
61 | 66 | # Maybe support other useful magic words here |
— | — | @@ -94,7 +99,7 @@ |
95 | 100 | } |
96 | 101 | } |
97 | 102 | function getSearchForm() { |
98 | | - global $wgUser; |
| 103 | + global $wgUser, $wgContLang; |
99 | 104 | |
100 | 105 | $sk=$wgUser->getSkin(); |
101 | 106 | $searchpath = $sk->escapeSearchLink(); |
— | — | @@ -104,25 +109,61 @@ |
105 | 110 | if(!$this->searchbuttonlabel) { |
106 | 111 | $this->searchbuttonlabel = wfMsgHtml( 'searchfulltext' ); |
107 | 112 | } |
108 | | - |
| 113 | + |
| 114 | + |
109 | 115 | $searchform=<<<ENDFORM |
110 | | -<table border="0" width="100%" cellspacing="0" cellpadding="0"> |
111 | | -<tr> |
112 | | -<td align="center" bgcolor="{$this->bgcolor}"> |
113 | | -<form name="searchbox" action="$searchpath" class="searchbox"> |
114 | | - <input class="searchboxInput" name="search" type="text" |
115 | | - value="{$this->defaulttext}" size="{$this->width}"/>{$this->br} |
116 | | - <input type='submit' name="go" class="searchboxGoButton" |
117 | | - value="{$this->buttonlabel}" |
118 | | - /> <input type='submit' name="fulltext" |
119 | | - class="searchboxSearchButton" |
120 | | - value="{$this->searchbuttonlabel}" /> |
121 | | -</form> |
122 | | -</td> |
123 | | -</tr> |
124 | | -</table> |
| 116 | + <table border="0" width="100%" cellspacing="0" cellpadding="0"> |
| 117 | + <tr> |
| 118 | + <td align="center" bgcolor="{$this->bgcolor}"> |
| 119 | + <form name="searchbox" action="$searchpath" class="searchbox"> |
| 120 | + <input class="searchboxInput" name="search" type="text" |
| 121 | + value="{$this->defaulttext}" size="{$this->width}"/>{$this->br} |
125 | 122 | ENDFORM; |
126 | | - return $searchform; |
| 123 | + |
| 124 | + // disabled when namespace filter active |
| 125 | + $gobutton=<<<ENDGO |
| 126 | +<input type='submit' name="go" class="searchboxGoButton" value="{$this->buttonlabel}" /> |
| 127 | +ENDGO; |
| 128 | + // Determine namespace checkboxes |
| 129 | + $namespaces = $wgContLang->getNamespaces(); |
| 130 | + $namespacesarray = explode(",",$this->namespaces); |
| 131 | + |
| 132 | + // Test if namespaces requested by user really exist |
| 133 | + if ($this->namespaces) { |
| 134 | + foreach ($namespacesarray as $usernamespace) { |
| 135 | + $checked = ''; |
| 136 | + // Namespace needs to be checked if flagged with "**" or if it's the only one |
| 137 | + if (strstr($usernamespace,'**') || count($namespacesarray)==1) { |
| 138 | + $usernamespace = str_replace("**","",$usernamespace); |
| 139 | + $checked =" checked"; |
| 140 | + } |
| 141 | + foreach ( $namespaces as $i => $name ) { |
| 142 | + if ($i < 0){ |
| 143 | + continue; |
| 144 | + }elseif($i==0) { |
| 145 | + $name='Main'; |
| 146 | + } |
| 147 | + if ($usernamespace == $name) { |
| 148 | + $searchform2 .= "<input type=checkbox name=\"ns{$i}\" value=\"1\"{$checked}>{$usernamespace}"; |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + //Line feed |
| 153 | + $searchform2 .= $this->br; |
| 154 | + //If namespaces are defined remove the go button |
| 155 | + //because go button doesn't accept namespaces parameters |
| 156 | + $gobutton=''; |
| 157 | + } |
| 158 | + $searchform3=<<<ENDFORM2 |
| 159 | + {$gobutton} |
| 160 | + <input type='submit' name="searchx" class="searchboxSearchButton" value="{$this->searchbuttonlabel}" /> |
| 161 | + </form> |
| 162 | + </td> |
| 163 | + </tr> |
| 164 | + </table> |
| 165 | +ENDFORM2; |
| 166 | + //Return form values |
| 167 | + return $searchform . $searchform2 . $searchform3; |
127 | 168 | } |
128 | 169 | |
129 | 170 | function getSearchForm2() { |
— | — | @@ -192,14 +233,13 @@ |
193 | 234 | $cond = ( strtolower( $this->br ) == "no" ); |
194 | 235 | $this->br = $cond ? '' : '<br />'; |
195 | 236 | } |
196 | | - |
| 237 | + |
197 | 238 | /** |
198 | 239 | * If the width is not supplied, set it to 50 |
199 | 240 | */ |
200 | 241 | function checkWidth() { |
201 | 242 | if( !$this->width || trim( $this->width ) == '' ) |
202 | 243 | $this->width = 50; |
203 | | - } |
204 | | - |
| 244 | + } |
205 | 245 | } |
206 | 246 | ?> |