PHP 4.1.2 compatibility fixes (based on patch submission by Asheesh Laroia)
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 10 May 2004 01:54:56 +0000 (01:54 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 10 May 2004 01:54:56 +0000 (01:54 +0000)
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.

RELEASE-NOTES
includes/GlobalFunctions.php
includes/Parser.php
includes/SkinPHPTal.php
includes/Title.php

index 8b4a250..4eafc10 100644 (file)
@@ -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 ===
 
index d526064..00ab811 100644 (file)
@@ -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()
index b5924c7..79aa4e7 100644 (file)
@@ -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
index 7ab274e..b5bf343 100644 (file)
@@ -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
index b387d17..7935679 100644 (file)
@@ -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 );