From: jenkins-bot Date: Tue, 4 Feb 2014 18:43:40 +0000 (+0000) Subject: Merge "API: Handle "special" options in action=options" X-Git-Tag: 1.31.0-rc.0~17029 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=11cb289cfc45fd40056bccae208934b11c98c10e;hp=da8e6bf5833671ba3dfa577c2fd7eff1638248f8;p=lhc%2Fweb%2Fwiklou.git Merge "API: Handle "special" options in action=options" --- diff --git a/includes/Preferences.php b/includes/Preferences.php index 44520e88d5..ba1aae8a6e 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -62,6 +62,13 @@ class Preferences { 'emailaddress', ); + /** + * @return array + */ + static function getSaveBlacklist() { + return self::$saveBlacklist; + } + /** * @throws MWException * @param $user User diff --git a/includes/User.php b/includes/User.php index ca3f79b5de..a762cd0c07 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2450,6 +2450,8 @@ class User { * - 'registered-checkmatrix' - as above, using the 'checkmatrix' type. * - 'userjs' - preferences with names starting with 'userjs-', intended to * be used by user scripts. + * - 'special' - "preferences" that are not accessible via User::getOptions + * or User::setOptions. * - 'unused' - preferences about which MediaWiki doesn't know anything. * These are usually legacy options, removed in newer versions. * @@ -2466,6 +2468,7 @@ class User { 'registered-multiselect', 'registered-checkmatrix', 'userjs', + 'special', 'unused' ); } @@ -2490,6 +2493,13 @@ class User { $prefs = Preferences::getPreferences( $this, $context ); $mapping = array(); + // Pull out the "special" options, so they don't get converted as + // multiselect or checkmatrix. + $specialOptions = array_fill_keys( Preferences::getSaveBlacklist(), true ); + foreach ( $specialOptions as $name => $value ) { + unset( $prefs[$name] ); + } + // Multiselect and checkmatrix options are stored in the database with // one key per option, each having a boolean value. Extract those keys. $multiselectOptions = array(); @@ -2532,6 +2542,8 @@ class User { $mapping[$key] = 'registered-multiselect'; } elseif ( isset( $checkmatrixOptions[$key] ) ) { $mapping[$key] = 'registered-checkmatrix'; + } elseif ( isset( $specialOptions[$key] ) ) { + $mapping[$key] = 'special'; } elseif ( substr( $key, 0, 7 ) === 'userjs-' ) { $mapping[$key] = 'userjs'; } else { diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index 929b0b6544..fb441a34f2 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -98,6 +98,9 @@ class ApiOptions extends ApiBase { $validation = true; } break; + case 'special': + $validation = "cannot be set by this module"; + break; case 'unused': default: $validation = "not a valid preference"; diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php index 6659414cb5..15bd8bb412 100644 --- a/tests/phpunit/includes/api/ApiOptionsTest.php +++ b/tests/phpunit/includes/api/ApiOptionsTest.php @@ -116,6 +116,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { 'testmultiselect-opt2' => 'registered-multiselect', 'testmultiselect-opt3' => 'registered-multiselect', 'testmultiselect-opt4' => 'registered-multiselect', + 'special' => 'special', ); if ( $options === null ) { @@ -389,6 +390,29 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $this->assertEquals( self::$Success, $response ); } + public function testSpecialOption() { + $this->mUserMock->expects( $this->never() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->never() ) + ->method( 'saveSettings' ); + + $request = $this->getSampleRequest( array( + 'change' => 'special=1' + ) ); + + $response = $this->executeQuery( $request ); + + $this->assertEquals( array( + 'options' => 'success', + 'warnings' => array( + 'options' => array( + '*' => "Validation error for 'special': cannot be set by this module" + ) + ) + ), $response ); + } + public function testUnknownOption() { $this->mUserMock->expects( $this->never() ) ->method( 'resetOptions' );