Index: trunk/phase3/includes/LogEventsList.php |
— | — | @@ -218,47 +218,45 @@ |
219 | 219 | * @return String: Formatted HTML |
220 | 220 | */ |
221 | 221 | private function getTypeMenu( $queryTypes ) { |
222 | | - global $wgLogRestrictions, $wgUser; |
| 222 | + $queryType = count($queryTypes) == 1 ? $queryTypes[0] : ''; |
| 223 | + $selector = $this->getTypeSelector(); |
| 224 | + $selector->setDefault( $queryType ); |
| 225 | + return $selector->getHtml(); |
| 226 | + } |
223 | 227 | |
224 | | - $html = "<select name='type'>\n"; |
| 228 | + /** |
| 229 | + * Returns log page selector. |
| 230 | + * @param $default string The default selection |
| 231 | + * @return XmlSelect |
| 232 | + * @since 1.19 |
| 233 | + */ |
| 234 | + public function getTypeSelector() { |
| 235 | + global $wgUser; |
225 | 236 | |
226 | | - $validTypes = LogPage::validTypes(); |
227 | 237 | $typesByName = array(); // Temporary array |
228 | | - |
229 | 238 | // First pass to load the log names |
230 | | - foreach( $validTypes as $type ) { |
231 | | - $text = LogPage::logName( $type ); |
232 | | - $typesByName[$type] = $text; |
| 239 | + foreach( LogPage::validTypes() as $type ) { |
| 240 | + $page = new LogPage( $type ); |
| 241 | + $restriction = $page->getRestriction(); |
| 242 | + if ( $wgUser->isAllowed( $restriction ) ) { |
| 243 | + $typesByName[$type] = $page->getName()->text(); |
| 244 | + } |
233 | 245 | } |
234 | 246 | |
235 | 247 | // Second pass to sort by name |
236 | 248 | asort($typesByName); |
237 | 249 | |
238 | | - // Note the query type |
239 | | - $queryType = count($queryTypes) == 1 ? $queryTypes[0] : ''; |
240 | | - |
241 | 250 | // Always put "All public logs" on top |
242 | | - if ( isset( $typesByName[''] ) ) { |
243 | | - $all = $typesByName['']; |
244 | | - unset( $typesByName[''] ); |
245 | | - $typesByName = array( '' => $all ) + $typesByName; |
246 | | - } |
| 251 | + $public = $typesByName['']; |
| 252 | + unset( $typesByName[''] ); |
| 253 | + $typesByName = array( '' => $public ) + $typesByName; |
247 | 254 | |
248 | | - // Third pass generates sorted XHTML content |
249 | | - foreach( $typesByName as $type => $text ) { |
250 | | - $selected = ($type == $queryType); |
251 | | - // Restricted types |
252 | | - if ( isset($wgLogRestrictions[$type]) ) { |
253 | | - if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) { |
254 | | - $html .= Xml::option( $text, $type, $selected ) . "\n"; |
255 | | - } |
256 | | - } else { |
257 | | - $html .= Xml::option( $text, $type, $selected ) . "\n"; |
258 | | - } |
| 255 | + $select = new XmlSelect( 'type' ); |
| 256 | + foreach( $typesByName as $type => $name ) { |
| 257 | + $select->addOption( $name, $type ); |
259 | 258 | } |
260 | 259 | |
261 | | - $html .= '</select>'; |
262 | | - return $html; |
| 260 | + return $select; |
263 | 261 | } |
264 | 262 | |
265 | 263 | /** |