jenkins-bot has submitted this change and it was merged.
Change subject: add render function to Template class
......................................................................
add render function to Template class
- have wfTemplate use render() from the template class
ultimately, for improved testing, would be nice to get away from
using wfTemplate entirely! this allows instantiating a template
and render it in the same way as wfTemplate.
Change-Id: Ie246ae35e70dbdee5147aa1ee1b9d7254690dcce
---
M lib/WikibaseLib.php
M lib/includes/TemplateRegistry.php
2 files changed, 19 insertions(+), 7 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php
index 486e4c5..10350b8 100644
--- a/lib/WikibaseLib.php
+++ b/lib/WikibaseLib.php
@@ -173,6 +173,9 @@
/**
* Shorthand function to retrieve a template filled with the specified
parameters.
*
+ * important! note that the Template class does not escape anything.
+ * be sure to escape your params before using this function!
+ *
* @since 0.2
*
* @param $key string template key
@@ -190,8 +193,7 @@
$template = new \Wikibase\Template(
\Wikibase\TemplateRegistry::singleton(), $key, $params );
- // Use plain() to prevent replacing {{...}}:
- return $template->plain();
+ return $template->render();
}
// Resource Loader Modules:
diff --git a/lib/includes/TemplateRegistry.php
b/lib/includes/TemplateRegistry.php
index ce423d3..3fc1e7a 100644
--- a/lib/includes/TemplateRegistry.php
+++ b/lib/includes/TemplateRegistry.php
@@ -50,7 +50,7 @@
* @param array $templates
*/
public function addTemplates( $templates ) {
- foreach ( $templates AS $key => $snippet ) {
+ foreach ( $templates as $key => $snippet ) {
$this->addTemplate( $key, $snippet );
}
}
@@ -83,17 +83,19 @@
}
/**
- * Represents a template that can contain placeholders just like MediWiki
messages.
+ * Represents a template that can contain placeholders just like MediaWiki
messages.
*/
class Template extends \Message {
protected $templateRegistry;
/**
- * Constructor.
+ * important! note that the Template class does not escape anything.
+ * be sure to escape your params before using this class!
*
* @param TemplateRegistry $templateRegistry
- * @param $key: message key, or array of message keys to try and use
the first non-empty message for
+ * @param $key: message key, or array of message keys to try
+ * and use the first non-empty message for
* @param $params Array message parameters
*/
public function __construct( TemplateRegistry $templateRegistry, $key,
$params = array() ) {
@@ -107,11 +109,19 @@
*
* @return string template
*/
- function fetchMessage() {
+ protected function fetchMessage() {
if ( !isset( $this->message ) ) {
$this->message = $this->templateRegistry->getTemplate(
$this->key );
}
return $this->message;
}
+ /**
+ * @return string
+ */
+ public function render() {
+ // Use plain() to prevent replacing {{...}}:
+ return $this->plain();
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/75082
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie246ae35e70dbdee5147aa1ee1b9d7254690dcce
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits