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

Change subject: Provide fallbacks for use of mb_convert_encoding() in 
HtmlFormatter
......................................................................


Provide fallbacks for use of mb_convert_encoding() in HtmlFormatter

Since we don't strictly require mbstring in core, provide fallbacks for
the use of mb_convert_encoding() to go to/from 'HTML-ENTITIES' in
HtmlFormatter.

This fixes the api help page on REL1_25, which wasn't depending
on it on REL1_24

Bug: T62174
Change-Id: I2dcde96e0e68a7d141f2ba79558b20e1d9c799ec
(cherry picked from commit 21ae7bdb3a48be60f1ce75979ccd31111c256af3)
---
M RELEASE-NOTES-1.25
M includes/HtmlFormatter.php
2 files changed, 20 insertions(+), 2 deletions(-)

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



diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25
index 3e25423..dec241b 100644
--- a/RELEASE-NOTES-1.25
+++ b/RELEASE-NOTES-1.25
@@ -12,6 +12,9 @@
   pointing to nonexistent pages.
 * (T104142) $wgEmergencyContact and $wgPasswordSender now use their default
   value if set to an empty string.
+* (T62174) Provide fallbacks for use of mb_convert_encoding() in
+  HtmlFormatter. It was causing an error when accessing the api help page
+  if the mbstring PHP extension was not installed.
 
 == MediaWiki 1.25.2 ==
 
diff --git a/includes/HtmlFormatter.php b/includes/HtmlFormatter.php
index b2926d1..221cefb 100644
--- a/includes/HtmlFormatter.php
+++ b/includes/HtmlFormatter.php
@@ -63,7 +63,15 @@
         */
        public function getDoc() {
                if ( !$this->doc ) {
-                       $html = mb_convert_encoding( $this->html, 
'HTML-ENTITIES', 'UTF-8' );
+                       // DOMDocument::loadHTML apparently isn't very good 
with encodings, so
+                       // convert input to ASCII by encoding everything above 
128 as entities.
+                       if ( function_exists( 'mb_convert_encoding' ) ) {
+                               $html = mb_convert_encoding( $this->html, 
'HTML-ENTITIES', 'UTF-8' );
+                       } else {
+                               $html = preg_replace_callback( 
'/[\x{80}-\x{10ffff}]/u', function ( $m ) {
+                                       return '&#' . 
UtfNormal\Utils::utf8ToCodepoint( $m[0] ) . ';';
+                               }, $this->html );
+                       }
 
                        // Workaround for bug that caused spaces before 
references
                        // to disappear during processing:
@@ -244,7 +252,14 @@
                        ) );
                }
                $html = $replacements->replace( $html );
-               $html = mb_convert_encoding( $html, 'UTF-8', 'HTML-ENTITIES' );
+
+               if ( function_exists( 'mb_convert_encoding' ) ) {
+                       // Just in case the conversion in getDoc() above used 
named
+                       // entities that aren't known to html_entity_decode().
+                       $html = mb_convert_encoding( $html, 'UTF-8', 
'HTML-ENTITIES' );
+               } else {
+                       $html = html_entity_decode( $html, ENT_COMPAT, 'utf-8' 
);
+               }
                return $html;
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2dcde96e0e68a7d141f2ba79558b20e1d9c799ec
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_25
Gerrit-Owner: Martineznovo <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to