Refactor somewhat so that escapeId() works right
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 5 Jan 2009 15:59:35 +0000 (15:59 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 5 Jan 2009 15:59:35 +0000 (15:59 +0000)
r45267 commented out the logic prohibiting numbers and so on at the
start of id's.  I've uncommented this logic, but passed 'noninitial' as
an option to escapeId() in all necessary circumstances.  Shouldn't
change behavior, this is to simplify some further work I'm about to do.

includes/Sanitizer.php
includes/Title.php
includes/parser/Parser.php

index e89633f..a433ce0 100644 (file)
@@ -620,7 +620,7 @@ class Sanitizer {
                        if ( $attribute === 'id' ) {
                                global $wgEnforceHtmlIds;
                                $value = Sanitizer::escapeId( $value,
-                                       $wgEnforceHtmlIds ? array() : 'xml' );
+                                       $wgEnforceHtmlIds ? 'noninitial' : 'xml' );
                        }
 
                        // If this attribute was previously set, override it.
@@ -806,18 +806,11 @@ class Sanitizer {
                        $id = urlencode( Sanitizer::decodeCharReferences( strtr( $id, ' ', '_' ) ) );
                        $id = str_replace( array_keys( $replace ), array_values( $replace ), $id );
 
-                       /*
-                       // Let's not go changing our links just yet, since we plan to
-                       // rip this out anyway and switch to the prettier Unicode-friendly
-                       // links as XHTML and HTML 5 allow and browsers seem to think is
-                       // just a-ok to do.
-                       //
                        if ( !preg_match( '/^[a-zA-Z]/', $id )
                        && !in_array( 'noninitial', $options ) )  {
                                // Initial character must be a letter!
                                $id = "x$id";
                        }
-                       */
                        return $id;
                }
 
index 9fd4c79..d41485c 100644 (file)
@@ -457,7 +457,7 @@ class Title {
                # one version of Opera 9.x.  The W3C validator, for one, doesn't seem
                # to care if they aren't encoded.
                return Sanitizer::escapeId( $fragment,
-                       $wgEnforceHtmlIds ? array() : 'xml' );
+                       $wgEnforceHtmlIds ? 'noninitial' : 'xml' );
        }
 
 #----------------------------------------------------------------------------
index a5adc7e..11cbc11 100644 (file)
@@ -3618,7 +3618,7 @@ class Parser
                        # Save headline for section edit hint before it's escaped
                        $headlineHint = $safeHeadline;
                        $safeHeadline = Sanitizer::escapeId( $safeHeadline,
-                               $wgEnforceHtmlIds ? array() : 'xml' );
+                               $wgEnforceHtmlIds ? 'noninitial' : 'xml' );
                        # HTML names must be case-insensitively unique (bug 10721)
                        $arrayKey = strtolower( $safeHeadline );
 
@@ -4688,7 +4688,7 @@ class Parser
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
                return '#' . Sanitizer::escapeId( $text,
-                       $wgEnforceHtmlIds ? array() : 'xml' );
+                       $wgEnforceHtmlIds ? 'noninitial' : 'xml' );
        }
 
        /**