Split getTypeMenu into two functions:
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Thu, 8 Sep 2011 08:51:32 +0000 (08:51 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Thu, 8 Sep 2011 08:51:32 +0000 (08:51 +0000)
* the current functions does the ugly thing extracting the current log type from array
* the new function just builds the selector, using XmlSelect - clearer and more flexible

includes/LogEventsList.php

index 43750ae..ed65c4e 100644 (file)
@@ -218,47 +218,45 @@ class LogEventsList {
         * @return String: Formatted HTML
         */
        private function getTypeMenu( $queryTypes ) {
-               global $wgLogRestrictions, $wgUser;
+               $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
+               $selector = $this->getTypeSelector();
+               $selector->setDefault( $queryType );
+               return $selector->getHtml();
+       }
 
-               $html = "<select name='type'>\n";
+       /**
+        * Returns log page selector.
+        * @param $default string The default selection
+        * @return XmlSelect
+        * @since 1.19
+        */
+       public function getTypeSelector() {
+               global $wgUser;
 
-               $validTypes = LogPage::validTypes();
                $typesByName = array(); // Temporary array
-
                // First pass to load the log names
-               foreach( $validTypes as $type ) {
-                       $text = LogPage::logName( $type );
-                       $typesByName[$type] = $text;
+               foreach(  LogPage::validTypes() as $type ) {
+                       $page = new LogPage( $type );
+                       $restriction = $page->getRestriction();
+                       if ( $wgUser->isAllowed( $restriction ) ) {
+                               $typesByName[$type] = $page->getName()->text();
+                       }
                }
 
                // Second pass to sort by name
                asort($typesByName);
 
-               // Note the query type
-               $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
-
                // Always put "All public logs" on top
-               if ( isset( $typesByName[''] ) ) {
-                       $all = $typesByName[''];
-                       unset( $typesByName[''] );
-                       $typesByName = array( '' => $all ) + $typesByName;
-               }
+               $public = $typesByName[''];
+               unset( $typesByName[''] );
+               $typesByName = array( '' => $public ) + $typesByName;
 
-               // Third pass generates sorted XHTML content
-               foreach( $typesByName as $type => $text ) {
-                       $selected = ($type == $queryType);
-                       // Restricted types
-                       if ( isset($wgLogRestrictions[$type]) ) {
-                               if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
-                                       $html .= Xml::option( $text, $type, $selected ) . "\n";
-                               }
-                       } else {
-                               $html .= Xml::option( $text, $type, $selected ) . "\n";
-                       }
+               $select = new XmlSelect( 'type' );
+               foreach( $typesByName as $type => $name ) {
+                       $select->addOption( $name, $type );
                }
 
-               $html .= '</select>';
-               return $html;
+               return $select;
        }
 
        /**