Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92928


Change subject: API: Return changed values for action=options
......................................................................

API: Return changed values for action=options

At the moment action=options does not provide a technical way, to see
which of the given changes are applied.
This patch set adds a list of changes to the result. It contains for
each given option a entry about the name, if it valid, changed and the
oldvalue.

Change-Id: Ifc11096b61c3eb95214ca67c72133f576ac84b0e
---
M includes/api/ApiOptions.php
1 file changed, 21 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/28/92928/1

diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php
index 7256066..c43b87c 100644
--- a/includes/api/ApiOptions.php
+++ b/includes/api/ApiOptions.php
@@ -76,12 +76,17 @@
                $prefs = Preferences::getPreferences( $user, 
$this->getContext() );
                $prefsKinds = $user->getOptionKinds( $this->getContext(), 
$changes );
 
+               $changedOptions = array();
                foreach ( $changes as $key => $value ) {
+                       $changedOption = array( 'name' => $key );
                        switch ( $prefsKinds[$key] ) {
                                case 'registered':
                                        // Regular option.
                                        $field = 
HTMLForm::loadInputFromParameters( $key, $prefs[$key] );
                                        $validation = $field->validate( $value, 
$user->getOptions() );
+                                       if ( $validation !== true ) {
+                                               $changedOption['invalidvalue'] 
= $validation;
+                                       }
                                        break;
                                case 'registered-multiselect':
                                case 'registered-checkmatrix':
@@ -98,18 +103,32 @@
                                        } else {
                                                $validation = true;
                                        }
+                                       if ( $validation !== true ) {
+                                               $changedOption['invalidvalue'] 
= $validation;
+                                       }
                                        break;
                                case 'unused':
                                default:
+                                       $changedOption['invalid'] = '';
                                        $validation = "not a valid preference";
                                        break;
                        }
                        if ( $validation === true ) {
+                               $oldValue = $user->getOption( $key );
                                $user->setOption( $key, $value );
+                               // compare is not type safe, because some 
default settings are integer,
+                               // but this will always set a string
+                               if ( $oldValue == $value ) {
+                                       $changedOption['nochange'] = '';
+                               } else {
+                                       $changedOption['oldvalue'] = $oldValue;
+                                       $changedOption['newvalue'] = $value;
+                               }
                                $changed = true;
                        } else {
                                $this->setWarning( "Validation error for 
'$key': $validation" );
                        }
+                       $changedOptions[] = $changedOption;
                }
 
                if ( $changed ) {
@@ -118,6 +137,8 @@
                }
 
                $this->getResult()->addValue( null, $this->getModuleName(), 
'success' );
+               $this->getResult()->setIndexedTagName( $changedOptions, 
'change' );
+               $this->getResult()->addValue( null, 'changes', $changedOptions 
);
        }
 
        public function mustBePosted() {

-- 
To view, visit https://gerrit.wikimedia.org/r/92928
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifc11096b61c3eb95214ca67c72133f576ac84b0e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to