Added escapeClass static function to Sanitizer and updated last commit to use it...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 20 Oct 2006 03:28:05 +0000 (03:28 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 20 Oct 2006 03:28:05 +0000 (03:28 +0000)
includes/Sanitizer.php
includes/Skin.php
includes/SkinTemplate.php

index 185679f..7d9ccc0 100644 (file)
@@ -736,6 +736,25 @@ class Sanitizer {
                return str_replace( array_keys( $replace ), array_values( $replace ), $id );
        }
 
+       /**
+        * Given a value, escape it so that it can be used as a CSS class and
+        * return it.
+        *
+        * TODO: For extra validity, input should be validated UTF-8.
+        *
+        * @link http://www.w3.org/TR/CSS21/syndata.html Valid characters/format
+        *
+        * @param string $class
+        * @return string
+        */
+       static function escapeClass( $class ) {
+               // Convert ugly stuff to underscores and kill underscores in ugly places
+               return rtrim(preg_replace(
+                       array('/(^[0-9\\-])|[\\x00-\\x20!"#$%&\'()*+,.\\/:;<=>?@[\\]^`{|}~]|\\xC2\\xA0/','/_+/'),
+                       '_',
+                       $class ), '_');
+       }
+
        /**
         * Regex replace callback for armoring links against further processing.
         * @param array $matches
index ea9dd21..d07bbb2 100644 (file)
@@ -478,7 +478,7 @@ END;
                        $a['onload'] .= 'setupRightClickEdit()';
                }
                $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
-               ' page-'.Sanitizer::escapeId( $wgTitle->getPrefixedText() );
+               ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
                return $a;
        }
 
index 20d88ba..ff3c1d1 100644 (file)
@@ -190,7 +190,7 @@ class SkinTemplate extends Skin {
                $tpl->set( 'title', $wgOut->getPageTitle() );
                $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
                $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
-               $tpl->set( 'pageclass', 'page-'.Sanitizer::escapeId( $wgTitle->getPrefixedText() ) );
+               $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
 
                $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ];
                if ( $nsname === NULL ) $nsname = $this->mTitle->getNsText();