Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/282999
Change subject: Add params to JCContentView::valueToHtml()
......................................................................
Add params to JCContentView::valueToHtml()
Sometimes valueToHtml needs access to the parser state.
This patch adds several parameters as given by the fillParserOutput()
Change-Id: Ie2d37efb581080f9c112510fcb47917e09b69dd0
---
M includes/JCContent.php
M includes/JCContentView.php
M includes/JCDefaultContentView.php
M includes/JCDefaultObjContentView.php
4 files changed, 51 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/JsonConfig
refs/changes/99/282999/1
diff --git a/includes/JCContent.php b/includes/JCContent.php
index 16f6eca..a7b56ec 100644
--- a/includes/JCContent.php
+++ b/includes/JCContent.php
@@ -3,6 +3,8 @@
namespace JsonConfig;
use FormatJson;
+use ParserOptions;
+use ParserOutput;
use Title;
use Status;
@@ -159,22 +161,31 @@
return $this;
}
- /**
- * Generates HTML representation of the content.
- * @return string HTML representation.
- */
- public function getHtml() {
- $status = $this->getStatus();
- if ( $status->isGood() ) {
- $html = '';
- } else {
- $html = $status->getHTML();
- }
- if ( $status->isOK() ) {
- $html .= $this->getView( $this->getModel()
)->valueToHtml( $this );
+ protected function fillParserOutput( Title $title, $revId,
ParserOptions $options,
+
$generateHtml, ParserOutput &$output ) {
+ if ( !$generateHtml ) {
+ return;
}
- return $html;
+ // Use user's language, and split parser cache. This should
not have a big
+ // impact because data namespace is rarely viewed, but viewing
it localized
+ // will be valuable
+ $lang = $options->getUserLangObj();
+
+ $status = $this->getStatus();
+ if ( !$status->isGood() ) {
+ $html = $status->getHTML( false, false, $lang );
+ } else {
+ $html = '';
+ }
+
+ if ( $status->isOK() ) {
+ $html .= $this
+ ->getView( $this->getModel() )
+ ->valueToHtml( $this, $title, $revId, $options,
$generateHtml, $output );
+ }
+
+ $output->setText( $html );
}
/**
diff --git a/includes/JCContentView.php b/includes/JCContentView.php
index d527fe0..e4355d4 100644
--- a/includes/JCContentView.php
+++ b/includes/JCContentView.php
@@ -1,6 +1,9 @@
<?php
namespace JsonConfig;
+use ParserOptions;
+use ParserOutput;
+use Title;
/**
* This class is used as a way to specify how to edit/view JCContent object
@@ -10,11 +13,18 @@
abstract class JCContentView {
/**
- * Render JCContent object as HTML
+ * Render JCContent object as HTML - replaces valueToHtml()
* @param JCContent $content
+ * @param Title $title
+ * @param $revId
+ * @param ParserOptions $options
+ * @param $generateHtml
+ * @param ParserOutput $output
* @return string
*/
- abstract public function valueToHtml( JCContent $content );
+ abstract public function valueToHtml(
+ JCContent $content, Title $title, $revId, ParserOptions
$options, $generateHtml,
+ ParserOutput &$output );
/**
* Returns default content for this object.
diff --git a/includes/JCDefaultContentView.php
b/includes/JCDefaultContentView.php
index f521bc2..616edcf 100644
--- a/includes/JCDefaultContentView.php
+++ b/includes/JCDefaultContentView.php
@@ -4,6 +4,9 @@
use FormatJson;
use Html;
+use ParserOptions;
+use ParserOutput;
+use Title;
/**
* This class is used in case when there is no custom view defined for
JCContent object
@@ -16,7 +19,10 @@
* @param JCContent $content
* @return string
*/
- public function valueToHtml( JCContent $content ) {
+ public function valueToHtml(
+ JCContent $content, Title $title, $revId, ParserOptions
$options, $generateHtml,
+ ParserOutput &$output
+ ) {
return $this->renderValue( $content, $content->getData(),
array() );
}
diff --git a/includes/JCDefaultObjContentView.php
b/includes/JCDefaultObjContentView.php
index 8a1685e..67d6895 100644
--- a/includes/JCDefaultObjContentView.php
+++ b/includes/JCDefaultObjContentView.php
@@ -4,6 +4,9 @@
use FormatJson;
use Html;
+use ParserOptions;
+use ParserOutput;
+use Title;
/**
* This class is used in case when there is no custom view defined for
JCContent object
@@ -16,7 +19,10 @@
* @param JCContent|JCObjContent $content
* @return string
*/
- public function valueToHtml( JCContent $content ) {
+ public function valueToHtml(
+ JCContent $content, Title $title, $revId, ParserOptions
$options, $generateHtml,
+ ParserOutput &$output
+ ) {
return $this->renderValue( $content,
$content->getValidationData(), array() );
}
--
To view, visit https://gerrit.wikimedia.org/r/282999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2d37efb581080f9c112510fcb47917e09b69dd0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits