r96544 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96543‎ | r96544 | r96545 >
Date:08:51, 8 September 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Split getTypeMenu into two functions:
* 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
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogEventsList.php
@@ -218,47 +218,45 @@
219219 * @return String: Formatted HTML
220220 */
221221 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+ }
223227
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;
225236
226 - $validTypes = LogPage::validTypes();
227237 $typesByName = array(); // Temporary array
228 -
229238 // 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+ }
233245 }
234246
235247 // Second pass to sort by name
236248 asort($typesByName);
237249
238 - // Note the query type
239 - $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
240 -
241250 // 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;
247254
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 );
259258 }
260259
261 - $html .= '</select>';
262 - return $html;
 260+ return $select;
263261 }
264262
265263 /**

Status & tagging log