[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Refactor DataAccessSnakFormatterFactory
Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/320790 Change subject: Refactor DataAccessSnakFormatterFactory .. Refactor DataAccessSnakFormatterFactory This is split from If613ac0 to make it easier to review. The goal is to reduce duplication. Otherwise there would be the same if-else in multiple places in the code base, just to call these two methods that don't do anything but turning their name into a string parameter. Bug: T113955 Change-Id: I1308fb883af64d8e9df3d27dba0b044f19f40cc5 --- M client/includes/DataAccess/DataAccessSnakFormatterFactory.php M client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php M client/tests/phpunit/includes/DataAccess/DataAccessSnakFormatterFactoryTest.php M client/tests/phpunit/includes/DataAccess/DataAccessSnakFormatterOutputFormatTest.php 6 files changed, 24 insertions(+), 56 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/90/320790/1 diff --git a/client/includes/DataAccess/DataAccessSnakFormatterFactory.php b/client/includes/DataAccess/DataAccessSnakFormatterFactory.php index 703e47c..f4f51ee 100644 --- a/client/includes/DataAccess/DataAccessSnakFormatterFactory.php +++ b/client/includes/DataAccess/DataAccessSnakFormatterFactory.php @@ -57,48 +57,19 @@ } /** -* This returns a SnakFormatter that will return wikitext escaped plain text. -* The only exception are URLs, these are plain text, but not escaped in any -* way. +* This returns a SnakFormatter that will return either "rich" wikitext, or wikitext escaped +* plain text. The only exception are URLs, these are not escaped but plain text. * * @param Language $language * @param UsageAccumulator $usageAccumulator +* @param string $type Either "escaped-plaintext" or "rich-wikitext". * * @return SnakFormatter */ - public function newEscapedPlainTextSnakFormatter( + public function newSnakFormatter( Language $language, - UsageAccumulator $usageAccumulator - ) { - return $this->newSnakFormatter( 'escaped-plaintext', $language, $usageAccumulator ); - } - - /** -* This returns a SnakFormatter that will return "rich" wikitext. -* -* @param Language $language -* @param UsageAccumulator $usageAccumulator -* -* @return SnakFormatter -*/ - public function newRichWikitextSnakFormatter( - Language $language, - UsageAccumulator $usageAccumulator - ) { - return $this->newSnakFormatter( 'rich-wikitext', $language, $usageAccumulator ); - } - - /** -* @param string $type -* @param Language $language -* @param UsageAccumulator $usageAccumulator -* -* @return SnakFormatter -*/ - private function newSnakFormatter( - $type, - Language $language, - UsageAccumulator $usageAccumulator + UsageAccumulator $usageAccumulator, + $type = 'escaped-plaintext' ) { $fallbackChain = $this->languageFallbackChainFactory->newFromLanguage( $language, diff --git a/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php b/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php index 1187d26..1dd03df 100644 --- a/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php +++ b/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php @@ -109,17 +109,11 @@ Language $language, UsageAccumulator $usageAccumulator ) { - if ( $type === 'rich-wikitext' ) { - $snakFormatter = $this->dataAccessSnakFormatterFactory->newRichWikitextSnakFormatter( - $language, - $usageAccumulator - ); - } else { - $snakFormatter = $this->dataAccessSnakFormatterFactory->newEscapedPlainTextSnakFormatter( - $language, - $usageAccumulator - ); - } + $snakFormatter = $this->dataAccessSnakFormatterFactory->newSnakFormatter( + $language, + $usageAccumulator, + $type + ); $entityStatementsRenderer = new StatementTransclusionInteractor(
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Refactor DataAccessSnakFormatterFactory
jenkins-bot has submitted this change and it was merged. Change subject: Refactor DataAccessSnakFormatterFactory .. Refactor DataAccessSnakFormatterFactory This is split from If613ac0 to make it easier to review. The goal is to reduce duplication. Otherwise there would be the same if-else in multiple places in the code base, just to call these two methods that don't do anything but turning their name into a string parameter. Bug: T113955 Change-Id: I1308fb883af64d8e9df3d27dba0b044f19f40cc5 --- M client/includes/DataAccess/DataAccessSnakFormatterFactory.php M client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseEntityLibrary.php M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php M client/tests/phpunit/includes/DataAccess/DataAccessSnakFormatterFactoryTest.php M client/tests/phpunit/includes/DataAccess/DataAccessSnakFormatterOutputFormatTest.php 6 files changed, 24 insertions(+), 56 deletions(-) Approvals: Hoo man: Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/DataAccess/DataAccessSnakFormatterFactory.php b/client/includes/DataAccess/DataAccessSnakFormatterFactory.php index 703e47c..d5a2797 100644 --- a/client/includes/DataAccess/DataAccessSnakFormatterFactory.php +++ b/client/includes/DataAccess/DataAccessSnakFormatterFactory.php @@ -57,48 +57,19 @@ } /** -* This returns a SnakFormatter that will return wikitext escaped plain text. -* The only exception are URLs, these are plain text, but not escaped in any -* way. +* This returns a SnakFormatter that will return either "rich" wikitext, or wikitext escaped +* plain text. The only exception are URLs, these are not escaped but plain text. * * @param Language $language * @param UsageAccumulator $usageAccumulator +* @param string $type Either "escaped-plaintext" or "rich-wikitext". * * @return SnakFormatter */ - public function newEscapedPlainTextSnakFormatter( + public function newWikitextSnakFormatter( Language $language, - UsageAccumulator $usageAccumulator - ) { - return $this->newSnakFormatter( 'escaped-plaintext', $language, $usageAccumulator ); - } - - /** -* This returns a SnakFormatter that will return "rich" wikitext. -* -* @param Language $language -* @param UsageAccumulator $usageAccumulator -* -* @return SnakFormatter -*/ - public function newRichWikitextSnakFormatter( - Language $language, - UsageAccumulator $usageAccumulator - ) { - return $this->newSnakFormatter( 'rich-wikitext', $language, $usageAccumulator ); - } - - /** -* @param string $type -* @param Language $language -* @param UsageAccumulator $usageAccumulator -* -* @return SnakFormatter -*/ - private function newSnakFormatter( - $type, - Language $language, - UsageAccumulator $usageAccumulator + UsageAccumulator $usageAccumulator, + $type = 'escaped-plaintext' ) { $fallbackChain = $this->languageFallbackChainFactory->newFromLanguage( $language, diff --git a/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php b/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php index 1187d26..224eac1 100644 --- a/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php +++ b/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php @@ -109,17 +109,11 @@ Language $language, UsageAccumulator $usageAccumulator ) { - if ( $type === 'rich-wikitext' ) { - $snakFormatter = $this->dataAccessSnakFormatterFactory->newRichWikitextSnakFormatter( - $language, - $usageAccumulator - ); - } else { - $snakFormatter = $this->dataAccessSnakFormatterFactory->newEscapedPlainTextSnakFormatter( - $language, - $usageAccumulator - ); - } + $snakFormatter = $this->dataAccessSnakFormatterFactory->newWikitextSnakFormatter( + $language, + $usageAccumulator, + $type + ); $entityStatementsRenderer = new StatementTransclusionInteractor( $language, diff --git a/client/includes/DataAcc