Added escapeClass static function to Sanitizer and updated last commit to use it instead of escapeId.

This commit is contained in:
Aryeh Gregor 2006-10-20 03:28:05 +00:00
parent 470cb09fbc
commit 2d2026c906
3 changed files with 21 additions and 2 deletions

View 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

View 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;
}

View 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();