r24577 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24576‎ | r24577 | r24578 >
Date:12:50, 4 August 2007
Author:robchurch
Status:old
Tags:
Comment:
Rewrite Xml::namespaceSelector() before it drives me to totemize somebody.
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -91,41 +91,37 @@
9292 }
9393
9494 /**
95 - * Create a namespace selector
 95+ * Build a drop-down box for selecting a namespace
9696 *
97 - * @param $selected Mixed: the namespace which should be selected, default ''
98 - * @param $allnamespaces String: value of a special item denoting all namespaces. Null to not include (default)
99 - * @param $includehidden Bool: include hidden namespaces?
100 - * @param array $exclude Array of namespace indexes to exclude
101 - * @return String: Html string containing the namespace selector
 97+ * @param mixed $selected Namespace which should be pre-selected
 98+ * @param mixed $all Value of an item denoting all namespaces, or null to omit
 99+ * @param bool $hidden Include hidden namespaces? [WTF? --RC]
 100+ * @param array $exclude Array of indexes to exclude
 101+ * @return string
102102 */
103 - public static function namespaceSelector($selected = '', $allnamespaces = null, $includehidden=false, $exclude = array() ) {
 103+ public static function namespaceSelector( $selected = '', $all = null, $hidden = false, $exclude = array() ) {
104104 global $wgContLang;
105 - if( is_null( $selected ) )
106 - $selected = '';
107 - $s = "\n<select id='namespace' name='namespace' class='namespaceselector'>\n";
108 - $arr = $wgContLang->getFormattedNamespaces();
109 - if( !is_null($allnamespaces) ) {
110 - $arr = array($allnamespaces => wfMsg('namespacesall')) + $arr;
111 - }
112 - foreach ($arr as $index => $name) {
 105+ $namespaces = $wgContLang->getFormattedNamespaces();
 106+ $options = array();
 107+
 108+ if( !is_null( $all ) )
 109+ $namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces;
 110+ foreach( $namespaces as $index => $name ) {
113111 if( $index < NS_MAIN || in_array( $index, $exclude ) )
114112 continue;
115 -
116 - $name = $index !== 0 ? $name : wfMsg('blanknamespace');
117 -
118 - if ($index === $selected) {
119 - $s .= "\t" . self::element("option",
120 - array("value" => $index, "selected" => "selected"),
121 - $name) . "\n";
122 - } else {
123 - $s .= "\t" . self::element("option", array("value" => $index), $name) . "\n";
124 - }
 113+ if( $index === 0 )
 114+ $name = wfMsg( 'blanknamespace' );
 115+ $options[] = self::option( $name, $index, $index === $selected );
125116 }
126 - $s .= "</select>\n";
127 - return $s;
 117+
 118+ return Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace',
 119+ 'class' => 'namespaceselector' ) )
 120+ . "\n"
 121+ . implode( "\n", $options )
 122+ . "\n"
 123+ . Xml::closeElement( 'select' );
128124 }
129 -
 125+
130126 /**
131127 * Create a date selector
132128 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007

Status & tagging log