Index: trunk/extensions/InputBox/InputBox.classes.php |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | * @param $type |
74 | 74 | */ |
75 | 75 | public function getSearchForm( $type ) { |
76 | | - global $wgContLang; |
| 76 | + global $wgContLang, $wgNamespaceAliases; |
77 | 77 | |
78 | 78 | // Use button label fallbacks |
79 | 79 | if ( !$this->mButtonLabel ) { |
— | — | @@ -120,51 +120,70 @@ |
121 | 121 | $htmlOut .= $this->mBR; |
122 | 122 | |
123 | 123 | // Determine namespace checkboxes |
124 | | - $namespaces = $wgContLang->getNamespaces(); |
125 | 124 | $namespacesArray = explode( ',', $this->mNamespaces ); |
126 | 125 | if ( $this->mNamespaces ) { |
127 | | - foreach ( $namespacesArray as $userNamespace ) { |
| 126 | + $namespaces = $wgContLang->getNamespaces(); |
| 127 | + $nsAliases = array_merge( $wgContLang->getNamespaceAliases(), $wgNamespaceAliases ); |
| 128 | + $showNamespaces = array(); |
| 129 | + # Check for valid namespaces |
| 130 | + foreach ( $namespacesArray as $userNS ) { |
| 131 | + $userNS = trim( $userNS ); # no whitespace |
| 132 | + |
| 133 | + $checkedNS = array(); |
| 134 | + # Namespace needs to be checked if flagged with "**" |
| 135 | + if ( strstr( $userNS, '**' ) ) { |
| 136 | + $userNS = str_replace( '**', '', $userNS ); |
| 137 | + $checkedNS[$userNS] = true; |
| 138 | + } |
| 139 | + |
| 140 | + $mainMsg = wfMsgForContent( 'inputbox-ns-main' ); |
| 141 | + if( $userNS == 'Main' || $userNS == $mainMsg ) { |
| 142 | + $i = 0; |
| 143 | + } elseif( array_search( $userNS, $namespaces ) ) { |
| 144 | + $i = array_search( $userNS, $namespaces ); |
| 145 | + } elseif ( isset( $nsAliases[$userNS] ) ) { |
| 146 | + $i = $nsAliases[$userNS]; |
| 147 | + } else { |
| 148 | + continue; # Namespace not recognised, skip |
| 149 | + } |
| 150 | + $showNamespaces[$i] = $userNS; |
| 151 | + if( isset( $checkedNS[$userNS] ) && $checkedNS[$userNS] ) { |
| 152 | + $checkedNS[$i] = true; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + # Show valid namespaces |
| 157 | + foreach( $showNamespaces as $i => $name ) { |
128 | 158 | $checked = array(); |
129 | | - // Namespace needs to be checked if flagged with "**" or if it's the only one |
130 | | - if ( strstr( $userNamespace, '**' ) || count( $namespacesArray ) == 1 ) { |
131 | | - $userNamespace = str_replace( '**', '', $userNamespace ); |
| 159 | + // Namespace flagged with "**" or if it's the only one |
| 160 | + if ( ( isset( $checkedNS[$i] ) && $checkedNS[$i] ) || count( $showNamespaces ) == 1 ) { |
132 | 161 | $checked = array( 'checked' => 'checked' ); |
133 | 162 | } |
134 | 163 | |
135 | | - // Namespace checkboxes |
136 | | - foreach ( $namespaces as $i => $name ) { |
137 | | - if ( $i < 0 ) { |
138 | | - continue; |
139 | | - } elseif ( $i == 0 ) { |
140 | | - $name = 'Main'; |
141 | | - } |
142 | | - if ( $userNamespace == $name ) { |
143 | | - if ( count( $namespacesArray ) == 1 ) { |
144 | | - // Checkbox |
145 | | - $htmlOut .= Xml::element( 'input', |
146 | | - array( |
147 | | - 'type' => 'hidden', |
148 | | - 'name' => 'ns' . $i, |
149 | | - 'value' => 1, |
150 | | - 'id' => 'mw-inputbox-ns' . $i |
151 | | - ) + $checked |
152 | | - ); |
153 | | - } else { |
154 | | - // Checkbox |
155 | | - $htmlOut .= ' <div class="inputbox-element" style="display: inline; white-space: nowrap;">'; |
156 | | - $htmlOut .= Xml::element( 'input', |
157 | | - array( |
158 | | - 'type' => 'checkbox', |
159 | | - 'name' => 'ns' . $i, |
160 | | - 'value' => 1, |
161 | | - 'id' => 'mw-inputbox-ns' . $i |
162 | | - ) + $checked |
163 | | - ); |
164 | | - // Label |
165 | | - $htmlOut .= ' ' . Xml::label( $userNamespace, 'mw-inputbox-ns' . $i ); |
166 | | - $htmlOut .= '</div> '; |
167 | | - } |
168 | | - } |
| 164 | + if ( count( $showNamespaces ) == 1 ) { |
| 165 | + // Checkbox |
| 166 | + $htmlOut .= Xml::element( 'input', |
| 167 | + array( |
| 168 | + 'type' => 'hidden', |
| 169 | + 'name' => 'ns' . $i, |
| 170 | + 'value' => 1, |
| 171 | + 'id' => 'mw-inputbox-ns' . $i |
| 172 | + ) + $checked |
| 173 | + ); |
| 174 | + } else { |
| 175 | + // Checkbox |
| 176 | + $htmlOut .= ' <div class="inputbox-element" style="display: inline; white-space: nowrap;">'; |
| 177 | + $htmlOut .= Xml::element( 'input', |
| 178 | + array( |
| 179 | + 'type' => 'checkbox', |
| 180 | + 'name' => 'ns' . $i, |
| 181 | + 'value' => 1, |
| 182 | + 'id' => 'mw-inputbox-ns' . $i |
| 183 | + ) + $checked |
| 184 | + ); |
| 185 | + // Label |
| 186 | + $htmlOut .= ' ' . Xml::label( $name, 'mw-inputbox-ns' . $i ); |
| 187 | + $htmlOut .= '</div> '; |
169 | 188 | } |
170 | 189 | } |
171 | 190 | |
Index: trunk/extensions/InputBox/InputBox.i18n.php |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | 'tryexact' => 'Try exact match', |
24 | 24 | 'searchfulltext' => 'Search full text', |
25 | 25 | 'createarticle' => 'Create page', |
| 26 | + 'inputbox-ns-main' => 'Main', |
26 | 27 | ); |
27 | 28 | |
28 | 29 | /** Message documentation (Message documentation) |
— | — | @@ -1221,6 +1222,7 @@ |
1222 | 1223 | 'tryexact' => 'Zoeken op exacte overeenkomst', |
1223 | 1224 | 'searchfulltext' => 'Volledige tekst doorzoeken', |
1224 | 1225 | 'createarticle' => 'Pagina aanmaken', |
| 1226 | + 'inputbox-ns-main' => 'Hoofdnaamruimte', |
1225 | 1227 | ); |
1226 | 1228 | |
1227 | 1229 | /** Norwegian Nynorsk (Norsk (nynorsk)) |