* Refactored namespace selector to it's own function
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 1 Aug 2005 23:47:22 +0000 (23:47 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 1 Aug 2005 23:47:22 +0000 (23:47 +0000)
* Killed one undefined variable warning
* some other cleanup like html-safe message fixes

includes/GlobalFunctions.php
includes/SpecialAllpages.php
includes/SpecialContributions.php
includes/SpecialRecentchanges.php

index 7673e64..c1303a4 100644 (file)
@@ -1151,7 +1151,7 @@ function wfGetSiteNotice() {
  *
  * @param string $element
  * @param array $attribs Name=>value pairs. Values will be escaped.
- * @param bool $contents NULL to make an open tag only; '' for a contentless closed tag (default)
+ * @param string $contents NULL to make an open tag only; '' for a contentless closed tag (default)
  * @return string
  */
 function wfElement( $element, $attribs = null, $contents = '') {
@@ -1182,7 +1182,7 @@ function wfElement( $element, $attribs = null, $contents = '') {
  *
  * @param string $element
  * @param array $attribs Name=>value pairs. Values will be escaped.
- * @param bool $contents NULL to make an open tag only; '' for a contentless closed tag (default)
+ * @param string $contents NULL to make an open tag only; '' for a contentless closed tag (default)
  * @return string
  */
 function wfElementClean( $element, $attribs = array(), $contents = '') {
@@ -1195,6 +1195,38 @@ function wfElementClean( $element, $attribs = array(), $contents = '') {
        return wfElement( $element, $attribs, $contents );
 }
 
+/**
+ * Create a namespace selector
+ *
+ * @param mixed $selected The namespace which should be selected, default ''
+ * @param string $allnamespaces Value of a special item denoting all namespaces. Null to not include (default)
+ * @return Html string containing the namespace selector
+ */
+function &HTMLnamespaceselector($selected = '', $allnamespaces = null) {
+       global $wgContLang;
+       $s = "<select name='namespace' class='namespaceselector'>\n";
+       $arr = $wgContLang->getFormattedNamespaces();
+       if( !is_null($allnamespaces) ) {
+               /* TODO: rename contributionsall to something meaningfull */
+               $arr = array($allnamespaces => wfMsgHtml('contributionsall')) + $arr;
+       }
+       foreach ($arr as $index => $name) {
+               if ($index < NS_MAIN) continue;
+
+               $name = $index !== 0 ? $name : wfMsgHtml('blanknamespace');
+
+               if ($index === $selected) {
+                       $s .= wfElement("option",
+                                       array("value" => $index, "selected" => "selected"),
+                                       $name);
+               } else {
+                       $s .= wfElement("option", array("value" => $index), $name);
+               }
+       }
+       $s .= "</select>\n";
+       return $s;
+}
+
 /** Global singleton instance of MimeMagic. This is initialized on demand,
 * please always use the wfGetMimeMagic() function to get the instance.
 * 
index a735b9c..8ab20b1 100644 (file)
@@ -49,16 +49,7 @@ function namespaceForm ( $namespace = NS_MAIN, $from = '' ) {
        global $wgContLang, $wgScript;
        $t = Title::makeTitle( NS_SPECIAL, "Allpages" );
 
-       $namespaceselect = "<select name='namespace' id='nsselectbox'>";
-       $arr = $wgContLang->getFormattedNamespaces();
-       foreach ( $arr as $ns => $name ) {
-               if ($ns < NS_MAIN)
-                       continue;
-               $n = $ns == 0 ? wfMsgHtml ( 'blanknamespace' ) : $name;
-               $sel = $ns == $namespace ? ' selected="selected"' : '';
-               $namespaceselect .= "<option value='$ns'$sel>$n</option>\n";
-       }
-       $namespaceselect .= '</select>';
+       $namespaceselect = HTMLnamespaceselector($namespace, null);
 
        $frombox = "<input type='text' size='20' name='from' id='nsfrom' value=\""
                    . htmlspecialchars ( $from ) . '"/>';
@@ -220,6 +211,7 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
        
        $sk = $wgUser->getSkin();
 
+       $fromTitle = null;
        if ($from!="") {
                $fromTitle = Title::newFromURL( $from );
                $fromNS = $fromTitle->getNamespace();
index 35afe17..0e55285 100644 (file)
@@ -245,19 +245,10 @@ function wfSpecialContributions( $par = null ) {
                        "type" => "hidden",
                        "value" => $target));
        $nsform .= "<p>";
-       $nsform .= htmlspecialchars(wfMsg('namespace')) . " <select name='namespace'>\n";
-       foreach (array("" => wfMsg('contributionsall')) + $arr as $nsn => $name) {
-               if ($nsn < 0)
-                       continue;
-               $name = $nsn!==0 ? $name : wfMsg('blanknamespace');
-               $nsform .= ("$nsn" == "$ns") ?
-                               wfElement("option",
-                                       array("value" => $nsn, "selected" => "selected"),
-                                       $name)
-                               :
-                               wfElement("option", array("value" => $nsn), $name);
-       }
-       $nsform .= "</select>\n";
+       $nsform .= wfMsgHtml('namespace');
+
+       $nsform .= HTMLnamespaceselector($ns, '');
+
        $nsform .= wfElement("input", array(
                        "type" => "submit",
                        "value" => wfMsg('allpagessubmit')));
index 7405e68..653cf84 100644 (file)
@@ -187,7 +187,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                        wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults);
 
                        // Add end of the texts
-                       $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) );
+                       $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) . "\n" );
                        $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults) . '</div>');
                }
 
@@ -458,34 +458,22 @@ function rcNamespaceForm ( $namespace, $invert, $nondefaults ) {
        global $wgContLang, $wgScript;
        $t = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
 
-       $namespaceselect = "<select name='namespace' id='nsselectbox'>";
-       $namespaceselect .= '<option value="" ' . ($namespace === '' ? ' selected="selected"' : '') . '>' . wfMsg( 'contributionsall' ) . '</option>';
-       $arr =  $wgContLang->getFormattedNamespaces();
-       foreach ( $arr as $ns => $name ) {
-               if( $ns < NS_MAIN )
-                       continue;
-               $n = $ns === NS_MAIN ? wfMsg ( 'blanknamespace' ) : $name;
-               $sel = $namespace === (string) $ns ? ' selected="selected"' : '';
-               $namespaceselect .= "<option value='$ns'$sel>$n</option>";
-       }
-       $namespaceselect .= '</select>';
+       $namespaceselect = HTMLnamespaceselector($namespace, '');
+       $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
+       $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
+
+       $out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
 
-       $out = '';
-       $out .= "<div class='namespaceselector'><form method='get' action='{$wgScript}'>\n";
        foreach ( $nondefaults as $key => $value ) {
                if ($key != 'namespace' && $key != 'invert')
-                       $out .= "<input type='hidden' name='$key' value='$value' />";
+                       $out .= wfElement('input', array( 'type' => 'hidden', 'name' => $key, 'value' => $value));
        }
-
-       $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
-       $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
-       
        
        $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
        $out .= "
 <div id='nsselect' class='recentchanges'>
-       <label for='nsselectbox'>" . wfMsg('namespace') . "</label>
-       $namespaceselect $submitbutton $invertbox <label for='nsinvert'>" . wfMsg('invert') . "</label>
+       <label for='namespace'>" . wfMsgHtml('namespace') . "</label>
+       $namespaceselect $submitbutton $invertbox <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>
 </div>";
        $out .= '</form></div>';
        return $out;