r36099 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36098‎ | r36099 | r36100 >
Date:19:27, 9 June 2008
Author:ialex
Status:old
Tags:
Comment:
It's now possible to preview changes in Special:Configure.
Modified paths:
  • /trunk/extensions/Configure/CHANGELOG (modified) (history)
  • /trunk/extensions/Configure/Configure.diff.php (modified) (history)
  • /trunk/extensions/Configure/Configure.obj.php (modified) (history)
  • /trunk/extensions/Configure/Configure.php (modified) (history)
  • /trunk/extensions/Configure/SpecialConfigure.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Configure/Configure.obj.php
@@ -96,6 +96,18 @@
9797 }
9898
9999 /**
 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+ /**
100112 * Get the current file name
101113 * @return String full path to the file
102114 */
Index: trunk/extensions/Configure/CHANGELOG
@@ -1,6 +1,9 @@
22 This file lists changes on this extension.
33 Localisation updates are done on betawiki and aren't listed here.
44
 5+0.4.1 - 9 June 2008
 6+ It's now possible to preview changes in Special:Configure.
 7+
58 0.4.0 - 8 June 2008
69 Added a difference engine to see differences between versions in
710 Special:ViewConfig.
Index: trunk/extensions/Configure/Configure.php
@@ -17,7 +17,7 @@
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:Configure',
1919 'description' => 'Allow authorised users to configure the wiki by a web-based interface',
2020 'descriptionmsg' => 'configure-desc',
21 - 'version' => '0.4.0',
 21+ 'version' => '0.4.1',
2222 );
2323
2424 ## Adding new rights...
@@ -55,6 +55,7 @@
5656 $wgSpecialPages['ViewConfig'] = 'SpecialViewConfig';
5757
5858 $wgAutoloadClasses['ConfigurationDiff'] = $dir . 'Configure.diff.php';
 59+$wgAutoloadClasses['PreviewConfigurationDiff'] = $dir . 'Configure.diff.php';
5960
6061 ## Adding the ajax function
6162 $wgAjaxExportList[] = 'efConfigureAjax';
Index: trunk/extensions/Configure/SpecialConfigure.php
@@ -175,6 +175,16 @@
176176 return;
177177 }
178178
 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+
179189 $this->outputHeader();
180190
181191 if( $version = $wgRequest->getVal( 'version' ) ){
@@ -191,12 +201,31 @@
192202 }
193203
194204 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 {
198212 $wgOut->addWikiText( wfMsgNoTrans( 'sessionfailure' ) );
 213+ $type = 'diff';
 214+ }
199215 } 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:
200228 $this->showForm();
 229+ break;
201230 }
202231 }
203232
@@ -248,15 +277,28 @@
249278 * Submit the posted request
250279 */
251280 protected function doSubmit(){
252 - global $wgConf, $wgOut, $wgRequest;
 281+ global $wgConf, $wgOut;
253282
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+
261303 $settings = array();
262304 foreach( self::getEditableSettings() as $name => $type ){
263305 if( !$this->userCanEdit( $name ) ){
@@ -404,6 +446,7 @@
405447 $perm = implode( ', ', $type );
406448 throw new MWException( "Value for \$$name setting is not in permitted (given: $val, permitted: $perm)" );
407449 }
 450+ $settings[$name] = $val;
408451 } else {
409452 throw new MWException( "Unknown setting type $type (setting name: \$$name)" );
410453 }
@@ -415,13 +458,7 @@
416459 unset( $settings[$name] );
417460 }
418461 }
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;
426463 }
427464
428465 /**
@@ -448,16 +485,8 @@
449486 * Show the main form
450487 */
451488 protected function showForm(){
452 - global $wgOut, $wgUser, $wgRequest;
 489+ global $wgOut, $wgUser;
453490
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 -
462491 $action = $this->getTitle()->escapeLocalURL();
463492 # We use <div id="preferences"> to have the tabs like in Special:Preferences
464493 $wgOut->addHtml(
@@ -471,10 +500,11 @@
472501 Xml::openElement( 'div', array( 'id' => 'prefsubmit' ) ) . "\n" .
473502 Xml::openElement( 'div', array() ) . "\n" .
474503 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" .
475505 Xml::closeElement( 'div' ) . "\n" .
476506 Xml::closeElement( 'div' ) . "\n" .
477507 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" : '' ) .
479509 Xml::closeElement( 'div' ) . "\n" .
480510 Xml::closeElement( 'form' )
481511 );
@@ -482,6 +512,30 @@
483513 }
484514
485515 /**
 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+ /**
486540 * Build links to old version of the configuration
487541 */
488542 protected function buildOldVersionSelect(){
Index: trunk/extensions/Configure/Configure.diff.php
@@ -249,3 +249,20 @@
250250 return $val;
251251 }
252252 }
 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

Status & tagging log