Content: Deprecate and stop using getHighlightHtml()
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 5 May 2014 15:59:54 +0000 (17:59 +0200)
committerOri.livneh <ori@wikimedia.org>
Fri, 9 May 2014 10:18:00 +0000 (10:18 +0000)
That function was clearly a bad idea, everyone should just use
getHtml() instead. It was supposed to allow extensions to extend
the content formatting process, but actually doesn't.

A better hook-based solution follows in separate commit I979e2438.

Split off from original I979e2438 and rebased with minor changes
(updated documentation comments, etc.).

Co-Authored-By: daniel <daniel.kinzler@wikimedia.de>
Co-Authored-By: Bartosz Dziewoński <matma.rex@gmail.com>
Change-Id: I76412f9d28bb145fb5975f59e538f6560e50472f

includes/content/CssContent.php
includes/content/JavaScriptContent.php
includes/content/TextContent.php

index 5fc2c9f..2673084 100644 (file)
@@ -67,7 +67,7 @@ class CssContent extends TextContent {
        protected function getHtml() {
                $html = "";
                $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
-               $html .= $this->getHighlightHtml();
+               $html .= htmlspecialchars( $this->getNativeData() );
                $html .= "\n</pre>\n";
 
                return $html;
index 11a470e..442b705 100644 (file)
@@ -66,7 +66,7 @@ class JavaScriptContent extends TextContent {
        protected function getHtml() {
                $html = "";
                $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
-               $html .= $this->getHighlightHtml();
+               $html .= htmlspecialchars( $this->getNativeData() );
                $html .= "\n</pre>\n";
 
                return $html;
index 0c6b06f..4c95d3c 100644 (file)
@@ -242,10 +242,12 @@ class TextContent extends AbstractContent {
         * Generates an HTML version of the content, for display. Used by
         * getParserOutput() to construct a ParserOutput object.
         *
-        * This default implementation just calls getHighlightHtml(). Content
-        * models that have another mapping to HTML (as is the case for markup
-        * languages like wikitext) should override this method to generate the
-        * appropriate HTML.
+        * Subclasses may override this to provide a custom HTML rendering.
+        * If further information is to be derived from the content (such as
+        * categories), the getParserOutput() method can be overridden instead.
+        *
+        * For backwards-compatibility, this default implementation just calls
+        * getHighlightHtml().
         *
         * @return string An HTML representation of the content
         */
@@ -254,13 +256,22 @@ class TextContent extends AbstractContent {
        }
 
        /**
-        * Generates a syntax-highlighted version of the content, as HTML.
-        * Used by the default implementation of getHtml().
+        * Generates an HTML version of the content, for display.
+        *
+        * This default implementation returns an HTML-escaped version
+        * of the raw text content.
+        *
+        * @note: The functionality of this method should really be implemented
+        * in getHtml(), and subclasses should override getHtml() if needed.
+        * getHighlightHtml() is kept around for backward compatibility with
+        * extensions that already override it.
         *
-        * @return string A HTML representation of the content's markup
+        * @deprecated since 1.24. Use getHtml() instead. In particular, subclasses overriding
+        *     getHighlightHtml() should override getHtml() instead.
+        *
+        * @return string An HTML representation of the content
         */
        protected function getHighlightHtml() {
-               # TODO: make Highlighter interface, use highlighter here, if available
                return htmlspecialchars( $this->getNativeData() );
        }