jenkins-bot has submitted this change and it was merged.

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
M includes/JCUtils.php
5 files changed, 70 insertions(+), 18 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/JCContent.php b/includes/JCContent.php
index 16f6eca..f21724f 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,30 @@
                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;
+               $status = $this->getStatus();
+               if ( !$status->isGood() ) {
+                       // 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();
+                       $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..45c7897 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
@@ -11,10 +14,20 @@
 
        /**
         * Render JCContent object as HTML
+        * Called from an override of AbstractContent::fillParserOutput()
+        *
+        * Render JCContent object as HTML - replaces valueToHtml()
         * @param JCContent $content
+        * @param Title $title Context title for parsing
+        * @param int|null $revId Revision ID (for {{REVISIONID}})
+        * @param ParserOptions $options Parser options
+        * @param bool $generateHtml Whether or not to generate HTML
+        * @param ParserOutput &$output The output object to fill (reference).
         * @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..6909ff2 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
@@ -13,10 +16,21 @@
 
        /**
         * Render JCContent object as HTML
+        * Called from an override of AbstractContent::fillParserOutput()
+        *
+        * Render JCContent object as HTML - replaces valueToHtml()
         * @param JCContent $content
+        * @param Title $title Context title for parsing
+        * @param int|null $revId Revision ID (for {{REVISIONID}})
+        * @param ParserOptions $options Parser options
+        * @param bool $generateHtml Whether or not to generate HTML
+        * @param ParserOutput &$output The output object to fill (reference).
         * @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..7bb398e 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
@@ -13,10 +16,21 @@
 
        /**
         * Render JCContent object as HTML
+        * Called from an override of AbstractContent::fillParserOutput()
+        *
+        * Render JCContent object as HTML - replaces valueToHtml()
         * @param JCContent|JCObjContent $content
+        * @param Title $title Context title for parsing
+        * @param int|null $revId Revision ID (for {{REVISIONID}})
+        * @param ParserOptions $options Parser options
+        * @param bool $generateHtml Whether or not to generate HTML
+        * @param ParserOutput &$output The output object to fill (reference).
         * @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() );
        }
 
diff --git a/includes/JCUtils.php b/includes/JCUtils.php
index 9317cd4..cece32f 100644
--- a/includes/JCUtils.php
+++ b/includes/JCUtils.php
@@ -7,6 +7,7 @@
 use Language;
 use MWHttpRequest;
 use stdClass;
+use StubUserLang;
 
 /**
  * Various useful utility functions (all static)
@@ -237,7 +238,7 @@
         * Find a message in a dictionary for the given language,
         * or use language fallbacks if message is not defined.
         * @param stdClass $map Dictionary of languageCode => string
-        * @param Language $lang language object
+        * @param Language|StubUserLang $lang language object
         * @return string message from the dictionary or "" if nothing found
         */
        public static function pickLocalizedString( stdClass $map, $lang ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/282999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie2d37efb581080f9c112510fcb47917e09b69dd0
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to