Adrian Lang has uploaded a new change for review.

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

Change subject: Move wbparsevalue and wbformatvalue calls to RepoApi
......................................................................

Move wbparsevalue and wbformatvalue calls to RepoApi

Change-Id: I4ab8d05a8b1e62387db06ccc7d5a52b72b6c96ec
---
M lib/resources/api/FormatValueCaller.js
M lib/resources/api/ParseValueCaller.js
M lib/resources/api/resources.php
M lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
4 files changed, 56 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/29/160429/1

diff --git a/lib/resources/api/FormatValueCaller.js 
b/lib/resources/api/FormatValueCaller.js
index 8cd0603..fb95f87 100644
--- a/lib/resources/api/FormatValueCaller.js
+++ b/lib/resources/api/FormatValueCaller.js
@@ -52,25 +52,17 @@
                                }
                        }
 
-                       var deferred = $.Deferred(),
-                               params = {
-                                       action: 'wbformatvalue',
-                                       datavalue:  JSON.stringify( {
-                                               value: dataValue.toJSON(),
-                                               type: dataValue.getType()
-                                       } ),
-                                       options: JSON.stringify( options || {} )
-                               };
+                       var deferred = $.Deferred();
 
-                       if( dataType ) {
-                               params.datatype = dataType;
-                       }
-
-                       if( outputFormat ) {
-                               params.generate = outputFormat;
-                       }
-
-                       this._api.get( params ).done( function( apiResult ) {
+                       this._api.formatValue(
+                               {
+                                       value: dataValue.toJSON(),
+                                       type: dataValue.getType()
+                               },
+                               options,
+                               dataType,
+                               outputFormat
+                       } ).done( function( apiResult ) {
                                if( apiResult.result ) {
                                        deferred.resolve( apiResult.result );
                                } else {
diff --git a/lib/resources/api/ParseValueCaller.js 
b/lib/resources/api/ParseValueCaller.js
index ee4d954..77f545b 100644
--- a/lib/resources/api/ParseValueCaller.js
+++ b/lib/resources/api/ParseValueCaller.js
@@ -46,14 +46,7 @@
 
                options = options || {};
 
-               this._api
-               .get( {
-                       action: 'wbparsevalue',
-                       parser: parser,
-                       values: values.join( '|' ),
-                       options: JSON.stringify( options )
-               } )
-               .done( function( response ) {
+               this._api.parseValue( parser, values, options ).done( function( 
response ) {
                        if( !response.results ) {
                                deferred.reject(
                                        'result-unexpected',
diff --git a/lib/resources/api/resources.php b/lib/resources/api/resources.php
index 36d3d51..80ccdae 100644
--- a/lib/resources/api/resources.php
+++ b/lib/resources/api/resources.php
@@ -29,7 +29,6 @@
                                'FormatValueCaller.js',
                        ),
                        'dependencies' => array(
-                               'json',
                                'wikibase.api.__namespace',
                        )
                ),
@@ -40,7 +39,6 @@
                        ),
                        'dependencies' => array(
                                'dataValues',
-                               'json',
                                'wikibase.api.__namespace',
                        )
                ),
diff --git a/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js 
b/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
index 20f3a43..0098095 100644
--- a/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
+++ b/lib/resources/wikibase.RepoApi/wikibase.RepoApi.js
@@ -91,6 +91,33 @@
        },
 
        /**
+        * Formats values.
+        *
+        * @param {Object} dataValue
+        * @param {Object} [options]
+        * @param {string} [dataType]
+        * @param {string} [outputFormat]
+        * @return {jQuery.Promise}
+        */
+       formatValue: function( dataValue, options, dataType, outputFormat)
+               var params = {
+                       action: 'wbformatvalue',
+                       datavalue:  JSON.stringify( dataValue ),
+                       options: JSON.stringify( options || {} )
+               };
+
+               if( dataType ) {
+                       params.datatype = dataType;
+               }
+
+               if( outputFormat ) {
+                       params.generate = outputFormat;
+               }
+
+               return this.get( params );
+       },
+
+       /**
         * Gets one or more Entities.
         *
         * @param {String[]|String} ids
@@ -149,6 +176,24 @@
        },
 
        /**
+        * Parses values.
+        *
+        * @param {string} parser
+        * @param {string[]} values
+        * @param {Object} options
+        * @return {jQuery.Promise}
+        */
+       parseValue: function( parser, values, options ) {
+               var params = {
+                       action: 'wbparsevalue',
+                       parser: parser,
+                       values: values.join( '|' ),
+                       options: JSON.stringify( options )
+               };
+               return this.get( params );
+       },
+
+       /**
         * Searches for entities containing the given text.
         *
         * @param {String} search search for this text

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4ab8d05a8b1e62387db06ccc7d5a52b72b6c96ec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>

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

Reply via email to