r92138 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92137‎ | r92138 | r92139 >
Date:03:51, 14 July 2011
Author:robin
Status:ok (Comments)
Tags:
Comment:
InputBox:
* instead of checking each namespace if it is given through the parameter, check each given namespace if it is a valid one
* this fixes the inconsistency where 2 namespaces are given but only 1 is valid and that one is shown (normally if there is only 1 given, it is hidden)
* fix bug 22591 (Allow i18n of Main namespace search option label)
* allow namespace aliases as well
* also trim the given namespaces, so spaces do not make them invalid
Modified paths:
  • /trunk/extensions/InputBox/InputBox.classes.php (modified) (history)
  • /trunk/extensions/InputBox/InputBox.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InputBox/InputBox.classes.php
@@ -72,7 +72,7 @@
7373 * @param $type
7474 */
7575 public function getSearchForm( $type ) {
76 - global $wgContLang;
 76+ global $wgContLang, $wgNamespaceAliases;
7777
7878 // Use button label fallbacks
7979 if ( !$this->mButtonLabel ) {
@@ -120,51 +120,70 @@
121121 $htmlOut .= $this->mBR;
122122
123123 // Determine namespace checkboxes
124 - $namespaces = $wgContLang->getNamespaces();
125124 $namespacesArray = explode( ',', $this->mNamespaces );
126125 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 ) {
128158 $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 ) {
132161 $checked = array( 'checked' => 'checked' );
133162 }
134163
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 .= '&#160;' . 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 .= '&#160;' . Xml::label( $name, 'mw-inputbox-ns' . $i );
 187+ $htmlOut .= '</div> ';
169188 }
170189 }
171190
Index: trunk/extensions/InputBox/InputBox.i18n.php
@@ -22,6 +22,7 @@
2323 'tryexact' => 'Try exact match',
2424 'searchfulltext' => 'Search full text',
2525 'createarticle' => 'Create page',
 26+ 'inputbox-ns-main' => 'Main',
2627 );
2728
2829 /** Message documentation (Message documentation)
@@ -1221,6 +1222,7 @@
12221223 'tryexact' => 'Zoeken op exacte overeenkomst',
12231224 'searchfulltext' => 'Volledige tekst doorzoeken',
12241225 'createarticle' => 'Pagina aanmaken',
 1226+ 'inputbox-ns-main' => 'Hoofdnaamruimte',
12251227 );
12261228
12271229 /** Norwegian Nynorsk (‪Norsk (nynorsk)‬)

Follow-up revisions

RevisionCommit summaryAuthorDate
r92139r92138: bump version (and update @version)robin03:59, 14 July 2011
r95282Use strpos() instead of strstr(), per Catrope on r92138.robin23:47, 22 August 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:55, 14 July 2011

Core refers to the zero namespace as (Main).

#Comment by SPQRobin (talk | contribs)   09:33, 14 July 2011

This has always been Main without brackets in InputBox...

#Comment by Catrope (talk | contribs)   09:01, 20 August 2011
+				if ( strstr( $userNS, '**' ) ) {

From the PHP manual:

If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead.

Status & tagging log