jenkins-bot has submitted this change and it was merged.
Change subject: Final wiring for the new {{#statements|…}} parser function
......................................................................
Final wiring for the new {{#statements|…}} parser function
Bug: T142941
Change-Id: Ie5a79ee32f589a3044a28d7b8d0342da84f37d8a
---
M client/WikibaseClient.i18n.magic.php
M client/config/WikibaseClient.default.php
M client/config/WikibaseClient.jenkins.php
M client/includes/DataAccess/PropertyParserFunction/Runner.php
M
client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php
M client/includes/Hooks/ParserFunctionRegistrant.php
M client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
M docs/options.wiki
8 files changed, 82 insertions(+), 21 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/WikibaseClient.i18n.magic.php
b/client/WikibaseClient.i18n.magic.php
index a87be89..7bf75c4 100644
--- a/client/WikibaseClient.i18n.magic.php
+++ b/client/WikibaseClient.i18n.magic.php
@@ -14,6 +14,7 @@
$magicWords['en'] = array(
'noexternallanglinks' => array( 0, 'noexternallanglinks' ),
'property' => array( 0, 'property' ),
+ 'statements' => array( 0, 'statements' ),
'wbreponame' => array( 0, 'wbreponame' ),
);
diff --git a/client/config/WikibaseClient.default.php
b/client/config/WikibaseClient.default.php
index 532b67d..b609d7d 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -50,6 +50,7 @@
// in the parser functions and via Lua.
// Allows users to split the ParserCache by user language.
'allowDataAccessInUserLanguage' => false,
+ 'enableStatementsParserFunction' => false,
/**
* Prefix to use for cache keys that should be shared among a
Wikibase Repo instance and all
diff --git a/client/config/WikibaseClient.jenkins.php
b/client/config/WikibaseClient.jenkins.php
index 4e98235..c354e41 100644
--- a/client/config/WikibaseClient.jenkins.php
+++ b/client/config/WikibaseClient.jenkins.php
@@ -15,3 +15,6 @@
// group in the sites table during testing.
// NOTE: This can be removed once T126596 is implemented.
$wgWBClientSettings['siteGroup'] = "mywikigroup";
+
+// TODO: Remove the feature flag when not needed any more!
+$wgWBClientSettings['enableStatementsParserFunction'] = true;
diff --git a/client/includes/DataAccess/PropertyParserFunction/Runner.php
b/client/includes/DataAccess/PropertyParserFunction/Runner.php
index e7e54d5..9b229e9 100644
--- a/client/includes/DataAccess/PropertyParserFunction/Runner.php
+++ b/client/includes/DataAccess/PropertyParserFunction/Runner.php
@@ -13,7 +13,7 @@
use Wikibase\Lib\Store\SiteLinkLookup;
/**
- * Runner for the {{#property}} parser function.
+ * Runner for the {{#property|…}} and {{#statements|…}} parser functions.
*
* @since 0.4
*
@@ -23,6 +23,7 @@
* @author Daniel Kinzler
* @author Liangent < [email protected] >
* @author Marius Hoch < [email protected] >
+ * @author Thiemo Mättig
*/
class Runner {
@@ -84,13 +85,15 @@
* @param Parser $parser
* @param PPFrame $frame
* @param array $args
+ * @param string $type Either "escaped-plaintext" or "rich-wikitext".
*
- * @return array Wikitext
+ * @return array Wikitext in element 0, flags in named elements
*/
public function runPropertyParserFunction(
Parser $parser,
PPFrame $frame,
- array $args
+ array $args,
+ $type = 'escaped-plaintext'
) {
$propertyLabelOrId = $frame->expand( $args[0] );
unset( $args[0] );
@@ -103,7 +106,7 @@
return $this->buildResult( '' );
}
- $renderer = $this->rendererFactory->newRendererFromParser(
$parser );
+ $renderer = $this->rendererFactory->newRendererFromParser(
$parser, $type );
$rendered = $renderer->render( $entityId, $propertyLabelOrId );
$result = $this->buildResult( $rendered );
@@ -163,32 +166,44 @@
}
/**
- * @param string $rendered
+ * @param string $rendered Wikitext
*
- * @return array
+ * @return array Wikitext in element 0, flags in named elements
*/
private function buildResult( $rendered ) {
- $result = array(
+ return [
$rendered,
'noparse' => false, // parse wikitext
'nowiki' => false, // formatters take care of escaping
as needed
- );
-
- return $result;
+ ];
}
/**
- * @since 0.4
+ * @since 0.5
*
* @param Parser $parser
* @param PPFrame $frame
* @param array $args
*
- * @return array
+ * @return array Wikitext in element 0, flags in named elements
*/
public static function renderEscapedPlainText( Parser $parser, PPFrame
$frame, array $args ) {
$runner =
WikibaseClient::getDefaultInstance()->getPropertyParserFunctionRunner();
return $runner->runPropertyParserFunction( $parser, $frame,
$args );
}
+ /**
+ * @since 0.5
+ *
+ * @param Parser $parser
+ * @param PPFrame $frame
+ * @param array $args
+ *
+ * @return array Wikitext in element 0, flags in named elements
+ */
+ public static function renderRichWikitext( Parser $parser, PPFrame
$frame, array $args ) {
+ $runner =
WikibaseClient::getDefaultInstance()->getPropertyParserFunctionRunner();
+ return $runner->runPropertyParserFunction( $parser, $frame,
$args, 'rich-wikitext' );
+ }
+
}
diff --git
a/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php
b/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php
index 4b55146..1187d26 100644
---
a/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php
+++
b/client/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactory.php
@@ -18,6 +18,7 @@
*
* @license GPL-2.0+
* @author Katie Filbert < [email protected] >
+ * @author Thiemo Mättig
*/
class StatementGroupRendererFactory {
@@ -74,27 +75,29 @@
/**
* @param Parser $parser
+ * @param string $type Either "escaped-plaintext" or "rich-wikitext".
*
* @return StatementGroupRenderer
*/
- public function newRendererFromParser( Parser $parser ) {
+ public function newRendererFromParser( Parser $parser, $type =
'escaped-plaintext' ) {
$usageAccumulator = new ParserOutputUsageAccumulator(
$parser->getOutput() );
if ( $this->allowDataAccessInUserLanguage ) {
// Use the user's language.
// Note: This splits the parser cache.
$targetLanguage =
$parser->getOptions()->getUserLangObj();
- return $this->newLanguageAwareRenderer(
$targetLanguage, $usageAccumulator );
+ return $this->newLanguageAwareRenderer( $type,
$targetLanguage, $usageAccumulator );
} elseif ( $this->useVariants( $parser ) ) {
$variants =
$parser->getConverterLanguage()->getVariants();
- return $this->newVariantsAwareRenderer( $variants,
$usageAccumulator );
+ return $this->newVariantsAwareRenderer( $type,
$variants, $usageAccumulator );
} else {
$targetLanguage = $parser->getTargetLanguage();
- return $this->newLanguageAwareRenderer(
$targetLanguage, $usageAccumulator );
+ return $this->newLanguageAwareRenderer( $type,
$targetLanguage, $usageAccumulator );
}
}
/**
+ * @param string $type
* @param Language $language
* @param UsageAccumulator $usageAccumulator
*
@@ -102,13 +105,21 @@
* @throws MWException
*/
private function newLanguageAwareRenderer(
+ $type,
Language $language,
UsageAccumulator $usageAccumulator
) {
- $snakFormatter =
$this->dataAccessSnakFormatterFactory->newEscapedPlainTextSnakFormatter(
- $language,
- $usageAccumulator
- );
+ if ( $type === 'rich-wikitext' ) {
+ $snakFormatter =
$this->dataAccessSnakFormatterFactory->newRichWikitextSnakFormatter(
+ $language,
+ $usageAccumulator
+ );
+ } else {
+ $snakFormatter =
$this->dataAccessSnakFormatterFactory->newEscapedPlainTextSnakFormatter(
+ $language,
+ $usageAccumulator
+ );
+ }
$entityStatementsRenderer = new StatementTransclusionInteractor(
$language,
@@ -125,17 +136,20 @@
}
/**
+ * @param string $type
* @param string $languageCode
* @param UsageAccumulator $usageAccumulator
*
* @return LanguageAwareRenderer
*/
private function getLanguageAwareRendererFromCode(
+ $type,
$languageCode,
UsageAccumulator $usageAccumulator
) {
if ( !isset( $this->languageAwareRenderers[$languageCode] ) ) {
$this->languageAwareRenderers[$languageCode] =
$this->newLanguageAwareRenderer(
+ $type,
Language::factory( $languageCode ),
$usageAccumulator
);
@@ -145,12 +159,14 @@
}
/**
+ * @param string $type
* @param string[] $variants
* @param UsageAccumulator $usageAccumulator
*
* @return VariantsAwareRenderer
*/
private function newVariantsAwareRenderer(
+ $type,
array $variants,
UsageAccumulator $usageAccumulator
) {
@@ -158,6 +174,7 @@
foreach ( $variants as $variant ) {
$languageAwareRenderers[$variant] =
$this->getLanguageAwareRendererFromCode(
+ $type,
$variant,
$usageAccumulator
);
diff --git a/client/includes/Hooks/ParserFunctionRegistrant.php
b/client/includes/Hooks/ParserFunctionRegistrant.php
index 1956724..ba97795 100644
--- a/client/includes/Hooks/ParserFunctionRegistrant.php
+++ b/client/includes/Hooks/ParserFunctionRegistrant.php
@@ -5,12 +5,14 @@
use Parser;
use PPFrame;
use Wikibase\Client\DataAccess\PropertyParserFunction\Runner;
+use Wikibase\Client\WikibaseClient;
/**
* @since 0.5
*
* @license GPL-2.0+
* @author Katie Filbert < [email protected] >
+ * @author Thiemo Mättig
*/
class ParserFunctionRegistrant {
@@ -54,6 +56,19 @@
},
Parser::SFH_OBJECT_ARGS
);
+
+ // TODO: Remove the feature flag when not needed any more!
+ if (
WikibaseClient::getDefaultInstance()->getSettings()->getSetting(
+ 'enableStatementsParserFunction'
+ ) ) {
+ $parser->setFunctionHook(
+ 'statements',
+ function( Parser $parser, PPFrame $frame, array
$args ) {
+ return Runner::renderRichWikitext(
$parser, $frame, $args );
+ },
+ Parser::SFH_OBJECT_ARGS
+ );
+ }
}
}
diff --git
a/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
b/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
index d5b9e2b..1c4bfb9 100644
--- a/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
+++ b/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
@@ -5,6 +5,7 @@
use Parser;
use PHPUnit_Framework_TestCase;
use Wikibase\Client\Hooks\ParserFunctionRegistrant;
+use Wikibase\Client\WikibaseClient;
/**
* @covers Wikibase\Client\Hooks\ParserFunctionRegistrant
@@ -31,6 +32,7 @@
[
'noexternallanglinks',
'property',
+ 'statements',
]
],
];
@@ -42,11 +44,17 @@
public function testRegisterParserFunctions( $allowDataTransclusion,
array $expected ) {
$parser = new Parser( [ 'class' => 'Parser' ] );
+ // TODO: Remove the feature flag when not needed any more!
+ $settings = WikibaseClient::getDefaultInstance()->getSettings();
+ $enabled = $settings->getSetting(
'enableStatementsParserFunction' );
+ $settings->setSetting( 'enableStatementsParserFunction', true );
+
$registrant = new ParserFunctionRegistrant(
$allowDataTransclusion );
$registrant->register( $parser );
-
$actual = $parser->getFunctionHooks();
+ $settings->setSetting( 'enableStatementsParserFunction',
$enabled );
+
$this->assertSame( $expected, $actual );
}
diff --git a/docs/options.wiki b/docs/options.wiki
index 562e080..39d8ec3 100644
--- a/docs/options.wiki
+++ b/docs/options.wiki
@@ -106,3 +106,4 @@
;showExternalRecentChanges: Whether changes on the repository should be
displayed on Special:RecentChanges, Special:Watchlist, etc on the client wiki.
In contrast to <code>injectRecentChanges</code>, this setting just removes the
changes from the user interface. The default is <code>false</code>. This is
intended to temporarily prevent external changes from showing in order to find
or fix some issue on a live site.
;sendEchoNotification: If true, allows users on the client wiki to get a
notification when a page they created is connected to a repo item. This
requires the Echo extension.
;repoIcon: If <code>sendEchoNotification</code> is set to <code>true</code>,
you can also provide what icon the user will see. The correct syntax is
<code>array( 'url' => '...' )</code> or <code>array( 'path' => '...' )</code>
where <code>path</code> is relative to <code>$wgExtensionAssetsPath</code>.
Defaults to <code>false</code> which means that there will be the default Echo
icon.
+;enableStatementsParserFunction: Feature flag for the
<code><nowiki>{{#statements|…}}</nowiki></code> parser function.
--
To view, visit https://gerrit.wikimedia.org/r/316790
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie5a79ee32f589a3044a28d7b8d0342da84f37d8a
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits