Aude has uploaded a new change for review.

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

Change subject: Update Wikidata - fix api xml / raw mode handling
......................................................................

Update Wikidata - fix api xml / raw mode handling

Change-Id: Ib9e78aceaa2e8f5e50bcb2655c62085afe724f5a
---
M composer.lock
M extensions/Wikibase/repo/includes/api/ApiHelperFactory.php
M extensions/Wikibase/repo/includes/api/ResultBuilder.php
M extensions/Wikibase/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
M vendor/composer/installed.json
5 files changed, 47 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikidata 
refs/changes/00/228300/1

diff --git a/composer.lock b/composer.lock
index 18290e0..07b433d 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1325,7 +1325,7 @@
             "source": {
                 "type": "git",
                 "url": 
"https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Wikibase.git";,
-                "reference": "8d8991d0c651dfe2f0e023516bd7a5a93d3e23fa"
+                "reference": "62e6fe44a874c861679bee3b0f1181d1e05c3f0b"
             },
             "require": {
                 "data-values/common": "~0.2.0",
@@ -1403,7 +1403,7 @@
                 "issues": "https://phabricator.wikimedia.org/";,
                 "irc": "irc://irc.freenode.net/wikidata"
             },
-            "time": "2015-07-29 16:54:34"
+            "time": "2015-07-31 01:14:29"
         },
         {
             "name": "wikibase/wikimedia-badges",
diff --git a/extensions/Wikibase/repo/includes/api/ApiHelperFactory.php 
b/extensions/Wikibase/repo/includes/api/ApiHelperFactory.php
index f402b99..5e977cd 100644
--- a/extensions/Wikibase/repo/includes/api/ApiHelperFactory.php
+++ b/extensions/Wikibase/repo/includes/api/ApiHelperFactory.php
@@ -102,8 +102,7 @@
                        $this->newLibSerializerFactory( $defaultOptions ),
                        $this->newSerializerFactory(),
                        $this->siteStore,
-                       $this->dataTypeLookup,
-                       $api->getResult()->getIsRawMode()
+                       $this->dataTypeLookup
                );
        }
 
diff --git a/extensions/Wikibase/repo/includes/api/ResultBuilder.php 
b/extensions/Wikibase/repo/includes/api/ResultBuilder.php
index ed788ea..690fdae 100644
--- a/extensions/Wikibase/repo/includes/api/ResultBuilder.php
+++ b/extensions/Wikibase/repo/includes/api/ResultBuilder.php
@@ -104,7 +104,7 @@
                SerializerFactory $serializerFactory,
                SiteStore $siteStore,
                PropertyDataTypeLookup $dataTypeLookup,
-               $isRawMode
+               $isRawMode = null
        ) {
                if ( !$result instanceof ApiResult ) {
                        throw new InvalidArgumentException( 'Result builder 
must be constructed with an ApiResult' );
@@ -130,11 +130,27 @@
        public function getOptions() {
                if ( !$this->options ) {
                        $this->options = new SerializationOptions();
-                       $this->options->setIndexTags( $this->isRawMode );
+                       $this->options->setIndexTags( $this->getIsRawMode() );
                        $this->options->setOption( 
EntitySerializer::OPT_SORT_ORDER, EntitySerializer::SORT_NONE );
                }
 
                return $this->options;
+       }
+
+       /**
+        * isRawMode needs to be lazy initialized since ApiMain may set it
+        * on the ApiResult after the module is constructed.
+        *
+        * isRawMode can be set in the constructor, such as for testing 
purposes.
+        *
+        * @return bool
+        */
+       private function getIsRawMode() {
+               if ( $this->isRawMode === null ) {
+                       $this->isRawMode = $this->result->getIsRawMode();
+               }
+
+               return $this->isRawMode;
        }
 
        /**
@@ -181,7 +197,7 @@
                $this->checkNameIsString( $name );
                $this->checkTagIsString( $tag );
 
-               if ( $this->isRawMode ) {
+               if ( $this->getIsRawMode() ) {
                        // Unset first, so we don't make the tag name an actual 
value.
                        // We'll be setting this to $tag by calling 
setIndexedTagName().
                        unset( $values['_element'] );
@@ -247,7 +263,7 @@
 
                $this->checkValueIsNotList( $value );
 
-               if ( $this->isRawMode ) {
+               if ( $this->getIsRawMode() ) {
                        $key = null;
                }
 
@@ -492,7 +508,7 @@
         * @param array|string $path where the data is located
         */
        public function addAliasGroupList( AliasGroupList $aliasGroupList, 
$path ) {
-               if ( $this->isRawMode ) {
+               if ( $this->getIsRawMode() ) {
                        $serializer = 
$this->serializerFactory->newAliasGroupSerializer();
                        $values = array();
                        foreach ( $aliasGroupList->toArray() as $aliasGroup ) {
@@ -528,7 +544,7 @@
                        $values = $this->getSiteLinkListArrayWithUrls( $values 
);
                }
 
-               if ( $this->isRawMode ) {
+               if ( $this->getIsRawMode() ) {
                        $values = $this->getRawModeSiteLinkListArray( $values );
                }
 
@@ -629,7 +645,7 @@
                        $this->getModCallbackToAddDataTypeToSnak()
                );
 
-               if ( $this->isRawMode ) {
+               if ( $this->getIsRawMode() ) {
                        $value = $this->getRawModeClaimArray( $value );
                }
 
@@ -693,7 +709,7 @@
 
                $value = $this->getArrayWithDataTypesInGroupedSnakListAtPath( 
$value, 'snaks' );
 
-               if ( $this->isRawMode ) {
+               if ( $this->getIsRawMode() ) {
                        $value = $this->getRawModeReferenceArray( $value );
                }
 
diff --git 
a/extensions/Wikibase/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php 
b/extensions/Wikibase/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
index ee90ddf..be0ab70 100644
--- a/extensions/Wikibase/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
+++ b/extensions/Wikibase/repo/tests/phpunit/includes/api/ApiXmlFormatTest.php
@@ -49,7 +49,7 @@
                );
 
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\GetEntities', 'wbgetentities', $params );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result, $entityId );
 
                $this->assertXmlStringEqualsXmlString( $this->getExpectedXml( 
'getentities' ), $actual );
@@ -65,7 +65,7 @@
                );
 
                $module = $this->getApiModule( '\Wikibase\Repo\Api\GetClaims', 
'wbgetclaims', $params );
-               $actual = $this->doApiRequest( $module );
+               $actual = $this->executeApiModule( $module );
 
                $this->assertXmlStringEqualsXmlString( $this->getExpectedXml( 
'getclaims' ), $actual );
        }
@@ -82,7 +82,7 @@
                );
 
                $module = $this->getApiModule( '\Wikibase\Repo\Api\SetLabel', 
'wbsetlabel', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result, $entityId );
 
                $this->assertXmlStringEqualsXmlString( $this->getExpectedXml( 
'setlabel' ), $actual );
@@ -100,7 +100,7 @@
                );
 
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\SetDescription', 'wbsetdescription', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result, $entityId );
 
                $this->assertXmlStringEqualsXmlString( $this->getExpectedXml( 
'setdescription' ), $actual );
@@ -118,7 +118,7 @@
                );
 
                $module = $this->getApiModule( '\Wikibase\Repo\Api\SetAliases', 
'wbsetaliases', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result, $entityId );
 
                $this->assertXmlStringEqualsXmlString( $this->getExpectedXml( 
'setaliases' ), $actual );
@@ -140,7 +140,7 @@
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\SetSiteLink', 'wbsetsitelink', $params, true );
                $siteTaregtProvider = new SiteLinkTargetProvider( 
MockSiteStore::newFromTestSites(), array() );
                $module->setServices( $siteTaregtProvider );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result, $entityId );
                //If a URL has been added just remove it as it is not always 
present
                $actual = str_replace( 
'url="https://en.wikipedia.org/wiki/Japan";', '', $actual );
@@ -160,7 +160,7 @@
 
                /** @var SetSiteLink $module */
                $module = $this->getApiModule( '\Wikibase\Repo\Api\SetClaim', 
'wbsetclaim', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result );
 
                $this->assertXmlStringEqualsXmlString( $this->getExpectedXml( 
'setclaim' ), $actual );
@@ -180,7 +180,7 @@
 
                /** @var SetSiteLink $module */
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\SetReference', 'wbsetreference', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result );
                $actual = $this->replaceHashWithMock( $actual );
 
@@ -201,7 +201,7 @@
 
                /** @var SetSiteLink $module */
                $module = $this->getApiModule( 
'\Wikibase\Repo\Api\SetQualifier', 'wbsetqualifier', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result );
                $actual = $this->replaceHashWithMock( $actual );
 
@@ -223,7 +223,7 @@
                );
 
                $module = $this->getApiModule( '\Wikibase\Repo\Api\EditEntity', 
'wbeditEntity', $params, true );
-               $result = $this->doApiRequest( $module );
+               $result = $this->executeApiModule( $module );
                $actual = $this->removePageInfoAttributes( $result, $entityId );
                $actual = $this->replaceHashWithMock( $actual );
 
@@ -295,17 +295,18 @@
                $request = new FauxRequest( $params, true );
                $main = new ApiMain( $request );
 
-               /**
-                * This has to be set before the Wikibase Api module is 
instansiated due to the ApiHelperFactory
-                * using $api->getResult()->getIsRawMode().
-                */
-               $main->getResult()->setRawMode( true );
-
                return new $moduleClass( $main, $moduleName );
        }
 
-       private function doApiRequest( ApiBase $module ) {
+       /**
+        * This mimics ApiMain::executeAction with the relevant parts,
+        * including setupExternalResponse where the printer is set. and
+        * Then raw mode is set the api format requires it. (always for xml)
+        * The module is then executed and results printed.
+        */
+       private function executeApiModule( ApiBase $module ) {
                $printer = $module->getMain()->createPrinterByName( 'xml' );
+               $module->getResult()->setRawMode( true );
 
                $module->execute();
 
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 2f0b713..b702e08 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -1417,7 +1417,7 @@
         "source": {
             "type": "git",
             "url": 
"https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Wikibase.git";,
-            "reference": "8d8991d0c651dfe2f0e023516bd7a5a93d3e23fa"
+            "reference": "62e6fe44a874c861679bee3b0f1181d1e05c3f0b"
         },
         "require": {
             "data-values/common": "~0.2.0",
@@ -1446,7 +1446,7 @@
         "require-dev": {
             "squizlabs/php_codesniffer": "~2.1"
         },
-        "time": "2015-07-29 09:28:08",
+        "time": "2015-07-31 00:21:34",
         "type": "mediawiki-extension",
         "installation-source": "source",
         "autoload": {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib9e78aceaa2e8f5e50bcb2655c62085afe724f5a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikidata
Gerrit-Branch: wmf/1.26wmf16
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to