From: Brion Vibber Date: Mon, 10 May 2004 01:54:56 +0000 (+0000) Subject: PHP 4.1.2 compatibility fixes (based on patch submission by Asheesh Laroia) X-Git-Tag: 1.3.0beta1~105 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=33f1e77c11bb5bfb1b4c1a4b467916b70854e855;p=lhc%2Fweb%2Fwiklou.git PHP 4.1.2 compatibility fixes (based on patch submission by Asheesh Laroia) Also, urlencode anchor names for non-ascii compatibility. This is the recommendation of HTML 4.01 standard in B.2.1, as far as I can tell. Works in UTF-8 at least for IE6/win, Firefox, Safari. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8b4a2505bf..4eafc10c72 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -46,6 +46,8 @@ Code and compatibility: * Bundled PHPTAL 0.7.0 from http://phptal.sourceforge.net/ (with some patches) * Most image-related code moved to Image.php +* More fixes for PHP 4.1.2 (thanks to Asheesh Laroia) +* URL encoding fix for anchors === Caveats === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index d526064bb0..00ab811cc8 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -36,6 +36,31 @@ if( !function_exists('file_get_contents') ) { } } +if( !function_exists('is_a') ) { + # Exists in PHP 4.2.0+ + function is_a( $object, $class_name ) { + return + (strcasecmp( get_class( $object, $class_name ) == 0) || + is_subclass_of( $object, $class_name ) ); + } +} + +# html_entity_decode exists in PHP 4.3.0+ but is FATALLY BROKEN even then, +# with no UTF-8 support. +function do_html_entity_decode( $string, $quote_style=ENT_COMPAT, $charset="ISO-8859-1" ) { + static $trans; + if( !isset( $trans ) ) { + $trans = array_flip( get_html_translation_table( HTML_ENTITIES, $quote_style ) ); + # Assumes $charset will always be the same through a run, and only understands + # utf-8 or default. Note - mixing latin1 named entities and unicode numbered + # ones will result in a bad link. + if( strcasecmp( "utf-8", $charset ) == 0 ) { + $trans = array_map( "utf8_encode", $trans ); + } + } + return strtr( $string, $trans ); +} + $wgRandomSeeded = false; function wfSeedRandom() diff --git a/includes/Parser.php b/includes/Parser.php index b5924c7304..79aa4e7244 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1674,6 +1674,8 @@ class Parser /* private */ function formatHeadings( $text ) { + global $wgInputEncoding; + $doNumberHeadings = $this->mOptions->getNumberHeadings(); $doShowToc = $this->mOptions->getShowToc(); if( !$this->mTitle->userCanEdit() ) { @@ -1774,7 +1776,7 @@ class Parser # strip out HTML $canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline ); $tocline = trim( $canonized_headline ); - $canonized_headline = preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', html_entity_decode( $tocline)); + $canonized_headline = preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', urlencode( do_html_entity_decode( $tocline, ENT_COMPAT, $wgInputEncoding ) ) ); $refer[$headlineCount] = $canonized_headline; # count how many in assoc. array so we can track dupes in anchors diff --git a/includes/SkinPHPTal.php b/includes/SkinPHPTal.php index 7ab274e5c2..b5bf3436f8 100644 --- a/includes/SkinPHPTal.php +++ b/includes/SkinPHPTal.php @@ -26,6 +26,7 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # http://www.gnu.org/copyleft/gpl.html + require_once "GlobalFunctions.php"; require_once "PHPTAL.php"; class MediaWiki_I18N extends PHPTAL_I18N diff --git a/includes/Title.php b/includes/Title.php index b387d172b9..7935679a63 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -55,24 +55,14 @@ class Title { # From text, such as what you would find in a link /* static */ function newFromText( $text, $defaultNamespace = 0 ) { - static $trans; $fname = "Title::newFromText"; wfProfileIn( $fname ); - # Note - mixing latin1 named entities and unicode numbered - # ones will result in a bad link. - if( !isset( $trans ) ) { - global $wgInputEncoding; - $trans = array_flip( get_html_translation_table( HTML_ENTITIES ) ); - if( strcasecmp( "utf-8", $wgInputEncoding ) == 0 ) { - $trans = array_map( "utf8_encode", $trans ); - } - } - if( is_object( $text ) ) { wfDebugDieBacktrace( "Called with object instead of string." ); } - $text = strtr( $text, $trans ); + global $wgInputEncoding; + $text = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding ); $text = wfMungeToUtf8( $text );