Index: trunk/extensions/Configure/Configure.page.php |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | $this->showForm(); |
110 | 110 | break; |
111 | 111 | case 'diff': |
112 | | - $this->conf = $this->importFromRequest(); |
| 112 | + $this->conf = $this->importFromRequest() + $this->conf; |
113 | 113 | $this->showDiff(); |
114 | 114 | case 'initial': |
115 | 115 | default: |
— | — | @@ -164,6 +164,15 @@ |
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
| 168 | + * Accessor for $this->conf |
| 169 | + * |
| 170 | + * @return array |
| 171 | + */ |
| 172 | + public function getConf() { |
| 173 | + return $this->conf; |
| 174 | + } |
| 175 | + |
| 176 | + /** |
168 | 177 | * Return true if the current user is allowed to configure $setting. |
169 | 178 | * @return bool |
170 | 179 | */ |
Index: trunk/extensions/Configure/CHANGELOG |
— | — | @@ -1,6 +1,9 @@ |
2 | 2 | This file lists changes on this extension. |
3 | 3 | Localisation updates are done on betawiki and aren't listed here. |
4 | 4 | |
| 5 | +0.13.1 - 12 March 2009 |
| 6 | + (bug 17112) Added dependencies checking for extensions. |
| 7 | + |
5 | 8 | 0.13.0 - 11 March 2009 |
6 | 9 | Rewrote extension definitions handling, now using text file. |
7 | 10 | |
Index: trunk/extensions/Configure/Configure.settings-ext.txt |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | settings[] = wgAbuseFilterRestrictedActions: array |
17 | 17 | array[] = wgAbuseFilterAvailableActions: simple |
18 | 18 | array[] = wgAbuseFilterRestrictedActions: simple |
| 19 | +extensions-dependencies[] = AntiSpoof |
19 | 20 | schema = true |
20 | 21 | url = http://www.mediawiki.org/wiki/Extension:AbuseFilter |
21 | 22 | |
— | — | @@ -240,6 +241,7 @@ |
241 | 242 | settings[] = wgAccountRequestExts: array |
242 | 243 | array[] = wgAccountRequestTypes: array, wgConfirmAccountSortkey: simple |
243 | 244 | array[] = wgAccountRequestExts: simple |
| 245 | +settings-dependencies[] = wgEnableEmail: true |
244 | 246 | schema = true |
245 | 247 | url = http://www.mediawiki.org/wiki/Extension:ConfirmAccount |
246 | 248 | |
Index: trunk/extensions/Configure/Configure.settings.php |
— | — | @@ -12,6 +12,8 @@ |
13 | 13 | protected $settings, $arrayDefs, $emptyValues, $editRestricted, |
14 | 14 | $viewRestricted, $notEditableSettings, $settingsVersion; |
15 | 15 | |
| 16 | + protected $extensionsObjects = null; |
| 17 | + |
16 | 18 | // Cache |
17 | 19 | protected $cache = array(); |
18 | 20 | |
— | — | @@ -51,34 +53,54 @@ |
52 | 54 | wfProfileOut( __METHOD__ ); |
53 | 55 | } |
54 | 56 | |
55 | | - /** |
56 | | - * Get an array of WebExtensions objects |
57 | | - * |
58 | | - * @return array |
59 | | - */ |
60 | | - public function getAllExtensionsObjects() { |
61 | | - static $list; |
| 57 | + protected function loadExtensions() { |
| 58 | + if ( is_array( $this->extensionsObjects ) ) |
| 59 | + return; |
62 | 60 | |
63 | | - if( isset( $list ) ) |
64 | | - return $list; |
65 | | - |
66 | 61 | wfProfileIn( __METHOD__ ); |
67 | 62 | |
68 | 63 | global $wgConfigureAdditionalExtensions; |
69 | 64 | $coreExtensions = TxtDef::remapForConfigure( TxtDef::loadFromFile( dirname( __FILE__ ) . '/Configure.settings-ext.txt' ) ); |
70 | 65 | $extensions = array_merge( $coreExtensions, $wgConfigureAdditionalExtensions ); |
71 | 66 | usort( $extensions, array( __CLASS__, 'compExt' ) ); |
| 67 | + $list = array(); |
72 | 68 | foreach( $extensions as $ext ) { |
73 | 69 | $ext = new WebExtension( $ext ); |
74 | 70 | #if( $ext->isInstalled() ) { |
75 | 71 | $list[] = $ext; |
76 | 72 | #} |
77 | 73 | } |
| 74 | + |
| 75 | + $this->extensionsObjects = $list; |
| 76 | + |
78 | 77 | wfProfileOut( __METHOD__ ); |
79 | | - return $list; |
80 | 78 | } |
81 | 79 | |
82 | 80 | /** |
| 81 | + * Get an array of WebExtensions objects |
| 82 | + * |
| 83 | + * @return array |
| 84 | + */ |
| 85 | + public function getAllExtensionsObjects() { |
| 86 | + $this->loadExtensions(); |
| 87 | + |
| 88 | + return $this->extensionsObjects; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Get an extension object by name |
| 93 | + */ |
| 94 | + public function getExtension( $name ) { |
| 95 | + $this->loadExtensions(); |
| 96 | + |
| 97 | + foreach( $this->extensionsObjects as $ext ) |
| 98 | + if ( $ext->getName() == $name ) |
| 99 | + return $ext; |
| 100 | + |
| 101 | + return null; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
83 | 105 | * Callback to sort extensions |
84 | 106 | */ |
85 | 107 | public static function compExt( $e1, $e2 ) { |
Index: trunk/extensions/Configure/Configure.ext.php |
— | — | @@ -14,16 +14,19 @@ |
15 | 15 | protected $mEditRestricted; |
16 | 16 | protected $mName; |
17 | 17 | protected $mDbChange; |
| 18 | + protected $mExtensionsDependencies; |
| 19 | + protected $mSettingsDependencies; |
18 | 20 | protected $mInputCallback = null; |
19 | 21 | protected $mDir; |
20 | 22 | protected $mFile; |
21 | 23 | protected $mDoc; |
22 | 24 | protected $mExtVar = null; |
| 25 | + protected $mObj = null; |
23 | 26 | |
24 | 27 | /** |
25 | 28 | * Construct a new object. |
26 | 29 | * |
27 | | - * @param array $conf |
| 30 | + * @param $conf Array |
28 | 31 | */ |
29 | 32 | public function __construct( /*array*/ $conf ) { |
30 | 33 | global $wgConfigureExtensionsVar; |
— | — | @@ -32,11 +35,13 @@ |
33 | 36 | $this->mSettings = isset( $conf['settings'] ) ? $conf['settings'] : array(); |
34 | 37 | $this->mDbChange = isset( $conf['schema'] ) && $conf['schema']; |
35 | 38 | $this->mDir = isset( $conf['dir'] ) ? $conf['dir'] : $conf['name']; |
36 | | - $this->mFile = isset( $conf['file'] ) ? $conf['file'] : $conf['name'] . '.php' ; |
| 39 | + $this->mFile = isset( $conf['file'] ) ? $conf['file'] : $conf['name'] . '.php'; |
37 | 40 | $this->mArrays = isset( $conf['array'] ) ? $conf['array'] : array(); |
38 | 41 | $this->mEmptyValues = isset( $conf['empty'] ) ? $conf['empty'] : array(); |
39 | 42 | $this->mViewRestricted = isset( $conf['view-restricted'] ) ? $conf['view-restricted'] : array(); |
40 | 43 | $this->mEditRestricted = isset( $conf['edit-restricted'] ) ? $conf['edit-restricted'] : array(); |
| 44 | + $this->mExtensionsDependencies = isset( $conf['extensions-dependencies'] ) ? $conf['extensions-dependencies'] : array(); |
| 45 | + $this->mSettingsDependencies = isset( $conf['settings-dependencies'] ) ? $conf['settings-dependencies'] : array(); |
41 | 46 | $this->mDoc = isset( $conf['url'] ) ? $conf['url'] : null; |
42 | 47 | if ( isset( $wgConfigureExtensionsVar[$this->mName] ) ) { |
43 | 48 | $this->mExtVar = $wgConfigureExtensionsVar[$this->mName]; |
— | — | @@ -116,6 +121,26 @@ |
117 | 122 | } |
118 | 123 | |
119 | 124 | /** |
| 125 | + * Get the list of extensions that needs to be activated so that this |
| 126 | + * extension can work |
| 127 | + * |
| 128 | + * @return array |
| 129 | + */ |
| 130 | + public function getExtensionsDependencies() { |
| 131 | + return $this->mExtensionsDependencies; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Get the associative array mapping settings to their values needed by this |
| 136 | + * extension |
| 137 | + * |
| 138 | + * @return array |
| 139 | + */ |
| 140 | + public function getSettingsDependencies() { |
| 141 | + return $this->mSettingsDependencies; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
120 | 145 | * Get a url for the description of this extension (or null) |
121 | 146 | * |
122 | 147 | * @return string or null |
— | — | @@ -135,18 +160,47 @@ |
136 | 161 | } |
137 | 162 | |
138 | 163 | /** |
| 164 | + * Prettify boolean settings to be correctly displayed |
| 165 | + * |
| 166 | + * @return String |
| 167 | + */ |
| 168 | + public static function prettifyForDisplay( $val ) { |
| 169 | + if ( is_bool( $val ) ) |
| 170 | + return wfBoolToStr( $val ); |
| 171 | + return $val; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
139 | 175 | * Generate html to configure this extension |
140 | 176 | * |
141 | | - * @return XHTML |
| 177 | + * @return String: XHTML |
142 | 178 | */ |
143 | 179 | public function getHtml() { |
144 | 180 | if ( !$this->isInstalled() ) |
145 | 181 | return ''; |
146 | 182 | $ret = '<fieldset><legend>' . htmlspecialchars( $this->mName ) . '</legend>'; |
| 183 | + if ( count( $errors = $this->checkSettingsDependencies() ) ) { |
| 184 | + $ret .= "<span class=\"errorbox\">"; |
| 185 | + $ret .= wfMsgExt( 'configure-ext-settings-dep-errors', array( 'parseinline' ), count( $errors ) ); |
| 186 | + $ret .= "<ul>\n"; |
| 187 | + foreach ( $errors as $err ) { |
| 188 | + list( $setting, $req, $cur ) = $err; |
| 189 | + $setting = '$'.$setting; |
| 190 | + $req = self::prettifyForDisplay( $req ); |
| 191 | + $cur = self::prettifyForDisplay( $cur ); |
| 192 | + $ret .= '<li>' . wfMsgExt( 'configure-ext-settings-dep-error', array( 'parseinline' ), $setting, $req, $cur ) . "</li>\n"; |
| 193 | + } |
| 194 | + return $ret . "</ul>\n</span>\n</fieldset>"; |
| 195 | + } |
147 | 196 | if ( $this->mDbChange ) { |
148 | 197 | $warn = wfMsgExt( 'configure-ext-schemachange', array( 'parseinline' ) ); |
149 | 198 | $ret .= "<span class=\"errorbox\">{$warn}</span><br clear=\"left\" />\n"; |
150 | 199 | } |
| 200 | + if ( count( $this->mExtensionsDependencies ) ) { |
| 201 | + global $wgLang; |
| 202 | + $warn = wfMsgExt( 'configure-ext-ext-dependencies', array( 'parseinline' ), $wgLang->listToText( $this->mExtensionsDependencies ), count( $this->mExtensionsDependencies ) ); |
| 203 | + $ret .= "<span class=\"errorbox\">{$warn}</span><br clear=\"left\" />\n"; |
| 204 | + } |
151 | 205 | $use = wfMsgExt( 'configure-ext-use', array( 'parseinline' ) ); |
152 | 206 | $ret .= "<h2>{$use}</h2>\n"; |
153 | 207 | $ret .= "<table class=\"configure-table configure-table-ext\"><tr><td>\n"; |
— | — | @@ -176,6 +230,39 @@ |
177 | 231 | } |
178 | 232 | |
179 | 233 | /** |
| 234 | + * Check for settings dependencies |
| 235 | + * |
| 236 | + * @return Boolean: Success |
| 237 | + */ |
| 238 | + public function checkSettingsDependencies() { |
| 239 | + if ( !$this->mObj instanceof ConfigurationPage ) |
| 240 | + throw new MWException( 'WebExtension::checkSettingsDependencies() called without prior call to WebExtension::setPageObj()' ); |
| 241 | + |
| 242 | + if ( !count( $this->mSettingsDependencies ) ) |
| 243 | + return array(); |
| 244 | + |
| 245 | + $ret = array(); |
| 246 | + $conf = $this->mObj->getConf(); |
| 247 | + foreach ( $this->mSettingsDependencies as $setting => $value ) { |
| 248 | + if ( $conf[$setting] !== $value ) { |
| 249 | + $ret[] = array( $setting, $value, $conf[$setting] ); |
| 250 | + } |
| 251 | + } |
| 252 | + return $ret; |
| 253 | + } |
| 254 | + |
| 255 | + /** |
| 256 | + * Whether the definition file can be included to get default values |
| 257 | + * |
| 258 | + * @return Boolean |
| 259 | + */ |
| 260 | + public function canIncludeFile() { |
| 261 | + if( !file_exists( $this->getFile() ) ) |
| 262 | + return false; |
| 263 | + return !count( $this->checkSettingsDependencies() ); |
| 264 | + } |
| 265 | + |
| 266 | + /** |
180 | 267 | * Return the name of the check that's used to select whether the extension |
181 | 268 | * should be activated |
182 | 269 | */ |
— | — | @@ -203,7 +290,7 @@ |
204 | 291 | /** |
205 | 292 | * Is this extension activated? |
206 | 293 | * |
207 | | - * @return bool |
| 294 | + * @return Boolean |
208 | 295 | */ |
209 | 296 | public function isActivated() { |
210 | 297 | if( $this->useVariable() ) { |
— | — | @@ -217,7 +304,7 @@ |
218 | 305 | /** |
219 | 306 | * Is this extension installed so that it can be used? |
220 | 307 | * |
221 | | - * @return bool |
| 308 | + * @return Boolean |
222 | 309 | */ |
223 | 310 | public function isInstalled() { |
224 | 311 | if( $this->useVariable() ) { |
Index: trunk/extensions/Configure/Configure.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Configure', |
19 | 19 | 'description' => 'Allow authorised users to configure the wiki via a web-based interface', |
20 | 20 | 'descriptionmsg' => 'configure-desc', |
21 | | - 'version' => '0.13.0', |
| 21 | + 'version' => '0.13.1', |
22 | 22 | ); |
23 | 23 | |
24 | 24 | # Configuration part |
— | — | @@ -88,6 +88,10 @@ |
89 | 89 | * extensions-all right |
90 | 90 | * - edit-restricted: list of settings that only be modified by users with |
91 | 91 | * extensions-all right |
| 92 | + * - extensions-dependencies: list of extensions that must be enabled so that |
| 93 | + * this extension can be enabled too |
| 94 | + * - settings-dependencies: array mapping settings to their values that must be |
| 95 | + * set so that this extension can be enabled |
92 | 96 | * - schema: put it to true if the extension requires a database schema change |
93 | 97 | * - url: url to the documentation page |
94 | 98 | */ |
Index: trunk/extensions/Configure/Configure.i18n.php |
— | — | @@ -20,9 +20,13 @@ |
21 | 21 | 'configure-edit-ext' => 'Extensions', |
22 | 22 | 'configure-viewconfig-default-diff' => 'Changes from default settings', |
23 | 23 | |
| 24 | + 'configure-ext-ext-dependencies' => "'''Warning:''' this extension requires the following {{PLURAL:$2|extension|extensions}} to be activated: $1.", |
| 25 | + 'configure-ext-ext-dependency-err' => "'''Error:''' the $1 extension requires the $2 extension to be activated.", |
24 | 26 | 'configure-ext-doc' => 'See online documentation', |
25 | 27 | 'configure-ext-schemachange' => "'''Warning:''' this extension requires a database update to work correctly!", |
26 | 28 | 'configure-ext-settings' => 'Settings', |
| 29 | + 'configure-ext-settings-dep-errors' => 'This extension cannot be enabled because the following {{PLURAL:$1|setting has|settings have}} an unacceptable value:', |
| 30 | + 'configure-ext-settings-dep-error' => '$1: required value: $2, current value: $3', |
27 | 31 | 'configure-ext-use-extension' => 'Use this extension', |
28 | 32 | 'configure-ext-use' => 'Use', |
29 | 33 | 'configure-form-reason' => 'Reason for change:', |
Index: trunk/extensions/Configure/SpecialExtensions.php |
— | — | @@ -28,6 +28,11 @@ |
29 | 29 | $current = $wgConf->getCurrent( $this->mWiki ); |
30 | 30 | $settings = $this->importFromRequest(); |
31 | 31 | $new = $settings + $current; |
| 32 | + if ( !$this->checkExtensionsDependencies() ) { |
| 33 | + $this->conf = $new; |
| 34 | + $this->showForm(); |
| 35 | + return; |
| 36 | + } |
32 | 37 | $new = $this->removeDefaults( $new ); |
33 | 38 | $new['__includes'] = $this->getRequiredFiles(); |
34 | 39 | $ok = $wgConf->saveNewSettings( $new, $this->mWiki, $reason ); |
— | — | @@ -52,6 +57,31 @@ |
53 | 58 | } |
54 | 59 | |
55 | 60 | /** |
| 61 | + * Check dependencies against other extensions, and print errors if any |
| 62 | + * |
| 63 | + * @return Boolean: success |
| 64 | + */ |
| 65 | + protected function checkExtensionsDependencies() { |
| 66 | + global $wgRequest, $wgOut; |
| 67 | + |
| 68 | + foreach ( $this->mConfSettings->getAllExtensionsObjects() as $ext ) { |
| 69 | + if ( !count( $ext->getExtensionsDependencies() ) || !$wgRequest->getCheck( $ext->getCheckName() ) ) |
| 70 | + continue; |
| 71 | + |
| 72 | + foreach ( $ext->getExtensionsDependencies() as $depName ) { |
| 73 | + $dep = $this->mConfSettings->getExtension( $depName ); |
| 74 | + if ( !is_object( $dep ) ) |
| 75 | + throw new MWException( "Unable to find \"{$depName}\" dependency for \"{$ext->getName()}\" extension" ); |
| 76 | + if ( !$wgRequest->getCheck( $dep->getCheckName() ) ) { |
| 77 | + $wgOut->wrapWikiMsg( '<span class="errorbox">$1</span>', array( 'configure-ext-ext-dependency-err', $ext->getName(), $depName ) ); |
| 78 | + return false; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + return true; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
56 | 86 | * Get an array of files to include at each request |
57 | 87 | * @return array |
58 | 88 | */ |
— | — | @@ -61,7 +91,8 @@ |
62 | 92 | return array(); |
63 | 93 | $arr = array(); |
64 | 94 | foreach ( $this->mConfSettings->getAllExtensionsObjects() as $ext ) { |
65 | | - if( !$ext->isInstalled() ) continue; // must exist |
| 95 | + if( !$ext->isInstalled() ) |
| 96 | + continue; // must exist |
66 | 97 | if ( $ext->useVariable() ) |
67 | 98 | continue; |
68 | 99 | if ( $wgRequest->getCheck( $ext->getCheckName() ) ) |
— | — | @@ -93,10 +124,12 @@ |
94 | 125 | $ret = ''; |
95 | 126 | $globalDone = false; |
96 | 127 | foreach ( $this->mConfSettings->getAllExtensionsObjects() as $ext ) { |
97 | | - if( !$ext->isInstalled() ) continue; // must exist |
| 128 | + if( !$ext->isInstalled() ) |
| 129 | + continue; // must exist |
| 130 | + $ext->setPageObj( $this ); |
98 | 131 | $settings = $ext->getSettings(); |
99 | 132 | foreach ( $settings as $setting => $type ) { |
100 | | - if ( !isset( $this->conf[$setting] ) && file_exists( $ext->getFile() ) ) { |
| 133 | + if ( !isset( $this->conf[$setting] ) && $ext->canIncludeFile() ) { |
101 | 134 | if ( !$globalDone ) { |
102 | 135 | extract( $GLOBALS, EXTR_REFS ); |
103 | 136 | global $wgHooks; |
— | — | @@ -109,7 +142,6 @@ |
110 | 143 | $this->conf[$setting] = $$setting; |
111 | 144 | } |
112 | 145 | } |
113 | | - $ext->setPageObj( $this ); |
114 | 146 | $ret .= $ext->getHtml(); |
115 | 147 | } |
116 | 148 | if ( $globalDone ) |