From: Aryeh Gregor Date: Fri, 20 Oct 2006 03:28:05 +0000 (+0000) Subject: Added escapeClass static function to Sanitizer and updated last commit to use it... X-Git-Tag: 1.31.0-rc.0~55429 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=2d2026c9062ee47d94eb23b89d5862a8d0c9fb34;p=lhc%2Fweb%2Fwiklou.git Added escapeClass static function to Sanitizer and updated last commit to use it instead of escapeId. --- diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 185679f6cd..7d9ccc0fb7 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -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 diff --git a/includes/Skin.php b/includes/Skin.php index ea9dd2152a..d07bbb2451 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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; } diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 20d88ba6f2..ff3c1d11ac 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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();