Index: trunk/phase3/includes/SiteConfiguration.php |
— | — | @@ -22,27 +22,64 @@ |
23 | 23 | var $settings = array(); |
24 | 24 | var $localVHosts = array(); |
25 | 25 | |
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 | + */ |
27 | 35 | function get( $settingName, $wiki, $suffix, $params = array(), $wikiTags = array() ) { |
28 | 36 | if ( array_key_exists( $settingName, $this->settings ) ) { |
29 | 37 | $thisSetting =& $this->settings[$settingName]; |
30 | 38 | do { |
| 39 | + // Do individual wiki settings |
31 | 40 | if ( array_key_exists( $wiki, $thisSetting ) ) { |
32 | 41 | $retval = $thisSetting[$wiki]; |
33 | 42 | break; |
| 43 | + } elseif ( array_key_exists( "+$wiki", $thisSetting ) && is_array($thisSetting["+$wiki"]) ) { |
| 44 | + $retval = $thisSetting["+$wiki"]; |
34 | 45 | } |
| 46 | + |
| 47 | + // Do tag settings |
35 | 48 | foreach ( $wikiTags as $tag ) { |
36 | 49 | 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 | + } |
38 | 55 | 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"] ); |
39 | 60 | } |
40 | 61 | } |
| 62 | + |
| 63 | + // Do suffix settings |
41 | 64 | 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 | + } |
43 | 70 | 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"] ); |
44 | 75 | } |
| 76 | + |
| 77 | + // Fall back to default. |
45 | 78 | 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 | + } |
47 | 84 | break; |
48 | 85 | } |
49 | 86 | $retval = null; |
— | — | @@ -73,7 +110,14 @@ |
74 | 111 | } |
75 | 112 | } |
76 | 113 | |
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 | + */ |
78 | 122 | function getAll( $wiki, $suffix, $params, $wikiTags = array() ) { |
79 | 123 | $localSettings = array(); |
80 | 124 | foreach ( $this->settings as $varname => $stuff ) { |
— | — | @@ -85,21 +129,37 @@ |
86 | 130 | return $localSettings; |
87 | 131 | } |
88 | 132 | |
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 | + */ |
90 | 142 | function getBool( $setting, $wiki, $suffix, $wikiTags = array() ) { |
91 | 143 | return (bool)($this->get( $setting, $wiki, $suffix, array(), $wikiTags ) ); |
92 | 144 | } |
93 | 145 | |
94 | | - /** */ |
| 146 | + /** Retrieves an array of local databases */ |
95 | 147 | function &getLocalDatabases() { |
96 | 148 | return $this->wikis; |
97 | 149 | } |
98 | 150 | |
99 | | - /** */ |
| 151 | + /** A no-op */ |
100 | 152 | function initialise() { |
101 | 153 | } |
102 | 154 | |
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 | + */ |
104 | 164 | function extractVar( $setting, $wiki, $suffix, &$var, $params, $wikiTags = array() ) { |
105 | 165 | $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags ); |
106 | 166 | if ( !is_null( $value ) ) { |
— | — | @@ -107,7 +167,14 @@ |
108 | 168 | } |
109 | 169 | } |
110 | 170 | |
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 | + */ |
112 | 179 | function extractGlobal( $setting, $wiki, $suffix, $params, $wikiTags = array() ) { |
113 | 180 | $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags ); |
114 | 181 | if ( !is_null( $value ) ) { |
— | — | @@ -115,7 +182,13 @@ |
116 | 183 | } |
117 | 184 | } |
118 | 185 | |
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 | + */ |
120 | 193 | function extractAllGlobals( $wiki, $suffix, $params, $wikiTags = array() ) { |
121 | 194 | foreach ( $this->settings as $varName => $setting ) { |
122 | 195 | $this->extractGlobal( $varName, $wiki, $suffix, $params, $wikiTags ); |
— | — | @@ -144,7 +217,7 @@ |
145 | 218 | return array( $site, $lang ); |
146 | 219 | } |
147 | 220 | |
148 | | - /** */ |
| 221 | + /** Returns true if the given vhost is handled locally. */ |
149 | 222 | function isLocalVHost( $vhost ) { |
150 | 223 | return in_array( $vhost, $this->localVHosts ); |
151 | 224 | } |