Index: trunk/extensions/Configure/Configure.obj.php |
— | — | @@ -96,6 +96,18 @@ |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
| 100 | + * Get the array representing the current configuration |
| 101 | + * |
| 102 | + * @param $wiki String: wiki name |
| 103 | + * @return array |
| 104 | + */ |
| 105 | + public function getCurrent( $wiki ){ |
| 106 | + list( $site, $lang ) = $this->siteFromDB( $wiki ); |
| 107 | + $rewrites = array( 'wiki' => $wiki, 'site' => $site, 'lang' => $lang ); |
| 108 | + return $this->getAll( $wiki, $site, $rewrites ); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
100 | 112 | * Get the current file name |
101 | 113 | * @return String full path to the file |
102 | 114 | */ |
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.4.1 - 9 June 2008 |
| 6 | + It's now possible to preview changes in Special:Configure. |
| 7 | + |
5 | 8 | 0.4.0 - 8 June 2008 |
6 | 9 | Added a difference engine to see differences between versions in |
7 | 10 | Special:ViewConfig. |
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 by a web-based interface', |
20 | 20 | 'descriptionmsg' => 'configure-desc', |
21 | | - 'version' => '0.4.0', |
| 21 | + 'version' => '0.4.1', |
22 | 22 | ); |
23 | 23 | |
24 | 24 | ## Adding new rights... |
— | — | @@ -55,6 +55,7 @@ |
56 | 56 | $wgSpecialPages['ViewConfig'] = 'SpecialViewConfig'; |
57 | 57 | |
58 | 58 | $wgAutoloadClasses['ConfigurationDiff'] = $dir . 'Configure.diff.php'; |
| 59 | +$wgAutoloadClasses['PreviewConfigurationDiff'] = $dir . 'Configure.diff.php'; |
59 | 60 | |
60 | 61 | ## Adding the ajax function |
61 | 62 | $wgAjaxExportList[] = 'efConfigureAjax'; |
Index: trunk/extensions/Configure/SpecialConfigure.php |
— | — | @@ -175,6 +175,16 @@ |
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
| 179 | + $wikiParam = $wgRequest->wasPosted() ? 'wpWiki' : 'wiki'; |
| 180 | + if( $wiki = $wgRequest->getVal( $wikiParam, false ) ){ |
| 181 | + if( !$this->isUserAllowedAll() ){ |
| 182 | + $msg = wfMsgNoTrans( 'configure-no-transwiki' ); |
| 183 | + $wgOut->addWikiText( "<div class='errorbox'><strong>$msg</strong></div>" ); |
| 184 | + return; |
| 185 | + } |
| 186 | + } |
| 187 | + $this->mWiki = $wiki; |
| 188 | + |
179 | 189 | $this->outputHeader(); |
180 | 190 | |
181 | 191 | if( $version = $wgRequest->getVal( 'version' ) ){ |
— | — | @@ -191,12 +201,31 @@ |
192 | 202 | } |
193 | 203 | |
194 | 204 | if( $wgRequest->wasPosted() ){ |
195 | | - if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) |
196 | | - $this->doSubmit(); |
197 | | - else |
| 205 | + if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ){ |
| 206 | + if( $wgRequest->getCheck( 'wpSave' ) ){ |
| 207 | + $type = 'submit'; |
| 208 | + } else { |
| 209 | + $type = 'diff'; |
| 210 | + } |
| 211 | + } else { |
198 | 212 | $wgOut->addWikiText( wfMsgNoTrans( 'sessionfailure' ) ); |
| 213 | + $type = 'diff'; |
| 214 | + } |
199 | 215 | } else { |
| 216 | + $type = 'initial'; |
| 217 | + } |
| 218 | + |
| 219 | + switch( $type ){ |
| 220 | + case 'submit': |
| 221 | + $this->doSubmit(); |
| 222 | + break; |
| 223 | + case 'diff': |
| 224 | + $this->conf = $this->importFromRequest(); |
| 225 | + $this->showDiff(); |
| 226 | + case 'initial': |
| 227 | + default: |
200 | 228 | $this->showForm(); |
| 229 | + break; |
201 | 230 | } |
202 | 231 | } |
203 | 232 | |
— | — | @@ -248,15 +277,28 @@ |
249 | 278 | * Submit the posted request |
250 | 279 | */ |
251 | 280 | protected function doSubmit(){ |
252 | | - global $wgConf, $wgOut, $wgRequest; |
| 281 | + global $wgConf, $wgOut; |
253 | 282 | |
254 | | - if( $wiki = $wgRequest->getVal( 'wpWiki', false ) ){ |
255 | | - if( !$this->isUserAllowedAll() ){ |
256 | | - $msg = wfMsgNoTrans( 'configure-no-transwiki' ); |
257 | | - $wgOut->addWikiText( "<div class='errorbox'><strong>$msg</strong></div>" ); |
258 | | - return; |
259 | | - } |
260 | | - } |
| 283 | + $settings = $this->importFromRequest(); |
| 284 | + $settings['wgCacheEpoch'] = max( $settings['wgCacheEpoch'], wfTimestampNow() ); |
| 285 | + $ok = $wgConf->saveNewSettings( $settings, $this->mWiki ); |
| 286 | + $msg = wfMsgNoTrans( $ok ? 'configure-saved' : 'configure-error' ); |
| 287 | + $class = $ok ? 'successbox' : 'errorbox'; |
| 288 | + |
| 289 | + $wgOut->addWikiText( "<div class=\"$class\"><strong>$msg</strong></div>" ); |
| 290 | + } |
| 291 | + |
| 292 | + /** |
| 293 | + * Import settings from posted datas |
| 294 | + * |
| 295 | + * @return array |
| 296 | + */ |
| 297 | + protected function importFromRequest(){ |
| 298 | + global $wgRequest; |
| 299 | + |
| 300 | + if( !$wgRequest->wasPosted() ) |
| 301 | + return array(); |
| 302 | + |
261 | 303 | $settings = array(); |
262 | 304 | foreach( self::getEditableSettings() as $name => $type ){ |
263 | 305 | if( !$this->userCanEdit( $name ) ){ |
— | — | @@ -404,6 +446,7 @@ |
405 | 447 | $perm = implode( ', ', $type ); |
406 | 448 | throw new MWException( "Value for \$$name setting is not in permitted (given: $val, permitted: $perm)" ); |
407 | 449 | } |
| 450 | + $settings[$name] = $val; |
408 | 451 | } else { |
409 | 452 | throw new MWException( "Unknown setting type $type (setting name: \$$name)" ); |
410 | 453 | } |
— | — | @@ -415,13 +458,7 @@ |
416 | 459 | unset( $settings[$name] ); |
417 | 460 | } |
418 | 461 | } |
419 | | - |
420 | | - $settings['wgCacheEpoch'] = max( $settings['wgCacheEpoch'], wfTimestampNow() ); |
421 | | - $ok = $wgConf->saveNewSettings( $settings, $wiki ); |
422 | | - $msg = wfMsgNoTrans( $ok ? 'configure-saved' : 'configure-error' ); |
423 | | - $class = $ok ? 'successbox' : 'errorbox'; |
424 | | - |
425 | | - $wgOut->addWikiText( "<div class=\"$class\"><strong>$msg</strong></div>" ); |
| 462 | + return $settings; |
426 | 463 | } |
427 | 464 | |
428 | 465 | /** |
— | — | @@ -448,16 +485,8 @@ |
449 | 486 | * Show the main form |
450 | 487 | */ |
451 | 488 | protected function showForm(){ |
452 | | - global $wgOut, $wgUser, $wgRequest; |
| 489 | + global $wgOut, $wgUser; |
453 | 490 | |
454 | | - if( $wiki = $wgRequest->getVal( 'wiki', false ) ){ |
455 | | - if( !$this->isUserAllowedAll() ){ |
456 | | - $msg = wfMsgNoTrans( 'configure-no-transwiki' ); |
457 | | - $wgOut->addWikiText( "<div class='errorbox'><strong>$msg</strong></div>" ); |
458 | | - return; |
459 | | - } |
460 | | - } |
461 | | - |
462 | 491 | $action = $this->getTitle()->escapeLocalURL(); |
463 | 492 | # We use <div id="preferences"> to have the tabs like in Special:Preferences |
464 | 493 | $wgOut->addHtml( |
— | — | @@ -471,10 +500,11 @@ |
472 | 501 | Xml::openElement( 'div', array( 'id' => 'prefsubmit' ) ) . "\n" . |
473 | 502 | Xml::openElement( 'div', array() ) . "\n" . |
474 | 503 | Xml::element( 'input', array( 'type' => 'submit', 'name' => 'wpSave', 'class' => 'btnSavePrefs', 'value' => wfMsgHtml( 'configure-btn-save' ) ) ) . "\n" . |
| 504 | + Xml::element( 'input', array( 'type' => 'submit', 'name' => 'wpPreview', 'value' => wfMsgHtml( 'showdiff' ) ) ) . "\n" . |
475 | 505 | Xml::closeElement( 'div' ) . "\n" . |
476 | 506 | Xml::closeElement( 'div' ) . "\n" . |
477 | 507 | Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpEditToken', 'value' => $wgUser->editToken() ) ) . "\n" . |
478 | | - ( $wiki ? Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpWiki', 'value' => $wiki ) ) . "\n" : '' ) . |
| 508 | + ( $this->mWiki ? Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpWiki', 'value' => $this->mWiki ) ) . "\n" : '' ) . |
479 | 509 | Xml::closeElement( 'div' ) . "\n" . |
480 | 510 | Xml::closeElement( 'form' ) |
481 | 511 | ); |
— | — | @@ -482,6 +512,30 @@ |
483 | 513 | } |
484 | 514 | |
485 | 515 | /** |
| 516 | + * Helper function for the diff engine |
| 517 | + * @param $setting setting name |
| 518 | + */ |
| 519 | + public function isSettingEditable( $setting ){ |
| 520 | + return ( self::isSettingAvailable( $setting ) |
| 521 | + && $this->userCanEdit( $setting ) |
| 522 | + && ( self::getSettingType( $setting ) != 'array' |
| 523 | + || !in_array( self::getArrayType( $setting ), array( 'array', null ) ) ) ); |
| 524 | + } |
| 525 | + |
| 526 | + /** |
| 527 | + * Show the diff between the current version and the posted version |
| 528 | + */ |
| 529 | + protected function showDiff(){ |
| 530 | + global $wgConf, $wgOut; |
| 531 | + $wiki = $this->mWiki ? $this->mWiki : $wgConf->getWiki(); |
| 532 | + $old = array( $wiki => $wgConf->getCurrent( $wiki ) ); |
| 533 | + $new = array( $wiki => $this->conf ); |
| 534 | + $diff = new PreviewConfigurationDiff( $old, $new, array( $wiki ) ); |
| 535 | + $diff->setViewCallback( array( $this, 'isSettingEditable' ) ); |
| 536 | + $wgOut->addHtml( $diff->getHtml() ); |
| 537 | + } |
| 538 | + |
| 539 | + /** |
486 | 540 | * Build links to old version of the configuration |
487 | 541 | */ |
488 | 542 | protected function buildOldVersionSelect(){ |
Index: trunk/extensions/Configure/Configure.diff.php |
— | — | @@ -249,3 +249,20 @@ |
250 | 250 | return $val; |
251 | 251 | } |
252 | 252 | } |
| 253 | + |
| 254 | +class PreviewConfigurationDiff extends ConfigurationDiff { |
| 255 | + |
| 256 | + public function __construct( $old, $new, $wikis ){ |
| 257 | + $this->old = $old; |
| 258 | + $this->new = $new; |
| 259 | + $this->wikis = $wikis; |
| 260 | + } |
| 261 | + |
| 262 | + protected function getOldVersion(){ |
| 263 | + return $this->old; |
| 264 | + } |
| 265 | + |
| 266 | + protected function getNewVersion(){ |
| 267 | + return $this->new; |
| 268 | + } |
| 269 | +} |
\ No newline at end of file |