[MediaWiki-commits] [Gerrit] Drop magic escaping logic from OutputFormatValueFormatterFac... - change (mediawiki...Wikibase)

2015-12-11 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Drop magic escaping logic from 
OutputFormatValueFormatterFactory.
..


Drop magic escaping logic from OutputFormatValueFormatterFactory.

Factory callbacks defined via DataTypeDefinitions are now required
directly to provide formatters for all output formats. This allows
us to drop some rather convoluted magic for escaping from the
factory. Magic that would have to be repeated in 
OutputFormatSnakFormatterFactory
in order to allow it to also use factory callbacks from DataTypeDefinitions.

Bug: T119877
Change-Id: I04e6db7524f0903c5d088adec5a0163fd35b3d69
---
M client/WikibaseClient.datatypes.php
M lib/includes/formatters/OutputFormatValueFormatterFactory.php
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
M lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
M lib/tests/phpunit/formatters/OutputFormatValueFormatterFactoryTest.php
M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
M repo/WikibaseRepo.datatypes.php
7 files changed, 265 insertions(+), 293 deletions(-)

Approvals:
  Thiemo Mättig (WMDE): Looks good to me, approved
  jenkins-bot: Verified

Objections:
  Aude: There's a problem with this change, please improve



diff --git a/client/WikibaseClient.datatypes.php 
b/client/WikibaseClient.datatypes.php
index ac41d79..75add0b 100644
--- a/client/WikibaseClient.datatypes.php
+++ b/client/WikibaseClient.datatypes.php
@@ -41,7 +41,8 @@
return array(
'VT:bad' => array(
'formatter-factory-callback' => function( $format, 
FormatterOptions $options ) {
-   return $format === SnakFormatter::FORMAT_PLAIN 
? new UnDeserializableValueFormatter( $options ) : null;
+   $factory = 
WikibaseClient::getDefaultFormatterBuilders();
+   return 
$factory->newUnDeserializableValueFormatter( $format, $options );
}
),
'VT:globecoordinate' => array(
@@ -64,7 +65,8 @@
),
'VT:string' => array(
'formatter-factory-callback' => function( $format, 
FormatterOptions $options ) {
-   return $format === SnakFormatter::FORMAT_PLAIN 
? new StringFormatter( $options ) : null;
+   $factory = 
WikibaseClient::getDefaultFormatterBuilders();
+   return $factory->newStringFormatter( $format, 
$options );
},
),
'PT:url' => array(
diff --git a/lib/includes/formatters/OutputFormatValueFormatterFactory.php 
b/lib/includes/formatters/OutputFormatValueFormatterFactory.php
index 48d7dd8..5bcf71a 100644
--- a/lib/includes/formatters/OutputFormatValueFormatterFactory.php
+++ b/lib/includes/formatters/OutputFormatValueFormatterFactory.php
@@ -138,163 +138,9 @@
public function getValueFormatter( $format, FormatterOptions $options ) 
{
$this->applyLanguageDefaults( $options );
 
-   switch ( $format ) {
-   case SnakFormatter::FORMAT_PLAIN:
-   $formatters = $this->getPlainTextFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_WIKI:
-   $formatters = $this->getWikiTextFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_HTML:
-   $formatters = $this->getHtmlFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_HTML_WIDGET:
-   $formatters = $this->getWidgetFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_HTML_DIFF:
-   $formatters = $this->getDiffFormatters( 
$options );
-   break;
-   default:
-   throw new InvalidArgumentException( 
'Unsupported format: ' . $format );
-   }
+   $formatters = $this->buildDefinedFormatters( $format, $options 
);
 
return new DispatchingValueFormatter( $formatters );
-   }
-
-   /**
-* Returns a full set of formatters for generating plain text output.
-*
-* @param FormatterOptions $options
-* @param string[] $skip A list of types to be skipped. Useful when the 
caller already has
-*formatters for some types.
-*
-* @return ValueFormatter[] A map from prefixed type IDs to 
ValueFormatter instances.
-*/
-   private function getPlainTextFormatters( FormatterOptions $options, 
array $skip = array() ) {
-   

[MediaWiki-commits] [Gerrit] Drop magic escaping logic from OutputFormatValueFormatterFac... - change (mediawiki...Wikibase)

2015-11-18 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review.

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

Change subject: Drop magic escaping logic from 
OutputFormatValueFormatterFactory.
..

Drop magic escaping logic from OutputFormatValueFormatterFactory.

Factory callbacks defined via DataTypeDefinitions are now required
directly to provide formatters for all output formats. This allows
us to drop some rather convoluted magic for escaping from the
factory. Magic that would have to be repeated in 
OutputFormatSnakFormatterFactory
in order to allow it to also use factory callbacks from DataTypeDefinitions.

Change-Id: I04e6db7524f0903c5d088adec5a0163fd35b3d69
---
M client/WikibaseClient.datatypes.php
M lib/includes/formatters/OutputFormatValueFormatterFactory.php
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
M lib/tests/phpunit/formatters/OutputFormatValueFormatterFactoryTest.php
M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
M repo/WikibaseRepo.datatypes.php
6 files changed, 186 insertions(+), 266 deletions(-)


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

diff --git a/client/WikibaseClient.datatypes.php 
b/client/WikibaseClient.datatypes.php
index e62c5ea..6ffc5c3 100644
--- a/client/WikibaseClient.datatypes.php
+++ b/client/WikibaseClient.datatypes.php
@@ -58,9 +58,7 @@
},
),
'string' => array(
-   'formatter-factory-callback' => function( $format, 
FormatterOptions $options ) {
-   return null; // rely on formatter for string 
value type
-   },
+   //'formatter-factory-callback' => // rely on formatter 
for string value type
),
'time' => array(
'formatter-factory-callback' => function( $format, 
FormatterOptions $options ) {
diff --git a/lib/includes/formatters/OutputFormatValueFormatterFactory.php 
b/lib/includes/formatters/OutputFormatValueFormatterFactory.php
index 48d7dd8..d14c1d2 100644
--- a/lib/includes/formatters/OutputFormatValueFormatterFactory.php
+++ b/lib/includes/formatters/OutputFormatValueFormatterFactory.php
@@ -138,163 +138,9 @@
public function getValueFormatter( $format, FormatterOptions $options ) 
{
$this->applyLanguageDefaults( $options );
 
-   switch ( $format ) {
-   case SnakFormatter::FORMAT_PLAIN:
-   $formatters = $this->getPlainTextFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_WIKI:
-   $formatters = $this->getWikiTextFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_HTML:
-   $formatters = $this->getHtmlFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_HTML_WIDGET:
-   $formatters = $this->getWidgetFormatters( 
$options );
-   break;
-   case SnakFormatter::FORMAT_HTML_DIFF:
-   $formatters = $this->getDiffFormatters( 
$options );
-   break;
-   default:
-   throw new InvalidArgumentException( 
'Unsupported format: ' . $format );
-   }
+   $formatters = $this->buildDefinedFormatters( $format, $options 
);
 
return new DispatchingValueFormatter( $formatters );
-   }
-
-   /**
-* Returns a full set of formatters for generating plain text output.
-*
-* @param FormatterOptions $options
-* @param string[] $skip A list of types to be skipped. Useful when the 
caller already has
-*formatters for some types.
-*
-* @return ValueFormatter[] A map from prefixed type IDs to 
ValueFormatter instances.
-*/
-   private function getPlainTextFormatters( FormatterOptions $options, 
array $skip = array() ) {
-   return $this->buildDefinedFormatters(
-   SnakFormatter::FORMAT_PLAIN,
-   $options,
-   $skip
-   );
-   }
-
-   /**
-* Returns a full set of formatters for generating wikitext output.
-* If there are formatters defined for plain text that are not defined 
for wikitext,
-* the plain text formatters are used with the appropriate escaping 
applied.
-*
-* @param FormatterOptions $options
-* @param string[] $skip A list of types to be skipped. Useful when the 
caller already has
-*formatters for some types.
-*
-* @return ValueFormatter[] A