r14494 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14493‎ | r14494 | r14495 >
Date:08:21, 31 May 2006
Author:erik
Status:old
Tags:
Comment:
support for namespace checkboxes in fulltext search

syntax:
namespaces=Name 1,Name 2,Name 3
(namespace 0 hardcoded as 'Main' for now)

original patch by Leonardo Pimenta, cleaned up a bit
Modified paths:
  • /trunk/extensions/inputbox/inputbox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/inputbox/inputbox.php
@@ -9,10 +9,12 @@
1010 * This extension requires MediaWiki 1.5 or higher.
1111 *
1212 * @author Erik Moeller <moeller@scireview.de>
 13+ * namespaces search improvements partially by
 14+ * Leonardo Pimenta <leo.lns@gmail.com>
1315 * @copyright Public domain
1416 * @license Public domain
1517 * @package MediaWikiExtensions
16 - * @version 0.1
 18+ * @version 0.1.1
1719 */
1820
1921 /**
@@ -36,6 +38,8 @@
3739 }
3840
3941
 42+
 43+
4044 /**
4145 * Renders an inputbox based on information provided by $input.
4246 */
@@ -50,11 +54,12 @@
5155 getBoxOption($inputbox->bgcolor,$input,'bgcolor');
5256 getBoxOption($inputbox->buttonlabel,$input,'buttonlabel');
5357 getBoxOption($inputbox->searchbuttonlabel,$input,'searchbuttonlabel');
 58+ getBoxOption($inputbox->namespaces,$input,'namespaces');
5459 getBoxOption($inputbox->id,$input,'id');
5560 getBoxOption($inputbox->labeltext,$input,'labeltext');
56 - getBoxOption( $inputbox->br, $input, 'break' );
 61+ getBoxOption($inputbox->br, $input, 'break');
5762 $inputbox->lineBreak();
58 - $inputbox->checkWidth();
 63+ $inputbox->checkWidth();
5964
6065 $boxhtml=$inputbox->render();
6166 # Maybe support other useful magic words here
@@ -94,7 +99,7 @@
95100 }
96101 }
97102 function getSearchForm() {
98 - global $wgUser;
 103+ global $wgUser, $wgContLang;
99104
100105 $sk=$wgUser->getSkin();
101106 $searchpath = $sk->escapeSearchLink();
@@ -104,25 +109,61 @@
105110 if(!$this->searchbuttonlabel) {
106111 $this->searchbuttonlabel = wfMsgHtml( 'searchfulltext' );
107112 }
108 -
 113+
 114+
109115 $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 - />&nbsp;<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}
125122 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}" />&nbsp;
 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;
127168 }
128169
129170 function getSearchForm2() {
@@ -192,14 +233,13 @@
193234 $cond = ( strtolower( $this->br ) == "no" );
194235 $this->br = $cond ? '' : '<br />';
195236 }
196 -
 237+
197238 /**
198239 * If the width is not supplied, set it to 50
199240 */
200241 function checkWidth() {
201242 if( !$this->width || trim( $this->width ) == '' )
202243 $this->width = 50;
203 - }
204 -
 244+ }
205245 }
206246 ?>

Status & tagging log