From 2d2026c9062ee47d94eb23b89d5862a8d0c9fb34 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 20 Oct 2006 03:28:05 +0000 Subject: [PATCH] Added escapeClass static function to Sanitizer and updated last commit to use it instead of escapeId. --- includes/Sanitizer.php | 19 +++++++++++++++++++ includes/Skin.php | 2 +- includes/SkinTemplate.php | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) 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(); -- 2.20.1