r45254 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45253‎ | r45254 | r45255 >
Date:21:15, 31 December 2008
Author:ialex
Status:deferred
Tags:
Comment:
* moved ConfigurationPage::getEditableSettings() and ConfigurationPage::getUneditableSettings() to WebConfiguration
* Only snapshot editable settings in WebConfiguration::snapshotDefaults()
* Fixed error on Special:Extensions when saving settings. CategoryTree's settings using radio buttons had no radio button pre-selected, resulting in an exception (reported by alonswartz on IRC)
Modified paths:
  • /trunk/extensions/Configure/Configure.obj.php (modified) (history)
  • /trunk/extensions/Configure/Configure.page.php (modified) (history)
  • /trunk/extensions/Configure/Configure.settings-core.php (modified) (history)
  • /trunk/extensions/Configure/Configure.settings.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Configure/Configure.page.php
@@ -218,18 +218,7 @@
219219 * @return array
220220 */
221221 protected function getUneditableSettings() {
222 - static $notEditable;
223 - if ( !isset( $notEditable ) ) {
224 - global $wgConfigureNotEditableSettings, $wgConfigureEditableSettings;
225 -
226 - if ( !count($wgConfigureNotEditableSettings) && count($wgConfigureEditableSettings ) ) {
227 - $wgConfigureNotEditableSettings = array_diff( array_keys( $this->mConfSettings->getAllSettings() ), $wgConfigureEditableSettings );
228 - }
229 -
230 - $notEditable = array_merge( $this->mConfSettings->getUneditableSettings(),
231 - $wgConfigureNotEditableSettings );
232 - }
233 - return $notEditable;
 222+ return $this->mConfSettings->getUneditableSettings();
234223 }
235224
236225 /**
@@ -238,11 +227,7 @@
239228 * @return array
240229 */
241230 protected function getEditableSettings() {
242 - $notEdit = $this->getUneditableSettings();
243 - $settings = $this->mConfSettings->getAllSettings();
244 - foreach ( $notEdit as $setting )
245 - unset( $settings[$setting] );
246 - return $settings;
 231+ return $this->mConfSettings->getEditableSettings();
247232 }
248233
249234 /**
@@ -760,15 +745,11 @@
761746 */
762747 protected function removeDefaults( $settings ) {
763748 global $wgConf;
764 - $defaultValues = $wgConf->getDefaultsForWiki( $this->mWiki );
 749+ $defaultValues = $wgConf->getDefaultsForWiki( $this->mWiki );
765750 foreach ( $defaultValues as $name => $default ) {
766751 ## Normalise the two, to avoid false "changes"
767752 if ( is_array( $default ) ) {
768 - try {
769 - $default = WebConfiguration::filterVar( $default );
770 - } catch( Exception $e ) {
771 - throw new MWException( $name );
772 - }
 753+ $default = WebConfiguration::filterVar( $default );
773754 }
774755
775756 if ( isset( $settings[$name] ) ) {
@@ -1005,8 +986,11 @@
1006987 if ( !$allowed )
1007988 return '<code>' . htmlspecialchars( $default ) . '</code>';
1008989 $ret = "\n";
 990+ var_dump( $default );
1009991 foreach ( $type as $val => $name ) {
1010 - $ret .= Xml::radioLabel( $name, 'wp' . $conf, $val, 'wp' . $conf . $val, strval($default) === strval($val) ) . "\n";
 992+ $checked = is_int( $val ) ?
 993+ $val === (int)$default : strval($default) === strval($val);
 994+ $ret .= Xml::radioLabel( $name, 'wp' . $conf, $val, 'wp' . $conf . $val, $checked ) . "\n";
1011995 }
1012996 return $ret;
1013997 }
Index: trunk/extensions/Configure/Configure.settings-core.php
@@ -668,18 +668,18 @@
669669 'wgAutoloadClasses' => 'array',
670670 'wgAvailableRights' => 'array',
671671 'wgDisableInternalSearch' => 'bool',
672 -# 'wgExceptionHooks' => 'array',
 672+ 'wgExceptionHooks' => 'array',
673673 'wgExtensionAliasesFiles' => 'array',
674674 'wgExtensionCredits' => 'array',
675 -# 'wgExtensionFunctions' => 'array',
 675+ 'wgExtensionFunctions' => 'array',
676676 'wgExtensionMessagesFiles' => 'array',
677677 'wgExternalStores' => 'array',
678 -# 'wgHooks' => 'array',
 678+ 'wgHooks' => 'array',
679679 'wgPagePropLinkInvalidations' => 'array',
680 -# 'wgParserOutputHooks' => 'array',
681 -# 'wgSpecialPageCacheUpdates' => 'array',
 680+ 'wgParserOutputHooks' => 'array',
 681+ 'wgSpecialPageCacheUpdates' => 'array',
682682 'wgSpecialPages' => 'array',
683 -# 'wgSkinExtensionFunctions' => 'array',
 683+ 'wgSkinExtensionFunctions' => 'array',
684684 ),
685685 ),
686686 'search' => array(
Index: trunk/extensions/Configure/Configure.settings.php
@@ -177,20 +177,59 @@
178178 * @return array
179179 */
180180 public function getUneditableSettings() {
 181+ if ( isset( $this->cache['uneditable'] ) )
 182+ return $this->cache['uneditable'];
 183+
181184 $this->loadSettingsDefs();
182 - $ret = array();
 185+ $notEditable = array();
183186 if ( ( $this->types & CONF_SETTINGS_CORE ) == CONF_SETTINGS_CORE ) {
184 - $ret += $this->notEditableSettings;
 187+ $notEditable += $this->notEditableSettings;
185188 }
186189 if ( ( $this->types & CONF_SETTINGS_EXT ) == CONF_SETTINGS_EXT ) {
187 - $ret += array(); // Nothing for extensions
 190+ $notEditable += array(); // Nothing for extensions
188191 }
189 - global $wgConf;
190 - $ret = array_merge( $ret, $wgConf->getUneditableSettings() );
191 - return $ret;
 192+
 193+ global $wgConf, $wgConfigureNotEditableSettings, $wgConfigureEditableSettings;
 194+ $notEditable = array_merge( $notEditable, $wgConf->getUneditableSettings() );
 195+
 196+ if ( !count( $wgConfigureNotEditableSettings ) && count( $wgConfigureEditableSettings ) ) {
 197+ $wgConfigureNotEditableSettings = array_diff( array_keys( $this->getAllSettings() ), $wgConfigureEditableSettings );
 198+ }
 199+
 200+ $notEditable = array_merge( $notEditable,
 201+ $wgConfigureNotEditableSettings );
 202+
 203+ return $this->cache['uneditable'] = $notEditable;
192204 }
193205
194206 /**
 207+ * Get a list of editable settings
 208+ *
 209+ * @return array
 210+ */
 211+ public function getEditableSettings() {
 212+ if ( isset( $this->cache['editable'] ) )
 213+ return $this->cache['editable'];
 214+
 215+ $this->cache['editable'] = array();
 216+ $this->loadSettingsDefs();
 217+
 218+ global $wgConfigureEditableSettings;
 219+ if( count( $wgConfigureEditableSettings ) ) {
 220+ foreach( $wgConfigureEditableSettings as $setting ) {
 221+ $this->cache['editable'][$setting] = $this->getSettingType( $setting );
 222+ }
 223+ return $this->cache['editable'];
 224+ }
 225+
 226+ $notEdit = $this->getUneditableSettings();
 227+ $settings = $this->getAllSettings();
 228+ foreach ( $notEdit as $setting )
 229+ unset( $settings[$setting] );
 230+ return $this->cache['editable'] = $settings;
 231+ }
 232+
 233+ /**
195234 * Get the list of all arrays settings, mapping setting name to its type
196235 *
197236 * @return array
Index: trunk/extensions/Configure/Configure.obj.php
@@ -78,14 +78,14 @@
7979 public function snapshotDefaults( /* options */ ) {
8080 $options = func_get_args();
8181 $noOverride = in_array( 'no_override', $options );
82 - if( !is_array($this->mDefaults) || in_array('allow_empty',$options) ) {
 82+ if( !is_array( $this->mDefaults ) || in_array( 'allow_empty', $options ) ) {
8383 if( !is_array( $this->mDefaults ) ) {
8484 $this->mDefaults = array();
8585 }
86 - $allSettings = ConfigurationSettings::singleton( CONF_SETTINGS_BOTH )->getAllSettings();
 86+ $allSettings = ConfigurationSettings::singleton( CONF_SETTINGS_BOTH )->getEditableSettings();
8787 foreach( $allSettings as $setting => $type ) {
88 - if( array_key_exists($setting,$GLOBALS) &&
89 - !( $noOverride && array_key_exists($setting,$this->mDefaults) ) )
 88+ if( array_key_exists( $setting, $GLOBALS ) &&
 89+ !( $noOverride && array_key_exists( $setting, $this->mDefaults ) ) )
9090 {
9191 $this->mDefaults[$setting] = $GLOBALS[$setting];
9292 }

Status & tagging log