r39577 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39576‎ | r39577 | r39578 >
Date:09:26, 18 August 2008
Author:werdna
Status:old
Tags:
Comment:
Allowed array-merging for site config. You can now set a setting for '+whatever', and it's the same as setting it for 'whatever', merged with the contents of the next level up. Should mean we're able to deprecate the ugly groupOverrides/groupOverrides2 syntax in InitialiseSettings.php.
Modified paths:
  • /trunk/phase3/includes/SiteConfiguration.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SiteConfiguration.php
@@ -22,27 +22,64 @@
2323 var $settings = array();
2424 var $localVHosts = array();
2525
26 - /** */
 26+ /**
 27+ * Retrieves a configuration setting for a given wiki.
 28+ * @param $settingName String ID of the setting name to retrieve
 29+ * @param $wiki String Wiki ID of the wiki in question.
 30+ * @param $suffix String The suffix of the wiki in question.
 31+ * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
 32+ * @param $wikiTags Array The tags assigned to the wiki.
 33+ * @return Mixed the value of the setting requested.
 34+ */
2735 function get( $settingName, $wiki, $suffix, $params = array(), $wikiTags = array() ) {
2836 if ( array_key_exists( $settingName, $this->settings ) ) {
2937 $thisSetting =& $this->settings[$settingName];
3038 do {
 39+ // Do individual wiki settings
3140 if ( array_key_exists( $wiki, $thisSetting ) ) {
3241 $retval = $thisSetting[$wiki];
3342 break;
 43+ } elseif ( array_key_exists( "+$wiki", $thisSetting ) && is_array($thisSetting["+$wiki"]) ) {
 44+ $retval = $thisSetting["+$wiki"];
3445 }
 46+
 47+ // Do tag settings
3548 foreach ( $wikiTags as $tag ) {
3649 if ( array_key_exists( $tag, $thisSetting ) ) {
37 - $retval = $thisSetting[$tag];
 50+ if ( is_array($retval) && is_array($thisSetting[$tag]) ) {
 51+ $retval = array_merge( $retval, $thisSetting[$tag] );
 52+ } else {
 53+ $retval = $thisSetting[$tag];
 54+ }
3855 break 2;
 56+ } elseif ( array_key_exists( "+$tag", $thisSetting ) && is_array($thisSetting["+$tag"]) ) {
 57+ if (!isset($retval))
 58+ $retval = array();
 59+ $retval = array_merge( $retval, $thisSetting["+$tag"] );
3960 }
4061 }
 62+
 63+ // Do suffix settings
4164 if ( array_key_exists( $suffix, $thisSetting ) ) {
42 - $retval = $thisSetting[$suffix];
 65+ if ( is_array($retval) && is_array($thisSetting[$suffix]) ) {
 66+ $retval = array_merge( $retval, $thisSetting[$suffix] );
 67+ } else {
 68+ $retval = $thisSetting[$suffix];
 69+ }
4370 break;
 71+ } elseif ( array_key_exists( "+$suffix", $thisSetting ) && is_array($thisSetting["+$suffix"]) ) {
 72+ if (!isset($retval))
 73+ $retval = array();
 74+ $retval = array_merge( $retval, $thisSetting["+$suffix"] );
4475 }
 76+
 77+ // Fall back to default.
4578 if ( array_key_exists( 'default', $thisSetting ) ) {
46 - $retval = $thisSetting['default'];
 79+ if ( is_array($retval) && is_array($thisSetting['default']) ) {
 80+ $retval = array_merge( $retval, $thisSetting['default'] );
 81+ } else {
 82+ $retval = $thisSetting['default'];
 83+ }
4784 break;
4885 }
4986 $retval = null;
@@ -73,7 +110,14 @@
74111 }
75112 }
76113
77 - /** */
 114+ /**
 115+ * Gets all settings for a wiki
 116+ * @param $wiki String Wiki ID of the wiki in question.
 117+ * @param $suffix String The suffix of the wiki in question.
 118+ * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
 119+ * @param $wikiTags Array The tags assigned to the wiki.
 120+ * @return Array Array of settings requested.
 121+ */
78122 function getAll( $wiki, $suffix, $params, $wikiTags = array() ) {
79123 $localSettings = array();
80124 foreach ( $this->settings as $varname => $stuff ) {
@@ -85,21 +129,37 @@
86130 return $localSettings;
87131 }
88132
89 - /** */
 133+ /**
 134+ * Retrieves a configuration setting for a given wiki, forced to a boolean.
 135+ * @param $settingName String ID of the setting name to retrieve
 136+ * @param $wiki String Wiki ID of the wiki in question.
 137+ * @param $suffix String The suffix of the wiki in question.
 138+ * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
 139+ * @param $wikiTags Array The tags assigned to the wiki.
 140+ * @return bool The value of the setting requested.
 141+ */
90142 function getBool( $setting, $wiki, $suffix, $wikiTags = array() ) {
91143 return (bool)($this->get( $setting, $wiki, $suffix, array(), $wikiTags ) );
92144 }
93145
94 - /** */
 146+ /** Retrieves an array of local databases */
95147 function &getLocalDatabases() {
96148 return $this->wikis;
97149 }
98150
99 - /** */
 151+ /** A no-op */
100152 function initialise() {
101153 }
102154
103 - /** */
 155+ /**
 156+ * Retrieves the value of a given setting, and places it in a variable passed by reference.
 157+ * @param $settingName String ID of the setting name to retrieve
 158+ * @param $wiki String Wiki ID of the wiki in question.
 159+ * @param $suffix String The suffix of the wiki in question.
 160+ * @param $var Reference The variable to insert the value into.
 161+ * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
 162+ * @param $wikiTags Array The tags assigned to the wiki.
 163+ */
104164 function extractVar( $setting, $wiki, $suffix, &$var, $params, $wikiTags = array() ) {
105165 $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
106166 if ( !is_null( $value ) ) {
@@ -107,7 +167,14 @@
108168 }
109169 }
110170
111 - /** */
 171+ /**
 172+ * Retrieves the value of a given setting, and places it in its corresponding global variable.
 173+ * @param $settingName String ID of the setting name to retrieve
 174+ * @param $wiki String Wiki ID of the wiki in question.
 175+ * @param $suffix String The suffix of the wiki in question.
 176+ * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
 177+ * @param $wikiTags Array The tags assigned to the wiki.
 178+ */
112179 function extractGlobal( $setting, $wiki, $suffix, $params, $wikiTags = array() ) {
113180 $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
114181 if ( !is_null( $value ) ) {
@@ -115,7 +182,13 @@
116183 }
117184 }
118185
119 - /** */
 186+ /**
 187+ * Retrieves the values of all settings, and places them in their corresponding global variables.
 188+ * @param $wiki String Wiki ID of the wiki in question.
 189+ * @param $suffix String The suffix of the wiki in question.
 190+ * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
 191+ * @param $wikiTags Array The tags assigned to the wiki.
 192+ */
120193 function extractAllGlobals( $wiki, $suffix, $params, $wikiTags = array() ) {
121194 foreach ( $this->settings as $varName => $setting ) {
122195 $this->extractGlobal( $varName, $wiki, $suffix, $params, $wikiTags );
@@ -144,7 +217,7 @@
145218 return array( $site, $lang );
146219 }
147220
148 - /** */
 221+ /** Returns true if the given vhost is handled locally. */
149222 function isLocalVHost( $vhost ) {
150223 return in_array( $vhost, $this->localVHosts );
151224 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r39669Commit currently badly-working copy of ConfigureWMF extension....vasilievvv22:28, 19 August 2008

Status & tagging log